public static Result ProjectPointsToBreps(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        var brep = gs.Object(0).Brep();
        if (brep == null)
          return Result.Failure;

        var points = Intersection.ProjectPointsToBreps(
                 new List<Brep> {brep}, // brep on which to project
                 new List<Point3d> {new Point3d(0, 0, 0), new Point3d(3,0,3), new Point3d(-2,0,-2)}, // some random points to project
                 new Vector3d(0, 1, 0), // project on Y axis
                 doc.ModelAbsoluteTolerance);

        if (points != null && points.Length > 0)
        {
          foreach (var point in points)
          {
        doc.Objects.AddPoint(point);
          }
        }
        doc.Views.Redraw();
        return Result.Success;
    }
Пример #2
0
        public static GH_LinearDimension GetLinearDimension2()
        {
            GetObject obj2;
            Label_0000:
            obj2 = new GetObject();
            if (m_reference)
            {
                obj2.SetCommandPrompt("LinearDimension  reference");
                obj2.AddOption("Mode", "Reference");
            }
            else
            {
                obj2.SetCommandPrompt("LinearDimension to copy");
                obj2.AddOption("Mode", "Copy");
            }
            obj2.GeometryFilter = ObjectType.Annotation;
            GetResult result = obj2.Get();
            if (result == GetResult.Option)
            {
                m_reference = !m_reference;
                goto Label_0000;
            }
            if (result != GetResult.Object)
            {
                return null;
            }
            if (!m_reference)
            {
                return new GH_LinearDimension((LinearDimension)obj2.Object(0).Geometry());
            }

            GH_LinearDimension dm =new GH_LinearDimension(obj2.Object(0).ObjectId);
            if ((dm != null) && (!dm.IsGeometryLoaded)) { dm.LoadGeometry(); }
            return dm;
        }
Пример #3
0
    public static Result DrawMesh(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select sphere");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();

        Sphere sphere;
        gs.Object(0).Surface().TryGetSphere(out sphere);
        if (sphere.IsValid)
        {
          var mesh = Mesh.CreateFromSphere(sphere, 10, 10);
          if (mesh == null)
        return Result.Failure;

          var conduit = new DrawBlueMeshConduit(mesh) {Enabled = true};
          doc.Views.Redraw();

          var in_str = "";
          Rhino.Input.RhinoGet.GetString("press <Enter> to continue", true, ref in_str);

          conduit.Enabled = false;
          doc.Views.Redraw();
          return Result.Success;
        }
        else
          return Result.Failure;
    }
Пример #4
0
    public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc)
    {
        // Get a single planar closed curve
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select curve");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        var objref      = go.Object(0);
        var base_curve  = objref.Curve();
        var first_point = objref.SelectionPoint();

        if (base_curve == null || !first_point.IsValid)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        Rhino.Geometry.Plane plane;
        if (!base_curve.TryGetPlane(out plane))
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Get a point constrained to a line passing through the initial selection
        // point and parallel to the plane's normal
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.SetCommandPrompt("Offset point");
        gp.DrawLineFromPoint(first_point, true);
        var line = new Rhino.Geometry.Line(first_point, first_point + plane.Normal);

        gp.Constrain(line);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }
        var second_point = gp.Point();

        Rhino.Geometry.Vector3d vec = second_point - first_point;
        if (vec.Length > 0.001)
        {
            var  xf = Rhino.Geometry.Transform.Translation(vec);
            Guid id = doc.Objects.Transform(objref, xf, false);
            if (id != Guid.Empty)
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Cancel);
    }
Пример #5
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var go = new Rhino.Input.Custom.GetObject();
      go.SetCommandPrompt("Select edge of surface to extend");
      go.GeometryFilter = ObjectType.EdgeFilter;
      go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve;
      go.Get();
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();
      var obj_ref = go.Object(0);

      var surface = obj_ref.Surface();
      if (surface == null)
      {
        RhinoApp.WriteLine("Unable to extend polysurfaces.");
        return Result.Failure;
      }

      var brep = obj_ref.Brep();
      var face = obj_ref.Face();
      if (brep == null || face == null)
        return Result.Failure;
      if (face.FaceIndex < 0)
        return Result.Failure;

      if( !brep.IsSurface)
      {
        RhinoApp.WriteLine("Unable to extend trimmed surfaces.");
        return Result.Nothing;
      }

      var curve = obj_ref.Curve();

      var trim = obj_ref.Trim();
      if (trim == null)
        return Result.Failure;

      if (trim.TrimType == BrepTrimType.Seam)
      {
        RhinoApp.WriteLine("Unable to extend surface at seam.");
        return Result.Nothing;
      }

      var extended_surface = surface.Extend(trim.IsoStatus, 5.0, true);
      if (extended_surface != null)
      {
        var mybrep = Brep.CreateFromSurface(extended_surface);
        doc.Objects.Replace(obj_ref.ObjectId, mybrep);
        doc.Views.Redraw();
      }
      return Result.Success;
    }
