Beispiel #1
0
        protected override GH_GetterResult Prompt_Singular(ref IGH_Goo value)
        {
            Rhino.Input.Custom.GetPoint gpC = new Rhino.Input.Custom.GetPoint();
            gpC.SetCommandPrompt("Set default tool center point.");
            gpC.AcceptNothing(true);

            Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
            go.SetCommandPrompt("Set default tool.");
            go.AcceptNothing(true);
            go.AddOption("True");

            switch (go.Get())
            {
            case Rhino.Input.GetResult.Option:
                if (go.Option().EnglishName == "True")
                {
                    value = ABBTool.Default;
                }
                return(GH_GetterResult.success);

            case Rhino.Input.GetResult.Nothing:
                return(GH_GetterResult.accept);

            default:
                return(GH_GetterResult.cancel);
            }
        }
Beispiel #2
0
    public static Rhino.Commands.Result AddLine(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Start of line");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        Rhino.Geometry.Point3d pt_start = gp.Point();

        gp.SetCommandPrompt("End of line");
        gp.SetBasePoint(pt_start, false);
        gp.DrawLineFromPoint(pt_start, true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        Rhino.Geometry.Point3d  pt_end = gp.Point();
        Rhino.Geometry.Vector3d v      = pt_end - pt_start;
        if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance))
        {
            return(Rhino.Commands.Result.Nothing);
        }

        if (doc.Objects.AddLine(pt_start, pt_end) != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            SampleCsGetMultiplePointsConduit conduit = new SampleCsGetMultiplePointsConduit();

            conduit.Enabled = true;

            Rhino.Commands.Result rc = Result.Nothing;

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            while (true)
            {
                if (0 == conduit.PointCount)
                {
                    gp.SetCommandPrompt("Location of point object.");
                    gp.AcceptNothing(false);
                    gp.ClearCommandOptions();
                }
                else
                {
                    gp.SetCommandPrompt("Location of point object. Press Enter when done");
                    gp.AcceptNothing(true);
                    gp.AddOption("Undo");
                }

                Rhino.Input.GetResult res = gp.Get();

                if (res == Rhino.Input.GetResult.Point)
                {
                    conduit.AddPoint(gp.Point());
                    doc.Views.Redraw();
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    conduit.RemoveLastPoint();
                    doc.Views.Redraw();
                }
                else if (res == Rhino.Input.GetResult.Nothing)
                {
                    rc = Rhino.Commands.Result.Success;
                    break;
                }
                else
                {
                    rc = Rhino.Commands.Result.Cancel;
                    break;
                }
            }

            if (rc == Result.Success && conduit.PointCount > 0)
            {
                doc.Objects.AddPoints(conduit.Points);
            }

            conduit.Enabled = false;
            doc.Views.Redraw();

            return(rc);
        }
Beispiel #4
0
    public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc)
    {
        // Get a single planar closed curve
        var go = new Rhino.Input.Custom.GetObject();

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

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

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

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

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

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

        Rhino.Geometry.Vector3d vec = second_point - first_point;
        if (vec.Length > 0.001)
        {
            var  xf = Rhino.Geometry.Transform.Translation(vec);
            Guid id = doc.Objects.Transform(objref, xf, false);
            if (id != Guid.Empty)
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Cancel);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      ObjRef obj_ref;
      var rc = RhinoGet.GetOneObject("Select surface for curvature measurement", true, 
        ObjectType.Surface, out obj_ref);
      if (rc != Result.Success)
        return rc;
      var surface = obj_ref.Surface();

      var gp = new Rhino.Input.Custom.GetPoint();
      gp.SetCommandPrompt("Select point on surface for curvature measurement");
      gp.Constrain(surface, false);
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
      var point_on_surface = gp.Point();

      double u, v;
      if (!surface.ClosestPoint(point_on_surface, out u, out v))
        return Result.Failure;

      var surface_curvature = surface.CurvatureAt(u, v);
      if (surface_curvature == null)
        return Result.Failure;

      RhinoApp.WriteLine("Surface curvature evaluation at parameter: ({0}, {1})", u, v);

      RhinoApp.WriteLine("  3-D Point: ({0}, {1}, {2})",
        surface_curvature.Point.X,
        surface_curvature.Point.Y,
        surface_curvature.Point.Z);

      RhinoApp.WriteLine("  3-D Normal: ({0}, {1}, {2})",
        surface_curvature.Normal.X,
        surface_curvature.Normal.Y,
        surface_curvature.Normal.Z);

      RhinoApp.WriteLine(string.Format("  Maximum principal curvature: {0} ({1}, {2}, {3})", 
        surface_curvature.Kappa(0), 
        surface_curvature.Direction(0).X, 
        surface_curvature.Direction(0).Y, 
        surface_curvature.Direction(0).Z));

      RhinoApp.WriteLine(string.Format("  Minimum principal curvature: {0} ({1}, {2}, {3})", 
        surface_curvature.Kappa(1), 
        surface_curvature.Direction(1).X, 
        surface_curvature.Direction(1).Y, 
        surface_curvature.Direction(1).Z));

      RhinoApp.WriteLine("  Gaussian curvature: {0}", surface_curvature.Gaussian);
      RhinoApp.WriteLine("  Mean curvature: {0}", surface_curvature.Mean);

      return Result.Success;
    }
