/// <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> /// Reset the static Dictionary and Set. To be done before parsing another IFC schema /// </summary> public static void Initialize(string schemaFile) { // If the same schema is already loaded and has content, do nothing if (loadedIfcSchemaVersion.Equals(schemaFile, StringComparison.InvariantCultureIgnoreCase) && EntityDict.Count > 0) { return; } // It is a new schema or the first time IfcEntityDict.Clear(); PredefinedTypeEnumDict.Clear(); rootNodes.Clear(); loadedIfcSchemaVersion = ""; }
/// <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); } } }