Beispiel #1
0
        public static IFCEntityType GetValidIFCEntityType(string entityType)
        {
            IFCEntityType ret = IFCEntityType.UnKnown;

            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.");
            }

            IfcSchemaEntityNode node = IfcSchemaEntityTree.Find(entityType);

            if (node != null && !node.isAbstract)
            {
                IFCEntityType ifcType = IFCEntityType.UnKnown;
                // Only IfcProduct or IfcTypeProduct can be assigned for export type
                if (!node.IsSubTypeOf("IfcProduct") && !node.IsSubTypeOf("IfcTypeProduct"))
                {
                    ret = ifcType;
                }
                else
                if (IFCEntityType.TryParse(entityType, out ifcType))
                {
                    ret = ifcType;
                }
            }

            return(ret);
        }
        void InitializePreDefinedTypeSelection(string ifcSchema, string ifcEntitySelected)
        {
            if (string.IsNullOrEmpty(ifcEntitySelected))
            {
                return;
            }

            InitializeComponent();
            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;
                m_TreeView.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);
                }
            }
            TreeView_PredefinedType.ItemsSource = m_TreeView.Items;
        }
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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);
        }
        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();
            }
        }
Beispiel #7
0
        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>
        /// 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)
        {
            IFCVersion          ifcVersion = ExporterCacheManager.ExportOptionsCache.FileVersion;
            IfcSchemaEntityTree theTree    = IfcSchemaEntityTree.GetEntityDictFor(ifcVersion);
            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 = theTree.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(ifcVersion, 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(ifcVersion, 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(ifcVersion, 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(ifcVersion, entityTypeStr, "IfcProduct", "IfcGroup");
                    foreach (IfcSchemaEntityNode instNode in instNodes)
                    {
                        typeName = instNode.Name + "Type";
                        IfcSchemaEntityNode node = theTree.Find(typeName);
                        if (node == null)
                        {
                            node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(ifcVersion, typeName);
                        }

                        if (node != null && !node.isAbstract)
                        {
                            instType = IFCEntityType.UnKnown;
                            if (IFCEntityType.TryParse(node.Name, true, out instType))
                            {
                                m_ExportType = instType;
                                break;
                            }
                        }
                    }
                }
            }

            ValidatedPredefinedType = predefineType;
        }