Example #1
0
        /// <summary>
        /// Processes an IFC unit in the property.
        /// </summary>
        /// <param name="ifcSimpleProperty">The simple property.</param>
        /// <param name="simplePropertyHandle">The simple property handle.</param>
        static protected void ProcessIFCSimplePropertyUnit(IFCSimpleProperty ifcSimpleProperty, IFCAnyHandle simplePropertyHandle)
        {
            IFCAnyHandle ifcUnitHandle = IFCImportHandleUtil.GetOptionalInstanceAttribute(simplePropertyHandle, "Unit");
            IFCUnit      ifcUnit       = (ifcUnitHandle != null) ? IFCUnit.ProcessIFCUnit(ifcUnitHandle) : null;

            if (ifcUnit == null)
            {
                if (ifcSimpleProperty.IFCPropertyValues.Count > 0)
                {
                    IFCPropertyValue propertyValue = ifcSimpleProperty.IFCPropertyValues[0];
                    if (propertyValue != null && propertyValue.HasValue() &&
                        (propertyValue.Type == IFCDataPrimitiveType.Integer) || (propertyValue.Type == IFCDataPrimitiveType.Double))
                    {
                        string   unitTypeName;
                        UnitType unitType = IFCDataUtil.GetUnitTypeFromData(propertyValue.Value, UnitType.UT_Undefined, out unitTypeName);
                        if (unitType != UnitType.UT_Undefined)
                        {
                            ifcUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(unitType);
                        }
                        else
                        {
                            Importer.TheLog.LogWarning(simplePropertyHandle.StepId, "Unhandled unit type: " + unitTypeName, true);
                        }
                    }
                }
            }

            ifcSimpleProperty.m_IFCUnit = ifcUnit;
        }