Пример #6
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      m_tolerance = doc.ModelAbsoluteTolerance;
      
      // only use a custom geometry filter if no simpler filter does the job

      // only curves
      var gc = new GetObject();
      gc.SetCommandPrompt("select curve");
      gc.GeometryFilter = ObjectType.Curve;
      gc.DisablePreSelect();
      gc.SubObjectSelect = false;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      if (null == gc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("curve was selected");

      // only closed curves
      var gcc = new GetObject();
      gcc.SetCommandPrompt("select closed curve");
      gcc.GeometryFilter = ObjectType.Curve;
      gcc.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
      gcc.DisablePreSelect();
      gcc.SubObjectSelect = false;
      gcc.Get();
      if (gcc.CommandResult() != Result.Success)
        return gcc.CommandResult();
      if (null == gcc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("closed curve was selected");

      // only circles with a radius of 10
      var gcc10 = new GetObject();
      gcc10.SetCommandPrompt("select circle with radius of 10");
      gc.GeometryFilter = ObjectType.Curve;
      gcc10.SetCustomGeometryFilter(CircleWithRadiusOf10GeometryFilter); // custom geometry filter
      gcc10.DisablePreSelect();
      gcc10.SubObjectSelect = false;
      gcc10.Get();
      if (gcc10.CommandResult() != Result.Success)
        return gcc10.CommandResult();
      if (null == gcc10.Object(0).Curve())
        return Result.Failure;
      RhinoApp.WriteLine("circle with radius of 10 was selected");

      return Result.Success;
    }
    public static Result FilletCurves(RhinoDoc doc)
    {
        var gc1 = new GetObject();
        gc1.DisablePreSelect();
        gc1.SetCommandPrompt("Select first curve to fillet (close to the end you want to fillet)");
        gc1.GeometryFilter = ObjectType.Curve;
        gc1.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc1.Get();
        if (gc1.CommandResult() != Result.Success)
          return gc1.CommandResult();
        var curve1_obj_ref = gc1.Object(0);
        var curve1 = curve1_obj_ref.Curve();
        if (curve1 == null) return Result.Failure;
        var curve1_point_near_end = curve1_obj_ref.SelectionPoint();
        if (curve1_point_near_end == Point3d.Unset)
          return Result.Failure;

        var gc2 = new GetObject();
        gc2.DisablePreSelect();
        gc2.SetCommandPrompt("Select second curve to fillet (close to the end you want to fillet)");
        gc2.GeometryFilter = ObjectType.Curve;
        gc2.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc2.Get();
        if (gc2.CommandResult() != Result.Success)
          return gc2.CommandResult();
        var curve2_obj_ref = gc2.Object(0);
        var curve2 = curve2_obj_ref.Curve();
        if (curve2 == null) return Result.Failure;
        var curve2_point_near_end = curve2_obj_ref.SelectionPoint();
        if (curve2_point_near_end == Point3d.Unset)
          return Result.Failure;

        double radius = 0;
        var rc = RhinoGet.GetNumber("fillet radius", false, ref radius);
        if (rc != Result.Success) return rc;

        var join = false;
        var trim = true;
        var arc_extension = true;
        var fillet_curves = Curve.CreateFilletCurves(curve1, curve1_point_near_end, curve2, curve2_point_near_end, radius,
          join, trim, arc_extension, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees);
        if (fillet_curves == null /*|| fillet_curves.Length != 3*/)
          return Result.Failure;

        foreach(var fillet_curve in fillet_curves)
          doc.Objects.AddCurve(fillet_curve);
        doc.Views.Redraw();
        return rc;
    }
    public static Result ReadDimensionText(RhinoDoc doc)
    {
        var go = new GetObject();
        go.SetCommandPrompt("Select annotation");
        go.GeometryFilter = ObjectType.Annotation;
        go.Get();
        if (go.CommandResult() != Result.Success)
          return Result.Failure;
        var annotation = go.Object(0).Object() as AnnotationObjectBase;
        if (annotation == null)
          return Result.Failure;

        RhinoApp.WriteLine("Annotation text = {0}", annotation.DisplayText);

        return Result.Success;
    }
    public static Result CurveSurfaceIntersect(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select brep");
        gs.GeometryFilter = ObjectType.Brep;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        var brep = gs.Object(0).Brep();

        var gc = new GetObject();
        gc.SetCommandPrompt("select curve");
        gc.GeometryFilter = ObjectType.Curve;
        gc.DisablePreSelect();
        gc.SubObjectSelect = false;
        gc.Get();
        if (gc.CommandResult() != Result.Success)
          return gc.CommandResult();
        var curve = gc.Object(0).Curve();

        if (brep == null || curve == null)
          return Result.Failure;

        var tolerance = doc.ModelAbsoluteTolerance;

        Point3d[] intersection_points;
        Curve[] overlap_curves;
        if (!Intersection.CurveBrep(curve, brep, tolerance, out overlap_curves, out intersection_points))
        {
          RhinoApp.WriteLine("curve brep intersection failed");
          return Result.Nothing;
        }

        foreach (var overlap_curve in overlap_curves)
          doc.Objects.AddCurve(overlap_curve);
        foreach (var intersection_point in intersection_points)
          doc.Objects.AddPoint(intersection_point);

        RhinoApp.WriteLine("{0} overlap curves, and {1} intersection points", overlap_curves.Length, intersection_points.Length);
        doc.Views.Redraw();

        return Result.Success;
    }
    public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc)
    {
        // Get a single planar closed curve
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select curve");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.Get();
        if( go.CommandResult() != Rhino.Commands.Result.Success )
          return go.CommandResult();
        var objref = go.Object(0);
        var base_curve = objref.Curve();
        var first_point = objref.SelectionPoint();
        if( base_curve==null || !first_point.IsValid )
          return Rhino.Commands.Result.Cancel;

        Rhino.Geometry.Plane plane;
        if( !base_curve.TryGetPlane(out plane) )
          return Rhino.Commands.Result.Cancel;

        // Get a point constrained to a line passing through the initial selection
        // point and parallel to the plane's normal
        var gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Offset point");
        gp.DrawLineFromPoint(first_point, true);
        var line = new Rhino.Geometry.Line(first_point, first_point+plane.Normal);
        gp.Constrain(line);
        gp.Get();
        if( gp.CommandResult() != Rhino.Commands.Result.Success )
          return gp.CommandResult();
        var second_point = gp.Point();
        Rhino.Geometry.Vector3d vec = second_point - first_point;
        if( vec.Length > 0.001 )
        {
          var xf = Rhino.Geometry.Transform.Translation(vec);
          Guid id = doc.Objects.Transform(objref, xf, false);
          if( id!=Guid.Empty )
          {
        doc.Views.Redraw();
        return Rhino.Commands.Result.Success;
          }
        }
        return Rhino.Commands.Result.Cancel;
    }
    public static Result FurthestZOnSurfaceGivenXY(RhinoDoc doc)
    {
        #region user input
        // select a surface
        var gs = new GetObject();
        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        // get the brep
        var brep = gs.Object(0).Brep();
        if (brep == null)
          return Result.Failure;

        // get X and Y
        double x = 0.0, y = 0.0;
        var rc = RhinoGet.GetNumber("value of X coordinate", true, ref x);
        if (rc != Result.Success)
          return rc;
        rc = RhinoGet.GetNumber("value of Y coordinate", true, ref y);
        if (rc != Result.Success)
          return rc;
        #endregion

        // an earlier version of this sample used a curve-brep intersection to find Z
        //var maxZ = maxZIntersectionMethod(brep, x, y, doc.ModelAbsoluteTolerance);

        // projecting points is another way to find Z
        var max_z = MaxZProjectionMethod(brep, x, y, doc.ModelAbsoluteTolerance);

        if (max_z != null)
        {
          RhinoApp.WriteLine("Maximum surface Z coordinate at X={0}, Y={1} is {2}", x, y, max_z);
          doc.Objects.AddPoint(new Point3d(x, y, max_z.Value));
          doc.Views.Redraw();
        }
        else
          RhinoApp.WriteLine("no maximum surface Z coordinate at X={0}, Y={1} found.", x, y);

        return Result.Success;
    }
