예제 #1
0
        internal static void ExportIfc(IfcProject ifcProject, DocProject docProject, Dictionary<DocObject, bool> included)
        {
            ifcProject.Name = "IFC4 Property Set Templates";

            // cache enumerators
            Dictionary<string, DocPropertyEnumeration> mapEnums = new Dictionary<string,DocPropertyEnumeration>();
            foreach (DocSection docSect in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSect.Schemas)
                {
                    foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums)
                    {
                        try
                        {
                            mapEnums.Add(docEnum.Name, docEnum);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            IfcLibraryInformation ifcLibInfo = null;
            #if false // optimization: don't include library info
            IfcLibraryInformation ifcLibInfo = new IfcLibraryInformation();
            ifcLibInfo.Publisher = null; // BuildingSmart...
            ifcLibInfo.Version = "IFC4";
            ifcLibInfo.VersionDate = DateTime.UtcNow;
            ifcLibInfo.Location = "";
            ifcLibInfo.Name = ifcProject.Name;
            IfcRelAssociatesLibrary ifcRelLibProject = new IfcRelAssociatesLibrary();
            ifcRelLibProject.RelatingLibrary = ifcLibInfo;
            ifcRelLibProject.RelatedObjects.Add(ifcProject);
            #endif

            IfcRelDeclares rel = new IfcRelDeclares();
            rel.RelatingContext = ifcProject;

            ifcProject.Declares.Add(rel);

            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocPropertySet docPset in docSchema.PropertySets)
                    {
                        if (included == null || included.ContainsKey(docPset))
                        {

                            IfcPropertySetTemplate ifcPset = new IfcPropertySetTemplate();
                            rel.RelatedDefinitions.Add(ifcPset);
                            ifcPset.GlobalId = SGuid.Format(docPset.Uuid);
                            ifcPset.Name = docPset.Name;
                            ifcPset.Description = docPset.Documentation;

                            switch (docPset.PropertySetType)
                            {
                                case "PSET_TYPEDRIVENOVERRIDE":
                                    ifcPset.PredefinedType = IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENOVERRIDE;
                                    break;

                                case "PSET_OCCURRENCEDRIVEN":
                                    ifcPset.PredefinedType = IfcPropertySetTemplateTypeEnum.PSET_OCCURRENCEDRIVEN;
                                    break;

                                case "PSET_PERFORMANCEDRIVEN":
                                    ifcPset.PredefinedType = IfcPropertySetTemplateTypeEnum.PSET_PERFORMANCEDRIVEN;
                                    break;
                            }

                            ifcPset.ApplicableEntity = docPset.ApplicableType;

                            foreach (DocLocalization docLoc in docPset.Localization)
                            {
                                IfcLibraryReference ifcLib = new IfcLibraryReference();
                                ifcLib.Language = docLoc.Locale;
                                ifcLib.Name = docLoc.Name;
                                ifcLib.Description = docLoc.Documentation;
                                ifcLib.ReferencedLibrary = ifcLibInfo;

                                IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
                                ifcRal.RelatingLibrary = ifcLib;
                                ifcRal.RelatedObjects.Add(ifcPset);

                                ifcPset.HasAssociations.Add(ifcRal);
                            }

                            foreach (DocProperty docProp in docPset.Properties)
                            {
                                IfcPropertyTemplate ifcProp = ExportIfcPropertyTemplate(docProp, ifcLibInfo, mapEnums);
                                ifcPset.HasPropertyTemplates.Add(ifcProp);
                            }
                        }
                    }

                    foreach (DocQuantitySet docQuantitySet in docSchema.QuantitySets)
                    {
                        if (included == null || included.ContainsKey(docQuantitySet))
                        {
                            IfcPropertySetTemplate ifcPset = new IfcPropertySetTemplate();
                            rel.RelatedDefinitions.Add(ifcPset);
                            ifcPset.Name = docQuantitySet.Name;
                            ifcPset.Description = docQuantitySet.Documentation;
                            ifcPset.PredefinedType = IfcPropertySetTemplateTypeEnum.QTO_OCCURRENCEDRIVEN;
                            ifcPset.ApplicableEntity = docQuantitySet.ApplicableType;

                            foreach (DocLocalization docLoc in docQuantitySet.Localization)
                            {
                                IfcLibraryReference ifcLib = new IfcLibraryReference();
                                ifcLib.Language = docLoc.Locale;
                                ifcLib.Name = docLoc.Name;
                                ifcLib.Description = docLoc.Documentation;
                                ifcLib.ReferencedLibrary = ifcLibInfo;

                                IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
                                ifcRal.RelatingLibrary = ifcLib;
                                ifcRal.RelatedObjects.Add(ifcPset);
                            }

                            foreach (DocQuantity docProp in docQuantitySet.Quantities)
                            {
                                IfcSimplePropertyTemplate ifcProp = new IfcSimplePropertyTemplate();
                                ifcPset.HasPropertyTemplates.Add(ifcProp);
                                ifcProp.Name = docProp.Name;
                                ifcProp.Description = docProp.Documentation;
                                ifcProp.TemplateType = (IfcSimplePropertyTemplateTypeEnum)Enum.Parse(typeof(IfcSimplePropertyTemplateTypeEnum), docProp.QuantityType.ToString());

                                foreach (DocLocalization docLoc in docProp.Localization)
                                {
                                    IfcLibraryReference ifcLib = new IfcLibraryReference();
                                    ifcLib.Language = docLoc.Locale;
                                    ifcLib.Name = docLoc.Name;
                                    ifcLib.Description = docLoc.Documentation;
                                    ifcLib.ReferencedLibrary = ifcLibInfo;

                                    IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
                                    ifcRal.RelatingLibrary = ifcLib;
                                    ifcRal.RelatedObjects.Add(ifcProp);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private static IfcPropertyTemplate ExportIfcPropertyTemplate(DocProperty docProp, IfcLibraryInformation ifcLibInfo, Dictionary<string, DocPropertyEnumeration> mapEnums)
        {
            if (docProp.PropertyType == DocPropertyTemplateTypeEnum.COMPLEX)
            {
                IfcComplexPropertyTemplate ifcProp = new IfcComplexPropertyTemplate();
                ifcProp.GlobalId = SGuid.Format(docProp.Uuid);
                ifcProp.Name = docProp.Name;
                ifcProp.Description = docProp.Documentation;
                ifcProp.TemplateType = IfcComplexPropertyTemplateTypeEnum.P_COMPLEX;
                ifcProp.UsageName = docProp.PrimaryDataType;

                foreach (DocProperty docSubProp in docProp.Elements)
                {
                    IfcPropertyTemplate ifcSub = ExportIfcPropertyTemplate(docSubProp, ifcLibInfo, mapEnums);
                    ifcProp.HasPropertyTemplates.Add(ifcSub);
                }

                return ifcProp;
            }
            else
            {
                IfcSimplePropertyTemplate ifcProp = new IfcSimplePropertyTemplate();
                ifcProp.GlobalId = SGuid.Format(docProp.Uuid);
                ifcProp.Name = docProp.Name;
                ifcProp.Description = docProp.Documentation;
                ifcProp.TemplateType = (IfcSimplePropertyTemplateTypeEnum)Enum.Parse(typeof(IfcSimplePropertyTemplateTypeEnum), docProp.PropertyType.ToString());
                ifcProp.PrimaryMeasureType = docProp.PrimaryDataType;
                ifcProp.SecondaryMeasureType = docProp.SecondaryDataType;

                foreach (DocLocalization docLoc in docProp.Localization)
                {
                    IfcLibraryReference ifcLib = new IfcLibraryReference();
                    ifcLib.Language = docLoc.Locale;
                    ifcLib.Name = docLoc.Name;
                    ifcLib.Description = docLoc.Documentation;
                    ifcLib.ReferencedLibrary = ifcLibInfo;

                    IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
                    ifcRal.RelatingLibrary = ifcLib;
                    ifcRal.RelatedObjects.Add(ifcProp);

                    ifcProp.HasAssociations.Add(ifcRal);
                }

                // enumerations
                if (ifcProp.TemplateType == IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE && ifcProp.SecondaryMeasureType != null)
                {
                    // NEW: lookup formal enumeration
                    string propdatatype = ifcProp.SecondaryMeasureType;
                    int colon = propdatatype.IndexOf(':');
                    if(colon > 0)
                    {
                        propdatatype = propdatatype.Substring(0, colon);
                    }

                    DocPropertyEnumeration docEnumeration = null;
                    if(mapEnums.TryGetValue(propdatatype, out docEnumeration))
                    {
                        ifcProp.Enumerators = new IfcPropertyEnumeration();
                        ifcProp.GlobalId = SGuid.Format(docEnumeration.Uuid);
                        ifcProp.Enumerators.Name = docEnumeration.Name;
                        ifcProp.Enumerators.EnumerationValues = new List<IfcValue>();
                        ifcProp.SecondaryMeasureType = null;

                        foreach(DocPropertyConstant docConst in docEnumeration.Constants)
                        {
                            IfcLabel label = new IfcLabel();
                            label.Value = docConst.Name;
                            ifcProp.Enumerators.EnumerationValues.Add(label);

                            foreach (DocLocalization docLoc in docConst.Localization)
                            {
                                IfcLibraryReference ifcLib = new IfcLibraryReference();
                                ifcLib.Identification = docConst.Name; // distinguishes the constant value within the enumeration
                                ifcLib.Language = docLoc.Locale;
                                ifcLib.Name = docLoc.Name;
                                ifcLib.Description = docLoc.Documentation;
                                ifcLib.ReferencedLibrary = ifcLibInfo;

                                if(docLoc.Documentation == null && docLoc.Locale == "en")
                                {
                                    ifcLib.Description = docConst.Documentation;
                                }

                                IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
                                ifcRal.RelatingLibrary = ifcLib;
                                ifcRal.RelatedObjects.Add(ifcProp);

                                ifcProp.HasAssociations.Add(ifcRal);
                            }

                        }
                    }

                }

                return ifcProp;
            }
        }