/// <summary>
        /// Process an IFCXML schema file
        /// </summary>
        /// <param name="ifcxmlSchemaFile">the IfcXML schema file info</param>
        public static bool ProcessIFCSchema(FileInfo ifcxmlSchemaFile)
        {
            if (ifcxmlSchemaFile.Name.Equals(loadedSchema) && IfcSchemaEntityTree.EntityDict.Count > 0)
            {
                return(false); // The schema file has been processed and loaded before
            }
            loadedSchema = ifcxmlSchemaFile.Name;
            IfcSchemaEntityTree.Initialize(loadedSchema);
            XmlTextReader reader    = new XmlTextReader(ifcxmlSchemaFile.FullName);
            XmlSchema     theSchema = XmlSchema.Read(reader, ValidationCallback);

            foreach (XmlSchemaObject item in theSchema.Items)
            {
                if (!(item is XmlSchemaComplexType))
                {
                    continue;
                }

                XmlSchemaComplexType ct = item as XmlSchemaComplexType;
                string entityName       = ct.Name;

                if (string.Compare(entityName, 0, "Ifc", 0, 3, ignoreCase: true) != 0)
                {
                    continue;
                }

                string parentName = string.Empty;

                if (ct.ContentModel == null)
                {
                    continue;
                }

                if (ct.ContentModel.Parent == null)
                {
                    continue;
                }

                if (ct.ContentModel.Parent is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType             parent            = ct.ContentModel.Parent as XmlSchemaComplexType;
                    XmlSchemaSimpleContentExtension  parentSimpleType  = parent.ContentModel.Content as XmlSchemaSimpleContentExtension;
                    XmlSchemaComplexContentExtension parentComplexType = parent.ContentModel.Content as XmlSchemaComplexContentExtension;
                    if (parentSimpleType != null)
                    {
                        parentName = parentSimpleType.BaseTypeName.Name;
                    }
                    if (parentComplexType != null)
                    {
                        parentName = parentComplexType.BaseTypeName.Name;
                    }
                }

                IfcSchemaEntityTree.Add(entityName, parentName, isAbstract: ct.IsAbstract);
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Find a Non ABS supertype entity from the input type name
        /// </summary>
        /// <param name="context">the IFC schema context</param>
        /// <param name="typeName">the type name</param>
        /// <returns>the non-abs supertype instance node</returns>
        static public IfcSchemaEntityNode FindNonAbsInstanceSuperType(string context, string typeName)
        {
            IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context);
            IfcSchemaEntityNode res = null;

            // Note: Implementer's agreement #CV-2x3-166 changes IfcSpaceHeaterType from IfcEnergyConversionDevice to IfcFlowTerminal.
            if (context.Equals(Ifc2x3Schema, StringComparison.InvariantCultureIgnoreCase) &&
                typeName.Equals("IfcSpaceHeaterType", StringComparison.InvariantCultureIgnoreCase))
            {
                res = ifcEntitySchemaTree.Find("IfcFlowTerminal");
                if (res.isAbstract)
                {
                    return(null);
                }
                return(res);
            }

            string theTypeName          = typeName.Substring(typeName.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase) ? typeName : typeName + "Type";
            IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(theTypeName);

            if (entNode != null)
            {
                while (true)
                {
                    res = entNode.GetParent();
                    // no more parent node to get
                    if (res == null)
                    {
                        break;
                    }

                    entNode = ifcEntitySchemaTree.Find(res.Name.Substring(0, res.Name.Length - 4));
                    if (entNode != null && !entNode.isAbstract)
                    {
                        res = entNode;
                        break;
                    }
                    else
                    {
                        entNode = res; // put back the Type Node
                    }
                }
            }

            return(res);
        }
Beispiel #3
0
        static public IList <IfcSchemaEntityNode> FindAllSuperTypes(string context, string entityName, params string[] stopNode)
        {
            IfcSchemaEntityTree         ifcEntitySchemaTree = GetEntityDictFor(context);
            IList <IfcSchemaEntityNode> res = new List <IfcSchemaEntityNode>();

            IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(entityName);

            if (entNode != null)
            {
                // return the list when it reaches the stop node
                foreach (string stopCond in stopNode)
                {
                    if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(res);
                    }
                }

                bool continueSearch = true;
                while (continueSearch)
                {
                    entNode = entNode.GetParent();
                    // no more parent node to get
                    if (entNode == null)
                    {
                        break;
                    }

                    // Stop the search when it reaches the stop node
                    foreach (string stopCond in stopNode)
                    {
                        if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continueSearch = false;
                            break;
                        }
                    }
                    if (entNode != null)
                    {
                        res.Add(entNode);
                    }
                }
            }
            return(res);
        }
