Ejemplo n.º 1
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // this creates a point where the mouse is clicked.
      var gp = new GetPoint();
      gp.SetCommandPrompt("Click for new point");
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
      var point3d = gp.Point();
      doc.Objects.AddPoint(point3d);
      doc.Views.Redraw();

      // selects a point that already exists
      ObjRef obj_ref;
      var rc = RhinoGet.GetOneObject("Select point", false, ObjectType.Point, out obj_ref);
      if (rc != Result.Success)
        return rc;
      var point = obj_ref.Point();
      RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", 
        point.Location.X,
        point.Location.Y,
        point.Location.Z);
      doc.Objects.UnselectAll();

      // selects multiple points that already exist
      ObjRef[] obj_refs;
      rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs);
      if (rc != Result.Success)
        return rc;
      foreach (var o_ref in obj_refs)
      {
        point = o_ref.Point();
        RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}",
          point.Location.X,
          point.Location.Y,
          point.Location.Z);
      }
      doc.Objects.UnselectAll();

      // also selects a point that already exists.
      // Used when RhinoGet doesn't provide enough control
      var go = new GetObject();
      go.SetCommandPrompt("Select point");
      go.GeometryFilter = ObjectType.Point;
      go.GetMultiple(1, 0);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();
      foreach (var o_ref in  go.Objects()) 
      {
        point = o_ref.Point();
        if (point != null)
          RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", 
            point.Location.X,
            point.Location.Y,
            point.Location.Z);
      }

      doc.Views.Redraw();
      return Result.Success;
    }
Ejemplo n.º 2
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gm = new GetObject();
      gm.SetCommandPrompt("Select solid meshes for volume calculation");
      gm.GeometryFilter = ObjectType.Mesh;
      gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh;
      gm.SubObjectSelect = false;
      gm.GroupSelect = true;
      gm.GetMultiple(1, 0);
      if (gm.CommandResult() != Result.Success)
        return gm.CommandResult();

      double volume = 0.0;
      double volume_error = 0.0;
      foreach (var obj_ref in gm.Objects())
      {
        if (obj_ref.Mesh() != null)
        {
          var mass_properties = VolumeMassProperties.Compute(obj_ref.Mesh());
          if (mass_properties != null)
          {
            volume += mass_properties.Volume;
            volume_error += mass_properties.VolumeError;
          }
        }
      }

      RhinoApp.WriteLine("Total volume = {0:f} (+/- {1:f})", volume, volume_error);
      return Result.Success;
    }
Ejemplo n.º 3
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      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;
    }
Ejemplo n.º 4
0
    public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.Geometry.Curve curve0 = go.Object(0).Curve();
        Rhino.Geometry.Curve curve1 = go.Object(1).Curve();
        if (null != curve0 && null != curve1)
        {
            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1);
            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }

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

        return(Rhino.Commands.Result.Failure);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      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;
    }
Ejemplo n.º 6
0
  public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.GetMultiple(1, 0);
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
    if( objrefs==null )
      return Rhino.Commands.Result.Nothing;

    double tolerance = doc.ModelAbsoluteTolerance;
    for( int i=0; i<objrefs.Length; i++ )
    {
      // get the curve geometry
      Rhino.Geometry.Curve curve = objrefs[i].Curve();
      if( curve==null )
        continue;
      Rhino.Geometry.Circle circle;
      if( curve.TryGetCircle(out circle, tolerance) )
      {
        Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center);
      }
    }
    return Rhino.Commands.Result.Success;
  }
  public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select two curves");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple(2, 2);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    Rhino.DocObjects.ObjRef objRef0 = go.Object(0);
    Rhino.DocObjects.ObjRef objRef1 = go.Object(1);

    double t0 = Rhino.RhinoMath.UnsetValue;
    double t1 = Rhino.RhinoMath.UnsetValue;
    Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0);
    Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1);
    if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) ||
        null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1) )
      return Rhino.Commands.Result.Failure;

    Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset;
    bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line);
    if (rc)
    {
      if (Guid.Empty != doc.Objects.AddLine(line))
      {
        doc.Views.Redraw();
        return Rhino.Commands.Result.Success;
      }
    }
    return Rhino.Commands.Result.Failure;
  }
