Пример #1
0
    public static Result GetAngle(RhinoDoc doc)
    {
        var gp = new GetPoint();

        gp.SetCommandPrompt("Base point");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var base_point = gp.Point();

        gp.SetCommandPrompt("First reference point");
        gp.DrawLineFromPoint(base_point, true);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var first_point = gp.Point();

        double angle_radians;
        var    rc = RhinoGet.GetAngle("Second reference point", base_point, first_point, 0, out angle_radians);

        if (rc == Result.Success)
        {
            RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians));
        }

        return(rc);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var conduit = new SampleCsGetMultiplePointsConduit {
                Enabled = true
            };

            Result rc;

            var gp = new GetPoint();

            while (true)
            {
                if (0 == conduit.PointCount)
                {
                    gp.SetCommandPrompt("Location of point object.");
                    gp.AcceptNothing(false);
                    gp.AcceptUndo(false);
                }
                else
                {
                    gp.SetCommandPrompt("Location of point object. Press Enter when done");
                    gp.AcceptNothing(true);
                    gp.AcceptUndo(true);
                }

                var res = gp.Get();

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

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

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

            return(rc);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select grips to move");
            go.GeometryFilter = ObjectType.Grip;
            go.EnablePreSelect(true, true);
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var from = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(from, true);
            gp.DrawLineFromPoint(from, true);
            gp.Get();
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var to = gp.Point();

            var dir = to - from;

            if (dir.IsTiny(doc.ModelAbsoluteTolerance))
            {
                return(Result.Nothing);
            }

            var xform = Transform.Translation(dir);

            var helper = new SampleCsGripHelper(doc);

            helper.AddGripObjects(go);
            helper.TransformAndUpdate(xform);

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d base_pt;
            var     rc = RhinoGet.GetPoint("Start of line", false, out base_pt);

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(base_pt, true);
            gp.DrawLineFromPoint(base_pt, true);
            gp.DynamicDraw += gp_DynamicDraw;
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var end_pt = gp.Point();
            var vector = end_pt - base_pt;

            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                var line = new Line(base_pt, end_pt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Пример #5
0
        public override Line EnterLine(string startPointPrompt = "Enter start of line", string endPointPrompt = "Enter end of line", Vector?startPoint = null)
        {
            /*GetLine gL = new GetLine();
             * gL.FirstPointPrompt = startPointPrompt;
             * gL.SecondPointPrompt = endPointPrompt;
             * if (startPoint != null) gL.SetFirstPoint(FBtoRC.Convert(startPoint ?? Vector.Unset));
             * RC.Line output;
             * if (gL.Get(out output) == Result.Cancel) throw new OperationCanceledException("Operation cancelled by user");
             * return RCtoFB.Convert(output);*/
            GetPoint gP = new GetPoint();

            gP.SetCommandPrompt(startPointPrompt);
            if (gP.Get() == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            GetPoint gP2 = new GetPointDynamic();

            gP2.SetCommandPrompt(endPointPrompt);
            gP2.SetBasePoint(gP.Point(), true);
            gP2.EnableDrawLineFromPoint(true);
            gP2.DrawLineFromPoint(gP.Point(), true);
            if (gP2.Get() == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            return(new Line(FromRC.Convert(gP.Point()), FromRC.Convert(gP2.Point())));
        }
Пример #6
0
        bool SelectHeight()
        {
            using (var cmd = new GetPoint())
            {
                cmd.SetCommandPrompt("Select the Height");
                cmd.AcceptNumber(true, true);
                cmd.SetDefaultNumber(DefaultHeight);

                var r = cmd.Get();
                switch (r)
                {
                case Rhino.Input.GetResult.Number:
                    m_height      = cmd.Number();
                    DefaultHeight = m_height;
                    break;

                case Rhino.Input.GetResult.Point:
                    m_height = cmd.Point().Z - m_basePoint.Z;
                    break;

                default:
                    return(false);
                }

                return(true);
            }
        }
Пример #7
0
        public static Result GetSpawn()
        {
            Point3d pt1;

            // string spawn = "0,0,0";

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select your character's spawn point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No spawn point selected");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
                //spawn = pt1.ToString();
                string username  = Environment.UserName;
                string directory = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio", username);
                System.IO.Directory.CreateDirectory(directory);
                string path = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio\spawn.xml", username);
                using (XmlWriter writer = XmlWriter.Create(path))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Spawn");

                    writer.WriteElementString("Location", pt1.ToString());


                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                }
            }
            RhinoApp.WriteLine(pt1.ToString());
            return(Result.Success);
        }
Пример #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var count = 0;

            var gp = new GetPoint();

            gp.AcceptNothing(true);
            for (; ;)
            {
                gp.SetCommandPrompt(0 == count ? "Location of text dot" : "Location of text dot. Press Enter when done");

                var res = gp.Get();

                if (res == GetResult.Point)
                {
                    var point = gp.Point();
                    var str   = count.ToString(CultureInfo.InvariantCulture);
                    var dot   = new TextDot(str, point);
                    doc.Objects.Add(dot);
                    doc.Views.Redraw();
                    count++;
                    continue;
                }

                break;
            }

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to draw from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var pt = gp.Point();

            var gd = new GetDirection();

            gd.SetCommandPrompt("Point to draw to");
            gd.SetBasePoint(pt, true);
            gd.DrawArrowFromPoint(pt, true, true);
            gd.Get();
            if (gd.CommandResult() != Result.Success)
            {
                return(gd.CommandResult());
            }

            // TODO...

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d basePt;
            Result  rc = RhinoGet.GetPoint("Start of line", false, out basePt);

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

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(basePt, true);
            gp.DrawLineFromPoint(basePt, true);
            gp.DynamicDraw += new EventHandler <GetPointDrawEventArgs>(gp_DynamicDraw);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d endPt = gp.Point();

            Rhino.Geometry.Vector3d vector = endPt - basePt;
            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                Line line = new Line(basePt, endPt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick a mesh
            ObjRef obj_ref;
            Result rc = RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out obj_ref);

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

            Rhino.Geometry.Mesh mesh = obj_ref.Mesh();
            if (null == mesh)
            {
                return(Result.Failure);
            }

            // Pick a point that is contrained to the mesh
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Pick point on mesh");
            gp.Constrain(mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();

            doc.Objects.AddPoint(point);
            doc.Views.Redraw();

            return(Result.Success);
        }
Пример #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            UsefulFunctions.XSelectCurves("Select curves for linear dimensioning", out CurveList curves);

            //var lines = new RhinoList<Line>();

            //for (var i = 0; i < curves.Count; i++)
            //{
            //    lines.Add(new Line(curves[i].PointAtStart, curves[i].PointAtEnd));
            //}



            //get the user to select a point

            var gp = new GetPoint();

            string prompt;

            prompt = "Pick a point";

            gp.SetCommandPrompt(prompt);


            gp.Get();

            Point3d pt = gp.Point();

            foreach (var curve in curves)
            {
                Point3d origin = curve.PointAtStart;
                Point3d offset = curve.PointAtEnd;

                //Vector3d linevec = new Vector3d(offset - origin);

                // you can rotate vector so its perp. with the line...


                Plane plane = Plane.WorldXY;

                plane.Origin = origin;

                double u, v;
                plane.ClosestParameter(origin, out u, out v);
                Point2d ext1 = new Point2d(u, v);

                plane.ClosestParameter(offset, out u, out v);
                Point2d ext2 = new Point2d(u, v);

                plane.ClosestParameter(pt, out u, out v);
                Point2d linePt = new Point2d(u, v);

                LinearDimension lindim = new LinearDimension(plane, ext1, ext2, linePt);

                doc.Objects.AddLinearDimension(lindim);
            }

            return(Result.Success);
        }
Пример #13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Start point");
            gp.AddOptionEnumList("Justification", m_justification);
            gp.ConstrainToConstructionPlane(false);
            for (;;)
            {
                var res = gp.Get();
                if (res == GetResult.Option)
                {
                    var option = gp.Option();
                    if (null != option)
                    {
                        var list = Enum.GetValues(typeof(TextJustification)).Cast <TextJustification>().ToList();
                        m_justification = list[option.CurrentListOptionIndex];
                    }
                    continue;
                }
                if (res != GetResult.Point)
                {
                    return(Result.Cancel);
                }
                break;
            }

            var point = gp.Point();

            var plane = gp.View().ActiveViewport.ConstructionPlane();

            plane.Origin = point;

            var text = new TextEntity
            {
                Plane         = plane,
                Justification = m_justification
            };

            text.PlainText = text.Justification.ToString();

            var attr = new ObjectAttributes
            {
                ColorSource = ObjectColorSource.ColorFromObject,
                ObjectColor = Color.FromArgb(0, 0, 255)
            };

            var object_id = doc.Objects.AddText(text, attr);

            RhinoApp.WriteLine("{0}", object_id.ToString());

            doc.Views.Redraw();

            return(Result.Success);
        }