Пример #13
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;

        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase           geom  = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Пример #14
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();
        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to flow", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
          return rc;

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
          return go0.CommandResult();

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
          return go1.CommandResult();

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
          doc.Objects.Add(geom);
          doc.Views.Redraw();
        }

        return Rhino.Commands.Result.Success;
    }
Пример #15
0
    public static Result ExtendCurve(RhinoDoc doc)
    {
        ObjRef[] boundary_obj_refs;
        var rc = RhinoGet.GetMultipleObjects("Select boundary objects", false, ObjectType.AnyObject, out boundary_obj_refs);
        if (rc != Result.Success)
          return rc;
        if (boundary_obj_refs == null || boundary_obj_refs.Length == 0)
          return Result.Nothing;

        var gc = new GetObject();
        gc.SetCommandPrompt("Select curve to extend");
        gc.GeometryFilter = ObjectType.Curve;
        gc.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc.DisablePreSelect ();
        gc.Get();
        if (gc.CommandResult() != Result.Success)
          return gc.CommandResult();
        var curve_obj_ref = gc.Object(0);

        var curve = curve_obj_ref.Curve();
        if (curve == null) return Result.Failure;
        double t;
        if (!curve.ClosestPoint(curve_obj_ref.SelectionPoint(), out t))
          return Result.Failure;
        var curve_end = t <= curve.Domain.Mid ? CurveEnd.Start : CurveEnd.End;

        var geometry = boundary_obj_refs.Select(obj=> obj.Geometry());
        var extended_curve = curve.Extend(curve_end, CurveExtensionStyle.Line, geometry);
        if (extended_curve != null && extended_curve.IsValid)
        {
          if (!doc.Objects.Replace(curve_obj_ref.ObjectId, extended_curve))
        return Result.Failure;
          doc.Views.Redraw();
        }
        else
        {
          RhinoApp.WriteLine("No boundary object was intersected so curve not extended");
          return Result.Nothing;
        }

        return Result.Success;
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gm = new GetObject();
      gm.SetCommandPrompt("Select open mesh");
      gm.GeometryFilter = ObjectType.Mesh;
      gm.GeometryAttributeFilter = GeometryAttributeFilter.OpenMesh;
      gm.Get();
      if (gm.CommandResult() != Result.Success)
        return gm.CommandResult();
      var mesh = gm.Object(0).Mesh();
      if (mesh == null)
        return Result.Failure;

      var polylines = mesh.GetNakedEdges();
      foreach (var polyline in polylines)
      {
        doc.Objects.AddPolyline(polyline);
      }

      return Result.Success;
    }
