Skip to content

Commit

Permalink
More rhino additions (#20)
Browse files Browse the repository at this point in the history
* add interfaces and fix projects

* more to host

* fix tohost stuff
  • Loading branch information
adamhathcock authored Jun 20, 2024
1 parent 137c6ac commit 5d3960e
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Revit/Speckle.Revit.Api/Speckle.Revit.Api.shproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>{E1C43415-3200-45F4-8BF9-A4DD7D7F2ED7}</ProjectGuid>
<ProjectGuid>{E1C43415-3101-45F4-8BF9-A4DD7D7F2ED7}</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand All @@ -10,4 +10,4 @@
<PropertyGroup />
<Import Project="Speckle.Revit.Api.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>{E1C43415-3200-45F4-8BF9-A4DD7D7F2ED6}</ProjectGuid>
<ProjectGuid>{E1C43415-3102-45F4-8BF9-A4DD7D7F2ED6}</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand All @@ -10,4 +10,4 @@
<PropertyGroup />
<Import Project="Speckle.Revit.Interfaces.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
</Project>
79 changes: 70 additions & 9 deletions Rhino/Speckle.Rhino.Api/IRhinoCurve.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections;
using Rhino;
using Rhino.Collections;
using Rhino.Display;
using Rhino.DocObjects;
using Rhino.DocObjects.Tables;
using Rhino.Geometry;
using Rhino.Geometry.Collections;
using Rhino.Geometry.MeshRefinements;
Expand All @@ -23,6 +25,61 @@ public partial class RhinoDocProxy
public RhinoUnitSystem ModelUnitSystem => EnumUtility<UnitSystem, RhinoUnitSystem>.Convert(_Instance.ModelUnitSystem);
}

[Proxy(typeof(RhinoView), new[] { "Equals" })]
public partial interface IRhinoViewProxy : IRhinoView;

[Proxy(typeof(GroupTable), new[] { "Equals", "ComponentType" })]
public partial interface IRhinoGroupTableProxy : IRhinoGroupTable;

public partial class GroupTableProxy
{
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public IEnumerator<IRhinoGroup> GetEnumerator()
{
foreach (var group in _Instance)
{
yield return new GroupProxy(group);
}
}

public int Count => _Instance.Count;
}

[Proxy(typeof(Group), new[] { "ComponentType" })]
public partial interface IRhinoGroupProxy : IRhinoGroup;

[Proxy(typeof(ObjectTable), new[] { "Equals", "ComponentType" })]
public partial interface IRhinoObjectTableProxy : IRhinoObjectTable;

public partial class ObjectTableProxy
{
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => _Instance.Count;
}

[Proxy(typeof(ViewTable), new[] { "Equals" })]
public partial interface IRhinoViewTableProxy : IRhinoViewTable;