Пример #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Location of point object");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var point = gp.Point();

            var point_id = MooseCommon.Utility.AddPoint(point);

            if (!Equals(point_id, Guid.Empty))
            {
                doc.Views.Redraw();

                var uuid_str = point_id.ToString();
                var str      = $"Identifier of point object is \"{uuid_str}\"";
                MooseCommon.Utility.Print(str);
            }


            var       sphere = new Sphere(Point3d.Origin, 5);
            var       brep   = sphere.ToBrep();
            const int x      = 1;
            const int y      = 2;
            var       rc     = MooseCommon.Utility.ExampleFunction(brep, x, y, out var points, out var lines);

            if (rc > 0)
            {
                foreach (var p in points)
                {
                    doc.Objects.AddPoint(p);
                }
                foreach (var l in lines)
                {
                    doc.Objects.AddLine(l);
                }
                doc.Views.Redraw();
            }


            var polylines = MooseCommon.Utility.ExampleGetPolylines();

            foreach (var pline in polylines)
            {
                doc.Objects.AddPolyline(pline);
            }
            doc.Views.Redraw();

            return(Result.Success);
        }
Пример #15
0
        public override Vector EnterVector(string prompt = "Enter vector")
        {
            //TODO: Get direction
            GetPoint gP = new GetPoint();

            gP.SetCommandPrompt(prompt);
            if (gP.Get() == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            return(FromRC.Convert(gP.Point()));
        }
Пример #16
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var start_point = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(start_point, false);
            gp.DrawLineFromPoint(start_point, true);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var end_point = gp.Point();

            var xform = Transform.Translation(end_point - start_point);

            foreach (var obj_ref in obj_refs)
            {
                doc.Objects.Transform(obj_ref, xform, true);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
    public static Result DetermineNormalDirectionOfBrepFace(RhinoDoc doc)
    {
        // select a surface
        var gs = new GetObject();

        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
        {
            return(gs.CommandResult());
        }
        // get the selected face
        var face = gs.Object(0).Face();

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

        // pick a point on the surface.  Constain
        // picking to the face.
        var gp = new GetPoint();

        gp.SetCommandPrompt("select point on surface");
        gp.Constrain(face, false);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }

        // get the parameters of the point on the
        // surface that is clesest to gp.Point()
        double u, v;

        if (face.ClosestPoint(gp.Point(), out u, out v))
        {
            var direction = face.NormalAt(u, v);
            if (face.OrientationIsReversed)
            {
                direction.Reverse();
            }
            RhinoApp.WriteLine(
                string.Format(
                    "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})",
                    u, v, direction.X, direction.Y, direction.Z));
        }
        return(Result.Success);
    }
Пример #18
0
    public static Result Ortho(RhinoDoc doc)
    {
        var gp = new GetPoint();

        gp.SetCommandPrompt("Start of line");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var start_point = gp.Point();

        var original_ortho = ModelAidSettings.Ortho;

        if (!original_ortho)
        {
            ModelAidSettings.Ortho = true;
        }

        gp.SetCommandPrompt("End of line");
        gp.SetBasePoint(start_point, false);
        gp.DrawLineFromPoint(start_point, true);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var end_point = gp.Point();

        if (ModelAidSettings.Ortho != original_ortho)
        {
            ModelAidSettings.Ortho = original_ortho;
        }

        doc.Objects.AddLine(start_point, end_point);
        doc.Views.Redraw();
        return(Result.Success);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Loop loop = new Loop();

            loop.Run(doc);

            return(Result.Success);

            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DynamicDraw +=
                    (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);

            // ---

            return(Result.Success);
        }
Пример #20
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the plane origin.");

                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No plane origin was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select a point on the new X-axis.");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            Point3d pt2;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select a point on the new Y-axis.");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt2 = getPointAction.Point();
            }

            Plane plane = new Plane(pt0, pt1, pt2);

            RNNPlugin.Instance.rnn.SetPlane(plane);
            return(Result.Success);
        }