Пример #17
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // select a surface
      var gs = new GetObject();
      gs.SetCommandPrompt("select surface");
      gs.GeometryFilter = ObjectType.Surface;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      // get the selected face
      var face = gs.Object(0).Face();
      if (face == null)
        return Result.Failure;

      // pick a point on the surface.  Constain
      // picking to the face.
      var gp = new GetPoint();
      gp.SetCommandPrompt("select point on surface");
      gp.Constrain(face, false);
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();

      // get the parameters of the point on the
      // surface that is clesest to gp.Point()
      double u, v;
      if (face.ClosestPoint(gp.Point(), out u, out v))
      {
        var direction = face.NormalAt(u, v);
        if (face.OrientationIsReversed)
          direction.Reverse();
        RhinoApp.WriteLine(
          string.Format(
            "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", 
            u, v, direction.X, direction.Y, direction.Z));
      }
      return Result.Success;
    }
Пример #18
0
  public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc)
  {
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select closed planar curve");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.SubObjectSelect = false;
    go.Get();
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    var curve = go.Object(0).Curve();
    if( curve==null || !curve.IsClosed || !curve.IsPlanar() )
      return Rhino.Commands.Result.Failure;

    string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name;
    var rc = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name);
    if( rc!= Rhino.Commands.Result.Success )
      return rc;
    hatch_name = hatch_name.Trim();
    if( string.IsNullOrWhiteSpace(hatch_name) )
      return Rhino.Commands.Result.Nothing;
    int index = doc.HatchPatterns.Find(hatch_name, true);
    if( index < 0 )
    {
      Rhino.RhinoApp.WriteLine("Hatch pattern does not exist.");
      return Rhino.Commands.Result.Nothing;
    }

    var hatches = Rhino.Geometry.Hatch.Create( curve, index, 0, 1);
    for( int i=0; i<hatches.Length; i++ )
      doc.Objects.AddHatch(hatches[i]);
    if( hatches.Length>0 )
      doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
