Пример #1
0
        public static void ImportPsdPropertyTemplate(PropertyDef def, DocProperty docprop)
        {
            DocPropertyTemplateTypeEnum proptype = DocPropertyTemplateTypeEnum.P_SINGLEVALUE;
            string datatype = String.Empty;
            string elemtype = String.Empty;

            if (def.PropertyType.TypePropertyEnumeratedValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE;
                datatype = "IfcLabel";
                StringBuilder sbEnum = new StringBuilder();
                sbEnum.Append(def.PropertyType.TypePropertyEnumeratedValue.EnumList.name);
                sbEnum.Append(":");
                foreach (EnumItem item in def.PropertyType.TypePropertyEnumeratedValue.EnumList.Items)
                {
                    sbEnum.Append(item.Value);
                    sbEnum.Append(",");
                }
                sbEnum.Length--; // remove trailing ','
                elemtype = sbEnum.ToString();
            }
            else if (def.PropertyType.TypePropertyReferenceValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_REFERENCEVALUE;
                datatype = def.PropertyType.TypePropertyReferenceValue.reftype;
                if (def.PropertyType.TypePropertyReferenceValue.DataType != null)
                {
                    elemtype = def.PropertyType.TypePropertyReferenceValue.DataType.type; // e.g. IfcTimeSeries
                }
            }
            else if (def.PropertyType.TypePropertyBoundedValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE;
                datatype = def.PropertyType.TypePropertyBoundedValue.DataType.type;
            }
            else if (def.PropertyType.TypePropertyListValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_LISTVALUE;
                datatype = def.PropertyType.TypePropertyListValue.ListValue.DataType.type;
            }
            else if (def.PropertyType.TypePropertyTableValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_TABLEVALUE;
                datatype = def.PropertyType.TypePropertyTableValue.DefiningValue.DataType.type;
                elemtype = def.PropertyType.TypePropertyTableValue.DefinedValue.DataType.type;
            }
            else if (def.PropertyType.TypePropertySingleValue != null)
            {
                proptype = DocPropertyTemplateTypeEnum.P_SINGLEVALUE;
                datatype = def.PropertyType.TypePropertySingleValue.DataType.type;
            }
            else if (def.PropertyType.TypeComplexProperty != null)
            {
                proptype = DocPropertyTemplateTypeEnum.COMPLEX;
                datatype = def.PropertyType.TypeComplexProperty.name;
            }

            if (!String.IsNullOrEmpty(def.IfdGuid))
            {
                try
                {
                    docprop.Uuid = new Guid(def.IfdGuid);
                }
                catch
                {
                }
            }

            docprop.Name = def.Name;
            if (def.Definition != null)
            {
                docprop.Documentation = def.Definition.Trim();
            }
            docprop.PropertyType = proptype;
            docprop.PrimaryDataType = datatype;
            docprop.SecondaryDataType = elemtype.Trim();

            foreach (NameAlias namealias in def.NameAliases)
            {
                string localdesc = null;
                foreach (DefinitionAlias docalias in def.DefinitionAliases)
                {
                    if (docalias.lang.Equals(namealias.lang))
                    {
                        localdesc = docalias.Value;
                    }
                }

                docprop.RegisterLocalization(namealias.lang, namealias.Value, localdesc);
            }

            // recurse for complex properties
            if (def.PropertyType.TypeComplexProperty != null)
            {
                foreach (PropertyDef subdef in def.PropertyType.TypeComplexProperty.PropertyDefs)
                {
                    DocProperty subprop = docprop.RegisterProperty(subdef.Name);
                    ImportPsdPropertyTemplate(subdef, subprop);
                }
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
        private static void ExportPsdProperty(DocProperty docProp, PropertyDef prop, Dictionary<string, DocPropertyEnumeration> mapPropEnum)
        {
            prop.IfdGuid = docProp.Uuid.ToString("N");
            prop.Name = docProp.Name;
            prop.Definition = docProp.Documentation;

            prop.NameAliases = new List<NameAlias>();
            prop.DefinitionAliases = new List<DefinitionAlias>();
            foreach (DocLocalization docLocal in docProp.Localization)
            {
                NameAlias na = new NameAlias();
                prop.NameAliases.Add(na);
                na.lang = docLocal.Locale;
                na.Value = docLocal.Name;

                DefinitionAlias da = new DefinitionAlias();
                prop.DefinitionAliases.Add(da);
                da.lang = docLocal.Locale;
                da.Value = docLocal.Documentation;
            }

            prop.PropertyType = new PropertyType();
            switch (docProp.PropertyType)
            {
                case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                    prop.PropertyType.TypePropertySingleValue = new TypePropertySingleValue();
                    prop.PropertyType.TypePropertySingleValue.DataType = new DataType();
                    prop.PropertyType.TypePropertySingleValue.DataType.type = docProp.PrimaryDataType;
                    break;

                case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                    prop.PropertyType.TypePropertyBoundedValue = new TypePropertyBoundedValue();
                    prop.PropertyType.TypePropertyBoundedValue.DataType = new DataType();
                    prop.PropertyType.TypePropertyBoundedValue.DataType.type = docProp.PrimaryDataType;
                    break;

                case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                    prop.PropertyType.TypePropertyEnumeratedValue = new TypePropertyEnumeratedValue();
                    prop.PropertyType.TypePropertyEnumeratedValue.EnumList = new EnumList();
                    {
                        if (docProp.SecondaryDataType != null)
                        {
                            string[] parts = docProp.SecondaryDataType.Split(':');
                            if (parts.Length == 2)
                            {
                                string[] enums = parts[1].Split(',');
                                prop.PropertyType.TypePropertyEnumeratedValue.EnumList.name = parts[0];
                                prop.PropertyType.TypePropertyEnumeratedValue.EnumList.Items = new List<EnumItem>();
                                foreach (string eachenum in enums)
                                {
                                    EnumItem eni = new EnumItem();
                                    prop.PropertyType.TypePropertyEnumeratedValue.EnumList.Items.Add(eni);
                                    eni.Value = eachenum.Trim();
                                }
                            }

                            string propenum = docProp.SecondaryDataType;
                            if (propenum != null)
                            {
                                int colon = propenum.IndexOf(':');
                                if (colon > 0)
                                {
                                    propenum = propenum.Substring(0, colon);
                                }
                            }
                            DocPropertyEnumeration docPropEnum = null;
                            if (mapPropEnum.TryGetValue(propenum, out docPropEnum))
                            {
                                prop.PropertyType.TypePropertyEnumeratedValue.ConstantList = new ConstantList();
                                prop.PropertyType.TypePropertyEnumeratedValue.ConstantList.Items = new List<ConstantDef>();
                                foreach (DocPropertyConstant docPropConst in docPropEnum.Constants)
                                {
                                    ConstantDef con = new ConstantDef();
                                    prop.PropertyType.TypePropertyEnumeratedValue.ConstantList.Items.Add(con);

                                    con.Name = docPropConst.Name.Trim();
                                    con.Definition = docPropConst.Documentation;
                                    con.NameAliases = new List<NameAlias>();
                                    con.DefinitionAliases = new List<DefinitionAlias>();

                                    foreach (DocLocalization docLocal in docPropConst.Localization)
                                    {
                                        NameAlias na = new NameAlias();
                                        con.NameAliases.Add(na);
                                        na.lang = docLocal.Locale;
                                        na.Value = docLocal.Name.Trim();

                                        DefinitionAlias da = new DefinitionAlias();
                                        con.DefinitionAliases.Add(da);
                                        da.lang = docLocal.Locale;
                                        da.Value = docLocal.Documentation;
                                    }
                                }
                            }
                        }
                    }

                    break;

                case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                    prop.PropertyType.TypePropertyListValue = new TypePropertyListValue();
                    prop.PropertyType.TypePropertyListValue.ListValue = new ListValue();
                    prop.PropertyType.TypePropertyListValue.ListValue.DataType = new DataType();
                    prop.PropertyType.TypePropertyListValue.ListValue.DataType.type = docProp.PrimaryDataType;
                    break;

                case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                    prop.PropertyType.TypePropertyTableValue = new TypePropertyTableValue();
                    prop.PropertyType.TypePropertyTableValue.Expression = String.Empty;
                    prop.PropertyType.TypePropertyTableValue.DefiningValue = new DefiningValue();
                    prop.PropertyType.TypePropertyTableValue.DefiningValue.DataType = new DataType();
                    prop.PropertyType.TypePropertyTableValue.DefiningValue.DataType.type = docProp.PrimaryDataType;
                    prop.PropertyType.TypePropertyTableValue.DefinedValue = new DefinedValue();
                    prop.PropertyType.TypePropertyTableValue.DefinedValue.DataType = new DataType();
                    prop.PropertyType.TypePropertyTableValue.DefinedValue.DataType.type = docProp.SecondaryDataType;
                    break;

                case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                    prop.PropertyType.TypePropertyReferenceValue = new TypePropertyReferenceValue();
                    prop.PropertyType.TypePropertyReferenceValue.reftype = docProp.PrimaryDataType;
                    break;

                case DocPropertyTemplateTypeEnum.COMPLEX:
                    prop.PropertyType.TypeComplexProperty = new TypeComplexProperty();
                    prop.PropertyType.TypeComplexProperty.name = docProp.PrimaryDataType;
                    prop.PropertyType.TypeComplexProperty.PropertyDefs = new List<PropertyDef>();
                    foreach(DocProperty docSub in docProp.Elements)
                    {
                        PropertyDef sub = new PropertyDef();
                        prop.PropertyType.TypeComplexProperty.PropertyDefs.Add(sub);
                        ExportPsdProperty(docSub, sub, mapPropEnum);
                    }
                    break;
            }
        }