Ejemplo n.º 8
0
    public static Result PrePostPick(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects");
        go.EnablePreSelect(true, true);
        go.EnablePostSelect(true);
        go.GetMultiple(0, 0);
        if (go.CommandResult() != Result.Success)
          return go.CommandResult();

        var selected_objects = go.Objects().ToList();

        if (go.ObjectsWerePreselected)
        {
          go.EnablePreSelect(false, true);
          go.DeselectAllBeforePostSelect = false;
          go.EnableUnselectObjectsOnExit(false);
          go.GetMultiple(0, 0);
          if (go.CommandResult() == Result.Success)
          {
        foreach (var obj in go.Objects())
        {
          selected_objects.Add(obj);
          // The normal behavior of commands is that when they finish,
          // objects that were pre-selected remain selected and objects
          // that were post-selected will not be selected. Because we
          // potentially could have both, we'll try to do something
          // consistent and make sure post-selected objects also stay selected
          obj.Object().Select(true);
        }
          }
        }
        return selected_objects.Count > 0 ? Result.Success : Result.Nothing;
    }
Ejemplo n.º 9
0
    public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to group");
        go.GroupSelect = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

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

        for (int i = 0; i < go.ObjectCount; i++)
        {
            ids.Add(go.Object(i).ObjectId);
        }
        int index = doc.Groups.Add(ids);

        doc.Views.Redraw();
        if (index >= 0)
        {
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
Ejemplo n.º 10
0
    public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
          return go.CommandResult();

        Rhino.Geometry.Curve curve0 = go.Object(0).Curve();
        Rhino.Geometry.Curve curve1 = go.Object(1).Curve();
        if (null != curve0 && null != curve1)
        {
          Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1);
          if (null != curves)
          {
        for (int i = 0; i < curves.Length; i++)
          doc.Objects.AddCurve(curves[i]);

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

        return Rhino.Commands.Result.Failure;
    }
Ejemplo n.º 11
0
    public static Result CopyGroups(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to copy in place");
        go.GroupSelect = true;
        go.SubObjectSelect = false;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Result.Success)
          return go.CommandResult();

        var xform = Transform.Identity;
        var group_map = new Dictionary<int, int>();

        foreach (var obj_ref in go.Objects())
        {
          if (obj_ref != null)
          {
        var obj = obj_ref.Object();
        var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false);
        RhinoUpdateObjectGroups(ref obj, ref group_map);
          }
        }
        doc.Views.Redraw();
        return Result.Success;
    }
Ejemplo n.º 12
0
    public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef rail_ref;
        var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        var rail_crv = rail_ref.Curve();

        if (rail_crv == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var gx = new Rhino.Input.Custom.GetObject();

        gx.SetCommandPrompt("Select cross section curves");
        gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        gx.EnablePreSelect(false, true);
        gx.GetMultiple(1, 0);
        if (gx.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gx.CommandResult());
        }

        var cross_sections = new List <Rhino.Geometry.Curve>();

        for (int i = 0; i < gx.ObjectCount; i++)
        {
            var crv = gx.Object(i).Curve();
            if (crv != null)
            {
                cross_sections.Add(crv);
            }
        }
        if (cross_sections.Count < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var sweep = new Rhino.Geometry.SweepOneRail();

        sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
        sweep.ClosedSweep           = false;
        sweep.SweepTolerance        = doc.ModelAbsoluteTolerance;
        sweep.SetToRoadlikeTop();
        var breps = sweep.PerformSweep(rail_crv, cross_sections);

        for (int i = 0; i < breps.Length; i++)
        {
            doc.Objects.AddBrep(breps[i]);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 13
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);
    }
Ejemplo n.º 14
0
    public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select lines");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        if (go.ObjectCount != 2)
        {
            return(Rhino.Commands.Result.Failure);
        }

        LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
        LineCurve crv1 = go.Object(1).Geometry() as LineCurve;

        if (crv0 == null || crv1 == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Line     line0 = crv0.Line;
        Line     line1 = crv1.Line;
        Vector3d v0    = line0.Direction;

        v0.Unitize();
        Vector3d v1 = line1.Direction;

        v1.Unitize();

        if (v0.IsParallelTo(v1) != 0)
        {
            Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
            return(Rhino.Commands.Result.Nothing);
        }

        double a, b;

        if (!Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
        {
            Rhino.RhinoApp.WriteLine("No intersection found.");
            return(Rhino.Commands.Result.Nothing);
        }

        Point3d pt0 = line0.PointAt(a);
        Point3d pt1 = line1.PointAt(b);

        // pt0 and pt1 should be equal, so we will only add pt0 to the document
        doc.Objects.AddPoint(pt0);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 15
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;
    }
Ejemplo n.º 16
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;
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      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;
    }
Ejemplo n.º 20
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);
    }
