Ejemplo n.º 1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("Numbers");

            if (layerCheck == null)
            {
                doc.Layers.Add("Numbers", System.Drawing.Color.DarkRed);
                layerCheck = doc.Layers.FindName("Numbers");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to number");
            var heightref = new Rhino.Input.Custom.OptionDouble(height);

            go.AddOptionDouble("Text_height_mm", ref heightref);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                height = heightref.CurrentValue;
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                Guid        objGuid            = objref.ObjectId;
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;

                int a = i + 1;

                Plane plane = Plane.WorldXY;
                plane.Origin = bbObjCenter;
                var    Justification = TextJustification.MiddleCenter;
                string text          = a.ToString();
                var    Font          = "Arial";

                Guid num = doc.Objects.AddText(text, plane, height, Font, false, false, Justification);

                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(num);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();

                int groupIndex = doc.Groups.Count;
                groupIndex++;
                string group = groupIndex.ToString();
                var    gI    = doc.Groups.Add(group);
                doc.Groups.AddToGroup(gI, num);
                doc.Groups.AddToGroup(gI, objGuid);
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
Ejemplo n.º 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var getNumber = new GetInteger();
            getNumber.SetLowerLimit(2, false);
            getNumber.SetUpperLimit(10000000, false);
            getNumber.SetDefaultInteger(RcCore.It.EngineSettings.Samples);
            getNumber.SetCommandPrompt("Set Debug Options");

            var toggleVerbose = new OptionToggle(RcCore.It.EngineSettings.Verbose, "No", "Yes");
            var toggleInteractive = new OptionToggle(RcCore.It.EngineSettings.UseInteractiveRenderer, "No", "Yes");

            var spotlightFactor = new OptionDouble(RcCore.It.EngineSettings.SpotlightFactor, 0.0, 1000000.0);
            var pointlightFactor = new OptionDouble(RcCore.It.EngineSettings.PointlightFactor, 0.0, 1000000.0);
            var sunlightFactor = new OptionDouble(RcCore.It.EngineSettings.SunlightFactor, 0.0, 1000000.0);
            var arealightFactor = new OptionDouble(RcCore.It.EngineSettings.ArealightFactor, 0.0, 1000000.0);
            var polishFactor = new OptionDouble(RcCore.It.EngineSettings.PolishFactor, 0.0, 1000000.0);

            getNumber.AddOptionToggle("verbose", ref toggleVerbose);
            getNumber.AddOptionToggle("use_interactive_renderer", ref toggleInteractive);

            getNumber.AddOptionDouble("spotlight_factor", ref spotlightFactor);
            getNumber.AddOptionDouble("pointlight_factor", ref pointlightFactor);
            getNumber.AddOptionDouble("sunlight_factor", ref sunlightFactor);
            getNumber.AddOptionDouble("arealight_factor", ref arealightFactor);
            getNumber.AddOptionDouble("polish_factor", ref polishFactor);

            while (true)
            {
                var getRc = getNumber.Get();
                if (getNumber.CommandResult() != Result.Success) return getNumber.CommandResult();
                switch (getRc)
                {
                    case GetResult.Nothing:
                    case GetResult.Number:
                        RcCore.It.EngineSettings.Samples = getNumber.Number();
                        ReadOptions(toggleVerbose, toggleInteractive, spotlightFactor, pointlightFactor, sunlightFactor, arealightFactor, polishFactor);
                        break;
                    case GetResult.Option:
                        ReadOptions(toggleVerbose, toggleInteractive, spotlightFactor, pointlightFactor, sunlightFactor, arealightFactor, polishFactor);
                        continue;
                    default:
                        continue;
                }

                break;
            }
            return Result.Success;
        }