Пример #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef objref;
            var    rc = RhinoGet.GetOneObject("Select object to move", false, ObjectType.AnyObject, out objref);

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

            Point3d first_point;

            rc = RhinoGet.GetPoint("Point to move from", false, out first_point);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(first_point, true);
            gp.DrawLineFromPoint(first_point, true);
            gp.Get();
            rc = gp.CommandResult();
            if (rc != Result.Success)
            {
                return(rc);
            }

            var second_point = gp.Point();

            var dir = second_point - first_point;

            if (dir.Length > RhinoMath.ZeroTolerance)
            {
                var xform = Transform.Translation(dir);
                doc.Objects.Transform(objref, xform, true);
                doc.Views.Redraw();
            }

            return(rc);
        }
Пример #22
0
        private Tuple <Point3d, Point3d> GetSpine()
        {
            // Get user input for spine
            bool    unsucessfulGetSpine = false;
            Point3d pt0 = new Point3d(0, 0, 0);

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Spine: start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    unsucessfulGetSpine = true;
                    //RhinoApp.WriteLine("No start point was selected.");
                    //return getPointAction.CommandResult();
                }
                if (!unsucessfulGetSpine)
                {
                    pt0 = getPointAction.Point();
                }
            }

            Point3d pt1 = new Point3d(0, 0, 0);

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Spine: end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DynamicDraw +=
                    (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
                if (getPointAction.Get() != GetResult.Point)
                {
                    unsucessfulGetSpine = true;
                    //RhinoApp.WriteLine("No end point was selected.");
                    //return getPointAction.CommandResult();
                }
                if (!unsucessfulGetSpine)
                {
                    pt1 = getPointAction.Point();
                }
            }
            if (unsucessfulGetSpine)
            {
                return(null);
            }
            return(new Tuple <Point3d, Point3d>(pt0, pt1));
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select closed curve for seam adjustment");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Curve curve = go.Object(0).Curve();

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

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("New seam location");
            gp.Constrain(curve, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();

            Curve  new_curve = curve.DuplicateCurve();
            double t         = Rhino.RhinoMath.UnsetValue;

            if (new_curve.ClosestPoint(point, out t))
            {
                if (new_curve.ChangeClosedCurveSeam(t))
                {
                    doc.Objects.Replace(go.Object(0), new_curve);
                }
            }

            return(Result.Success);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
#if IncludeSample
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;
            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;
            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DrawLineFromPoint(pt0, true);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);


            return(Result.Success);
