/// <summary> /// Gets export type from IFC class name. /// </summary> /// <param name="ifcClassName">The IFC class name.</param> /// <returns>The export type.</returns> public static IFCExportInfoPair GetExportTypeFromClassName(String ifcClassName) { IFCExportInfoPair exportInfoPair = new IFCExportInfoPair(); if (ifcClassName.StartsWith("Ifc", true, null)) { // Here we try to catch any possible types that are missing above by checking both the class name or the type name // Unless there is any special treatment needed most of the above check can be done here string clName = ifcClassName.Substring(ifcClassName.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase) ? ifcClassName.Substring(0, ifcClassName.Length - 4) : ifcClassName; string tyName = null; if (((ExporterCacheManager.ExportOptionsCache.ExportAs2x2 || ExporterCacheManager.ExportOptionsCache.ExportAs2x3)) && (clName.Equals("IfcDoor", StringComparison.InvariantCultureIgnoreCase) || clName.Equals("ifcWindow", StringComparison.InvariantCultureIgnoreCase))) { // Prior to IFC4 Door and Window types are not "Ifc..Type", but "Ifc.. Style" tyName = clName + "Style"; } else { tyName = clName + "Type"; } IFCEntityType theGenExportClass; IFCEntityType theGenExportType; var ifcEntitySchemaTree = IfcSchemaEntityTree.GetEntityDictFor(ExporterCacheManager.ExportOptionsCache.FileVersion); if (ifcEntitySchemaTree == null || ifcEntitySchemaTree.Count == 0) { throw new Exception("Unable to locate IFC Schema xsd file! Make sure the relevant xsd " + ExporterCacheManager.ExportOptionsCache.FileVersion + " exists."); } bool clNameValid = false; bool tyNameValid = false; IfcSchemaEntityNode clNode = IfcSchemaEntityTree.Find(clName); if (clNode != null) { clNameValid = IfcSchemaEntityTree.IsSubTypeOf(clName, "IfcProduct") && !clNode.isAbstract; } IfcSchemaEntityNode tyNode = IfcSchemaEntityTree.Find(tyName); if (tyNode != null) { tyNameValid = IfcSchemaEntityTree.IsSubTypeOf(tyName, "IfcTypeProduct") && !tyNode.isAbstract; } if (tyNameValid) { if (IFCEntityType.TryParse(tyName, out theGenExportType)) { exportInfoPair.ExportType = theGenExportType; } } if (clNameValid) { if (IFCEntityType.TryParse(clName, out theGenExportClass)) { exportInfoPair.ExportInstance = theGenExportClass; } } // If the instance is not valid, but the type is valid, try find the paired instance supertype that is not Abstract type else if (tyNameValid) { IfcSchemaEntityNode compatibleInstance = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(tyName); if (compatibleInstance != null) { if (IFCEntityType.TryParse(compatibleInstance.Name, out theGenExportClass)) { exportInfoPair.ExportInstance = theGenExportClass; } } } // This used to throw an exception, but this could abort export if the user enters a bad IFC class name // in the ExportLayerOptions table. In the future, we should log this. //throw new Exception("IFC: Unknown IFC type in getExportTypeFromClassName: " + ifcClassName); //return IFCExportType.IfcBuildingElementProxyType; if (exportInfoPair.ExportInstance == IFCEntityType.UnKnown) { exportInfoPair.ExportInstance = IFCEntityType.IfcBuildingElementProxy; } } //return IFCExportType.DontExport; return(exportInfoPair); }
/// <summary> /// Set the pair information using only either the entity or the type /// </summary> /// <param name="entityTypeStr">the entity or type string</param> /// <param name="predefineType">predefinedtype string</param> public void SetValueWithPair(string entityTypeStr, string predefineType = null) { int typeLen = 4; bool isType = entityTypeStr.Substring(entityTypeStr.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase); if (!isType) { if (entityTypeStr.Equals("IfcDoorStyle", StringComparison.InvariantCultureIgnoreCase) || entityTypeStr.Equals("IfcWindowStyle", StringComparison.InvariantCultureIgnoreCase)) { isType = true; typeLen = 5; } } if (isType) { // Get the instance string instName = entityTypeStr.Substring(0, entityTypeStr.Length - typeLen); IfcSchemaEntityNode node = IfcSchemaEntityTree.Find(instName); if (node != null && !node.isAbstract) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(instName, true, out instType)) { m_ExportInstance = instType; } } else { // If not found, try non-abstract supertype derived from the type node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(instName); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, true, out instType)) { m_ExportInstance = instType; } } } // set the type IFCEntityType entityType = ElementFilteringUtil.GetValidIFCEntityType(entityTypeStr); if (entityType != IFCEntityType.UnKnown) { m_ExportType = entityType; } else { node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, true, out instType)) { m_ExportType = instType; } } } } else { // set the instance IFCEntityType instType = ElementFilteringUtil.GetValidIFCEntityType(entityTypeStr); if (instType != IFCEntityType.UnKnown) { m_ExportInstance = instType; } else { // If not found, try non-abstract supertype derived from the type IfcSchemaEntityNode node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr); if (node != null) { instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, true, out instType)) { m_ExportInstance = instType; } } } // set the type pair string typeName = entityTypeStr; if (ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4 && (entityTypeStr.Equals("IfcDoor", StringComparison.InvariantCultureIgnoreCase) || entityTypeStr.Equals("IfcWindow", StringComparison.InvariantCultureIgnoreCase))) { typeName += "Style"; } else { typeName += "Type"; } IFCEntityType entityType = ElementFilteringUtil.GetValidIFCEntityType(typeName); if (entityType != IFCEntityType.UnKnown) { m_ExportType = entityType; } else { // If the type name is not found, likely it does not have the pair at this level, needs to get the supertype of the instance to get the type pair IList <IfcSchemaEntityNode> instNodes = IfcSchemaEntityTree.FindAllSuperTypes(entityTypeStr, "IfcProduct", "IfcGroup"); foreach (IfcSchemaEntityNode instNode in instNodes) { typeName = instNode.Name + "Type"; IfcSchemaEntityNode node = IfcSchemaEntityTree.Find(typeName); if (node == null) { node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(typeName); } if (node != null && !node.isAbstract) { instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, true, out instType)) { m_ExportType = instType; break; } } } } } ValidatedPredefinedType = predefineType; }
/// <summary> /// Set the pair information using only either the entity or the type /// </summary> /// <param name="entityType">the entity or type</param> public void SetValueWithPair(IFCEntityType entityType) { string entityTypeStr = entityType.ToString(); bool isType = entityTypeStr.Substring(entityTypeStr.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase); if (isType) { // Get the instance string instName = entityTypeStr.Substring(0, entityTypeStr.Length - 4); IfcSchemaEntityNode node = IfcSchemaEntityTree.Find(instName); if (node != null && !node.isAbstract) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(instName, out instType)) { ExportInstance = instType; } } // If not found, try non-abstract supertype derived from the type node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(instName); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, out instType)) { ExportInstance = instType; } } // set the type entityType = ElementFilteringUtil.GetValidIFCEntityType(entityType); if (entityType != IFCEntityType.UnKnown) { ExportType = entityType; } else { node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, out instType)) { ExportType = instType; } } } } else { // set the instance entityType = ElementFilteringUtil.GetValidIFCEntityType(entityType); if (entityType != IFCEntityType.UnKnown) { ExportInstance = entityType; } else { // If not found, try non-abstract supertype derived from the type IfcSchemaEntityNode node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, out instType)) { ExportInstance = instType; } } } // set the type pair string typeName = entityType.ToString() + "Type"; entityType = ElementFilteringUtil.GetValidIFCEntityType(typeName); if (entityType != IFCEntityType.UnKnown) { ExportType = entityType; } else { IfcSchemaEntityNode node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(typeName); if (node != null) { IFCEntityType instType = IFCEntityType.UnKnown; if (IFCEntityType.TryParse(node.Name, out instType)) { ExportType = instType; } } } } }