/// <summary> /// Given an unrolled text dot, returns the index of the source, or following text dot. /// </summary> /// <param name="dot">An unrolled text dot returned by Unroller.PerformUnroll.</param> /// <returns>The index of the text dot added by Unroller.AddFollowingGeometry if successful, otherwise -1.</returns> /// <since>6.0</since> public int FollowingGeometryIndex(TextDot dot) { if (dot == null) { throw new ArgumentNullException("dot"); } IntPtr ptr_const_textdot = dot.ConstPointer(); return(UnsafeNativeMethods.CRhinoUnrollResults_FollowingGeometryIndex(ptr_const_textdot)); }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex) { if (IntPtr.Zero == pGeometry) { return(null); } var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) { return(null); } GeometryBase rc = null; switch (type) { case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1 rc = new Curve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8 rc = new Point(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10 rc = new Surface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11 rc = new Brep(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20 { int faceindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (ptr_brep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Faces[faceindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21 { int edgeindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (ptr_brep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Edges[edgeindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32 rc = new Light(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35 { int loopindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (ptr_brep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Loops[loopindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36 { int trimindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (ptr_brep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Trims[trimindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38 rc = new Leader(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39 rc = new SubD(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40 rc = new LinearDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41 rc = new AngularDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42 rc = new RadialDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43 rc = new OrdinateDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44 rc = new Centermark(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45 rc = new TextEntity(pGeometry, parent); break; default: rc = new UnknownGeometry(pGeometry, parent, subobjectIndex); break; } return(rc); }
/// <summary> /// Executes unrolling operations. /// </summary> /// <param name="unrolledCurves">An array of unrolled curves is assigned during the call in this out parameter.</param> /// <param name="unrolledPoints">An array of unrolled points is assigned during the call in this out parameter.</param> /// <param name="unrolledDots">An array of unrolled text dots is assigned during the call in this out parameter.</param> /// <returns>An array of breps. This array can be empty.</returns> /// <since>5.0</since> public Brep[] PerformUnroll(out Curve[] unrolledCurves, out Point3d[] unrolledPoints, out TextDot[] unrolledDots) { unrolledCurves = new Curve[0]; unrolledPoints = new Point3d[0]; unrolledDots = new TextDot[0]; IntPtr ptr_unroller = IntPtr.Zero; if (m_surface != null) { IntPtr const_ptr_surface = m_surface.ConstPointer(); ptr_unroller = UnsafeNativeMethods.CRhinoUnroll_NewSrf(const_ptr_surface, m_absolute_tolerance, m_relative_tolerance); } else if (m_brep != null) { IntPtr const_ptr_brep = m_brep.ConstPointer(); ptr_unroller = UnsafeNativeMethods.CRhinoUnroll_NewBrp(const_ptr_brep, m_absolute_tolerance, m_relative_tolerance); } if (ptr_unroller == IntPtr.Zero) { throw new Exception("Unable to access input surface or brep"); } var rc = new Brep[0]; if (0 == UnsafeNativeMethods.CRhinoUnroll_PrepareFaces(ptr_unroller)) { if (m_curves.Count > 0) { var crvs = new Runtime.InteropWrappers.SimpleArrayCurvePointer(m_curves); IntPtr const_ptr_curves = crvs.ConstPointer(); UnsafeNativeMethods.CRhinoUnroll_PrepareCurves(ptr_unroller, const_ptr_curves); } if (m_points.Count > 0) { Point3d[] pts = m_points.ToArray(); UnsafeNativeMethods.CRhinoUnroll_PreparePoints(ptr_unroller, pts.Length, pts); } if (m_dots.Count > 0) { using (var dots = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(m_dots)) { IntPtr const_ptr_dots = dots.ConstPointer(); UnsafeNativeMethods.CRhinoUnroll_PrepareDots(ptr_unroller, const_ptr_dots); } } int brep_count = 0; int curve_count = 0; int point_count = 0; int dot_count = 0; double explode_dist = -1; if (m_explode_output) { explode_dist = m_explode_spacing; } IntPtr ptr_results = UnsafeNativeMethods.CRhinoUnroll_CreateFlatBreps(ptr_unroller, explode_dist, ref brep_count, ref curve_count, ref point_count, ref dot_count); if (ptr_results != IntPtr.Zero) { if (brep_count > 0) { rc = new Brep[brep_count]; for (int i = 0; i < brep_count; i++) { IntPtr ptr_brep = UnsafeNativeMethods.CRhinoUnrollResults_GetBrep(ptr_results, i); if (ptr_brep != IntPtr.Zero) { rc[i] = new Brep(ptr_brep, null); } } } if (curve_count > 0) { unrolledCurves = new Curve[curve_count]; for (int i = 0; i < curve_count; i++) { IntPtr ptr_curve = UnsafeNativeMethods.CRhinoUnrollResults_GetCurve(ptr_results, i); if (ptr_curve != IntPtr.Zero) { unrolledCurves[i] = new Curve(ptr_curve, null); } } } if (point_count > 0) { unrolledPoints = new Point3d[point_count]; UnsafeNativeMethods.CRhinoUnrollResults_GetPoints(ptr_results, point_count, unrolledPoints); } if (dot_count > 0) { unrolledDots = new TextDot[dot_count]; for (int i = 0; i < dot_count; i++) { IntPtr ptr_dots = UnsafeNativeMethods.CRhinoUnrollResults_GetDot(ptr_results, i); if (ptr_dots != IntPtr.Zero) { unrolledDots[i] = new TextDot(ptr_dots, null); } } } UnsafeNativeMethods.CRhinoUnrollResults_Delete(ptr_results); } } UnsafeNativeMethods.CRhinoUnroll_Delete(ptr_unroller); return(rc); }
/// <summary> /// Adds a text dot that should be unrolled along with the surface/brep. /// </summary> /// <param name="dot">A text dot.</param> /// <since>5.0</since> public void AddFollowingGeometry(TextDot dot) { m_dots.Add(dot); }
/// <summary> /// Adds a text dot that should be unrolled along with the surface/brep. /// </summary> /// <param name="dotLocation">A dot point.</param> /// <param name="dotText">A dot text.</param> /// <since>5.0</since> public void AddFollowingGeometry(Point3d dotLocation, string dotText) { var dot = new TextDot(dotText, dotLocation); AddFollowingGeometry(dot); }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobject_index) { if (IntPtr.Zero == pGeometry) return null; int type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) return null; GeometryBase rc = null; switch (type) { case idxON_Curve: //1 rc = new Curve(pGeometry, parent, subobject_index); break; case idxON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobject_index); break; case idxON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobject_index); break; case idxON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobject_index); break; case idxON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobject_index); break; case idxON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobject_index); break; case idxON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case idxON_Point: //8 rc = new Point(pGeometry, parent); break; case idxON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case idxON_Surface: //10 rc = new Surface(pGeometry, parent); break; case idxON_Brep: //11 rc = new Brep(pGeometry, parent); break; case idxON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case idxON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case idxON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case idxON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case idxON_Annotation2: // 16 rc = new AnnotationBase(pGeometry, parent); break; case idxON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case idxON_TextEntity2: //18 rc = new TextEntity(pGeometry, parent); break; case idxON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case idxON_BrepFace: //20 { int faceindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (pBrep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Faces[faceindex]; } } break; case idxON_BrepEdge: // 21 { int edgeindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (pBrep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Edges[edgeindex]; } } break; case idxON_InstanceDefinition: // 22 rc = new InstanceDefinitionGeometry(pGeometry, parent); break; case idxON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; #if USING_V5_SDK case idxON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; #endif case idxON_LinearDimension2: //25 rc = new LinearDimension(pGeometry, parent); break; case idxON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case idxON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case idxON_AngularDimension2: // 28 rc = new AngularDimension(pGeometry, parent); break; case idxON_RadialDimension2: // 29 rc = new RadialDimension(pGeometry, parent); break; case idxON_Leader: // 30 rc = new Leader(pGeometry, parent); break; case idxON_OrdinateDimension2: // 31 rc = new OrdinateDimension(pGeometry, parent); break; case idxON_Light: //32 rc = new Light(pGeometry, parent); break; case idxON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case idxON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case idxON_BrepLoop: //35 { int loopindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (pBrep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Loops[loopindex]; } } break; case idxON_BrepTrim: // 36 { int trimindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (pBrep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Trims[trimindex]; } } break; default: rc = new UnknownGeometry(pGeometry, parent, subobject_index); break; } return rc; }
/// <summary> /// Adds a text dot that should be unrolled along with the surface/brep. /// </summary> /// <param name="dot">A text dot.</param> public void AddFollowingGeometry(TextDot dot) { m_dots.Add(dot); }
/// <summary> /// Executes unrolling operations. /// </summary> /// <param name="unrolledCurves">An array of unrolled curves is assigned during the call in this out parameter.</param> /// <param name="unrolledPoints">An array of unrolled points is assigned during the call in this out parameter.</param> /// <param name="unrolledDots">An array of unrolled text dots is assigned during the call in this out parameter.</param> /// <returns>An array of breps. This array can be empty.</returns> public Brep[] PerformUnroll(out Curve[] unrolledCurves, out Point3d[] unrolledPoints, out TextDot[] unrolledDots) { unrolledCurves = new Curve[0]; unrolledPoints = new Point3d[0]; unrolledDots = new TextDot[0]; IntPtr pUnroller = IntPtr.Zero; if (m_surface != null) { IntPtr pSurface = m_surface.ConstPointer(); pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewSrf(pSurface, m_dAbsoluteTolerance, m_dRelativeTolerance); } else if (m_brep != null) { IntPtr pBrep = m_brep.ConstPointer(); pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewBrp(pBrep, m_dAbsoluteTolerance, m_dRelativeTolerance); } if (pUnroller == IntPtr.Zero) throw new Exception("Unable to access input surface or brep"); Brep[] rc = new Brep[0]; if (0 == UnsafeNativeMethods.CRhinoUnroll_PrepareFaces(pUnroller)) { if (m_curves.Count > 0) { Runtime.InteropWrappers.SimpleArrayCurvePointer crvs = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(m_curves); IntPtr pCrvs = crvs.ConstPointer(); UnsafeNativeMethods.CRhinoUnroll_PrepareCurves(pUnroller, pCrvs); } if (m_points.Count > 0) { Point3d[] pts = m_points.ToArray(); UnsafeNativeMethods.CRhinoUnroll_PreparePoints(pUnroller, pts.Length, pts); } if (m_dots.Count > 0) { Runtime.INTERNAL_GeometryArray dots = new Rhino.Runtime.INTERNAL_GeometryArray(m_dots); IntPtr pDots = dots.ConstPointer(); UnsafeNativeMethods.CRhinoUnroll_PrepareDots(pUnroller, pDots); } int brepCount = 0; int curveCount = 0; int pointCount = 0; int dotCount = 0; double explode_dist = -1; if (m_bExplodeOutput) explode_dist = m_dExplodeSpacing; IntPtr pResults = UnsafeNativeMethods.CRhinoUnroll_CreateFlatBreps(pUnroller, explode_dist, ref brepCount, ref curveCount, ref pointCount, ref dotCount); if (pResults != IntPtr.Zero) { if (brepCount > 0) { rc = new Brep[brepCount]; for (int i = 0; i < brepCount; i++) { IntPtr pBrep = UnsafeNativeMethods.CRhinoUnrollResults_GetBrep(pResults, i); if (pBrep != IntPtr.Zero) rc[i] = new Brep(pBrep, null); } } if (curveCount > 0) { unrolledCurves = new Curve[curveCount]; for (int i = 0; i < curveCount; i++) { IntPtr pCurve = UnsafeNativeMethods.CRhinoUnrollResults_GetCurve(pResults, i); if (pCurve != IntPtr.Zero) unrolledCurves[i] = new Curve(pCurve, null); } } if (pointCount > 0) { unrolledPoints = new Point3d[pointCount]; UnsafeNativeMethods.CRhinoUnrollResults_GetPoints(pResults, pointCount, unrolledPoints); } if (dotCount > 0) { unrolledDots = new TextDot[dotCount]; for (int i = 0; i < dotCount; i++) { IntPtr pDot = UnsafeNativeMethods.CRhinoUnrollResults_GetDot(pResults, i); if (pDot != IntPtr.Zero) unrolledDots[i] = new TextDot(pDot, null); } } UnsafeNativeMethods.CRhinoUnrollResults_Delete(pResults); } } UnsafeNativeMethods.CRhinoUnroll_Delete(pUnroller); return rc; }
/// <summary> /// Adds a text dot that should be unrolled along with the surface/brep. /// </summary> /// <param name="dotLocation">A dot point.</param> /// <param name="dotText">A dot text.</param> public void AddFollowingGeometry(Point3d dotLocation, string dotText) { TextDot dot = new TextDot(dotText, dotLocation); AddFollowingGeometry(dot); }
public static Rhino.Commands.Result UnrollSurface(Rhino.RhinoDoc doc) { const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Unroller unroll = null; Rhino.Geometry.Brep brep = objref.Brep(); if (brep != null) { unroll = new Rhino.Geometry.Unroller(brep); } else { Rhino.Geometry.Surface srf = objref.Surface(); if (srf != null) { unroll = new Rhino.Geometry.Unroller(srf); } } if (unroll == null) { return(Rhino.Commands.Result.Cancel); } unroll.AbsoluteTolerance = 0.01; unroll.RelativeTolerance = 0.01; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select points, curves, and dots to unroll with surface"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot; go.AcceptNothing(true); go.GetMultiple(0, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } for (int i = 0; i < go.ObjectCount; i++) { objref = go.Object(i); Rhino.Geometry.GeometryBase g = objref.Geometry(); Rhino.Geometry.Point pt = g as Rhino.Geometry.Point; Rhino.Geometry.Curve crv = g as Rhino.Geometry.Curve; Rhino.Geometry.TextDot dot = g as Rhino.Geometry.TextDot; if (pt != null) { unroll.AddFollowingGeometry(pt.Location); } else if (crv != null) { unroll.AddFollowingGeometry(crv); } else if (dot != null) { unroll.AddFollowingGeometry(dot); } } unroll.ExplodeOutput = false; Rhino.Geometry.Curve[] curves; Rhino.Geometry.Point3d[] points; Rhino.Geometry.TextDot[] dots; Rhino.Geometry.Brep[] breps = unroll.PerformUnroll(out curves, out points, out dots); if (breps == null || breps.Length < 1) { return(Rhino.Commands.Result.Failure); } for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Objects.AddPoints(points); for (int i = 0; i < dots.Length; i++) { doc.Objects.AddTextDot(dots[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }