/// <summary>
        /// Creates a property from the calculator.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="exporterIFC">The ExporterIFC.</param>
        /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param>
        /// <param name="element">The element.</param>
        /// <param name="elementType">The element type.</param>
        /// <param name="handle">The handle for which we calculate the property.</param>
        /// <returns>The property handle.</returns>
        IFCAnyHandle CreatePropertyFromCalculator(IFCFile file, ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element,
                                                  ElementType elementType, IFCAnyHandle handle, PropertyType propertyType, PropertyValueType valueType, Type propertyEnumerationType, string propertyName)
        {
            IFCAnyHandle propHnd = null;

            if (PropertyCalculator == null)
            {
                return(propHnd);
            }

            if (PropertyCalculator.GetParameterFromSubelementCache(element, handle) ||
                PropertyCalculator.Calculate(exporterIFC, extrusionCreationData, element, elementType))
            {
                switch (propertyType)
                {
                case PropertyType.Label:
                {
                    if (PropertyCalculator.CalculatesMutipleValues)
                    {
                        propHnd = PropertyUtil.CreateLabelProperty(file, propertyName, PropertyCalculator.GetStringValues(), valueType, propertyEnumerationType);
                    }
                    else
                    {
                        bool cacheLabel = PropertyCalculator.CacheStringValues;
                        propHnd = PropertyUtil.CreateLabelPropertyFromCache(file, null, propertyName, PropertyCalculator.GetStringValue(), valueType, cacheLabel, propertyEnumerationType);
                    }
                    break;
                }

                case PropertyType.Text:
                {
                    propHnd = PropertyUtil.CreateTextPropertyFromCache(file, propertyName, PropertyCalculator.GetStringValue(), valueType);
                    break;
                }

                case PropertyType.Identifier:
                {
                    propHnd = PropertyUtil.CreateIdentifierPropertyFromCache(file, propertyName, PropertyCalculator.GetStringValue(), valueType);
                    break;
                }

                case PropertyType.Boolean:
                {
                    propHnd = PropertyUtil.CreateBooleanPropertyFromCache(file, propertyName, PropertyCalculator.GetBooleanValue(), valueType);
                    break;
                }

                case PropertyType.Logical:
                {
                    propHnd = PropertyUtil.CreateLogicalPropertyFromCache(file, propertyName, PropertyCalculator.GetLogicalValue(), valueType);
                    break;
                }

                case PropertyType.Integer:
                {
                    if (PropertyCalculator.CalculatesMultipleParameters)
                    {
                        propHnd = PropertyUtil.CreateIntegerPropertyFromCache(file, propertyName, PropertyCalculator.GetIntValue(propertyName), valueType);
                    }
                    else
                    {
                        propHnd = PropertyUtil.CreateIntegerPropertyFromCache(file, propertyName, PropertyCalculator.GetIntValue(), valueType);
                    }
                    break;
                }

                case PropertyType.Real:
                {
                    propHnd = PropertyUtil.CreateRealPropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.Length:
                {
                    if (PropertyCalculator.CalculatesMultipleParameters)
                    {
                        propHnd = PropertyUtil.CreateLengthMeasurePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(propertyName), valueType);
                    }
                    else
                    {
                        propHnd = PropertyUtil.CreateLengthMeasurePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    }
                    break;
                }

                case PropertyType.PositiveLength:
                {
                    if (PropertyCalculator.CalculatesMultipleParameters)
                    {
                        propHnd = PropertyUtil.CreatePositiveLengthMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(propertyName), valueType);
                    }
                    else
                    {
                        propHnd = PropertyUtil.CreatePositiveLengthMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    }
                    break;
                }

                case PropertyType.NormalisedRatio:
                {
                    propHnd = PropertyUtil.CreateNormalisedRatioMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.PositiveRatio:
                {
                    propHnd = PropertyUtil.CreatePositiveRatioMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.Ratio:
                {
                    propHnd = PropertyUtil.CreateRatioMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.PlaneAngle:
                {
                    propHnd = PropertyUtil.CreatePlaneAngleMeasurePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.PositivePlaneAngle:
                {
                    propHnd = PositivePlaneAnglePropertyUtil.CreatePositivePlaneAngleMeasurePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.Area:
                {
                    propHnd = PropertyUtil.CreateAreaMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.Count:
                {
                    if (PropertyCalculator.CalculatesMultipleParameters)
                    {
                        propHnd = PropertyUtil.CreateCountMeasureProperty(file, propertyName, PropertyCalculator.GetIntValue(propertyName), valueType);
                    }
                    else
                    {
                        propHnd = PropertyUtil.CreateCountMeasureProperty(file, propertyName, PropertyCalculator.GetIntValue(), valueType);
                    }
                    break;
                }

                case PropertyType.Frequency:
                {
                    propHnd = FrequencyPropertyUtil.CreateFrequencyProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.Power:
                {
                    propHnd = PropertyUtil.CreatePowerPropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.ThermodynamicTemperature:
                {
                    propHnd = PropertyUtil.CreateThermodynamicTemperaturePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.ThermalTransmittance:
                {
                    propHnd = PropertyUtil.CreateThermalTransmittancePropertyFromCache(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.VolumetricFlowRate:
                {
                    propHnd = PropertyUtil.CreateVolumetricFlowRateMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                case PropertyType.LinearVelocity:
                {
                    propHnd = PropertyUtil.CreateLinearVelocityMeasureProperty(file, propertyName, PropertyCalculator.GetDoubleValue(), valueType);
                    break;
                }

                default:
                    throw new InvalidOperationException();
                }
            }

            return(propHnd);
        }
Esempio n. 2
0
        /// <summary>
        /// Process to create element quantity.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element of which this property is created for.
        /// </param>
        /// <param name="elementType">
        /// The element type of which this quantity is created for.
        /// </param>
        /// <returns>
        /// Then created quantity handle.
        /// </returns>
        public IFCAnyHandle ProcessEntry(IFCFile file, ExporterIFC exporterIFC,
                                         IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            bool useProperty = (!String.IsNullOrEmpty(RevitParameterName)) || (RevitBuiltInParameter != BuiltInParameter.INVALID);

            bool   success = false;
            double val     = 0;

            if (useProperty)
            {
                success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitParameterName, out val) != null);
                if (!success && RevitBuiltInParameter != BuiltInParameter.INVALID)
                {
                    success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitBuiltInParameter, out val) != null);
                }

                if (success) // factor in the scale factor for all the parameters depending of the data type to get the correct value
                {
                    switch (m_QuantityType)
                    {
                    case QuantityType.PositiveLength:
                        val = UnitUtil.ScaleLength(val);
                        break;

                    case QuantityType.Area:
                        val = UnitUtil.ScaleArea(val);
                        break;

                    case QuantityType.Volume:
                        val = UnitUtil.ScaleVolume(val);
                        break;

                    default:
                        break;
                    }
                }
            }

            if (PropertyCalculator != null && !success)
            {
                success = PropertyCalculator.Calculate(exporterIFC, extrusionCreationData, element, elementType);
                if (success)
                {
                    val = PropertyCalculator.GetDoubleValue();
                }
            }

            IFCAnyHandle quantityHnd = null;

            if (success)
            {
                switch (QuantityType)
                {
                case QuantityType.PositiveLength:
                    quantityHnd = IFCInstanceExporter.CreateQuantityLength(file, PropertyName, MethodOfMeasurement, null, val);
                    break;

                case QuantityType.Area:
                    quantityHnd = IFCInstanceExporter.CreateQuantityArea(file, PropertyName, MethodOfMeasurement, null, val);
                    break;

                case QuantityType.Volume:
                    quantityHnd = IFCInstanceExporter.CreateQuantityVolume(file, PropertyName, MethodOfMeasurement, null, val);
                    break;

                default:
                    throw new InvalidOperationException("Missing case!");
                }
            }

            return(quantityHnd);
        }
Esempio n. 3
0
        /// <summary>
        /// Process to create element quantity.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param>
        /// <param name="element">The element of which this property is created for.</param>
        /// <param name="elementType">The element type of which this quantity is created for.</param>
        /// <returns>The created quantity handle.</returns>
        public IFCAnyHandle ProcessEntry(IFCFile file, ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData,
                                         Element element, ElementType elementType, QuantityEntry parentEntry)
        {
            bool useProperty = (!String.IsNullOrEmpty(RevitParameterName)) || (RevitBuiltInParameter != BuiltInParameter.INVALID);

            bool   success = false;
            object val     = 0;

            if (useProperty)
            {
                double dblVal = 0.0;

                if (parentEntry.QuantityType is QuantityType.Count)
                {
                    int?intValPar = null;
                    intValPar = (ParameterUtil.GetIntValueFromElementOrSymbol(element, RevitParameterName));
                    if (intValPar.HasValue)
                    {
                        success = true;
                        val     = intValPar.Value;
                    }
                }
                else
                {
                    success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitParameterName, parentEntry.IgnoreInternalValue, out dblVal) != null);
                    if (!success && RevitBuiltInParameter != BuiltInParameter.INVALID)
                    {
                        success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitBuiltInParameter, out dblVal) != null);
                    }
                    if (success)
                    {
                        val = dblVal;
                    }
                }

                if (success) // factor in the scale factor for all the parameters depending of the data type to get the correct value
                {
                    switch (parentEntry.QuantityType)
                    {
                    case QuantityType.PositiveLength:
                    case QuantityType.Length:
                        val = UnitUtil.ScaleLength((double)val);
                        break;

                    case QuantityType.Area:
                        val = UnitUtil.ScaleArea((double)val);
                        break;

                    case QuantityType.Volume:
                        val = UnitUtil.ScaleVolume((double)val);
                        break;

                    case QuantityType.Count:
                        break;

                    case QuantityType.Time:
                        break;

                    default:
                        break;
                    }
                }
            }

            if (PropertyCalculator != null && !success)
            {
                success = PropertyCalculator.Calculate(exporterIFC, extrusionCreationData, element, elementType, this);
                if (success && parentEntry.QuantityType == QuantityType.Count)
                {
                    val = PropertyCalculator.GetIntValue();
                }
                else
                {
                    val = PropertyCalculator.GetDoubleValue();
                }
            }

            IFCAnyHandle quantityHnd = null;

            if (success)
            {
                switch (parentEntry.QuantityType)
                {
                case QuantityType.PositiveLength:
                case QuantityType.Length:
                    quantityHnd = IFCInstanceExporter.CreateQuantityLength(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val);
                    break;

                case QuantityType.Area:
                    quantityHnd = IFCInstanceExporter.CreateQuantityArea(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val);
                    break;

                case QuantityType.Volume:
                    quantityHnd = IFCInstanceExporter.CreateQuantityVolume(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val);
                    break;

                case QuantityType.Weight:
                    quantityHnd = IFCInstanceExporter.CreateQuantityWeight(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val);
                    break;

                case QuantityType.Count:
                    quantityHnd = IFCInstanceExporter.CreateQuantityCount(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (int)val);
                    break;

                case QuantityType.Time:
                    quantityHnd = IFCInstanceExporter.CreateQuantityTime(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val);
                    break;

                default:
                    throw new InvalidOperationException("Missing case!");
                }
            }

            return(quantityHnd);
        }