public partial class ViewTableProxy
{
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

[Proxy(typeof(Layer), new[] { "Equals", "ComponentType" })]
public partial interface IRhinoLayerProxy : IRhinoLayer;

[Proxy(typeof(LayerTable), new[] { "Equals", "ComponentType", "Count" })]
public partial interface IRhinoLayerTableProxy : IRhinoLayerTable;

public partial class LayerTableProxy
{
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => _Instance.Count;
}

[Proxy(typeof(Curve), new[] { "Duplicate" })]
public partial interface IRhinoCurveProxy : IRhinoCurve;

Expand All @@ -44,19 +101,26 @@ public partial interface IRhinoGeometryBaseProxy : IRhinoGeometryBase;

public partial class GeometryBaseProxy
{
public bool Transform(IRhinoTransform transform) =>
_Instance.Transform(transform.To<IRhinoTransformProxy>().NotNull()._Instance);
public bool Transform(IRhinoTransform transform) => _Instance.Transform(transform.To<TransformProxy>()._Instance);
}

[Proxy(typeof(CommonObject))]
public partial interface IRhinoCommonObjectProxy : IRhinoCommonObject;

[Proxy(typeof(RhinoObject), new[] { "ComponentType" })]
[Proxy(typeof(RhinoObject), new[] { "ComponentType", "ObjectType" })]
public partial interface IRhinoObjectProxy : IRhinoObject;

public partial class RhinoObjectProxy
{
public RhinoObjectType ObjectType => EnumUtility<ObjectType, RhinoObjectType>.Convert(_Instance.ObjectType);
}

[Proxy(typeof(ModelComponent))]
public partial interface IRhinoModelComponentProxy : IRhinoModelComponent;

[Proxy(typeof(ObjectAttributes))]
public partial interface IRhinoObjectAttributesProxy : IRhinoObjectAttributes;

[Proxy(typeof(ArcCurve))]
public partial interface IRhinoArcCurveProxy : IRhinoArcCurve;

Expand Down Expand Up @@ -226,10 +290,7 @@ public IEnumerator<IRhinoBrepLoop> GetEnumerator()
public IRhinoBrepLoop Add(RhinoBrepLoopType type, IRhinoBrepFace face)
{
return A.Cast<IRhinoBrepLoop, BrepLoop>(
_Instance.Add(
EnumUtility<RhinoBrepLoopType, BrepLoopType>.Convert(type),
face.To<IRhinoBrepFaceProxy>()._Instance
)
_Instance.Add(EnumUtility<RhinoBrepLoopType, BrepLoopType>.Convert(type), face.To<BrepFaceProxy>()._Instance)
)
.NotNull();
}
Expand Down Expand Up @@ -288,8 +349,8 @@ int curveIndex
) =>
A.Cast<IRhinoBrepTrim, BrepTrim>(
_Instance.AddSingularTrim(
vertex.To<IRhinoBrepVertexProxy>()._Instance,
loop.To<IRhinoBrepLoopProxy>()._Instance,
vertex.To<BrepVertexProxy>()._Instance,
loop.To<BrepLoopProxy>()._Instance,
EnumUtility<RhinoIsoStatus, IsoStatus>.Convert(status),
curveIndex
)
Expand Down
54 changes: 30 additions & 24 deletions Rhino/Speckle.Rhino.Api/RhinoMeshFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Rhino;
using Rhino.Collections;
using Rhino.DocObjects;
using Rhino.Geometry;
using Speckle.ProxyGenerator;
using Speckle.Rhino7.Interfaces;
Expand All @@ -13,7 +14,7 @@ public class RhinoMeshFactory : IRhinoMeshFactory

public IEnumerable<IRhinoMesh> CreateFromBrep(IRhinoBrep brep, double density, double minimumEdgeLength)
{
var b = brep.To<IRhinoBrepProxy>()._Instance;
var b = brep.To<BrepProxy>()._Instance;
return Mesh.CreateFromBrep(b, new MeshingParameters(density, minimumEdgeLength)).Select(x => new MeshProxy(x));
}
}
Expand All @@ -23,16 +24,14 @@ public class RhinoArcFactory : IRhinoArcFactory
public IRhinoArc Create(IRhinoPoint3d startPoint, IRhinoPoint3d midPoint, IRhinoPoint3d endPoint) =>
new ArcProxy(
new Arc(
startPoint.To<IRhinoPoint3dProxy>()._Instance,
midPoint.To<IRhinoPoint3dProxy>()._Instance,
endPoint.To<IRhinoPoint3dProxy>()._Instance
startPoint.To<Point3dProxy>()._Instance,
midPoint.To<Point3dProxy>()._Instance,
endPoint.To<Point3dProxy>()._Instance
)
);

public IRhinoArcCurve Create(IRhinoArc arc, IRhinoInterval domain) =>
new ArcCurveProxy(
new ArcCurve(arc.To<IRhinoArcProxy>()._Instance) { Domain = domain.To<IRhinoIntervalProxy>()._Instance }
);
new ArcCurveProxy(new ArcCurve(arc.To<ArcProxy>()._Instance) { Domain = domain.To<IntervalProxy>()._Instance });
}

public class RhinoPointFactory : IRhinoPointFactory
Expand All @@ -41,11 +40,10 @@ public class RhinoPointFactory : IRhinoPointFactory

public IRhinoPoint3d Create(double x, double y, double z) => new Point3dProxy(new Point3d(x, y, z));

public IRhinoPoint Create(IRhinoPoint3d point3d) =>
new PointProxy(new Point(point3d.To<IRhinoPoint3dProxy>()._Instance));
public IRhinoPoint Create(IRhinoPoint3d point3d) => new PointProxy(new Point(point3d.To<Point3dProxy>()._Instance));

