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;
    }
Exemple #2
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);
        }