/// <summary> /// Checks if the IFC type is MEP type. /// </summary> /// <param name="exportType">IFC Export Type to check</param> /// <returns>True for MEP type of elements.</returns> public static bool IsMEPType(IFCExportInfoPair exportType) { bool instanceIsMEPInst = IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportInstance.ToString(), IFCEntityType.IfcDistributionElement.ToString(), strict: false); // The Type probably is not needed for check? bool typeIsMEPType = IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportType.ToString(), IFCEntityType.IfcDistributionElementType.ToString(), strict: false); return(instanceIsMEPInst); }
/// <summary> /// Constructor for initializing EntityTree /// </summary> /// <param name="ifcVersion">the selected IFC version. This will "lock" the schema version in the dialog</param> /// <param name="excludeFilter">the initial list of the excluded entities. Can be used to initialize the setting</param> /// <param name="singleNodeSelection">true if the tree is used for a single node selection</param> /// <param name="showTypeNodeOnly">option to show IfcTypeObject tree only</param> /// <param name="preSelectItem">preselect an item (works for a single node selection only)</param> /// <param name="preSelectPdef">pre-select the predefined type</param> public EntityTree(IFCVersion ifcVersion, string excludeFilter, string desc, bool singleNodeSelection = false, bool showTypeNodeOnly = false, string preSelectEntity = null, string preSelectPdef = null) { m_IfcVersion = IfcSchemaEntityTree.SchemaName(ifcVersion); ExclElementSet = FillSetFromList(excludeFilter); m_SingleNodeSelection = singleNodeSelection; TreeSelectionDesc = desc; m_ShowTypeNodeOnly = showTypeNodeOnly; InitializeEntityTree(preSelectEntity, preSelectPdef); }
void InitializeEntityTree(string preSelectEntity, string preSelectPDef) { IfcSchemaEntityTree.GetAllEntityDict(); InitializeComponent(); textBox_Search.Focus(); if (m_SingleNodeSelection) { label_Show.Visibility = System.Windows.Visibility.Hidden; comboBox_ShowItems.Visibility = System.Windows.Visibility.Hidden; } else { HelpRun.Text = Properties.Resources.HelpSelectEntityForExport; comboBox_ShowItems.ItemsSource = new List <string>() { Properties.Resources.ShowAll, Properties.Resources.ShowChecked, Properties.Resources.ShowUnchecked }; comboBox_ShowItems.SelectedIndex = 0; // Default selection to show All } // If the IFC schema version is selected for export, the combobox will be disabled for selection ComboBox_IFCSchema.IsEnabled = false; // Assign default if (string.IsNullOrEmpty(m_IfcVersion)) { m_IfcVersion = IFCVersion.IFC4.ToString(); ComboBox_IFCSchema.IsEnabled = true; } ComboBox_IFCSchema.ItemsSource = IfcSchemaEntityTree.GetAllCachedSchemaNames(); ComboBox_IFCSchema.SelectedItem = m_IfcVersion; if (m_SingleNodeSelection) { Grid_Main.ColumnDefinitions[2].MinWidth = 200; } else { // In multi-selection mode, hide the TreView panel for the PredefinedType Grid_Main.ColumnDefinitions[2].MinWidth = 0; GridLengthConverter grLenConv = new GridLengthConverter(); GridLength grLen = (GridLength)grLenConv.ConvertFrom(0); Grid_Main.ColumnDefinitions[2].Width = grLen; } LoadTreeviewFilterElement(); PreSelectItem(preSelectEntity, preSelectPDef); IfcSchemaEntityTree.GenerateEntityTrie(ref m_EntityTrie); }
/// <summary> /// Get valid IFC entity type by using the official IFC schema (using the XML schema). It checks the non-abstract valid entity. /// If it is found to be abstract, it will try to find its supertype until it finds a non-abstract type. /// </summary> /// <param name="entityType">the IFC entity type (string) to check</param> /// <returns>return the appropriate IFCEntityType enumeration or Unknown</returns> public static IFCEntityType GetValidIFCEntityType(string entityType) { IFCVersion ifcVersion = ExporterCacheManager.ExportOptionsCache.FileVersion; IFCEntityType ret = IFCEntityType.UnKnown; var ifcEntitySchemaTree = IfcSchemaEntityTree.GetEntityDictFor(ExporterCacheManager.ExportOptionsCache.FileVersion); 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 " + ExporterCacheManager.ExportOptionsCache.FileVersion + " exists."); } IfcSchemaEntityNode node = ifcEntitySchemaTree.Find(entityType); IFCEntityType ifcType = IFCEntityType.UnKnown; if (node != null && !node.isAbstract) { // Only IfcProduct or IfcTypeProduct can be assigned for export type //if (!node.IsSubTypeOf("IfcProduct") && !node.IsSubTypeOf("IfcTypeProduct") && !node.Name.Equals("IfcGroup", StringComparison.InvariantCultureIgnoreCase)) if ((node.IsSubTypeOf("IfcObject") && (node.IsSubTypeOf("IfcProduct") || node.IsSubTypeOf("IfcGroup") || node.Name.Equals("IfcGroup", StringComparison.InvariantCultureIgnoreCase))) || node.IsSubTypeOf("IfcProject") || node.Name.Equals("IfcProject", StringComparison.InvariantCultureIgnoreCase) || node.IsSubTypeOf("IfcTypeObject")) { if (IFCEntityType.TryParse(entityType, true, out ifcType)) { ret = ifcType; } } else { ret = ifcType; } } else if (node != null && node.isAbstract) { node = IfcSchemaEntityTree.FindNonAbsSuperType(ifcVersion, entityType, "IfcProduct", "IfcProductType", "IfcGroup", "IfcProject"); if (node != null) { if (Enum.TryParse <IFCEntityType>(node.Name, true, out ifcType)) { ret = ifcType; } } } return(ret); }
private void button_supertypeTest_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(textBox_type1.Text) || string.IsNullOrEmpty(textBox_type2.Text)) { return; } bool res = IfcSchemaEntityTree.IsSuperTypeOf(textBox_type1.Text, textBox_type2.Text); if (res) { checkBox_testResult.IsChecked = true; } else { checkBox_testResult.IsChecked = false; } }
/// <summary> /// /// </summary> /// <param name="handle"></param> /// <returns></returns> public bool IsSubTypeOfEntityTypes(IFCEntityType ifcEntityType) { var ifcEntitySchemaTree = IfcSchemaEntityTree.GetEntityDictFor(ExporterCacheManager.ExportOptionsCache.FileVersion); if (ifcEntitySchemaTree == null || ifcEntitySchemaTree.Count == 0) { return(false); } // Note that although EntityTypes is represented as a set, we still need to go through each item in the last to check for subtypes. foreach (IFCEntityType entityType in EntityTypes) { if (IfcSchemaEntityTree.IsSubTypeOf(ifcEntityType.ToString(), entityType.ToString(), strict: false)) { return(true); } } return(false); }
void InitializePreDefinedTypeSelection(string ifcSchema, string ifcEntitySelected) { if (string.IsNullOrEmpty(ifcEntitySelected)) { return; } TreeView predefinedTypeTreeView = new TreeView(); IfcSchemaEntityTree ifcEntityTree = IfcSchemaEntityTree.GetEntityDictFor(ifcSchema); IList <string> predefinedTypeList = IfcSchemaEntityTree.GetPredefinedTypeList(ifcEntityTree, ifcEntitySelected); if (predefinedTypeList != null && predefinedTypeList.Count > 0) { TreeViewItem ifcEntityViewItem = new TreeViewItem(); ifcEntityViewItem.Name = ifcEntitySelected; ifcEntityViewItem.Header = ifcEntitySelected + ".PREDEFINEDTYPE"; ifcEntityViewItem.IsExpanded = true; predefinedTypeTreeView.Items.Add(ifcEntityViewItem); foreach (string predefItem in predefinedTypeList) { TreeViewItem childNode = new TreeViewItem(); RadioButton childNodeItem = new RadioButton(); childNode.Name = predefItem; childNodeItem.Name = predefItem; childNodeItem.Content = predefItem; childNodeItem.Checked += new RoutedEventHandler(PredefSelected_Checked); childNodeItem.Unchecked += new RoutedEventHandler(PredefSelected_Unchecked); childNode.Header = childNodeItem; ifcEntityViewItem.Items.Add(childNode); } } else { TreeViewItem ifcEntityViewItem = new TreeViewItem(); ifcEntityViewItem.Name = ifcEntitySelected; ifcEntityViewItem.Header = Properties.Resources.NoPredefinedType; predefinedTypeTreeView.Items.Add(ifcEntityViewItem); } PredefinedTypeTreeView.ItemsSource = predefinedTypeTreeView.Items; }
/// <summary> /// Procees an IFC schema from the IFCXML schema /// </summary> /// <param name="f">IFCXML schema file</param> private void processSchema(FileInfo f) { ProcessIFCXMLSchema.ProcessIFCSchema(f); string schemaName = f.Name.Replace(".xsd", ""); if (checkBox_outputSchemaTree.IsChecked == true) { string treeDump = IfcSchemaEntityTree.DumpTree(); System.IO.File.WriteAllText(outputFolder + @"\entityTree" + schemaName + ".txt", treeDump); } if (checkBox_outputSchemaEnum.IsChecked == true) { string dictDump = IfcSchemaEntityTree.DumpEntityDict(schemaName); System.IO.File.WriteAllText(outputFolder + @"\entityEnum" + schemaName + ".cs", dictDump); } // Add aggregate of the entity list into a set foreach (KeyValuePair <string, IfcSchemaEntityNode> entry in IfcSchemaEntityTree.EntityDict) { aggregateEntities.Add(entry.Key); } }
void LoadTreeviewFilterElement() { button_Reset.IsEnabled = true; try { string schemaFile = m_IfcVersion + ".xsd"; // Process IFCXml schema here, then search for IfcProduct and build TreeView beginning from that node. Allow checks for the tree nodes. Grey out (and Italic) the abstract entity schemaFile = System.IO.Path.Combine(DirectoryUtil.IFCSchemaLocation, schemaFile); FileInfo schemaFileInfo = new FileInfo(schemaFile); IFCEntityTrie entityTrie = new IFCEntityTrie(); IfcSchemaEntityTree ifcEntityTree = IfcSchemaEntityTree.GetEntityDictFor(m_IfcVersion); if (ifcEntityTree != null || m_TreeView.Items.Count == 0) { m_TreeView.Items.Clear(); m_TreeViewItemDict.Clear(); if (!m_ShowTypeNodeOnly) { IfcSchemaEntityNode ifcProductNode; if (ifcEntityTree.IfcEntityDict.TryGetValue("IfcProduct", out ifcProductNode)) { // From IfcProductNode, recursively get all the children nodes and assign them into the treeview node (they are similar in the form) TreeViewItem prod = new TreeViewItem(); prod.Name = "IfcProduct"; if (m_SingleNodeSelection) { prod.Header = ifcProductNode.Name + " " + TreeSelectionDesc; } else { ToggleButton prodNode = new CheckBox(); prodNode.Name = prod.Name; prodNode.Content = prod.Name; prodNode.IsChecked = true; prod.Header = prodNode; prodNode.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); prodNode.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); } prod.IsExpanded = true; prod.FontWeight = FontWeights.Bold; m_TreeView.Items.Add(GetNode(ifcProductNode, prod, ExclElementSet)); } } IfcSchemaEntityNode ifcTypeProductNode; if (ifcEntityTree.IfcEntityDict.TryGetValue("IfcTypeProduct", out ifcTypeProductNode)) { // From IfcTypeProductNode, recursively get all the children nodes and assign them into the treeview node (they are similar in the form) TreeViewItem typeProd = new TreeViewItem(); typeProd.Name = "IfcTypeProduct"; typeProd.Header = ifcTypeProductNode.Name + " " + TreeSelectionDesc; if (m_SingleNodeSelection) { typeProd.Header = ifcTypeProductNode.Name + " " + TreeSelectionDesc; } else { ToggleButton typeProdNode = new CheckBox(); typeProdNode.Name = typeProd.Name; typeProdNode.Content = typeProd.Name; typeProdNode.IsChecked = true; typeProd.Header = typeProdNode; typeProdNode.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); typeProdNode.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); } typeProd.IsExpanded = true; typeProd.FontWeight = FontWeights.Bold; m_TreeView.Items.Add(GetNode(ifcTypeProductNode, typeProd, ExclElementSet)); } if (!m_ShowTypeNodeOnly) { IfcSchemaEntityNode ifcGroupNode; if (ifcEntityTree.IfcEntityDict.TryGetValue("IfcGroup", out ifcGroupNode)) { // For IfcGroup, a header is neaded because the IfcGroup itself is not a Abstract entity TreeViewItem groupHeader = new TreeViewItem(); groupHeader.Name = "IfcGroup"; if (m_SingleNodeSelection) { groupHeader.Header = "IfcGroup" + " " + TreeSelectionDesc; } else { ToggleButton groupHeaderNode = new CheckBox(); groupHeaderNode.Name = groupHeader.Name; groupHeaderNode.Content = groupHeader.Name; groupHeaderNode.IsChecked = true; groupHeader.Header = groupHeaderNode; groupHeaderNode.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); groupHeaderNode.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); } groupHeader.IsExpanded = true; groupHeader.FontWeight = FontWeights.Bold; m_TreeView.Items.Add(groupHeader); // From IfcGroup Node, recursively get all the children nodes and assign them into the treeview node (they are similar in the form) TreeViewItem groupNode = new TreeViewItem(); ToggleButton groupNodeItem; if (m_SingleNodeSelection) { groupNodeItem = new RadioButton(); } else { groupNodeItem = new CheckBox(); } groupNode.Name = "IfcGroup"; groupNode.Header = groupNodeItem; groupNode.IsExpanded = true; m_TreeViewItemDict.Add(groupNode.Name, groupNode); m_EntityTrie.AddIFCEntityToDict(groupNode.Name); groupNodeItem.Name = "IfcGroup"; groupNodeItem.Content = "IfcGroup"; groupNodeItem.FontWeight = FontWeights.Normal; groupNodeItem.IsChecked = true; // Default is always Checked if (ExclElementSet.Contains(groupNode.Name) || m_SingleNodeSelection) { groupNodeItem.IsChecked = false; // if the name is inside the excluded element hashset, UNcheck the checkbox (= remember the earlier choice) } groupNodeItem.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); groupNodeItem.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); groupHeader.Items.Add(GetNode(ifcGroupNode, groupNode, ExclElementSet)); } } } else { // Check all elements that have been excluded before for this configuration foreach (TreeViewItem tvItem in m_TreeView.Items) { UnCheckSelectedNode(tvItem, ExclElementSet); } } } catch { // Error above in processing - disable the tree view. m_TreeView.IsEnabled = false; } IFCEntityTreeView.ItemsSource = m_TreeView.Items; }
/// <summary> /// Checks if export type is conversion device. /// </summary> /// <param name="exportType"> /// The export type. /// </param> /// <returns> /// True if it is conversion device, false otherwise. /// </returns> public static bool IsEnergyConversionDeviceSubType(IFCExportInfoPair exportType) { return(IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportInstance.ToString(), IFCEntityType.IfcEnergyConversionDevice.ToString(), strict: false) || IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportType.ToString(), IFCEntityType.IfcEnergyConversionDeviceType.ToString(), strict: false)); }
/// <summary> /// Checks if export type is flow fitting. /// </summary> /// <param name="exportType"> /// The export type. /// </param> /// <returns> /// True if it is flow fitting, false otherwise. /// </returns> public static bool IsFlowFittingSubType(IFCExportInfoPair exportType) { return(IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportInstance.ToString(), IFCEntityType.IfcFlowFitting.ToString(), strict: false) || IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportType.ToString(), IFCEntityType.IfcFlowFittingType.ToString(), strict: false)); }
/// <summary> /// Initialization for the class for PredefinedType selection /// </summary> /// <param name="ifcVersion">the IFC version selected. If it is specific, it will be locked</param> /// <param name="ifcEntitySelected">the ifc entity to find the predefinedtype</param> public PredefinedTypeSelection(IFCVersion ifcVersion, string ifcEntitySelected) { string ifcSchema = IfcSchemaEntityTree.SchemaName(ifcVersion); InitializePreDefinedTypeSelection(ifcSchema, ifcEntitySelected); }
/// <summary> /// Checks if export type is distribution control element. /// </summary> /// <param name="exportType"> /// The export type. /// </param> /// <returns> /// True if it is distribution control element, false otherwise. /// </returns> public static bool IsDistributionControlElementSubType(IFCExportInfoPair exportType) { return(IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportInstance.ToString(), IFCEntityType.IfcDistributionControlElement.ToString(), strict: false) || IfcSchemaEntityTree.IsSubTypeOf(ExporterCacheManager.ExportOptionsCache.FileVersion, exportType.ExportType.ToString(), IFCEntityType.IfcDistributionControlElementType.ToString(), strict: false)); }
/// <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> /// 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="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; } } } } }
TreeViewItem GetNode(IfcSchemaEntityNode ifcNode, TreeViewItem thisNode, HashSet <string> exclSet) { foreach (IfcSchemaEntityNode ifcNodeChild in ifcNode.GetChildren()) { // Skip deprecated entity if (IfcSchemaEntityTree.IsDeprecatedOrUnsupported(m_IfcVersion, ifcNodeChild.Name)) { continue; } TreeViewItem childNode = new TreeViewItem(); if (m_SingleNodeSelection) { childNode.Name = ifcNodeChild.Name; m_TreeViewItemDict.Add(childNode.Name, childNode); m_EntityTrie.AddIFCEntityToDict(ifcNodeChild.Name); if (ifcNodeChild.isAbstract) { childNode.Header = ifcNodeChild.Name; childNode.FontWeight = FontWeights.Normal; } else { ToggleButton childNodeItem; childNodeItem = new RadioButton(); childNodeItem.Name = ifcNodeChild.Name; childNodeItem.Content = ifcNodeChild.Name; childNodeItem.FontWeight = FontWeights.Normal; childNodeItem.IsChecked = false; childNodeItem.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); childNodeItem.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); childNode.Header = childNodeItem; } } else { childNode.Name = ifcNodeChild.Name; m_TreeViewItemDict.Add(childNode.Name, childNode); m_EntityTrie.AddIFCEntityToDict(ifcNodeChild.Name); ToggleButton childNodeItem; childNodeItem = new CheckBox(); childNodeItem.Name = ifcNodeChild.Name; childNodeItem.Content = ifcNodeChild.Name; childNodeItem.FontWeight = FontWeights.Normal; childNodeItem.IsChecked = true; // Default is always Checked if (exclSet.Contains(ifcNodeChild.Name)) { childNodeItem.IsChecked = false; // if the name is inside the excluded element hashset, UNcheck the checkbox (= remember the earlier choice) } childNodeItem.Checked += new RoutedEventHandler(TreeViewItem_HandleChecked); childNodeItem.Unchecked += new RoutedEventHandler(TreeViewItem_HandleUnchecked); childNode.Header = childNodeItem; } childNode.IsExpanded = true; childNode = GetNode(ifcNodeChild, childNode, exclSet); thisNode.Items.Add(childNode); } return(thisNode); }
private void button_Go_Click(object sender, RoutedEventArgs e) { if (listBox_schemaList.SelectedItems.Count == 0) { return; } DirectoryInfo dInfo = new DirectoryInfo(textBox_folderLocation.Text); if (dInfo == null) { return; } if (aggregateEntities == null) { aggregateEntities = new SortedSet <string>(); } aggregateEntities.Clear(); if (!Directory.Exists(textBox_outputFolder.Text)) { textBox_outputFolder.Text = ""; return; } logF = new StreamWriter(System.IO.Path.Combine(outputFolder, "entityList.log")); IList <IFCEntityAndPsetList> fxEntityNPsetList = new List <IFCEntityAndPsetList>(); string jsonFile = outputFolder + @"\IFCEntityAndPsetDefs.json"; if (File.Exists(jsonFile)) { File.Delete(jsonFile); } FileStream fs = File.Create(jsonFile); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List <IFCEntityAndPsetList>)); foreach (string fileName in listBox_schemaList.SelectedItems) { FileInfo f = dInfo.GetFiles(fileName).First(); processSchema(f); ProcessPsetDefinition procPdef = new ProcessPsetDefinition(logF); string schemaName = f.Name.Replace(".xsd", ""); IDictionary <string, IfcSchemaEntityNode> entDict = IfcSchemaEntityTree.GetEntityDictFor(f.Name); IFCEntityAndPsetList schemaEntities = new IFCEntityAndPsetList(); schemaEntities.Version = schemaName; schemaEntities.EntityList = new HashSet <IFCEntityInfo>(); schemaEntities.PsetDefList = new HashSet <IFCPropertySetDef>(); DirectoryInfo[] psdFolders = new DirectoryInfo(System.IO.Path.Combine(textBox_folderLocation.Text, schemaName)).GetDirectories("psd", SearchOption.AllDirectories); DirectoryInfo[] underpsdFolders = psdFolders[0].GetDirectories(); if (underpsdFolders.Count() > 0) { foreach (DirectoryInfo subDir in psdFolders[0].GetDirectories()) { procPdef.ProcessSchemaPsetDef(schemaName, subDir); } } else { procPdef.ProcessSchemaPsetDef(schemaName, psdFolders[0]); } //Collect information on applicable Psets for Entity IDictionary <string, HashSet <string> > entPsetDict = new Dictionary <string, HashSet <string> >(); foreach (KeyValuePair <string, IList <VersionSpecificPropertyDef> > pdefEntry in procPdef.allPDefDict) { foreach (VersionSpecificPropertyDef vPdef in pdefEntry.Value) { //if (vPdef.IfcVersion.Equals(schemaName, StringComparison.InvariantCultureIgnoreCase)) { IFCPropertySetDef psetDef = new IFCPropertySetDef(); psetDef.PsetName = vPdef.PropertySetDef.Name; IList <string> props = new List <string>(); foreach (PropertySet.PsetProperty property in vPdef.PropertySetDef.properties) { props.Add(property.Name); } psetDef.Properties = props; schemaEntities.PsetDefList.Add(psetDef); // TODO: to check the appl classes either a type or not and check whether the pair (type or without) exists in entDict, if there is add foreach (string applEntity in vPdef.PropertySetDef.ApplicableClasses) { if (entPsetDict.ContainsKey(applEntity)) { entPsetDict[applEntity].Add(vPdef.PropertySetDef.Name); } else { entPsetDict.Add(applEntity, new HashSet <string>() { vPdef.PropertySetDef.Name }); } // The Pset will be valid for both the Instance and the Type. Check for that here and add if found string entOrTypePair; if (applEntity.Length > 4 && applEntity.EndsWith("Type")) { entOrTypePair = applEntity.Substring(0, applEntity.Length - 4); } else { entOrTypePair = applEntity + "Type"; } if (aggregateEntities.Contains(entOrTypePair)) { if (entPsetDict.ContainsKey(entOrTypePair)) { entPsetDict[entOrTypePair].Add(vPdef.PropertySetDef.Name); } else { entPsetDict.Add(entOrTypePair, new HashSet <string>() { vPdef.PropertySetDef.Name }); } } } } } } // For every entity of the schema, collect the list of PredefinedType (obtained from the xsd), and collect all applicable // Pset Definitions collected above foreach (KeyValuePair <string, IfcSchemaEntityNode> ent in entDict) { IFCEntityInfo entInfo = new IFCEntityInfo(); // The abstract entity type is not going to be listed here as they can never be created if (ent.Value.isAbstract) { continue; } // Collect only the IfcProducts or IfcGroup if (!ent.Value.IsSubTypeOf("IfcProduct") && !ent.Value.IsSubTypeOf("IfcGroup") && !ent.Value.IsSubTypeOf("IfcTypeProduct")) { continue; } entInfo.Entity = ent.Key; if (!string.IsNullOrEmpty(ent.Value.PredefinedType)) { if (IfcSchemaEntityTree.PredefinedTypeEnumDict.ContainsKey(ent.Value.PredefinedType)) { entInfo.PredefinedType = IfcSchemaEntityTree.PredefinedTypeEnumDict[ent.Value.PredefinedType]; } } // Get Pset list that is applicable to this entity type if (entPsetDict.ContainsKey(entInfo.Entity)) { entInfo.PropertySets = entPsetDict[entInfo.Entity].ToList(); } // Collect Pset that is applicable to the supertype of this entity IList <IfcSchemaEntityNode> supertypeList = IfcSchemaEntityTree.FindAllSuperTypes(entInfo.Entity, "IfcProduct", "IfcTypeProduct", "IfcGroup"); if (supertypeList != null && supertypeList.Count > 0) { foreach (IfcSchemaEntityNode superType in supertypeList) { if (entPsetDict.ContainsKey(superType.Name)) { if (entInfo.PropertySets == null) { entInfo.PropertySets = new List <string>(); } foreach (string pset in entPsetDict[superType.Name]) { entInfo.PropertySets.Add(pset); } } } } schemaEntities.EntityList.Add(entInfo); } fxEntityNPsetList.Add(schemaEntities); } ser.WriteObject(fs, fxEntityNPsetList); fs.Close(); if (aggregateEntities.Count > 0) { string entityList; entityList = "using System;" + "\r\nusing System.Collections.Generic;" + "\r\nusing System.Linq;" + "\r\nusing System.Text;" + "\r\n" + "\r\nnamespace Revit.IFC.Common.Enums" + "\r\n{" + "\r\n /// <summary>" + "\r\n /// IFC entity types. Combining IFC2x3 and IFC4 (Add2) entities." + "\r\n /// List of Entities for IFC2x is found in IFC2xEntityType.cs" + "\r\n /// List of Entities for IFC4 is found in IFC4EntityType.cs" + "\r\n /// </summary>" + "\r\n public enum IFCEntityType" + "\r\n {"; foreach (string ent in aggregateEntities) { entityList += "\r\n /// <summary>" + "\r\n /// IFC Entity " + ent + " enumeration" + "\r\n /// </summary>" + "\r\n " + ent + ",\n"; } entityList += "\r\n Unknown," + "\r\n DontExport" + "\r\n }" + "\r\n}"; System.IO.File.WriteAllText(outputFolder + @"\IFCEntityType.cs", entityList); } foreach (IFCEntityAndPsetList fxEntityNPset in fxEntityNPsetList) { string entityList; entityList = "using System;" + "\r\nusing System.Collections.Generic;" + "\r\nusing System.Linq;" + "\r\nusing System.Text;" + "\r\n" + "\r\nnamespace Revit.IFC.Common.Enums." + fxEntityNPset.Version + "\r\n{" + "\r\n /// <summary>" + "\r\n /// List of Entities for " + fxEntityNPset.Version + "\r\n /// </summary>" + "\r\n public enum EntityType" + "\r\n {"; foreach (IFCEntityInfo entInfo in fxEntityNPset.EntityList) { entityList += "\r\n /// <summary>" + "\r\n /// IFC Entity " + entInfo.Entity + " enumeration" + "\r\n /// </summary>" + "\r\n " + entInfo.Entity + ",\r\n"; } entityList += "\r\n Unknown," + "\r\n DontExport" + "\r\n }" + "\r\n}"; System.IO.File.WriteAllText(outputFolder + @"\" + fxEntityNPset.Version + "EntityType.cs", entityList); } // Only allows test when only one schema is selected if (listBox_schemaList.SelectedItems.Count == 1) { button_subtypeTest.IsEnabled = true; button_supertypeTest.IsEnabled = true; button_ExportInfoPair.IsEnabled = true; } else { button_subtypeTest.IsEnabled = false; button_supertypeTest.IsEnabled = false; button_ExportInfoPair.IsEnabled = false; } if (logF != null) { logF.Close(); } }