Beispiel #6
0
        /// <since>5.0</since>
        public bool PickGumball(Rhino.Input.Custom.PickContext pickContext, Rhino.Input.Custom.GetPoint getPoint)
        {
            IntPtr pThis             = NonConstPointer();
            IntPtr pConstPickContext = pickContext.ConstPointer();
            IntPtr pGetPoint         = IntPtr.Zero;

            if (getPoint != null)
            {
                getPoint.NonConstPointer();
            }
            return(UnsafeNativeMethods.CRhinoGumballDisplayConduit_PickGumball(pThis, pConstPickContext, pGetPoint));
        }
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Mesh meshObj;
            Point3d pointObj = new Point3d(0.0,0.0,0.0);

            RhinoApp.WriteLine("dikka dikka dikka...");

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("Start of ray");
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
                return gp.CommandResult();

            pointObj = gp.Point();
            doc.Objects.AddPoint(pointObj);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("sdfafadsfda");
                return rc;
            }

            RhinoApp.WriteLine("2 2 dikka dikka dikka...");

            meshObj = new Mesh();
            if (go.ObjectCount == 1)
            {
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null)
                {
                    return rc;
                }
            }

            Ray3d rayObj = new Ray3d(pointObj, new Vector3d(1.0, 1.0, 1.0));
            doc.Objects.AddPoint(rayObj.PointAt(1.0));
            doc.Objects.AddPoint(rayObj.PointAt(2.0));
            doc.Objects.AddPoint(rayObj.PointAt(3.0));

            double p  = Intersection.MeshRay(meshObj, rayObj);
            string a = string.Format("mesh ray gives {0:0.00}",p);
            doc.Objects.AddPoint(rayObj.PointAt(p));
            RhinoApp.WriteLine(a);
            return Rhino.Commands.Result.Success;
        }
Beispiel #8
0
    public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc)
    {
        // For this example we will use a GetPoint class, but all of the custom
        // "Get" classes support command line options.
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("GetPoint with options");

        // set up the options
        Rhino.Input.Custom.OptionInteger intOption  = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
        Rhino.Input.Custom.OptionDouble  dblOption  = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
        Rhino.Input.Custom.OptionToggle  boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
        string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

        gp.AddOptionInteger("Integer", ref intOption);
        gp.AddOptionDouble("Double", ref dblOption);
        gp.AddOptionToggle("Boolean", ref boolOption);
        int listIndex = 3;
        int opList    = gp.AddOptionList("List", listValues, listIndex);

        while (true)
        {
            // perform the get operation. This will prompt the user to input a point, but also
            // allow for command line options defined above
            Rhino.Input.GetResult get_rc = gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gp.CommandResult());
            }

            if (get_rc == Rhino.Input.GetResult.Point)
            {
                doc.Objects.AddPoint(gp.Point());
                doc.Views.Redraw();
                Rhino.RhinoApp.WriteLine("Command line option values are");
                Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]);
            }
            else if (get_rc == Rhino.Input.GetResult.Option)
            {
                if (gp.OptionIndex() == opList)
                {
                    listIndex = gp.Option().CurrentListOptionIndex;
                }
                continue;
            }
            break;
        }
        return(Rhino.Commands.Result.Success);
    }
    public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc)
    {
        // For this example we will use a GetPoint class, but all of the custom
        // "Get" classes support command line options.
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("GetPoint with options");

        // set up the options
        Rhino.Input.Custom.OptionInteger intOption = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
        Rhino.Input.Custom.OptionDouble dblOption = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
        Rhino.Input.Custom.OptionToggle boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
        string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

        gp.AddOptionInteger("Integer", ref intOption);
        gp.AddOptionDouble("Double", ref dblOption);
        gp.AddOptionToggle("Boolean", ref boolOption);
        int listIndex = 3;
        int opList = gp.AddOptionList("List", listValues, listIndex);

        while (true)
        {
          // perform the get operation. This will prompt the user to input a point, but also
          // allow for command line options defined above
          Rhino.Input.GetResult get_rc = gp.Get();
          if (gp.CommandResult() != Rhino.Commands.Result.Success)
        return gp.CommandResult();

          if (get_rc == Rhino.Input.GetResult.Point)
          {
        doc.Objects.AddPoint(gp.Point());
        doc.Views.Redraw();
        Rhino.RhinoApp.WriteLine("Command line option values are");
        Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]);
          }
          else if (get_rc == Rhino.Input.GetResult.Option)
          {
        if (gp.OptionIndex() == opList)
          listIndex = gp.Option().CurrentListOptionIndex;
        continue;
          }
          break;
        }
        return Rhino.Commands.Result.Success;
    }
    public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc)
    {
        Rhino.Display.RhinoView view;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetView("Select view to adjust", out view);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d location;
        rc = Rhino.Input.RhinoGet.GetPoint("Camera Location", false, out location);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Look At Location");
        gp.DrawLineFromPoint(location, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }
        Rhino.Geometry.Point3d lookat = gp.Point();

        string name = view.ActiveViewport.Name;

        rc = Rhino.Input.RhinoGet.GetString("Name", true, ref name);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Display.RhinoViewport vp = view.ActiveViewport;
        // save the current viewport projection
        vp.PushViewProjection();
        vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis;
        vp.SetCameraLocation(location, false);
        vp.SetCameraDirection(lookat - location, true);
        vp.Name = name;

        doc.NamedViews.Add(name, vp.Id);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Beispiel #11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var view = doc.Views.ActiveView;
            var vp   = view.ActiveViewport;

            var target = vp.CameraTarget;
            var camera = vp.CameraLocation;

            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("New target location");
            gp.SetDefaultPoint(target);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            target = gp.Point();

            gp.ClearDefault();
            gp.SetCommandPrompt("New camera location");
            gp.SetDefaultPoint(camera);
            gp.SetBasePoint(target, true);
            gp.DrawLineFromPoint(target, true);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            camera = gp.Point();

            var camdir = target - camera;

            camdir.Unitize();
            if (camdir.IsTiny())
            {
                return(Result.Cancel);
            }

            vp.SetCameraLocations(target, camera);
            view.Redraw();

            return(Result.Success);
        }
