Beispiel #1
0
    public static Rhino.Commands.Result SpriteDrawing(RhinoDoc doc)
    {
        var sprite_mode  = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite");
        var size_option  = new Rhino.Input.Custom.OptionDouble(m_sprite_size);
        var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World");
        var go           = new Rhino.Input.Custom.GetOption();

        go.SetCommandPrompt("Sprite drawing mode");
        go.AddOptionToggle("Mode", ref sprite_mode);
        go.AddOptionDouble("Size", ref size_option);
        go.AddOptionToggle("DrawSpace", ref space_option);
        int option_go   = go.AddOption("Spin");
        int option_file = go.AddOption("FileSprite");

        Rhino.Display.DisplayPipeline.PostDrawObjects      += DisplayPipeline_PostDrawObjects;
        Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox;

        doc.Views.Redraw();
        while (go.Get() == Rhino.Input.GetResult.Option)
        {
            m_draw_single_sprite  = sprite_mode.CurrentValue;
            m_sprite_size         = (float)size_option.CurrentValue;
            m_draw_world_location = space_option.CurrentValue;
            if (go.OptionIndex() == option_go)
            {
                var gs = new Rhino.Input.Custom.GetOption();
                gs.SetCommandPrompt("press enter/escape to end");
                gs.SetWaitDuration(1);

                var vp = doc.Views.ActiveView.MainViewport;
                while (gs.Get() == Rhino.Input.GetResult.Timeout)
                {
                    vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin);
                    doc.Views.Redraw();
                }
            }
            else if (go.OptionIndex() == option_file)
            {
                var dlg = new Rhino.UI.OpenFileDialog();
                if (dlg.ShowDialog())
                {
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName);
                    m_sprite = new Rhino.Display.DisplayBitmap(bmp);
                }
                doc.Views.Redraw();
            }
            else
            {
                doc.Views.Redraw();
            }
        }

        Rhino.Display.DisplayPipeline.PostDrawObjects      -= DisplayPipeline_PostDrawObjects;
        Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox;
        return(Rhino.Commands.Result.Success);
    }
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
      var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite");
      var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size);
      var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World");
      var go = new Rhino.Input.Custom.GetOption();
      go.SetCommandPrompt("Sprite drawing mode");
      go.AddOptionToggle("Mode", ref sprite_mode);
      go.AddOptionDouble("Size", ref size_option);
      go.AddOptionToggle("DrawSpace", ref space_option);
      int option_go = go.AddOption("Spin");
      int option_file = go.AddOption("FileSprite");

      Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects;
      Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox;

      doc.Views.Redraw();
      while (go.Get() == Rhino.Input.GetResult.Option)
      {
        m_draw_single_sprite = sprite_mode.CurrentValue;
        m_sprite_size = (float)size_option.CurrentValue;
        m_draw_world_location = space_option.CurrentValue;
        if (go.OptionIndex() == option_go)
        {
          var gs = new Rhino.Input.Custom.GetOption();
          gs.SetCommandPrompt("press enter/escape to end");
          gs.SetWaitDuration(1);

          var vp = doc.Views.ActiveView.MainViewport;
          while (gs.Get() == Rhino.Input.GetResult.Timeout)
          {
            vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin);
            doc.Views.Redraw();
          }
        }
        else if (go.OptionIndex() == option_file)
        {
          System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
          if (dlg.ShowDialog(RhinoApp.MainWindow()) == System.Windows.Forms.DialogResult.OK)
          {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName);
            m_sprite = new Rhino.Display.DisplayBitmap(bmp);
          }
          doc.Views.Redraw();
        }
        else
          doc.Views.Redraw();
      }

      Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects;
      Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox;
      return Rhino.Commands.Result.Success;
    }
        private void GetNestingSettings()
        {
            //Parameters
            Rhino.Input.Custom.GetOption gp = new Rhino.Input.Custom.GetOption();
            gp.SetCommandPrompt("OpenNest: Set nesting settings");

            Rhino.Input.Custom.OptionInteger Iterations     = new Rhino.Input.Custom.OptionInteger(1, 1, 100);
            Rhino.Input.Custom.OptionDouble  Spacing        = new Rhino.Input.Custom.OptionDouble(0.01, 0.001, 10);
            Rhino.Input.Custom.OptionInteger Placement      = new Rhino.Input.Custom.OptionInteger(1, 0, 4);
            Rhino.Input.Custom.OptionDouble  Tolerance      = new Rhino.Input.Custom.OptionDouble(0.1, 0.01, 10);
            Rhino.Input.Custom.OptionInteger Rotations      = new Rhino.Input.Custom.OptionInteger(4, 0, 360);
            Rhino.Input.Custom.OptionInteger Seed           = new Rhino.Input.Custom.OptionInteger(0, 1, 100);
            Rhino.Input.Custom.OptionDouble  ClosestObjects = new Rhino.Input.Custom.OptionDouble(0.01, 0, 100);

            gp.AddOptionInteger("Iterations", ref Iterations);
            gp.AddOptionDouble("Spacing", ref Spacing);
            gp.AddOptionInteger("Placement", ref Placement);
            gp.AddOptionDouble("Tolerance", ref Tolerance);
            gp.AddOptionInteger("Rotations", ref Rotations);
            gp.AddOptionInteger("Seed", ref Seed);
            gp.AddOptionDouble("ClosestObjects", ref ClosestObjects);

            while (true)
            {
                Rhino.Input.GetResult get_rc = gp.Get();
                if (gp.CommandResult() != Rhino.Commands.Result.Success)
                {
                    break;
                }
            }

            this.iterations    = Iterations.CurrentValue;
            this.spacing       = Spacing.CurrentValue;
            this.placementType = Placement.CurrentValue;
            this.tolerance     = Tolerance.CurrentValue;
            this.rotations     = Rotations.CurrentValue;
            this.seed          = Seed.CurrentValue;
            this.spacing      *= (1 / tolerance);
            this.cp            = ClosestObjects.CurrentValue;
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick some objects to smooth
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to smooth");
            go.SubObjectSelect       = false;
            go.ReferenceObjectSelect = false;
            go.GeometryFilter        = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Mesh;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            // Prompt for some command line options. In this case,
            // we will clone the -Smooth command.
            Rhino.Input.Custom.GetOption gs = new Rhino.Input.Custom.GetOption();
            gs.SetCommandPrompt("Choose smooth option");
            gs.AcceptNothing(true);
            for (; ;)
            {
                gs.ClearCommandOptions();

                Rhino.Input.Custom.OptionDouble smooth_factor_option  = new Rhino.Input.Custom.OptionDouble(m_smooth_factor);
                Rhino.Input.Custom.OptionToggle use_cplane_option     = new Rhino.Input.Custom.OptionToggle(m_use_cplane, "World", "CPlane");
                Rhino.Input.Custom.OptionToggle smooth_x_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_x, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_y_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_y, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_z_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_z, "No", "Yes");
                Rhino.Input.Custom.OptionToggle fix_boundaries_option = new Rhino.Input.Custom.OptionToggle(m_fix_boundaries, "No", "Yes");

                int smooth_factor_index  = gs.AddOptionDouble("SmoothFactor", ref smooth_factor_option);
                int use_cplane_index     = gs.AddOptionToggle("CoordinateSystem", ref use_cplane_option);
                int smooth_x_index       = gs.AddOptionToggle("X", ref smooth_x_option);
                int smooth_y_index       = gs.AddOptionToggle("Y", ref smooth_y_option);
                int smooth_z_index       = gs.AddOptionToggle("Z", ref smooth_z_option);
                int fix_boundaries_index = gs.AddOptionToggle("FixBoundaries", ref fix_boundaries_option);

                Rhino.Input.GetResult getrc = gs.Get();
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }

                if (getrc == Rhino.Input.GetResult.Option)
                {
                    int index = gs.OptionIndex();
                    if (index == smooth_factor_index)
                    {
                        m_smooth_factor = smooth_factor_option.CurrentValue;
                    }
                    else if (index == use_cplane_index)
                    {
                        m_use_cplane = use_cplane_option.CurrentValue;
                    }
                    else if (index == smooth_x_index)
                    {
                        m_smooth_x = smooth_x_option.CurrentValue;
                    }
                    else if (index == smooth_y_index)
                    {
                        m_smooth_y = smooth_y_option.CurrentValue;
                    }
                    else if (index == smooth_z_index)
                    {
                        m_smooth_z = smooth_z_option.CurrentValue;
                    }
                    else if (index == fix_boundaries_index)
                    {
                        m_fix_boundaries = fix_boundaries_option.CurrentValue;
                    }

                    continue;
                }

                break;
            }

            // Build a command line macro that we can script
            StringBuilder sb = new StringBuilder();

            sb.Append("_-Smooth ");
            sb.Append(string.Format("_SmoothFactor={0} ", m_smooth_factor));
            sb.Append(string.Format("_CoordinateSystem={0} ", m_use_cplane ? "_CPlane" : "_World"));
            sb.Append(string.Format("_X={0} ", m_smooth_x ? "_Yes" : "_No"));
            sb.Append(string.Format("_Y={0} ", m_smooth_y ? "_Yes" : "_No"));
            sb.Append(string.Format("_Z={0} ", m_smooth_z ? "_Yes" : "_No"));
            sb.Append(string.Format("_FixBoundaries={0} ", m_fix_boundaries ? "_Yes" : "_No"));
            sb.Append("_Enter");

            string script = sb.ToString();

#if (!RELEASE)
            Rhino.RhinoApp.WriteLine(script);
#endif

            // Script the smooth command
            Rhino.RhinoApp.RunScript(script, false);

            return(Result.Success);
        }