/// <summary> /// Check whether an entity (string) is a supertype of another entity /// </summary> /// <param name="context">the IFC version in context for the check</param> /// <param name="superTypeName">the supertype name</param> /// <param name="subTypeName">the subtype name</param> /// <param name="strict">whether the supertype is strictly supertype. Set to false if it "supertype == subtype" is acceptable</param> /// <returns>true if it is supertype</returns> static public bool IsSuperTypeOf(string context, string superTypeName, string subTypeName, bool strict = true) { IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context); //var ifcEntitySchemaTree = IfcSchemaEntityTree.GetEntityDictFor(context); if (ifcEntitySchemaTree == null || ifcEntitySchemaTree.IfcEntityDict == null || ifcEntitySchemaTree.IfcEntityDict.Count == 0) { throw new Exception("Unable to locate IFC Schema xsd file! Make sure the relevant xsd " + context + " exists."); } IfcSchemaEntityNode theNode = ifcEntitySchemaTree.Find(superTypeName); if (theNode != null) { if (strict) { return(theNode.IsSuperTypeOf(subTypeName)); } else { return(theNode.Name.Equals(subTypeName, StringComparison.InvariantCultureIgnoreCase) || theNode.IsSuperTypeOf(subTypeName)); } } return(false); }
/// <summary> /// Find a Non ABS supertype entity from the input type name /// </summary> /// <param name="context">the IFC schema context</param> /// <param name="typeName">the type name</param> /// <returns>the non-abs supertype instance node</returns> static public IfcSchemaEntityNode FindNonAbsInstanceSuperType(string context, string typeName) { IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context); IfcSchemaEntityNode res = null; // Note: Implementer's agreement #CV-2x3-166 changes IfcSpaceHeaterType from IfcEnergyConversionDevice to IfcFlowTerminal. if (context.Equals(Ifc2x3Schema, StringComparison.InvariantCultureIgnoreCase) && typeName.Equals("IfcSpaceHeaterType", StringComparison.InvariantCultureIgnoreCase)) { res = ifcEntitySchemaTree.Find("IfcFlowTerminal"); if (res.isAbstract) { return(null); } return(res); } string theTypeName = typeName.Substring(typeName.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase) ? typeName : typeName + "Type"; IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(theTypeName); if (entNode != null) { while (true) { res = entNode.GetParent(); // no more parent node to get if (res == null) { break; } entNode = ifcEntitySchemaTree.Find(res.Name.Substring(0, res.Name.Length - 4)); if (entNode != null && !entNode.isAbstract) { res = entNode; break; } else { entNode = res; // put back the Type Node } } } return(res); }
static public IList <IfcSchemaEntityNode> FindAllSuperTypes(string context, string entityName, params string[] stopNode) { IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context); IList <IfcSchemaEntityNode> res = new List <IfcSchemaEntityNode>(); IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(entityName); if (entNode != null) { // return the list when it reaches the stop node foreach (string stopCond in stopNode) { if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase)) { return(res); } } bool continueSearch = true; while (continueSearch) { entNode = entNode.GetParent(); // no more parent node to get if (entNode == null) { break; } // Stop the search when it reaches the stop node foreach (string stopCond in stopNode) { if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase)) { continueSearch = false; break; } } if (entNode != null) { res.Add(entNode); } } } return(res); }
/// <summary> /// Find a Non-Abstract Super Type in the current IFC Schema /// </summary> /// <param name="context">the IFC schema context</param> /// <param name="typeName">the entity name</param> /// <param name="stopNode">optional list of entity name(s) to stop the search</param> /// <returns>the appropriate node or null</returns> static public IfcSchemaEntityNode FindNonAbsSuperType(string context, string entityName, params string[] stopNode) { IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context); IfcSchemaEntityNode res = null; IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(entityName); if (entNode != null) { foreach (string stopCond in stopNode) { if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase)) { return(res); } } while (true) { entNode = entNode.GetParent(); // no more parent node to get if (entNode == null) { break; } foreach (string stopCond in stopNode) { if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase)) { break; } } if (entNode != null && !entNode.isAbstract) { res = entNode; break; } } } return(res); }