Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                Importer.TheProcessor.CreateOrUpdateElement(Id, GlobalId, EntityType.ToString(), CategoryId.IntegerValue, null);

                // Set the element name.
                SetName(doc, element, category);

                // Set the element description.
                SetDescription(doc, element, category);

                // The list of materials.
                SetMaterialParameter(doc, element, category);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element, category);

                bool elementIsType = (element is ElementType);
                if (!string.IsNullOrWhiteSpace(GlobalId))
                {
                    BuiltInParameter ifcGUIDId = GetGUIDParameter(element, elementIsType);
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcGUIDId, GlobalId, true);
                }

                // Set the built-in parameters.
                (string entityName, string predefinedType) = IFCCategoryUtil.GetEntityNameAndPredefinedType(this);
                if (!string.IsNullOrWhiteSpace(entityName))
                {
                    BuiltInParameter ifcExportElementAsParam = elementIsType ? BuiltInParameter.IFC_EXPORT_ELEMENT_TYPE_AS : BuiltInParameter.IFC_EXPORT_ELEMENT_AS;
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcExportElementAsParam, entityName, true);
                }

                if (!string.IsNullOrWhiteSpace(predefinedType))
                {
                    BuiltInParameter ifcPredefinedTypeParam = elementIsType ? BuiltInParameter.IFC_EXPORT_PREDEFINEDTYPE_TYPE : BuiltInParameter.IFC_EXPORT_PREDEFINEDTYPE;
                    Importer.TheProcessor.SetStringParameter(element, Id, ifcPredefinedTypeParam, predefinedType, true);
                }
                // Set the IFCElementAssembly Parameter
                if (Decomposes != null)
                {
                    string containerParamName     = (Decomposes is IFCElementAssembly) ? "IfcElementAssembly" : "IfcDecomposes";
                    string containerParamGUIDName = (Decomposes is IFCElementAssembly) ? "IfcElementAssemblyGUID" : "IfcDecomposesGUID";
                    IFCPropertySet.AddParameterString(doc, element, category, this, containerParamName, Decomposes.Name, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, this, containerParamGUIDName, Decomposes.GlobalId, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, category, this, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, category, this, parItem.Key, SpecTypeId.Custom, UnitTypeId.General, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, category, this, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, category, this, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                // Set the element name.
                SetName(doc, element);

                // Set the element description.
                SetDescription(doc, element);

                // The list of materials.
                SetMaterialParameter(doc, element);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element);

                // Set the element GUID.
                bool             elementIsType = (element is ElementType);
                BuiltInParameter ifcGUIDId     = GetGUIDParameter(element, elementIsType);
                Parameter        guidParam     = element.get_Parameter(ifcGUIDId);
                if (guidParam != null)
                {
                    if (!guidParam.IsReadOnly)
                    {
                        guidParam.Set(GlobalId);
                    }
                }
                else
                {
                    ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId);
                }

                // Set the "IfcExportAs" parameter.
                string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this);
                if (!string.IsNullOrWhiteSpace(ifcExportAs))
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcExportAs", ifcExportAs, Id);
                }

                // 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.
                string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList";
                IFCPropertySet.AddParameterString(doc, element, propertySetListName, "", Id);

                // Set the IFCElementAssembly Parameter
                if (Decomposes != null && Decomposes is IFCElementAssembly)
                {
                    IFCPropertySet.AddParameterString(doc, element, "IfcElementAssembly", Decomposes.Name, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, parItem.Key, UnitType.UT_Custom, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected virtual void CreateParametersInternal(Document doc, Element element)
        {
            if (element != null)
            {
                Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

                // Set the element name.
                SetName(doc, element, category);

                // Set the element description.
                SetDescription(doc, element, category);

                // The list of materials.
                SetMaterialParameter(doc, element, category);

                // Set the "IfcSystem" parameter.
                SetSystemParameter(doc, element, category);

                // Set the element GUID.
                bool             elementIsType = (element is ElementType);
                BuiltInParameter ifcGUIDId     = GetGUIDParameter(element, elementIsType);
                Parameter        guidParam     = element.get_Parameter(ifcGUIDId);
                if (guidParam != null)
                {
                    if (!guidParam.IsReadOnly)
                    {
                        guidParam.Set(GlobalId);
                    }
                }
                else
                {
                    ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId);
                }

                // Set the "IfcExportAs" parameter.
                string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this);
                if (!string.IsNullOrWhiteSpace(ifcExportAs))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, this, IFCSharedParameters.IfcExportAs, ifcExportAs, Id);
                }

                // Set the IFCElementAssembly Parameter
                if (Decomposes != null)
                {
                    string containerParamName     = (Decomposes is IFCElementAssembly) ? "IfcElementAssembly" : "IfcDecomposes";
                    string containerParamGUIDName = (Decomposes is IFCElementAssembly) ? "IfcElementAssemblyGUID" : "IfcDecomposesGUID";
                    IFCPropertySet.AddParameterString(doc, element, category, containerParamName, Decomposes.Name, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, containerParamGUIDName, Decomposes.GlobalId, Id);
                }

                // Set additional parameters (if any), e.g. for Classification assignments
                if (AdditionalIntParameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters)
                    {
                        if (parItem.Value is string)
                        {
                            IFCPropertySet.AddParameterString(doc, element, category, parItem.Key, (string)parItem.Value, Id);
                        }
                        else if (parItem.Value is double)
                        {
                            IFCPropertySet.AddParameterDouble(doc, element, category, parItem.Key, SpecTypeId.Custom, (double)parItem.Value, Id);
                        }
                        else if (parItem.Value is int)
                        {
                            IFCPropertySet.AddParameterInt(doc, element, category, parItem.Key, (int)parItem.Value, Id);
                        }
                        else if (parItem.Value is bool)
                        {
                            IFCPropertySet.AddParameterBoolean(doc, element, category, parItem.Key, (bool)parItem.Value, Id);
                        }
                    }
                }
            }
        }