public override StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { if (context == null) { return(base.GetStandardValues(context)); } CustomModel.CustomPropertyDescriptor customPropertyDescriptor = context.PropertyDescriptor as CustomModel.CustomPropertyDescriptor; if (customPropertyDescriptor != null) { IEnumerable <string> ie = customPropertyDescriptor.PropertyItem.ComboboxValues.Select(item => item.Key); StandardValuesCollection standardValuesCollection = new StandardValuesCollection(ie.ToList()); return(standardValuesCollection); } return(base.GetStandardValues(context)); }
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (context != null && value.GetType() == typeof(string)) { CustomModel.CustomPropertyDescriptor customPropertyDescriptor = context.PropertyDescriptor as CustomModel.CustomPropertyDescriptor; if (customPropertyDescriptor != null && customPropertyDescriptor.PropertyItem != null) { CustomPropertyStandardValue enumItem; enumItem = customPropertyDescriptor.PropertyItem.ComboboxValues.Find(item => item.DisplayText.Equals((string)value)); if (enumItem != null) { // System.Diagnostics.Debug.WriteLine(String.Format("ConvertFrom: {0} - {1}", value, enumItem.Key)); return(enumItem.Key); } } } return(base.ConvertFrom(context, culture, value)); }
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); }