//this function gets the first point from the user
        private Result GetFirstPoint(ref Point3d pt, Plane pl, bool IsFirstRun)
        {
            using (GetPoint getPointAction = new GetPoint())
            {
                if (IsFirstRun)
                {
                    getPointAction.AddOptionDouble("Width", ref this.width);
                    getPointAction.AddOptionDouble("RailHeight", ref this.railHeight);
                    getPointAction.AddOptionToggle("LeftRail", ref this.leftRail);
                    getPointAction.AddOptionToggle("RightRail", ref this.rightRail);
                }
                if (!IsFirstRun)
                {
                    getPointAction.AddOptionToggle("Landing", ref this.LandingToggle);
                }

                getPointAction.SetCommandPrompt("Begin making stairs. Select the starting point of the run");
                if (!IsFirstRun)
                {
                    getPointAction.Constrain(pl, false);
                }

                while (true)
                {
                    GetResult get_rc = getPointAction.Get();
                    if (getPointAction.CommandResult() != Result.Success)
                    {
                        return(getPointAction.CommandResult());
                    }
                    if (get_rc == GetResult.Point)
                    {
                        pt = getPointAction.Point();
                    }
                    else if (get_rc == GetResult.Option)
                    {
                        continue;
                    }
                    break;
                }

                return(Result.Success);
            }
        }
Exemple #2
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            var dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string[] pathComponent = new string[] { dirname.ToString(), @"common_paper_sizes.json" };
            var      jsonPath      = Path.Combine(pathComponent);

            GetPoint gp   = new GetPoint();
            string   text = System.IO.File.ReadAllText(jsonPath);

            gp.SetCommandPrompt("Set Origin of Paper Rectangle");

            OptionToggle boolOption = new OptionToggle(false, "Off", "On");

            gp.AddOptionToggle("Portrait", ref boolOption);

            var listNames  = new List <string>();
            var listValues = new List <Point2d>();



            List <Paper> papers = JsonConvert.DeserializeObject <List <Paper> >(text);
            //foreach(var paper in papers)
            //{
            var count = 0;

            foreach (var format in papers[0].formats)
            {
                var num = int.Parse(Regex.Match(format.name, @"\d+").Value);

                if (num < 6 && !format.name.Contains("C"))
                {
                    listNames.Add(format.name);
                    listValues.Add(new Point2d(format.size.mm[0], format.size.mm[1]));
                    count++;
                }
            }

            //}
            var listNamesArr = listNames.ToArray();
            int listIndex    = 0;
            int opList       = gp.AddOptionList("PaperType", listNamesArr, 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)
                {
                    var plane = doc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane;
                    plane.Origin = gp.Point();
                    var item       = listValues[listIndex];
                    var isPortrait = boolOption.CurrentValue;
                    var rect       = new Rectangle3d(plane, isPortrait ? item.X : item.Y, isPortrait ? item.Y : item.X);
                    var attr       = new Rhino.DocObjects.ObjectAttributes();
                    attr.Name       = listNames[listIndex];
                    attr.LayerIndex = doc.Layers.CurrentLayerIndex;
                    doc.Objects.AddRectangle(rect, attr);
                    doc.Views.Redraw();
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gp.OptionIndex() == opList)
                    {
                        listIndex = gp.Option().CurrentListOptionIndex;
                    }
                    continue;
                }
                break;
            }
            return(Rhino.Commands.Result.Success);
        }
Exemple #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            points.Clear();

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

                bool    undo = false;
                Point3d pt0;
                Point3d pt0M;
                int     insert;

                GetPoint getPoint = new GetPoint();
                getPoint.SetCommandPrompt("Please select point");

                var boolOptionAxis = new Rhino.Input.Custom.OptionToggle(front, "Front", "Side");
                getPoint.AddOptionToggle("MirrorPlane", ref boolOptionAxis);
                var boolOption = new Rhino.Input.Custom.OptionToggle(clamped, "Off", "On");
                getPoint.AddOptionToggle("Closed", ref boolOption);
                var undoOption = new Rhino.Input.Custom.OptionToggle(undo, "No", "Yes");
                getPoint.AddOptionToggle("Undo", ref undoOption);

                if (points.Count > 1)
                {
                    getPoint.DynamicDraw += DynDrawCurve;
                }

                getPoint.AcceptNothing(true);
                GetResult gr = getPoint.Get();
                if (gr == GetResult.Nothing)
                {
                    break;
                }
                else if (gr == GetResult.Option)
                {
                    clamped = boolOption.CurrentValue;
                    front   = boolOptionAxis.CurrentValue;
                    undo    = undoOption.CurrentValue;
                    if (front == false)
                    {
                        xm = -1;
                        ym = 1;
                    }
                    else if (front)
                    {
                        xm = 1;
                        ym = -1;
                    }
                    if (undo)
                    {
                        points.RemoveAt(points.Count / 2);
                        points.RemoveAt(points.Count / 2);
                    }
                }
                else if (gr == GetResult.Point)
                {
                    pt0    = getPoint.Point();
                    pt0M   = new Point3d(xm * pt0.X, ym * pt0.Y, pt0.Z);
                    insert = points.Count / 2;
                    points.Insert(insert, pt0);
                    points.Insert(insert + 1, pt0M);
                }

                if (m_escape_key_pressed)
                {
                    break;
                }
            }

            NurbsCurve nc = NurbsCurve.Create(clamped, 3, points);

            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
            doc.Objects.AddCurve(nc);
            doc.Views.Redraw();

            return(Result.Success);
        }
