/// <summary> /// Create property sets for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="propertySetsCreated">A concatenated string of property sets created, used to filter schedules.</returns> public override void CreatePropertySets(Document doc, Element element, string propertySetsCreated) { if (PropertySets != null && PropertySets.Count > 0) { IFCParameterSetByGroup parameterGroupMap = IFCParameterSetByGroup.Create(element); foreach (IFCPropertySetDefinition propertySet in PropertySets.Values) { KeyValuePair <string, bool> newPropertySetCreated = propertySet.CreatePropertySet(doc, element, parameterGroupMap); if (!newPropertySetCreated.Value || string.IsNullOrWhiteSpace(newPropertySetCreated.Key)) { continue; } if (propertySetsCreated == null) { propertySetsCreated = newPropertySetCreated.Key; } else { propertySetsCreated += ";" + newPropertySetCreated.Key; } } Parameter propertySetList = element.LookupParameter("Type IfcPropertySetList"); if (propertySetList != null) { propertySetList.Set(propertySetsCreated); } } }
/// <summary> /// Create property sets for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="propertySetsCreated">A concatenated string of property sets created, used to filter schedules.</returns> /// <param name="propertySetListName">The name of the parameter that contains the property set list name.</param> /// <param name="propertySets">The list of properties.</param> protected void CreatePropertySetsBase(Document doc, Element element, string propertySetsCreated, string propertySetListName, IDictionary <string, IFCPropertySetDefinition> propertySets) { if (propertySetsCreated == null) { propertySetsCreated = ""; } if (propertySets != null && propertySets.Count > 0) { IFCParameterSetByGroup parameterGroupMap = IFCParameterSetByGroup.Create(element); foreach (IFCPropertySetDefinition propertySet in propertySets.Values) { Tuple <string, bool> newPropertySetCreated = propertySet.CreatePropertySet(doc, element, this, parameterGroupMap); if (newPropertySetCreated == null || !newPropertySetCreated.Item2 || string.IsNullOrWhiteSpace(newPropertySetCreated.Item1)) { continue; } if (propertySetsCreated == "") { propertySetsCreated = newPropertySetCreated.Item1; } else { propertySetsCreated += ";" + newPropertySetCreated.Item1; } } } // Add property set-based parameters. // We are going to create this "fake" parameter so that we can filter elements in schedules based on their property sets. Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id); IFCPropertySet.AddParameterString(doc, element, category, this, propertySetListName, propertySetsCreated, Id); }
/// <summary> /// Create property sets for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="propertySetsCreated">A concatenated string of property sets created, used to filter schedules.</returns> public override void CreatePropertySets(Document doc, Element element, string propertySetsCreated) { if (PropertySets != null && PropertySets.Count > 0) { IFCParameterSetByGroup parameterGroupMap = IFCParameterSetByGroup.Create(element); foreach (IFCPropertySetDefinition propertySet in PropertySets.Values) { string newPropertySetCreated = propertySet.CreatePropertySet(doc, element, parameterGroupMap); if (propertySetsCreated == null) { propertySetsCreated = newPropertySetCreated; } else { propertySetsCreated += ";" + newPropertySetCreated; } } Parameter propertySetList = element.LookupParameter("IfcPropertySetList"); if (propertySetList != null) { propertySetList.Set(propertySetsCreated); } } }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created.</returns> public override string CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { IDictionary <string, IFCData> parametersToAdd = new Dictionary <string, IFCData>(); foreach (KeyValuePair <Tuple <string, UnitType, AllowedValues>, double> property in DoubleProperties) { string name = property.Key.Item1; Parameter existingParameter = null; if (!parameterGroupMap.TryFindParameter(name, out existingParameter)) { IFCPropertySet.AddParameterDouble(doc, element, name, property.Key.Item2, property.Value, Id); continue; } switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(property.Value.ToString()); break; case StorageType.Double: existingParameter.Set(property.Value); break; default: IFCImportFile.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false); break; } } foreach (KeyValuePair <string, string> property in StringProperties) { string name = property.Key; Parameter existingParameter = null; if (!parameterGroupMap.TryFindParameter(name, out existingParameter)) { IFCPropertySet.AddParameterString(doc, element, property.Key, property.Value, Id); continue; } switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(property.Value); break; default: IFCImportFile.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false); break; } } return("\"" + EntityType.ToString() + "\""); }
/// <summary> /// Create quantities for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the element quantity created, if it was created.</returns> public override string CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { string quotedName = "\"" + Name + "\""; ISet <string> parametersCreated = new HashSet <string>(); foreach (IFCPhysicalQuantity quantity in IFCQuantities.Values) { quantity.Create(doc, element, parameterGroupMap, Name, parametersCreated); } CreateScheduleForPropertySet(doc, element, parameterGroupMap, parametersCreated); return(quotedName); }
/// <summary> /// Create a quantity for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="category">The element's category.</param> /// <param name="parameterMap">The parameters of the element. Cached for performance.</param> /// <param name="propertySetName">The name of the containing property set.</param> /// <param name="createdParameters">The names of the created parameters.</param> public abstract void Create(Document doc, Element element, Category category, IFCParameterSetByGroup parameterGroupMap, string propertySetName, ISet <string> createdParameters);
/// <summary> /// Create quantities for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public override Tuple <string, bool> CreatePropertySet(Document doc, Element element, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap) { Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id); string quotedName = "\"" + Name + "\""; ISet <string> parametersCreated = new HashSet <string>(); foreach (IFCPhysicalQuantity quantity in IFCQuantities.Values) { quantity.Create(doc, element, category, objDef, parameterGroupMap, Name, parametersCreated); } return(Tuple.Create(quotedName, true)); }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public virtual KeyValuePair <string, bool> CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { return(new KeyValuePair <string, bool>(null, false)); }
/// <summary> /// Create a schedule for a given property set. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <param name="parametersCreated">The created parameters.</param> protected void CreateScheduleForPropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap, ISet <string> parametersCreated) { // Don't bother creating schedules if we are maximizing performance. if (IFCImportFile.TheFile.Options.UseStreamlinedOptions) { return; } if (parametersCreated.Count == 0) { return; } Category category = element.Category; if (category == null) { return; } ElementId categoryId = category.Id; bool elementIsType = (element is ElementType); Tuple <ElementId, bool, string> scheduleKey = new Tuple <ElementId, bool, string>(categoryId, elementIsType, Name); ISet <string> viewScheduleNames = Importer.TheCache.ViewScheduleNames; IDictionary <Tuple <ElementId, bool, string>, ElementId> viewSchedules = Importer.TheCache.ViewSchedules; ElementId viewScheduleId; if (!viewSchedules.TryGetValue(scheduleKey, out viewScheduleId)) { string scheduleName = scheduleKey.Item3; string scheduleTypeName = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty; int index = 1; while (viewScheduleNames.Contains(scheduleName)) { string indexString = (index > 1) ? " " + index.ToString() : string.Empty; scheduleName += " (" + category.Name + scheduleTypeName + indexString + ")"; index++; if (index > 1000) { Importer.TheLog.LogWarning(Id, "Too many property sets with the name " + scheduleKey.Item3 + ", no longer creating schedules with that name.", true); return; } } // Not all categories allow creating schedules. Skip these. ViewSchedule viewSchedule = null; try { viewSchedule = ViewSchedule.CreateSchedule(doc, scheduleKey.Item1); } catch { // Only try to create the schedule once per key. viewSchedules[scheduleKey] = ElementId.InvalidElementId; return; } if (viewSchedule != null) { viewSchedule.Name = scheduleName; viewSchedules[scheduleKey] = viewSchedule.Id; viewScheduleNames.Add(scheduleName); ElementId ifcGUIDId = new ElementId(elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID); string propertySetListName = elementIsType ? Resources.IFCTypeSchedule + " IfcPropertySetList" : "IfcPropertySetList"; IList <SchedulableField> schedulableFields = viewSchedule.Definition.GetSchedulableFields(); bool filtered = false; foreach (SchedulableField sf in schedulableFields) { string fieldName = sf.GetName(doc); if (parametersCreated.Contains(fieldName) || sf.ParameterId == ifcGUIDId) { viewSchedule.Definition.AddField(sf); } else if (!filtered && fieldName == propertySetListName) { // We want to filter the schedule for specifically those elements that have this property set assigned. ScheduleField scheduleField = viewSchedule.Definition.AddField(sf); scheduleField.IsHidden = true; ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, ScheduleFilterType.Contains, "\"" + Name + "\""); viewSchedule.Definition.AddFilter(filter); filtered = true; } } } } return; }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public override Tuple <string, bool> CreatePropertySet(Document doc, Element element, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap) { IDictionary <string, IFCData> parametersToAdd = new Dictionary <string, IFCData>(); Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id); foreach (KeyValuePair <Tuple <string, ForgeTypeId, AllowedValues>, double> property in DoubleProperties) { string name = property.Key.Item1; Parameter existingParameter = null; if (!parameterGroupMap.TryFindParameter(name, out existingParameter)) { ForgeTypeId valueType = property.Key.Item2; // If we aren't scaling values, all length values have come from Attributes // and so will always be in feet. ForgeTypeId unitType = (!Importer.TheProcessor.ScaleValues && valueType == SpecTypeId.Length) ? UnitTypeId.Feet : null; IFCPropertySet.AddParameterDouble(doc, element, category, objDef, name, valueType, unitType, property.Value, Id); continue; } switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(property.Value.ToString()); break; case StorageType.Double: existingParameter.Set(property.Value); break; default: Importer.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false); break; } } foreach (KeyValuePair <string, string> property in StringProperties) { string name = property.Key; Parameter existingParameter = null; if (!parameterGroupMap.TryFindParameter(name, out existingParameter)) { IFCPropertySet.AddParameterString(doc, element, category, objDef, property.Key, property.Value, Id); continue; } switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(property.Value); break; default: Importer.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false); break; } } return(Tuple.Create("\"" + EntityType.ToString() + "\"", false)); }
/// <summary> /// Create a quantity for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="category">The element's category.</param> /// <param name="parameterMap">The parameters of the element. Cached for performance.</param> /// <param name="propertySetName">The name of the containing property set.</param> /// <param name="createdParameters">The names of the created parameters.</param> public override void Create(Document doc, Element element, Category category, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap, string propertySetName, ISet <string> createdParameters) { double baseValue = 0.0; IFCDataPrimitiveType type = Value.PrimitiveType; switch (type) { case IFCDataPrimitiveType.Double: baseValue = Value.AsDouble(); break; case IFCDataPrimitiveType.Integer: // This case isn't valid, but could happen when repairing a file Importer.TheLog.LogWarning(Id, "Unexpected integer parameter type, repairing.", false); baseValue = Value.AsInteger(); break; default: Importer.TheLog.LogError(Id, "Invalid parameter type: " + type.ToString() + " for IfcPhysicalSimpleQuantity", false); return; } double doubleValueToUse = Importer.TheProcessor.ScaleValues ? IFCUnit?.Convert(baseValue) ?? baseValue : baseValue; Parameter existingParameter = null; string originalParameterName = propertySetName + "." + Name; string parameterName = originalParameterName; if (!parameterGroupMap.TryFindParameter(parameterName, out existingParameter)) { int parameterNameCount = 2; while (createdParameters.Contains(parameterName)) { parameterName = originalParameterName + " " + parameterNameCount; parameterNameCount++; } if (parameterNameCount > 2) { Importer.TheLog.LogWarning(Id, "Renamed parameter: " + originalParameterName + " to: " + parameterName, false); } if (existingParameter == null) { ForgeTypeId specTypeId; ForgeTypeId unitsTypeId = null; if (IFCUnit != null) { specTypeId = IFCUnit.Spec; unitsTypeId = IFCUnit.Unit; } else { specTypeId = IFCDataUtil.GetUnitTypeFromData(Value, SpecTypeId.Number); } bool created = IFCPropertySet.AddParameterDouble(doc, element, category, objDef, parameterName, specTypeId, unitsTypeId, doubleValueToUse, Id); if (created) { createdParameters.Add(parameterName); } return; } } bool setValue = true; switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(doubleValueToUse.ToString()); break; case StorageType.Double: existingParameter.Set(doubleValueToUse); break; default: setValue = false; break; } if (!setValue) { Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name + " of storage type: " + existingParameter.StorageType.ToString(), false); } }
/// <summary> /// Create a schedule for a given property set. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <param name="parametersCreated">The created parameters.</param> protected void CreateScheduleForPropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap, ISet <string> parametersCreated) { if (parametersCreated.Count == 0) { return; } Category category = element.Category; if (category == null) { return; } ElementId categoryId = category.Id; KeyValuePair <ElementId, string> scheduleKey = new KeyValuePair <ElementId, string>(categoryId, Name); ISet <string> viewScheduleNames = Importer.TheCache.ViewScheduleNames; IDictionary <KeyValuePair <ElementId, string>, ElementId> viewSchedules = Importer.TheCache.ViewSchedules; ElementId viewScheduleId; if (!viewSchedules.TryGetValue(scheduleKey, out viewScheduleId)) { // Not all categories allow creating schedules. Skip these. ViewSchedule viewSchedule = null; try { viewSchedule = ViewSchedule.CreateSchedule(doc, scheduleKey.Key); } catch { } if (viewSchedule != null) { string scheduleName = scheduleKey.Value; if (viewScheduleNames.Contains(scheduleName)) { scheduleName += " (" + category.Name + ")"; } viewSchedule.Name = scheduleName; viewSchedules[scheduleKey] = viewSchedule.Id; viewScheduleNames.Add(scheduleName); bool elementIsType = (element is ElementType); ElementId ifcGUIDId = new ElementId(elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID); string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList"; IList <SchedulableField> schedulableFields = viewSchedule.Definition.GetSchedulableFields(); bool filtered = false; foreach (SchedulableField sf in schedulableFields) { string fieldName = sf.GetName(doc); if (parametersCreated.Contains(fieldName) || sf.ParameterId == ifcGUIDId) { viewSchedule.Definition.AddField(sf); } else if (!filtered && fieldName == propertySetListName) { // We want to filter the schedule for specifically those elements that have this property set assigned. ScheduleField scheduleField = viewSchedule.Definition.AddField(sf); scheduleField.IsHidden = true; ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, ScheduleFilterType.Contains, "\"" + Name + "\""); viewSchedule.Definition.AddFilter(filter); filtered = true; } } } } return; }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public virtual Tuple <string, bool> CreatePropertySet(Document doc, Element element, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap) { return(new Tuple <string, bool>(null, false)); }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public override Tuple <string, bool> CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { Category category = GetCategoryForParameterIfValid(element, Id); if (category == null) { return(null); } string quotedName = "\"" + Name + "\""; ISet <string> parametersCreated = new HashSet <string>(); foreach (IFCProperty property in IFCProperties.Values) { property.Create(doc, element, category, parameterGroupMap, Name, parametersCreated); } CreateScheduleForPropertySet(doc, element, category, parameterGroupMap, parametersCreated); return(Tuple.Create(quotedName, true)); }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created.</returns> public virtual string CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { return(null); }
/// <summary> /// Create a property for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="category">The category of the element being created.</param> /// <param name="parameterMap">The parameters of the element. Cached for performance.</param> /// <param name="propertySetName">The name of the containing property set.</param> /// <param name="createdParameters">The names of the created parameters.</param> public void Create(Document doc, Element element, Category category, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap, string propertySetName, ISet <string> createdParameters) { // Try to get the single value from the property. If we can't get a single value, get it as a string. IFCPropertyValue propertyValueToUse = null; if (this is IFCSimpleProperty) { IFCSimpleProperty simpleProperty = this as IFCSimpleProperty; IList <IFCPropertyValue> propertyValues = simpleProperty.IFCPropertyValues; if (propertyValues != null && propertyValues.Count == 1) { // If the value isn't set, skip it. We won't warn. if (!propertyValues[0].HasValue()) { return; } propertyValueToUse = propertyValues[0]; } } IFCDataPrimitiveType dataType = IFCDataPrimitiveType.Unknown; ForgeTypeId specTypeId = new ForgeTypeId(); ForgeTypeId unitsTypeId = null; bool? boolValueToUse = null; IFCLogical?logicalValueToUse = null; int? intValueToUse = null; double? doubleValueToUse = null; ElementId elementIdValueToUse = null; string stringValueToUse = null; if (propertyValueToUse == null) { string propertyValueAsString = PropertyValueAsString(); if (propertyValueAsString == null) { Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name, false); return; } dataType = IFCDataPrimitiveType.String; stringValueToUse = propertyValueAsString; } else { dataType = propertyValueToUse.Value.PrimitiveType; if (dataType == IFCDataPrimitiveType.Instance) { IFCAnyHandle propertyValueHandle = propertyValueToUse.Value.AsInstance(); ElementId propertyValueAsId = IFCObjectReferenceSelect.ToElementId(propertyValueHandle); if (propertyValueAsId != ElementId.InvalidElementId) { elementIdValueToUse = propertyValueAsId; } else { stringValueToUse = IFCObjectReferenceSelect.ToString(propertyValueHandle); dataType = IFCDataPrimitiveType.String; } } else { switch (dataType) { case IFCDataPrimitiveType.String: case IFCDataPrimitiveType.Enumeration: case IFCDataPrimitiveType.Binary: stringValueToUse = propertyValueToUse.AsString(); break; case IFCDataPrimitiveType.Integer: intValueToUse = propertyValueToUse.AsInteger(); break; case IFCDataPrimitiveType.Boolean: boolValueToUse = propertyValueToUse.AsBoolean(); break; case IFCDataPrimitiveType.Logical: logicalValueToUse = propertyValueToUse.AsLogical(); break; case IFCDataPrimitiveType.Double: if (propertyValueToUse.IFCUnit != null) { specTypeId = propertyValueToUse.IFCUnit.Spec; unitsTypeId = propertyValueToUse.IFCUnit.Unit; } else { specTypeId = IFCDataUtil.GetUnitTypeFromData(propertyValueToUse.Value, SpecTypeId.Number); } doubleValueToUse = Importer.TheProcessor.ScaleValues ? propertyValueToUse.AsScaledDouble() : propertyValueToUse.AsUnscaledDouble(); break; default: Importer.TheLog.LogError(Id, "Unknown value type for parameter: " + Name, false); return; } } } if (stringValueToUse != null && stringValueToUse.Length == 0) { return; } Parameter existingParameter = null; bool elementIsType = (element is ElementType); string typeString = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty; string originalParameterName = propertySetName + "." + Name + typeString; string parameterName = originalParameterName; if (parameterGroupMap.TryFindParameter(parameterName, out existingParameter)) { if ((existingParameter != null) && !IsValidParameterType(existingParameter, dataType)) { existingParameter = null; } } if (existingParameter == null) { int parameterNameCount = 2; while (createdParameters.Contains(parameterName)) { parameterName = originalParameterName + " " + parameterNameCount; parameterNameCount++; } if (parameterNameCount > 2) { Importer.TheLog.LogWarning(Id, "Renamed parameter: " + originalParameterName + " to: " + parameterName, false); } bool created = false; switch (dataType) { case IFCDataPrimitiveType.String: case IFCDataPrimitiveType.Enumeration: case IFCDataPrimitiveType.Binary: created = IFCPropertySet.AddParameterString(doc, element, category, objDef, parameterName, stringValueToUse, Id); break; case IFCDataPrimitiveType.Integer: created = IFCPropertySet.AddParameterInt(doc, element, category, objDef, parameterName, intValueToUse.Value, Id); break; case IFCDataPrimitiveType.Boolean: created = IFCPropertySet.AddParameterBoolean(doc, element, category, objDef, parameterName, boolValueToUse.Value, Id); break; case IFCDataPrimitiveType.Logical: if (logicalValueToUse != IFCLogical.Unknown) { created = IFCPropertySet.AddParameterBoolean(doc, element, category, objDef, parameterName, (logicalValueToUse == IFCLogical.True), Id); } break; case IFCDataPrimitiveType.Double: created = IFCPropertySet.AddParameterDouble(doc, element, category, objDef, parameterName, specTypeId, unitsTypeId, doubleValueToUse.Value, Id); break; case IFCDataPrimitiveType.Instance: created = IFCPropertySet.AddParameterElementId(doc, element, category, objDef, parameterName, elementIdValueToUse, Id); break; } if (created) { createdParameters.Add(originalParameterName); } return; } bool couldSetValue = false; switch (existingParameter.StorageType) { case StorageType.String: { switch (dataType) { case IFCDataPrimitiveType.String: case IFCDataPrimitiveType.Enumeration: case IFCDataPrimitiveType.Binary: couldSetValue = existingParameter.Set(stringValueToUse); break; case IFCDataPrimitiveType.Integer: couldSetValue = existingParameter.Set(intValueToUse.Value.ToString()); break; case IFCDataPrimitiveType.Boolean: couldSetValue = existingParameter.Set(boolValueToUse.Value ? "True" : "False"); break; case IFCDataPrimitiveType.Logical: couldSetValue = existingParameter.Set(logicalValueToUse.ToString()); break; case IFCDataPrimitiveType.Double: couldSetValue = existingParameter.Set(doubleValueToUse.ToString()); break; default: break; } } break; case StorageType.Integer: if (dataType == IFCDataPrimitiveType.Integer) { couldSetValue = existingParameter.Set(intValueToUse.Value); } else if (dataType == IFCDataPrimitiveType.Boolean) { couldSetValue = existingParameter.Set(boolValueToUse.Value ? 1 : 0); } else if (dataType == IFCDataPrimitiveType.Logical) { couldSetValue = (logicalValueToUse == IFCLogical.Unknown) ? true : existingParameter.Set((logicalValueToUse == IFCLogical.True) ? 1 : 0); } break; case StorageType.Double: if (dataType == IFCDataPrimitiveType.Double) { couldSetValue = existingParameter.Set(doubleValueToUse.Value); } else if (dataType == IFCDataPrimitiveType.Integer) { couldSetValue = existingParameter.Set(intValueToUse.Value); } else if (dataType == IFCDataPrimitiveType.Boolean) { couldSetValue = existingParameter.Set(boolValueToUse.Value ? 1 : 0); } else if ((dataType == IFCDataPrimitiveType.Logical) && (logicalValueToUse != IFCLogical.Unknown)) { couldSetValue = existingParameter.Set((logicalValueToUse == IFCLogical.True) ? 1 : 0); } break; } if (!couldSetValue) { Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name + " of storage type: " + existingParameter.StorageType.ToString(), false); } }
/// <summary> /// Create a quantity for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterMap">The parameters of the element. Cached for performance.</param> /// <param name="propertySetName">The name of the containing property set.</param> /// <param name="createdParameters">The names of the created parameters.</param> public override void Create(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap, string propertySetName, ISet <string> createdParameters) { double doubleValueToUse = IFCUnit != null?IFCUnit.Convert(Value.AsDouble()) : Value.AsDouble(); Parameter existingParameter = null; string originalParameterName = Name + "(" + propertySetName + ")"; string parameterName = originalParameterName; if (!parameterGroupMap.TryFindParameter(parameterName, out existingParameter)) { int parameterNameCount = 2; while (createdParameters.Contains(parameterName)) { parameterName = originalParameterName + " " + parameterNameCount; parameterNameCount++; } if (parameterNameCount > 2) { Importer.TheLog.LogWarning(Id, "Renamed parameter: " + originalParameterName + " to: " + parameterName, false); } if (existingParameter == null) { UnitType unitType = UnitType.UT_Undefined; if (IFCUnit != null) { unitType = IFCUnit.UnitType; } else { unitType = IFCDataUtil.GetUnitTypeFromData(Value, UnitType.UT_Number); } bool created = IFCPropertySet.AddParameterDouble(doc, element, parameterName, unitType, doubleValueToUse, Id); if (created) { createdParameters.Add(parameterName); } return; } } bool setValue = true; switch (existingParameter.StorageType) { case StorageType.String: existingParameter.Set(doubleValueToUse.ToString()); break; case StorageType.Double: existingParameter.Set(doubleValueToUse); break; default: setValue = false; break; } if (!setValue) { Importer.TheLog.LogError(Id, "Couldn't create parameter: " + Name + " of storage type: " + existingParameter.StorageType.ToString(), false); } }
/// <summary> /// Create a property set for a given element. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns> public override KeyValuePair <string, bool> CreatePropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap) { string quotedName = "\"" + Name + "\""; ISet <string> parametersCreated = new HashSet <string>(); foreach (IFCProperty property in IFCProperties.Values) { property.Create(doc, element, parameterGroupMap, Name, parametersCreated); } CreateScheduleForPropertySet(doc, element, parameterGroupMap, parametersCreated); return(new KeyValuePair <string, bool>(quotedName, true)); }