/// <summary>
        /// Constructs an array of <see cref="Hatch">hatches</see> from a set of curves.
        /// </summary>
        /// <param name="curves">An array, a list or any enumarable set of <see cref="Curve"/>.</param>
        /// <param name="hatchPatternIndex">The index of the hatch pattern in the document hatch pattern table.</param>
        /// <param name="rotationRadians">The relative rotation of the pattern.</param>
        /// <param name="scale">A scaling factor.</param>
        /// <returns>An array of hatches. The array might be empty on error.</returns>
        /// <exception cref="ArgumentNullException">If curves is null.</exception>
        public static Hatch[] Create(IEnumerable <Curve> curves, int hatchPatternIndex, double rotationRadians, double scale)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer curvearray = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(curves);
            IntPtr pCurveArray = curvearray.NonConstPointer();

            Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer hatcharray = new Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer();
            IntPtr pOutput = hatcharray.NonConstPointer();

            UnsafeNativeMethods.RHC_RhinoCreateHatches(pCurveArray, hatchPatternIndex, rotationRadians, scale, pOutput);
            GeometryBase[] g = hatcharray.ToNonConstArray();
            if (g == null)
            {
                return(new Hatch[0]);
            }
            List <Hatch> hatches = new List <Hatch>();

            for (int i = 0; i < g.Length; i++)
            {
                Hatch hatch = g[i] as Hatch;
                if (hatch != null)
                {
                    hatches.Add(hatch);
                }
            }
            return(hatches.ToArray());
        }
Example #2
0
        /// <summary>
        /// Computes an AreaMassProperties for a hatch.
        /// </summary>
        /// <param name="hatch">Hatch to measure.</param>
        /// <returns>The AreaMassProperties for the given hatch or null on failure.</returns>
        /// <exception cref="System.ArgumentNullException">When hatch is null.</exception>
        public static AreaMassProperties Compute(Hatch hatch)
        {
            if (hatch == null)
            {
                throw new ArgumentNullException("hatch");
            }

            const double relativeTolerance = 1.0e-6;
            const double absoluteTolerance = 1.0e-6;
            IntPtr       ptr = hatch.ConstPointer();
            IntPtr       rc  = UnsafeNativeMethods.ON_Hatch_AreaMassProperties(ptr, relativeTolerance, absoluteTolerance);

            return(rc == IntPtr.Zero ? null : new AreaMassProperties(rc, false));
        }
Example #3
0
        public static void drawHatch(Rectangle3d tempBoundingBox, Rhino.Geometry.Hatch hatch, double tempScaleFactor, System.Windows.Point tempOrigin, System.Windows.Media.Brush solidColor, ref Canvas UnitPlanCanvas)
        {
            Curve[] outerCurves = hatch.Get3dCurves(true);
            Curve[] innerCurves = hatch.Get3dCurves(false);

            foreach (Curve i in outerCurves)
            {
                drawBackGround(tempBoundingBox, i, tempScaleFactor, tempOrigin, ref UnitPlanCanvas, solidColor);
            }

            foreach (Curve i in innerCurves)
            {
                drawBackGround(tempBoundingBox, i, tempScaleFactor, tempOrigin, ref UnitPlanCanvas, System.Windows.Media.Brushes.White);
            }
        }
Example #4
0
        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);
        }
 public bool SetFromHatch(Hatch hatch)
 {
   IntPtr pThis = NonConstPointer();
   IntPtr pConstHatch = hatch.ConstPointer();
   return UnsafeNativeMethods.CRhinoGumball_SetFromHatch(pThis, pConstHatch);
 }
    /// <summary>
    /// Computes an AreaMassProperties for a hatch.
    /// </summary>
    /// <param name="hatch">Hatch to measure.</param>
    /// <returns>The AreaMassProperties for the given hatch or null on failure.</returns>
    /// <exception cref="System.ArgumentNullException">When hatch is null.</exception>
    public static AreaMassProperties Compute(Hatch hatch)
    {
      if (hatch == null)
        throw new ArgumentNullException("hatch");

      const double relativeTolerance = 1.0e-6;
      const double absoluteTolerance = 1.0e-6;
      IntPtr ptr = hatch.ConstPointer();
      IntPtr rc = UnsafeNativeMethods.ON_Hatch_AreaMassProperties(ptr, relativeTolerance, absoluteTolerance);
      return rc == IntPtr.Zero ? null : new AreaMassProperties(rc, false);
    }
    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;
    }
Example #8
0
    public static Rhino.Commands.Result ExplodeHatch(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Hatch;

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select hatch to explode", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
        {
            return(rc);
        }

        Rhino.Geometry.Hatch hatch = objref.Geometry() as Rhino.Geometry.Hatch;
        if (null == hatch)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.GeometryBase[] hatch_geom = hatch.Explode();
        if (null != hatch_geom)
        {
            for (int i = 0; i < hatch_geom.Length; i++)
            {
                Rhino.Geometry.GeometryBase geom = hatch_geom[i];
                if (null != geom)
                {
                    switch (geom.ObjectType)
                    {
                    case Rhino.DocObjects.ObjectType.Point:
                    {
                        Rhino.Geometry.Point point = geom as Rhino.Geometry.Point;
                        if (null != point)
                        {
                            doc.Objects.AddPoint(point.Location);
                        }
                    }
                    break;

                    case Rhino.DocObjects.ObjectType.Curve:
                    {
                        Rhino.Geometry.Curve curve = geom as Rhino.Geometry.Curve;
                        if (null != curve)
                        {
                            doc.Objects.AddCurve(curve);
                        }
                    }
                    break;

                    case Rhino.DocObjects.ObjectType.Brep:
                    {
                        Rhino.Geometry.Brep brep = geom as Rhino.Geometry.Brep;
                        if (null != brep)
                        {
                            doc.Objects.AddBrep(brep);
                        }
                    }
                    break;
                    }
                }
            }
        }

        return(Rhino.Commands.Result.Success);
    }