public IRhinoPoint3dList Create(IList<IRhinoPoint3d> list) =>
new Point3dListProxy(new Point3dList(list.Select(x => x.To<IRhinoPoint3dProxy>()._Instance)));
new Point3dListProxy(new Point3dList(list.Cast<Point3dProxy>().Select(x => x._Instance)));
}

public class RhinoIntervalFactory : IRhinoIntervalFactory
Expand All @@ -56,12 +54,10 @@ public class RhinoIntervalFactory : IRhinoIntervalFactory
public class RhinoCircleFactory : IRhinoCircleFactory
{
public IRhinoCircle Create(IRhinoPlane plane, double raduis) =>
new CircleProxy(new Circle(plane.To<IRhinoPlaneProxy>()._Instance, raduis));
new CircleProxy(new Circle(plane.To<PlaneProxy>()._Instance, raduis));

public IRhinoArcCurve Create(IRhinoCircle arc, IRhinoInterval domain) =>
new ArcCurveProxy(
new ArcCurve(arc.To<IRhinoCircleProxy>()._Instance) { Domain = domain.To<IRhinoIntervalProxy>()._Instance }
);
new ArcCurveProxy(new ArcCurve(arc.To<CircleProxy>()._Instance) { Domain = domain.To<IntervalProxy>()._Instance });
}

public class RhinoCurveFactory : IRhinoCurveFactory
Expand All @@ -74,23 +70,22 @@ public class RhinoCurveFactory : IRhinoCurveFactory
public class RhinoLineFactory : IRhinoLineFactory
{
public IRhinoLine Create(IRhinoPoint3d start, IRhinoPoint3d end) =>
new LineProxy(new Line(start.To<IRhinoPoint3dProxy>()._Instance, end.To<IRhinoPoint3dProxy>()._Instance));
new LineProxy(new Line(start.To<Point3dProxy>()._Instance, end.To<Point3dProxy>()._Instance));

public IRhinoLineCurve Create(IRhinoLine line) =>
new LineCurveProxy(new LineCurve(line.To<IRhinoLineProxy>()._Instance));
public IRhinoLineCurve Create(IRhinoLine line) => new LineCurveProxy(new LineCurve(line.To<LineProxy>()._Instance));

public IRhinoPolyline Create(IRhinoPoint3dList list) =>
new PolylineProxy(new Polyline(list.Select(x => x.To<IRhinoPoint3dProxy>()._Instance)));
new PolylineProxy(new Polyline(list.Select(x => x.To<Point3dProxy>()._Instance)));
}

public class RhinoPlaneFactory : IRhinoPlaneFactory
{
public IRhinoPlane Create(IRhinoPoint3d origin, IRhinoVector3d xdir, IRhinoVector3d ydir) =>
new PlaneProxy(
new Plane(
origin.To<IRhinoPoint3dProxy>()._Instance,
xdir.To<IRhinoVector3dProxy>()._Instance,
ydir.To<IRhinoVector3dProxy>()._Instance
origin.To<Point3dProxy>()._Instance,
xdir.To<Vector3dProxy>()._Instance,
ydir.To<Vector3dProxy>()._Instance
)
);
}
Expand All @@ -116,13 +111,13 @@ public class RhinoTransformFactory : IRhinoTransformFactory
public IRhinoTransform Identity => new TransformProxy(Transform.Identity);

public IRhinoTransform Scale(IRhinoPoint3d origin, double y) =>
new TransformProxy(Transform.Scale(origin.To<IRhinoPoint3dProxy>()._Instance, y));
new TransformProxy(Transform.Scale(origin.To<Point3dProxy>()._Instance, y));
}

public class RhinoPointCloudFactory : IRhinoPointCloudFactory
{
public IRhinoPointCloud Create(IRhinoPoint3dList list) =>
new PointCloudProxy(new PointCloud(list.To<IRhinoPoint3dListProxy>()._Instance));
new PointCloudProxy(new PointCloud(list.To<Point3dListProxy>()._Instance));
}

