Exemple #1
0
        private void button_subtypeTest_Click(object sender, RoutedEventArgs e)
        {
            if (listBox_schemaList.SelectedItems.Count == 0 || listBox_schemaList.SelectedItems.Count > 1)
            {
                return;
            }

            DirectoryInfo dInfo      = new DirectoryInfo(textBox_folderLocation.Text);
            FileInfo      f          = dInfo.GetFiles(listBox_schemaList.SelectedItem.ToString()).First();
            string        schemaName = f.Name.Replace(".xsd", "");

            if (string.IsNullOrEmpty(textBox_type1.Text) || string.IsNullOrEmpty(textBox_type2.Text))
            {
                return;
            }

            bool res = IfcSchemaEntityTree.IsSubTypeOf(schemaName, textBox_type1.Text, textBox_type2.Text);

            if (res)
            {
                checkBox_testResult.IsChecked = true;
            }
            else
            {
                checkBox_testResult.IsChecked = false;
            }
        }
        /// <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);
        }
        private void button_subtypeTest_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_type1.Text) || string.IsNullOrEmpty(textBox_type2.Text))
            {
                return;
            }

            bool res = IfcSchemaEntityTree.IsSubTypeOf(textBox_type1.Text, textBox_type2.Text);

            if (res)
            {
                checkBox_testResult.IsChecked = true;
            }
            else
            {
                checkBox_testResult.IsChecked = false;
            }
        }
Exemple #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);
        }
 /// <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>
 /// 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 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));
 }
Exemple #8
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);
        }
Exemple #9
0
        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();

            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);

                // Add creation of Json file for FORNAX universal template
                string schemaName = f.Name.Replace(".xsd", "");
                IDictionary <string, IfcSchemaEntityNode> entDict = IfcSchemaEntityTree.GetEntityDictFor(schemaName);
                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> >();
                schemaEntities.PsetDefList.Add(DefineFXProperties());
                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
                                        });
                                    }
                                }
                            }
                        }
                    }
                }


#if FORNAX_EXTENSION
                foreach (IfcPropertySetTemplate pset in LoadUserDefinedPset())
                {
                    IFCPropertySetDef psetDef = new IFCPropertySetDef();
                    psetDef.PsetName = pset.Name;
                    IList <string> props = new List <string>();
                    foreach (KeyValuePair <string, GeometryGym.Ifc.IfcPropertyTemplate> property in pset.HasPropertyTemplates)
                    {
                        props.Add(property.Key);
                    }
                    psetDef.Properties = props;
                    schemaEntities.PsetDefList.Add(psetDef);

                    if (entPsetDict.ContainsKey(pset.ApplicableEntity))
                    {
                        entPsetDict[pset.ApplicableEntity].Add(pset.Name);
                    }
                    else
                    {
                        entPsetDict.Add(pset.ApplicableEntity, new HashSet <string>()
                        {
                            pset.Name
                        });
                    }

                    // The Pset will be valid for both the Instance and the Type. Check for that here and add if found
                    string entOrTypePair;
                    if (pset.ApplicableEntity.Length > 4 && pset.ApplicableEntity.EndsWith("Type"))
                    {
                        entOrTypePair = pset.ApplicableEntity.Substring(0, pset.ApplicableEntity.Length - 4);
                    }
                    else
                    {
                        entOrTypePair = pset.ApplicableEntity + "Type";
                    }

                    if (aggregateEntities.Contains(entOrTypePair))
                    {
                        if (entPsetDict.ContainsKey(entOrTypePair))
                        {
                            entPsetDict[entOrTypePair].Add(pset.Name);
                        }
                        else
                        {
                            entPsetDict.Add(entOrTypePair, new HashSet <string>()
                            {
                                pset.Name
                            });
                        }
                    }
                }
#endif

                // 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;
                    if (!IfcSchemaEntityTree.IsSubTypeOf(ent.Value.Name, "IfcProduct") &&
                        !IfcSchemaEntityTree.IsSubTypeOf(ent.Value.Name, "IfcTypeProduct") &&
                        !IfcSchemaEntityTree.IsSubTypeOf(ent.Value.Name, "IfcGroup", strict: false))
                    {
                        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();
                    }
