protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Pick a mesh ObjRef obj_ref; Result rc = RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out obj_ref); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Mesh mesh = obj_ref.Mesh(); if (null == mesh) { return(Result.Failure); } // Pick a point that is contrained to the mesh GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Pick point on mesh"); gp.Constrain(mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d point = gp.Point(); doc.Objects.AddPoint(point); doc.Views.Redraw(); return(Result.Success); }
public static Result DetermineNormalDirectionOfBrepFace(RhinoDoc doc) { // select a surface var gs = new GetObject(); gs.SetCommandPrompt("select surface"); gs.GeometryFilter = ObjectType.Surface; gs.DisablePreSelect(); gs.SubObjectSelect = false; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } // get the selected face var face = gs.Object(0).Face(); if (face == null) { return(Result.Failure); } // pick a point on the surface. Constain // picking to the face. var gp = new GetPoint(); gp.SetCommandPrompt("select point on surface"); gp.Constrain(face, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } // get the parameters of the point on the // surface that is clesest to gp.Point() double u, v; if (face.ClosestPoint(gp.Point(), out u, out v)) { var direction = face.NormalAt(u, v); if (face.OrientationIsReversed) { direction.Reverse(); } RhinoApp.WriteLine( string.Format( "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", u, v, direction.X, direction.Y, direction.Z)); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); go.SetCommandPrompt("Select closed curve for seam adjustment"); go.GeometryFilter = ObjectType.Curve; go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } Curve curve = go.Object(0).Curve(); if (null == curve) { return(Result.Failure); } GetPoint gp = new GetPoint(); gp.SetCommandPrompt("New seam location"); gp.Constrain(curve, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d point = gp.Point(); Curve new_curve = curve.DuplicateCurve(); double t = Rhino.RhinoMath.UnsetValue; if (new_curve.ClosestPoint(point, out t)) { if (new_curve.ChangeClosedCurveSeam(t)) { doc.Objects.Replace(go.Object(0), new_curve); } } return(Result.Success); }
//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); } }
public static Result FindCurveParameterAtPoint(RhinoDoc doc) { Rhino.DocObjects.ObjRef objref; var rc = RhinoGet.GetOneObject("Select curve", true, ObjectType.Curve, out objref); if (rc != Result.Success) { return(rc); } var curve = objref.Curve(); if (curve == null) { return(Result.Failure); } var gp = new GetPoint(); gp.SetCommandPrompt("Pick a location on the curve"); gp.Constrain(curve, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var point = gp.Point(); double closest_point_param; if (curve.ClosestPoint(point, out closest_point_param)) { RhinoApp.WriteLine("point: ({0}), parameter: {1}", point, closest_point_param); doc.Objects.AddPoint(point); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); go.SetCommandPrompt("Select curve to split"); go.GeometryFilter = ObjectType.Curve; go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } ObjRef object_ref = go.Object(0); RhinoObject rh_object = object_ref.Object(); Curve curve = object_ref.Curve(); if (null == rh_object || null == curve) { return(Result.Failure); } GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Point on curve to split at"); gp.Constrain(curve, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d point = gp.Point(); double t = Rhino.RhinoMath.UnsetValue; if (!curve.ClosestPoint(point, out t)) { return(Result.Failure); } List <double> curve_t = new List <double>(3); curve_t.Add(curve.Domain.Min); curve_t.Add(curve.Domain.Max); curve_t.Add(t); curve_t.Sort(); List <double> culled_t = curve_t.Distinct().ToList(); if (culled_t.Count < 3) { return(Result.Nothing); } ObjectAttributes attributes = rh_object.Attributes.Duplicate(); attributes.ObjectId = Guid.Empty; for (int i = 0; i < culled_t.Count - 1; i++) { Interval domain = new Interval(culled_t[i], culled_t[i + 1]); if (curve.Domain.IncludesInterval(domain)) { Curve trim = curve.Trim(domain); if (null != trim) { doc.Objects.Add(trim, attributes); } } } doc.Objects.Delete(object_ref, false); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef obj_ref; const string prompt = "Select curve to edit"; const ObjectType object_type = ObjectType.Curve; Result res = RhinoGet.GetOneObject(prompt, false, object_type, out obj_ref); if (res != Result.Success) { return(res); } Curve crv = obj_ref.Curve(); if (null == crv) { return(Result.Failure); } GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Start point for deletion"); gp.Constrain(crv, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } double t0 = RhinoMath.UnsetValue; Curve out_crv = gp.PointOnCurve(out t0); if (null == out_crv) { return(Result.Failure); } gp.SetCommandPrompt("End point for deletion"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } double t1 = RhinoMath.UnsetValue; out_crv = gp.PointOnCurve(out t1); if (null == out_crv) { return(Result.Failure); } if (Math.Abs(t1 - t0) < RhinoMath.ZeroTolerance) { return(Result.Nothing); } Interval range = new Interval(t0, t1); if (!crv.IsClosed && range.IsDecreasing) { range.Swap(); } Curve sub_crv = crv.Trim(crv.Domain.Min, range.Min); if (null != sub_crv) { doc.Objects.AddCurve(sub_crv); } sub_crv = crv.Trim(range.Max, crv.Domain.Max); if (null != sub_crv) { doc.Objects.AddCurve(sub_crv); } doc.Objects.Delete(obj_ref, true); doc.Views.Redraw(); return(Result.Success); }
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); }
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) { 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); }
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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. //DijkstraGraph graph = new DijkstraGraph(50); MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; Mesh my_mesh = p.painted_object_; int vertex_list_count = p.graph.GetVertexListCount(); RhinoApp.WriteLine("the total number of vertices is {0}", vertex_list_count); GetPoint gp_start = new GetPoint(); gp_start.SetCommandPrompt("Get the begin point on mesh: "); gp_start.Constrain(my_mesh, false); gp_start.Get(); if (gp_start.CommandResult() != Result.Success) { return(gp_start.CommandResult()); } Point3d p_start = gp_start.Point(); GetPoint gp_end = new GetPoint(); gp_end.SetCommandPrompt("Get the end point on mesh: "); gp_end.Constrain(my_mesh, false); gp_end.Get(); if (gp_end.CommandResult() != Result.Success) { return(gp_end.CommandResult()); } Point3d p_end = gp_end.Point(); int begin_num = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_start, 0).FaceIndex); int end_num = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_end, 0).FaceIndex); /* * GetInteger g_begin = new GetInteger(); * g_begin.SetCommandPrompt("Type in the number of beginning vertex"); * g_begin.AcceptNumber(true, true); * g_begin.Get(); * int begin_num = g_begin.Number(); * GetInteger g_end = new GetInteger(); * g_end.SetCommandPrompt("Type in the number of the ending vertex"); * g_end.AcceptNumber(true, true); * g_end.Get(); * int end_num = g_end.Number(); */ NurbsCurve d_path = p.graph.GetDijkstraPath(begin_num, end_num, true).path; ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.AddCurve(d_path, my_attributes); doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_start, 0).Point); doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_end, 0).Point); doc.Views.Redraw(); return(Result.Success); }