Ejemplo n.º 1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var fruit_list     = new[] { "Apple", "Bannana", "Grape", "Mango", "Orange", "Pear" };
            var nut_list       = new[] { "Almonds", "Cashews", "Hazelnuts", "Pecans", "Pistachios", "Walnuts" };
            var vegetable_list = new[] { "Asparagus", "Broccoli", "Carrot", "Corn", "Lettuce", "Onion" };

            // Get persistent settings
            var fruit_value     = Settings.GetInteger("Fruit", 0);
            var nut_value       = Settings.GetInteger("Nut", 0);
            var vegetable_value = Settings.GetInteger("Vegetable", 0);

            var gp = new GetPoint();

            gp.SetCommandPrompt("GetPoint with options");

            var rc = Result.Cancel;

            while (true)
            {
                gp.ClearCommandOptions();

                var fruit_index     = gp.AddOptionList("Fruit", fruit_list, fruit_value);
                var nut_index       = gp.AddOptionList("Nut", nut_list, nut_value);
                var vegetable_index = gp.AddOptionList("Vegetable", vegetable_list, vegetable_value);

                var res = gp.Get();

                if (res == Rhino.Input.GetResult.Point)
                {
                    doc.Objects.AddPoint(gp.Point());
                    doc.Views.Redraw();
                    rc = Result.Success;
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    var option = gp.Option();
                    if (null != option)
                    {
                        if (option.Index == fruit_index)
                        {
                            fruit_value = option.CurrentListOptionIndex;
                        }
                        else if (option.Index == nut_index)
                        {
                            nut_value = option.CurrentListOptionIndex;
                        }
                        else if (option.Index == vegetable_index)
                        {
                            vegetable_value = option.CurrentListOptionIndex;
                        }
                    }
                    continue;
                }

                break;
            }

            if (rc == Result.Success)
            {
                // Set persistent settings
                Settings.SetInteger("Fruit", fruit_value);
                Settings.SetInteger("Nut", nut_value);
                Settings.SetInteger("Vegetable", vegetable_value);
            }

            return(rc);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// RunCommand override
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get persistent settings (from Registry)
            var bool_value = Settings.GetBool("BoolValue", BOOL_DEFAULT);
            var int_value  = Settings.GetInteger("IntValue", INT_DEFAULT);
            var dbl_value  = Settings.GetDouble("DblValue", DBL_DEFAULT);
            var list_value = Settings.GetInteger("ListValue", LIST_DEFAULT);

            var gp = new GetPoint();

            gp.SetCommandPrompt("GetPoint with options");

            var rc = Result.Cancel;

            while (true)
            {
                gp.ClearCommandOptions();

                var bool_option = new OptionToggle(bool_value, "Off", "On");
                var int_option  = new OptionInteger(int_value, 1, 99);
                var dbl_option  = new OptionDouble(dbl_value, 0, 99.9);
                var list_items  = new[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

                var bool_index  = gp.AddOptionToggle("Boolean", ref bool_option);
                var int_index   = gp.AddOptionInteger("Integer", ref int_option);
                var dbl_index   = gp.AddOptionDouble("Double", ref dbl_option);
                var list_index  = gp.AddOptionList("List", list_items, list_value);
                var reset_index = gp.AddOption("Reset");

                var res = gp.Get();

                if (res == Rhino.Input.GetResult.Point)
                {
                    doc.Objects.AddPoint(gp.Point());
                    doc.Views.Redraw();
                    rc = Result.Success;
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    var option = gp.Option();
                    if (null != option)
                    {
                        if (option.Index == bool_index)
                        {
                            bool_value = bool_option.CurrentValue;
                        }
                        else if (option.Index == int_index)
                        {
                            int_value = int_option.CurrentValue;
                        }
                        else if (option.Index == dbl_index)
                        {
                            dbl_value = dbl_option.CurrentValue;
                        }
                        else if (option.Index == list_index)
                        {
                            list_value = option.CurrentListOptionIndex;
                        }
                        else if (option.Index == reset_index)
                        {
                            bool_value = BOOL_DEFAULT;
                            int_value  = INT_DEFAULT;
                            dbl_value  = DBL_DEFAULT;
                            list_value = LIST_DEFAULT;
                        }
                    }
                    continue;
                }

                break;
            }

            if (rc == Result.Success)
            {
                // Set persistent settings (to Registry)
                Settings.SetBool("BoolValue", bool_value);
                Settings.SetInteger("IntValue", int_value);
                Settings.SetDouble("DblValue", dbl_value);
                Settings.SetInteger("ListValue", list_value);
            }

            return(rc);
        }