/// <summary> /// Find whether an entity is already created before /// </summary> /// <param name="entityName">the entity in concern</param> /// <returns>the entity node in the tree</returns> public IfcSchemaEntityNode Find(string entityName) { IfcSchemaEntityNode res = null; IfcEntityDict.TryGetValue(entityName, out res); return(res); }
/// <summary> /// Add a new node into the tree /// </summary> /// <param name="entityName">the entity name</param> /// <param name="parentNodeName">the name of the supertype entity</param> public void Add(string entityName, string parentNodeName, string predefTypeEnum, bool isAbstract = false) { if (string.IsNullOrEmpty(entityName)) { return; } // We will skip the entityname or its parent name that does not start with Ifc (except Entity) if (string.Compare(entityName, 0, "Ifc", 0, 3, ignoreCase: true) != 0 || (string.Compare(parentNodeName, 0, "Ifc", 0, 3, ignoreCase: true) != 0 && string.Compare(parentNodeName, "Entity", ignoreCase: true) != 0)) { return; } IfcSchemaEntityNode parentNode = null; if (!string.IsNullOrEmpty(parentNodeName)) { // skip if the parent name does not start with Ifc if (string.Compare(parentNodeName, 0, "Ifc", 0, 3, ignoreCase: true) == 0) { if (!IfcEntityDict.TryGetValue(parentNodeName, out parentNode)) { // Parent node does not exist yet, create parentNode = new IfcSchemaEntityNode(parentNodeName); IfcEntityDict.Add(parentNodeName, parentNode); TheTree.Add(parentNode); // Add first into the rootNodes because the parent is null at this stage, we will remove it later is not the case } } } IfcSchemaEntityNode entityNode; if (!IfcEntityDict.TryGetValue(entityName, out entityNode)) { if (parentNode != null) { entityNode = new IfcSchemaEntityNode(entityName, parentNode, predefTypeEnum, abstractEntity: isAbstract); parentNode.AddChildNode(entityNode); } else { entityNode = new IfcSchemaEntityNode(entityName, abstractEntity: isAbstract); // Add into the set of root nodes when parent is null/no parent TheTree.Add(entityNode); } IfcEntityDict.Add(entityName, entityNode); } else { // Update the node's isAbstract property and the parent node (if any) entityNode.isAbstract = isAbstract; if (parentNode != null) { entityNode.SetParentNode(parentNode); if (TheTree.Contains(entityNode)) { TheTree.Remove(entityNode); } parentNode.AddChildNode(entityNode); } } }