IfcDoc.Program.ImportPsdPropertyTemplate C# (CSharp) Method

ImportPsdPropertyTemplate() public static method

public static ImportPsdPropertyTemplate ( IfcDoc.Schema.PSD.PropertyDef def, DocProperty docprop ) : void
def IfcDoc.Schema.PSD.PropertyDef
docprop DocProperty
return void
        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);
                }
            }
        }