Ejemplo n.º 3
0
  public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc)
  {
    // For this example we will use a GetPoint class, but all of the custom
    // "Get" classes support command line options.
    Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
    gp.SetCommandPrompt("GetPoint with options");

    // 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[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" };

    gp.AddOptionInteger("Integer", ref intOption);
    gp.AddOptionDouble("Double", ref dblOption);
    gp.AddOptionToggle("Boolean", ref boolOption);
    int listIndex = 3;
    int opList = gp.AddOptionList("List", listValues, listIndex);

    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 = gp.Get();
      if (gp.CommandResult() != Rhino.Commands.Result.Success)
        return gp.CommandResult();

      if (get_rc == Rhino.Input.GetResult.Point)
      {
        doc.Objects.AddPoint(gp.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(" List = {0}", listValues[listIndex]);
      }
      else if (get_rc == Rhino.Input.GetResult.Option)
      {
        if (gp.OptionIndex() == opList)
          listIndex = gp.Option().CurrentListOptionIndex;
        continue;
      }
      break;
    }
    return Rhino.Commands.Result.Success;
  }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double       tolerance = doc.ModelAbsoluteTolerance;
            List <Curve> curves    = new List <Curve>();

            //Select surface

            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref_Surface = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj            = objref_Surface.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref_Surface.Surface();

            if (surface == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);

            //Select Line(s)
            GetObject gl = new GetObject();

            gl.SetCommandPrompt("Select one or two line(s)");
            gl.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gl.DeselectAllBeforePostSelect = true;
            gl.OneByOnePostSelect          = true;
            gl.GetMultiple(1, 0);

            for (int i = 0; i < gl.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref_Line = gl.Object(i);
                curve = objref_Line.Curve();

                Curve curveRe = curve.Rebuild(60, 3, true);
                curves.Add(curveRe);
            }

            List <Guid> cir_guid_list = new List <Guid>();

            if (curves.Count > 1)
            {
                Curve curve2 = curves[0];
                Curve curve3 = curves[1];
                if (curve2.IsClosed || curve3.IsClosed)
                {
                    Rhino.UI.Dialogs.ShowMessage("Please only select open curves for two line pave.", "Warning!");
                    return(Result.Failure);
                }

                while (true)
                {
                    cir_guid_list = new List <Guid>();



                    var   tweenCurves = Curve.CreateTweenCurvesWithSampling(curve2, curve3, 1, 30, tolerance);
                    Curve tCurve      = tweenCurves[0];

                    //3 point circle
                    Point3d   po1   = curve2.PointAtStart;
                    Point3d   po2   = curve3.PointAtStart;
                    LineCurve line1 = new LineCurve(po1, po2);
                    double[]  param = line1.DivideByCount(2, false);

                    double param1 = param[0];
                    double param2 = param[0];
                    double param3 = param[0];

                    Curve curve1 = line1;



                    while (true)
                    {
                        Circle outCircle = Circle.TryFitCircleTTT(curve1, curve2, curve3, param1, param2, param3);


                        //circle normal to surface

                        Point3d outCircleCenter = outCircle.Center;
                        double  outCircleRadius = outCircle.Radius;
                        double  u, v;
                        surface.ClosestPoint(outCircleCenter, out u, out v);
                        var     direction  = surface.NormalAt(u, v);
                        Point3d surfCenter = surface.PointAt(u, v);
                        Plane   pl1        = new Plane(surfCenter, direction);
                        Circle  circle     = new Circle(pl1, surfCenter, outCircleRadius - offSetStone);
                        Circle  circleDist = new Circle(pl1, surfCenter, outCircleRadius + stoneDist);
                        Guid    cir_guid   = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);


                        //Cut tween curve at latest circle center
                        Point3d pointOnCurve;
                        Point3d pointOnCircle;
                        Curve   circleDistCurve = circleDist.ToNurbsCurve();
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        Curve[] splitCurves = tCurve.Split(outCircleRadius);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];
                        tCurve.ClosestPoints(circleDistCurve, out pointOnCurve, out pointOnCircle);

                        //Cut tween curve at latest circle border
                        double curveSplitParam;
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        tCurve.ClosestPoint(pointOnCurve, out curveSplitParam);
                        splitCurves = tCurve.Split(curveSplitParam);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];

                        //New parameter at curve1
                        double circleParam;
                        circleDistCurve.ClosestPoint(pointOnCircle, out circleParam);
                        param1 = circleParam;
                        curve1 = circleDistCurve;

                        //New parameter at curves[0]
                        double paramCurve0New;
                        curve2.ClosestPoint(pointOnCircle, out paramCurve0New);
                        Point3d pointCurve0New = curve2.PointAt(paramCurve0New);
                        double  distNewPoints0 = pointOnCircle.DistanceTo(pointCurve0New);
                        param2 = paramCurve0New + distNewPoints0;

                        //New parameter at curves[1]
                        double paramCurve1New;
                        curve3.ClosestPoint(pointOnCircle, out paramCurve1New);
                        Point3d pointCurve1New = curve3.PointAt(paramCurve1New);
                        double  distNewPoints1 = pointOnCircle.DistanceTo(pointCurve1New);
                        param3 = paramCurve1New + distNewPoints1;
                    }

                    doc.Views.Redraw();


                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");


                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var distStone  = new Rhino.Input.Custom.OptionDouble(stoneDist);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");


                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionDouble("Distance", ref distStone);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }



                    offSetStone = stoneOff.CurrentValue;
                    stoneDist   = distStone.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve2.Reverse();
                        curve2 = curve2.Rebuild(60, 3, false);
                        curve3.Reverse();
                        curve3     = curve3.Rebuild(60, 3, false);
                        optionBool = false;
                    }
                }
            }

            else
            {
                while (true)
                {
                    cir_guid_list = new List <Guid>();
                    List <Point3d> points = new List <Point3d>();


                    double length     = (diamStone / 2) + offSetStone;
                    double crv_length = curve.GetLength();

                    Point3d point = curve.PointAtLength(length);
                    points.Add(point);

                    while (true)
                    {
                        length += diamStone + offSetStone;
                        if (length > crv_length)
                        {
                            break;
                        }
                        point = curve.PointAtLength(length);
                        points.Add(point);
                    }

                    foreach (var poi in points)
                    {
                        double u, v;
                        surface.ClosestPoint(poi, out u, out v);
                        var      direction = surface.NormalAt(u, v);
                        double   x         = direction.X;
                        double   y         = direction.Y;
                        double   z         = direction.Z;
                        Vector3d vt1       = new Vector3d(x, y, z);
                        Plane    pl1       = new Plane(poi, vt1);
                        Circle   circle    = new Circle(pl1, poi, diamStone / 2);
                        Guid     cir_guid  = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);
                    }

                    doc.Views.Redraw();

                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");

                    var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                    go.AddOptionDouble("StoneDiam", ref stoneDiam);
                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }


                    diamStone   = stoneDiam.CurrentValue;
                    offSetStone = stoneOff.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve.Reverse();
                    }
                }
            }


            doc.Views.Redraw();

            doc.Groups.Add(cir_guid_list);

            return(Result.Success);
        }
Ejemplo n.º 7
0
        private static void ReadOptions(OptionToggle toggleVerbose, OptionToggle toggleInteractive,
			OptionDouble spotlightFactor, OptionDouble pointlightFactor, OptionDouble sunlightFactor,
			OptionDouble arealightFactor, OptionDouble polishFactor)
        {
            RcCore.It.EngineSettings.Verbose = toggleVerbose.CurrentValue;
            RcCore.It.EngineSettings.UseInteractiveRenderer = toggleInteractive.CurrentValue;
            RcCore.It.EngineSettings.SpotlightFactor = (float) spotlightFactor.CurrentValue;
            RcCore.It.EngineSettings.PointlightFactor = (float) pointlightFactor.CurrentValue;
            RcCore.It.EngineSettings.SunlightFactor = (float) sunlightFactor.CurrentValue;
            RcCore.It.EngineSettings.ArealightFactor = (float) arealightFactor.CurrentValue;
            RcCore.It.EngineSettings.PolishFactor = (float) polishFactor.CurrentValue;
        }
