Ejemplo n.º 1
0
        /// <summary>
        /// Simple version of the above method that only returns a single vertex
        /// Does not add any properties to the vertex.
        /// </summary>
        /// <returns></returns>
        public IList <PFVertex> PickVertexSingle()
        {
            var innerVerts    = Vertices.Where(x => !x.External);
            var pickedVerts   = new List <PFVertex>();
            var doc           = Rhino.RhinoDoc.ActiveDoc;
            var vertexConduit = new DrawPFVertexConduit(innerVerts)
            {
                Enabled = true
            };

            doc.Views.Redraw();
            var gVert = new GetPFVertex(innerVerts);

            gVert.AddSnapPoints(innerVerts.Select(x => x.Point).ToArray());
            while (true)
            {
                gVert.SetCommandPrompt("select Vertex points. (<ESC> to exit");
                gVert.AcceptNothing(true);
                gVert.AcceptString(true);
                //gVert.SetCursor() // this we can change after switching to Rhino 6 - api

                gVert.SetDefaultString($"({pickedVerts.Count}) vertices selected press <Enter> to accept");
                gVert.Get(true);


                doc.Views.Redraw();
                var result    = gVert.CommandResult();
                var strResult = gVert.StringResult();
                pickedVerts = new List <PFVertex>();
                if (gVert.CommandResult() == Rhino.Commands.Result.Cancel)
                {
                    break;
                }
                bool brkFlag = false;
                foreach (var vrt in innerVerts)
                {
                    if (vrt.Picked)
                    {
                        pickedVerts.Add(vrt);
                        brkFlag = true;
                        break; // remove this for multiple picks
                    }
                }
                if (brkFlag)
                {
                    break;
                }
            }
            vertexConduit.Enabled = false;
            doc.Views.Redraw();

            return(pickedVerts);
        }
Ejemplo n.º 2
0
        public IList <PFVertex> PickVertex()
        {
            var innerVerts    = Vertices.Where(x => !x.External);
            var pickedVerts   = new List <PFVertex>();
            var doc           = Rhino.RhinoDoc.ActiveDoc;
            var vertexConduit = new DrawPFVertexConduit(innerVerts)
            {
                Enabled = true
            };

            doc.Views.Redraw();
            var gVert = new GetPFVertex(innerVerts);

            //var permOption = new OptionToggle(false, "temp", "perm");
            gVert.AddSnapPoints(innerVerts.Select(x => x.Point).ToArray());
            while (true)
            {
                gVert.SetCommandPrompt("select Vertex points. (<ESC> to exit");
                //gVert.AddOptionToggle("Remember", ref permOption);
                gVert.AcceptNothing(true);
                gVert.AcceptString(true);
                //gVert.SetCursor() // this we can change after switching to Rhino 6 - api

                gVert.SetDefaultString($"({pickedVerts.Count}) vertices selected press <Enter> to accept");
                gVert.Get(true);


                doc.Views.Redraw();
                var result    = gVert.CommandResult();
                var strResult = gVert.StringResult();
                pickedVerts = new List <PFVertex>();
                if (gVert.CommandResult() == Rhino.Commands.Result.Cancel)
                {
                    break;
                }
                foreach (var vrt in innerVerts)
                {
                    if (vrt.Picked)
                    {
                        pickedVerts.Add(vrt);
                    }
                }
                if (gVert.GotDefault())
                {
                    // here use a pick mechanism to get the geometry
                    if (pickedVerts.Count > 0)
                    {
                        var outside   = new OptionToggle(true, "true", "false");
                        var fixPoint  = new OptionToggle(false, "constrain", "fix");
                        var getRefGeo = new GetObject();
                        getRefGeo.SetCommandPrompt("Pick the constrain object for the selected vertices");

                        getRefGeo.AddOptionToggle("Outside", ref outside);
                        getRefGeo.AddOptionToggle("Fixed", ref fixPoint);
                        getRefGeo.AcceptNothing(true);
                        getRefGeo.DisablePreSelect();



                        if (getRefGeo.Get() == Rhino.Input.GetResult.Object)
                        {
                            var geoGet = getRefGeo.Object(0);
                            var idGet  = getRefGeo.Object(0).ObjectId;

                            SetVertexConstraints(pickedVerts, geoGet.Object(), 1, outside.CurrentValue);
                        }

                        else if (getRefGeo.Result() == Rhino.Input.GetResult.Nothing)
                        {
                            foreach (var vert in pickedVerts)
                            {
                                vert.RestrictPosition = null;
                                vert.RestrictSupport  = null;
                                vert.SupportGuid      = Guid.Empty;
                            }
                        }

                        else if (getRefGeo.Result() == Rhino.Input.GetResult.Option && fixPoint.CurrentValue == true)
                        {
                            foreach (var vert in pickedVerts)
                            {
                                vert.RestrictPosition = vert.ConstrainPoint;
                                vert.RestrictSupport  = new Rhino.Geometry.Point(vert.Point); // this is what keeps the vertex in place
                                vert.InfluenceCoef    = 100;                                  // this is what makes it relatively immovable
                                vert.SupportGuid      = Guid.Empty;
                                vert.Fixed            = true;                                 // this is just for serilization refference
                            }
                        }
                        doc.Objects.UnselectAll();
                        pickedVerts.ForEach(x => x.Picked = false);
                        doc.Views.Redraw();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            vertexConduit.Enabled = false;
            doc.Views.Redraw();

            return(pickedVerts);
        }