diff --git a/SpeckleCore b/SpeckleCore index 53332c9..74ecc5a 160000 --- a/SpeckleCore +++ b/SpeckleCore @@ -1 +1 @@ -Subproject commit 53332c9fd2c281a6d16d9e37e7488db8a826c74d +Subproject commit 74ecc5ad2693f61ebf70e0afbd153dbc0cb71532 diff --git a/SpeckleRhinoConverter/src/SpeckleRhGhConverter.cs b/SpeckleRhinoConverter/src/SpeckleRhGhConverter.cs index 91fe403..7a6efa5 100644 --- a/SpeckleRhinoConverter/src/SpeckleRhGhConverter.cs +++ b/SpeckleRhinoConverter/src/SpeckleRhGhConverter.cs @@ -230,7 +230,7 @@ public static SpeckleInterval ToSpeckle( this Interval interval ) public static Interval ToNative( this SpeckleInterval interval ) { - return new Interval( ( double ) interval.Start, ( double ) interval.End ); ; + return new Interval( ( double ) interval.Start, ( double ) interval.End ); } // Interval2d @@ -270,14 +270,16 @@ public static SpeckleLine ToSpeckle( this Line line ) // Rh Line capture public static SpeckleLine ToSpeckle( this LineCurve line ) { - return new SpeckleLine( ( new Point3d[ ] { line.PointAtStart, line.PointAtEnd } ).ToFlatArray(), properties: line.UserDictionary.ToSpeckle() ); + return new SpeckleLine( ( new Point3d[ ] { line.PointAtStart, line.PointAtEnd } ).ToFlatArray(), properties: line.UserDictionary.ToSpeckle() ) { Domain = line.Domain.ToSpeckle() }; } - // Back again only to LINECURVES because we hate rhinocommon + // Back again only to LINECURVES because we hate grasshopper and its dealings with rhinocommon public static LineCurve ToNative( this SpeckleLine line ) { var pts = line.Value.ToPoints(); var myLine = new LineCurve( pts[ 0 ], pts[ 1 ] ); + if ( line.Domain != null ) + myLine.Domain = line.Domain.ToNative(); myLine.UserDictionary.ReplaceContentsWith( line.Properties.ToNative() ); return myLine; } @@ -285,7 +287,7 @@ public static LineCurve ToNative( this SpeckleLine line ) // Rectangles now and forever forward will become polylines public static SpecklePolyline ToSpeckle( this Rectangle3d rect ) { - return new SpecklePolyline( ( new Point3d[ ] { rect.Corner( 0 ), rect.Corner( 1 ), rect.Corner( 2 ), rect.Corner( 3 ) } ).ToFlatArray() ) { closed = true }; + return new SpecklePolyline( ( new Point3d[ ] { rect.Corner( 0 ), rect.Corner( 1 ), rect.Corner( 2 ), rect.Corner( 3 ) } ).ToFlatArray() ) { Closed = true }; } // Circle @@ -299,6 +301,7 @@ public static ArcCurve ToNative( this SpeckleCircle circ ) { Circle circle = new Circle( new Plane( circ.Center.ToNative().Location, circ.Normal.ToNative() ), ( double ) circ.Radius ); var myCircle = new ArcCurve( circle ); + myCircle.Domain = circ.Domain.ToNative(); myCircle.UserDictionary.ReplaceContentsWith( circ.Properties.ToNative() ); return myCircle; } @@ -312,6 +315,7 @@ public static SpeckleObject ToSpeckle( this ArcCurve a ) Circle preCircle; a.TryGetCircle( out preCircle ); SpeckleCircle myCircle = preCircle.ToSpeckle(); + myCircle.Domain = a.Domain.ToSpeckle(); myCircle.Properties = a.UserDictionary.ToSpeckle(); return myCircle; } @@ -320,6 +324,7 @@ public static SpeckleObject ToSpeckle( this ArcCurve a ) Arc preArc; a.TryGetArc( out preArc ); SpeckleArc myArc = preArc.ToSpeckle(); + myArc.Domain = a.Domain.ToSpeckle(); myArc.Properties = a.UserDictionary.ToSpeckle(); return myArc; } @@ -335,7 +340,11 @@ public static SpeckleArc ToSpeckle( this Arc a ) public static ArcCurve ToNative( this SpeckleArc a ) { Arc arc = new Arc( a.Plane.ToNative(), ( double ) a.Radius, ( double ) a.AngleRadians ); + arc.StartAngle = ( double ) a.StartAngle; + arc.EndAngle = ( double ) a.EndAngle; var myArc = new ArcCurve( arc ); + if ( a.Domain != null ) + myArc.Domain = a.Domain.ToNative(); myArc.UserDictionary.ReplaceContentsWith( a.Properties.ToNative() ); return myArc; } @@ -350,6 +359,8 @@ public static NurbsCurve ToNative( this SpeckleEllipse e ) { Ellipse elp = new Ellipse( e.Plane.ToNative(), ( double ) e.FirstRadius, ( double ) e.SecondRadius ); var myEllp = elp.ToNurbsCurve(); + if ( e.Domain != null ) + myEllp.Domain = e.Domain.ToNative(); myEllp.UserDictionary.ReplaceContentsWith( e.Properties.ToNative() ); return myEllp; } @@ -363,9 +374,9 @@ public static SpeckleObject ToSpeckle( this Polyline poly ) return new SpeckleLine( poly.ToFlatArray() ); var myPoly = new SpecklePolyline( poly.ToFlatArray() ); - myPoly.closed = poly.IsClosed; + myPoly.Closed = poly.IsClosed; - if ( myPoly.closed ) + if ( myPoly.Closed ) myPoly.Value.RemoveRange( myPoly.Value.Count - 3, 3 ); return myPoly; @@ -382,11 +393,12 @@ public static SpeckleObject ToSpeckle( this PolylineCurve poly ) return new SpeckleLine( polyline.ToFlatArray(), null, poly.UserDictionary.ToSpeckle() ); var myPoly = new SpecklePolyline( polyline.ToFlatArray() ); - myPoly.closed = polyline.IsClosed; + myPoly.Closed = polyline.IsClosed; - if ( myPoly.closed ) + if ( myPoly.Closed ) myPoly.Value.RemoveRange( myPoly.Value.Count - 3, 3 ); + myPoly.Domain = poly.Domain.ToSpeckle(); myPoly.Properties = poly.UserDictionary.ToSpeckle(); return myPoly; } @@ -397,9 +409,11 @@ public static SpeckleObject ToSpeckle( this PolylineCurve poly ) public static PolylineCurve ToNative( this SpecklePolyline poly ) { var points = poly.Value.ToPoints().ToList(); - if ( poly.closed ) points.Add( points[ 0 ] ); + if ( poly.Closed ) points.Add( points[ 0 ] ); var myPoly = new PolylineCurve( points ); + if ( poly.Domain != null ) + myPoly.Domain = poly.Domain.ToNative(); myPoly.UserDictionary.ReplaceContentsWith( poly.Properties.ToNative() ); return myPoly; } @@ -409,23 +423,25 @@ public static PolylineCurve ToNative( this SpecklePolyline poly ) public static SpecklePolycurve ToSpeckle( this PolyCurve p ) { SpecklePolycurve myPoly = new SpecklePolycurve(); + myPoly.Closed = p.IsClosed; + myPoly.Domain = p.Domain.ToSpeckle(); p.RemoveNesting(); var segments = p.Explode(); myPoly.Segments = segments.Select( s => { return s.ToSpeckle(); } ).ToList(); myPoly.Properties = p.UserDictionary.ToSpeckle(); - myPoly.SetHashes( myPoly.Segments.Select( obj => obj.Hash ).ToArray() ); + myPoly.SetHashes( myPoly.Segments.Select( obj => obj.Hash ).ToArray() ); + return myPoly; } public static PolyCurve ToNative( this SpecklePolycurve p ) { - PolyCurve myPolyc = new PolyCurve(); foreach ( var segment in p.Segments ) { - switch(segment) + switch ( segment ) { case SpeckleCore.SpeckleCurve crv: myPolyc.Append( crv.ToNative() ); @@ -442,6 +458,8 @@ public static PolyCurve ToNative( this SpecklePolycurve p ) } } myPolyc.UserDictionary.ReplaceContentsWith( p.Properties.ToNative() ); + if ( p.Domain != null ) + myPolyc.Domain = p.Domain.ToNative(); return myPolyc; } @@ -495,6 +513,7 @@ public static SpeckleObject ToSpeckle( this Curve curve ) myCurve.Periodic = nurbsCurve.IsPeriodic; myCurve.Rational = nurbsCurve.IsRational; myCurve.Domain = nurbsCurve.Domain.ToSpeckle(); + myCurve.Closed = nurbsCurve.IsClosed; myCurve.Properties = properties; return myCurve; @@ -537,7 +556,6 @@ public static SpeckleObject ToSpeckle( this NurbsCurve curve ) curve.ToPolyline( 0, 1, 0, 0, 0, 0.1, 0, 0, true ).TryGetPolyline( out poly ); SpeckleCurve myCurve = new SpeckleCurve( poly: ( SpecklePolyline ) poly.ToSpeckle(), properties: curve.UserDictionary.ToSpeckle() ); - myCurve.Weights = curve.Points.Select( ctp => ctp.Weight ).ToList(); myCurve.Points = curve.Points.Select( ctp => ctp.Location ).ToFlatArray().ToList(); myCurve.Knots = curve.Knots.ToList(); @@ -545,6 +563,7 @@ public static SpeckleObject ToSpeckle( this NurbsCurve curve ) myCurve.Periodic = curve.IsPeriodic; myCurve.Rational = curve.IsRational; myCurve.Domain = curve.Domain.ToSpeckle(); + myCurve.Closed = curve.IsClosed; myCurve.Properties = properties; return myCurve; @@ -552,20 +571,41 @@ public static SpeckleObject ToSpeckle( this NurbsCurve curve ) public static NurbsCurve ToNative( this SpeckleCurve curve ) { - var ptsList = curve.Points.ToPoints(); - - // Bug/feature in Rhino sdk: creating a periodic curve adds two extra stupid points? - var myCurve = NurbsCurve.Create( curve.Periodic, curve.Degree, new Point3d[ curve.Periodic ? ptsList.Length - 2 : ptsList.Length ] ); - myCurve.Domain = curve.Domain.ToNative(); - - for ( int i = 0; i < ptsList.Length; i++ ) - myCurve.Points.SetPoint( i, ptsList[ i ].X, ptsList[ i ].Y, ptsList[ i ].Z, curve.Weights[ i ] ); - - for ( int i = 0; i < curve.Knots.Count; i++ ) - myCurve.Knots[ i ] = curve.Knots[ i ]; + var ptsList = curve.Points.ToPoints(); - myCurve.UserDictionary.ReplaceContentsWith( curve.Properties.ToNative() ); - return myCurve; + if ( !curve.Periodic ) + { + // Bug/feature in Rhino sdk: creating a periodic curve adds two extra stupid points? + var myCurve = NurbsCurve.Create( curve.Periodic, curve.Degree, ptsList ); + myCurve.Domain = curve.Domain.ToNative(); + + // set weights + for ( int i = 0; i < ptsList.Length; i++ ) + myCurve.Points.SetPoint( i, ptsList[ i ].X, ptsList[ i ].Y, ptsList[ i ].Z, curve.Weights[ i ] ); + + // set knots + for ( int i = 0; i < curve.Knots.Count; i++ ) + myCurve.Knots[ i ] = curve.Knots[ i ]; + + myCurve.UserDictionary.ReplaceContentsWith( curve.Properties.ToNative() ); + return myCurve; + } + else + { + var thePts = ptsList.Take( ptsList.Length - 3 ).ToArray(); + var myCurve = NurbsCurve.Create( curve.Periodic, curve.Degree, thePts ); + + // set weights + for ( int i = 0; i < ptsList.Length; i++ ) + myCurve.Points.SetPoint( i, ptsList[ i ].X, ptsList[ i ].Y, ptsList[ i ].Z, curve.Weights[ i ] ); + + // set knots + for ( int i = 0; i < curve.Knots.Count; i++ ) + myCurve.Knots[ i ] = curve.Knots[ i ]; + + myCurve.Domain = curve.Domain.ToNative(); + return myCurve; + } } #endregion @@ -649,7 +689,7 @@ public static SpeckleBrep ToSpeckle( this Brep brep ) { MeshingParameters mySettings; #if R6 - mySettings = new MeshingParameters(0); + mySettings = new MeshingParameters( 0 ); #else mySettings = MeshingParameters.Coarse; @@ -789,15 +829,15 @@ public static object ToNative( this SpeckleAnnotation annot ) TextHeight = ( double ) annot.TextHeight }; #if R6 - var dimStyleIndex = Rhino.RhinoDoc.ActiveDoc.DimStyles.Add("Speckle"); - var dimStyle = new Rhino.DocObjects.DimensionStyle - { - TextHeight = (double)annot.TextHeight, - Font = new Rhino.DocObjects.Font(annot.FontName, Rhino.DocObjects.Font.FontWeight.Bold, Rhino.DocObjects.Font.FontStyle.Italic, false, false) - }; - Rhino.RhinoDoc.ActiveDoc.DimStyles.Modify(dimStyle, dimStyleIndex, true); - - textEntity.DimensionStyleId = Rhino.RhinoDoc.ActiveDoc.DimStyles[dimStyleIndex].Id; + var dimStyleIndex = Rhino.RhinoDoc.ActiveDoc.DimStyles.Add( "Speckle" ); + var dimStyle = new Rhino.DocObjects.DimensionStyle + { + TextHeight = ( double ) annot.TextHeight, + Font = new Rhino.DocObjects.Font( annot.FontName, Rhino.DocObjects.Font.FontWeight.Bold, Rhino.DocObjects.Font.FontStyle.Italic, false, false ) + }; + Rhino.RhinoDoc.ActiveDoc.DimStyles.Modify( dimStyle, dimStyleIndex, true ); + + textEntity.DimensionStyleId = Rhino.RhinoDoc.ActiveDoc.DimStyles[ dimStyleIndex ].Id; #endif @@ -812,7 +852,6 @@ public static object ToNative( this SpeckleAnnotation annot ) } } - // Blocks and groups // TODO