Ejemplo n.º 8
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;
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            SearchMode sm = SearchMode.CurveLength;

            Curve[] curves;
            OptionToggle tog = new OptionToggle(false, "Hide", "Show");
            OptionDouble tol = new OptionDouble(RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, true, 0.0);
            using (CurvesGetter getLines = new CurvesGetter("Select curves meeting at endpoints. Press Enter when done"))
            {
                for( ; ;)
                {
                    getLines.ClearCommandOptions();
                    getLines.EnableClearObjectsOnEntry(false);
                    int showInt = getLines.AddOptionToggle("Topology", ref tog);
                    int tolInt = getLines.AddOptionDouble("Tolerance", ref tol);
                    int modeInt = GetterExtension.AddEnumOptionList(getLines, sm);

                    if (getLines.Curves(1, 0, out curves))
                        break;
                    else
                    {
                        if (getLines.Result() == GetResult.Option)
                        {
                            if (getLines.Option().Index == modeInt)
                            {
                                sm = GetterExtension.RetrieveEnumOptionValue<SearchMode>
                                    (getLines.Option().CurrentListOptionIndex);
                            }
                            continue;
                        }
                        else
                        {
                            RhinoApp.WriteLine("Less than three lines were selected");
                            return Result.Cancel;
                        }
                    }
                }
            }
            CurvesTopology crvTopology = new CurvesTopology(curves, tol.CurrentValue);

            Guid[] ids = null;
            if (tog.CurrentValue)
                ids = CurvesTopologyPreview.Mark(crvTopology, Color.LightBlue, Color.LightCoral);

            int walkFromIndex;
            using (var getStart = new TrackingPointGetter("Select the start point of the walk on the curves", crvTopology))
            {
                if (getStart.GetPointOnTopology(out walkFromIndex) != Result.Success)
                {
                    EndOperations(ids);
                    return Result.Cancel;
                }
            }

            Result wasSuccessful = Result.Cancel;

            for (; ; )
            {

                int walkToIndex;
                double[] distances;
                using (var getEnd = new TrackingPointGetter("Select the end point", crvTopology, walkFromIndex, sm))
                {
                    if (getEnd.GetPointOnTopology(out walkToIndex) != Result.Success)
                    {
                        break;
                    }
                    distances = getEnd.DistanceCache;
                }

                if (walkFromIndex == walkToIndex)
                {
                    RhinoApp.WriteLine("Start and end points are equal");
                    EndOperations(ids);
                    return Result.Nothing;
                }

                PathMethod pathSearch = PathMethod.FromMode(sm, crvTopology, distances);

                int[] nIndices, eIndices;
                bool[] eDirs;
                double totLength;
                Curve c =
                    pathSearch.Cross(walkFromIndex, walkToIndex, out nIndices, out eIndices, out eDirs, out totLength);

                if (c != null && c.IsValid)
                {
                    if (tog.CurrentValue)
                    {
                        RhinoApp.WriteLine("Vertices: {0}", FormatNumbers(nIndices));
                        RhinoApp.WriteLine("Edges: {0}", FormatNumbers(eIndices));
                    }

                    var a = RhinoDoc.ActiveDoc.CreateDefaultAttributes();
                    Guid g = RhinoDoc.ActiveDoc.Objects.AddCurve(c, a);

                    var obj = RhinoDoc.ActiveDoc.Objects.Find(g);
                    if (obj != null)
                    {
                        obj.Select(true);
                        wasSuccessful = Result.Success;
                        walkFromIndex = walkToIndex;
                    }
                    else
                    {
                        RhinoApp.WriteLine("An error occurred while adding the new polycurve.");
                        wasSuccessful = Result.Failure;
                        break;
                    }
                }
                else
                {
                    RhinoApp.WriteLine("No path was found. Nodes are isolated.");
                    wasSuccessful = Result.Nothing;
                }
            }

            EndOperations(ids);
            return wasSuccessful;
        }
Ejemplo n.º 10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Mesh        meshSurf;
            List <Guid> ids       = new List <Guid>();
            double      tolerance = doc.ModelAbsoluteTolerance;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;

            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = geometryFilter;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }

            brepSurf = objref.Brep();
            if (brepSurf == null)
            {
                meshSurf = objref.Mesh();
                brepSurf = Brep.CreateFromMesh(meshSurf, true);
            }
            if (brepSurf == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);


            while (true)
            {
                w_key_pressed = false;
                s_key_pressed = false;
                a_key_pressed = false;
                d_key_pressed = false;

                m_escape_key_pressed = false;

                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
                RhinoApp.KeyboardEvent    += OnRhinoKeyboardEvent;

                Point3d  pt0;
                GetPoint getPointAction = new GetPoint();
                getPointAction.SetCommandPrompt("Please select insert point(s) on surface.");
                getPointAction.Constrain(brepSurf, -1, -1, false);

                var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");
                var moveOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                getPointAction.AddOptionDouble("StoneDiam", ref stoneDiam);
                getPointAction.AddOptionDouble("Offset", ref stoneOff);
                getPointAction.AddOptionToggle("Delete", ref boolOption);
                getPointAction.AddOptionToggle("Move", ref moveOption);
                getPointAction.DynamicDraw += RefCircleDraw;
                getPointAction.Tag          = obj;
                getPointAction.AcceptString(false);
                getPointAction.AcceptNothing(true);
                var res = getPointAction.Get();


                if (w_key_pressed || s_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    w_key_pressed           = false;
                    s_key_pressed           = false;
                    stoneDiam.CurrentValue  = diamStone;
                }
                if (a_key_pressed || d_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    a_key_pressed           = false;
                    d_key_pressed           = false;
                    stoneOff.CurrentValue   = offSetStone;
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }
                if (m_escape_key_pressed)
                {
                    break;
                }

                diamStone   = stoneDiam.CurrentValue;
                offSetStone = stoneOff.CurrentValue;
                optionBool  = boolOption.CurrentValue;
                moveBool    = moveOption.CurrentValue;

                RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;

                if (moveBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to move. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();

                        getPointAction.Get();
                        pt0 = getPointAction.Point();
                        Point3d        closestPoint;
                        ComponentIndex compIndex;
                        double         u, v;
                        Vector3d       vt1;

                        brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                        Plane  pl1  = new Plane(pt0, vt1);
                        Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                        var    crgu = doc.Objects.AddCircle(cr1);
                        ids.Add(crgu);
                        doc.Views.Redraw();
                    }
                    moveBool = false;
                }
                if (optionBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to delete. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();
                    }
                    optionBool = false;
                }

                if (res == GetResult.Point)
                {
                    pt0 = getPointAction.Point();
                    Point3d        closestPoint;
                    ComponentIndex compIndex;
                    double         u, v;
                    Vector3d       vt1;
                    brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                    Plane  pl1  = new Plane(pt0, vt1);
                    Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                    var    crgu = doc.Objects.AddCircle(cr1);
                    ids.Add(crgu);
                    doc.Views.Redraw();
                }
            }
            RhinoApp.KeyboardEvent    -= OnRhinoKeyboardEvent;
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
            doc.Groups.Add(ids);
            return(Result.Success);
        }