Beispiel #4
0
        /// <summary>
        /// Find a Non-Abstract Super Type in the current IFC Schema
        /// </summary>
        /// <param name="context">the IFC schema context</param>
        /// <param name="typeName">the entity name</param>
        /// <param name="stopNode">optional list of entity name(s) to stop the search</param>
        /// <returns>the appropriate node or null</returns>
        static public IfcSchemaEntityNode FindNonAbsSuperType(string context, string entityName, params string[] stopNode)
        {
            IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context);
            IfcSchemaEntityNode res = null;

            IfcSchemaEntityNode entNode = ifcEntitySchemaTree.Find(entityName);

            if (entNode != null)
            {
                foreach (string stopCond in stopNode)
                {
                    if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(res);
                    }
                }

                while (true)
                {
                    entNode = entNode.GetParent();
                    // no more parent node to get
                    if (entNode == null)
                    {
                        break;
                    }

                    foreach (string stopCond in stopNode)
                    {
                        if (entNode.Name.Equals(stopCond, StringComparison.InvariantCultureIgnoreCase))
                        {
                            break;
                        }
                    }

                    if (entNode != null && !entNode.isAbstract)
                    {
                        res = entNode;
                        break;
                    }
                }
            }
            return(res);
        }
Beispiel #5
0
        /// <summary>
        /// Get the IFC Entity Dictionary for the given IFC version specified by the schema file name (without extension)
        /// </summary>
        /// <param name="schemaFile">the IFC schema file name (without extension). Caller must make sure it is the supported schema file</param>
        /// <returns>the tree, or null if the schema file is not found</returns>
        static public IfcSchemaEntityTree GetEntityDictFor(string schemaFile)
        {
            if (m_IFCSchemaDict.ContainsKey(schemaFile))
            {
                return(m_IFCSchemaDict[schemaFile]);
            }

            // if not found, process the file and add into the static dictionary
            IfcSchemaEntityTree entityTree = PopulateEntityDictFor(schemaFile);

            if (entityTree == null)
            {
                return(null);
            }

            m_IFCSchemaDict.Add(schemaFile, entityTree);
            m_IFCEntityPredefTypeDict.Add(schemaFile, entityTree.PredefinedTypeEnumDict);
            return(entityTree);
        }