public class RhinoVectorFactory : IRhinoVectorFactory
Expand All @@ -133,7 +128,7 @@ public class RhinoVectorFactory : IRhinoVectorFactory
public class RhinoEllipseFactory : IRhinoEllipseFactory
{
public IRhinoEllipse Create(IRhinoPlane plane, double firstRadius, double secondRaduis) =>
new EllipseProxy(new Ellipse(plane.To<IRhinoPlaneProxy>()._Instance, firstRadius, secondRaduis));
new EllipseProxy(new Ellipse(plane.To<PlaneProxy>()._Instance, firstRadius, secondRaduis));
}

public class RhinoBrepFactory : IRhinoBrepFactory
Expand All @@ -150,4 +145,15 @@ public IRhinoMeshNgon Create(IList<int> faces, IList<int> indices) =>
public class RhinoDocFactory : IRhinoDocFactory
{
public IRhinoDoc ActiveDoc() => new RhinoDocProxy(RhinoDoc.ActiveDoc);

public IRhinoLayer CreateLayer(string name) => new LayerProxy(new Layer() { Name = name });

public IRhinoLayer CreateLayer(string name, Guid parentLayerId) =>
new LayerProxy(new Layer() { Name = name, ParentLayerId = parentLayerId });

public IRhinoObjectAttributes CreateAttributes(int layerIndex) =>
new ObjectAttributesProxy(new ObjectAttributes() { LayerIndex = layerIndex });

public int UnsetIntIndex => RhinoMath.UnsetIntIndex;
public string LayerPathSeparator => Layer.PathSeparator;
}
8 changes: 8 additions & 0 deletions Rhino/Speckle.Rhino.Interfaces/IRhinoDocFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ namespace Speckle.Rhino7.Interfaces;
public interface IRhinoDocFactory
{
IRhinoDoc ActiveDoc();

IRhinoLayer CreateLayer(string name);
IRhinoLayer CreateLayer(string name, Guid parentLayerId);

IRhinoObjectAttributes CreateAttributes(int layerIndex);

int UnsetIntIndex { get; }
string LayerPathSeparator { get; }
}
62 changes: 61 additions & 1 deletion Rhino/Speckle.Rhino.Interfaces/RhinoCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@ public interface IRhinoDoc
{
double ModelAbsoluteTolerance { get; }
RhinoUnitSystem ModelUnitSystem { get; }

IRhinoViewTable Views { get; }
IRhinoLayerTable Layers { get; }
IRhinoObjectTable Objects { get; }
IRhinoGroupTable Groups { get; }
}

public interface IRhinoGroupTable : IReadOnlyCollection<IRhinoGroup>
{
IRhinoGroup FindIndex(int index);
int Add(string name, IEnumerable<Guid> ids);
}

public interface IRhinoGroup
{
Guid Id { get; }
}

public interface IRhinoObjectTable : IReadOnlyCollection<IRhinoObject>
{
Guid Add(IRhinoGeometryBase obj, IRhinoObjectAttributes attributes);
}

public interface IRhinoViewTable : IEnumerable<IRhinoView>
{
void Redraw();

bool RedrawEnabled { get; set; }
}

public interface IRhinoView { }

public interface IRhinoLayerTable : IReadOnlyList<IRhinoLayer>
{
int Find(Guid guid, string name, int index);
IRhinoLayer FindName(string name);
IRhinoLayer FindIndex(int value);
bool Purge(int index, bool real);
int Add(IRhinoLayer layer);
}

public interface IRhinoLayer : IRhinoModelComponent
{
IRhinoLayer[]? GetChildren();
int Index { get; }
Guid Id { get; }
}

public interface IRhinoObjectAttributes : IRhinoCommonObject
{
string Name { get; }
string GetUserString(string key);
}

public interface IRhinoCurve : IRhinoGeometryBase
Expand Down Expand Up @@ -48,7 +100,15 @@ public interface IRhinoGeometryBase : IRhinoCommonObject

public interface IRhinoCommonObject;

public interface IRhinoObject : IRhinoModelComponent;
public interface IRhinoObject : IRhinoModelComponent
{
Guid Id { get; }
IRhinoObjectAttributes Attributes { get; }

RhinoObjectType ObjectType { get; }

IRhinoGeometryBase Geometry { get; }
}

public interface IRhinoModelComponent : IRhinoCommonObject;

Expand Down
Loading

0 comments on commit 5d3960e

Please sign in to comment.