예제 #1
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);
    }
예제 #2
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;
    }
예제 #4
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);
    }
예제 #5
0
        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;
        }
    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;
    }
예제 #7
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);
        }
예제 #8
0
    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);
    }
예제 #9
0
  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;
  }
예제 #10
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);
    }
예제 #11
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);
    }
    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());
    }
예제 #13
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);
        }
예제 #14
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);
        }
        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);
        }
예제 #16
0
        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);
        }
예제 #17
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
                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 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);
    }
예제 #19
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
        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;
  }