Esempio n. 1
0
        /// <summary>
        /// Write a history record referencing the antecedent objects
        /// The history should contain all the information required to reconstruct the input.
        /// This may include parameters, options, or settings.
        /// </summary>
        private bool WriteHistory(Rhino.DocObjects.HistoryRecord history, List <Guid> ids, double radius1, double radius2, int capIndex)
        {
            if (!history.SetGuids(0, ids))
            {
                return(false);
            }

            if (!history.SetDouble(1, radius1))
            {
                return(false);
            }

            if (!history.SetDouble(2, radius2))
            {
                return(false);
            }

            if (!history.SetInt(3, capIndex))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.ApplicationSettings.HistorySettings.RecordingEnabled = true;
            double tolerance = doc.ModelAbsoluteTolerance;

            GetObject gc = new GetObject();

            gc.SetCommandPrompt("Select curve(s) for multipipe");
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gc.GroupSelect    = true;
            gc.GetMultiple(1, 0);

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

            List <Curve> curves = new List <Curve>();

            for (int i = 0; i < gc.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = gc.Object(i);
                Rhino.Geometry.Curve    curve  = objref.Curve();
                curves.Add(curve);
                ids.Add(objref.ObjectId);
            }


            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("Start and end radius");
            int opList = gn.AddOptionList("Cap", caps, capIndex);

            gn.SetDefaultNumber(radius1);

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

                if (get_rc == Rhino.Input.GetResult.Number)
                {
                    radius1 = gn.Number();
                    if (radius1 < 0 || radius1 < 0.0)
                    {
                        Dialogs.ShowMessage("Value must be >= 0.0", "Warning!");
                        continue;
                    }
                }


                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gn.OptionIndex() == opList)
                    {
                        capIndex = gn.Option().CurrentListOptionIndex;
                    }
                    continue;
                }

                break;
            }



            while (true)
            {
                RhinoGet.GetNumber("Middle radius", false, ref radius2);
                if (radius2 <= 0 || radius2 <= 0.0)
                {
                    Dialogs.ShowMessage("Value must be > 0.0", "Warning!");
                    continue;
                }

                break;
            }



            Brep[] pipe;

            double[]      radiParam = { 0.0, 0.5, 1.0 };
            double[]      radi      = { radius1, radius2, radius1 };
            PipeCapMode[] pCapM     = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round };

            // Create a history record
            Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, HISTORY_VERSION);
            WriteHistory(history, ids, radius1, radius2, capIndex);

            foreach (Curve x in curves)
            {
                pipe = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceRadians);
                doc.Objects.AddBrep(pipe[0], null, history, false);
                doc.Views.Redraw();
            }


            doc.Views.Redraw();
            return(Result.Success);
        }