Пример #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double       tolerance = doc.ModelAbsoluteTolerance;
            List <Curve> curves    = new List <Curve>();

            //Select surface

            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref_Surface = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj            = objref_Surface.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref_Surface.Surface();

            if (surface == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);

            //Select Line(s)
            GetObject gl = new GetObject();

            gl.SetCommandPrompt("Select one or two line(s)");
            gl.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gl.DeselectAllBeforePostSelect = true;
            gl.OneByOnePostSelect          = true;
            gl.GetMultiple(1, 0);

            for (int i = 0; i < gl.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref_Line = gl.Object(i);
                curve = objref_Line.Curve();

                Curve curveRe = curve.Rebuild(60, 3, true);
                curves.Add(curveRe);
            }

            List <Guid> cir_guid_list = new List <Guid>();

            if (curves.Count > 1)
            {
                Curve curve2 = curves[0];
                Curve curve3 = curves[1];
                if (curve2.IsClosed || curve3.IsClosed)
                {
                    Rhino.UI.Dialogs.ShowMessage("Please only select open curves for two line pave.", "Warning!");
                    return(Result.Failure);
                }

                while (true)
                {
                    cir_guid_list = new List <Guid>();



                    var   tweenCurves = Curve.CreateTweenCurvesWithSampling(curve2, curve3, 1, 30, tolerance);
                    Curve tCurve      = tweenCurves[0];

                    //3 point circle
                    Point3d   po1   = curve2.PointAtStart;
                    Point3d   po2   = curve3.PointAtStart;
                    LineCurve line1 = new LineCurve(po1, po2);
                    double[]  param = line1.DivideByCount(2, false);

                    double param1 = param[0];
                    double param2 = param[0];
                    double param3 = param[0];

                    Curve curve1 = line1;



                    while (true)
                    {
                        Circle outCircle = Circle.TryFitCircleTTT(curve1, curve2, curve3, param1, param2, param3);


                        //circle normal to surface

                        Point3d outCircleCenter = outCircle.Center;
                        double  outCircleRadius = outCircle.Radius;
                        double  u, v;
                        surface.ClosestPoint(outCircleCenter, out u, out v);
                        var     direction  = surface.NormalAt(u, v);
                        Point3d surfCenter = surface.PointAt(u, v);
                        Plane   pl1        = new Plane(surfCenter, direction);
                        Circle  circle     = new Circle(pl1, surfCenter, outCircleRadius - offSetStone);
                        Circle  circleDist = new Circle(pl1, surfCenter, outCircleRadius + stoneDist);
                        Guid    cir_guid   = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);


                        //Cut tween curve at latest circle center
                        Point3d pointOnCurve;
                        Point3d pointOnCircle;
                        Curve   circleDistCurve = circleDist.ToNurbsCurve();
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        Curve[] splitCurves = tCurve.Split(outCircleRadius);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];
                        tCurve.ClosestPoints(circleDistCurve, out pointOnCurve, out pointOnCircle);

                        //Cut tween curve at latest circle border
                        double curveSplitParam;
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        tCurve.ClosestPoint(pointOnCurve, out curveSplitParam);
                        splitCurves = tCurve.Split(curveSplitParam);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];

                        //New parameter at curve1
                        double circleParam;
                        circleDistCurve.ClosestPoint(pointOnCircle, out circleParam);
                        param1 = circleParam;
                        curve1 = circleDistCurve;

                        //New parameter at curves[0]
                        double paramCurve0New;
                        curve2.ClosestPoint(pointOnCircle, out paramCurve0New);
                        Point3d pointCurve0New = curve2.PointAt(paramCurve0New);
                        double  distNewPoints0 = pointOnCircle.DistanceTo(pointCurve0New);
                        param2 = paramCurve0New + distNewPoints0;

                        //New parameter at curves[1]
                        double paramCurve1New;
                        curve3.ClosestPoint(pointOnCircle, out paramCurve1New);
                        Point3d pointCurve1New = curve3.PointAt(paramCurve1New);
                        double  distNewPoints1 = pointOnCircle.DistanceTo(pointCurve1New);
                        param3 = paramCurve1New + distNewPoints1;
                    }

                    doc.Views.Redraw();


                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");


                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var distStone  = new Rhino.Input.Custom.OptionDouble(stoneDist);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");


                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionDouble("Distance", ref distStone);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }



                    offSetStone = stoneOff.CurrentValue;
                    stoneDist   = distStone.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve2.Reverse();
                        curve2 = curve2.Rebuild(60, 3, false);
                        curve3.Reverse();
                        curve3     = curve3.Rebuild(60, 3, false);
                        optionBool = false;
                    }
                }
            }

            else
            {
                while (true)
                {
                    cir_guid_list = new List <Guid>();
                    List <Point3d> points = new List <Point3d>();


                    double length     = (diamStone / 2) + offSetStone;
                    double crv_length = curve.GetLength();

                    Point3d point = curve.PointAtLength(length);
                    points.Add(point);

                    while (true)
                    {
                        length += diamStone + offSetStone;
                        if (length > crv_length)
                        {
                            break;
                        }
                        point = curve.PointAtLength(length);
                        points.Add(point);
                    }

                    foreach (var poi in points)
                    {
                        double u, v;
                        surface.ClosestPoint(poi, out u, out v);
                        var      direction = surface.NormalAt(u, v);
                        double   x         = direction.X;
                        double   y         = direction.Y;
                        double   z         = direction.Z;
                        Vector3d vt1       = new Vector3d(x, y, z);
                        Plane    pl1       = new Plane(poi, vt1);
                        Circle   circle    = new Circle(pl1, poi, diamStone / 2);
                        Guid     cir_guid  = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);
                    }

                    doc.Views.Redraw();

                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");

                    var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                    go.AddOptionDouble("StoneDiam", ref stoneDiam);
                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }


                    diamStone   = stoneDiam.CurrentValue;
                    offSetStone = stoneOff.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve.Reverse();
                    }
                }
            }


            doc.Views.Redraw();

            doc.Groups.Add(cir_guid_list);

            return(Result.Success);
        }