Beispiel #12
0
    public static Rhino.Commands.Result InsertKnot(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Curve;

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve for knot insertion", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Curve curve = objref.Curve();
        if (null == curve)
        {
            return(Rhino.Commands.Result.Failure);
        }
        Rhino.Geometry.NurbsCurve nurb = curve.ToNurbsCurve();
        if (null == nurb)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point on curve to add knot");
        gp.Constrain(nurb, false);
        gp.Get();
        if (gp.CommandResult() == Rhino.Commands.Result.Success)
        {
            double t;
            Rhino.Geometry.Curve crv = gp.PointOnCurve(out t);
            if (crv != null && nurb.Knots.InsertKnot(t))
            {
                doc.Objects.Replace(objref, nurb);
                doc.Views.Redraw();
            }
        }
        return(Rhino.Commands.Result.Success);
    }
Beispiel #13
0
    public static Rhino.Commands.Result PickPoints(RhinoDoc doc)
    {
        var conduit = new PointsConduit(m_conduit_points);

        conduit.Enabled = true;

        var gp = new Rhino.Input.Custom.GetPoint();

        while (true)
        {
            gp.SetCommandPrompt("click location to create point. (<ESC> exit)");
            gp.AcceptNothing(true);
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
            {
                break;
            }
            m_conduit_points.Add(new ConduitPoint(gp.Point()));
            doc.Views.Redraw();
        }

        var gcp = new GetConduitPoint(m_conduit_points);

        while (true)
        {
            gcp.SetCommandPrompt("select conduit point. (<ESC> to exit)");
            gcp.AcceptNothing(true);
            gcp.Get(true);
            doc.Views.Redraw();
            if (gcp.CommandResult() != Rhino.Commands.Result.Success)
            {
                break;
            }
        }

        return(Rhino.Commands.Result.Success);
    }
  public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc)
  {
    Rhino.Display.RhinoView view;
    Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetView("Select view to adjust", out view);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    Rhino.Geometry.Point3d location;
    rc = Rhino.Input.RhinoGet.GetPoint("Camera Location", false, out location);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
    gp.SetCommandPrompt("Look At Location");
    gp.DrawLineFromPoint(location, false);
    gp.Get();
    if (gp.CommandResult() != Rhino.Commands.Result.Success)
      return gp.CommandResult();
    Rhino.Geometry.Point3d lookat = gp.Point();
    
    string name = view.ActiveViewport.Name;
    rc = Rhino.Input.RhinoGet.GetString("Name", true, ref name);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    Rhino.Display.RhinoViewport vp = view.ActiveViewport;
    // save the current viewport projection
    vp.PushViewProjection();
    vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis;
    vp.SetCameraLocation(location, false);
    vp.SetCameraDirection(lookat - location, true);
    vp.Name = name;

    doc.NamedViews.Add(name, vp.Id);
    view.Redraw();
    return Rhino.Commands.Result.Success;
  }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh;
            var rc = RhinoGet.GetMultipleObjects("Select objects to contour", false, filter, out var objrefs);

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

            if (objrefs == null || objrefs.Length < 1)
            {
                return(Result.Failure);
            }

            rc = RhinoGet.GetPoint("Contour plane base point", false, out var base_point);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Direction perpendicular to contour planes");
            gp.DrawLineFromPoint(base_point, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var end_point = gp.Point();

            var interval = 1.0;

            rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var bounds     = BoundingBox.Unset;
            var geometries = new List <GeometryBase>();

            foreach (var objref in objrefs)
            {
                var geometry = objref.Geometry();
                if (geometry is Extrusion)
                {
                    geometry = objref.Brep();
                }
                geometries.Add(geometry);
                var bbox = geometry.GetBoundingBox(false);
                bounds.Union(bbox);
            }

            var normal = end_point - base_point;

            normal.Unitize();
            var curplane = new Plane(base_point, normal);

            if (!curplane.DistanceTo(bounds, out var min_t, out var max_t))
            {
                return(Result.Failure);
            }

            min_t -= interval;
            max_t += interval;
            min_t  = Math.Floor(min_t / interval);
            max_t  = Math.Ceiling(max_t / interval);
            var tolerance = doc.ModelAbsoluteTolerance;

            var tasks = new List <Task <Curve[]> >();
            var gc    = new Rhino.Input.Custom.GetCancel();

            for (var t = min_t; t <= max_t; t += 1.0)
            {
                var offset = t * interval;
                var point  = base_point + normal * offset;
                var plane  = new Plane(point, normal);
                foreach (var geom in geometries)
                {
                    var geom1 = geom;
                    var task  = Task.Run(() => Section(plane, geom1, tolerance), gc.Token);
                    tasks.Add(task);
                }
            }
            gc.TaskCompleted += OnTaskCompleted;
            rc = gc.WaitAll(tasks, doc);
            return(rc);
        }
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
        Rhino.DocObjects.ObjRef objref;
        var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref);

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

        rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        var obj = objref.Object();

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

        // create an instance of a GetPoint class and add a delegate
        // for the DynamicDraw event
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.DrawLineFromPoint(m_point_start, true);
        var  optdouble    = new Rhino.Input.Custom.OptionDouble(m_distance);
        bool constrain    = false;
        var  optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On");

        gp.AddOptionDouble("Distance", ref optdouble);
        gp.AddOptionToggle("Constrain", ref optconstrain);
        gp.DynamicDraw += ArrayByDistanceDraw;
        gp.Tag          = obj;
        while (gp.Get() == Rhino.Input.GetResult.Option)
        {
            m_distance = optdouble.CurrentValue;
            if (constrain != optconstrain.CurrentValue)
            {
                constrain = optconstrain.CurrentValue;
                if (constrain)
                {
                    var gp2 = new Rhino.Input.Custom.GetPoint();
                    gp2.DrawLineFromPoint(m_point_start, true);
                    gp2.SetCommandPrompt("Second point on constraint line");
                    if (gp2.Get() == Rhino.Input.GetResult.Point)
                    {
                        gp.Constrain(m_point_start, gp2.Point());
                    }
                    else
                    {
                        gp.ClearCommandOptions();
                        optconstrain.CurrentValue = false;
                        constrain = false;
                        gp.AddOptionDouble("Distance", ref optdouble);
                        gp.AddOptionToggle("Constrain", ref optconstrain);
                    }
                }
                else
                {
                    gp.ClearConstraints();
                }
            }
        }

        if (gp.CommandResult() == Rhino.Commands.Result.Success)
        {
            m_distance = optdouble.CurrentValue;
            var    pt     = gp.Point();
            var    vec    = pt - m_point_start;
            double length = vec.Length;
            vec.Unitize();
            int count = (int)(length / m_distance);
            for (int i = 1; i < count; i++)
            {
                var translate = vec * (i * m_distance);
                var xf        = Rhino.Geometry.Transform.Translation(translate);
                doc.Objects.Transform(obj, xf, false);
            }
            doc.Views.Redraw();
        }

        return(gp.CommandResult());
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // mimic the functionality of the contour command using a background threads
            // The tricky parts to the contour command are that it dynamically adds
            // sections as they are found
            const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh;

            ObjRef[] objrefs;
            var      rc = RhinoGet.GetMultipleObjects("Select objects for contours", false, filter, out objrefs);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (objrefs == null || objrefs.Length < 1)
            {
                return(Result.Failure);
            }

            Point3d base_point;

            rc = RhinoGet.GetPoint("Contour plane base point", false, out base_point);
            if (rc != Result.Success)
            {
                return(rc);
            }
            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Direction perpendicular to contour planes");
            gp.DrawLineFromPoint(base_point, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            Point3d end_point = gp.Point();

            double interval = 1;

            rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // figure out the combined bounding box of all the selected geometry
            BoundingBox bounds     = BoundingBox.Unset;
            var         geometries = new List <GeometryBase>();

            foreach (var objref in objrefs)
            {
                var geometry  = objref.Geometry();
                var extrusion = geometry as Extrusion;
                if (extrusion != null)
                {
                    geometry = objref.Brep();
                }
                geometries.Add(geometry);
                var bbox = geometry.GetBoundingBox(false);
                bounds.Union(bbox);
            }

            Vector3d normal = end_point - base_point;

            normal.Unitize();
            var    curplane = new Plane(base_point, normal);
            double min_t, max_t;

            if (!curplane.DistanceTo(bounds, out min_t, out max_t))
            {
                return(Result.Failure);
            }

            min_t -= interval;
            max_t += interval;
            min_t  = Math.Floor(min_t / interval);
            max_t  = Math.Ceiling(max_t / interval);
            double tolerance = doc.ModelAbsoluteTolerance;

            var tasks = new List <Task <Curve[]> >();
            var gc    = new Rhino.Input.Custom.GetCancel();

            for (double t = min_t; t <= max_t; t += 1.0)
            {
                double offset = t * interval;
                var    point  = base_point + normal * offset;
                var    plane  = new Plane(point, normal);
                foreach (var geom in geometries)
                {
                    var geom1 = geom;
                    var task  = Task.Run(() => Section(plane, geom1, tolerance), gc.Token);
                    tasks.Add(task);
                }
            }
            gc.TaskCompleted += OnTaskCompleted;
            rc = gc.WaitAll(tasks, doc);
            return(rc);
        }
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
      // Select objects to scale
      var list = new Rhino.Collections.TransformObjectList();
      var rc = SelectObjects("Select objects to scale", list);
      if (rc != Rhino.Commands.Result.Success)
        return rc;

      var anchor = new Point3d();
      var _ref = new Point3d();
      Plane plane = new Plane();

      // Origin point
      var gp = new Rhino.Input.Custom.GetPoint();
      gp.SetCommandPrompt("Origin point");
      var copy = new Rhino.Input.Custom.OptionToggle(m_copy,"No", "Yes");
      gp.AddOptionToggle("Copy", ref copy);
      for (; ; )
      {
        var res = gp.Get();
        if (res == Rhino.Input.GetResult.Point)
        {
          var view = gp.View();
          if (view == null)
            return Rhino.Commands.Result.Failure;
          plane = view.ActiveViewport.ConstructionPlane();
          anchor = gp.Point();
          break;
        }
        if (res == Rhino.Input.GetResult.Option)
          continue;

        return Rhino.Commands.Result.Cancel;
      }

      bool bAcceptDefault = true;

      // Scale factor or first reference point
      gp.SetCommandPrompt("Scale factor or first reference point");
      gp.SetBasePoint(anchor, true);
      gp.DrawLineFromPoint(anchor, true);
      gp.ConstrainToConstructionPlane(true);
      for (; ; )
      {
        if (bAcceptDefault)
        {
          gp.AcceptNumber(true, false);
          gp.SetDefaultNumber(m_scale);
        }
        else
        {
          gp.AcceptNothing(true);
          gp.ClearDefault();
        }

        var res = gp.Get();
        if (res == Rhino.Input.GetResult.Point)
        {
          _ref = gp.Point();
          break;
        }
        if (res == Rhino.Input.GetResult.Number)
        {
          double scale = Math.Abs(gp.Number());
          const double EPS_DIVIDE = 0.000001;
          if (scale < EPS_DIVIDE)
            continue;
          m_scale = scale;
          plane.Origin = anchor;

          var xform = Transform.Scale(plane, m_scale, m_scale, m_scale);
          TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
          m_copy = copy.CurrentValue;
          if (m_copy)
          {
            bAcceptDefault = false;
            continue;
          }
          doc.Views.Redraw();
          return Rhino.Commands.Result.Success;
        }

        if (res == Rhino.Input.GetResult.Nothing)
        {
          if (bAcceptDefault == false)
            return Rhino.Commands.Result.Success;

          plane.Origin = anchor;
          var xform = Transform.Scale(plane, m_scale, m_scale, m_scale);
          TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);

          m_copy = copy.CurrentValue;
          if (m_copy)
          {
            bAcceptDefault = false;
            continue;
          }
          doc.Views.Redraw();
          return Rhino.Commands.Result.Success;
        }
        if (res == Rhino.Input.GetResult.Option)
          continue;
        return Rhino.Commands.Result.Cancel;
      }

      // Second reference point
      var gx = new GetScaleXform();
      gx.SetCommandPrompt("Second reference point");
      gx.AddOptionToggle("copy", ref copy);
      gx.AddTransformObjects(list);
      gx.SetBasePoint(anchor, true);
      gx.DrawLineFromPoint(anchor, true);
      gx.ConstrainToConstructionPlane(true);
      gx.Plane = plane;
      gx.RefPoint = _ref;
      gx.AcceptNothing(true);
      gx.AcceptNumber(true, false);

      rc = Rhino.Commands.Result.Cancel;
      for (; ; )
      {
        var res = gx.GetXform();
        if (res == Rhino.Input.GetResult.Point)
        {
          var view = gx.View();
          if (view == null)
          {
            rc = Rhino.Commands.Result.Failure;
            break;
          }
          var xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
          if (xform.IsValid && xform != Transform.Identity)
          {
            TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
            rc = Rhino.Commands.Result.Success;
            m_scale = gx.Scale;
          }
          m_copy = copy.CurrentValue;
          if (m_copy)
            continue;

          break;
        }

        if (res == Rhino.Input.GetResult.Number)
        {
          var view = gx.View();
          if (view == null)
          {
            rc = Rhino.Commands.Result.Failure;
            break;
          }

          var xform = gx.CalculateTransform(view.ActiveViewport, gx.Number());
          if (xform.IsValid && xform != Transform.Identity)
          {
            TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
            rc = Rhino.Commands.Result.Success;
            m_scale = gx.Scale;
          }
          m_copy = copy.CurrentValue;
          if (m_copy)
            continue;
          break;
        }

        if (res == Rhino.Input.GetResult.Option)
          continue;

        if (res == Rhino.Input.GetResult.Nothing)
          break;

        break;
      }

      doc.Views.Redraw();
      return rc;
    }