Ejemplo n.º 21
0
  public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt( "Select lines" );
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple( 2, 2);
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();
    if( go.ObjectCount != 2 )
      return Rhino.Commands.Result.Failure;

    LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
    LineCurve crv1 = go.Object(1).Geometry() as LineCurve;
    if( crv0==null || crv1==null )
      return Rhino.Commands.Result.Failure;

    Line line0 = crv0.Line;
    Line line1 = crv1.Line;
    Vector3d v0 = line0.Direction;
    v0.Unitize();
    Vector3d v1 = line1.Direction;
    v1.Unitize();

    if( v0.IsParallelTo(v1) != 0 )
    {
      Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
      return Rhino.Commands.Result.Nothing;
    }

    double a, b;
    if( !Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
    {
      Rhino.RhinoApp.WriteLine("No intersection found.");
      return Rhino.Commands.Result.Nothing;
    }

    Point3d pt0 = line0.PointAt(a);
    Point3d pt1 = line1.PointAt(b);
    // pt0 and pt1 should be equal, so we will only add pt0 to the document
    doc.Objects.AddPoint( pt0 );
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
Ejemplo n.º 22
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;
    }
    public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to group");
        go.GroupSelect = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
          return go.CommandResult();

        List<Guid> ids = new List<Guid>();
        for (int i = 0; i < go.ObjectCount; i++)
        {
          ids.Add(go.Object(i).ObjectId);
        }
        int index = doc.Groups.Add(ids);
        doc.Views.Redraw();
        if (index >= 0)
          return Rhino.Commands.Result.Success;
        return Rhino.Commands.Result.Failure;
    }
Ejemplo n.º 24
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      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.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;
    }
Ejemplo n.º 25
0
    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;
    }
Ejemplo n.º 26
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // select curves to loft
      var gs = new GetObject();
      gs.SetCommandPrompt("select curves to loft");
      gs.GeometryFilter = ObjectType.Curve;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.GetMultiple(2, 0);
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();

      var curves = gs.Objects().Select(obj => obj.Curve()).ToList();

      var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false);
      foreach (var brep in breps)
        doc.Objects.AddBrep(brep);

      doc.Views.Redraw();
      return Result.Success;
    }
Ejemplo n.º 27
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;
    }
Ejemplo n.º 28
0
  public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc)
  {
    Rhino.DocObjects.ObjRef rail_ref;
    var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref);
    if(rc!=Rhino.Commands.Result.Success)
      return rc;

    var rail_crv = rail_ref.Curve();
    if( rail_crv==null )
      return Rhino.Commands.Result.Failure;

    var gx = new Rhino.Input.Custom.GetObject();
    gx.SetCommandPrompt("Select cross section curves");
    gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    gx.EnablePreSelect(false, true);
    gx.GetMultiple(1,0);
    if( gx.CommandResult() != Rhino.Commands.Result.Success )
      return gx.CommandResult();
    
    var cross_sections = new List<Rhino.Geometry.Curve>();
    for( int i=0; i<gx.ObjectCount; i++ )
    {
      var crv = gx.Object(i).Curve();
      if( crv!= null)
        cross_sections.Add(crv);
    }
    if( cross_sections.Count<1 )
      return Rhino.Commands.Result.Failure;

    var sweep = new Rhino.Geometry.SweepOneRail();
    sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
    sweep.ClosedSweep = false;
    sweep.SweepTolerance = doc.ModelAbsoluteTolerance;
    sweep.SetToRoadlikeTop();
    var breps = sweep.PerformSweep(rail_crv, cross_sections);
    for( int i=0; i<breps.Length; i++ )
      doc.Objects.AddBrep(breps[i]);
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
Ejemplo n.º 29
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var go = new GetObject();
      go.SetCommandPrompt("Select 2, 3, or 4 open curves");
      go.GeometryFilter = ObjectType.Curve;
      go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
      go.GetMultiple(2, 4);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();

      var curves = go.Objects().Select(o => o.Curve());

      var brep = Brep.CreateEdgeSurface(curves);

      if (brep != null)
      {
        doc.Objects.AddBrep(brep);
        doc.Views.Redraw();
      }

      return Result.Success;
    }
    public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef objRef0 = go.Object(0);
        Rhino.DocObjects.ObjRef objRef1 = go.Object(1);

        double t0 = Rhino.RhinoMath.UnsetValue;
        double t1 = Rhino.RhinoMath.UnsetValue;

        Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0);
        Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1);
        if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) ||
            null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1))
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset;
        bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line);

        if (rc)
        {
            if (Guid.Empty != doc.Objects.AddLine(line))
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Failure);
    }
