/// <summary> /// Attaches a mobile plane to a Rhino object /// </summary> public static bool Attach(RhinoObject obj, Plane plane, Guid viewportId) { var rc = false; if (null != obj) { var data = DataFromObject(obj); if (null != data) { data.Plane = plane; data.ViewportId = viewportId; rc = true; } else { data = new SampleCsMobilePlaneUserData { Plane = plane, ViewportId = viewportId, Enabled = true }; rc = obj.Geometry.UserData.Add(data); } } return(rc); }
/// <summary> /// Show the mobile construction plane axes. /// </summary> private Result ShowOption(RhinoDoc doc, RhinoObject obj) { if (null == doc || null == obj) { return(Result.Failure); } var data = SampleCsMobilePlaneUserData.DataFromObject(obj); if (null == data) { RhinoApp.WriteLine("No mobile plane attached."); return(Result.Success); } var conduit = new SampleCsMobilePlaneConduit(data.Plane); doc.Views.Redraw(); var gs = new GetString(); gs.SetCommandPrompt("Press <Enter> when done."); gs.Get(); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
/// <summary>. /// Enable mobile plane's dynamic construction plane update. /// </summary> private Result EnableOption(RhinoDoc doc, RhinoObject obj) { if (null == doc || null == obj) { return(Result.Failure); } if (!SampleCsMobilePlaneUserData.IsAttached(obj)) { RhinoApp.WriteLine("No mobile plane attached."); return(Result.Success); } var enable = SampleCsMobilePlaneUserData.IsEnabled(obj); var res = RhinoGet.GetBool("Enable object mobile plane", true, "Disable", "Enable", ref enable); if (res != Result.Success) { return(res); } var rc = SampleCsMobilePlaneUserData.Enable(obj, enable); return(rc ? Result.Success : Result.Failure); }
/// <summary> /// Gets the mobile plane user data from a Rhino object /// </summary> public static SampleCsMobilePlaneUserData DataFromObject(RhinoObject obj) { SampleCsMobilePlaneUserData rc = null; if (null != obj) { rc = obj.Geometry.UserData.Find(typeof(SampleCsMobilePlaneUserData)) as SampleCsMobilePlaneUserData; } return(rc); }
/// <summary> /// Refreshes, or updates, the construction plane tracked by the mobile plane. /// </summary> private Result RefreshOption(RhinoDoc doc, RhinoObject obj) { if (null == doc || null == obj) { return(Result.Failure); } if (!SampleCsMobilePlaneUserData.IsAttached(obj)) { RhinoApp.WriteLine("No mobile plane attached."); return(Result.Success); } var rc = SampleCsMobilePlaneUserData.Refresh(obj, true); return(rc ? Result.Success : Result.Failure); }
/// <summary> /// Attaches a mobile plane to a Rhino object /// </summary> private Result AttachOption(RhinoDoc doc, RhinoObject obj) { if (null == doc || null == obj) { return(Result.Failure); } var viewport_id = doc.Views.ActiveView.ActiveViewportID; Plane plane; var res = RhinoGet.GetPlane(out plane); if (res != Result.Success) { return(res); } var rc = SampleCsMobilePlaneUserData.Attach(obj, plane, viewport_id); return(rc ? Result.Success : Result.Failure); }
/// <summary> /// Called if an object is undeleted (e.g. Undo) /// </summary> void OnUndeleteRhinoObject(object sender, RhinoObjectEventArgs e) { SampleCsMobilePlaneUserData.Refresh(e.TheObject, false); }