Beispiel #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjRef obj_ref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve", false, Rhino.DocObjects.ObjectType.Curve, out obj_ref);

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

            Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
            if (null == obj)
            {
                return(Result.Failure);
            }

            obj_ref.Object().Select(false);
            doc.Views.Redraw();

            Rhino.Geometry.Curve crv = obj_ref.Curve();
            if (null == crv)
            {
                return(Result.Failure);
            }

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("First point on curve");
            gp.Constrain(crv, false);
            gp.Get();
            rc = gp.CommandResult();
            if (rc != Result.Success)
            {
                return(rc);
            }

            double t0 = Rhino.RhinoMath.UnsetValue;

            if (null == gp.PointOnCurve(out t0))
            {
                return(Result.Failure);
            }

            gp.SetCommandPrompt("Second point on curve");
            gp.Get();
            rc = gp.CommandResult();
            if (rc != Result.Success)
            {
                return(rc);
            }

            double t1 = Rhino.RhinoMath.UnsetValue;

            if (null == gp.PointOnCurve(out t1))
            {
                return(Result.Failure);
            }

            if (System.Math.Abs(t1 - t0) < Rhino.RhinoMath.ZeroTolerance)
            {
                return(Result.Failure);
            }

            if (crv.IsClosed || (!crv.IsClosed && t0 > t1))
            {
                double t = t0;
                t0 = t1;
                t1 = t;
            }

            Rhino.Geometry.Interval range  = new Rhino.Geometry.Interval(t0, t1);
            Rhino.Geometry.Curve    subcrv = crv.Trim(range);
            if (null != subcrv)
            {
                System.Guid id = doc.Objects.Add(subcrv);
                obj = doc.Objects.Find(id);
                if (null != obj)
                {
                    obj.Select(true);
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
    public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc)
    {
        // Allow the user to select a bitmap file
        var fd = new Rhino.UI.OpenFileDialog {
            Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"
        };

        if (!fd.ShowOpenDialog())
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify the file that was selected
        System.Drawing.Image image;
        try
        {
            image = System.Drawing.Image.FromFile(fd.FileName);
        }
        catch (Exception)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Allow the user to pick the bitmap origin
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.SetCommandPrompt("Bitmap Origin");
        gp.ConstrainToConstructionPlane(true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Get the view that the point was picked in.
        // This will be the view that the bitmap appears in.
        var view = gp.View();

        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }

        // Allow the user to specify the bitmap width in model units
        var gn = new Rhino.Input.Custom.GetNumber();

        gn.SetCommandPrompt("Bitmap width");
        gn.SetLowerLimit(1.0, false);
        gn.Get();
        if (gn.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gn.CommandResult());
        }

        // Cook up some scale factors
        var w            = gn.Number();
        var image_width  = image.Width;
        var image_height = image.Height;
        var h            = w * (image_height / image_width);

        var plane = view.ActiveViewport.ConstructionPlane();

        plane.Origin = gp.Point();
        view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Beispiel #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef obj_ref;
            var    rc = RhinoGet.GetOneObject("Select surface for curvature measurement", true,
                                              ObjectType.Surface, out obj_ref);

            if (rc != Result.Success)
            {
                return(rc);
            }
            var surface = obj_ref.Surface();

            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Select point on surface for curvature measurement");
            gp.Constrain(surface, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var point_on_surface = gp.Point();

            double u, v;

            if (!surface.ClosestPoint(point_on_surface, out u, out v))
            {
                return(Result.Failure);
            }

            var surface_curvature = surface.CurvatureAt(u, v);

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

            RhinoApp.WriteLine("Surface curvature evaluation at parameter: ({0}, {1})", u, v);

            RhinoApp.WriteLine("  3-D Point: ({0}, {1}, {2})",
                               surface_curvature.Point.X,
                               surface_curvature.Point.Y,
                               surface_curvature.Point.Z);

            RhinoApp.WriteLine("  3-D Normal: ({0}, {1}, {2})",
                               surface_curvature.Normal.X,
                               surface_curvature.Normal.Y,
                               surface_curvature.Normal.Z);

            RhinoApp.WriteLine(string.Format("  Maximum principal curvature: {0} ({1}, {2}, {3})",
                                             surface_curvature.Kappa(0),
                                             surface_curvature.Direction(0).X,
                                             surface_curvature.Direction(0).Y,
                                             surface_curvature.Direction(0).Z));

            RhinoApp.WriteLine(string.Format("  Minimum principal curvature: {0} ({1}, {2}, {3})",
                                             surface_curvature.Kappa(1),
                                             surface_curvature.Direction(1).X,
                                             surface_curvature.Direction(1).Y,
                                             surface_curvature.Direction(1).Z));

            RhinoApp.WriteLine("  Gaussian curvature: {0}", surface_curvature.Gaussian);
            RhinoApp.WriteLine("  Mean curvature: {0}", surface_curvature.Mean);

            return(Result.Success);
        }
    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
                const 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);
    }
  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
        const 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;
  }