Example #2
0
        /// <summary>
        /// Processes an IFC physical simple quantity.
        /// </summary>
        /// <param name="ifcPhysicalQuantity">The IfcPhysicalSimpleQuantity object.</param>
        /// <returns>The IFCPhysicalSimpleQuantity object.</returns>
        override protected void Process(IFCAnyHandle ifcPhysicalSimpleQuantity)
        {
            base.Process(ifcPhysicalSimpleQuantity);

            IFCAnyHandle unit = IFCImportHandleUtil.GetOptionalInstanceAttribute(ifcPhysicalSimpleQuantity, "Unit");

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(unit))
            {
                IFCUnit = IFCUnit.ProcessIFCUnit(unit);
            }

            // Process subtypes of IfcPhysicalSimpleQuantity here.
            string attributeName = ifcPhysicalSimpleQuantity.TypeName.Substring(11) + "Value";

            Value        = ifcPhysicalSimpleQuantity.GetAttribute(attributeName);
            BaseUnitType = IFCDataUtil.GetUnitTypeFromData(Value, UnitType.UT_Undefined);

            if (BaseUnitType == UnitType.UT_Undefined)
            {
                // Determine it from the attributeName.
                if (string.Compare(attributeName, "LengthValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Length;
                }
                else if (string.Compare(attributeName, "AreaValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Area;
                }
                else if (string.Compare(attributeName, "VolumeValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Volume;
                }
                else if (string.Compare(attributeName, "CountValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Number;
                }
                else if (string.Compare(attributeName, "WeightValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Mass;
                }
                else if (string.Compare(attributeName, "TimeValue", true) == 0)
                {
                    BaseUnitType = UnitType.UT_Number; // No time unit type in Revit.
                }
                else
                {
                    Importer.TheLog.LogWarning(Id, "Can't determine unit type for IfcPhysicalSimpleQuantity of type: " + attributeName, true);
                    BaseUnitType = UnitType.UT_Number;
                }
            }


            if (IFCUnit == null)
            {
                IFCUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(BaseUnitType);
            }
        }
        /// <summary>
        /// Create a label property.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <param name="valueType">The value type of the property.</param>
        /// <returns>The created property handle.</returns>
        public static IFCAnyHandle CreateElectricalCurrentMeasureProperty(IFCFile file, string propertyName, double value, PropertyValueType valueType)
        {
            switch (valueType)
            {
            case PropertyValueType.EnumeratedValue:
            {
                IList <IFCData> valueList = new List <IFCData>();
                valueList.Add(IFCDataUtil.CreateAsElectricalCurrentMeasure(value));
                return(IFCInstanceExporter.CreatePropertyEnumeratedValue(file, propertyName, null, valueList, null));
            }

            case PropertyValueType.SingleValue:
                return(IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, IFCDataUtil.CreateAsElectricalCurrentMeasure(value), null));

            default:
                throw new InvalidOperationException("Missing case!");
            }
        }
Example #4
0
        public static IFCAnyHandle GetOrCreateMaterialStyle(Document document, ExporterIFC exporterIFC, ElementId materialId)
        {
            IFCAnyHandle styleHnd = ExporterCacheManager.MaterialIdToStyleHandleCache.Find(materialId);

            if (styleHnd == null)
            {
                Material material = document.GetElement(materialId) as Material;
                if (material == null)
                {
                    return(null);
                }

                string matName = material.Name;

                Color  color    = material.Color;
                double blueVal  = color.Blue / 255.0;
                double greenVal = color.Green / 255.0;
                double redVal   = color.Red / 255.0;

                IFCFile      file     = exporterIFC.GetFile();
                IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal);

                double  transparency = ((double)material.Transparency) / 100.0;
                IFCData smoothness   = IFCDataUtil.CreateAsNormalisedRatioMeasure(((double)material.Smoothness) / 100.0);

                IFCData specularExp = IFCDataUtil.CreateAsSpecularExponent(material.Shininess);

                IFCReflectanceMethod method = IFCReflectanceMethod.NotDefined;

                IFCAnyHandle renderingHnd = IFCInstanceExporter.CreateSurfaceStyleRendering(file, colorHnd, transparency,
                                                                                            null, null, null, null, smoothness, specularExp, method);

                ICollection <IFCAnyHandle> surfStyles = new HashSet <IFCAnyHandle>();
                surfStyles.Add(renderingHnd);

                IFCSurfaceSide surfSide = IFCSurfaceSide.Both;
                styleHnd = IFCInstanceExporter.CreateSurfaceStyle(file, matName, surfSide, surfStyles);
                ExporterCacheManager.MaterialIdToStyleHandleCache.Register(materialId, styleHnd);
            }

            return(styleHnd);
        }
        /// <summary>
        /// Create a label property.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <param name="valueType">The value type of the property.</param>
        /// <returns>The created property handle.</returns>
        public static IFCAnyHandle CreatePositivePlaneAngleMeasureProperty(IFCFile file, string propertyName, double value, PropertyValueType valueType)
        {
            // Ensure it is positive.  Don't throw, but should tell user.
            if (value <= MathUtil.Eps())
            {
                return(null);
            }

            switch (valueType)
            {
            case PropertyValueType.EnumeratedValue:
            {
                IList <IFCData> valueList = new List <IFCData>();
                valueList.Add(IFCDataUtil.CreateAsPositivePlaneAngleMeasure(value));
                return(IFCInstanceExporter.CreatePropertyEnumeratedValue(file, propertyName, null, valueList, null));
            }

            case PropertyValueType.SingleValue:
                return(IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, IFCDataUtil.CreateAsPositivePlaneAngleMeasure(value), null));

            default:
                throw new InvalidOperationException("Missing case!");
            }
        }
Example #6
0
        /// <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);
            }
        }
