Ejemplo n.º 1
0
  // The following example code demonstrates how to modify advanced display settings using
  // the Rhino SDK. In this example, a display mode's mesh wireframe thickness (in pixels)
  // will be modified.
  public static Rhino.Commands.Result AdvancedDisplay(Rhino.RhinoDoc doc)
  {
    // Use the display attributes manager to build a list of display modes.
    // Note, these are copies of the originals...
    DisplayModeDescription[] display_modes = DisplayModeDescription.GetDisplayModes();
    if( display_modes==null || display_modes.Length<1 )
      return Rhino.Commands.Result.Failure;

    // Construct an options picker so the user can pick which
    // display mode they want modified
    Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
    go.SetCommandPrompt("Display mode to modify mesh thickness");
    List<int> opt_list = new List<int>();

    for( int i=0; i<display_modes.Length; i++ )
    {
      string english_name = display_modes[i].EnglishName;
      english_name = english_name.Replace("_", "");
      english_name = english_name.Replace(" ", "");
      english_name = english_name.Replace("-", "");
      english_name = english_name.Replace(",", "");
      english_name = english_name.Replace(".", "");
      int index = go.AddOption(english_name);
      opt_list.Add(index);
    }
    
    // Get the command option
    go.Get();
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    int selected_index = go.Option().Index;
    DisplayModeDescription selected_description = null;
    for( int i=0; i<opt_list.Count; i++ )
    {
      if( opt_list[i]==selected_index )
      {
        selected_description = display_modes[i];
        break;
      }
    }
 
    // Validate...
    if( selected_description==null )
      return Rhino.Commands.Result.Failure;

    // Modify the desired display mode. In this case, we
    // will just set the mesh wireframe thickness to zero.
    selected_description.DisplayAttributes.MeshSpecificAttributes.MeshWireThickness = 0;
    // Use the display attributes manager to update the display mode.
    DisplayModeDescription.UpdateDisplayMode(selected_description);

    // Force the document to regenerate.
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
Ejemplo n.º 2
0
        /// <summary>
        /// Called by Rhino when the user wants to run this command.
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            System.Guid panelId  = SampleCsWpfPanelHost.PanelId;
            bool        bVisible = Rhino.UI.Panels.IsPanelVisible(panelId);

            string prompt = (bVisible)
        ? "Sample panel is visible. New value"
        : "Sample Manager panel is hidden. New value";

            Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
            int hide_index   = go.AddOption("Hide");
            int show_index   = go.AddOption("Show");
            int toggle_index = go.AddOption("Toggle");

            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Input.Custom.CommandLineOption option = go.Option();
            if (null == option)
            {
                return(Rhino.Commands.Result.Failure);
            }

            int index = option.Index;

            if (index == hide_index)
            {
                if (bVisible)
                {
                    Rhino.UI.Panels.ClosePanel(panelId);
                }
            }
            else if (index == show_index)
            {
                if (!bVisible)
                {
                    Rhino.UI.Panels.OpenPanel(panelId);
                }
            }
            else if (index == toggle_index)
            {
                if (bVisible)
                {
                    Rhino.UI.Panels.ClosePanel(panelId);
                }
                else
                {
                    Rhino.UI.Panels.OpenPanel(panelId);
                }
            }
            return(Result.Success);
        }
