Пример #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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// This method is a recursive method that checks the current node properties
        /// and collects
        /// </summary>
        /// <param name="childNode"></param>
        /// <param name="ifcSchemaVersion"></param>
        /// <param name="currentNodeName"></param>
        /// <returns></returns>
        private List <ObjectHierarchy> CollectObjectHierarchies(IfcSchemaEntityNode childNode, string ifcSchemaVersion, string currentNodeName)
        {
            List <ObjectHierarchy> objectHierarchies = new List <ObjectHierarchy>();

            //check if current child node has a child
            IList <IfcSchemaEntityNode> descendantNodes = childNode.GetChildren();

            if (descendantNodes.Count == 0)
            {
                int level = 0;
                //add the current child node into the list
                objectHierarchies.Add(new ObjectHierarchy(ifcSchemaVersion, childNode.Name, childNode.Name,
                                                          childNode.isAbstract, level));

                IfcSchemaEntityNode parentNode = childNode.GetParent();

                //add every current child node parent's parent node into the list
                while (parentNode != null)
                {
                    level++;
                    //stops the loop when the current node and child node's parent are the same
                    if (currentNodeName != parentNode.Name)
                    {
                        objectHierarchies.Add(new ObjectHierarchy(ifcSchemaVersion, parentNode.Name, childNode.Name,
                                                                  parentNode.isAbstract, level));
                    }
                    else
                    {
                        objectHierarchies.Add(new ObjectHierarchy(ifcSchemaVersion, parentNode.Name, childNode.Name,
                                                                  parentNode.isAbstract, level));
                        break;
                    }
                    parentNode = parentNode.GetParent();
                }
            }

            foreach (var descendantNode in descendantNodes)
            {
                objectHierarchies.AddRange(CollectObjectHierarchies(descendantNode, ifcSchemaVersion, currentNodeName));
            }
            return(objectHierarchies);
        }
Пример #4
0
        /// <summary>
        /// This method generates object hierarchy based on the ifcshema
        /// </summary>
        /// <param name="ifcSchemaFile"></param>
        /// <returns>List of object hierarchies</returns>
        public List <ObjectHierarchy> GenerateObjectHierarchy(string ifcSchemaFile)
        {
            if (string.IsNullOrEmpty(ifcSchemaFile))
            {
                return(new List <ObjectHierarchy>());
            }

            FileInfo schemaFileInfo = new FileInfo(ifcSchemaFile);
            bool     newLoad        = ProcessIFCXMLSchema.ProcessIFCSchema(schemaFileInfo);

            if (newLoad)
            {
                string ifcVersion = Path.GetFileNameWithoutExtension(schemaFileInfo.Name);
                List <ObjectHierarchy> objectHierarchies = new List <ObjectHierarchy>();
                foreach (var entityDict in IfcSchemaEntityTree.EntityDict)
                {
                    IfcSchemaEntityNode parentEntityNode = entityDict.Value;

                    if (parentEntityNode.Name.Contains("IfcProduct") || parentEntityNode.Name.Contains("IfcTypeProduct") || parentEntityNode.Name.Contains("IfcGroup"))
                    {
                        //check if current has a child
                        IList <IfcSchemaEntityNode> childNodes = parentEntityNode.GetChildren();
                        if (childNodes.Count == 0)
                        {
                            objectHierarchies.Add(new ObjectHierarchy(ifcVersion, parentEntityNode.Name, parentEntityNode.Name,
                                                                      parentEntityNode.isAbstract, 0));
                            continue;
                        }

                        foreach (IfcSchemaEntityNode childNode in childNodes)
                        {
                            List <ObjectHierarchy> hierarchies = CollectObjectHierarchies(childNode, ifcVersion, parentEntityNode.Name);
                            objectHierarchies.AddRange(hierarchies);
                        }
                    }
                }
                return(objectHierarchies);
            }
            return(new List <ObjectHierarchy>());
        }
Пример #5
0
        /// <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;
        }
Пример #6
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);
        }
Пример #7
0
        /// <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;
                        }
                    }
                }
            }
        }
Пример #8
0
        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);
        }