Ejemplo n.º 11
0
  protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
  {
    Rhino.DocObjects.ObjRef objref;
    var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start);
    if (rc != Rhino.Commands.Result.Success)
      return rc;

    var obj = objref.Object();
    if (obj == null)
      return Rhino.Commands.Result.Failure;

    // create an instance of a GetPoint class and add a delegate
    // for the DynamicDraw event
    var gp = new Rhino.Input.Custom.GetPoint();
    gp.DrawLineFromPoint(m_point_start, true);
    var optdouble = new Rhino.Input.Custom.OptionDouble(m_distance);
    bool constrain = false;
    var optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On");
    gp.AddOptionDouble("Distance", ref optdouble);
    gp.AddOptionToggle("Constrain", ref optconstrain);
    gp.DynamicDraw += ArrayByDistanceDraw;
    gp.Tag = obj;
    while (gp.Get() == Rhino.Input.GetResult.Option)
    {
      m_distance = optdouble.CurrentValue;
      if (constrain != optconstrain.CurrentValue)
      {
        constrain = optconstrain.CurrentValue;
        if (constrain)
        {
          var gp2 = new Rhino.Input.Custom.GetPoint();
          gp2.DrawLineFromPoint(m_point_start, true);
          gp2.SetCommandPrompt("Second point on constraint line");
          if (gp2.Get() == Rhino.Input.GetResult.Point)
            gp.Constrain(m_point_start, gp2.Point());
          else
          {
            gp.ClearCommandOptions();
            optconstrain.CurrentValue = false;
            constrain = false;
            gp.AddOptionDouble("Distance", ref optdouble);
            gp.AddOptionToggle("Constrain", ref optconstrain);
          }
        }
        else
        {
          gp.ClearConstraints();
        }
      }
    }

    if (gp.CommandResult() == Rhino.Commands.Result.Success)
    {
      m_distance = optdouble.CurrentValue;
      var pt = gp.Point();
      var vec = pt - m_point_start;
      double length = vec.Length;
      vec.Unitize();
      int count = (int)(length / m_distance);
      for (int i = 1; i < count; i++)
      {
        var translate = vec * (i * m_distance);
        var xf = Rhino.Geometry.Transform.Translation(translate);
        doc.Objects.Transform(obj, xf, false);
      }
      doc.Views.Redraw();
    }

    return gp.CommandResult();
  }