Beispiel #6
0
        /// <summary>
        /// Get the PredefinedType list from the given Ifc Entity tree
        /// </summary>
        /// <param name="context">The IFC version</param>
        /// <param name="ifcEntity">the specific Entity to get the PredefinedType list from</param>
        /// <returns>List of PredefinedType strings</returns>
        static public IList <string> GetPredefinedTypeList(IfcSchemaEntityTree ifcEntitySchemaTree, string ifcEntity)
        {
            IList <string> predefinedtypeList = new List <string>();

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

            if (string.IsNullOrEmpty(ifcEntity))
            {
                return(null);
            }

            // Check for both <name>Enum, and <name>TypeEnum
            string entEnum;
            string entTypeEnum;

            if (ifcEntity.EndsWith("Type", StringComparison.InvariantCultureIgnoreCase))
            {
                entTypeEnum = ifcEntity + "Enum";
                entEnum     = ifcEntity.Remove(ifcEntity.Length - 4) + "Enum";
            }
            else
            {
                entEnum     = ifcEntity + "Enum";
                entTypeEnum = ifcEntity + "TypeEnum";
            }
            if (ifcEntitySchemaTree.PredefinedTypeEnumDict.ContainsKey(entEnum))
            {
                return(ifcEntitySchemaTree.PredefinedTypeEnumDict[entEnum]);
            }
            if (ifcEntitySchemaTree.PredefinedTypeEnumDict.ContainsKey(entTypeEnum))
            {
                return(ifcEntitySchemaTree.PredefinedTypeEnumDict[entTypeEnum]);
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Get the PredefinedType list from the processed schema
        /// </summary>
        /// <param name="context"></param>
        /// <param name="ifcEntity"></param>
        /// <returns></returns>
        static public IList <string> GetPredefinedTypeList(IFCVersion context, string ifcEntity)
        {
            IfcSchemaEntityTree ifcEntitySchemaTree = GetEntityDictFor(context);

            return(GetPredefinedTypeList(ifcEntitySchemaTree, ifcEntity));
        }
Beispiel #8
0
        /// <summary>
        /// Process an IFCXML schema file
        /// </summary>
        /// <param name="ifcxmlSchemaFile">the IfcXML schema file info</param>
        public static bool ProcessIFCSchema(FileInfo ifcxmlSchemaFile)
        {
            if (ifcxmlSchemaFile.Name.Equals(loadedSchema) && IfcSchemaEntityTree.EntityDict.Count > 0)
            {
                return(false); // The schema file has been processed and loaded before
            }
            loadedSchema = Path.GetFileNameWithoutExtension(ifcxmlSchemaFile.Name);
            IfcSchemaEntityTree.Initialize(loadedSchema);
            XmlTextReader reader    = new XmlTextReader(ifcxmlSchemaFile.FullName);
            XmlSchema     theSchema = XmlSchema.Read(reader, ValidationCallback);

            foreach (XmlSchemaObject item in theSchema.Items)
            {
                if (item is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ct = item as XmlSchemaComplexType;
                    string entityName       = ct.Name;

                    if (string.Compare(entityName, 0, "Ifc", 0, 3, ignoreCase: true) != 0)
                    {
                        continue;
                    }

                    string parentName = string.Empty;

                    if (ct.ContentModel == null)
                    {
                        continue;
                    }

                    if (ct.ContentModel.Parent == null)
                    {
                        continue;
                    }

                    string predefTypeEnum = null;
                    if (ct.ContentModel.Parent is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType             parent            = ct.ContentModel.Parent as XmlSchemaComplexType;
                        XmlSchemaSimpleContentExtension  parentSimpleType  = parent.ContentModel.Content as XmlSchemaSimpleContentExtension;
                        XmlSchemaComplexContentExtension parentComplexType = parent.ContentModel.Content as XmlSchemaComplexContentExtension;
                        if (parentSimpleType != null)
                        {
                            parentName = parentSimpleType.BaseTypeName.Name;
                            foreach (XmlSchemaAttribute attr in parentSimpleType.Attributes)
                            {
                                if (attr.Name != null && attr.Name.Equals("PredefinedType", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    predefTypeEnum = attr.SchemaTypeName.Name;
                                }
                            }
                        }
                        if (parentComplexType != null)
                        {
                            parentName = parentComplexType.BaseTypeName.Name;
                            foreach (XmlSchemaAttribute attr in parentComplexType.Attributes)
                            {
                                if (attr.Name != null && attr.Name.Equals("PredefinedType", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    predefTypeEnum = attr.SchemaTypeName.Name;
                                    break;
                                }
                            }

                            if (string.IsNullOrEmpty(predefTypeEnum) && parentComplexType.Particle != null)
                            {
                                XmlSchemaSequence seq = parentComplexType.Particle as XmlSchemaSequence;
                                if (seq != null)
                                {
                                    foreach (XmlSchemaElement elem in seq.Items)
                                    {
                                        if (elem.Name != null && elem.Name.Equals("PredefinedType", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            predefTypeEnum = elem.SchemaTypeName.Name;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    IfcSchemaEntityTree.Add(entityName, parentName, predefTypeEnum, isAbstract: ct.IsAbstract);
                }
                else if (item is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType st = item as XmlSchemaSimpleType;
                    if (st.Name.StartsWith("Ifc", StringComparison.InvariantCultureIgnoreCase) &&
                        st.Name.EndsWith("Enum", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string enumName = st.Name;
                        XmlSchemaSimpleTypeRestriction enums = st.Content as XmlSchemaSimpleTypeRestriction;
                        if (enums != null)
                        {
                            IList <string> enumValueList = new List <string>();
                            foreach (XmlSchemaEnumerationFacet enumFacet in enums.Facets)
                            {
                                if (IfcSchemaEntityTree.PredefinedTypeEnumDict.ContainsKey(enumName))
                                {
                                    IfcSchemaEntityTree.PredefinedTypeEnumDict[enumName].Add(enumFacet.Value.ToUpper());
                                }
                                else
                                {
                                    enumValueList.Add(enumFacet.Value.ToUpper());
                                }
                            }
                            if (enumValueList.Count > 0)
                            {
                                IfcSchemaEntityTree.PredefinedTypeEnumDict.Add(enumName, enumValueList);
                            }
                        }
                    }
                }
            }
            return(true);
        }