Beispiel #24
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Select objects to scale
            var list = new Rhino.Collections.TransformObjectList();
            var rc   = SelectObjects("Select objects to scale", list);

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

            Point3d anchor;
            Point3d _ref;
            Plane   plane;

            // Origin point
            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Origin point");
            var copy = new Rhino.Input.Custom.OptionToggle(m_copy, "No", "Yes");

            gp.AddOptionToggle("Copy", ref copy);
            for (; ;)
            {
                var res = gp.Get();
                if (res == Rhino.Input.GetResult.Point)
                {
                    var view = gp.View();
                    if (view == null)
                    {
                        return(Rhino.Commands.Result.Failure);
                    }
                    plane  = view.ActiveViewport.ConstructionPlane();
                    anchor = gp.Point();
                    break;
                }
                if (res == Rhino.Input.GetResult.Option)
                {
                    continue;
                }

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

            bool bAcceptDefault = true;

            // Scale factor or first reference point
            gp.SetCommandPrompt("Scale factor or first reference point");
            gp.SetBasePoint(anchor, true);
            gp.DrawLineFromPoint(anchor, true);
            gp.ConstrainToConstructionPlane(true);
            for (; ;)
            {
                if (bAcceptDefault)
                {
                    gp.AcceptNumber(true, false);
                    gp.SetDefaultNumber(m_scale);
                }
                else
                {
                    gp.AcceptNothing(true);
                    gp.ClearDefault();
                }

                var res = gp.Get();
                if (res == Rhino.Input.GetResult.Point)
                {
                    _ref = gp.Point();
                    break;
                }
                if (res == Rhino.Input.GetResult.Number)
                {
                    double       scale      = Math.Abs(gp.Number());
                    const double EPS_DIVIDE = 0.000001;
                    if (scale < EPS_DIVIDE)
                    {
                        continue;
                    }
                    m_scale      = scale;
                    plane.Origin = anchor;

                    var xform = Transform.Scale(plane, m_scale, m_scale, m_scale);
                    TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
                    m_copy = copy.CurrentValue;
                    if (m_copy)
                    {
                        bAcceptDefault = false;
                        continue;
                    }
                    doc.Views.Redraw();
                    return(Rhino.Commands.Result.Success);
                }

                if (res == Rhino.Input.GetResult.Nothing)
                {
                    if (bAcceptDefault == false)
                    {
                        return(Rhino.Commands.Result.Success);
                    }

                    plane.Origin = anchor;
                    var xform = Transform.Scale(plane, m_scale, m_scale, m_scale);
                    TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);

                    m_copy = copy.CurrentValue;
                    if (m_copy)
                    {
                        bAcceptDefault = false;
                        continue;
                    }
                    doc.Views.Redraw();
                    return(Rhino.Commands.Result.Success);
                }
                if (res == Rhino.Input.GetResult.Option)
                {
                    continue;
                }
                return(Rhino.Commands.Result.Cancel);
            }

            // Second reference point
            var gx = new GetScaleXform();

            gx.SetCommandPrompt("Second reference point");
            gx.AddOptionToggle("copy", ref copy);
            gx.AddTransformObjects(list);
            gx.SetBasePoint(anchor, true);
            gx.DrawLineFromPoint(anchor, true);
            gx.ConstrainToConstructionPlane(true);
            gx.Plane    = plane;
            gx.RefPoint = _ref;
            gx.AcceptNothing(true);
            gx.AcceptNumber(true, false);

            rc = Rhino.Commands.Result.Cancel;
            for (; ;)
            {
                var res = gx.GetXform();
                if (res == Rhino.Input.GetResult.Point)
                {
                    var view = gx.View();
                    if (view == null)
                    {
                        rc = Rhino.Commands.Result.Failure;
                        break;
                    }
                    var xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
                    if (xform.IsValid && xform != Transform.Identity)
                    {
                        TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
                        rc      = Rhino.Commands.Result.Success;
                        m_scale = gx.Scale;
                    }
                    m_copy = copy.CurrentValue;
                    if (m_copy)
                    {
                        continue;
                    }

                    break;
                }

                if (res == Rhino.Input.GetResult.Number)
                {
                    var view = gx.View();
                    if (view == null)
                    {
                        rc = Rhino.Commands.Result.Failure;
                        break;
                    }

                    var xform = gx.CalculateTransform(view.ActiveViewport, gx.Number());
                    if (xform.IsValid && xform != Transform.Identity)
                    {
                        TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue);
                        rc      = Rhino.Commands.Result.Success;
                        m_scale = gx.Scale;
                    }
                    m_copy = copy.CurrentValue;
                    if (m_copy)
                    {
                        continue;
                    }
                    break;
                }

                if (res == Rhino.Input.GetResult.Option)
                {
                    continue;
                }

                break;
            }

            doc.Views.Redraw();
            return(rc);
        }