Ejemplo n.º 3
0
    public static Rhino.Commands.Result ObjectDisplayMode(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = ObjectType.Mesh | ObjectType.Brep;
        ObjRef           objref;
        Result           rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh or surface", true, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Guid viewportId = doc.Views.ActiveView.ActiveViewportID;

        ObjectAttributes attr = objref.Object().Attributes;

        if (attr.HasDisplayModeOverride(viewportId))
        {
            RhinoApp.WriteLine("Removing display mode override from object");
            attr.RemoveDisplayModeOverride(viewportId);
        }
        else
        {
            Rhino.Display.DisplayModeDescription[] modes = Rhino.Display.DisplayModeDescription.GetDisplayModes();
            Rhino.Display.DisplayModeDescription   mode  = null;
            if (modes.Length == 1)
            {
                mode = modes[0];
            }
            else
            {
                Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Select display mode");
                string[] str_modes = new string[modes.Length];
                for (int i = 0; i < modes.Length; i++)
                {
                    str_modes[i] = modes[i].EnglishName.Replace(" ", "").Replace("-", "");
                }
                go.AddOptionList("DisplayMode", str_modes, 0);
                if (go.Get() == Rhino.Input.GetResult.Option)
                {
                    mode = modes[go.Option().CurrentListOptionIndex];
                }
            }
            if (mode == null)
            {
                return(Rhino.Commands.Result.Cancel);
            }
            attr.SetDisplayModeOverride(mode, viewportId);
        }
        doc.Objects.ModifyAttributes(objref, attr, false);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            System.Guid panelId = PanelTestUserControl.PanelId;
            bool bVisible = Rhino.UI.Panels.IsPanelVisible(panelId);

            string prompt = (bVisible)
              ? "Sample panel is visible. New value"
              : "Sample Manager panel is hidden. New value";

            Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
            int hide_index = go.AddOption("Hide");
            int show_index = go.AddOption("Show");
            int toggle_index = go.AddOption("Toggle");

            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
                return go.CommandResult();

            Rhino.Input.Custom.CommandLineOption option = go.Option();
            if (null == option)
                return Rhino.Commands.Result.Failure;

            int index = option.Index;

            if (index == hide_index)
            {
                if (bVisible)
                    Rhino.UI.Panels.ClosePanel(panelId);
            }
            else if (index == show_index)
            {
                if (!bVisible)
                    Rhino.UI.Panels.OpenPanel(panelId);
            }
            else if (index == toggle_index)
            {
                if (bVisible)
                    Rhino.UI.Panels.ClosePanel(panelId);
                else
                    Rhino.UI.Panels.OpenPanel(panelId);
            }

            return Rhino.Commands.Result.Success;
        }
Ejemplo n.º 5
0
  public static Rhino.Commands.Result ObjectDisplayMode(Rhino.RhinoDoc doc)
  {
    Rhino.Commands.Result rc = Rhino.Commands.Result.Cancel;
    ObjectType filter = ObjectType.Mesh | ObjectType.Brep;
    ObjRef objref;
    rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh or surface", true, filter, out objref);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    Guid viewportId = doc.Views.ActiveView.ActiveViewportID;

    ObjectAttributes attr = objref.Object().Attributes;
    if (attr.HasDisplayModeOverride(viewportId))
    {
      RhinoApp.WriteLine("Removing display mode override from object");
      attr.RemoveDisplayModeOverride(viewportId);
    }
    else
    {
      Rhino.Display.DisplayModeDescription[] modes = Rhino.Display.DisplayModeDescription.GetDisplayModes();
      Rhino.Display.DisplayModeDescription mode = null;
      if (modes.Length == 1)
        mode = modes[0];
      else
      {
        Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
        go.SetCommandPrompt("Select display mode");
        string[] str_modes = new string[modes.Length];
        for (int i = 0; i < modes.Length; i++)
          str_modes[i] = modes[i].EnglishName.Replace(" ", "").Replace("-", "");
        go.AddOptionList("DisplayMode", str_modes, 0);
        if (go.Get() == Rhino.Input.GetResult.Option)
          mode = modes[go.Option().CurrentListOptionIndex];
      }
      if (mode == null)
        return Rhino.Commands.Result.Cancel;
      attr.SetDisplayModeOverride(mode, viewportId);
    }
    doc.Objects.ModifyAttributes(objref, attr, false);
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var enabled = EventHandlers.Instance.IsEnabled;
            var prompt = enabled ? "Equal area transform mode is enabled." : "Equal area transform mode is disabled.";

            var go = new GetOption();
            go.SetCommandPrompt(prompt);
            go.AcceptNothing(true);

            var d_option = go.AddOption("Disable");
            var e_option = go.AddOption("Enable");

            var res = go.Get();
            if (res == GetResult.Nothing)
                return Result.Success;
            if (res != GetResult.Option)
                return Result.Cancel;

            var option = go.Option();
            if (null == option)
                return Result.Failure;

            if (d_option == option.Index)
            {
                if (enabled)
                {
                    EventHandlers.Instance.Enable(false);
                }
            }
            else if (e_option == option.Index)
            {
                if (!enabled)
                {
                    EventHandlers.Instance.Enable(true);
                }
            }

            return Result.Success;
        }
