protected override Result RunCommand(RhinoDoc doc, RunMode mode) { 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) { //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to expand"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); goList.Add(obj); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); Rhino.Display.RhinoView view = gp2.View(); plane2D = view.ActiveViewport.ConstructionPlane(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Expantion factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); Vector3d planeNormal = plane2D.Normal; if (planeNormal[0] != 0) { vec.X = 0; } else if (planeNormal[1] != 0) { vec.Y = 0; } else if (planeNormal[2] != 0) { vec.Z = 0; } var xform = Rhino.Geometry.Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vecEach = (centers[i] - scaleCenter); double vecEachLength = vecEach.Length * (factor - 1); Vector3d vec = (scaleRefPoint - scaleCenter); double angleVec = Vector3d.VectorAngle(vecEach, vec); int pol = 1; if (angleVec > 1.57) { pol = -1; } vec.Unitize(); vec = vec * vecEachLength * pol; var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } goList = new List <Object>(); centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); doc.Views.Redraw(); 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) { // Locals Plane plane; Point3d base_point = Point3d.Unset; Point3d ref_point = Point3d.Unset; GetResult res = GetResult.Nothing; Result rc = Result.Nothing; // Select objects to rotate TransformObjectList list = new TransformObjectList(); rc = SelectObjects("Select objects to rotate", list); if (rc != Result.Success) { return(rc); } GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Center of rotation"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } RhinoView view = gp.View(); if (null == view) { return(Result.Failure); } base_point = gp.Point(); plane = view.ActiveViewport.ConstructionPlane(); plane.Origin = base_point; // Angle or first reference point GetReferencePoint gr = new GetReferencePoint(base_point); gr.SetCommandPrompt("Angle or first reference point"); res = gr.Get(); if (res == GetResult.Point) { view = gr.View(); rc = (null != view) ? Result.Success : Result.Failure; if (rc == Result.Success) { plane = view.ActiveViewport.ConstructionPlane(); plane.Origin = base_point; ref_point = plane.ClosestPoint(gr.Point()); if (base_point.DistanceTo(ref_point) <= RhinoMath.ZeroTolerance) { rc = Result.Nothing; } } if (rc != Result.Success) { return(rc); } } else if (res == GetResult.Number) { Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gr.Number()), plane.Normal, base_point); rc = (xform.IsValid) ? Result.Success : Result.Failure; if (rc == Result.Success) { TransformObjects(list, xform, false, false); doc.Views.Redraw(); } return(rc); } else { return(Result.Cancel); } // Second reference point GetRotationTransform gx = new GetRotationTransform(plane, base_point, ref_point); gx.SetCommandPrompt("Second reference point"); gx.AddTransformObjects(list); res = gx.GetXform(); if (res == GetResult.Point) { view = gx.View(); rc = (null != view) ? Result.Success : Result.Failure; if (rc == Result.Success) { Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point()); rc = (xform.IsValid) ? Result.Success : Result.Failure; if (rc == Result.Success) { TransformObjects(list, xform, false, false); doc.Views.Redraw(); } } } else if (res == GetResult.Number) { Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gx.Number()), plane.Normal, base_point); rc = (xform.IsValid) ? Result.Success : Result.Failure; if (rc == Result.Success) { TransformObjects(list, xform, false, false); doc.Views.Redraw(); } } else { rc = Result.Cancel; } return(rc); }
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) { GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Base of cylinder"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d center = gp.Point(); Plane plane = Plane.WorldXY; RhinoView view = gp.View(); if (null != view) { plane = view.ActiveViewport.ConstructionPlane(); } plane.Origin = center; var cylinder = new SampleCsGumballCylinder(plane, m_radius, m_height); var radius_go = new GumballObject(); var height_go = new GumballObject(); var radius_dc = new GumballDisplayConduit(); var height_dc = new GumballDisplayConduit(); var radius_gas = RadiusGumballAppearanceSettings(); var height_gas = HeightGumballAppearanceSettings(); while (true) { radius_go.SetFromPlane(cylinder.RadiusPlane); height_go.SetFromPlane(cylinder.HeightPlane); radius_dc.SetBaseGumball(radius_go, radius_gas); height_dc.SetBaseGumball(height_go, height_gas); radius_dc.Enabled = true; height_dc.Enabled = true; var gx = new SampleCsGumballCylinderGetPoint(cylinder, radius_dc, height_dc); gx.SetCommandPrompt("Drag gumball. Press Enter when done"); gx.AcceptNothing(true); gx.MoveGumball(); radius_dc.Enabled = false; height_dc.Enabled = false; if (gx.CommandResult() != Result.Success) { break; } var res = gx.Result(); if (res == GetResult.Point) { var radius = cylinder.Radius; var height = cylinder.Height; cylinder = new SampleCsGumballCylinder(plane, radius, height); continue; } if (res == GetResult.Nothing) { m_radius = cylinder.Radius; m_height = cylinder.Height; cylinder = new SampleCsGumballCylinder(plane, m_radius, m_height); var brep = cylinder.ToBrep; if (null != brep) { doc.Objects.AddBrep(brep); } } break; } 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); } }
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) { 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // this creates a point where the mouse is clicked. var gp = new GetPoint(); gp.SetCommandPrompt("Click for new point"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var point3d = gp.Point(); doc.Objects.AddPoint(point3d); doc.Views.Redraw(); // selects a point that already exists ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select point", false, ObjectType.Point, out obj_ref); if (rc != Result.Success) { return(rc); } var point = obj_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); doc.Objects.UnselectAll(); // selects multiple points that already exist ObjRef[] obj_refs; rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs); if (rc != Result.Success) { return(rc); } foreach (var o_ref in obj_refs) { point = o_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } doc.Objects.UnselectAll(); // also selects a point that already exists. // Used when RhinoGet doesn't provide enough control var go = new GetObject(); go.SetCommandPrompt("Select point"); go.GeometryFilter = ObjectType.Point; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } foreach (var o_ref in go.Objects()) { point = o_ref.Point(); if (point != null) { RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } } doc.Views.Redraw(); 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop; //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to scale"); go.GeometryFilter = myTypes; //go.GroupSelect = true; go.SubObjectSelect = true; //go.EnableClearObjectsOnEntry(false); //go.EnableUnselectObjectsOnExit(false); //go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); dynRef.Add(objref); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } Rhino.Display.RhinoView view = gp.View(); plane2D = view.ActiveViewport.ConstructionPlane(); //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Scale factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { var xform = Transform.Scale(centers[i], factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { plane2D.Origin = centers[i]; var xform = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (scaleRefPoint - scaleCenter); Plane scalePlane = new Plane(centers[i], vec); var xform = Transform.Scale(scalePlane, 1, 1, factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); dynRef = new List <Rhino.DocObjects.ObjRef>(); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Called by Rhino to 'run' this command /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Select objects to orient var go = new GetObject(); go.SetCommandPrompt("Select objects to orient"); go.SubObjectSelect = false; go.EnableIgnoreGrips(true); go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } // Point to move from var gp = new GetPoint(); gp.SetCommandPrompt("Point to move from"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } // Calculate source plane var plane = gp.View().ActiveViewport.ConstructionPlane(); plane.Origin = gp.Point(); // Mesh to orient on var gm = new GetObject(); gm.SetCommandPrompt("Mesh to orient on"); gm.GeometryFilter = ObjectType.Mesh; gm.EnablePreSelect(false, true); gm.DeselectAllBeforePostSelect = false; gm.Get(); if (gm.CommandResult() != Result.Success) { return(gm.CommandResult()); } var mesh = gm.Object(0).Mesh(); if (null == mesh) { return(Result.Failure); } // Point on mesh to orient to var gpm = new GetPointOnMesh(mesh, plane); gpm.SetCommandPrompt("Point on mesh to orient to"); gpm.AppendObjects(go); gpm.Get(); if (gpm.CommandResult() != Result.Success) { return(gpm.CommandResult()); } // One final calculation var xform = new Transform(1); if (gpm.CalculateTransform(gpm.View().ActiveViewport, gpm.Point(), ref xform)) { foreach (var objRef in go.Objects()) { var obj = objRef.Object(); if (null != obj) { doc.Objects.Transform(obj, xform, true); } } doc.Views.Redraw(); } 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); }
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); }