Example #1
0
 public CustomProperty(object instance, string key, string propertyName, Type type, string displayName, string description, List <Attribute> attributes, CustomPropertyStandardValues standardValues)
     : this(instance, key, propertyName, type, displayName, description, attributes, standardValues, null)
 {
 }
Example #2
0
        public CustomProperty(object instance, string key, string propertyName, Type type, string displayName, string description, List <Attribute> attributeList, CustomPropertyStandardValues standardValues, object[] args)
        {
            DisplayBold  = false;
            Instance     = instance;
            Key          = key;
            Name         = propertyName;
            DisplayName  = displayName;
            TypeName     = type.AssemblyQualifiedName;
            PropertyType = type;
            Category     = "UNKNOWN";
            Description  = description;
            DefaultValue = null;

            IfcPropertyName     = String.Empty;
            IfcPropertyGlobalId = String.Empty;

            ComboboxValues = null;
            if (standardValues != null)
            {
                ComboboxValues = new CustomPropertyStandardValues();
                ComboboxValues.AddRange(standardValues);
            }

            Args = args;

            if (attributeList == null)
            {
                attributeList = new List <Attribute>();
            }

            IEnumerable <Attribute> query = attributeList.Where(e => e is System.ComponentModel.EditorAttribute);

            // Falls kein TypeEditor angemeldet ist
            // den korrekten Typeeditor anmelden

            if (query.Count() == 0)
            {
                // Falls String
                if (type == typeof(System.String))
                {
                    IEnumerable <Attribute> query1 = attributeList.Where(e => e is System.ComponentModel.TypeConverterAttribute || e is System.ComponentModel.EditorAttribute);
                    if (query1.Count() == 0)
                    {
                        // gilt für alle String properties
                        // Standard TextEditor benutzen
                        string editorTypeName = "";
                        attributeList.Add(new System.ComponentModel.EditorAttribute(editorTypeName, typeof(System.Drawing.Design.UITypeEditor)));
                    }
                }

                // falls nicht string
                else
                {
                }
            }
            else
            {
                foreach (System.ComponentModel.EditorAttribute editorAttribute in query)
                {
                    if (editorAttribute.EditorTypeName == "")
                    {
                        CanOnlyEditByExternalDialog = true;
                    }
                }
            }
            // ----------------------------------------------------------------------------
            if (type == typeof(Boolean))
            {
                // wird nur für die Übersetzung benötigt
                if (!(attributeList.Exists(item => item is System.ComponentModel.TypeConverterAttribute)))
                {
                    string typeConverter = "";
                    attributeList.Add(new System.ComponentModel.TypeConverterAttribute(typeConverter));
                }
            }


            // ----------------------------------------------------------------------------
            // TODOJV zur Zeit kein Multiselect
            // MergableAttribute auf false setzen
            // kein MultiSelect erlaubt
            System.ComponentModel.MergablePropertyAttribute mergablePropertyAttribute;
            mergablePropertyAttribute = attributeList.Find(item => item.GetType() == typeof(System.ComponentModel.MergablePropertyAttribute)) as System.ComponentModel.MergablePropertyAttribute;
            bool updateMergableAttribute = false;
            bool allowMerge = false;

            if (mergablePropertyAttribute == null)
            {
                updateMergableAttribute = true;
                allowMerge = false;
            }
            if (updateMergableAttribute)
            {
                attributeList.Add(new System.ComponentModel.MergablePropertyAttribute(allowMerge));
            }
            // ----------------------------------------------------------------------------

            Attributes = attributeList.ToArray();
        }
        private List <CustomModel.CustomPropertyDescriptor> GetRuntimeProperties(Ifc4.BaseObject baseObject)
        {
            CustomModel.CustomPropertyDescriptor        cpd;
            CustomModel.CustomProperty                  customProperty;
            List <CustomModel.CustomPropertyDescriptor> propertyDescriptorCollection = new List <CustomModel.CustomPropertyDescriptor>();

            Ifc4.CcFacility facility = baseObject as Ifc4.CcFacility;
            if (facility == null || String.IsNullOrEmpty(facility.ObjectTypeId))
            {
                return(propertyDescriptorCollection);
            }

            Ifc4.Document document = baseObject.GetParent <Ifc4.Document>();

            IEnumerable <Ifc4.IfcPropertySetTemplate> ifcPropertySetTemplateCollection = document.GetIfcPropertySetTemplateCollection(facility);

            ////string objectTypeId = null;
            ////if (facility != null && !String.IsNullOrEmpty(facility.ObjectTypeId))
            ////{
            ////    objectTypeId = facility.ObjectTypeId;
            ////    IEnumerable<Ifc4.IfcRelAssociatesClassification> ifcRelAssociatesClassificationCollection = document.IfcXmlDocument.Items.OfType<Ifc4.IfcRelAssociatesClassification>();
            ////    IEnumerable<string> relatedObjectsRefs = from ifcRelAssociatesClassification in ifcRelAssociatesClassificationCollection
            ////                                             from relatedObject in ifcRelAssociatesClassification.RelatedObjects.Items
            ////                                             where ifcRelAssociatesClassification.RelatingClassification.Item != null && ifcRelAssociatesClassification.RelatingClassification.Item.Ref == objectTypeId
            ////                                             select relatedObject.Ref;

            ////    ifcPropertySetTemplateCollection = document.IfcXmlDocument.Items.OfType<Ifc4.IfcPropertySetTemplate>().Where(item => relatedObjectsRefs.Contains(item.Id));
            ////}

            if (ifcPropertySetTemplateCollection == null)
            {
                return(propertyDescriptorCollection);
            }


            foreach (var ifcPropertySetTemplate in ifcPropertySetTemplateCollection)
            {
                foreach (var propertyTemplate in ifcPropertySetTemplate.HasPropertyTemplates.Items)
                {
                    Ifc4.IfcSimplePropertyTemplate simplePropertyTemplate = propertyTemplate as Ifc4.IfcSimplePropertyTemplate;

                    if (simplePropertyTemplate == null)
                    {
                        continue;
                    }

                    //string displayName = String.IsNullOrEmpty(simplePropertyTemplate.PrimaryMeasureType) ? simplePropertyTemplate.Name : String.Format("{0} [{1}]", simplePropertyTemplate.Name, simplePropertyTemplate.PrimaryMeasureType);
                    string displayName = simplePropertyTemplate.Name;

                    string unit = null;
                    if (simplePropertyTemplate.PrimaryUnit != null)
                    {
                        if (simplePropertyTemplate.PrimaryUnit.Item is Ifc4.IfcSIUnit)
                        {
                            Ifc4.IfcSIUnit ifcSIUnit = GetUnit((Ifc4.IfcSIUnit)simplePropertyTemplate.PrimaryUnit.Item);
                            if (ifcSIUnit.NameSpecified)
                            {
                                if (ifcSIUnit.PrefixSpecified)
                                {
                                    if (ifcSIUnit.Prefix == IfcSIPrefix.Centi && ifcSIUnit.Name == IfcSIUnitName.Metre)
                                    {
                                        unit = "[cm]";
                                    }
                                    else if (ifcSIUnit.Prefix == IfcSIPrefix.Milli && ifcSIUnit.Name == IfcSIUnitName.Metre)
                                    {
                                        unit = "[mm]";
                                    }
                                    else if (ifcSIUnit.Prefix == IfcSIPrefix.Kilo && ifcSIUnit.Name == IfcSIUnitName.Gram)
                                    {
                                        unit = "[kg]";
                                    }
                                    else if (ifcSIUnit.Prefix == IfcSIPrefix.Kilo && ifcSIUnit.Name == IfcSIUnitName.Watt)
                                    {
                                        unit = "[kW]";
                                    }
                                }
                                else
                                {
                                    if (ifcSIUnit.Name == IfcSIUnitName.Metre)
                                    {
                                        unit = "[m]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.SquareMetre)
                                    {
                                        unit = "[m²]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.CubicMetre)
                                    {
                                        unit = "[m³]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.Volt)
                                    {
                                        unit = "[V]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.DegreeCelsius)
                                    {
                                        unit = "[°C]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.Ampere)
                                    {
                                        unit = "[A]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.Hertz)
                                    {
                                        unit = "[Hz]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.Watt)
                                    {
                                        unit = "[W]";
                                    }
                                    else if (ifcSIUnit.Name == IfcSIUnitName.Pascal)
                                    {
                                        unit = "[Pa]";
                                    }
                                }
                            }
                        }
                        else if (simplePropertyTemplate.PrimaryUnit.Item is Ifc4.IfcDerivedUnit)
                        {
                            Ifc4.IfcDerivedUnit ifcDerivedUnit = GetUnit <Ifc4.IfcDerivedUnit>((Ifc4.IfcDerivedUnit)simplePropertyTemplate.PrimaryUnit.Item);
                            if (ifcDerivedUnit.UnitTypeSpecified)
                            {
                                if (ifcDerivedUnit.UnitType == IfcDerivedUnitEnum.Heatfluxdensityunit)
                                {
                                    unit = "[Ah]";
                                }
                                else if (ifcDerivedUnit.UnitType == IfcDerivedUnitEnum.Volumetricflowrateunit)
                                {
                                    unit = "[m³/h]";
                                }
                                else if (ifcDerivedUnit.UnitType == IfcDerivedUnitEnum.Massdensityunit)
                                {
                                    unit = "[kg/m³]";
                                }
                                else if (ifcDerivedUnit.UnitType == IfcDerivedUnitEnum.Soundpowerlevelunit)
                                {
                                    unit = "[db]";
                                }
                            }
                        }
                        if (!String.IsNullOrEmpty(unit))
                        {
                            displayName = String.Concat(displayName, " ", unit);
                        }
                    }

                    List <Attribute> attributes = new List <Attribute>()
                    {
                        new System.ComponentModel.BrowsableAttribute(true),
                        new System.ComponentModel.CategoryAttribute("Runtime Object"),
                        new System.ComponentModel.DisplayNameAttribute(displayName)
                    };


                    CustomPropertyStandardValues customPropertyStandardValues = null;
                    Type customPropertyType;

                    string primaryMeasureType = simplePropertyTemplate.PrimaryMeasureType;

                    if (simplePropertyTemplate.TemplateType == Ifc4.IfcSimplePropertyTemplateTypeEnum.PSinglevalue)
                    {
                        // default
                        customPropertyType = typeof(System.String);

                        // overwrite
                        if (!String.IsNullOrEmpty(primaryMeasureType))
                        {
                            if (primaryMeasureType.Equals("IfcText", StringComparison.OrdinalIgnoreCase))
                            {
                                customPropertyType = typeof(System.String);
                            }
                            else if (primaryMeasureType.Equals("IfcDate", StringComparison.OrdinalIgnoreCase))
                            {
                                customPropertyType = typeof(System.Nullable <DateTime>);
                                attributes.Add(new System.ComponentModel.TypeConverterAttribute(typeof(CustomNullableTypeConverter <DateTime?>)));
                            }
                            else if (primaryMeasureType.Equals("IfcReal", StringComparison.OrdinalIgnoreCase))
                            {
                                customPropertyType = typeof(System.Nullable <double>);
                                attributes.Add(new System.ComponentModel.TypeConverterAttribute(typeof(CustomNullableTypeConverter <double?>)));
                            }
                            else if (primaryMeasureType.Equals("IfcBoolean", StringComparison.OrdinalIgnoreCase))
                            {
                                customPropertyType = typeof(System.String);
                                attributes.Add(new System.ComponentModel.TypeConverterAttribute(typeof(CustomBooleanNullableTypeConverter)));
                            }
                        }
                    }
                    else if (simplePropertyTemplate.TemplateType == Ifc4.IfcSimplePropertyTemplateTypeEnum.PEnumeratedvalue)
                    {
                        customPropertyStandardValues = new CustomPropertyStandardValues();
                        attributes.Add(new System.ComponentModel.TypeConverterAttribute(typeof(CustomEnumTypeConverter)));

                        int i = 0;
                        // add empty enum value
                        if (simplePropertyTemplate.Enumerators.EnumerationValues.Items.Any())
                        {
                            // empty string not possible - use a string with length > 0
                            customPropertyStandardValues.Add(new CustomPropertyStandardValue("E" + (i++), " "));
                        }

                        foreach (var enumItem in simplePropertyTemplate.Enumerators.EnumerationValues.Items)
                        {
                            string enumValue;
                            if (enumItem is Ifc4.IfcLabelwrapper)
                            {
                                Ifc4.IfcLabelwrapper labelWrapper = enumItem as Ifc4.IfcLabelwrapper;
                                enumValue = labelWrapper.Value;
                            }
                            else
                            {
                                enumValue = enumItem.ToString();
                            }

                            customPropertyStandardValues.Add(new CustomPropertyStandardValue("E" + (i++), enumValue.Trim()));
                        }

                        customPropertyType = typeof(System.Enum);
                    }
                    else
                    {
                        customPropertyType = typeof(System.String);
                    }

                    // ------------------------------------------------------------------
                    StringBuilder sbAttributeDescription = new StringBuilder();
                    sbAttributeDescription.AppendLine("");
                    if (String.IsNullOrEmpty(primaryMeasureType))
                    {
                        sbAttributeDescription.AppendLine(String.Format("IFC4 Type: {0}", "unknown"));
                    }
                    else
                    {
                        sbAttributeDescription.AppendLine(String.Format("IFC4 Type: {0}", primaryMeasureType));
                    }

                    if (customPropertyType.IsGenericType && customPropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        sbAttributeDescription.AppendLine(String.Format(".NET Type: Nullable {0}", (customPropertyType.GetGenericArguments()[0]).Name));
                    }
                    else
                    {
                        sbAttributeDescription.AppendLine(String.Format(".NET Type: {0}", customPropertyType.Name));
                    }


                    if (!String.IsNullOrEmpty(simplePropertyTemplate.Description))
                    {
                        sbAttributeDescription.AppendLine("");
                        sbAttributeDescription.AppendLine(simplePropertyTemplate.Description);
                    }

                    if (sbAttributeDescription.Length > 0)
                    {
                        attributes.Add(new System.ComponentModel.DescriptionAttribute(sbAttributeDescription.ToString()));
                    }
                    // ------------------------------------------------------------------

                    customProperty = new CustomModel.CustomProperty
                                     (
                        null,
                        simplePropertyTemplate.TempId.ToString("N"),
                        simplePropertyTemplate.TempId.ToString("N"),
                        customPropertyType,
                        simplePropertyTemplate.Name,
                        simplePropertyTemplate.Description,
                        attributes,
                        customPropertyStandardValues,
                        null
                                     );

                    customProperty.IfcPropertyName     = simplePropertyTemplate.Name;
                    customProperty.IfcPropertyGlobalId = simplePropertyTemplate.GlobalId;

                    CustomModel.CustomAssembly customAssembly = new CustomAssembly();
                    Type type = customAssembly.CreateDynamicEnum(customProperty);
                    if (type != null)
                    {
                        customProperty.PropertyType = type;
                    }

                    cpd = new CustomModel.CustomPropertyDescriptor(customProperty, this);
                    propertyDescriptorCollection.Add(cpd);
                }
            }

            return(propertyDescriptorCollection);
        }