Ejemplo n.º 7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var pack_algorithm = PackingAlgorithm.Fast;
              Point3d base_point = new Point3d();
              var option_count = new OptionInteger(100, true, 2);
              var option_min_radius = new OptionDouble(0.1, true, 0.001);
              var option_max_radius = new OptionDouble(1.0, true, 0.001);
              var option_iterations = new OptionInteger(10000, false, 100);

              bool done_looping = false;
              while (!done_looping)
              {
            var gp = new GetPoint();
            gp.SetCommandPrompt("Center of fitting solution");
            gp.AddOptionInteger("Count", ref option_count);
            gp.AddOptionDouble("MinRadius", ref option_min_radius);
            gp.AddOptionDouble("MaxRadius", ref option_max_radius);
            gp.AddOptionInteger("IterationLimit", ref option_iterations);
            int index_option_packing = gp.AddOption("Packing", pack_algorithm.ToString());
            gp.AcceptNumber(true, true);

            switch( gp.Get() )
            {
              case GetResult.Point:
            base_point = gp.Point();
            done_looping = true;
            break;
              case GetResult.Option:
            if (index_option_packing == gp.OptionIndex())
            {
              var get_algorithm = new GetOption();
              get_algorithm.SetCommandPrompt("Packing");
              get_algorithm.SetDefaultString(pack_algorithm.ToString());
              var opts = new string[]{"Fast", "Double", "Random", "Simple"};
              int current_index = 0;
              switch(pack_algorithm)
              {
                case PackingAlgorithm.Fast:
                  current_index = 0;
                  break;
                case PackingAlgorithm.Double:
                  current_index = 1;
                  break;
                case PackingAlgorithm.Random:
                  current_index = 2;
                  break;
                case PackingAlgorithm.Simple:
                  current_index = 3;
                  break;
              }
              int index_list = get_algorithm.AddOptionList("algorithm", opts, current_index);
              get_algorithm.AddOption("Help");
              while( get_algorithm.Get() == GetResult.Option )
              {
                if (index_list == get_algorithm.OptionIndex())
                {
                  int index = get_algorithm.Option().CurrentListOptionIndex;
                  if (0 == index)
                    pack_algorithm = PackingAlgorithm.Fast;
                  if (1 == index)
                    pack_algorithm = PackingAlgorithm.Double;
                  if (2 == index)
                    pack_algorithm = PackingAlgorithm.Simple;
                  if (3 == index)
                    pack_algorithm = PackingAlgorithm.Random;
                  break;
                }
                // if we get here, the user selected help
                const string help =
                  @"Fast: fast packing prevents collisions by moving one
            circle away from all its intersectors. After every collision
            iteration, all circles are moved towards the centre of the
            packing to reduce the amount of wasted space. Collision
            detection proceeds from the center outwards.

            Double: similar to Fast, except that both circles are moved
            in case of a collision.

            Random: similar to Fast, except that collision detection is
            randomized rather than sorted.

            Simple: similar to Fast, but without a contraction pass
            after every collision iteration.";
                Rhino.UI.Dialogs.ShowMessageBox(help, "Packing algorithm description", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
              }
            }
            break;
              default:
            return Result.Cancel;
            }
              }
              int count = option_count.CurrentValue;
              double min_radius = option_min_radius.CurrentValue;
              double max_radius = option_max_radius.CurrentValue;
              int iterations = option_iterations.CurrentValue;

              // TODO: try setting up a background worker thread and
              // communicate with the GetString through messages
              //GetString gs = new GetString();
              //gs.SetCommandPrompt("Press escape to cancel");

              using (var all_circles = new PackCircles(base_point, count, min_radius, max_radius))
              {
            double damping = 0.1;
            for (int i = 1; i <= iterations; i++)
            {
              RhinoApp.SetCommandPrompt(string.Format("Performing circle packing iteration {0}...  (Press Shift+Ctrl to abort)", i));

              if (System.Windows.Forms.Control.ModifierKeys == (System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift))
              {
            RhinoApp.WriteLine("Circle fitting process aborted at iteration {0}...", i);
            break;
              }

              if (!all_circles.Pack(pack_algorithm, damping, doc.ModelAbsoluteTolerance))
              {
            RhinoApp.WriteLine("Circle fitting process completed at iteration {0}...", i);
            break;
              }

              damping *= 0.98;
              doc.Views.Redraw();
              RhinoApp.Wait();
            }
            all_circles.Add(doc);
              }
              doc.Views.Redraw();
              return Result.Success;
        }
    public static Result ConduitArrowHeads(RhinoDoc doc)
    {
        if (m_draw_conduit != null)
        {
          RhinoApp.WriteLine("Turn off existing arrowhead conduit");
          m_draw_conduit.Enabled = false;
          m_draw_conduit = null;
        }
        else
        {
          // get arrow head size
          var go = new GetOption();
          go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?");
          go.AddOption("screen");
          go.AddOption("world");
          go.Get();
          if (go.CommandResult() != Result.Success)
        return go.CommandResult();

          int screen_size = 0;
          double world_size = 0.0;
          if (go.Option().EnglishName == "screen")
          {
        var gi = new GetInteger();
        gi.SetLowerLimit(0, true);
        gi.SetCommandPrompt("Length of arrow head in pixels");
        gi.Get();
        if (gi.CommandResult() != Result.Success)
          return gi.CommandResult();
        screen_size = gi.Number();
          }
          else
          {
        var gi = new GetInteger();
        gi.SetLowerLimit(0, true);
        gi.SetUpperLimit(100, false);
        gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length");
        gi.Get();
        if (gi.CommandResult() != Result.Success)
          return gi.CommandResult();
        world_size = gi.Number() / 100.0;
          }

          // get arrow start and end points
          var gp = new GetPoint();
          gp.SetCommandPrompt("Start of line");
          gp.Get();
          if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
          var start_point = gp.Point();

          gp.SetCommandPrompt("End of line");
          gp.SetBasePoint(start_point, false);
          gp.DrawLineFromPoint(start_point, true);
          gp.Get();
          if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
          var end_point = gp.Point();

          var v = end_point - start_point;
          if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance))
        return Result.Nothing;

          var line = new Line(start_point, end_point);

          m_draw_conduit = new DrawArrowHeadsConduit(line, screen_size, world_size);
          // toggle conduit on/off
          m_draw_conduit.Enabled = true;
          RhinoApp.WriteLine("Draw arrowheads conduit enabled.");
        }
        doc.Views.Redraw();
        return Result.Success;
    }