Ejemplo n.º 12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance      = doc.ModelAbsoluteTolerance;
            double angleTolerance = doc.ModelAngleToleranceRadians;


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

            GetObject gcr = new Rhino.Input.Custom.GetObject();

            gcr.SetCommandPrompt("Select reference circles for prongs. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;

                Point3d pt0 = new Point3d(0, 0, hight);
                Point3d pt1 = new Point3d(0, 0, -(length - hight));

                double rotationRadiant = ((rotation / 180) * 3.1415);

                List <Point3d> curvePoints = new List <Point3d>()
                {
                    pt0, pt1
                };
                Curve prongCurve = Curve.CreateInterpolatedCurve(curvePoints, 3);

                if (!capBool)
                {
                    capMode = PipeCapMode.Flat;
                }
                else if (capBool)
                {
                    capMode = PipeCapMode.Round;
                }

                Brep[] cylBrep1 = Brep.CreatePipe(prongCurve, prongDia / 2, false, capMode, false, tolerance, angleTolerance);
                Brep   cylBrep2 = cylBrep1[0];
                cylBrep2.Faces.RemoveAt(2);
                Brep cylBrep3 = cylBrep2.CapPlanarHoles(tolerance);

                if (capBool)
                {
                    Vector3d     scaleVec   = new Vector3d(0, 0, 1);
                    var          scalePlane = new Plane(pt0, scaleVec);
                    var          capScale   = Transform.Scale(scalePlane, 1.0, 1.0, capHight);
                    var          surf2      = cylBrep3.Faces[1].UnderlyingSurface();
                    NurbsSurface nurbSurf2  = surf2.ToNurbsSurface();
                    nurbSurf2.Transform(capScale);
                    Brep capBrep = nurbSurf2.ToBrep();
                    cylBrep3.Append(capBrep);
                    cylBrep3.Faces.RemoveAt(1);
                }

                cylBrep3.Compact();
                cylBrep3.JoinNakedEdges(tolerance);
                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrep3
                };
                var prongIndex = doc.InstanceDefinitions.Add("Prong" + instDefCount, "RefProng", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleProngs = new Circle();
                    c.TryGetCircle(out circleProngs, tolerance);
                    NurbsCurve curveProngs = circleProngs.ToNurbsCurve();

                    Plane    planeNew = circleProngs.Plane;
                    Vector3d plVec    = planeNew.Normal;

                    if (planeNew == null)
                    {
                        curveProngs.DivideByCount(3, true, out Point3d[] curveProngsPoints);
                        planeNew = new Plane(curvePoints[0], curveProngsPoints[1], curveProngsPoints[2]);
                    }


                    Curve[] offsetCurveArray = curveProngs.Offset(planeNew, prongDia / 4, tolerance, CurveOffsetCornerStyle.Sharp);

                    Curve offsetCurve = offsetCurveArray[0];

                    double[] segParameters = offsetCurve.DivideByCount(prongCount, true);

                    List <Point3d> prongPoints = new List <Point3d>();
                    List <Guid>    idsInter    = new List <Guid>();

                    foreach (double p in segParameters)
                    {
                        Point3d zen        = new Point3d(0, 0, 0);
                        Point3d prongPoint = offsetCurve.PointAt(p);

                        Point3d  center  = circleProngs.Center;
                        Vector3d moveV   = new Vector3d(prongPoint);
                        Vector3d zaxis   = new Vector3d(0.0, 0.0, 1.0);
                        Plane    planeOr = new Plane(zen, zaxis);
                        Plane    plane   = new Plane(prongPoint, plVec);

                        var transform1 = Transform.PlaneToPlane(planeOr, plane);
                        var transform2 = Transform.Rotation(rotationRadiant, plVec, center);

                        var prongA = doc.Objects.AddInstanceObject(prongIndex, transform1);
                        var prongB = doc.Objects.Transform(prongA, transform2, true);

                        ids.Add(prongB);
                    }
                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set prong parameters.");
                go.AcceptNothing(true);

                var countProng  = new Rhino.Input.Custom.OptionInteger(prongCount);
                var diaProng    = new Rhino.Input.Custom.OptionDouble(prongDia);
                var hightProng  = new Rhino.Input.Custom.OptionDouble(hight);
                var lengthProng = new Rhino.Input.Custom.OptionDouble(length);
                var rotProng    = new Rhino.Input.Custom.OptionDouble(rotation);
                var capProng    = new Rhino.Input.Custom.OptionToggle(capBool, "Flat", "Round");
                var hightCap    = new Rhino.Input.Custom.OptionDouble(capHight);

                go.AddOptionInteger("Count", ref countProng);
                go.AddOptionDouble("Diameter", ref diaProng);
                go.AddOptionDouble("Hight", ref hightProng);
                go.AddOptionDouble("Length", ref lengthProng);
                go.AddOptionDouble("Rotation", ref rotProng);
                go.AddOptionToggle("Cap", ref capProng);
                if (capBool)
                {
                    go.AddOptionDouble("Caphight", ref hightCap);
                }

                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }

                hight      = hightProng.CurrentValue;
                length     = lengthProng.CurrentValue;
                prongCount = countProng.CurrentValue;
                prongDia   = diaProng.CurrentValue;
                rotation   = rotProng.CurrentValue;
                capBool    = capProng.CurrentValue;
                capHight   = hightCap.CurrentValue;

                if (length <= 0.0)
                {
                    length = 1.0;
                }
                if (prongCount <= 0)
                {
                    prongCount = 1;
                }
                if (prongDia <= 0.0)
                {
                    prongDia = 1.0;
                }
                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
Ejemplo n.º 13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //Pick curve for chain
            GetObject getCurve = new GetObject();

            getCurve.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            getCurve.SetCommandPrompt("Select curve for chain");
            var res = getCurve.Get();

            Rhino.DocObjects.ObjRef      objref = getCurve.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            curve = objref.Curve();
            if (curve == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);

            //Pick object for chain (instance)
            //pick objekt to orient
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select chain element.");
            go.SubObjectSelect             = true;
            go.DeselectAllBeforePostSelect = false;
            //go.GroupSelect = true;
            //go.GetMultiple(1, -1);
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref1 = go.Object(0);
            Rhino.DocObjects.RhinoObject obj1    = objref1.Object();
            GeometryBase obj1Base = obj1.Geometry;


            int    obCount      = go.ObjectCount;
            string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");

            //create block instance and plane for instance
            Rhino.Input.Custom.GetPoint gp1 = new Rhino.Input.Custom.GetPoint();
            gp1.SetCommandPrompt("Center point to orient from");
            gp1.Get();
            if (gp1.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gp1.CommandResult());
            }
            Point3d pt1 = gp1.Point();

            Rhino.Input.Custom.GetPoint gp2 = new Rhino.Input.Custom.GetPoint();
            gp2.SetCommandPrompt("Point for orientation");
            gp2.DrawLineFromPoint(pt1, false);
            gp2.Get();
            if (gp2.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gp2.CommandResult());
            }
            Point3d pt2 = gp2.Point();

            Vector3d vt1 = pt2 - pt1;

            sourcePlane = new Plane(pt1, vt1);
            Plane     originPlane = new Plane(Point3d.Origin, vt1);
            Transform bform       = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane);

            obj1Base.Transform(bform);

            GeometryBase[] obj1List = new GeometryBase[1] {
                obj1Base
            };

            var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List);


            //orient instances along curve

            List <Guid> chainBlocks = new List <Guid>();
            Guid        chainBlock;

            while (true)
            {
                foreach (var block in chainBlocks)
                {
                    doc.Objects.Delete(block, false);
                }
                chainBlocks = new List <Guid>();
                double curveLength    = curve.GetLength();
                double curveDivide    = curveLength / chainDis;
                int    curveDivideInt = Convert.ToInt32(curveDivide);

                for (int ic = 0; ic < curveDivideInt; ic++)
                {
                    Point3d  insertPoint = curve.PointAtLength(chainDis * ic);
                    Vector3d insertVec   = curve.PointAtLength(chainDis * ic + 1) - curve.PointAtLength(chainDis * ic - 1);
                    Plane    targetPlane = new Plane(insertPoint, insertVec);

                    var xvec = targetPlane.XAxis;
                    if (xvec.Z != 0)
                    {
                        targetPlane.Rotate(Math.PI / 2, insertVec);
                    }

                    var yvec = targetPlane.YAxis;
                    if (yvec.Z < 0)
                    {
                        targetPlane.Rotate(Math.PI, insertVec);
                    }

                    if (ic % 2 == 0)
                    {
                        targetPlane.Rotate(Math.PI / 2, insertVec);
                    }
                    targetPlane.Rotate(axisOffsetRadiant, insertVec);
                    Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, targetPlane);
                    chainBlock = doc.Objects.AddInstanceObject(orientBlock, xform);
                    chainBlocks.Add(chainBlock);
                }

                doc.Views.Redraw();
                GetOption gd = new GetOption();
                gd.SetCommandPrompt("Set distance between element centers in mm and rotation offset in degree. Press enter to accept.");
                var dis        = new Rhino.Input.Custom.OptionDouble(chainDis);
                var axisOffset = new Rhino.Input.Custom.OptionInteger(chainAxisOffset);
                gd.AddOptionDouble("distance", ref dis);
                gd.AddOptionInteger("rotation", ref axisOffset);
                gd.AcceptNothing(true);
                var resdis = gd.Get();
                if (resdis == GetResult.Nothing)
                {
                    break;
                }

                chainDis          = dis.CurrentValue;
                chainAxisOffset   = axisOffset.CurrentValue;
                axisOffsetRadiant = chainAxisOffset * (Math.PI / 180);
            }

            int index = doc.Groups.Add(chainBlocks);

            return(Result.Success);
        }
