Ejemplo n.º 1
0
    public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc)
    {
        // For this example we will use a GetPoint class, but all of the custom
        // "Get" classes support command line options.
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("GetPoint with options");

        // set up the options
        Rhino.Input.Custom.OptionInteger intOption  = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
        Rhino.Input.Custom.OptionDouble  dblOption  = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
        Rhino.Input.Custom.OptionToggle  boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
        string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

        gp.AddOptionInteger("Integer", ref intOption);
        gp.AddOptionDouble("Double", ref dblOption);
        gp.AddOptionToggle("Boolean", ref boolOption);
        int listIndex = 3;
        int opList    = gp.AddOptionList("List", listValues, listIndex);

        while (true)
        {
            // perform the get operation. This will prompt the user to input a point, but also
            // allow for command line options defined above
            Rhino.Input.GetResult get_rc = gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gp.CommandResult());
            }

            if (get_rc == Rhino.Input.GetResult.Point)
            {
                doc.Objects.AddPoint(gp.Point());
                doc.Views.Redraw();
                Rhino.RhinoApp.WriteLine("Command line option values are");
                Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
                Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]);
            }
            else if (get_rc == Rhino.Input.GetResult.Option)
            {
                if (gp.OptionIndex() == opList)
                {
                    listIndex = gp.Option().CurrentListOptionIndex;
                }
                continue;
            }
            break;
        }
        return(Rhino.Commands.Result.Success);
    }
    public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc)
    {
        // For this example we will use a GetPoint class, but all of the custom
        // "Get" classes support command line options.
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("GetPoint with options");

        // set up the options
        Rhino.Input.Custom.OptionInteger intOption = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
        Rhino.Input.Custom.OptionDouble dblOption = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
        Rhino.Input.Custom.OptionToggle boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
        string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

        gp.AddOptionInteger("Integer", ref intOption);
        gp.AddOptionDouble("Double", ref dblOption);
        gp.AddOptionToggle("Boolean", ref boolOption);
        int listIndex = 3;
        int opList = gp.AddOptionList("List", listValues, listIndex);

        while (true)
        {
          // perform the get operation. This will prompt the user to input a point, but also
          // allow for command line options defined above
          Rhino.Input.GetResult get_rc = gp.Get();
          if (gp.CommandResult() != Rhino.Commands.Result.Success)
        return gp.CommandResult();

          if (get_rc == Rhino.Input.GetResult.Point)
          {
        doc.Objects.AddPoint(gp.Point());
        doc.Views.Redraw();
        Rhino.RhinoApp.WriteLine("Command line option values are");
        Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
        Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]);
          }
          else if (get_rc == Rhino.Input.GetResult.Option)
          {
        if (gp.OptionIndex() == opList)
          listIndex = gp.Option().CurrentListOptionIndex;
        continue;
          }
          break;
        }
        return Rhino.Commands.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);
        }
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
        Rhino.DocObjects.ObjRef objref;
        var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref);

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

        rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        var obj = objref.Object();

        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // create an instance of a GetPoint class and add a delegate
        // for the DynamicDraw event
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.DrawLineFromPoint(m_point_start, true);
        var  optdouble    = new Rhino.Input.Custom.OptionDouble(m_distance);
        bool constrain    = false;
        var  optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On");

        gp.AddOptionDouble("Distance", ref optdouble);
        gp.AddOptionToggle("Constrain", ref optconstrain);
        gp.DynamicDraw += ArrayByDistanceDraw;
        gp.Tag          = obj;
        while (gp.Get() == Rhino.Input.GetResult.Option)
        {
            m_distance = optdouble.CurrentValue;
            if (constrain != optconstrain.CurrentValue)
            {
                constrain = optconstrain.CurrentValue;
                if (constrain)
                {
                    var gp2 = new Rhino.Input.Custom.GetPoint();
                    gp2.DrawLineFromPoint(m_point_start, true);
                    gp2.SetCommandPrompt("Second point on constraint line");
                    if (gp2.Get() == Rhino.Input.GetResult.Point)
                    {
                        gp.Constrain(m_point_start, gp2.Point());
                    }
                    else
                    {
                        gp.ClearCommandOptions();
                        optconstrain.CurrentValue = false;
                        constrain = false;
                        gp.AddOptionDouble("Distance", ref optdouble);
                        gp.AddOptionToggle("Constrain", ref optconstrain);
                    }
                }
                else
                {
                    gp.ClearConstraints();
                }
            }
        }

        if (gp.CommandResult() == Rhino.Commands.Result.Success)
        {
            m_distance = optdouble.CurrentValue;
            var    pt     = gp.Point();
            var    vec    = pt - m_point_start;
            double length = vec.Length;
            vec.Unitize();
            int count = (int)(length / m_distance);
            for (int i = 1; i < count; i++)
            {
                var translate = vec * (i * m_distance);
                var xf        = Rhino.Geometry.Transform.Translation(translate);
                doc.Objects.Transform(obj, xf, false);
            }
            doc.Views.Redraw();
        }

        return(gp.CommandResult());
    }
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;
    }