Example #7
0
        /// <summary>
        /// Get the handles of Grid Axes.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="sameDirectionAxes">The grid axes in the same direction of one level.</param>
        /// <param name="representations">The representation of grid axis.</param>
        /// <returns>The list of handles of grid axes.</returns>
        private static List <IFCAnyHandle> CreateIFCGridAxisAndRepresentations(ExporterIFC exporterIFC, ProductWrapper productWrapper, IList <Grid> sameDirectionAxes,
                                                                               IList <IFCAnyHandle> representations, GridRepresentationData gridRepresentationData)
        {
            if (sameDirectionAxes.Count == 0)
            {
                return(null);
            }

            IDictionary <ElementId, List <IFCAnyHandle> > gridAxisMap = new Dictionary <ElementId, List <IFCAnyHandle> >();
            IDictionary <ElementId, List <IFCAnyHandle> > gridRepMap  = new Dictionary <ElementId, List <IFCAnyHandle> >();

            IFCFile ifcFile  = exporterIFC.GetFile();
            Grid    baseGrid = sameDirectionAxes[0];

            Transform lcs = Transform.Identity;

            List <IFCAnyHandle> ifcGridAxes = new List <IFCAnyHandle>();

            foreach (Grid grid in sameDirectionAxes)
            {
                // Because the IfcGrid is a collection of Revit Grids, any one of them can override the IFC CAD Layer.
                // We will take the first name, and not do too much checking.
                if (string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer))
                {
                    ParameterUtil.GetStringValueFromElementOrSymbol(grid, "IFCCadLayer", out gridRepresentationData.m_IFCCADLayer);
                }

                // Get the handle of curve.
                XYZ          projectionDirection = lcs.BasisZ;
                IFCAnyHandle axisCurve;
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                {
                    axisCurve = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, grid.Curve, lcs, projectionDirection);
                }
                else
                {
                    IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, lcs, projectionDirection, false);
                    ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, grid.Curve, XYZ.Zero, false);
                    IList <IFCAnyHandle> curves = info.GetCurves();
                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    axisCurve = curves[0];
                }

                bool sameSense = true;
                if (baseGrid.Curve is Line)
                {
                    Line baseLine = baseGrid.Curve as Line;
                    Line axisLine = grid.Curve as Line;
                    sameSense = (axisLine.Direction.IsAlmostEqualTo(baseLine.Direction));
                }

                IFCAnyHandle ifcGridAxis = IFCInstanceExporter.CreateGridAxis(ifcFile, grid.Name, axisCurve, sameSense);
                ifcGridAxes.Add(ifcGridAxis);

                HashSet <IFCAnyHandle> AxisCurves = new HashSet <IFCAnyHandle>();
                AxisCurves.Add(axisCurve);

                IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(ifcFile, AxisCurves);

                // get the weight and color from the GridType to create the curve style.
                GridType gridType = grid.Document.GetElement(grid.GetTypeId()) as GridType;

                IFCData curveWidth = null;
                if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
                {
                    int    outWidth;
                    double width =
                        (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_WEIGHT, out outWidth) != null) ? outWidth : 1;
                    curveWidth = IFCDataUtil.CreateAsPositiveLengthMeasure(width);
                }

                if (!ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                {
                    int outColor;
                    int color =
                        (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_COLOR, out outColor) != null) ? outColor : 0;
                    double blueVal  = 0.0;
                    double greenVal = 0.0;
                    double redVal   = 0.0;
                    GeometryUtil.GetRGBFromIntValue(color, out blueVal, out greenVal, out redVal);
                    IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(ifcFile, null, redVal, greenVal, blueVal);

                    BodyExporter.CreateCurveStyleForRepItem(exporterIFC, repItemHnd, curveWidth, colorHnd);
                }

                HashSet <IFCAnyHandle> curveSet = new HashSet <IFCAnyHandle>();
                curveSet.Add(repItemHnd);

                gridRepresentationData.m_Grids.Add(grid);
                gridRepresentationData.m_curveSets.Add(curveSet);
            }

            return(ifcGridAxes);
        }