#else
            // TODO: start here modifying the behaviour of your command.

            return(Result.Success);
#endif
        }
Пример #25
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Start point");
            gp.AddOptionEnumList("Justification", m_justification);
            gp.ConstrainToConstructionPlane(false);
            for (;;)
            {
                GetResult res = gp.Get();
                if (res == GetResult.Option)
                {
                    CommandLineOption option = gp.Option();
                    if (null != option)
                    {
                        List <TextJustification> list = Enum.GetValues(typeof(TextJustification)).Cast <TextJustification>().ToList();
                        m_justification = list[option.CurrentListOptionIndex];
                    }
                    continue;
                }
                else if (res != GetResult.Point)
                {
                    return(Result.Cancel);
                }
                break;
            }

            Point3d point = gp.Point();

            Plane plane = gp.View().ActiveViewport.ConstructionPlane();

            plane.Origin = point;

            TextEntity text = new TextEntity();

            text.Plane         = plane;
            text.Justification = m_justification;
            text.Text          = text.Justification.ToString();

            doc.Objects.AddPoint(point);
            doc.Objects.AddText(text);
            doc.Views.Redraw();

            return(Result.Success);
        }
        //this function gets the first point from the user
        private Result GetFirstPoint(ref Point3d pt, Plane pl, bool IsFirstRun)
        {
            using (GetPoint getPointAction = new GetPoint())
            {
                if (IsFirstRun)
                {
                    getPointAction.AddOptionDouble("Width", ref this.width);
                    getPointAction.AddOptionDouble("RailHeight", ref this.railHeight);
                    getPointAction.AddOptionToggle("LeftRail", ref this.leftRail);
                    getPointAction.AddOptionToggle("RightRail", ref this.rightRail);
                }
                if (!IsFirstRun)
                {
                    getPointAction.AddOptionToggle("Landing", ref this.LandingToggle);
                }

                getPointAction.SetCommandPrompt("Begin making stairs. Select the starting point of the run");
                if (!IsFirstRun)
                {
                    getPointAction.Constrain(pl, false);
                }

                while (true)
                {
                    GetResult get_rc = getPointAction.Get();
                    if (getPointAction.CommandResult() != Result.Success)
                    {
                        return(getPointAction.CommandResult());
                    }
                    if (get_rc == GetResult.Point)
                    {
                        pt = getPointAction.Point();
                    }
                    else if (get_rc == GetResult.Option)
                    {
                        continue;
                    }
                    break;
                }

                return(Result.Success);
            }
        }
