//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); } }
// 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); } }
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); }
/// <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); }
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); }