Ejemplo n.º 31
0
  public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc)
  {
    // Select two curves to intersect
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select two curves");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple(2, 2);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Validate input
    var curveA = go.Object(0).Curve();
    var curveB = go.Object(1).Curve();
    if (curveA == null || curveB == null)
      return Rhino.Commands.Result.Failure;

    // Calculate the intersection
    double intersection_tolerance = 0.001;
    double overlap_tolerance = 0.0;
    var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance);

    // Process the results
    if (events != null)
    {
      for (int i = 0; i < events.Count; i++)
      {
        var ccx_event = events[i];
        doc.Objects.AddPoint(ccx_event.PointA);
        if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
        {
          doc.Objects.AddPoint(ccx_event.PointB);
          doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB);
        }
      }
      doc.Views.Redraw();
    }
    return Rhino.Commands.Result.Success;
  }
Ejemplo n.º 32
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;
  }
Ejemplo n.º 33
0
    public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc)
    {
        // Select objects to define block
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select objects to define block");
        go.ReferenceObjectSelect = false;
        go.SubObjectSelect       = false;
        go.GroupSelect           = true;

        // Phantoms, grips, lights, etc., cannot be in blocks.
        const ObjectType forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
                                                     Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
        const ObjectType geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject;

        go.GeometryFilter = geometry_filter;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Block base point
        Rhino.Geometry.Point3d base_point;
        var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        // Block definition name
        string idef_name = "";

        rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        // Validate block name
        idef_name = idef_name.Trim();
        if (string.IsNullOrEmpty(idef_name))
        {
            return(Rhino.Commands.Result.Nothing);
        }

        // See if block name already exists
        Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true);
        if (existing_idef != null)
        {
            Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
            return(Rhino.Commands.Result.Nothing);
        }

        // Gather all of the selected objects
        var geometry   = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>();
        var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>();

        for (int i = 0; i < go.ObjectCount; i++)
        {
            var rhinoObject = go.Object(i).Object();
            if (rhinoObject != null)
            {
                geometry.Add(rhinoObject.Geometry);
                attributes.Add(rhinoObject.Attributes);
            }
        }

        // Gather all of the selected objects
        int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

        if (idef_index < 0)
        {
            Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name);
            return(Rhino.Commands.Result.Failure);
        }
        return(Rhino.Commands.Result.Failure);
    }
Ejemplo n.º 34
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);
        }
Ejemplo n.º 35
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);
        }
Ejemplo n.º 36
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);
        }
Ejemplo n.º 37
0
  public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc)
  {
    // Select objects to define block
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt( "Select objects to define block" );
    go.ReferenceObjectSelect = false;
    go.SubObjectSelect = false;
    go.GroupSelect = true;

    // Phantoms, grips, lights, etc., cannot be in blocks.
    var forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
      Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
    var geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject;
    go.GeometryFilter = geometry_filter;
    go.GetMultiple(1, 0);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Block base point
    Rhino.Geometry.Point3d base_point;
    var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    // Block definition name
    string idef_name = "";
    rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    // Validate block name
    idef_name = idef_name.Trim();
    if (string.IsNullOrEmpty(idef_name))
      return Rhino.Commands.Result.Nothing;

    // See if block name already exists
    Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true);
    if (existing_idef != null)
    {
      Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
      return Rhino.Commands.Result.Nothing;
    }

    // Gather all of the selected objects
    var geometry = new System.Collections.Generic.List<Rhino.Geometry.GeometryBase>();
    var attributes = new System.Collections.Generic.List<Rhino.DocObjects.ObjectAttributes>();
    for (int i = 0; i < go.ObjectCount; i++)
    {
      var rhinoObject = go.Object(i).Object();
      if (rhinoObject != null)
      {
        geometry.Add(rhinoObject.Geometry);
        attributes.Add(rhinoObject.Attributes);
      }
    }

    // Gather all of the selected objects
    int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

    if( idef_index < 0 )
    {
      Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name);
      return Rhino.Commands.Result.Failure;
    }
    return Rhino.Commands.Result.Failure;
  }
Ejemplo n.º 38
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;
    }