Ejemplo n.º 9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // --- Set tolerance

            _unit = doc.ModelAbsoluteTolerance;


            // --- Get Mesh

            var getMesh = new GetObject { GeometryFilter = ObjectType.Mesh };
            getMesh.SetCommandPrompt("Select mesh");

            while (true)
            {
                var getMeshResult = getMesh.Get();

                if (getMesh.CommandResult() != Result.Success)
                    return getMesh.CommandResult();

                if (getMeshResult == GetResult.Object)
                    break;
            }

            _mesh = (Mesh)getMesh.Object(0).Geometry();

            doc.Objects.UnselectAll();


            // --- Start preview
            
            DisplayPipeline.DrawOverlay += DisplayPipelineOnDrawOverlay;


            // --- Get options

            var getOptions = new GetOption();
            getOptions.SetCommandPrompt("Settings:");
            getOptions.AddOptionInteger("CountX", ref _countX);
            getOptions.AddOptionInteger("CountY", ref _countY);
            getOptions.AddOptionDouble("Thickness", ref _thickness);
            getOptions.AddOption("Plane");
            getOptions.AddOptionDouble("Deeper", ref _deeper);
            getOptions.AddOptionToggle("DeleteInput", ref _deleteSource);
            getOptions.AddOptionToggle("Project", ref _project);
            getOptions.AddOptionDouble("ProjectSpace", ref _projectSpace);
            getOptions.AcceptNothing(true);

            do
            {
                doc.Views.Redraw();

                getOptions.Get();

                switch (getOptions.Result())
                {
                    case GetResult.Option:
                        switch (getOptions.Option().EnglishName)
                        {
                            case "Plane":
                                _plane = PlaneGetter.GetPlane() ?? _plane;
                                break;
                        }
                        break;
                }
            } while (getOptions.CommandResult() == Result.Success && getOptions.Result() != GetResult.Nothing);


            // --- Stop preview

            DisplayPipeline.DrawOverlay -= DisplayPipelineOnDrawOverlay;


            // --- Check for cancel with ESC

            if (getOptions.Result() == GetResult.Cancel)
                return Result.Cancel;


            // --- Execute

            var result = Waffle.Create(_mesh, _plane, _thickness.CurrentValue, _deeper.CurrentValue, _countX.CurrentValue, _countY.CurrentValue, _unit, _project.CurrentValue, _projectSpace.CurrentValue);


            // --- Add objects

            foreach (var curves in result.CurvesX)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));

            foreach (var curves in result.CurvesY)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));


            // --- Delete input

            if (_deleteSource.CurrentValue)
                doc.Objects.Delete(getMesh.Object(0).ObjectId, true);


            // --- Update views

            doc.Views.Redraw();


            return Result.Success;
        }