Exemple #4
0
    public static Result ExtractIsoCurve(RhinoDoc doc)
    {
        ObjRef obj_ref;
        var    rc = RhinoGet.GetOneObject("Select surface", false, ObjectType.Surface, out obj_ref);

        if (rc != Result.Success || obj_ref == null)
        {
            return(rc);
        }
        var surface = obj_ref.Surface();

        var gp = new GetPoint();

        gp.SetCommandPrompt("Point on surface");
        gp.Constrain(surface, false);
        var option_toggle = new OptionToggle(false, "U", "V");

        gp.AddOptionToggle("Direction", ref option_toggle);
        Point3d point = Point3d.Unset;

        while (true)
        {
            var grc = gp.Get();
            if (grc == GetResult.Option)
            {
                continue;
            }
            else if (grc == GetResult.Point)
            {
                point = gp.Point();
                break;
            }
            else
            {
                return(Result.Nothing);
            }
        }
        if (point == Point3d.Unset)
        {
            return(Result.Nothing);
        }

        int    direction = option_toggle.CurrentValue ? 1 : 0; // V : U
        double u_parameter, v_parameter;

        if (!surface.ClosestPoint(point, out u_parameter, out v_parameter))
        {
            return(Result.Failure);
        }

        var iso_curve = surface.IsoCurve(direction, direction == 1 ? u_parameter : v_parameter);

        if (iso_curve == null)
        {
            return(Result.Failure);
        }

        doc.Objects.AddCurve(iso_curve);
        doc.Views.Redraw();
        return(Result.Success);
    }
        // gets the third point from the user
        private Result GetThirdPoint(Point3d firstPt, Point3d secondPt, ref Point3d pt, bool IsFirstRun)
        {
            Run myRun;

            using (GetPoint getPointAction = new GetPoint())
            {
                if (IsFirstRun)
                {
                    getPointAction.AddOptionDouble("Width", ref this.width);
                    getPointAction.AddOptionDouble("RailHeight", ref this.railHeight);
                    getPointAction.AddOptionToggle("LeftRail", ref this.leftRail);
                    getPointAction.AddOptionToggle("RightRail", ref this.rightRail);
                }
                if (!IsFirstRun)
                {
                    getPointAction.AddOptionToggle("Landing", ref this.LandingToggle);
                }

                getPointAction.SetCommandPrompt("Select the third point to determine the height of the run");
                getPointAction.SetBasePoint(secondPt, true);
                getPointAction.Constrain(secondPt, secondPt + Vector3d.ZAxis);

                getPointAction.DynamicDraw += (sender, e) =>
                {
                    myRun = new Run(firstPt, e.CurrentPoint, this.width.CurrentValue);
                    updateRunOptions(ref myRun);
                    Color drawColor = Color.White;
                    if (!myRun.IsValid)
                    {
                        double validVert = myRun.VerticalDistance;
                        double mySlope   = myRun.VerticalDistance / myRun.HorizontalDistance;
                        if (mySlope < code.MIN_SLOPE)
                        {
                            validVert = myRun.HorizontalDistance * code.MIN_SLOPE;
                        }
                        else if (mySlope > code.MAX_SLOPE)
                        {
                            validVert = myRun.HorizontalDistance * code.MAX_SLOPE;
                        }

                        Point3d validEndPt = secondPt + (myRun.RiserDirection * validVert);
                        Run     validRun   = new Run(firstPt, validEndPt, this.width.CurrentValue);
                        updateRunOptions(ref validRun);
                        e.Display.DrawSurface(validRun.getStepSurface(), drawColor, 1);
                        drawColor = Color.Red;
                    }
                    e.Display.DrawSurface(myRun.getStepSurface(), drawColor, 2);
                    e.Display.DrawLines(myRun.getRails(), drawColor);
                    e.Display.DrawLines(myRun.getBalusters(), drawColor);
                    //drawing the landing if this is not the first run
                    if ((!IsFirstRun) && LandingToggle.CurrentValue)
                    {
                        Landing land = new Landing(this.prevRun, myRun);
                        if (land.IsValid)
                        {
                            e.Display.DrawBrepWires(land.LandingSurface, Color.Blue);
                            List <Curve> railing = land.getRailings(this.leftRail.CurrentValue, this.rightRail.CurrentValue);
                            foreach (Curve rail in railing)
                            {
                                e.Display.DrawCurve(rail, Color.Blue);
                            }
                        }
                    }
                };

                while (true)
                {
                    GetResult get_rc = getPointAction.Get();
                    if (getPointAction.CommandResult() != Result.Success)
                    {
                        return(getPointAction.CommandResult());
                    }
                    if (get_rc == GetResult.Point)
                    {
                        pt = getPointAction.Point();
                    }
                    else if (get_rc == GetResult.Option)
                    {
                        continue;
                    }
                    break;
                }

                return(Result.Success);
            }
        }
        //gets the second point from the user
        private Result GetSecondPoint(Point3d firstPt, ref Point3d pt, bool IsFirstRun)
        {
            Run myRun;

            using (GetPoint getPointAction = new GetPoint())
            {
                if (IsFirstRun)
                {
                    getPointAction.AddOptionDouble("Width", ref this.width);
                    getPointAction.AddOptionDouble("RailHeight", ref this.railHeight);
                    getPointAction.AddOptionToggle("LeftRail", ref this.leftRail);
                    getPointAction.AddOptionToggle("RightRail", ref this.rightRail);
                }
                if (!IsFirstRun)
                {
                    getPointAction.AddOptionToggle("Landing", ref this.LandingToggle);
                }

                getPointAction.SetCommandPrompt("Select the ending point of the run (projected)");
                getPointAction.SetBasePoint(firstPt, true);

                Plane hPlane = new Plane(firstPt, Vector3d.ZAxis);
                getPointAction.Constrain(hPlane, false);
                getPointAction.DynamicDraw += (sender, e) =>
                {
                    myRun = new Run(firstPt, e.CurrentPoint, this.width.CurrentValue);
                    e.Display.DrawLines(myRun.getFlatLines(), Color.White);
                    if ((!IsFirstRun) && LandingToggle.CurrentValue)
                    {
                        Landing land = new Landing(this.prevRun, myRun);
                        if (land.IsValid)
                        {
                            e.Display.DrawBrepWires(land.LandingSurface, Color.Blue);
                        }
                    }
                    string textTip = String.Format("N: {0}\nMax.Ht:{1}", myRun.NumSteps, myRun.NumSteps * code.MAX_RISER);
                    e.Display.Draw3dText(new Rhino.Display.Text3d(textTip,
                                                                  new Plane(e.CurrentPoint, Vector3d.ZAxis), code.MIN_TREAD / 2),
                                         Color.Blue,
                                         e.CurrentPoint);
                    //e.Display.Draw2dText("Hello", Color.White, Rhino.UI.MouseCallback.)
                };

                while (true)
                {
                    GetResult get_rc = getPointAction.Get();
                    if (getPointAction.CommandResult() != Result.Success)
                    {
                        return(getPointAction.CommandResult());
                    }
                    if (get_rc == GetResult.Point)
                    {
                        pt = getPointAction.Point();
                    }
                    else if (get_rc == GetResult.Option)
                    {
                        continue;
                    }
                    break;
                }

                return(Result.Success);
            }
        }
Exemple #7
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);
        }
Exemple #8
0
        /// <summary>
        /// RunCommand override
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get persistent settings (from Registry)
            var bool_value = Settings.GetBool("BoolValue", BOOL_DEFAULT);
            var int_value  = Settings.GetInteger("IntValue", INT_DEFAULT);
            var dbl_value  = Settings.GetDouble("DblValue", DBL_DEFAULT);
            var list_value = Settings.GetInteger("ListValue", LIST_DEFAULT);

            var gp = new GetPoint();

            gp.SetCommandPrompt("GetPoint with options");

            var rc = Result.Cancel;

            while (true)
            {
                gp.ClearCommandOptions();

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

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

                var res = gp.Get();

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

                break;
            }

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

            return(rc);
        }