#if FORNAX_EXTENSION
                    // Add FORNAX special property sets IFCATTRIBUTES
                    if (entInfo.PropertySets == null)
                    {
                        entInfo.PropertySets = new List <string>()
                        {
                            "IFCATTRIBUTES"
                        }
                    }
                    ;
                    else
                    {
                        entInfo.PropertySets.Add("IFCATTRIBUTES");
                    }
                    // TODO: Add the pset definition of IFCATTRIBUTES to ... (probably has to be dne earlier)
#endif

                    // Collect Pset that is applicable to the supertype of this entity
                    IList <IfcSchemaEntityNode> supertypeList = IfcSchemaEntityTree.FindAllSuperTypes(entInfo.Entity,
                                                                                                      "IfcProduct", "IfcTypeProduct", "IfcObject");
                    if (supertypeList != null && supertypeList.Count > 0)
                    {
                        foreach (IfcSchemaEntityNode superType in supertypeList)
                        {
                            if (entPsetDict.ContainsKey(superType.Name))
                            {
                                if (entInfo.PropertySets == null)
#if FORNAX_EXTENSION
                                { entInfo.PropertySets = new List <string>()
                                  {
                                      "IFCATTRIBUTES"
                                  } };
#else
                                { entInfo.PropertySets = new List <string>(); }
#endif
                                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;"
                             + "\nusing System.Collections.Generic;"
                             + "\nusing System.Linq;"
                             + "\nusing System.Text;"
                             + "\n"
                             + "\nnamespace Revit.IFC.Common.Enums"
                             + "\n{"
                             + "\n\t/// <summary>"
                             + "\n\t/// IFC entity types. Combining IFC2x3 and IFC4 (Add2) entities."
                             + "\n\t/// List of Entities for IFC2x is found in IFC2xEntityType.cs"
                             + "\n\t/// List of Entities for IFC4 is found in IFC4EntityType.cs"
                             + "\n\t/// </summary>"
                             + "\n\tpublic enum IFCEntityType"
                             + "\n\t{";

                foreach (string ent in aggregateEntities)
                {
                    entityList += "\n\t\t/// <summary>"
                                  + "\n\t\t/// IFC Entity " + ent + " enumeration"
                                  + "\n\t\t/// </summary>"
                                  + "\n\t\t" + ent + ",\n";
                }
                entityList += "\n\t\tUnknown,"
                              + "\n\t\tDontExport"
                              + "\n\t}"
                              + "\n}";
                System.IO.File.WriteAllText(outputFolder + @"\IFCEntityType.cs", entityList);
            }

            foreach (IFCEntityAndPsetList fxEntityNPset in fxEntityNPsetList)
            {
                string entityList;
                entityList = "using System;"
                             + "\nusing System.Collections.Generic;"
                             + "\nusing System.Linq;"
                             + "\nusing System.Text;"
                             + "\n"
                             + "\nnamespace Revit.IFC.Common.Enums." + fxEntityNPset.Version
                             + "\n{"
                             + "\n\t/// <summary>"
                             + "\n\t/// List of Entities for " + fxEntityNPset.Version
                             + "\n\t/// </summary>"
                             + "\n\tpublic enum EntityType"
                             + "\n\t{";

                foreach (IFCEntityInfo entInfo in fxEntityNPset.EntityList)
                {
                    entityList += "\n\t\t/// <summary>"
                                  + "\n\t\t/// IFC Entity " + entInfo.Entity + " enumeration"
                                  + "\n\t\t/// </summary>"
                                  + "\n\t\t" + entInfo.Entity + ",\n";
                }
                entityList += "\n\t\tUnknown,"
                              + "\n\t\tDontExport"
                              + "\n\t}"
                              + "\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;
            }
            else
            {
                button_subtypeTest.IsEnabled   = false;
                button_supertypeTest.IsEnabled = false;
            }

            if (logF != null)
            {
                logF.Close();
            }
        }