Example #8
0
        /// <summary>
        /// Creates IfcPresentationStyleAssignment for text element type.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textElemType">
        /// The text note element type.
        /// </param>
        /// <param name="cache">
        /// The cache of IfcPresentationStyleAssignment.
        /// </param>
        static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache)
        {
            IFCFile file = exporterIFC.GetFile();

            string fontName;

            if (ParameterUtil.GetStringValueFromElement(textElemType, BuiltInParameter.TEXT_FONT, out fontName) == null)
            {
                fontName = null;
            }

            double fontSize;

            if (ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize) == null)
            {
                fontSize = -1.0;
            }

            double viewScale = 100.0; // currently hardwired.

            fontSize = UnitUtil.ScaleLength(fontSize * viewScale);

            string ifcPreDefinedItemName = "Text Font";

            IList <string> fontNameList = new List <string>();

            fontNameList.Add(fontName);

            IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize));

            int color;

            ParameterUtil.GetIntValueFromElement(textElemType, BuiltInParameter.LINE_COLOR, out color);

            double blueVal  = ((double)((color & 0xff0000) >> 16)) / 255.0;
            double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0;
            double redVal   = ((double)(color & 0xff)) / 255.0;

            IFCAnyHandle colorHnd     = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal);
            IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null);

            string       ifcAttrName  = textElemType.Name;
            IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd))
            {
                return;
            }

            HashSet <IFCAnyHandle> presStyleSet = new HashSet <IFCAnyHandle>();

            presStyleSet.Add(textStyleHnd);

            IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd))
            {
                return;
            }

            cache.Register(textElemType.Id, presStyleHnd);
        }
Example #9
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);
            }
        }
        /// <summary>
        /// Create a label property.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <param name="valueType">The value type of the property.</param>
        /// <returns>The created property handle.</returns>
        public static IFCAnyHandle CreateElectricalVoltageMeasureProperty(IFCFile file, string propertyName, double value, PropertyValueType valueType)
        {
            IFCData electricalVoltageData = IFCDataUtil.CreateAsElectricalVoltageMeasure(value);

            return(CreateCommonProperty(file, propertyName, electricalVoltageData, valueType, null));
        }
Example #11
0
        /// <summary>
        /// Creates IfcPresentationStyleAssignment for text element type.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textElemType">
        /// The text note element type.
        /// </param>
        /// <param name="cache">
        /// The cache of IfcPresentationStyleAssignment.
        /// </param>
        static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache)
        {
            IFCFile file = exporterIFC.GetFile();

            Parameter fontNameParam = textElemType.get_Parameter(BuiltInParameter.TEXT_FONT);
            string    fontName      = (fontNameParam != null && fontNameParam.StorageType == StorageType.String) ? fontNameParam.AsString() : null;


            Parameter fontSizeParam = textElemType.get_Parameter(BuiltInParameter.TEXT_SIZE);
            double    fontSize      = (fontSizeParam != null && fontSizeParam.StorageType == StorageType.Double) ? fontSizeParam.AsDouble() : -1.0;

            double scale     = exporterIFC.LinearScale;
            double viewScale = 100.0;  // currently hardwired.

            fontSize *= (scale * viewScale);

            string ifcPreDefinedItemName = "Text Font";

            IList <string> fontNameList = new List <string>();

            fontNameList.Add(fontName);

            IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize));

            Parameter fontColorParam = textElemType.get_Parameter(BuiltInParameter.LINE_COLOR);
            int       color          = (fontColorParam != null && fontColorParam.StorageType == StorageType.Integer) ? fontColorParam.AsInteger() : 0;

            double blueVal  = ((double)((color & 0xff0000) >> 16)) / 255.0;
            double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0;
            double redVal   = ((double)(color & 0xff)) / 255.0;

            IFCAnyHandle colorHnd     = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal);
            IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null);

            string       ifcAttrName  = textElemType.Name;
            IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd))
            {
                return;
            }

            HashSet <IFCAnyHandle> presStyleSet = new HashSet <IFCAnyHandle>();

            presStyleSet.Add(textStyleHnd);

            IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd))
            {
                return;
            }

            cache.Register(textElemType.Id, presStyleHnd);
        }
Example #12
0
        /// <summary>Create a FrequencyMeasure property.</summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <param name="valueType">The value type of the property.</param>
        /// <returns>The created property handle.</returns>
        public static IFCAnyHandle CreateFrequencyProperty(IFCFile file, string propertyName, double value, PropertyValueType valueType)
        {
            IFCData frequencyData = IFCDataUtil.CreateAsFrequencyMeasure(value);

            return(CreateCommonProperty(file, propertyName, frequencyData, valueType, null));
        }
Example #13
0
        /// <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);
            }
        }