internal AttributeLayout(MeshChannel channel, ComponentIndex index, Vector2 range, int mask) { this.channel = channel; this.index = index; this.range = range; this.mask = mask; }
public int AddComponent <T>(T component) where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); AddComponent(index, component); return(index); }
//This is used in subselection, in which need to replace entire geometry after property changes public static FaceEntity TryGetFrom(ObjRef roomHostObjRef, ComponentIndex componentIndex) { var roomHostObject = roomHostObjRef.Brep(); var rc = new FaceEntity(); if (roomHostObject == null) { return(rc); } if (componentIndex.ComponentIndexType != ComponentIndexType.BrepFace) { return(rc); } var face = roomHostObject.Faces[componentIndex.Index]; var ent = face.TryGetFaceEntity(); if (!ent.IsValid) { return(rc); } //updates hostObjRef to its room's host ent.RoomHostObjRef = roomHostObjRef; ent.ComponentIndex = componentIndex; return(ent); }
public static ComponentProblem Add(ref ComponentProblems problems, BrepEdge edge, BrepTrim trim, string problem, ComponentProblemTypes type, object data = null) { var componentReal = new ComponentIndex(ComponentIndexType.BrepEdge, edge.EdgeIndex); var componentGUI = new ComponentIndex(ComponentIndexType.BrepEdge, trim.TrimIndex); return(Add(ref problems, componentReal, componentGUI, problem, type, data)); }
public Curve WallEdge(ComponentIndex ci) { IntPtr ptr_const_this = ConstPointer(); IntPtr ptr_new_curve = UnsafeNativeMethods.ON_Extrusion_WallEdge(ptr_const_this, ci); return(CreateGeometryHelper(ptr_new_curve, null) as Curve); }
public Surface WallSurface(ComponentIndex ci) { IntPtr ptr_const_this = ConstPointer(); IntPtr ptr_new_surface = UnsafeNativeMethods.ON_Extrusion_WallSurface(ptr_const_this, ci); return(CreateGeometryHelper(ptr_new_surface, null) as Surface); }
public void GetString() { //wrong tests //because C# will let you cast any value outside the enum Assert.IsTrue(((ComponentIndex)100).GetString() == "100"); ComponentIndex index = ComponentIndex.R; Assert.IsTrue(index.GetString(ComponentIndexType.Color) == "R"); index = ComponentIndex.G; Assert.IsTrue(index.GetString(ComponentIndexType.Color) == "G"); index = ComponentIndex.B; Assert.IsTrue(index.GetString(ComponentIndexType.Color) == "B"); index = ComponentIndex.A; Assert.IsTrue(index.GetString(ComponentIndexType.Color) == "A"); index = ComponentIndex.X; Assert.IsTrue(index.GetString(ComponentIndexType.Vector) == "X"); index = ComponentIndex.Y; Assert.IsTrue(index.GetString(ComponentIndexType.Vector) == "Y"); index = ComponentIndex.Z; Assert.IsTrue(index.GetString(ComponentIndexType.Vector) == "Z"); index = ComponentIndex.W; Assert.IsTrue(index.GetString(ComponentIndexType.Vector) == "W"); index = ComponentIndex.R; Assert.IsTrue(index.GetString(ComponentIndexType.Index) == "0"); }
string GetName(NameFormat nameFormat, GameObjectIndex gameObjectIndex, ComponentIndex componentIndex) { string name = string.Empty; switch (nameFormat) { case NameFormat.gameObject: name = gameObjectIndex.gameObject.name; break; case NameFormat.component: name = componentIndex.component.GetType().Name; break; case NameFormat.gameObject_component: name = gameObjectIndex.gameObject.name + "_" + componentIndex.component.GetType().Name; break; case NameFormat.path: name = gameObjectIndex.path; break; case NameFormat.path_component: name = gameObjectIndex.path + "_" + componentIndex.component.GetType().Name; break; default: break; } name = name.Replace(" ", ""); return(name); }
/// <summary> /// 获取游戏对象索引 /// </summary> /// <param name="gameObject">游戏对象</param> /// <param name="parentHierarchy">父级层级</param> /// <returns></returns> GameObjectIndex GetGameObjectIndex(GameObject gameObject, int parentHierarchy, string path) { GameObjectIndex prefabIndex = new GameObjectIndex(); prefabIndex.gameObject = gameObject; prefabIndex.hierarchy = parentHierarchy + 1; Component[] components = gameObject.GetComponents <Component>(); for (int i = 0; i < components.Length; i++) { Component component = components[i]; ComponentIndex activeComponent = new ComponentIndex(); activeComponent.component = component; activeComponent.name = GetName(activeComponent.nameFormat, prefabIndex, activeComponent); activeComponent.path = path; prefabIndex.components.Add(activeComponent); allComponentIndex.Add(activeComponent); } return(prefabIndex); }
public ComponentIndex ComponentIndex() { ComponentIndex ci = new ComponentIndex(); IntPtr ptr = ConstPointer(); UnsafeNativeMethods.ON_Geometry_ComponentIndex(ptr, ref ci); return(ci); }
internal AttributeLayout(MeshChannel channel, ComponentIndex index, Vector2 range, int mask, bool isBaseTexture = false) { this.channel = channel; this.index = index; this.range = range; this.mask = mask; this.isBaseTexture = isBaseTexture; }
public override int GetHashCode() { int hashCode = RegisterKey.GetHashCode() ^ ComponentIndex.GetHashCode(); return(hashCode); }
// // kamran : Get an index from Entitas // public int GetIndex <T>(bool useExisted = true) where T : IComponent, new() { //T component; int index = ComponentIndex <T> .FindIn(_contextInfo); return(index); }
internal override IntPtr _InternalGetConstPointer() { if (null != m_shallow_parent) { return(m_shallow_parent.ConstPointer()); } #if RHINO_SDK ObjRef obj_ref = m__parent as ObjRef; if (null != obj_ref) { return(obj_ref.GetGeometryConstPointer(this)); } RhinoObject parent_object = ParentRhinoObject(); if (parent_object == null) { FileIO.File3dmObject fileobject = m__parent as FileIO.File3dmObject; if (null != fileobject) { return(fileobject.GetGeometryConstPointer()); } } uint serial_number = 0; IntPtr ptr_parent_rhinoobject = IntPtr.Zero; if (null != parent_object) { serial_number = parent_object.m_rhinoobject_serial_number; ptr_parent_rhinoobject = parent_object.m_pRhinoObject; if (IntPtr.Zero == ptr_parent_rhinoobject && parent_object.m__parent != null && parent_object.m__parent is ObjRef) { ObjRef objref = parent_object.m__parent as ObjRef; IntPtr constPtrObjRef = objref.ConstPointer(); ptr_parent_rhinoobject = UnsafeNativeMethods.CRhinoObjRef_Object(constPtrObjRef); } } ComponentIndex ci = new ComponentIndex(); // There are a few cases (like in ReplaceObject callback) where the parent // rhino object temporarily holds onto the CRhinoObject* because the object // is not officially in the document yet. if (ptr_parent_rhinoobject != IntPtr.Zero) { return(UnsafeNativeMethods.CRhinoObject_Geometry(ptr_parent_rhinoobject, ci)); } return(UnsafeNativeMethods.CRhinoObject_Geometry2(serial_number, ci)); #else var fileobject = m__parent as Pixel.Rhino.FileIO.File3dmObject; if (null != fileobject) { return(fileobject.GetGeometryConstPointer()); } return(IntPtr.Zero); #endif }
/// replace Component with a NEW one public T ReplaceNew <T>() where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(_contextInfo); T component = CreateComponent <T>(index); ReplaceComponent(index, component); return(component); }
private static ComponentProblem Add(ref ComponentProblems problems, ComponentIndex componentReal, ComponentIndex componentGUI, string problem, ComponentProblemTypes type, object data = null) { if (problems == null) { problems = new ComponentProblems(); } var res = problems.AddProblem(componentReal, componentGUI, problem, type, data); return(res); }
/// replace Component with a NEW one public static T ReplaceNewComponent <T>(this Entity entity) where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(entity.contextInfo); T component = entity.CreateComponent <T>(index); entity.ReplaceComponent(index, component); return(component); }
/// <summary> /// 解析组建 /// </summary> /// <param name="prefabIndex"></param> void ParseComponents(GameObjectIndex prefabIndex) { for (int i = 0; i < prefabIndex.components.Count; i++) { ComponentIndex activeComponent = prefabIndex.components[i]; if (activeComponent.component.GetType() == typeof(Transform)) { continue; } EditorGUILayout.BeginHorizontal(); { GUIStyle style = new GUIStyle("TextField"); if (activeComponent.nameIsError) { Color myStyleColor = Color.red; style.normal.textColor = myStyleColor; style.onNormal.textColor = myStyleColor; style.hover.textColor = myStyleColor; style.onHover.textColor = myStyleColor; style.focused.textColor = myStyleColor; style.onFocused.textColor = myStyleColor; style.active.textColor = myStyleColor; style.onActive.textColor = myStyleColor; } string name = EditorGUILayout.TextField(string.Format(componentText, activeComponent.component.GetType().Name), activeComponent.name, style); if (activeComponent.name != name) { name = name.Replace(" ", ""); activeComponent.name = name; //修改后 遍历一次名字 CheckName(); } if (advanced) { NameFormat nameFormat = (NameFormat)EditorGUILayout.EnumPopup(nameFormatText, activeComponent.nameFormat); if (activeComponent.nameFormat != nameFormat) { activeComponent.nameFormat = nameFormat; activeComponent.name = GetName(nameFormat, prefabIndex, activeComponent); } } EditorGUILayout.EndHorizontal(); } } }
public void Remove <T>(bool ignoreNotFound = true) where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); if (ignoreNotFound && !HasComponent(index)) { return; } RemoveComponent(index); }
public static void RemoveComponent <T>(this Entity entity, bool ignoreNotExists = false) where T : IComponent { int index = ComponentIndex <T> .FindIn(entity.contextInfo); if (ignoreNotExists && !entity.HasComponent(index)) { return; } entity.RemoveComponent(index); }
public ComponentIndex[] ToArray() { int count = Count; if (count < 1) { return(null); } ComponentIndex[] rc = new ComponentIndex[count]; UnsafeNativeMethods.ON_ComponentIndexArray_CopyValues(m_ptr, ref rc[0]); return(rc); }
private static bool CircleWithRadiusOf10GeometryFilter(Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { bool is_circle_with_radius_of10 = false; Circle circle; if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle)) { is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance; } return(is_circle_with_radius_of10); }
/// <summary> /// Convert a `ComponentIndex` enum value into a flag /// </summary> /// <param name="e"></param> /// <returns>the flag value</returns> internal static uint ToFlag(this ComponentIndex e) { //out of range case if (!Enum.IsDefined(typeof(ComponentIndex), e)) { return((uint)e); } int i = ((int)e) + 1; return((uint)(i < 3 ? i : i == 3 ? 4 : 8)); }
/// <summary> /// Get a list of enities which contain the specified component /// </summary> /// <param name="ComponentID">The specific component to check for</param> /// <returns>List of entities containing the component specified</returns> public List <int> GetAllEntitiesWithComponent(ComponentIndex ComponentID) { List <int> EntitiesFound = new List <int>(); // Search through every entity and check if they contain the component foreach (int Entity in Entities.Keys) { if (HasComponent(Entity, ComponentID)) { EntitiesFound.Add(Entity); } } return(EntitiesFound); }
void CheckName(ComponentIndex componentIndex) { componentIndex.nameIsError = false; //判断是否为数字开头 Regex regNum = new Regex("^[0-9]"); if (regNum.IsMatch(componentIndex.name)) { componentIndex.nameIsError = true; } //判断是否有一样的命名 CheckSameName(componentIndex); }
private ComponentProblem AddProblem(ComponentIndex componentReal, ComponentIndex componentGUI, string problem, ComponentProblemTypes type, object data = null) { var p = new ComponentProblem { Component = componentReal, ComponentGUI = componentGUI, Problem = problem, Type = type, Data = data }; Problems.Add(p); IsProblemsSorted = false; fixWhat = null; return(p); }
bool IsError() { bool isError = false; for (int i = 0; i < allComponentIndex.Count; i++) { ComponentIndex componentIndex = allComponentIndex[i]; if (componentIndex.nameIsError == true) { isError = true; break; } } return(isError); }
void SetIndexs(List <GameObjectIndex> prefabIndexs, NameFormat nameType) { for (int i = 0; i < prefabIndexs.Count; i++) { GameObjectIndex children = prefabIndexs[i]; for (int j = 0; j < children.components.Count; j++) { ComponentIndex component = children.components[j]; component.nameFormat = nameType; component.name = GetName(nameType, children, component); } SetIndexs(children.children, nameType); } }
/// add a new Component, return the old one if exists public T Add <T>(bool useExisted = true) where T : IComponent, new() { T component; int index = ComponentIndex <T> .FindIn(_contextInfo); if (useExisted && HasComponent(index)) { component = (T)GetComponent(index); FireModifiedEvent(index, component); } else { component = CreateComponent <T>(index); AddComponent(index, component); } return(component); }
void CheckName() { if (allComponentIndex == null) { return; } for (int i = 0; i < allComponentIndex.Count; i++) { ComponentIndex componentIndex = allComponentIndex[i]; if (componentIndex.component.GetType() == typeof(Transform)) { continue; } CheckName(componentIndex); } }
// RB 8/16/13 public void TraverseTestBenchForComponentExport(MgaFCO currentobj, string OutputDirectory, string ProjectDirectory) { string type = currentobj.MetaBase.Name; if (type != "TestBench" && type != "BallisticTestBench" && type != "BlastTestBench") { GMEConsole.Info.WriteLine("ERROR: " + type + " != TestBench or BlastTestBench or BallisticTestBench"); return; } //CyPhy.TestBench tb = CyPhyClasses.TestBench.Cast(currentobj); // DY: META-1971 CyPhy.TestBenchType tb = CyPhyClasses.TestBenchType.Cast(currentobj); var catlsut = tb.Children.ComponentAssemblyCollection.FirstOrDefault(); if (catlsut == null) { throw new Exception("There is no elaborated system under test component assembly in the model!"); } ComponentIndex compindex = new ComponentIndex(); //create index TraverseComponentAssemblyForComponentExport(compindex, catlsut, OutputDirectory, ProjectDirectory); }
// 8/16/13 private void TraverseComponentAssemblyForComponentExport(ComponentIndex compindex, CyPhy.ComponentAssembly componentasm, string OutputDirectory, string ProjectDirectory) { foreach (CyPhy.ComponentRef cref in componentasm.Children.ComponentRefCollection) { throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path + "]"); } foreach (CyPhy.ComponentAssembly cainst in componentasm.Children.ComponentAssemblyCollection) { TraverseComponentAssemblyForComponentExport(compindex, cainst, OutputDirectory, ProjectDirectory); } foreach (CyPhy.Component cint in componentasm.Children.ComponentCollection) { var console = GMEConsole.CreateFromProject(cint.Impl.Project); string comp_inst_loc = cint.Attributes.InstanceGUID; //Component Instance char[] charsToTrim = { '{', '}' }; string ACMDir = Path.Combine(OutputDirectory, "ComponentACMs"); //create folder for component acm's if (!Directory.Exists(ACMDir)) Directory.CreateDirectory(ACMDir); string avmid = cint.Attributes.AVMID; string newACMComponentFileLocation; char[] charsToTrim1 = { '{', '}' }; string RandACMFileName = System.IO.Path.GetRandomFileName() + ".component.acm"; newACMComponentFileLocation = Path.Combine(ACMDir, RandACMFileName); String classification = ""; try { // First, try to copy the original ACM file, if found. // If not, then export a new one. CAD model must be present. string originalACMFilePath = ""; if (META.ComponentLibraryManager.TryGetOriginalACMFilePath(cint, out originalACMFilePath, META.ComponentLibraryManager.PathConvention.ABSOLUTE, ProjectDirectory: ProjectDirectory)) { File.Copy(originalACMFilePath, newACMComponentFileLocation); classification = cint.Attributes.Classifications.Split('\n').FirstOrDefault(); } else { const string cadFormat = "Creo"; CyPhy.CADModel cadmodel = cint.Children.CADModelCollection.FirstOrDefault(x => x.Attributes.FileFormat.ToString() == cadFormat); if (cadmodel == null || cadmodel.Attributes.FileFormat.ToString() != cadFormat) { console.Warning.WriteLine("Skipping component export for {0}. No original ACM file found and no CAD model present in component.", Safeify(cint.Name)); continue; } else { var avmComponentModel = CyPhyML2AVM.AVMComponentBuilder.CyPhyML2AVM(cint); SerializeAvmComponent(avmComponentModel, newACMComponentFileLocation); classification = avmComponentModel.Classifications.FirstOrDefault(); } } } catch (Exception ex) { //var console = GMEConsole.CreateFromProject(cint.Impl.Project); console.Warning.WriteLine("Unable to find original ACM file or export a new one for {0}. Reason: {1} Moving to next component.", Safeify(cint.Name), Safeify(ex.Message)); continue; } System.Uri acm = new Uri(newACMComponentFileLocation); System.Uri acm_folder = new Uri(ACMDir); string relative_path = Uri.UnescapeDataString(acm_folder.MakeRelativeUri(acm).ToString()); compindex.AddMember(cint.Name, cint.Attributes.AVMID, cint.Attributes.InstanceGUID, relative_path, classification); //add component to index compindex.Serialize(); compindex.SerializeToFile(Path.Combine(OutputDirectory, "component_index.json")); } }