Пример #20
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select edge of surface to extend");
            go.GeometryFilter          = ObjectType.EdgeFilter;
            go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }
            var obj_ref = go.Object(0);

            var surface = obj_ref.Surface();

            if (surface == null)
            {
                RhinoApp.WriteLine("Unable to extend polysurfaces.");
                return(Result.Failure);
            }

            var brep = obj_ref.Brep();
            var face = obj_ref.Face();

            if (brep == null || face == null)
            {
                return(Result.Failure);
            }
            if (face.FaceIndex < 0)
            {
                return(Result.Failure);
            }

            if (!brep.IsSurface)
            {
                RhinoApp.WriteLine("Unable to extend trimmed surfaces.");
                return(Result.Nothing);
            }

            var curve = obj_ref.Curve();

            var trim = obj_ref.Trim();

            if (trim == null)
            {
                return(Result.Failure);
            }

            if (trim.TrimType == BrepTrimType.Seam)
            {
                RhinoApp.WriteLine("Unable to extend surface at seam.");
                return(Result.Nothing);
            }

            var extended_surface = surface.Extend(trim.IsoStatus, 5.0, true);

            if (extended_surface != null)
            {
                var mybrep = Brep.CreateFromSurface(extended_surface);
                doc.Objects.Replace(obj_ref.ObjectId, mybrep);
                doc.Views.Redraw();
            }
            return(Result.Success);
        }
Пример #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //pick surface to orient to or block instance to relocate
            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient new object on or BlockInstance to move");
            gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.InstanceReference;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = false;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref.Surface();


            //relocate block instance
            if (surface == null)
            {
                Rhino.DocObjects.InstanceObject instance1 = objref.Object() as Rhino.DocObjects.InstanceObject;

                instancePoint = instance1.InsertionPoint;
                double g, h;
                surface2.ClosestPoint(instancePoint, out g, out h);
                var instanceDirection = surface2.NormalAt(g, h);
                instancePlane = new Plane(instancePoint, instanceDirection);

                Rhino.Input.Custom.GetPoint gpss = new Rhino.Input.Custom.GetPoint();
                gpss.SetCommandPrompt("Point on surface to orient to");
                gpss.Constrain(surface2, false);

                gpss.DynamicDraw += RefObjDraw;
                gpss.Tag          = instance1;

                gpss.Get();
                if (gpss.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gpss.CommandResult());
                }
                Point3d ptss = gpss.Point();
                surface2.ClosestPoint(ptss, out g, out h);
                var       direction1 = surface2.NormalAt(g, h);
                Plane     pl11       = new Plane(ptss, direction1);
                Transform iform      = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, pl11);
                doc.Objects.Transform(instance1, iform, true);

                return(Result.Success);
            }

            obj.Select(false);

            //pick objekt to orient
            var copy = new Rhino.Input.Custom.OptionToggle(false, "No", "Yes");

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select object to orient.");
            go.AddOptionToggle("Copy", ref copy);
            go.SubObjectSelect             = true;
            go.DeselectAllBeforePostSelect = false;
            go.GroupSelect = true;

            for (; ;)
            {
                var res = go.GetMultiple(1, -1);
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }
                if (res == GetResult.Option)
                {
                    copyBol = copy.CurrentValue;
                    continue;
                }
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }

                break;
            }



            int    obCount      = go.ObjectCount;
            string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");

            //create block instance and plane for instance
            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("Point to orient from");
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gp.CommandResult());
            }

            Vector3d vt1 = new Vector3d(0, 0, 1);
            Point3d  pt1 = gp.Point();

            sourcePlane = new Plane(pt1, vt1);
            Plane     originPlane = new Plane(Point3d.Origin, vt1);
            Transform bform       = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane);

            //block instance
            GeometryBase[] obj1List = new GeometryBase[obCount];
            List <Brep>    opList   = new List <Brep>();

            for (int igo = 0; igo < obCount; igo++)
            {
                Rhino.DocObjects.ObjRef      objref1 = go.Object(igo);
                Rhino.DocObjects.RhinoObject obj1    = objref1.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);


                Rhino.Geometry.Brep opItem = objref1.Brep();
                opList.Add(opItem);

                GeometryBase obj1Base = obj1.Geometry;
                obj1Base.Transform(bform);

                obj1List[igo] = obj1Base;
            }

            var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List);

            //get all go.Objects to .Tag
            Brep[] op = new Brep[obCount];
            op = Brep.CreateBooleanUnion(opList, 0.01);
            Brep od = new Brep();

            od = op[0];
            var odGuid = doc.Objects.AddBrep(od);

            Rhino.DocObjects.ObjRef      objref2 = new Rhino.DocObjects.ObjRef(odGuid);
            Rhino.DocObjects.RhinoObject objDrw  = objref2.Object();

            //orient plane to surface
            if (copyBol)
            {
                while (true)
                {
                    Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint();
                    gps.SetCommandPrompt("Point on surface to orient to. Press enter when done.");
                    gps.Constrain(surface, false);
                    gps.AcceptNothing(true);
                    gps.DynamicDraw += RefObjDraw;
                    gps.Tag          = objDrw;

                    var res = gps.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    //else if (gps.CommandResult() != Rhino.Commands.Result.Success)
                    //    return gps.CommandResult();


                    Point3d pts = gps.Point();
                    double  u, v;
                    surface.ClosestPoint(pts, out u, out v);
                    Vector3d direction = surface.NormalAt(u, v);
                    Plane    pl1       = new Plane(pts, direction);

                    Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1);

                    doc.Objects.AddInstanceObject(orientBlock, xform);

                    doc.Objects.Delete(objDrw);
                }
                copyBol = false;
            }
            else
            {
                Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint();
                gps.SetCommandPrompt("Point on surface to orient to");
                gps.Constrain(surface, false);

                gps.DynamicDraw += RefObjDraw;
                gps.Tag          = objDrw;

                gps.Get();
                if (gps.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gps.CommandResult());
                }
                Point3d pts = gps.Point();
                double  u, v;
                surface.ClosestPoint(pts, out u, out v);
                Vector3d direction = surface.NormalAt(u, v);
                Plane    pl1       = new Plane(pts, direction);

                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1);

                doc.Objects.AddInstanceObject(orientBlock, xform);

                doc.Objects.Delete(objDrw);
            }

            surface2 = surface;

            return(Result.Success);
        }
