コード例 #1
0
            protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            {
                string selectedSchema  = "";
                var    selectedObjects = GetObjectSelection();

                if (selectedObjects == null)
                {
                    return(Result.Cancel);
                }

                // Construct an options getter for BIM element types
                // DirectShape assigns selected type as the family
                var getOpt = new GetOption();

                getOpt.SetCommandPrompt("Select BIM type. Press Enter when done");
                List <string> schemas = Enum.GetNames(typeof(SchemaObjectFilter.SupportedSchema)).ToList();
                int           schemaListOptionIndex = getOpt.AddOptionList("Type", schemas, 0);

                // Get options
                while (getOpt.Get() == GetResult.Option)
                {
                    if (getOpt.OptionIndex() == schemaListOptionIndex)
                    {
                        selectedSchema = schemas[getOpt.Option().CurrentListOptionIndex];
                    }
                }

                ApplySchema(selectedObjects, selectedSchema, doc, true);
                return(Result.Success);
            }
        public static int AddEnumOptionList(GetOption getOptions, Enum enumerationCurrent)
        {
            Type type = enumerationCurrent.GetType();

            string[] names   = Enum.GetNames(type);
            string   current = Enum.GetName(type, enumerationCurrent);

            int location = Array.IndexOf(names, current);

            if (location == -1)
            {
                throw new ArgumentException("enumerationCurrent is not an existing value");
            }

            return(getOptions.AddOptionList(type.Name, names, location));
        }
コード例 #3
0
        private void RestoreOptions(ref GetOption go, int ResolutionIndex)
        {
            Size size = RhinoHelpers.CalculateSize(
                ResolutionIndex,
                widthOpt.CurrentValue,
                heightOpt.CurrentValue,
                dpiOpt.CurrentValue,
                portraitToggle.CurrentValue
                );

            if (size.IsEmpty)
            {
                size = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.Bounds.Size;
            }

            go.SetCommandPrompt("Screenshot (" + size.Width + "x" + size.Height + ")");
            go.ClearCommandOptions();
            go.AddOptionList("Resolution", new string[] { "FullHD", "4K", "A4", "A3", "View", "Custom" }, ResolutionIndex);

            // Show option width and height only if "Custom" is selected.
            if (ResolutionIndex == 5)
            {
                go.AddOptionInteger("Width", ref this.widthOpt);
                go.AddOptionInteger("Height", ref this.heightOpt);

                go.AddOptionToggle("KeepRatio", ref this.ratioToggle);
            }
            else if (ResolutionIndex >= 2 && ResolutionIndex <= 3)
            {
                go.AddOptionToggle("Orientation", ref this.portraitToggle);
                go.AddOptionInteger("DPI", ref this.dpiOpt);
            }

            // Show option Grid And Axes
            go.AddOptionToggle("GridAndAxes", ref this.gridAxesToggle);
        }
コード例 #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int counter = 0;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select curves to offset.");
            go.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            go.GroupSelect                 = true;
            go.SubObjectSelect             = true;
            go.DeselectAllBeforePostSelect = true;
            go.OneByOnePostSelect          = false;
            go.GetMultiple(1, 0);


            GetOption gop  = new GetOption();
            var       dist = new Rhino.Input.Custom.OptionDouble(distVal);

            gop.SetCommandPrompt("Set values. Press enter when done.");
            gop.AddOptionDouble("Distance", ref dist);
            int optList = gop.AddOptionList("CornerStyle", corners, cornerIndex);

            gop.AcceptNothing(true);

            while (true)
            {
                if (gop.Get() == GetResult.Nothing)
                {
                    break;
                }

                else if (gop.OptionIndex() == optList)
                {
                    cornerIndex = gop.Option().CurrentListOptionIndex;
                }

                else
                {
                    distVal = dist.CurrentValue;
                }
            }



            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                var curve = objref.Curve();
                if (curve == null)
                {
                    return(Result.Nothing);
                }
                Plane plane;
                if (!curve.TryGetPlane(out plane))
                {
                    curve.DivideByCount(3, true, out Point3d[] curvePoints);
                    plane = new Plane(curvePoints[0], curvePoints[1], curvePoints[2]);
                }

                try
                {
                    var curves = curve.Offset(plane, distVal, doc.ModelAbsoluteTolerance, cornerStyle[cornerIndex]);
                    foreach (var offsetcurve in curves)
                    {
                        doc.Objects.AddCurve(offsetcurve);
                    }
                }
                catch
                {
                    counter++;
                }
            }

            if (counter > 0)
            {
                RhinoApp.WriteLine(counter + " out of " + go.ObjectCount + " offset values were out of scope!");
            }

            doc.Views.Redraw();



            // ---

            return(Result.Success);
        }