Ejemplo n.º 10
0
    // The following example code demonstrates how to modify advanced display settings using
    // the Rhino SDK. In this example, a display mode's mesh wireframe thickness (in pixels)
    // will be modified.
    public static Rhino.Commands.Result AdvancedDisplay(Rhino.RhinoDoc doc)
    {
        // Use the display attributes manager to build a list of display modes.
        // Note, these are copies of the originals...
        DisplayModeDescription[] display_modes = DisplayModeDescription.GetDisplayModes();
        if (display_modes == null || display_modes.Length < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Construct an options picker so the user can pick which
        // display mode they want modified
        Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
        go.SetCommandPrompt("Display mode to modify mesh thickness");
        List <int> opt_list = new List <int>();

        for (int i = 0; i < display_modes.Length; i++)
        {
            string english_name = display_modes[i].EnglishName;
            english_name = english_name.Replace("_", "");
            english_name = english_name.Replace(" ", "");
            english_name = english_name.Replace("-", "");
            english_name = english_name.Replace(",", "");
            english_name = english_name.Replace(".", "");
            int index = go.AddOption(english_name);
            opt_list.Add(index);
        }

        // Get the command option
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        int selected_index = go.Option().Index;
        DisplayModeDescription selected_description = null;

        for (int i = 0; i < opt_list.Count; i++)
        {
            if (opt_list[i] == selected_index)
            {
                selected_description = display_modes[i];
                break;
            }
        }

        // Validate...
        if (selected_description == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Modify the desired display mode. In this case, we
        // will just set the mesh wireframe thickness to zero.
        selected_description.DisplayAttributes.MeshSpecificAttributes.MeshWireThickness = 0;
        // Use the display attributes manager to update the display mode.
        DisplayModeDescription.UpdateDisplayMode(selected_description);

        // Force the document to regenerate.
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var options = new GetOption();
            options.SetCommandPrompt("Rhino-Pong");
            var indexLevel = options.AddOption("Level");
            var indexShowFps = options.AddOption("ShowFPS");
            var indexSetFps = options.AddOption("SetFPS");
            var indexSound = options.AddOption("Sound");
            var indexReset = options.AddOption("Reset");
            var indexExit = options.AddOption("Exit");

            var levelOptions = new GetOption();
            levelOptions.SetCommandPrompt("Select Level");



            var indexLevelEasy = levelOptions.AddOption("Easy");
            var indexLevelMedium = levelOptions.AddOption("Medium");
            var indexLevelHard = levelOptions.AddOption("Hard");
            var indexLevelImpossible = levelOptions.AddOption("Impossible");

            var game = new Pong();
            game.OnStopGame += (o, e) => RhinoApp.SendKeystrokes("!", true);
            game.StartGame();

            while (true)
            {
                options.Get();
                var slectedOption = options.Option();
                if (slectedOption == null) break;

                if (slectedOption.Index == indexLevel)
                {
                    levelOptions.Get();
                    if (levelOptions.Option() == null) break;
                    var selectedLevelIndex = levelOptions.Option().Index;

                    if (selectedLevelIndex == indexLevelEasy)
                    {
                        RhinoPong.Settings.IALevel = IALevel.Easy;
                    }
                    if (selectedLevelIndex == indexLevelMedium)
                    {
                        RhinoPong.Settings.IALevel = IALevel.Medium;
                    }
                    if (selectedLevelIndex == indexLevelHard)
                    {
                        RhinoPong.Settings.IALevel = IALevel.Hard;
                    }
                    if (selectedLevelIndex == indexLevelImpossible)
                    {
                        RhinoPong.Settings.IALevel = IALevel.Impossible;
                    }

                }

                else if (slectedOption.Index == indexShowFps)
                {
                    game.ShowFps = !game.ShowFps;
                }
                else if (slectedOption.Index == indexSetFps)
                {
                    var fps = RhinoPong.Settings.Fps;

                    var res = RhinoGet.GetNumber("Type FPS", true, ref fps);

                    if (res == Result.Success)
                    {
                        RhinoPong.Settings.Fps = RhinoMath.Clamp(fps, 20, 500);
                    }
                }
                else if (slectedOption.Index == indexSound)
                {
                    game.SoundEnabled = !game.SoundEnabled;
                }
                else if (slectedOption.Index == indexReset)
                {
                    game.ResetGame();
                }
                else
                {
                    break;
                }
            }
            game.StopGame();
            return Result.Success;
        }