Пример #22
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();
        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
          return rc;

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
          return go.CommandResult();

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;
        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u,v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
          doc.Objects.Add(geom);
          doc.Views.Redraw();
        }

        return Rhino.Commands.Result.Success;
    }
Пример #23
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // --- Set tolerance

            _unit = doc.ModelAbsoluteTolerance;


            // --- Get Mesh

            var getMesh = new GetObject { GeometryFilter = ObjectType.Mesh };
            getMesh.SetCommandPrompt("Select mesh");

            while (true)
            {
                var getMeshResult = getMesh.Get();

                if (getMesh.CommandResult() != Result.Success)
                    return getMesh.CommandResult();

                if (getMeshResult == GetResult.Object)
                    break;
            }

            _mesh = (Mesh)getMesh.Object(0).Geometry();

            doc.Objects.UnselectAll();


            // --- Start preview
            
            DisplayPipeline.DrawOverlay += DisplayPipelineOnDrawOverlay;


            // --- Get options

            var getOptions = new GetOption();
            getOptions.SetCommandPrompt("Settings:");
            getOptions.AddOptionInteger("CountX", ref _countX);
            getOptions.AddOptionInteger("CountY", ref _countY);
            getOptions.AddOptionDouble("Thickness", ref _thickness);
            getOptions.AddOption("Plane");
            getOptions.AddOptionDouble("Deeper", ref _deeper);
            getOptions.AddOptionToggle("DeleteInput", ref _deleteSource);
            getOptions.AddOptionToggle("Project", ref _project);
            getOptions.AddOptionDouble("ProjectSpace", ref _projectSpace);
            getOptions.AcceptNothing(true);

            do
            {
                doc.Views.Redraw();

                getOptions.Get();

                switch (getOptions.Result())
                {
                    case GetResult.Option:
                        switch (getOptions.Option().EnglishName)
                        {
                            case "Plane":
                                _plane = PlaneGetter.GetPlane() ?? _plane;
                                break;
                        }
                        break;
                }
            } while (getOptions.CommandResult() == Result.Success && getOptions.Result() != GetResult.Nothing);


            // --- Stop preview

            DisplayPipeline.DrawOverlay -= DisplayPipelineOnDrawOverlay;


            // --- Check for cancel with ESC

            if (getOptions.Result() == GetResult.Cancel)
                return Result.Cancel;


            // --- Execute

            var result = Waffle.Create(_mesh, _plane, _thickness.CurrentValue, _deeper.CurrentValue, _countX.CurrentValue, _countY.CurrentValue, _unit, _project.CurrentValue, _projectSpace.CurrentValue);


            // --- Add objects

            foreach (var curves in result.CurvesX)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));

            foreach (var curves in result.CurvesY)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));


            // --- Delete input

            if (_deleteSource.CurrentValue)
                doc.Objects.Delete(getMesh.Object(0).ObjectId, true);


            // --- Update views

            doc.Views.Redraw();


            return Result.Success;
        }