Ejemplo n.º 14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: start here modifying the behaviour of your command.
            // ---
            //RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);



            GetObject getBreps = new GetObject();

            getBreps.SetCommandPrompt("Pick the breps to create a PolyhedralFrame");
            getBreps.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
            // set up options

            OptionDouble dblOptionCollapse = new Rhino.Input.Custom.OptionDouble(0.1, true, 0.0);
            OptionDouble dblOptionPlanar   = new Rhino.Input.Custom.OptionDouble(0.1, true, 0.0);
            OptionToggle togOptionReplace  = new OptionToggle(true, "Keep", "Replace");

            getBreps.AddOptionDouble("PointCollapseLimit", ref dblOptionCollapse);
            getBreps.AddOptionDouble("PlanarityMaxDeviation", ref dblOptionPlanar);

            getBreps.AddOptionToggle("ReplaceGeo", ref togOptionReplace);
            getBreps.AcceptNothing(false);

            while (true)
            {
                var r = getBreps.GetMultiple(1, 0);
                if (r == GetResult.Cancel)
                {
                    return(getBreps.CommandResult());
                }
                else if (r == GetResult.Object)
                {
                    break;
                }
            }

            List <Guid> ids = new List <Guid>();

            for (int i = 0; i < getBreps.ObjectCount; i++)
            {
                ids.Add(getBreps.Object(i).ObjectId);
            }

            var foam           = new PFoam();
            var deleteOriginal = false;

            try
            {
                foam.ProcessBFaces(Util.DecomposeG(ids), dblOptionCollapse.CurrentValue, dblOptionPlanar.CurrentValue);
                doc.Objects.UnselectAll();
                if (foam.Faces.Count > 2)
                {
                    foam.MakeCells();
                    Point3d newCentroid = foam.Centroid;
                    if (!togOptionReplace.CurrentValue)
                    {
                        Rhino.Input.RhinoGet.GetPoint("Place the PolyFrame", true, out newCentroid);
                    }
                    else
                    {
                        deleteOriginal = true;
                    }
                    //Rhino.RhinoDoc.ActiveDoc.Objects.Delete(ids, true);


                    foam.Offset(newCentroid - foam.Centroid);
                    foam.Show(true, true, false);
                    foam.ShowCells();


                    if (!foam.SaveToDocument())
                    {
                        foam.Hide();
                        return(Result.Cancel);
                    }


                    foam.Hide();

                    if (deleteOriginal)
                    {
                        Rhino.RhinoDoc.ActiveDoc.Objects.Delete(ids, true);
                    }
                    doc.Views.Redraw();
                    Rhino.RhinoApp.WriteLine($"Constructed a PolyFrame object with {foam.Cells.Count} cells, {foam.Faces.Count} half-faces, {foam.Edges.Count} half-edges and {foam.Vertices.Count} vertices.");

                    return(Result.Success);
                }
                else
                {
                    Rhino.RhinoApp.WriteLine("Not enough faces!");
                    return(Result.Failure);
                }
            }
            catch (Exception pfE)
            {
                RhinoApp.WriteLine(pfE.Message + " Press <Esc> to continue.");
                foam.Hide();
                return(Result.Failure);
            }
        }
