protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Point3d base_pt; var rc = RhinoGet.GetPoint("Start of line", false, out base_pt); if (rc != Result.Success) { return(rc); } var gp = new GetPoint(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(base_pt, true); gp.DrawLineFromPoint(base_pt, true); gp.DynamicDraw += gp_DynamicDraw; gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_pt = gp.Point(); var vector = end_pt - base_pt; if (vector.Length > doc.ModelAbsoluteTolerance) { var line = new Line(base_pt, end_pt); doc.Objects.AddLine(line); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Point3d basePt; Result rc = RhinoGet.GetPoint("Start of line", false, out basePt); if (rc != Result.Success) { return(rc); } GetPoint gp = new GetPoint(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(basePt, true); gp.DrawLineFromPoint(basePt, true); gp.DynamicDraw += new EventHandler <GetPointDrawEventArgs>(gp_DynamicDraw); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d endPt = gp.Point(); Rhino.Geometry.Vector3d vector = endPt - basePt; if (vector.Length > doc.ModelAbsoluteTolerance) { Line line = new Line(basePt, endPt); doc.Objects.AddLine(line); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select grips to move"); go.GeometryFilter = ObjectType.Grip; go.EnablePreSelect(true, true); go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var gp = new GetPoint(); gp.SetCommandPrompt("Point to move from"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var from = gp.Point(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(from, true); gp.DrawLineFromPoint(from, true); gp.Get(); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var to = gp.Point(); var dir = to - from; if (dir.IsTiny(doc.ModelAbsoluteTolerance)) { return(Result.Nothing); } var xform = Transform.Translation(dir); var helper = new SampleCsGripHelper(doc); helper.AddGripObjects(go); helper.TransformAndUpdate(xform); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Loop loop = new Loop(); loop.Run(doc); return(Result.Success); // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } doc.Objects.AddLine(pt0, pt1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); // --- return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef objref; var rc = RhinoGet.GetOneObject("Select object to move", false, ObjectType.AnyObject, out objref); if (rc != Result.Success) { return(rc); } if (null == objref) { return(Result.Failure); } Point3d first_point; rc = RhinoGet.GetPoint("Point to move from", false, out first_point); if (rc != Result.Success) { return(rc); } var gp = new GetPoint(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(first_point, true); gp.DrawLineFromPoint(first_point, true); gp.Get(); rc = gp.CommandResult(); if (rc != Result.Success) { return(rc); } var second_point = gp.Point(); var dir = second_point - first_point; if (dir.Length > RhinoMath.ZeroTolerance) { var xform = Transform.Translation(dir); doc.Objects.Transform(objref, xform, true); doc.Views.Redraw(); } return(rc); }
private Tuple <Point3d, Point3d> GetSpine() { // Get user input for spine bool unsucessfulGetSpine = false; Point3d pt0 = new Point3d(0, 0, 0); using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Spine: start point"); if (getPointAction.Get() != GetResult.Point) { unsucessfulGetSpine = true; //RhinoApp.WriteLine("No start point was selected."); //return getPointAction.CommandResult(); } if (!unsucessfulGetSpine) { pt0 = getPointAction.Point(); } } Point3d pt1 = new Point3d(0, 0, 0); using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Spine: end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed); if (getPointAction.Get() != GetResult.Point) { unsucessfulGetSpine = true; //RhinoApp.WriteLine("No end point was selected."); //return getPointAction.CommandResult(); } if (!unsucessfulGetSpine) { pt1 = getPointAction.Point(); } } if (unsucessfulGetSpine) { return(null); } return(new Tuple <Point3d, Point3d>(pt0, pt1)); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { #if IncludeSample // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DrawLineFromPoint(pt0, true); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } doc.Objects.AddLine(pt0, pt1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); return(Result.Success); #else // TODO: start here modifying the behaviour of your command. return(Result.Success); #endif }
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); // сообщение в командной строке о том что команда запущена и что она будет делать // Point3d pt0; // декларируем новую переменную точка (начало линии) using (GetPoint getPointAction = new GetPoint()) // ?? { // getPointAction.SetCommandPrompt("Please select the start point"); // призыв к действию в командной строке (жирным) if (getPointAction.Get() != GetResult.Point) // что делать если точкка не выбрана но был нажет Enter { // RhinoApp.WriteLine("No start point was selected."); // если точкка не выбрана но был нажет Enter, то написать это в командной строке return(getPointAction.CommandResult()); // ?? } // pt0 = getPointAction.Point(); // присвоить для переменной pt1 только что выбранную точку } Point3d pt1; // декларируе новую переменную точка ( конец линии) using (GetPoint getPointAction = new GetPoint()) { // getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed); if (getPointAction.Get() != GetResult.Point) // если точкка не выбрана но был нажет Enter { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); // присвоить для переменной pt1 только что выбранную точку } doc.Objects.AddLine(pt0, pt1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); // сообщение в командную строку что всё готово // --- return(Result.Success); }
protected override Result RunCommand(Rhino.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); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DrawLineFromPoint(pt0, true); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } Rhino.Geometry.Line line1 = new Line(pt0, pt1); doc.Objects.AddLine(line1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); RhinoApp.WriteLine("The distance between the two points is {0} {1}.", line1.Length, doc.ModelUnitSystem.ToString().ToLower()); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs); if (rc != Result.Success || obj_refs == null) { return(rc); } var gp = new GetPoint(); gp.SetCommandPrompt("Point to move from"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var start_point = gp.Point(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_point = gp.Point(); var xform = Transform.Translation(end_point - start_point); foreach (var obj_ref in obj_refs) { doc.Objects.Transform(obj_ref, xform, true); } doc.Views.Redraw(); return(Result.Success); }
public static Result Ortho(RhinoDoc doc) { var gp = new GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var start_point = gp.Point(); var original_ortho = ModelAidSettings.Ortho; if (!original_ortho) { ModelAidSettings.Ortho = true; } gp.SetCommandPrompt("End of line"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_point = gp.Point(); if (ModelAidSettings.Ortho != original_ortho) { ModelAidSettings.Ortho = original_ortho; } doc.Objects.AddLine(start_point, end_point); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select curve to intersect"); go.GeometryFilter = ObjectType.Curve; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var curve = go.Object(0).Curve(); if (null == curve) { return(Result.Failure); } var gp = new GetPoint(); gp.SetCommandPrompt("First point of infinite intersecting line"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var from = gp.Point(); gp.SetCommandPrompt("Second point of infinite intersecting line"); gp.SetBasePoint(from, true); gp.DrawLineFromPoint(from, true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var line = new Rhino.Geometry.Line(from, gp.Point()); if (!line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon) { return(Result.Nothing); } var ccx = IntersectCurveLine(curve, line, doc.ModelAbsoluteTolerance, doc.ModelAbsoluteTolerance); if (null != ccx) { foreach (var x in ccx) { if (x.IsPoint) { doc.Objects.AddPoint(x.PointA); } } doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (TimePanel.Instance.Restarted && TimePanel.Instance.TrackbarValue == 0) { RhinoApp.WriteLine("Now it's time to draw a sphere"); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("The center of the sphere"); if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No center point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); if (pt0.Z != 0) { RhinoApp.WriteLine("The center of the sphere is not on the plane XY"); return(getPointAction.CommandResult()); } } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("The end point of the radius of the sphere"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawSphere(new Sphere(pt0, new Line(pt0, e.CurrentPoint).Length), Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No radius point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } double radius = new Line(pt0, pt1).Length; Shape sphereShape = new SphereShape((float)radius); RigidBody rigidSphere = new RigidBody(sphereShape); rigidSphere.Position = new JVector((float)pt0.X, (float)pt0.Y, (float)pt0.Z); Sphere sphere = new Sphere(pt0, radius); //Original one with the center in 0,0,0 Sphere copySphere = new Sphere(new Point3d(0, 0, 0), radius); Brep brepSphere = copySphere.ToBrep(); //Copy to translate and rotate Brep copyToAdd = sphere.ToBrep(); RigidBodyManager.RigidBodies.Add(rigidSphere); RigidBodyManager.GeometryList.Add(brepSphere); RigidBodyManager.GuidList.Add(doc.Objects.Add(copyToAdd)); doc.Views.Redraw(); return(Result.Success); } else { Dialogs.ShowMessage("Press Restart before use other commands", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Success); } }
private static Result GetTolerance(ref double tolerance) { var gp = new GetPoint(); gp.SetCommandPrompt("Tolerance"); gp.SetDefaultNumber(tolerance); gp.AcceptNumber(true, false); for (; ;) { var res = gp.Get(); if (res == GetResult.Number) { var d = gp.Number(); if (d < 0.0) { RhinoApp.WriteLine("Tolerance must be greater than 0."); } else { tolerance = d; return(Result.Success); } } if (res != GetResult.Point) { return(Result.Cancel); } break; } var base_point = gp.Point(); gp.SetBasePoint(base_point, true); gp.DrawLineFromPoint(base_point, true); gp.DynamicDrawColor = Rhino.ApplicationSettings.AppearanceSettings.TrackingColor; for (; ;) { var res = gp.Get(); if (res == GetResult.Number) { var d = gp.Number(); if (d < 0.0) { RhinoApp.WriteLine("Tolerance must be greater than 0."); } else { tolerance = d; return(Result.Success); } } if (res != GetResult.Point) { return(Result.Cancel); } break; } tolerance = base_point.DistanceTo(gp.Point()); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (m_draw_conduit != null) { RhinoApp.WriteLine("Turn off existing arrowhead conduit"); m_draw_conduit.Enabled = false; m_draw_conduit = null; } else { // get arrow head size var go = new GetOption(); go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?"); go.AddOption("screen"); go.AddOption("world"); go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } int screen_size = 0; double world_size = 0.0; if (go.Option().EnglishName == "screen") { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetCommandPrompt("Length of arrow head in pixels"); gi.Get(); if (gi.CommandResult() != Result.Success) { return(gi.CommandResult()); } screen_size = gi.Number(); } else { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetUpperLimit(100, false); gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length"); gi.Get(); if (gi.CommandResult() != Result.Success) { return(gi.CommandResult()); } world_size = gi.Number() / 100.0; } // get arrow start and end points var gp = new GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var start_point = gp.Point(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_point = gp.Point(); var v = end_point - start_point; if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance)) { return(Result.Nothing); } var line = new Line(start_point, end_point); m_draw_conduit = new DrawArrowHeadsConduit(line, screen_size, world_size); // toggle conduit on/off m_draw_conduit.Enabled = true; RhinoApp.WriteLine("Draw arrowheads conduit enabled."); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (TimePanel.Instance.Restarted && TimePanel.Instance.TrackbarValue == 0) { RhinoApp.WriteLine("Now it's time to draw a box"); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("First corner of the base"); if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No corner point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); if (pt0.Z != 0) { RhinoApp.WriteLine("The base of the square is not on the plane XY"); return(getPointAction.CommandResult()); } } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Other corner of the base"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(pt0, new Point3d(pt0.X, e.CurrentPoint.Y, 0), Color.Black); e.Display.DrawLine(pt0, new Point3d(e.CurrentPoint.X, pt0.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, e.CurrentPoint.Y, 0), e.CurrentPoint, Color.Black); e.Display.DrawLine(new Point3d(e.CurrentPoint.X, pt0.Y, 0), e.CurrentPoint, Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No corner point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); if (pt1.Z != 0) { RhinoApp.WriteLine("The base of the square is not on the plane XY"); return(getPointAction.CommandResult()); } if (pt1.Equals(pt0)) { RhinoApp.WriteLine("The second point is the same of the first"); return(getPointAction.CommandResult()); } } Point3d pt2; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Height"); getPointAction.SetBasePoint(pt1, true); var line = new Rhino.Geometry.Line(pt1, new Point3d(pt1.X, pt1.Y, 1)); getPointAction.Constrain(line); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(pt0, new Point3d(pt0.X, pt1.Y, 0), Color.Black); e.Display.DrawLine(pt0, new Point3d(pt1.X, pt0.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, 0), pt1, Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, 0), pt1, Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), e.CurrentPoint, Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), e.CurrentPoint, Color.Black); e.Display.DrawLine(pt0, new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(pt1, new Point3d(pt1.X, pt1.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), new Point3d(pt0.X, pt1.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt1.X, pt0.Y, 0), Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No Height point was selected."); return(getPointAction.CommandResult()); } pt2 = getPointAction.Point(); if (pt2.Z == 0) { RhinoApp.WriteLine("The height of the box must be different of 0"); return(getPointAction.CommandResult()); } } //Find center of the box Point3d middleDiagonal = new Point3d((pt0.X + pt1.X) / 2, (pt0.Y + pt1.Y) / 2, 0); Point3d middleHeight = new Point3d(0, 0, (pt1.Z + pt2.Z) / 2); Point3d centerBox = new Point3d(middleDiagonal.X, middleDiagonal.Y, middleHeight.Z); //Find dimension of the box Shape boxShape = new BoxShape((float)Math.Abs(pt1.X - pt0.X), (float)Math.Abs(pt1.Y - pt0.Y), (float)Math.Abs(pt2.Z)); RigidBody rigidBox = new RigidBody(boxShape); rigidBox.Position = new JVector((float)centerBox.X, (float)centerBox.Y, (float)centerBox.Z); Box box = new Box(new BoundingBox(RigidBodyManager.JVectorToPoint3d(boxShape.BoundingBox.Min), RigidBodyManager.JVectorToPoint3d(boxShape.BoundingBox.Max))); //Original one with the center in 0,0,0 Brep brepBox = box.ToBrep(); //Copy to translate and rotate Brep copyToAdd = brepBox.DuplicateBrep(); //Move the box to the correct position copyToAdd.Translate(centerBox.X, centerBox.Y, centerBox.Z); RigidBodyManager.RigidBodies.Add(rigidBox); RigidBodyManager.GeometryList.Add(brepBox); RigidBodyManager.GuidList.Add(doc.Objects.Add(copyToAdd)); doc.Views.Redraw(); return(Result.Success); } else { Dialogs.ShowMessage("Press Restart before use other commands", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); 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) { if (TimePanel.Instance.Restarted && TimePanel.Instance.TrackbarValue == 0) { RhinoApp.WriteLine("Now it's time to draw a cylinder"); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("The center of the base"); if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No center point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); if (pt0.Z != 0) { RhinoApp.WriteLine("The center of the cylinder is not on the plane XY"); return(getPointAction.CommandResult()); } } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("The end point of the radius of the cylinder"); getPointAction.SetBasePoint(pt0, true); var line = new Line(pt0, new Point3d(pt0.X, pt0.Y, 1)); getPointAction.Constrain(line); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(new Line(e.CurrentPoint, new Point3d(e.CurrentPoint.X, e.CurrentPoint.Y, -e.CurrentPoint.Z)), Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No radius point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } Point3d pt2; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Height"); getPointAction.SetBasePoint(pt1, true); var line = new Rhino.Geometry.Line(pt1, new Point3d(pt1.X, 1, pt1.Z)); getPointAction.Constrain(line); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(new Line(pt1, new Point3d(pt1.X, pt1.Y, -pt1.Z)), Color.Black); e.Display.DrawLine(new Line(pt1, e.CurrentPoint), Color.Black); e.Display.DrawLine(new Line(new Point3d(e.CurrentPoint.X, e.CurrentPoint.Y, -e.CurrentPoint.Z), e.CurrentPoint), Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No Height point was selected."); return(getPointAction.CommandResult()); } pt2 = getPointAction.Point(); if (pt2.Z == 0) { RhinoApp.WriteLine("The height of the cylinder must be different of 0"); return(getPointAction.CommandResult()); } } double radius = new Line(pt0, pt1).Length; double height = new Line(pt1, pt2).Length; Shape cylinderShape = new CylinderShape((float)height, (float)radius); RigidBody rigidCylinder = new RigidBody(cylinderShape); //Translate to the user position rigidCylinder.Position = new JVector((float)(pt0.X), (float)(pt0.Y - height / 2), 0); Cylinder cylinder = new Cylinder(new Circle(Point3d.Origin, radius), height); //Original one with the center in 0,0,0 Cylinder copyCylinder = new Cylinder(new Circle(new Point3d(0, 0, 0), radius), height); Brep brepCylinder = copyCylinder.ToBrep(true, true); Transform trafo = MatrixXRotation(90); trafo = trafo.Transpose(); //put center in 0,0,0 brepCylinder.Translate(new Vector3d(0, 0, -height / 2)); brepCylinder.Transform(trafo); //Copy to translate and rotate Brep copyToAdd = cylinder.ToBrep(true, true); copyToAdd.Translate(new Vector3d(0, 0, -height / 2)); copyToAdd.Transform(trafo); if (pt0.Y > pt2.Y) { copyToAdd.Translate(new Vector3d(pt0.X, pt0.Y - height / 2, 0)); } else { copyToAdd.Translate(new Vector3d(pt2.X, pt2.Y - height / 2, 0)); } RigidBodyManager.RigidBodies.Add(rigidCylinder); RigidBodyManager.GeometryList.Add(brepCylinder); RigidBodyManager.GuidList.Add(doc.Objects.Add(copyToAdd)); doc.Views.Redraw(); } else { Dialogs.ShowMessage("Press Restart before use other commands", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); } return(Result.Success); }