コード例 #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetOption go = new GetOption();
            go.SetCommandPrompt("Set Faro scan settings");

            Rhino.Input.Custom.GetString gs = new GetString();
            gs.SetCommandPrompt("Set Faro IP address.");
            gs.SetDefaultString("127.0.0.1");

            gs.AddOption("Scanner IP");

            gs.Get();

            string val = gs.StringResult();

            Rhino.RhinoApp.WriteLine("IP: " + val);

            // 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[] resolutionValues  = new string[] { "Full", "Half", "Quarter", "Eighth", "Sixsteenth" };
            string[] measurementValues = new string[] { "Low", "Medium", "High" };
            string[] noiseValues       = new string[] { "Low", "Medium", "High" };


            go.AddOptionInteger("Integer", ref intOption);
            go.AddOptionDouble("Double", ref dblOption);
            go.AddOptionToggle("Boolean", ref boolOption);

            int resolutionIndex  = 2;
            int measurementIndex = 1;
            int noiseIndex       = 1;

            int resolutionList  = go.AddOptionList("Resolution", resolutionValues, resolutionIndex);
            int measurementList = go.AddOptionList("MeasurementRate", measurementValues, measurementIndex);
            int noiseList       = go.AddOptionList("NoiseCompression", noiseValues, noiseIndex);

            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 = go.Get();
                Rhino.RhinoApp.WriteLine(get_rc.ToString());

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

                if (get_rc == Rhino.Input.GetResult.Nothing)
                {
                    //doc.Objects.AddPoint(go.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(" Measurement rate = {0}", measurementValues[measurementIndex]);
                    Rhino.RhinoApp.WriteLine(" Resolution = {0}", resolutionValues[resolutionIndex]);
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (go.OptionIndex() == resolutionList)
                    {
                        resolutionIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == measurementList)
                    {
                        measurementIndex = go.Option().CurrentListOptionIndex;
                    }

                    continue;
                }
                break;
            }

            return(Rhino.Commands.Result.Success);
        }
コード例 #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var cities         = new OptionInteger(50, 3, 1000);
            var time           = new OptionInteger(10, 5, 120);
            var algorithmIndex = 0;

            var get = new GetOption();

            get.SetCommandPrompt("Optimize TSP");
            get.AddOptionInteger("Cities", ref cities);
            get.AddOptionInteger("Time", ref time);
            get.AddOptionList("Algorithm", new[] { "RandomSearch", "HillClimbing", "SimulatedAnnealing" }, 0);
            get.AddOption("Run");

            while (true)
            {
                get.Get();

                if (get.CommandResult() != Result.Success)
                {
                    return(get.CommandResult());
                }

                if (get.Option().EnglishName == "Algorithm")
                {
                    algorithmIndex = get.Option().CurrentListOptionIndex;
                }

                if (get.Option().EnglishName == "Run")
                {
                    RhinoApp.WriteLine("Optimization started...");
                    break;
                }
            }

            var optimizer = new Optimizer(cities.CurrentValue, time.CurrentValue);
            var conduit   = new OptimizeConduit(optimizer.Path)
            {
                Enabled = true
            };

            Task updateTask = null;

            optimizer.UpdatedCandidate += (o, e) =>
            {
                conduit.Path = optimizer.Path;
                conduit.Info = optimizer.Info;

                //doc.Views.Redraw();

                if (updateTask?.IsCompleted != false)
                {
                    updateTask = Task.Run(() => doc.Views.Redraw());
                }
            };

            optimizer.Finished += (o, e) =>
            {
                conduit.Enabled = false;
                doc.Objects.AddPolyline(optimizer.Path);
                doc.Views.Redraw();
                RhinoApp.WriteLine($"Optimization finished ({optimizer.Info}).");
            };

            var algorithms = new Action[]
            {
                optimizer.RandomSearch,
                optimizer.HillClimbing,
                optimizer.SimulatedAnnealing
            };

            Task.Run(algorithms[algorithmIndex]);

            return(Result.Success);
        }
