IfcDoc.Program.ExportPsd C# (CSharp) Method

ExportPsd() public static method

public static ExportPsd ( DocPropertySet docPset, DocPropertyEnumeration>.Dictionary mapEnum ) : IfcDoc.Schema.PSD.PropertySetDef
docPset DocPropertySet
mapEnum DocPropertyEnumeration>.Dictionary
return IfcDoc.Schema.PSD.PropertySetDef
        public static PropertySetDef ExportPsd(DocPropertySet docPset, Dictionary<string, DocPropertyEnumeration> mapEnum)
        {
            string[] apptypes = new string[0];

            if (docPset.ApplicableType != null)
            {
                apptypes = docPset.ApplicableType.Split(',');
            }

            // convert to psd schema
            PropertySetDef psd = new PropertySetDef();
            psd.Versions = new List<IfcVersion>();
            psd.Versions.Add(new IfcVersion());
            psd.Versions[0].version = "IFC4";
            psd.Name = docPset.Name;
            psd.Definition = docPset.Documentation;
            psd.TemplateType = docPset.PropertySetType;
            psd.ApplicableTypeValue = docPset.ApplicableType;
            psd.ApplicableClasses = new List<ClassName>();
            foreach (string app in apptypes)
            {
                ClassName cln = new ClassName();
                cln.Value = app;
                psd.ApplicableClasses.Add(cln);
            }
            psd.IfdGuid = docPset.Uuid.ToString("N");

            psd.PsetDefinitionAliases = new List<PsetDefinitionAlias>();
            foreach (DocLocalization docLocal in docPset.Localization)
            {
                PsetDefinitionAlias alias = new PsetDefinitionAlias();
                psd.PsetDefinitionAliases.Add(alias);
                alias.lang = docLocal.Locale;
                alias.Value = docLocal.Documentation;
            }

            psd.PropertyDefs = new List<PropertyDef>();
            foreach (DocProperty docProp in docPset.Properties)
            {
                PropertyDef prop = new PropertyDef();
                psd.PropertyDefs.Add(prop);
                ExportPsdProperty(docProp, prop, mapEnum);
            }

            return psd;
        }

Usage Example

Exemplo n.º 1
0
        public void Save()
        {
            // build map of enumerations
            Dictionary <string, DocPropertyEnumeration> mapPropEnum = new Dictionary <string, DocPropertyEnumeration>();

            foreach (DocPropertyEnumeration docEnum in this.m_project.PropertyEnumerations)
            {
                if (!mapPropEnum.ContainsKey(docEnum.Name))
                {
                    mapPropEnum.Add(docEnum.Name, docEnum);
                }
            }

            using (Package zip = ZipPackage.Open(this.m_stream, FileMode.Create))
            {
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        if (this.m_type == null || this.m_type == typeof(DocPropertySet))
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                if (m_included == null || this.m_included.ContainsKey(docPset))
                                {
                                    if (docPset.IsVisible())
                                    {
                                        Uri         uri  = PackUriHelper.CreatePartUri(new Uri(docPset.Name + ".xml", UriKind.Relative));
                                        PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);
                                        using (Stream refstream = part.GetStream())
                                        {
                                            refstream.SetLength(0);
                                            PropertySetDef psd = Program.ExportPsd(docPset, mapPropEnum, this.m_project);
                                            using (FormatXML format = new FormatXML(refstream, typeof(PropertySetDef), PropertySetDef.DefaultNamespace, null))
                                            {
                                                format.Instance = psd;
                                                format.Save();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (this.m_type == null || this.m_type == typeof(DocQuantitySet))
                        {
                            foreach (DocQuantitySet docQset in docSchema.QuantitySets)
                            {
                                if (m_included == null || this.m_included.ContainsKey(docQset))
                                {
                                    Uri         uri  = PackUriHelper.CreatePartUri(new Uri(docQset.Name + ".xml", UriKind.Relative));
                                    PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);
                                    using (Stream refstream = part.GetStream())
                                    {
                                        refstream.SetLength(0);
                                        QtoSetDef psd = Program.ExportQto(docQset, this.m_project);
                                        using (FormatXML format = new FormatXML(refstream, typeof(QtoSetDef), PropertySetDef.DefaultNamespace, null))
                                        {
                                            format.Instance = psd;
                                            format.Save();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }