示例#1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

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

            using (var object_list = new TransformObjectList())
            {
                object_list.AddObjects(go, true);

                var dir   = new Vector3d(5, 0, 0); // 5 units in world x-axis direction
                var xform = Transform.Translation(dir);

                foreach (var grip in object_list.GripArray())
                {
                    grip.Move(xform);
                }

                foreach (var owner in object_list.GripOwnerArray())
                {
                    doc.Objects.GripUpdate(owner, true);
                }

                doc.Views.Redraw();
            }

            return(Result.Success);
        }
示例#2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Result    rc  = Result.Nothing;
            GetResult res = GetResult.Nothing;

            // Select objects to rotate
            TransformObjectList list = new TransformObjectList();

            rc = SelectObjects("Select objects to transform", list);
            if (rc != Result.Success)
            {
                return(rc);
            }

            OptionToggle opt_xset = new OptionToggle(true, "No", "Yes");
            OptionToggle opt_yset = new OptionToggle(true, "No", "Yes");
            OptionToggle opt_zset = new OptionToggle(true, "No", "Yes");

            // Second reference point
            GetSetPointTransform gx = new GetSetPointTransform(true, true, true);

            gx.SetCommandPrompt("Location for points");
            gx.AddTransformObjects(list);
            for (;;)
            {
                gx.ClearCommandOptions();
                gx.AddOptionToggle("XSet", ref opt_xset);
                gx.AddOptionToggle("YSet", ref opt_yset);
                gx.AddOptionToggle("ZSet", ref opt_zset);

                res = gx.GetXform();

                if (res == GetResult.Point)
                {
                    RhinoView view = gx.View();
                    rc = (null != view) ? Result.Success : Result.Failure;
                    if (rc == Result.Success)
                    {
                        Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
                        rc = (xform.IsValid) ? Result.Success : Result.Failure;
                        if (rc == Result.Success)
                        {
                            TransformObjects(list, xform, false, false);
                            doc.Views.Redraw();
                        }
                    }
                }
                else if (res == GetResult.Option)
                {
                    gx.SetX = opt_xset.CurrentValue;
                    gx.SetY = opt_yset.CurrentValue;
                    gx.SetZ = opt_zset.CurrentValue;
                    continue;
                }
                else
                {
                    rc = Result.Cancel;
                }

                break;
            }

            return(rc);
        }
示例#3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Locals
            Plane     plane;
            Point3d   base_point = Point3d.Unset;
            Point3d   ref_point  = Point3d.Unset;
            GetResult res        = GetResult.Nothing;
            Result    rc         = Result.Nothing;


            // Select objects to rotate
            TransformObjectList list = new TransformObjectList();

            rc = SelectObjects("Select objects to rotate", list);
            if (rc != Result.Success)
            {
                return(rc);
            }

            GetPoint gp = new GetPoint();

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

            RhinoView view = gp.View();

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

            base_point   = gp.Point();
            plane        = view.ActiveViewport.ConstructionPlane();
            plane.Origin = base_point;


            // Angle or first reference point
            GetReferencePoint gr = new GetReferencePoint(base_point);

            gr.SetCommandPrompt("Angle or first reference point");
            res = gr.Get();
            if (res == GetResult.Point)
            {
                view = gr.View();
                rc   = (null != view) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    plane        = view.ActiveViewport.ConstructionPlane();
                    plane.Origin = base_point;
                    ref_point    = plane.ClosestPoint(gr.Point());
                    if (base_point.DistanceTo(ref_point) <= RhinoMath.ZeroTolerance)
                    {
                        rc = Result.Nothing;
                    }
                }
                if (rc != Result.Success)
                {
                    return(rc);
                }
            }
            else if (res == GetResult.Number)
            {
                Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gr.Number()), plane.Normal, base_point);
                rc = (xform.IsValid) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    TransformObjects(list, xform, false, false);
                    doc.Views.Redraw();
                }
                return(rc);
            }
            else
            {
                return(Result.Cancel);
            }


            // Second reference point
            GetRotationTransform gx = new GetRotationTransform(plane, base_point, ref_point);

            gx.SetCommandPrompt("Second reference point");
            gx.AddTransformObjects(list);
            res = gx.GetXform();
            if (res == GetResult.Point)
            {
                view = gx.View();
                rc   = (null != view) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
                    rc = (xform.IsValid) ? Result.Success : Result.Failure;
                    if (rc == Result.Success)
                    {
                        TransformObjects(list, xform, false, false);
                        doc.Views.Redraw();
                    }
                }
            }
            else if (res == GetResult.Number)
            {
                Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gx.Number()), plane.Normal, base_point);
                rc = (xform.IsValid) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    TransformObjects(list, xform, false, false);
                    doc.Views.Redraw();
                }
            }
            else
            {
                rc = Result.Cancel;
            }

            return(rc);
        }