Ejemplo n.º 39
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //select the cross-section faces
            var gb = new Rhino.Input.Custom.GetObject();

            gb.SetCommandPrompt("Select the surfaces which form the cross-section of the beam.");
            gb.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            gb.EnablePreSelect(false, true);
            gb.GetMultiple(1, 0);
            if (gb.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gb.CommandResult());
            }

            List <BrepFace> cross_section = new List <BrepFace>();

            for (int i = 0; i < gb.ObjectCount; i++)
            {
                var face = gb.Object(i).Face();
                if (face != null)
                {
                    cross_section.Add(face);
                }
            }

            //select the rail
            Rhino.DocObjects.ObjRef rail_ref;
            var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }

            var rail_crv = rail_ref.Curve();

            if (rail_crv == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            var gx = new Rhino.Input.Custom.GetObject();

            gx.SetCommandPrompt("Select cross section curves");
            gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gx.EnablePreSelect(false, true);
            gx.GetMultiple(1, 0);
            if (gx.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gx.CommandResult());
            }

            var cross_sections = new List <Rhino.Geometry.Curve>();

            for (int i = 0; i < gx.ObjectCount; i++)
            {
                var crv = gx.Object(i).Curve();
                if (crv != null)
                {
                    cross_sections.Add(crv);
                }
            }
            if (cross_sections.Count < 1)
            {
                return(Rhino.Commands.Result.Failure);
            }

            var sweep = new Rhino.Geometry.SweepOneRail();

            sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
            sweep.ClosedSweep           = false;
            sweep.SweepTolerance        = doc.ModelAbsoluteTolerance;
            //sweep.SetToRoadlikeTop();
            var breps = sweep.PerformSweep(rail_crv, cross_sections);

            for (int i = 0; i < breps.Length; i++)
            {
                doc.Objects.AddBrep(breps[i]);
            }
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
Ejemplo n.º 40
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;
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //select the cross-section faces
            var gc = new Rhino.Input.Custom.GetObject();

            gc.SetCommandPrompt("Select the surfaces which form the cross-section of the beam.");
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            gc.EnablePreSelect(false, true);
            gc.GetMultiple(1, 1);
            if (gc.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gc.CommandResult());
            }

            var face = gc.Object(0).Face();

            //for each cross-section, get the base-surface curve
            var gv = new Rhino.Input.Custom.GetObject();

            gv.SetCommandPrompt("Select the base_curve.");
            gv.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gv.EnablePreSelect(false, true);
            gv.GetMultiple(1, 1);
            if (gv.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gv.CommandResult());
            }

            var base_curve = gv.Object(0).Curve();

            //List of all the sub section
            List <Brep> sub_sections = new List <Brep>();

            for (int i = 0; i < 10; i++)
            {
                //offset the base to form a closed loop
                var curves = base_curve.OffsetOnSurface(face, 0.1, doc.ModelAbsoluteTolerance);
                if (curves.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one offset");
                    return(Result.Failure);
                }
                var offset_curve = curves[0];

                //connect the curves in a closed loop
                LineCurve    edge1   = new LineCurve(base_curve.PointAtStart, offset_curve.PointAtStart);
                LineCurve    edge2   = new LineCurve(offset_curve.PointAtEnd, base_curve.PointAtEnd);
                List <Curve> prejoin = new List <Curve>();
                prejoin.Add(edge1);
                prejoin.Add(edge2);
                prejoin.Add(base_curve);
                prejoin.Add(offset_curve);

                var loops = Curve.JoinCurves(prejoin, doc.ModelAbsoluteTolerance);

                if (loops.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one joined loops");
                    return(Result.Failure);
                }
                var loop  = loops[0];
                var breps = Rhino.Geometry.Brep.CreatePlanarBreps(loop);

                if (breps.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one joined loops");
                    return(Result.Failure);
                }

                sub_sections.Add(breps[0]);

                doc.Objects.AddBrep(breps[0]);
                doc.Views.Redraw();

                base_curve = offset_curve;
            }

            //compute moment of inertia
            var area_properties1 = Rhino.Geometry.AreaMassProperties.Compute(sub_sections);
            var area_properties2 = Rhino.Geometry.AreaMassProperties.Compute(face);

            //check for the difference
            Rhino.RhinoApp.WriteLine("Area {0}", area_properties1.Area);
            Rhino.RhinoApp.WriteLine("Difference in Area {0}", area_properties1.Area - area_properties2.Area);

            Rhino.RhinoApp.WriteLine("Moment X: {0}; Y: {1}; Z: {2} in WCS ", area_properties1.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z);
            Rhino.RhinoApp.WriteLine("Difference in Moment X: {0}; Y: {1}; Z: {2} in WCS", area_properties1.WorldCoordinatesMomentsOfInertia.X - area_properties2.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y - area_properties2.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z - area_properties2.WorldCoordinatesMomentsOfInertia.Z);

            //display the centroids
            doc.Objects.AddPoint(area_properties1.Centroid);
            doc.Objects.AddPoint(area_properties2.Centroid);

            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 42
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            var 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);
        }
Ejemplo n.º 43
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;
  }
Ejemplo n.º 44
0
  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;
  }
Ejemplo n.º 45
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);
        }