private List <string> GetTags(ModelComponent InModelComponent) { List <string> NodeTags = new List <string>(); NodeTags.Add(string.Format("Rhino.ID: {0}", InModelComponent.Id)); string ComponentTypeString = FUniqueNameGenerator.GetDefaultTypeName(InModelComponent); NodeTags.Add(string.Format("Rhino.Entity.Type: {0}", ComponentTypeString)); //Add the groups this object belongs to. RhinoObject InRhinoObject = InModelComponent as RhinoObject; if (InRhinoObject != null && InRhinoObject.GroupCount > 0) { int[] GroupIndices = InRhinoObject.GetGroupList(); for (int GroupArrayIndex = 0; GroupArrayIndex < GroupIndices.Length; ++GroupArrayIndex) { string GroupName = GroupNameList[GroupIndices[GroupArrayIndex]]; if (GroupName != null) { NodeTags.Add(GroupName); } } } return(NodeTags); }
private void GetUserStringDictionary(RhinoObject ro, ref Dictionary <string, string> dictionary) { var sc = ro.Attributes.GetUserStrings().Count; for (var i = 0; i < sc; i++) { var k = ro.Attributes.GetUserStrings().GetKey(i); var v = ro.Attributes.GetUserString(k); if (k == string.Empty) { continue; } if (dictionary.ContainsKey(k)) { string value; m_dictionary.TryGetValue(k, out value); if (value != v) { m_dictionary[k] = m_varies; } } else { dictionary.Add(k, v); } } }
private static bool IsUnsupportedObject(RhinoObject InObject) { // Geometry objects without meshes are currently not supported, unless they are points. return(InObject.ComponentType == ModelComponentType.ModelGeometry && !InObject.IsMeshable(MeshType.Render) && InObject.ObjectType != ObjectType.Point); }
void OnSelectObjects(object sender, RhinoObjectSelectionEventArgs args) { if (args.Selected) // objects were selected { //Control if all selected RhinoObjects are static (if only one object is not static or not a jittershape, uncheck the box) bool isStatic = true; bool jitterShape = true; for (int i = 0; i < args.RhinoObjects.Length; i++) { RhinoObject obj = args.RhinoObjects[i]; Guid id = obj.Id; if (RigidBodyManager.GuidList.Contains(id)) { int index = RigidBodyManager.GuidList.IndexOf(id); if (!RigidBodyManager.RigidBodies[index].IsStatic) { isStatic = false; } } else { jitterShape = false; } } //If all RhinoObjects are static set check otherwise uncheck TimePanel.Instance.IsStaticCheckBoxChecked = isStatic; //if there is minimum one selected shape that is not a jitter shape, so disable the checkbox TimePanel.Instance.IsStaticCheckBoxEnabled = jitterShape; //Now show the checked box with the correct value TimePanel.Instance.PropertiesGroupShow(); } }
//adds new tags to objects, or new objects to old tags public static bool AddTag(RhinoObject obj, string tag, bool updateUI = false) { if (!IsValid(tag)) { #if RhinoV5 Rhino.UI.Dialogs.ShowMessageBox("Please make sure that tag names only contain alpha numeric characters", "Tag names are invalid"); #elif RhinoV6 Rhino.UI.Dialogs.ShowMessage("Please make sure that tag names only contain alpha numeric characters", "Tag names are invalid"); #endif return(false); } List <string> tags = GetTags(obj); if (tags.Contains(tag)) { return(true); } tags.Add(tag); SaveTags(obj, tags); if (updateUI) { UpdateUI(tag); } return(true); }
public RhinoObject[] GetSelectedObjects(ObjectType filter) { var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(this); var object_count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref object_count); var rc = new List <RhinoObject>(); for (var i = 0; i < object_count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var rhino_object = RhinoObject.CreateRhinoObjectHelper(pointer); if (rhino_object != null) { rc.Add(rhino_object); } } UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsClear(array_pointer); return(rc.ToArray()); }
/// <summary> /// Return true if any of the selected objects match the given type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="allMustMatch"> /// If true then every selected object must match the object type /// otherwise; only a single object has to be of the specified type /// </param> /// <returns></returns> /// <since>6.7</since> public bool AnySelectedObject <T>(bool allMustMatch) where T : RhinoObject { var type = typeof(T); var filter = allMustMatch ? ObjectType.AnyObject : TypeFilter(type); var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(this); var count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref count); for (var i = 0; i < count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var obj = RhinoObject.CreateRhinoObjectHelper(pointer) as T; // If all objects must match and this object does not then return false if (allMustMatch && obj == null) { return(false); } // No requirement for all objects to match and this one does then just return true now if (!allMustMatch && obj != null) { return(true); } } return(allMustMatch && count > 0); }
public virtual bool ShouldDisplay(RhinoObject rhObj) { var e = new ObjectPropertiesPageEventArgs(this); var value = e.IncludesObjectsType(SupportedTypes, AllObjectsMustBeSupported); return(value); }
public static void CopyObjects(RhinoDoc doc, Layer OldLayer, Layer NewLayer, out List <RhinoObject> rhObjList) { // copy objects from old layer to new layer ObjectType type = ObjectType.Brep; rhObjList = new List <RhinoObject>(); List <RhinoObject> rhObjList0 = doc.Objects.FindByLayer(OldLayer).ToList(); // rhObjList= doc.Objects.FindByObjectType(type).ToList(); // rhObjList = doc.Objects.GetObjectList(type).ToList(); foreach (RhinoObject obj in rhObjList0) { if (type == obj.ObjectType) { Guid Duplicates = doc.Objects.Transform(obj.Id, Transform.Identity, false); RhinoObject rhobj = doc.Objects.Find(Duplicates); if (Duplicates != null) { rhobj.Attributes.LayerIndex = NewLayer.LayerIndex; rhobj.CommitChanges(); } rhObjList.Add(rhobj); } } }
public override bool TryDump(RhinoObject obj, Model model, RhinoDoc document) { if (obj.ObjectType != ObjectType.Curve) { return(false); } var curve = (Curve)obj.Geometry; var key = obj.GetKey(); var geometryItem = new Item($"{key}.NurbsCurveGeometry3D", "NurbsCurveGeometry3D"); DumpNurbsCurve3D(geometryItem, curve.ToNurbsCurve()); var curveItem = new Item(key, "Curve3D"); curveItem.Set("geometry", geometryItem.Key); curveItem.Set("domain", curve.Domain); model.Items.Add(geometryItem); model.Items.Add(curveItem); return(true); }
public override bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { if (null == rhObject || null == geometry) { return(false); } if (ComponentIndexType.BrepLoop != componentIndex.ComponentIndexType) { return(false); } var loop = geometry as BrepLoop; if (null == loop) { return(false); } var brep = loop.Brep; if (null == brep) { return(false); } return(IsHoleLoop(brep, loop.LoopIndex, true, false, m_tolerance)); }
/// <summary> /// Get selected objects of a given type /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> /// <since>6.0</since> public T[] GetObjects <T>() where T : RhinoObject { var type = typeof(T); var filter = TypeFilter(type); var page_pointer = RhinoPageHooks.UnmanagedIRhinoPagePointerFromPage(Page); var object_count = 0; var array_pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjects(page_pointer, (uint)filter, ref object_count); var rc = new List <T>(); for (var i = 0; i < object_count; i++) { var pointer = UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsAt(array_pointer, i); if (pointer == IntPtr.Zero) { continue; } var rhino_object = RhinoObject.CreateRhinoObjectHelper(pointer) as T; if (rhino_object != null) { rc.Add(rhino_object); } } UnsafeNativeMethods.IRhinoPropertiesPanelPage_GetObjectsClear(array_pointer); return(rc.ToArray()); }
private static void AddMetadataToDatasmithActor(FDatasmithFacadeActor InDatasmithActor, RhinoSceneHierarchyNode InNode, FDatasmithFacadeScene InDatasmithScene) { if (!InNode.Info.bHasRhinoObject) { return; } RhinoObject NodeObject = InNode.Info.RhinoModelComponent as RhinoObject; NameValueCollection UserStrings = NodeObject.Attributes.GetUserStrings(); if (UserStrings != null && UserStrings.Count > 0) { string[] Keys = UserStrings.AllKeys; FDatasmithFacadeMetaData DatasmithMetaData = new FDatasmithFacadeMetaData(InDatasmithActor.GetName() + "_DATA"); DatasmithMetaData.SetLabel(InDatasmithActor.GetLabel()); DatasmithMetaData.SetAssociatedElement(InDatasmithActor); for (int KeyIndex = 0; KeyIndex < Keys.Length; ++KeyIndex) { string CurrentKey = Keys[KeyIndex]; string EvaluatedValue = FDatasmithRhinoUtilities.EvaluateAttributeUserText(InNode, UserStrings.Get(CurrentKey)); DatasmithMetaData.AddPropertyString(CurrentKey, EvaluatedValue); } InDatasmithScene.AddMetaData(DatasmithMetaData); } }
/// <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); }
public override void InitializeControls(RhinoObject rhObj) { if (m_page_control != null) { m_page_control.InitializeControls(rhObj); } }
/// <summary> /// Delegate function used to turn custom grips on /// </summary> public void TurnOnGrips(RhinoObject rhObject) { if (rhObject == null) { return; } var polyline_curve = rhObject.Geometry as PolylineCurve; if (polyline_curve == null) { return; } if (!SampleCsRectangleHelper.IsRectangle(polyline_curve)) { return; } var rectangle_grips = new SampleCsRectangleGrips(); if (!rectangle_grips.CreateGrips(polyline_curve)) { return; } rhObject.EnableCustomGrips(rectangle_grips); }
protected override void DrawOverlay(Rhino.Display.DrawEventArgs e) { base.DrawOverlay(e); Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; for (int i = 0; i < Ids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Ids[i]); Rhino.Geometry.BoundingBox bbox = foundObject.Geometry.GetBoundingBox(true); Rhino.Geometry.Plane myFrustumPlane = new Rhino.Geometry.Plane(); //viewport.GetFrustumFarPlane(out myFrustumPlane); //myFrustumPlane.Origin = bbox.Center; //Rhino.Geometry.Circle myFrustumCircle = new Rhino.Geometry.Circle(); //myFrustumCircle.Plane = myFrustumPlane; //myFrustumCircle.Radius = bbox.Diagonal.Length / 2; //Rhino.Geometry.Curve myFrustumCurve = myFrustumCircle.ToNurbsCurve(); //myFrustumCurve.Domain = new Rhino.Geometry.Interval(0.0,1.0); //e.Display.DrawDot(myFrustumCurve.PointAtNormalizedLength(0.4), i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
public override bool LoadGeometry(Rhino.RhinoDoc doc) { RhinoObject obj = doc.Objects.Find(ReferenceID); if (obj == null) { return(false); } //if (obj.Geometry.ObjectType == ObjectType.Curve) //{ // var c = (Curve)obj.Geometry; // // m_value = RhinoMeshSupport.ExtractTMesh(c); // ClearCaches(); // return true; //} if (obj.Geometry.ObjectType == ObjectType.Mesh) { var m = (Mesh)obj.Geometry; m_value = RhinoSupport.ToPlanktonMesh(m); ClearCaches(); return(true); } return(false); }
/// <summary> /// Checks geometry to see if it can be selected. /// Override to provide fancy filtering. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex"> /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex. /// </param> /// <returns> /// The default returns true unless you've set a custom geometry filter. If a custom /// filter has been set, that delegate is called. /// </returns> /// <remarks>The delegate should not throw exceptions. If an exception is thrown, a message box will show and /// the filter will be disabled.</remarks> /// <since>5.0</since> public virtual bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { if (m_filter != null) { try { return(m_filter(rhObject, geometry, componentIndex)); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show( "The CustomGeometryFilter() function threw an uncaught exception. It will be disabled." + "Details: \n\n" + $"Type: {ex.GetType().FullName} \n" + $"Message: {ex.Message} \n" + $"StackTrace: \n{ex.StackTrace}" , "CustomGeometryFilter exception boundary"); //we need to stop the exception from repeating. m_filter = null; } } return(true); }
/// <summary> /// Returns the preview-meshes of the RhinoObject. /// TODO: Extend to handle sub-assigned materials returning a list of KV-pairs of meshes, materials. /// </summary> /// <param name="rhinoObject"></param> /// <returns></returns> public static Rhino.Geometry.Mesh[] GetMeshes(RhinoObject rhinoObject) { if (rhinoObject.ObjectType == ObjectType.Mesh) { MeshObject meshObj = rhinoObject as MeshObject; return(new Rhino.Geometry.Mesh[] { meshObj.MeshGeometry }); } // Need to get a Mesh from the None-mesh object. Using the FastRenderMesh here. Could be made configurable. // First make sure the internal rhino mesh has been created rhinoObject.CreateMeshes(MeshType.Preview, MeshingParameters.FastRenderMesh, true); // Then get the internal rhino meshes Rhino.Geometry.Mesh[] meshes = rhinoObject.GetMeshes(MeshType.Preview); List <Rhino.Geometry.Mesh> validMeshes = new List <Mesh>(); foreach (Rhino.Geometry.Mesh mesh in meshes) { if (MeshIsValidForExport(mesh)) { mesh.EnsurePrivateCopy(); validMeshes.Add(mesh); } } return(validMeshes.Count == 0 ? new Rhino.Geometry.Mesh[] { } : validMeshes.ToArray()); }
int?GetMaterial(RenderMaterial material, RhinoObject rhinoObject) { if (!options.ExportMaterials) { return(null); } if (material == null && options.UseDisplayColorForUnsetMaterials) { Color4f objectColor = GetObjectColor(rhinoObject); return(CreateSolidColorMaterial(objectColor)); } else if (material == null) { material = Rhino.DocObjects.Material.DefaultMaterial.RenderMaterial; } Guid materialId = material.Id; if (!materialsMap.TryGetValue(materialId, out int materialIndex)) { RhinoMaterialGltfConverter materialConverter = new RhinoMaterialGltfConverter(options, binary, dummy, binaryBuffer, material, workflow); materialIndex = materialConverter.AddMaterial(); materialsMap.Add(materialId, materialIndex); } return(materialIndex); }
// in place just to handle brep differentiation to srfs and polysrfs protected ObjectType GetCustomObjectType(RhinoObject obj) { switch (obj.ObjectType) { case ObjectType.Brep: Brep brp = obj.Geometry as Brep; if (brp.Faces.Count == 1) { return(ObjectType.Surface); } else if (!brp.IsSolid && brp.IsManifold) { return(ObjectType.PolysrfFilter); } else { return(obj.ObjectType); } case ObjectType.Curve: case ObjectType.Surface: case ObjectType.Mesh: default: return(obj.ObjectType); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType filter = ObjectType.AnyObject; ObjRef objref; var rc = RhinoGet.GetOneObject("Select object", false, filter, out objref); if (rc != Result.Success || null == objref) { return(rc); } RhinoObject obj = objref.Object(); if (null == obj) { return(Result.Failure); } var ud = obj.Attributes.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null != ud) { RhinoApp.WriteLine("{0} = {1}", ud.Description, ud.Notes); } else { RhinoApp.WriteLine("User data not found."); } return(Result.Success); }
// check object name and then layer path for all supported schemas private void ApplyNamingFilter() { for (int j = objsToBeFiltered.Count - 1; j >= 0; j--) { RhinoObject obj = objsToBeFiltered[j]; string objName = obj.Attributes.Name; string objPath = Doc.Layers[obj.Attributes.LayerIndex].FullPath; SupportedSchema foundSchema = SupportedSchema.none; foreach (SupportedSchema schema in Enum.GetValues(typeof(SupportedSchema))) { if (objName != null && objName.Contains(schema.ToString())) { foundSchema = schema; break; } } if (foundSchema == SupportedSchema.none) { foreach (SupportedSchema schema in Enum.GetValues(typeof(SupportedSchema))) { if (objPath.Contains(schema.ToString())) { foundSchema = schema; break; } } } if (foundSchema != SupportedSchema.none) { // add to filter dict and remove from filter list filterDictionary[foundSchema].Add(obj); objsToBeFiltered.RemoveAt(j); } } }
public override bool IsCurrentModelStateInAnySnapshot(RhinoDoc doc, RhinoObject doc_object, BinaryArchiveReader archive, SimpleArrayBinaryArchiveReader archive_array, TextLog text_log = null) { var userdata = archive.ReadDictionary(); string name = ""; if (!userdata.TryGetString("ObjName", out name)) { return(false); } for (int i = 0; i < archive_array.Count; i++) { var ba = archive_array.Get(i); var ud = ba.ReadDictionary(); string s = ""; if (ud.TryGetString("ObjName", out s)) { if (0 == s.CompareTo(name)) { return(true); } } } return(false); }
protected override void OnDuplicate(RhinoObject source) { using (var other = source as RectangleObject) { this.Attributes.UserData.Add(other.Data); } }
private RenderMaterial GetMaterial(RhinoObject o) { var material = o.GetMaterial(true); var renderMaterial = new RenderMaterial(); // If it's a default material use the display color. if (!material.HasId) { renderMaterial.diffuse = o.Attributes.DrawColor(Doc).ToArgb(); return(renderMaterial); } // Otherwise, extract what properties we can. renderMaterial.name = material.Name; renderMaterial.diffuse = material.DiffuseColor.ToArgb(); renderMaterial.emissive = material.EmissionColor.ToArgb(); renderMaterial.opacity = 1 - material.Transparency; renderMaterial.metalness = material.Reflectivity; if (material.Name.ToLower().Contains("glass") && renderMaterial.opacity == 0) { renderMaterial.opacity = 0.3; } return(renderMaterial); }
/// <inheritdoc /> protected override void UpdateVertexColors(RhinoObject obj, Mesh[] meshes) { // A "mapping tag" is used to determine if the colors need to be set var mt = GetMappingTag(); foreach (var mesh in meshes) { if (mesh.VertexColors.Tag.Id != Id) { // 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. var colors = new Color[mesh.Vertices.Count]; for (var i = 0; i < mesh.Vertices.Count; i++) { double z = mesh.Vertices[i].Z; colors[i] = FalseColor(z); } mesh.VertexColors.SetColors(colors); // set the mesh's color tag mesh.VertexColors.Tag = mt; } } }
public static GetObject GetRhinoObjects(string prompt, ObjectType geometryFilter) { GetObject go = new GetObject(); go.SetCommandPrompt(prompt); go.GeometryFilter = geometryFilter; go.GroupSelect = false; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = true; for (; ;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(go); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } } return(go); }
public static void DecomposeObj_Invalid(RhinoDoc doc, Layer layer, RhinoObject obj, Brep brep, ref int progressCurrentIndex, ref int progressShowedPercent, int progressMax, bool beforeFixAllIssues, int objsInLayerCount = -1) { var newLayerIndex = GetNewLayer(doc, layer, obj, beforeFixAllIssues); var newlayer = doc.Layers[newLayerIndex]; //var savedCurrentIndex = doc.Layers.CurrentLayerIndex; //doc.Layers.SetCurrentLayerIndex(newLayerIndex, true); try { //var objsbefore = doc.Objects.FindByLayer(layer); //var map = new Dictionary<uint, bool>(); //foreach (var o in objsbefore) //{ // map[o.RuntimeSerialNumber] = true; //} // move obj to new layer obj.Attributes.LayerIndex = newLayerIndex; obj.CommitChanges(); // explode it doc.Objects.UnselectAll(); doc.Objects.Select(obj.Id); if (RhinoApp.RunScript("_Explode", false)) { var objsnow = doc.Objects.FindByLayer(newlayer); objsInLayerCount = objsnow.Length; int index = 0; int nameLength = 1; if (objsInLayerCount >= 10) { nameLength = 2; } if (objsInLayerCount >= 100) { nameLength = 3; } if (objsInLayerCount >= 1000) { nameLength = 4; } if (objsInLayerCount >= 10000) { nameLength = 5; } foreach (var newobj in objsnow) { index++; newobj.Attributes.Name = index.ToString("D" + nameLength); newobj.CommitChanges(); } Shared.SharedCommands.Execute(SharedCommandsEnum.ST_UpdateGeomNames); } progressCurrentIndex += brep.Faces.Count; } finally { doc.Objects.UnselectAll(); //doc.Layers.SetCurrentLayerIndex(savedCurrentIndex, true); } }