コード例 #7
0
            protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            {
                // Command variables
                var    selectedObjects = new List <RhinoObject>();
                string selectedSchema  = "";
                bool   automatic       = true;
                bool   directShape     = false;

                // Construct an objects getter
                // This includes an option toggle for "Automatic" (true means automagic schema application, no directshapes)
                var getObj = new GetObject();

                getObj.SetCommandPrompt("Select geometry");
                var toggleAutomatic = new OptionToggle(true, "Off", "On");

                getObj.AddOptionToggle("Automatic", ref toggleAutomatic);
                getObj.GroupSelect     = true;
                getObj.SubObjectSelect = false;
                getObj.EnableClearObjectsOnEntry(false);
                getObj.EnableUnselectObjectsOnExit(false);
                getObj.DeselectAllBeforePostSelect = false;

                // Get objects
                for (; ;)
                {
                    GetResult res = getObj.GetMultiple(1, 0);
                    if (res == GetResult.Option)
                    {
                        getObj.EnablePreSelect(false, true);
                        continue;
                    }
                    else if (res != GetResult.Object)
                    {
                        return(Result.Cancel);
                    }
                    if (getObj.ObjectsWerePreselected)
                    {
                        getObj.EnablePreSelect(false, true);
                        continue;
                    }
                    break;
                }

                selectedObjects = getObj.Objects().Select(o => o.Object()).ToList();
                automatic       = toggleAutomatic.CurrentValue;

                // Construct an options getter if "Automatic" was set to "off"
                if (!automatic)
                {
                    // Construct an options getter for schema options
                    // This includes an option toggle for "DirectShape" (true will asign selected schema as the family)
                    // Also includes an option list of supported schemas
                    var getOpt = new GetOption();
                    getOpt.SetCommandPrompt("Select schema options. Press Enter when done");
                    var           toggleDirectShape     = new OptionToggle(false, "Off", "On");
                    var           directShapeIndex      = getOpt.AddOptionToggle("DirectShape", ref toggleDirectShape);
                    List <string> schemas               = Enum.GetNames(typeof(SchemaObjectFilter.SupportedSchema)).ToList();
                    int           schemaListOptionIndex = getOpt.AddOptionList("Schema", schemas, 0);

                    // Get options
                    while (getOpt.Get() == GetResult.Option)
                    {
                        if (getOpt.OptionIndex() == schemaListOptionIndex)
                        {
                            selectedSchema = schemas[getOpt.Option().CurrentListOptionIndex];
                        }
                        if (getOpt.OptionIndex() == directShapeIndex)
                        {
                            directShape = toggleDirectShape.CurrentValue;
                        }
                    }
                }

                // Apply schemas
                if (automatic)
                {
                    ApplySchemas(selectedObjects, doc);
                }
                else
                {
                    ApplySchema(selectedObjects, selectedSchema, doc, directShape);
                }
                return(Result.Success);
            }
コード例 #8
0
        public bool SaveToDocument(ContainerType container = ContainerType.Edge)
        {
            var getOption = new GetOption();

            getOption.SetCommandPrompt("What type of geometry container?");
            string[] listValues = new string[] { "Edges", "BrepFaces", "BrepCells", "MeshFaces", "MeshCells" };
            int      opList     = getOption.AddOptionList("Type", listValues, (int)container);

            getOption.SetDefaultString("_");

            getOption.Get();

            var getOp = (int)container;

            if (getOption.Result() == GetResult.Option)
            {
                getOp = getOption.Option().CurrentListOptionIndex;
            }

            if (getOption.Result() == GetResult.Option || getOption.GotDefault())
            {
                if (getOp == 0)
                {
                    SaveAsEdges();
                }
                else if (getOp == 1)
                {
                    SaveAsFaces();
                }
                else if (getOp == 2)
                {
                    if (Cells.Count > 0)
                    {
                        SaveAsCells(true);
                    }
                    else
                    {
                        Rhino.RhinoApp.WriteLine("No cells in the PolyFrame, faces will be saved instead.");
                        SaveAsFaces();
                    }
                }

                else if (getOp == 3)
                {
                    SaveAsFaces(true);
                }
                else if (getOp == 4)
                {
                    if (Cells.Count > 0)
                    {
                        SaveAsCells(true, true);
                    }
                    else
                    {
                        Rhino.RhinoApp.WriteLine("No cells in the PolyFrame, faces will be saved instead.");
                        SaveAsFaces(true);
                    }
                }
            }

            else
            {
                return(false);
            }

            return(true);
        }
コード例 #9
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);
        }