Пример #27
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)                                    // всё происходит здесь внутри
        {
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);                  // сообщение в командной строке о том что команда запущена и что она будет делать
                                                                                                            //
            Point3d pt0;                                                                                    // декларируем новую переменную точка (начало линии)

            using (GetPoint getPointAction = new GetPoint())                                                // ??
            {                                                                                               //
                getPointAction.SetCommandPrompt("Please select the start point");                           // призыв к действию в командной строке (жирным)
                if (getPointAction.Get() != GetResult.Point)                                                // что делать если точкка не выбрана но был нажет Enter
                {                                                                                           //
                    RhinoApp.WriteLine("No start point was selected.");                                     // если точкка не выбрана но был нажет Enter, то написать это в командной строке
                    return(getPointAction.CommandResult());                                                 // ??
                }                                                                                           //
                pt0 = getPointAction.Point();                                                               // присвоить для переменной pt1 только что выбранную точку
            }

            Point3d pt1;                                                                                    // декларируе новую переменную точка ( конец линии)

            using (GetPoint getPointAction = new GetPoint())
            {                                                                                               //
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DynamicDraw +=
                    (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
                if (getPointAction.Get() != GetResult.Point)                                                // если точкка не выбрана но был нажет Enter
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();                                                               // присвоить для переменной pt1 только что выбранную точку
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);             // сообщение в командную строку что всё готово

            // ---

            return(Result.Success);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DrawLineFromPoint(pt0, true);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }
            Rhino.Geometry.Line line1 = new Line(pt0, pt1);
            doc.Objects.AddLine(line1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);
            RhinoApp.WriteLine("The distance between the two points is {0} {1}.", line1.Length, doc.ModelUnitSystem.ToString().ToLower());

            return(Result.Success);
        }
        public TrackingPointGetter(string prompt, CurvesTopology crvTopology, int fromIndex, SearchMode mode)
        {
            _crvTopology = crvTopology;
            _fromIndex   = fromIndex;

            if (!Enum.IsDefined(typeof(SearchMode), mode))
            {
                throw new ArgumentException("Enum is undefined.", "mode");
            }
            _sm = mode;


            if (!string.IsNullOrEmpty(prompt))
            {
                _getPoint.SetCommandPrompt(prompt);
            }

            if (fromIndex != -1)
            {
                switch (mode)
                {
                case SearchMode.CurveLength:
                    _distances = crvTopology.MeasureAllEdgeLengths();
                    break;

                case SearchMode.LinearDistance:
                    _distances = crvTopology.MeasureAllEdgeLinearDistances();
                    break;

                case SearchMode.Links:
                    _distances = null;
                    break;

                default:
                    throw new ApplicationException("Behaviour for this enum value is undefined.");
                }
            }
            _getPoint.DynamicDraw += DynamicDraw;

            _pathSearchMethod = PathMethod.FromMode(_sm, _crvTopology, _distances);
        }
Пример #30
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Center of circle");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var view = gp.View();

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

            var plane = view.ActiveViewport.ConstructionPlane();

            plane.Origin = gp.Point();

            var gr = new GetRadiusPoint(plane);

            gr.SetCommandPrompt("Radius");
            gr.Get();
            if (gr.CommandResult() != Result.Success)
            {
                return(gr.CommandResult());
            }

            if (gr.CalculateCircle(gr.Point()))
            {
                doc.Objects.AddCircle(gr.Circle);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }