Ejemplo n.º 1
0
        /// <summary>
        /// Adds any objects you want transformed and grips you want transformed.
        /// Make sure no duplicates are in the list and that no grip ownwers are
        /// passed in as objects.
        /// </summary>
        /// <param name="list">A custom transform object list.</param>
        public void AddTransformObjects(Rhino.Collections.TransformObjectList list)
        {
            IntPtr pThis      = NonConstPointer();
            IntPtr pConstList = list.ConstPointer();

            UnsafeNativeMethods.CRhinoGetXform_AppendObjects(pThis, pConstList);
        }
Ejemplo n.º 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var list = new Rhino.Collections.TransformObjectList();
            var rc   = SelectObjects("Select objects to move", list);

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

            var gp = new GetPoint();

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


            var gt = new GetTranslation();

            gt.SetCommandPrompt("Point to move to");
            gt.SetBasePoint(gp.Point(), true);
            gt.DrawLineFromPoint(gp.Point(), true);
            gt.AddTransformObjects(list);
            gt.GetXform();
            if (gt.CommandResult() != Result.Success)
            {
                return(gt.CommandResult());
            }

            var xform = gt.CalculateTransform(gt.View().ActiveViewport, gt.Point());

            TransformObjects(list, xform, false, false);
            doc.Views.Redraw();
            return(Result.Success);
        }
Ejemplo n.º 3
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Select objects to scale
            var list = new Rhino.Collections.TransformObjectList();
            var rc   = SelectObjects("Select objects to scale", list);

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

            Point3d anchor;
            Point3d _ref;
            Plane   plane;

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

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

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

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

            bool bAcceptDefault = true;

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

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

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

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

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

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

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

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

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

                    break;
                }

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

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

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

                break;
            }

            doc.Views.Redraw();
            return(rc);
        }
Ejemplo n.º 4
0
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
      // Select objects to scale
      var list = new Rhino.Collections.TransformObjectList();
      var rc = SelectObjects("Select objects to gumball", list);
      if (rc != Rhino.Commands.Result.Success)
        return rc;

      var bbox = list.GetBoundingBox(true, true);
      if (!bbox.IsValid)
        return Rhino.Commands.Result.Failure;

      Rhino.Commands.Result cmdrc;

      var base_gumball = new Rhino.UI.Gumball.GumballObject();
      base_gumball.SetFromBoundingBox(bbox);
      var dc = new Rhino.UI.Gumball.GumballDisplayConduit();
      var appearance = new Rhino.UI.Gumball.GumballAppearanceSettings();

      // turn off some of the scale appearance settings to have a slightly different gumball
      appearance.ScaleXEnabled = false;
      appearance.ScaleYEnabled = false;
      appearance.ScaleZEnabled = false;

      bool bCopy = false;
      while (true)
      {
        dc.SetBaseGumball(base_gumball, appearance);
        dc.Enabled = true;
        doc.Views.Redraw();

        GetGumballXform gp = new GetGumballXform(dc);
        int copy_optindx = gp.AddOption("Copy");
        if (dc.PreTransform == Transform.Identity)
          gp.SetCommandPrompt("Drag gumball");
        else
        {
          gp.AcceptNothing(true);
          gp.SetCommandPrompt("Drag gumball. Press Enter when done");
        }
        gp.AddTransformObjects(list);
        gp.MoveGumball();
        dc.Enabled = false;
        cmdrc = gp.CommandResult();
        if (cmdrc != Rhino.Commands.Result.Success)
          break;

        var getpoint_result = gp.Result();
        if (getpoint_result == Rhino.Input.GetResult.Point)
        {
          if (!dc.InRelocate)
          {
            Transform xform = dc.TotalTransform;
            dc.PreTransform = xform;
          }
          // update location of base gumball
          var gbframe = dc.Gumball.Frame;
          var baseFrame = base_gumball.Frame;
          baseFrame.Plane = gbframe.Plane;
          baseFrame.ScaleGripDistance = gbframe.ScaleGripDistance;
          base_gumball.Frame = baseFrame;
          continue;
        }
        if (getpoint_result == Rhino.Input.GetResult.Option)
        {
          if (gp.OptionIndex() == copy_optindx)
            bCopy = true;
          continue;
        }

        break;
      }

      dc.Enabled = false;
      if (dc.PreTransform != Transform.Identity)
      {
        Transform xform = dc.PreTransform;
        TransformObjects(list, xform, bCopy, bCopy);
      }
      doc.Views.Redraw();
      return cmdrc;
    }
Ejemplo n.º 5
0
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
      // Select objects to scale
      var list = new Rhino.Collections.TransformObjectList();
      var rc = SelectObjects("Select objects to scale", list);
      if (rc != Rhino.Commands.Result.Success)
        return rc;

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

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

        return Rhino.Commands.Result.Cancel;
      }

      bool bAcceptDefault = true;

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

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

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

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

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

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

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

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

          break;
        }

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

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

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

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

        break;
      }

      doc.Views.Redraw();
      return rc;
    }
Ejemplo n.º 6
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Select objects to scale
            var list = new Rhino.Collections.TransformObjectList();
            var rc   = SelectObjects("Select objects to gumball", list);

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

            var bbox = list.GetBoundingBox(true, true);

            if (!bbox.IsValid)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Commands.Result cmdrc;

            var base_gumball = new Rhino.UI.Gumball.GumballObject();

            base_gumball.SetFromBoundingBox(bbox);
            var dc         = new Rhino.UI.Gumball.GumballDisplayConduit();
            var appearance = new Rhino.UI.Gumball.GumballAppearanceSettings();

            // turn off some of the scale appearance settings to have a slightly different gumball
            appearance.ScaleXEnabled = false;
            appearance.ScaleYEnabled = false;
            appearance.ScaleZEnabled = false;

            bool bCopy = false;

            while (true)
            {
                dc.SetBaseGumball(base_gumball, appearance);
                dc.Enabled = true;
                doc.Views.Redraw();

                GetGumballXform gp           = new GetGumballXform(dc);
                int             copy_optindx = gp.AddOption("Copy");
                if (dc.PreTransform == Transform.Identity)
                {
                    gp.SetCommandPrompt("Drag gumball");
                }
                else
                {
                    gp.AcceptNothing(true);
                    gp.SetCommandPrompt("Drag gumball. Press Enter when done");
                }
                gp.AddTransformObjects(list);
                gp.MoveGumball();
                dc.Enabled = false;
                cmdrc      = gp.CommandResult();
                if (cmdrc != Rhino.Commands.Result.Success)
                {
                    break;
                }

                var getpoint_result = gp.Result();
                if (getpoint_result == Rhino.Input.GetResult.Point)
                {
                    if (!dc.InRelocate)
                    {
                        Transform xform = dc.TotalTransform;
                        dc.PreTransform = xform;
                    }
                    // update location of base gumball
                    var gbframe   = dc.Gumball.Frame;
                    var baseFrame = base_gumball.Frame;
                    baseFrame.Plane             = gbframe.Plane;
                    baseFrame.ScaleGripDistance = gbframe.ScaleGripDistance;
                    base_gumball.Frame          = baseFrame;
                    continue;
                }
                if (getpoint_result == Rhino.Input.GetResult.Option)
                {
                    if (gp.OptionIndex() == copy_optindx)
                    {
                        bCopy = true;
                    }
                    continue;
                }

                break;
            }

            dc.Enabled = false;
            if (dc.PreTransform != Transform.Identity)
            {
                Transform xform = dc.PreTransform;
                TransformObjects(list, xform, bCopy, bCopy);
            }
            doc.Views.Redraw();
            return(cmdrc);
        }