Ejemplo n.º 15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance = doc.ModelAbsoluteTolerance;

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

            GetObject gcr = new Rhino.Input.Custom.GetObject();

            gcr.SetCommandPrompt("Select reference circles for drill. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;


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

                Point3d centerTop = new Point3d(0, 0, (headDrill + topDrill) * drillScale);
                Circle  circleTop = new Circle(centerTop, ancheadDrill / 2 * drillScale);
                Curve   curveTop  = circleTop.ToNurbsCurve();
                curveDrill.Add(curveTop);
                Point3d centerMid = new Point3d(0, 0, topDrill * drillScale);
                Circle  circleMid = new Circle(centerMid, drillScale / 2);
                Curve   curveMid  = circleMid.ToNurbsCurve();
                curveDrill.Add(curveMid);
                Circle circleBase = new Circle(drillScale / 2);
                Curve  curveBase  = circleBase.ToNurbsCurve();
                curveDrill.Add(curveBase);
                Point3d centerLow = new Point3d(0, 0, -midDrill * drillScale);
                Circle  circleLow = new Circle(centerLow, ancDrill / 2 * drillScale);
                Curve   curveLow  = circleLow.ToNurbsCurve();
                curveDrill.Add(curveLow);
                if (bottDrill != 0)
                {
                    Point3d centerBot = new Point3d(0, 0, (-midDrill - bottDrill) * drillScale);
                    Circle  circleBot = new Circle(centerBot, ancDrill / 2 * drillScale);
                    Curve   curveBot  = circleBot.ToNurbsCurve();
                    curveDrill.Add(curveBot);
                }


                Brep[] cylBrep1     = Brep.CreateFromLoft(curveDrill, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                Brep[] cylBrep2     = Brep.CreateBooleanUnion(cylBrep1, tolerance);
                Brep   cylBrepFinal = cylBrep1[0];
                cylBrepFinal = cylBrepFinal.CapPlanarHoles(tolerance);


                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrepFinal
                };
                var drillIndex = doc.InstanceDefinitions.Add("Drill" + instDefCount, "RefDrill 1mm", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleDrill = new Circle();
                    c.TryGetCircle(out circleDrill, tolerance);

                    double   radiusDrill = circleDrill.Diameter;
                    Point3d  center      = circleDrill.Center;
                    Vector3d moveV       = new Vector3d(center);
                    Vector3d zaxis       = new Vector3d(0.0, 0.0, 1.0);
                    Plane    planeOr     = new Plane(center, zaxis);
                    Plane    planeNew    = circleDrill.Plane;
                    var      transform1  = Transform.Translation(moveV);
                    var      transform2  = Transform.Scale(center, radiusDrill);
                    var      transform3  = Transform.PlaneToPlane(planeOr, planeNew);

                    var stoneA = doc.Objects.AddInstanceObject(drillIndex, transform1);
                    var stoneB = doc.Objects.Transform(stoneA, transform2, true);
                    var stoneC = doc.Objects.Transform(stoneB, transform3, true);

                    ids.Add(stoneC);

                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set drill parameters.");
                go.AcceptNothing(true);

                var drillHead    = new Rhino.Input.Custom.OptionDouble(headDrill);
                var drillAncHead = new Rhino.Input.Custom.OptionDouble(ancheadDrill);
                var drillTop     = new Rhino.Input.Custom.OptionDouble(topDrill);
                var drillMid     = new Rhino.Input.Custom.OptionDouble(midDrill);
                var drillAnc     = new Rhino.Input.Custom.OptionDouble(ancDrill);
                var drillBott    = new Rhino.Input.Custom.OptionDouble(bottDrill);
                var scaleDrill   = new Rhino.Input.Custom.OptionDouble(drillScale);
                go.AddOptionDouble("Top", ref drillHead);
                go.AddOptionDouble("TopAngle", ref drillAncHead);
                go.AddOptionDouble("Mid", ref drillTop);
                go.AddOptionDouble("Bottom", ref drillMid);
                go.AddOptionDouble("BottomAngle", ref drillAnc);
                go.AddOptionDouble("Tail", ref drillBott);
                go.AddOptionDouble("Scale", ref scaleDrill);


                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }



                topDrill     = drillTop.CurrentValue;
                midDrill     = drillMid.CurrentValue;
                ancDrill     = drillAnc.CurrentValue;
                bottDrill    = drillBott.CurrentValue;
                drillScale   = scaleDrill.CurrentValue;
                headDrill    = drillHead.CurrentValue;
                ancheadDrill = drillAncHead.CurrentValue;


                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
Ejemplo n.º 16
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var getNumber = new GetNumber();
            getNumber.SetLowerLimit(2.0, false);
            getNumber.SetUpperLimit(100000.0, false);
            getNumber.SetDefaultInteger(RcCore.It.EngineSettings.Samples);
            getNumber.SetCommandPrompt("Set render samples");

            var useCustomSettings = new OptionToggle(RcCore.It.EngineSettings.UseCustomQualitySettings, "No", "Yes");

            var minBounce = new OptionInteger(RcCore.It.EngineSettings.MinBounce, 0, 500);
            var maxBounce = new OptionInteger(RcCore.It.EngineSettings.MaxBounce, 0, 500);

            var maxDiffuseBounce = new OptionInteger(RcCore.It.EngineSettings.MaxDiffuseBounce, 0, 200);
            var maxGlossyBounce = new OptionInteger(RcCore.It.EngineSettings.MaxGlossyBounce, 0, 200);
            var maxTransmissionBounce = new OptionInteger(RcCore.It.EngineSettings.MaxTransmissionBounce, 0, 200);
            var maxVolumeBounce = new OptionInteger(RcCore.It.EngineSettings.MaxVolumeBounce, 0, 200);

            var noCaustics = new OptionToggle(RcCore.It.EngineSettings.NoCaustics, "Caustics", "NoCaustics");

            var aaSamples = new OptionInteger(RcCore.It.EngineSettings.AaSamples, 1, 100);
            var diffSamples = new OptionInteger(RcCore.It.EngineSettings.DiffuseSamples, 1, 100);
            var glossySamples = new OptionInteger(RcCore.It.EngineSettings.GlossySamples, 1, 100);

            var seed = new OptionInteger(RcCore.It.EngineSettings.Seed, 0, int.MaxValue);

            var sensorWidth = new OptionDouble(RcCore.It.EngineSettings.SensorWidth, 10.0, 100.0);
            var sensorHeight = new OptionDouble(RcCore.It.EngineSettings.SensorHeight, 10.0, 100.0);

            var transparentMinBounce = new OptionInteger(RcCore.It.EngineSettings.TransparentMinBounce, 0, 200);
            var transparentMaxBounce = new OptionInteger(RcCore.It.EngineSettings.TransparentMaxBounce, 0, 200);
            var transparentShadows = new OptionToggle(RcCore.It.EngineSettings.TransparentShadows, "NoTransparentShadows", "TransparentShadows");

            var branched = new OptionToggle(RcCore.It.EngineSettings.IntegratorMethod==IntegratorMethod.BranchedPath, "Path", "BranchedPath");

            var samplingPattern = new OptionToggle(RcCore.It.EngineSettings.SamplingPattern == SamplingPattern.CMJ, "Sobol", "CMJ");
            var filterGlossy = new OptionDouble(RcCore.It.EngineSettings.FilterGlossy, 0.0, 100.0);
            var sampleClampDirect = new OptionDouble(RcCore.It.EngineSettings.SampleClampDirect, 0.0, 100.0);
            var sampleClampIndirect = new OptionDouble(RcCore.It.EngineSettings.SampleClampIndirect, 0.0, 100.0);
            var sampleAllLights = new OptionToggle(RcCore.It.EngineSettings.SampleAllLights, "no", "yes");
            var sampleAllLightsIndirect = new OptionToggle(RcCore.It.EngineSettings.SampleAllLightsIndirect, "no", "yes");

            getNumber.AddOptionToggle("use_custom_quality_settings", ref useCustomSettings);

            getNumber.AddOptionInteger("min_bounces", ref minBounce);
            getNumber.AddOptionInteger("max_bounces", ref maxBounce);
            getNumber.AddOptionToggle("no_caustics", ref noCaustics);

            getNumber.AddOptionInteger("max_diffuse_bounce", ref maxDiffuseBounce);
            getNumber.AddOptionInteger("max_glossy_bounce", ref maxGlossyBounce);
            getNumber.AddOptionInteger("max_transmission_bounce", ref maxTransmissionBounce);
            getNumber.AddOptionInteger("max_volume_bounce", ref maxVolumeBounce);

            getNumber.AddOptionInteger("transparent_min_bounce", ref transparentMinBounce);
            getNumber.AddOptionInteger("transparent_max_bounce", ref transparentMaxBounce);
            getNumber.AddOptionToggle("transparent_shadows", ref transparentShadows);

            getNumber.AddOptionInteger("aa_samples", ref aaSamples);
            getNumber.AddOptionInteger("diffuse_samples", ref diffSamples);
            getNumber.AddOptionInteger("glossy_samples", ref glossySamples);

            getNumber.AddOptionDouble("sensor_width", ref sensorWidth);
            getNumber.AddOptionDouble("sensor_height", ref sensorHeight);

            getNumber.AddOptionToggle("integrator_method", ref branched);

            getNumber.AddOptionInteger("seed", ref seed, "Seed to use for sampling distribution");

            getNumber.AddOptionToggle("sampling_pattern", ref samplingPattern);
            getNumber.AddOptionDouble("filter_glossy", ref filterGlossy);
            getNumber.AddOptionDouble("sample_clamp_direct", ref sampleClampDirect);
            getNumber.AddOptionDouble("sample_clamp_indirect", ref sampleClampIndirect);
            getNumber.AddOptionToggle("sample_all_lights", ref sampleAllLights);
            getNumber.AddOptionToggle("sample_all_lights_indirect", ref sampleAllLightsIndirect);

            while (true)
            {
                var getRc = getNumber.Get();
                if (getNumber.CommandResult() != Result.Success) return getNumber.CommandResult();
                switch (getRc)
                {
                    case GetResult.Number:
                        RhinoApp.WriteLine($"We got: {getNumber.Number()}, {minBounce.CurrentValue}, {maxBounce.CurrentValue}");
                        RcCore.It.EngineSettings.Samples = (int)getNumber.Number();
                        RcCore.It.EngineSettings.UseCustomQualitySettings = useCustomSettings.CurrentValue;
                        RcCore.It.EngineSettings.Seed = seed.CurrentValue;
                        RcCore.It.EngineSettings.MaxBounce = maxBounce.CurrentValue;
                        RcCore.It.EngineSettings.MinBounce = minBounce.CurrentValue;
                        RcCore.It.EngineSettings.NoCaustics = noCaustics.CurrentValue;
                        RcCore.It.EngineSettings.MaxDiffuseBounce = maxDiffuseBounce.CurrentValue;
                        RcCore.It.EngineSettings.MaxGlossyBounce = maxGlossyBounce.CurrentValue;
                        RcCore.It.EngineSettings.MaxTransmissionBounce = maxTransmissionBounce.CurrentValue;
                        RcCore.It.EngineSettings.MaxVolumeBounce = maxVolumeBounce.CurrentValue;
                        RcCore.It.EngineSettings.TransparentMinBounce = transparentMinBounce.CurrentValue;
                        RcCore.It.EngineSettings.TransparentMaxBounce = transparentMaxBounce.CurrentValue;
                        RcCore.It.EngineSettings.TransparentShadows = transparentShadows.CurrentValue;
                        RcCore.It.EngineSettings.AaSamples = aaSamples.CurrentValue;
                        RcCore.It.EngineSettings.DiffuseSamples = diffSamples.CurrentValue;
                        RcCore.It.EngineSettings.GlossySamples = glossySamples.CurrentValue;
                        RcCore.It.EngineSettings.SensorWidth = (float)sensorWidth.CurrentValue;
                        RcCore.It.EngineSettings.SensorHeight = (float)sensorHeight.CurrentValue;
                        RcCore.It.EngineSettings.IntegratorMethod = branched.CurrentValue ? IntegratorMethod.BranchedPath : IntegratorMethod.Path;
                        RcCore.It.EngineSettings.SamplingPattern = SamplingPattern.Sobol;
                        RcCore.It.EngineSettings.FilterGlossy = 0.0f;
                        RcCore.It.EngineSettings.SampleClampDirect = 0.0f;
                        RcCore.It.EngineSettings.SampleClampIndirect = 0.0f;
                        RcCore.It.EngineSettings.SampleAllLights = true;
                        RcCore.It.EngineSettings.SampleAllLightsIndirect = true;
                        break;
                    case GetResult.Option:
                        continue;
                }

                break;
            }
            return Result.Success;
        }