Beispiel #25
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get a polyframe
            // Get a new point
            // Create the pipes and lines in the new location
            // the lines will be from an edge container of the PolyFrame
            // The pipes will be added extra. This will allow for the pipes to be used as a PolyFrame


            var primal = new PFoam();
            var dual   = new PFoam();

            try
            {
                var guids = LoadData.LoadPrimalDual(out primal, out dual, out ContainerType container);


                if (primal.Cells.Count < 1)
                {
                    Rhino.RhinoApp.WriteLine("Error loading PolyFrame from provided data!");
                    return(Result.Failure);
                }

                var form = primal.Edges.Where(e => e.Id > 0).Any(x => x.Faces.Count < 2);



                if (dual.Cells.Count < 1)
                {
                    RhinoApp.WriteLine("Could not load dual from the selected PolyFrame.");
                    return(Result.Failure);
                }

                double minLen;
                double maxLen;

                var pipePolyFrame = new PFoam();
                if (form)
                {
                    pipePolyFrame = primal;
                }
                else
                {
                    pipePolyFrame = dual;
                }
                var edgeLengths = pipePolyFrame.Edges.Select(x => x.GetLength());

                minLen = edgeLengths.Min();
                maxLen = edgeLengths.Max();
                //var medLen = edgeLengths.Average();



                var gp        = new Rhino.Input.Custom.GetPoint();
                var minRadius = new Rhino.Input.Custom.OptionDouble(minLen / 10, true, double.Epsilon);
                var maxRadius = new Rhino.Input.Custom.OptionDouble(minLen / 2, true, double.Epsilon);
                gp.SetCommandPrompt("Place the Pipes. Hit <Enter> to replace Input");
                gp.SetDefaultPoint(primal.Centroid);
                gp.AcceptPoint(true);
                gp.AddOptionDouble("MinRadius", ref minRadius);
                gp.AddOptionDouble("MaxRadius", ref maxRadius);


                while (true)
                {
                    gp.Get();
                    if (gp.Result() == Rhino.Input.GetResult.Point)
                    {
                        break;
                    }
                    else if (gp.Result() == Rhino.Input.GetResult.Cancel)
                    {
                        return(Result.Failure);
                    }
                }

                var moveVect = gp.Point() - pipePolyFrame.Centroid;
                pipePolyFrame.Offset(moveVect);

                if (gp.GotDefault())
                {
                    if (!form)
                    {
                        moveVect = primal.Centroid - dual.Centroid;
                    }
                    doc.Objects.Delete(guids, true);
                    doc.Views.Redraw();
                }


                var pipeLayer = new Rhino.DocObjects.Layer()
                {
                    Name = "_Pipes"
                };
                if (doc.Layers.All(x => x.Name != pipeLayer.Name))
                {
                    doc.Layers.Add(pipeLayer);
                }
                pipeLayer = doc.Layers.First(x => x.Name == "_Pipes");

                var pipeCol   = pipePolyFrame.PipeGeoDual(minRadius.CurrentValue, maxRadius.CurrentValue, pipePolyFrame.Edges.Select(x => x.Id).ToList());
                var pipeGuids = new List <Guid>();
                foreach (var pc in pipeCol)
                {
                    var att = new Rhino.DocObjects.ObjectAttributes
                    {
                        LayerIndex  = pipeLayer.Index,
                        ObjectColor = pc.Item2,
                        ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
                    };
                    pipeGuids.Add(doc.Objects.AddBrep(pc.Item1, att));
                }
                doc.Groups.Add(pipePolyFrame.Id.ToString() + "_Pipes", pipeGuids);

                pipePolyFrame.SaveAsEdges();

                doc.Views.Redraw();
            }

            catch (PolyFrameworkException pfE)
            {
                RhinoApp.WriteLine(pfE.Message);
                primal.Hide();
                dual.Hide();
                return(Result.Failure);
            }


            return(Result.Success);
        }