Пример #24
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Mesh        meshSurf;
            List <Guid> ids       = new List <Guid>();
            double      tolerance = doc.ModelAbsoluteTolerance;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;

            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = geometryFilter;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }

            brepSurf = objref.Brep();
            if (brepSurf == null)
            {
                meshSurf = objref.Mesh();
                brepSurf = Brep.CreateFromMesh(meshSurf, true);
            }
            if (brepSurf == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);


            while (true)
            {
                w_key_pressed = false;
                s_key_pressed = false;
                a_key_pressed = false;
                d_key_pressed = false;

                m_escape_key_pressed = false;

                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
                RhinoApp.KeyboardEvent    += OnRhinoKeyboardEvent;

                Point3d  pt0;
                GetPoint getPointAction = new GetPoint();
                getPointAction.SetCommandPrompt("Please select insert point(s) on surface.");
                getPointAction.Constrain(brepSurf, -1, -1, false);

                var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");
                var moveOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                getPointAction.AddOptionDouble("StoneDiam", ref stoneDiam);
                getPointAction.AddOptionDouble("Offset", ref stoneOff);
                getPointAction.AddOptionToggle("Delete", ref boolOption);
                getPointAction.AddOptionToggle("Move", ref moveOption);
                getPointAction.DynamicDraw += RefCircleDraw;
                getPointAction.Tag          = obj;
                getPointAction.AcceptString(false);
                getPointAction.AcceptNothing(true);
                var res = getPointAction.Get();


                if (w_key_pressed || s_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    w_key_pressed           = false;
                    s_key_pressed           = false;
                    stoneDiam.CurrentValue  = diamStone;
                }
                if (a_key_pressed || d_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    a_key_pressed           = false;
                    d_key_pressed           = false;
                    stoneOff.CurrentValue   = offSetStone;
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }
                if (m_escape_key_pressed)
                {
                    break;
                }

                diamStone   = stoneDiam.CurrentValue;
                offSetStone = stoneOff.CurrentValue;
                optionBool  = boolOption.CurrentValue;
                moveBool    = moveOption.CurrentValue;

                RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;

                if (moveBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to move. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();

                        getPointAction.Get();
                        pt0 = getPointAction.Point();
                        Point3d        closestPoint;
                        ComponentIndex compIndex;
                        double         u, v;
                        Vector3d       vt1;

                        brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                        Plane  pl1  = new Plane(pt0, vt1);
                        Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                        var    crgu = doc.Objects.AddCircle(cr1);
                        ids.Add(crgu);
                        doc.Views.Redraw();
                    }
                    moveBool = false;
                }
                if (optionBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to delete. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();
                    }
                    optionBool = false;
                }

                if (res == GetResult.Point)
                {
                    pt0 = getPointAction.Point();
                    Point3d        closestPoint;
                    ComponentIndex compIndex;
                    double         u, v;
                    Vector3d       vt1;
                    brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                    Plane  pl1  = new Plane(pt0, vt1);
                    Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                    var    crgu = doc.Objects.AddCircle(cr1);
                    ids.Add(crgu);
                    doc.Views.Redraw();
                }
            }
            RhinoApp.KeyboardEvent    -= OnRhinoKeyboardEvent;
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
            doc.Groups.Add(ids);
            return(Result.Success);
        }
Пример #25
0
  public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
  {
    // Select objects to orient
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects to orient");
    go.SubObjectSelect = false;
    go.GroupSelect = true;
    go.GetMultiple(1, 0);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Point to orient from
    Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
    gp.SetCommandPrompt("Point to orient from");
    gp.Get();
    if (gp.CommandResult() != Rhino.Commands.Result.Success)
      return gp.CommandResult();

    // Define source plane
    Rhino.Display.RhinoView view = gp.View();
    if (view == null)
    {
      view = doc.Views.ActiveView;
      if (view == null)
        return Rhino.Commands.Result.Failure;
    }
    Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
    source_plane.Origin = gp.Point();

    // Surface to orient on
    Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
    gs.SetCommandPrompt("Surface to orient on");
    gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
    gs.SubObjectSelect = true;
    gs.DeselectAllBeforePostSelect = false;
    gs.OneByOnePostSelect = true;
    gs.Get();
    if (gs.CommandResult() != Rhino.Commands.Result.Success)
      return gs.CommandResult();

    Rhino.DocObjects.ObjRef objref = gs.Object(0);
    // get selected surface object
    Rhino.DocObjects.RhinoObject obj = objref.Object();
    if (obj == null)
      return Rhino.Commands.Result.Failure;
    // get selected surface (face)
    Rhino.Geometry.Surface surface = objref.Surface();
    if (surface == null)
      return Rhino.Commands.Result.Failure;
    // Unselect surface
    obj.Select(false);

    // Point on surface to orient to
    gp.SetCommandPrompt("Point on surface to orient to");
    gp.Constrain(surface, false);
    gp.Get();
    if (gp.CommandResult() != Rhino.Commands.Result.Success)
      return gp.CommandResult();

    // Do transformation
    Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
    double u, v;
    if (surface.ClosestPoint(gp.Point(), out u, out v))
    {
      Rhino.Geometry.Plane target_plane;
      if (surface.FrameAt(u, v, out target_plane))
      {
        // Build transformation
        Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

        // Do the transformation. In this example, we will copy the original objects
        bool delete_original = false;
        for (int i = 0; i < go.ObjectCount; i++)
          doc.Objects.Transform(go.Object(i), xform, delete_original);

        doc.Views.Redraw();
        rc = Rhino.Commands.Result.Success;
      }
    }
    return rc;
  }