public override void OnDeselectObject(ref MRhinoDoc doc, IRhinoObject @object) { if (true == m_control.Visible) { m_control.OnDeselectObject(ref doc, @object); } }
/// <summary> /// Removes an array of string data from an /// object's attribute user string data. /// </summary> public static bool RemoveData(IRhinoObject obj, string[] string_data) { if (obj != null && string_data.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int num_removed = 0; for (int i = 0; i < string_data.Length; i++) { for (int j = 0; j < string_array.Length; j++) { if (string_array[i].IndexOf(string_data[j]) >= 0) { string_array[i] = String.Empty; num_removed++; break; } } } if (num_removed > 0) { if (num_removed == string_array.Length) { return(SetData(obj, String.Empty)); } return(SetData(obj, string_array)); } } } return(false); }
/// <summary> /// Calculates the area of an object /// </summary> public static double GetArea(IRhinoObject obj, double tol) { if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) { return(GetCurveArea(crv, tol)); } IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) { return(GetSurfaceArea(srf)); } IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) { return(GetBrepArea(brep)); } IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) { return(GetMeshArea(mesh)); } } return(0.0); }
/// <summary> /// MRhinoVisualAnalysisMode override /// </summary> public override bool ObjectSupportsAnalysisMode(IRhinoObject obj) { bool rc = false; if (null != obj) { switch (obj.ObjectType()) { case IOn.object_type.mesh_object: rc = true; break; case IOn.object_type.surface_object: case IOn.object_type.polysrf_filter: case IOn.object_type.brep_object: { if (null != MRhinoBrepObject.ConstCast(obj)) { rc = true; } } break; } } return(rc); }
// Called by SampleCsObjectPropertiesDialogPage public bool AddPageToControlBar(IRhinoObject obj) { // TODO: test to see if this object qualifies this page // to be shown. For this example, we will always display // our dialog page. return(true); }
// Called by SampleCsObjectPropertiesDialogPage public bool AddPageToControlBar(IRhinoObject obj) { // TODO: test to see if this object qualifies this page // to be shown. For this example, we will always display // our dialog page. return true; }
public override bool ExecConduit(ref MRhinoDisplayPipeline pipeline, uint channel, ref bool terminate) { if (MSupportChannels.SC_CALCBOUNDINGBOX == channel) { // If you are dynamically drawing objects, then we must implement the // this channel to add to the overall scene bounding box. This will make // Rhino adjust its clipping planes to include our geometry. for (int i = 0; i < m_objects.Count; i++) { IRhinoObject obj = m_objects[i]; if (null != obj) { OnBoundingBox bbox = obj.BoundingBox(); bbox.Transform(m_xform); m_pChannelAttrs.m_BoundingBox.Union(bbox); } } } else if (MSupportChannels.SC_DRAWOVERLAY == channel) { // This channel is where the drawing takes place. for (int i = 0; i < m_objects.Count; i++) { IRhinoObject obj = m_objects[i]; if (null != obj) { pipeline.SetObjectColor(obj.ObjectDrawColor()); pipeline.DrawObject(obj, m_xform); } } } return(true); }
/// <summary> /// Removes all string data /// object's attribute user string data. /// </summary> public static bool RemoveAllData(IRhinoObject obj) { if (obj != null) { return(SetData(obj, String.Empty)); } return(false); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Object name to select"); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } string name = gs.String().Trim(); if (string.IsNullOrEmpty(name)) { return(IRhinoCommand.result.nothing); } MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.normal_objects, IRhinoObjectIterator.object_category.active_and_reference_objects ); int num_selected = 0; IRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) { if (name.Equals(obj.Attributes().m_name, StringComparison.OrdinalIgnoreCase)) { obj.Select(true, true, true); num_selected++; } } if (0 == num_selected) { RhUtil.RhinoApp().Print("0 objects selected\n"); } else if (1 == num_selected) { RhUtil.RhinoApp().Print("1 object selected\n"); } else { RhUtil.RhinoApp().Print(string.Format("{0} objects selected\n", num_selected)); } if (0 < num_selected) { context.m_doc.Redraw(); } return(IRhinoCommand.result.success); }
/// <summary> /// Low level function to get formattted string data from an /// object's attribute user string data. /// </summary> public static int GetData(IRhinoObject obj, ref string string_data) { if (obj != null) { if (obj.Attributes().GetUserString(GetKey(), ref string_data)) { return(string_data.Length); } } return(0); }
public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci) { if (obj != null) { if (obj.IsSolid()) { return(true); } } return(false); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select object"); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } MRhinoObjRef obj_ref = go.Object(0); IRhinoObject obj = obj_ref.Object(); if (null == obj) { return(IRhinoCommand.result.failure); } // 1.) Try the object test RhUtil.RhinoApp().Print("Object Test: "); if (IsLeader(obj)) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } // 2.) Try the GUID test RhUtil.RhinoApp().Print("GUID Test: "); if (IsLeader(obj.Attributes().m_uuid)) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } // 3.) Try the geometry test RhUtil.RhinoApp().Print("Geometry Test: "); if (IsLeader(obj_ref.Geometry())) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } return(IRhinoCommand.result.success); }
bool IsLeader(IRhinoObject obj) { bool rc = false; if (null != obj) { IRhinoAnnotationLeader leader_obj = MRhinoAnnotationLeader.ConstCast(obj); if (null != leader_obj) rc = true; } return rc; }
/// <summary> /// Low level function to get an array of string data from an /// object's attribute user string data. /// </summary> public static int GetData(IRhinoObject obj, ref string[] string_array) { string string_data = String.Empty; if (GetData(obj, ref string_data) > 0) { char[] delims = new char[] { ';' }; string_array = string_data.Split(delims, StringSplitOptions.RemoveEmptyEntries); return(string_array.Length); } return(0); }
bool IsLeader(Guid guid) { bool rc = false; MRhinoObjRef obj_ref = new MRhinoObjRef(guid); IRhinoObject obj = obj_ref.Object(); if (null != obj) { rc = IsLeader(obj); } return(rc); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List<IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List<int>[VoxelCT, VoxelCT, VoxelCT]; Voxel = new List<On3dPoint>[VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT-1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List<On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List<int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT]; Voxel = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List <int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
/// <summary> /// Calculates the length of an object /// </summary> public static double GetLength(IRhinoObject obj) { double length = 0.0; if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) { crv.GetLength(ref length); } } return(length); }
bool IsLeader(IRhinoObject obj) { bool rc = false; if (null != obj) { IRhinoAnnotationLeader leader_obj = MRhinoAnnotationLeader.ConstCast(obj); if (null != leader_obj) { rc = true; } } return(rc); }
/// <summary> /// Adds an array of string data to an /// object's attribute user string data. /// </summary> public static bool AddData(IRhinoObject obj, string[] string_data) { if (obj != null && string_data.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int string_array_length = string_array.Length; for (int i = 0; i < string_data.Length; i++) { bool found = false; for (int j = 0; j < string_array.Length; j++) { if (string_array[j].IndexOf(string_data[i]) >= 0) { found = true; break; } } if (!found) { // Copy array string[] new_string_array = new string[string_array.Length + 1]; Array.Copy(string_array, new_string_array, string_array.Length); // Add to end of copy new_string_array[new_string_array.Length - 1] = string_data[i]; // Replace original with copy string_array = new_string_array; } } if (string_array.Length > string_array_length) { // Sort array Array.Sort(string_array); // Set data return(SetData(obj, string_array)); } } else { return(SetData(obj, string_data)); } } return(false); }
/// <summary> /// Adds an array of string data to an /// object's attribute user string data. /// </summary> public static bool AddData(IRhinoObject obj, string[] string_data) { if (obj != null && string_data.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int string_array_length = string_array.Length; for (int i = 0; i < string_data.Length; i++) { bool found = false; for (int j = 0; j < string_array.Length; j++) { if (string_array[j].IndexOf(string_data[i]) >= 0) { found = true; break; } } if (!found) { // Copy array string[] new_string_array = new string[string_array.Length + 1]; Array.Copy(string_array, new_string_array, string_array.Length); // Add to end of copy new_string_array[new_string_array.Length - 1] = string_data[i]; // Replace original with copy string_array = new_string_array; } } if (string_array.Length > string_array_length) { // Sort array Array.Sort(string_array); // Set data return SetData(obj, string_array); } } else { return SetData(obj, string_data); } } return false; }
/// <summary> /// Low level function to set formattted string data to an /// object's attribute user string data. /// </summary> public static bool SetData(IRhinoObject obj, string string_data) { if (obj != null) { MRhinoDoc doc = obj.Document(); if (doc != null) { MRhinoObjectAttributes atts = new MRhinoObjectAttributes(obj.Attributes()); if (atts.SetUserString(GetKey(), string_data)) { return(doc.ModifyObjectAttributes(new MRhinoObjRef(obj), atts)); } } } return(false); }
public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci) { if (geo != null) { IOnCurve crv = OnCurve.ConstCast(geo); if (crv != null) { if (crv.IsClosed() && crv.IsPlanar()) { return(true); } else { return(false); } } IOnBrep brep = OnBrep.ConstCast(geo); if (brep != null) { if (brep.m_F.Count() == 1) { return(true); } else { return(false); } } IOnSurface srf = OnSurface.ConstCast(geo); if (srf != null) { return(true); } IOnMesh mesh = OnMesh.ConstCast(geo); if (mesh != null) { return(true); } } return(false); }
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects for Z analysis"); go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object ); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } int count = 0; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (null == obj) { continue; } if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID)) { // This object is already in Z analysis mode continue; } if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true)) { // A new object is in Z analysis mode count++; } } context.m_doc.Redraw(); RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count)); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select edge curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); IRhinoObject obj = go.Object(0).Object(); IOnBrep brep = go.Object(0).Brep(); IOnBrepEdge edge = go.Object(0).Edge(); if (null == obj || null == brep || null == edge) return IRhinoCommand.result.failure; MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes()); if (attribs.GroupCount() > 0) attribs.RemoveFromAllGroups(); for (int i = 0; i < edge.TrimCount(); i++) { IOnBrepTrim trim = edge.Trim(i); if (null != trim) { IOnBrepFace face = trim.Face(); if (null != face) { OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true); if (null != face_brep) { MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs); if (null != face_brep_obj) face_brep_obj.Select(); } } } } context.m_doc.Redraw(); return IRhinoCommand.result.success; }
public void OnDeselectObject(ref MRhinoDoc doc, IRhinoObject obj) { if (m_bInSelect) { return; } m_bInEvent = true; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) { m_listbox.SetSelected(index, false); } } SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Low level function to set an array of string data to an /// object's attribute user string data. /// </summary> public static bool SetData(IRhinoObject obj, string[] string_array) { if (obj != null && string_array.Length > 0) { string string_data = String.Empty; for (int i = 0; i < string_array.Length; i++) { if (string_array[i].Length > 0) { if (i > 0 && string_data.Length > 0) { string_data += ";"; } string_data += string_array[i]; } } return(SetData(obj, string_data)); } return(false); }
/// <summary> /// MRhinoVisualAnalysisMode override /// </summary> public override void UpdateVertexColors(IRhinoObject obj, OnMesh[] meshes) { // Rhino calls this function when it is time for you // to set the false colors on the analysis mesh vertices. // For breps, there is one mesh per face. For mesh objects, // there is a single mesh. int count = meshes.Length; if (count > 0) { // A "mapping tag" is used to determine if the colors need to be set OnMappingTag mt = MappingTag(); for (int mi = 0; mi < count; mi++) { OnMesh mesh = meshes[mi]; if (null != mesh && 0 != mt.Compare(mesh.m_Ctag)) { // The mesh's mapping tag is different from ours. Either // the mesh has no false colors, has false colors set by // another analysis mode, has false colors set using // different m_z_range[]/m_hue_range[] values, or the // mesh has been moved. In any case, we need to set // the false colors to the ones we want. int vcount = mesh.m_V.Count(); ArrayOnColor vertex_colors = mesh.m_C; vertex_colors.SetCount(0); // in case something else had set the colors vertex_colors.Reserve(vcount); // for efficiency for (int vi = 0; vi < vcount; vi++) { double z = mesh.m_V[vi].z; OnColor color = FalseColor(z); vertex_colors.Append(color); } // set the mesh's color tag mesh.m_Ctag = mt; } } } }
/// <summary> /// Adds a single string datum to an /// object's attribute user string data. /// </summary> public static bool AddData(IRhinoObject obj, string string_datum) { if (obj != null && string_datum.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int num_added = 0; for (int i = 0; i < string_array.Length; i++) { if (string_array[i].IndexOf(string_datum) >= 0) { num_added++; break; } } if (num_added > 0) { // Copy array string[] new_string_array = new string[string_array.Length + 1]; Array.Copy(string_array, new_string_array, string_array.Length); // Add to end of copy new_string_array[new_string_array.Length - 1] = string_datum; // Sort copy Array.Sort(new_string_array); // Set data return(SetData(obj, new_string_array)); } } else { return(SetData(obj, string_datum)); } } return(false); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); int count = 0; context.m_doc.UnselectAll(); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.normal_objects, IRhinoObjectIterator.object_category.active_objects ); IRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) { if (obj.IsSolid()) { IOn.object_type type = obj.ObjectType(); if (type == IOn.object_type.surface_object || type == IOn.object_type.brep_object) { obj.Select(true); string fname = string.Format("{0}\\rhino_sat_export_{1}.sat", path, count++); string script = string.Format("_-Export \"{0}\" Inventor _Enter", fname); RhUtil.RhinoApp().RunScript(script, 1); obj.Select(false); } } } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
/// <summary> /// Adds a single string datum to an /// object's attribute user string data. /// </summary> public static bool AddData(IRhinoObject obj, string string_datum) { if (obj != null && string_datum.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int num_added = 0; for (int i = 0; i < string_array.Length; i++) { if (string_array[i].IndexOf(string_datum) >= 0) { num_added++; break; } } if (num_added > 0) { // Copy array string[] new_string_array = new string[string_array.Length + 1]; Array.Copy(string_array, new_string_array, string_array.Length); // Add to end of copy new_string_array[new_string_array.Length - 1] = string_datum; // Sort copy Array.Sort(new_string_array); // Set data return SetData(obj, new_string_array); } } else { return SetData(obj, string_datum); } } return false; }
public void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (m_bInSelect) { return; } m_bInEvent = true; for (int i = 0; i < objects.Length; i++) { IRhinoObject obj = objects[i]; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) { m_listbox.SetSelected(index, true); } } } SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Calculates the volume of an object /// </summary> public static double GetVolume(IRhinoObject obj) { if (null != obj && obj.IsSolid()) { IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) { return(GetSurfaceVolume(srf)); } IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) { return(GetBrepVolume(brep)); } IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) { return(GetMeshVolume(mesh)); } } return(0.0); }
/// <summary> /// Low level function to get formattted string data from an /// object's attribute user string data. /// </summary> public static int GetData(IRhinoObject obj, ref string string_data) { if (obj != null) { if (obj.Attributes().GetUserString(GetKey(), ref string_data)) return string_data.Length; } return 0; }
/// <summary> /// Low level function to get an array of string data from an /// object's attribute user string data. /// </summary> public static int GetData(IRhinoObject obj, ref string[] string_array) { string string_data = String.Empty; if (GetData(obj, ref string_data) > 0) { char[] delims = new char[] { ';' }; string_array = string_data.Split(delims, StringSplitOptions.RemoveEmptyEntries); return string_array.Length; } return 0; }
public void AppendObject(IRhinoObject obj) { m_list.AddObject(obj); }
// Called by SampleCsObjectPropertiesDialogPage public IRhinoCommand.result RunScript(IRhinoObject[] objects) { // TODO: add command line, script handling, code here return IRhinoCommand.result.success; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select a curve object MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Validate the selection IRhinoObject obj = go.Object(0).Object(); if (null == obj) return IRhinoCommand.result.failure; // Get the active view MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null == view) return IRhinoCommand.result.failure; // Get the construction plane from the active view OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane); // Create a construction plane aligned bounding box OnBoundingBox bbox = new OnBoundingBox(); IRhinoObject[] objs = new IRhinoObject[1] { obj }; bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane); if (rc == false) return IRhinoCommand.result.failure; // Validate bounding box if (0 != bbox.IsDegenerate()) { RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n"); return IRhinoCommand.result.nothing; } // ON_BrepBox wants 8 points defining the box corners // arranged in this order: // // v7______________v6 // |\ |\ // | \ | \ // | \ _____________\ // | v4 | v5 // | | | | // | | | | // v3---|---------v2 | // \ | \ | // \ | \ | // \ | \ | // \v0____________\v1 // On3dPoint[] box_corners = new On3dPoint[8]; box_corners[0] = bbox.Corner(0, 0, 0); box_corners[1] = bbox.Corner(1, 0, 0); box_corners[2] = bbox.Corner(1, 1, 0); box_corners[3] = bbox.Corner(0, 1, 0); box_corners[4] = bbox.Corner(0, 0, 1); box_corners[5] = bbox.Corner(1, 0, 1); box_corners[6] = bbox.Corner(1, 1, 1); box_corners[7] = bbox.Corner(0, 1, 1); // Transform points to the world-xy plane OnXform p2w = new OnXform(); p2w.ChangeBasis(plane, OnUtil.On_xy_plane); for (int i = 0; i < 8; i++) box_corners[i].Transform(p2w); // Make a brep box OnBrep brep = OnUtil.ON_BrepBox(box_corners); if (null != brep) { context.m_doc.AddBrepObject(brep); context.m_doc.Redraw(); } return IRhinoCommand.result.success; }
public void OnDeselectObject(ref MRhinoDoc doc, IRhinoObject obj) { if (m_bInSelect) return; m_bInEvent = true; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) m_listbox.SetSelected(index, false); } SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Removes all string data /// object's attribute user string data. /// </summary> public static bool RemoveAllData(IRhinoObject obj) { if (obj != null) return SetData(obj, String.Empty); return false; }
public override IRhinoCommand.result RunScript(IRhinoObject[] objects) { return _control.RunScript(objects); }
public override void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (true == m_control.Visible) m_control.OnSelectObjects(ref doc, objects); }
public override bool AddPageToControlBar(IRhinoObject obj) { return _control.AddPageToControlBar(obj); }
public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci) { if (geo != null) { IOnCurve crv = OnCurve.ConstCast(geo); if (crv != null) { if (crv.IsClosed() && crv.IsPlanar()) return true; else return false; } IOnBrep brep = OnBrep.ConstCast(geo); if (brep != null) { if (brep.m_F.Count() == 1) return true; else return false; } IOnSurface srf = OnSurface.ConstCast(geo); if (srf != null) return true; IOnMesh mesh = OnMesh.ConstCast(geo); if (mesh != null) return true; } return false; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select tagged object to report"); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IRhinoObject obj = go.Object(0).Object(); if (null == obj) { return(IRhinoCommand.result.failure); } IOnGeometry geo = obj.Geometry(); if (null == geo) { return(IRhinoCommand.result.failure); } string[] string_array = null; if (0 == EstimatorHelpers.GetData(obj, ref string_array)) { RhUtil.RhinoApp().Print("No Estimator tag data found.\n"); return(IRhinoCommand.result.nothing); } string filename = null; SaveFileDialog sd = new SaveFileDialog(); sd.DefaultExt = "xml"; sd.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*"; sd.AddExtension = true; sd.RestoreDirectory = true; sd.Title = "Save"; if (sd.ShowDialog() == DialogResult.OK) { filename = sd.FileName; } sd.Dispose(); sd = null; if (null == filename) { return(IRhinoCommand.result.cancel); } XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteComment("Saved on " + DateTime.Now); // Write root element writer.WriteStartElement("Estimator"); writer.WriteAttributeString("Version", "1.0"); // Write object writer.WriteStartElement("Object"); writer.WriteAttributeString("Type", geo.ObjectType().ToString()); writer.WriteElementString("Uuid", obj.Attributes().m_uuid.ToString()); if (obj.Attributes().m_name.Length > 0) { writer.WriteElementString("Name", obj.Attributes().m_name); } else { writer.WriteElementString("Name", "(none)"); } // Write object length double length = EstimatorHelpers.GetLength(obj); if (length > 0.0) { writer.WriteElementString("Length", length.ToString()); } else { writer.WriteElementString("Length", "n/a"); } double tol = context.m_doc.AbsoluteTolerance(); // Write object area double area = EstimatorHelpers.GetArea(obj, tol); if (area > 0.0) { writer.WriteElementString("Area", area.ToString()); } else { writer.WriteElementString("Area", "n/a"); } // Write object volume double volume = EstimatorHelpers.GetVolume(obj); if (volume > 0.0) { writer.WriteElementString("Volume", volume.ToString()); } else { writer.WriteElementString("Volume", "n/a"); } // Write object tags writer.WriteStartElement("Tags"); for (int i = 0; i < string_array.Length; i++) { writer.WriteElementString("Tag", string_array[i]); } writer.WriteEndElement(); // Tags writer.WriteEndElement(); // Object writer.WriteEndElement(); // Estimator writer.WriteEndDocument(); writer.Flush(); writer.Close(); return(IRhinoCommand.result.success); }
/// <summary> /// MRhinoVisualAnalysisMode override /// </summary> public override bool ObjectSupportsAnalysisMode(IRhinoObject obj) { bool rc = false; if (null != obj) { switch (obj.ObjectType()) { case IOn.object_type.mesh_object: rc = true; break; case IOn.object_type.surface_object: case IOn.object_type.polysrf_filter: case IOn.object_type.brep_object: { if (null != MRhinoBrepObject.ConstCast(obj)) rc = true; } break; } } return rc; }
/// <summary> /// Calculates the length of an object /// </summary> public static double GetLength(IRhinoObject obj) { double length = 0.0; if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) crv.GetLength(ref length); } return length; }
/// <summary> /// Calculates the volume of an object /// </summary> public static double GetVolume(IRhinoObject obj) { if (null != obj && obj.IsSolid()) { IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) return GetSurfaceVolume(srf); IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) return GetBrepVolume(brep); IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) return GetMeshVolume(mesh); } return 0.0; }
/// <summary> /// Removes an array of string data from an /// object's attribute user string data. /// </summary> public static bool RemoveData(IRhinoObject obj, string[] string_data) { if (obj != null && string_data.Length > 0) { string[] string_array = null; if (GetData(obj, ref string_array) > 0) { int num_removed = 0; for (int i = 0; i < string_data.Length; i++) { for (int j = 0; j < string_array.Length; j++) { if (string_array[i].IndexOf(string_data[j]) >= 0) { string_array[i] = String.Empty; num_removed++; break; } } } if (num_removed > 0) { if (num_removed == string_array.Length) return SetData(obj, String.Empty); return SetData(obj, string_array); } } } return false; }
/// <summary> /// Low level function to set formattted string data to an /// object's attribute user string data. /// </summary> public static bool SetData(IRhinoObject obj, string string_data) { if (obj != null) { MRhinoDoc doc = obj.Document(); if (doc != null) { MRhinoObjectAttributes atts = new MRhinoObjectAttributes(obj.Attributes()); if (atts.SetUserString(GetKey(), string_data)) return doc.ModifyObjectAttributes(new MRhinoObjRef(obj), atts); } } return false; }
public void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (m_bInSelect) return; m_bInEvent = true; for (int i = 0; i < objects.Length; i++) { IRhinoObject obj = objects[i]; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) m_listbox.SetSelected(index, true); } } SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Low level function to set an array of string data to an /// object's attribute user string data. /// </summary> public static bool SetData(IRhinoObject obj, string[] string_array) { if (obj != null && string_array.Length > 0) { string string_data = String.Empty; for (int i = 0; i < string_array.Length; i++) { if (string_array[i].Length > 0) { if (i > 0 && string_data.Length > 0) string_data += ";"; string_data += string_array[i]; } } return SetData(obj, string_data); } return false; }
/// <summary> /// MRhinoVisualAnalysisMode override /// </summary> public override void UpdateVertexColors(IRhinoObject obj, OnMesh[] meshes) { // Rhino calls this function when it is time for you // to set the false colors on the analysis mesh vertices. // For breps, there is one mesh per face. For mesh objects, // there is a single mesh. int count = meshes.Length; if (count > 0 ) { // A "mapping tag" is used to determine if the colors need to be set OnMappingTag mt = MappingTag(); for ( int mi = 0; mi < count; mi++ ) { OnMesh mesh = meshes[mi]; if (null != mesh && 0 != mt.Compare(mesh.m_Ctag) ) { // The mesh's mapping tag is different from ours. Either // the mesh has no false colors, has false colors set by // another analysis mode, has false colors set using // different m_z_range[]/m_hue_range[] values, or the // mesh has been moved. In any case, we need to set // the false colors to the ones we want. int vcount = mesh.m_V.Count(); ArrayOnColor vertex_colors = mesh.m_C; vertex_colors.SetCount(0); // in case something else had set the colors vertex_colors.Reserve(vcount); // for efficiency for (int vi = 0; vi < vcount; vi++ ) { double z = mesh.m_V[vi].z; OnColor color = FalseColor(z); vertex_colors.Append(color); } // set the mesh's color tag mesh.m_Ctag = mt; } } } }
public override void OnSelectObject(ref MRhinoDoc doc, IRhinoObject @object) { if (true == m_control.Visible) m_control.OnSelectObject(ref doc, @object); }
// Called by SampleCsObjectPropertiesDialogPage public void InitControls(IRhinoObject new_obj) { // TODO: add control initialization here }
/// <summary> /// Calculates the area of an object /// </summary> public static double GetArea(IRhinoObject obj, double tol) { if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) return GetCurveArea(crv, tol); IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) return GetSurfaceArea(srf); IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) return GetBrepArea(brep); IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) return GetMeshArea(mesh); } return 0.0; }
public override void InitControls(IRhinoObject new_obj) { _control.InitControls(new_obj); }
public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci) { if (obj != null) { if (obj.IsSolid() ) return true; } return false; }