/// <summary>
        /// Create a label property, or retrieve from cache.
        /// </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 or cached property handle.</returns>
        public static IFCAnyHandle CreateElectricalCurrentMeasurePropertyFromCache(IFCFile file, string propertyName, double value, PropertyValueType valueType)
        {
            // We have a partial cache here - we will only cache multiples of 15 degrees.
            bool canCache = false;
            double ampsDiv5 = Math.Floor(value / 5.0 + 0.5);
            double integerAmps = ampsDiv5 * 5.0;
            if (MathUtil.IsAlmostEqual(value, integerAmps))
            {
                canCache = true;
                value = integerAmps;
            }

            IFCAnyHandle propertyHandle;
            if (canCache)
            {
                propertyHandle = ExporterCacheManager.PropertyInfoCache.ElectricalCurrentCache.Find(propertyName, value);
                if (propertyHandle != null)
                    return propertyHandle;
            }

            propertyHandle = CreateElectricalCurrentMeasureProperty(file, propertyName, value, valueType);

            if (canCache && !IFCAnyHandleUtil.IsNullOrHasNoValue(propertyHandle))
            {
                ExporterCacheManager.PropertyInfoCache.ElectricalCurrentCache.Add(propertyName, value, propertyHandle);
            }

            return propertyHandle;
        }
        /// <summary>
        /// Creates uniformat classification.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC.</param>
        /// <param name="file">The file.</param>
        /// <param name="element">The element.</param>
        /// <param name="elemHnd">The element handle.</param>
        public static void CreateUniformatClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd)
        {
            // Create Uniformat classification, if it is not set.
            string uniformatKeyString = "Uniformat";
            string uniformatCode = "";
            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, BuiltInParameter.UNIFORMAT_CODE, false, out uniformatCode) == null)
                ParameterUtil.GetStringValueFromElementOrSymbol(element, "Assembly Code", out uniformatCode);
            string uniformatDescription = "";

            if (!String.IsNullOrWhiteSpace(uniformatCode))
            {
                if (ParameterUtil.GetStringValueFromElementOrSymbol(element, BuiltInParameter.UNIFORMAT_DESCRIPTION, false, out uniformatDescription) == null)
                    ParameterUtil.GetStringValueFromElementOrSymbol(element, "Assembly Description", out uniformatDescription);
            }

            IFCAnyHandle classification;
            if (!ExporterCacheManager.ClassificationCache.ClassificationHandles.TryGetValue(uniformatKeyString, out classification))
            {
                classification = IFCInstanceExporter.CreateClassification(file, "http://www.csiorg.net/uniformat", "1998", null, uniformatKeyString);
                ExporterCacheManager.ClassificationCache.ClassificationHandles.Add(uniformatKeyString, classification);
            }

                InsertClassificationReference(exporterIFC, file, element, elemHnd, uniformatKeyString, uniformatCode, uniformatDescription, "http://www.csiorg.net/uniformat" );

        }
Example #3
0
        /// <summary>
        /// Creates uniformat classification.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC.</param>
        /// <param name="file">The file.</param>
        /// <param name="element">The element.</param>
        /// <param name="elemHnd">The element handle.</param>
        public static void CreateUniformatClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd)
        {
            // Create Uniformat classification, if it is set.
            string uniformatCode = "";
            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, BuiltInParameter.UNIFORMAT_CODE, false, out uniformatCode) ||
                ParameterUtil.GetStringValueFromElementOrSymbol(element, "Assembly Code", out uniformatCode))
            {
                string uniformatDescription = "";
                if (!ParameterUtil.GetStringValueFromElementOrSymbol(element, BuiltInParameter.UNIFORMAT_DESCRIPTION, false, out uniformatDescription))
                    ParameterUtil.GetStringValueFromElementOrSymbol(element, "Assembly Description", out uniformatDescription);

                IFCAnyHandle classification;
                if (!ExporterCacheManager.ClassificationCache.TryGetValue("UniFormat", out classification))
                {
                    classification = IFCInstanceExporter.CreateClassification(file, "http://www.csiorg.net/uniformat", "1998", null, "UniFormat");
                    ExporterCacheManager.ClassificationCache.Add("UniFormat", classification);
                }

                IFCAnyHandle classificationReference = IFCInstanceExporter.CreateClassificationReference(file,
                  "http://www.csiorg.net/uniformat", uniformatCode, uniformatDescription, classification);

                HashSet<IFCAnyHandle> relatedObjects = new HashSet<IFCAnyHandle>();
                relatedObjects.Add(elemHnd);

                IFCAnyHandle relAssociates = IFCInstanceExporter.CreateRelAssociatesClassification(file, ExporterIFCUtils.CreateGUID(),
                   exporterIFC.GetOwnerHistoryHandle(), "UniFormatClassification", "", relatedObjects, classificationReference);
            }
        }
        /// <summary>
        /// Creates IfcAxis2Placement3D object.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="origin">
        /// The origin.
        /// </param>
        /// <param name="zDirection">
        /// The Z direction.
        /// </param>
        /// <param name="xDirection">
        /// The X direction.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateAxis(IFCFile file, XYZ origin, XYZ zDirection, XYZ xDirection)
        {
            IFCAnyHandle directionOpt = IFCAnyHandle.Create();
            IFCAnyHandle refOpt = IFCAnyHandle.Create();
            IFCAnyHandle location = IFCAnyHandle.Create();

            if (origin != null)
            {
                IList<double> measure = new List<double>();
                measure.Add(origin.X); measure.Add(origin.Y); measure.Add(origin.Z);
                location = CreateCartesianPoint(file, measure);
            }
            else
            {
                location = ExporterIFCUtils.GetGlobal3DOriginHandle();
            }

            bool exportzDirectionAndxDirection = (zDirection != null && xDirection != null && (!MathUtil.IsAlmostEqual(zDirection[2], 1.0) || !MathUtil.IsAlmostEqual(xDirection[0], 1.0)));

            if (exportzDirectionAndxDirection)
            {
                IList<double> axisPts = new List<double>();
                axisPts.Add(zDirection.X); axisPts.Add(zDirection.Y); axisPts.Add(zDirection.Z);
                directionOpt = CreateDirection(file, axisPts);
            }

            if (exportzDirectionAndxDirection)
            {
                IList<double> axisPts = new List<double>();
                axisPts.Add(xDirection.X); axisPts.Add(xDirection.Y); axisPts.Add(xDirection.Z);
                refOpt = CreateDirection(file, axisPts);
            }

            return file.CreateAxis2Placement3D(location, directionOpt, refOpt);
        }
 /// <summary>
 /// Create a Frequency measure property from the element's parameter.
 /// </summary>
 /// <param name="file">The IFC file.</param>
 /// <param name="exporterIFC">The ExporterIFC.</param>
 /// <param name="elem">The Element.</param>
 /// <param name="revitParameterName">The name of the parameter.</param>
 /// <param name="ifcPropertyName">The name of the property.</param>
 /// <param name="valueType">The value type of the property.</param>
 /// <returns>The created property handle.</returns>
 public static IFCAnyHandle CreateFrequencyPropertyFromElement(IFCFile file, ExporterIFC exporterIFC, Element elem,
     string revitParameterName, string ifcPropertyName, PropertyValueType valueType)
 {
     double propertyValue;
     if (ParameterUtil.GetDoubleValueFromElement(elem, null, revitParameterName, out propertyValue) != null)
         return CreateFrequencyProperty(file, ifcPropertyName, propertyValue, valueType);
     return null;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="exporterIFC"></param>
        /// <param name="file"></param>
        /// <param name="element"></param>
        /// <param name="elemHnd"></param>
        /// <param name="location"></param>
        public static void CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd, string location)
        {
            string paramClassificationCode = "";
            string classificationName = null;
            string classificationCode = null;
            string classificationDescription = null;
            // For now the support is fixed to 10 predefined classification code parameter names (to support limitation of schedule key that supports only one category per schedule key and needs one parameter for each)
            int noClassCodeParam = 10;
            string [] classCodeParamName = {"ClassificationCode", "ClassificationCode(2)", "ClassificationCode(3)", "ClassificationCode(4)", "ClassificationCode(5)",
                                           "ClassificationCode(6)", "ClassificationCode(7)", "ClassificationCode(8)", "ClassificationCode(9)", "ClassificationCode(10)"}; 
            int ret = 0;

            for (int n = 0; n < noClassCodeParam; n++)
            {
                // Create A classification, if it is not set.
                if (ParameterUtil.GetStringValueFromElementOrSymbol(element, classCodeParamName[n], out paramClassificationCode))
                {
                    ret = parseClassificationCode(paramClassificationCode, out classificationName, out classificationCode, out classificationDescription);

                    if (string.IsNullOrEmpty(classificationName))
                        classificationName = "Default Classification";

                    IFCAnyHandle classification;
                    if (!ExporterCacheManager.ClassificationCache.TryGetValue(classificationName, out classification))
                    {
                        IFCClassificationMgr savedClassificationFromUI = new IFCClassificationMgr();
                        IFCClassification savedClassification = new IFCClassification();

                        if (savedClassificationFromUI.GetSavedClassificationByName(element.Document, classificationName, out savedClassification))
                        {
                            if (savedClassification.ClassificationEditionDate == null)
                            {
                                IFCAnyHandle editionDate = IFCInstanceExporter.CreateCalendarDate(file, savedClassification.ClassificationEditionDate.Day, savedClassification.ClassificationEditionDate.Month, savedClassification.ClassificationEditionDate.Year);

                                classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition,
                                    editionDate, savedClassification.ClassificationName);
                            }
                            else
                                classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition,
                                    null, savedClassification.ClassificationName);
                        }
                        else
                            classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName);

                        ExporterCacheManager.ClassificationCache.Add(classificationName, classification);
                        if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation))
                            ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation);
                    }

                    if (String.IsNullOrEmpty(location))
                    {
                        ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location);
                    }
                    InsertClassificationReference(exporterIFC, file, element, elemHnd, classificationName, classificationCode, classificationDescription, location);
                }
            }
        }
        /// <summary>
        /// Creates a handle representing an IfcActor and assigns it to the file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="ownerHistory">The owner history.</param>
        /// <param name="name">The name</param>
        /// <param name="description">The description</param>
        /// <param name="objectType">The object type.</param>
        /// <param name="theActor">The actor.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle CreateActor(IFCFile file, string guid, IFCAnyHandle ownerHistory,
            string name, string description, string objectType, IFCAnyHandle theActor)
        {
            ValidateActor(guid, ownerHistory, name, description, objectType, theActor);

            IFCAnyHandle actorHandle = CreateInstance(file, IFCEntityType.IfcActor);
            SetActor(actorHandle, guid, ownerHistory, name, description, objectType, theActor);
            return actorHandle;
        }
 /// <summary>
 /// Creates handles for the quantities.
 /// </summary>
 /// <param name="file">The IFC file.</param>
 /// <param name="exporterIFC">The ExporterIFC class.</param>
 /// <param name="ifcParams">The extrusion creation data, used to get extra parameter information.</param>
 /// <param name="elementToUse">The base element.</param>
 /// <param name="elemTypeToUse">The base element type.</param>
 /// <returns>A set of quantities handles.</returns>
 public HashSet<IFCAnyHandle> ProcessEntries(IFCFile file, ExporterIFC exporterIFC, IFCExtrusionCreationData ifcParams, Element elementToUse, ElementType elemTypeToUse)
 {
     HashSet<IFCAnyHandle> props = new HashSet<IFCAnyHandle>();
     foreach (QuantityEntry entry in m_Entries)
     {
         IFCAnyHandle propHnd = entry.ProcessEntry(file, exporterIFC, ifcParams, elementToUse, elemTypeToUse);
         if (!IFCAnyHandleUtil.IsNullOrHasNoValue(propHnd))
             props.Add(propHnd);
     }
     return props;
 }
        /// <summary>
        /// Creates an IfcActuatorType, and assigns it to the file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="guid">The GUID.</param>
        /// <param name="ownerHistory">The owner history.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="applicableOccurrence">The attribute optionally defines the data type of the occurrence object.</param>
        /// <param name="propertySets">The property set(s) associated with the type.</param>
        /// <param name="representationMaps">The mapped geometries associated with the type.</param>
        /// <param name="elementTag">The tag that represents the entity.</param>
        /// <param name="elementType">The type name.</param>
        /// <param name="predefinedType">The predefined types.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle CreateActuatorType(IFCFile file, string guid, IFCAnyHandle ownerHistory, string name,
            string description, string applicableOccurrence, HashSet<IFCAnyHandle> propertySets,
            IList<IFCAnyHandle> representationMaps, string elementTag, string elementType, IFCActuatorType predefinedType)
        {
            ValidateElementType(guid, ownerHistory, name, description, applicableOccurrence, propertySets,
                representationMaps, elementTag, elementType);

            IFCAnyHandle actuatorType = CreateInstance(file, IFCEntityType.IfcActuatorType);
            IFCAnyHandleUtil.SetAttribute(actuatorType, "PredefinedType", predefinedType);
            SetElementType(actuatorType, guid, ownerHistory, name, description, applicableOccurrence, propertySets,
                representationMaps, elementTag, elementType);
            return actuatorType;
        }
 /// <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 #11
0
        private static IFCAnyHandle CreateSweptDiskSolid(ExporterIFC exporterIFC, IFCFile file, Curve centerCurve, double radius)
        {
            IList<Curve> curves = new List<Curve>();
            double endParam = 0.0;
            if (centerCurve is Arc || centerCurve is Ellipse)
            {
                if (centerCurve.IsBound)
                    endParam = (centerCurve.get_EndParameter(1) - centerCurve.get_EndParameter(0)) * 180 / Math.PI;
                else
                    endParam = (2 * Math.PI) * 180 / Math.PI;
            }
            else
                endParam = 1.0;
            curves.Add(centerCurve);

            IFCAnyHandle compositeCurve = GeometryUtil.CreateCompositeCurve(exporterIFC, curves);
            return IFCInstanceExporter.CreateSweptDiskSolid(file, compositeCurve, radius, null, 0, endParam);
        }
        /// <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!");
            }
        }
 protected static IFCAnyHandle CreateCommonProperty(IFCFile file, string propertyName, IFCData valueData, PropertyValueType valueType, string unitTypeKey)
 {
     switch (valueType)
     {
         case PropertyValueType.EnumeratedValue:
             {
                 IList<IFCData> valueList = new List<IFCData>();
                 valueList.Add(valueData);
                 return IFCInstanceExporter.CreatePropertyEnumeratedValue(file, propertyName, null, valueList, null);
             }
         case PropertyValueType.SingleValue:
             {
                 if (unitTypeKey != null)
                     return IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, valueData, ExporterCacheManager.UnitsCache[unitTypeKey]);
                 else
                     return IFCInstanceExporter.CreatePropertySingleValue(file, propertyName, null, valueData, null);
             }
         default:
             throw new InvalidOperationException("Missing case!");
     }
 }
Example #14
0
        /// <summary>
        /// Create a Frequency measure property from the element's or type's parameter.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="exporterIFC">The ExporterIFC.</param>
        /// <param name="elem">The Element.</param>
        /// <param name="revitParameterName">The name of the parameter.</param>
        /// <param name="revitBuiltInParam">The built in parameter to use, if revitParameterName isn't found.</param>
        /// <param name="ifcPropertyName">The name of the property.</param>
        /// <param name="valueType">The value type of the property.</param>
        /// <returns>The created property handle.</returns>
        public static IFCAnyHandle CreateFrequencyPropertyFromElementOrSymbol(IFCFile file, ExporterIFC exporterIFC, Element elem,
            string revitParameterName, BuiltInParameter revitBuiltInParam, string ifcPropertyName, PropertyValueType valueType)
        {
            IFCAnyHandle propHnd = CreateFrequencyPropertyFromElement(file, exporterIFC, elem, revitParameterName, ifcPropertyName, valueType);
            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(propHnd))
                return propHnd;

            if (revitBuiltInParam != BuiltInParameter.INVALID)
            {
                string builtInParamName = LabelUtils.GetLabelFor(revitBuiltInParam);
                propHnd = CreateFrequencyPropertyFromElement(file, exporterIFC, elem, builtInParamName, ifcPropertyName, valueType);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(propHnd))
                    return propHnd;
            }

            // For Symbol
            Document document = elem.Document;
            ElementId typeId = elem.GetTypeId();
            Element elemType = document.GetElement(typeId);
            if (elemType != null)
                return CreateFrequencyPropertyFromElementOrSymbol(file, exporterIFC, elemType, revitParameterName, revitBuiltInParam, ifcPropertyName, valueType);
            else
                return null;
        }
Example #15
0
 /// <summary>
 /// Creates IfcMappedItem object at (0,0,0).
 /// </summary>
 /// <param name="file">
 /// The IFC file.
 /// </param>
 /// <param name="repMap">
 /// The handle to be mapped.
 /// </param>
 /// <param name="orig">
 /// The orig for mapping transformation.
 /// </param>
 /// <returns>
 /// The handle.
 /// </returns>
 public static IFCAnyHandle CreateDefaultMappedItem(IFCFile file, IFCAnyHandle repMap)
 {
     IFCAnyHandle transformHnd = ExporterCacheManager.GetDefaultCartesianTransformationOperator3D(file);
     return IFCInstanceExporter.CreateMappedItem(file, repMap, transformHnd);
 }
Example #16
0
        /// <summary>
        /// Creates IfcMappedItem object from an origin.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="repMap">
        /// The handle to be mapped.
        /// </param>
        /// <param name="orig">
        /// The orig for mapping transformation.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateDefaultMappedItem(IFCFile file, IFCAnyHandle repMap, XYZ orig)
        {
            if (MathUtil.IsAlmostZero(orig.X) && MathUtil.IsAlmostZero(orig.Y) && MathUtil.IsAlmostZero(orig.Z))
                return CreateDefaultMappedItem(file, repMap);

            IFCAnyHandle origin = CreateCartesianPoint(file, orig);
            double scale = 1.0;
            IFCAnyHandle mappingTarget =
               IFCInstanceExporter.CreateCartesianTransformationOperator3D(file, null, null, origin, scale, null);
            return IFCInstanceExporter.CreateMappedItem(file, repMap, mappingTarget);
        }
Example #17
0
 /// <summary>
 /// Creates a default IfcAxis2Placement3D object.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <returns>The handle.</returns>
 public static IFCAnyHandle CreateAxis2Placement3D(IFCFile file)
 {
     return CreateAxis2Placement3D(file, null);
 }
Example #18
0
 /// <summary>
 /// Creates an IfcAxis2Placement3D object.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="location">The origin.</param>
 /// <returns>The handle.</returns>
 public static IFCAnyHandle CreateAxis2Placement3D(IFCFile file, XYZ location)
 {
     return CreateAxis2Placement3D(file, location, null, null);
 }
Example #19
0
        /// <summary>
        /// Creates an IfcAxis2Placement3D object.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="location">The origin. If null, it will use the global origin handle.</param>
        /// <param name="axis">The Z direction.</param>
        /// <param name="refDirection">The X direction.</param>
        /// <returns>the handle.</returns>
        public static IFCAnyHandle CreateAxis2Placement3D(IFCFile file, XYZ location, XYZ axis, XYZ refDirection)
        {
            IFCAnyHandle locationHandle = null;
            if (location != null)
            {
                List<double> measure = new List<double>();
                measure.Add(location.X);
                measure.Add(location.Y);
                measure.Add(location.Z);
                locationHandle = CreateCartesianPoint(file, measure);
            }
            else
            {
                locationHandle = ExporterIFCUtils.GetGlobal3DOriginHandle();
            }


            bool exportDirAndRef = (axis != null && refDirection != null &&
                (!MathUtil.IsAlmostEqual(axis[2], 1.0) || !MathUtil.IsAlmostEqual(refDirection[0], 1.0)));

            if ((axis != null) ^ (refDirection != null))
            {
                exportDirAndRef = false;
            }

            IFCAnyHandle axisHandle = null;
            if (exportDirAndRef)
            {
                List<double> measure = new List<double>();
                measure.Add(axis.X);
                measure.Add(axis.Y);
                measure.Add(axis.Z);
                axisHandle = CreateDirection(file, measure);
            }

            IFCAnyHandle refDirectionHandle = null;
            if (exportDirAndRef)
            {
                List<double> measure = new List<double>();
                measure.Add(refDirection.X);
                measure.Add(refDirection.Y);
                measure.Add(refDirection.Z);
                refDirectionHandle = CreateDirection(file, measure);
            }

            return IFCInstanceExporter.CreateAxis2Placement3D(file, locationHandle, axisHandle, refDirectionHandle);
        }
Example #20
0
        /// <summary>
        /// Creates IfcCartesianPoint object.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="measure">
        /// The list of doubles to create the Cartesian point.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateCartesianPoint(IFCFile file, IList<double> measure)
        {
            IList<double> cleanMeasure = new List<double>();
            foreach (double value in measure)
            {
                double ceilMeasure = Math.Ceiling(value);
                double floorMeasure = Math.Floor(value);

                if (MathUtil.IsAlmostEqual(value, ceilMeasure))
                    cleanMeasure.Add(ceilMeasure);
                else if (MathUtil.IsAlmostEqual(value, floorMeasure))
                    cleanMeasure.Add(floorMeasure);
                else
                    cleanMeasure.Add(value);
            }

            if (MathUtil.IsAlmostZero(cleanMeasure[0]) && MathUtil.IsAlmostZero(cleanMeasure[1]))
            {
                if (measure.Count == 2)
                {
                    return ExporterIFCUtils.GetGlobal2DOriginHandle();
                }
                if (measure.Count == 3 && MathUtil.IsAlmostZero(cleanMeasure[2]))
                {
                    return ExporterIFCUtils.GetGlobal3DOriginHandle();
                }

            }

            IFCAnyHandle pointHandle = IFCInstanceExporter.CreateCartesianPoint(file, cleanMeasure);

            return pointHandle;
        }
Example #21
0
 /// <summary>
 /// Creates IfcDirection object.
 /// </summary>
 /// <param name="file">
 /// The IFC file.
 /// </param>
 /// <param name="direction">
 /// The direction.
 /// </param>
 /// <returns>
 /// The handle.
 /// </returns>
 public static IFCAnyHandle CreateDirection(IFCFile file, XYZ direction)
 {
     IList<double> measure = new List<double>();
     measure.Add(direction.X);
     measure.Add(direction.Y);
     measure.Add(direction.Z);
     return CreateDirection(file, measure);
 }
Example #22
0
 /// <summary>
 /// Creates a new local placement object.
 /// </summary>
 /// <param name="file">The IFC file.</param>
 /// <param name="placementRelTo">The placement object.</param>
 /// <param name="location">The relative placement origin.</param>
 /// <param name="axis">The relative placement Z value.</param>
 /// <param name="refDirection">The relative placement X value.</param>
 /// <returns></returns>
 public static IFCAnyHandle CreateLocalPlacement(IFCFile file, IFCAnyHandle placementRelTo, XYZ location, XYZ axis, XYZ refDirection)
 {
     IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, location, axis, refDirection);
     return IFCInstanceExporter.CreateLocalPlacement(file, placementRelTo, relativePlacement);
 }
Example #23
0
 /// <summary>
 /// Creates a copy of local placement object.
 /// </summary>
 /// <param name="file">
 /// The IFC file.
 /// </param>
 /// <param name="originalPlacement">
 /// The original placement object to be copied.
 /// </param>
 /// <returns>
 /// The handle.
 /// </returns>
 public static IFCAnyHandle CopyLocalPlacement(IFCFile file, IFCAnyHandle originalPlacement)
 {
     IFCAnyHandle placementRelToOpt = GeometryUtil.GetPlacementRelToFromLocalPlacement(originalPlacement);
     IFCAnyHandle relativePlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(originalPlacement);
     return IFCInstanceExporter.CreateLocalPlacement(file, placementRelToOpt, relativePlacement);
 }
Example #24
0
 /// <summary>
 /// Creates IfcMappedItem object from a transform
 /// </summary>
 /// <param name="file">
 /// The IFC file.
 /// </param>
 /// <param name="repMap">
 /// The handle to be mapped.
 /// </param>
 /// <param name="transform">
 /// The transform.
 /// </param>
 /// <returns>
 /// The handle.
 /// </returns>
 public static IFCAnyHandle CreateMappedItemFromTransform(IFCFile file, IFCAnyHandle repMap, Transform transform)
 {
     IFCAnyHandle axis1 = CreateDirection(file, transform.BasisX);
     IFCAnyHandle axis2 = CreateDirection(file, transform.BasisY);
     IFCAnyHandle axis3 = CreateDirection(file, transform.BasisZ);
     IFCAnyHandle origin = CreateCartesianPoint(file, transform.Origin);
     double scale = 1.0;
     IFCAnyHandle mappingTarget =
        IFCInstanceExporter.CreateCartesianTransformationOperator3D(file, axis1, axis2, origin, scale, axis3);
     return IFCInstanceExporter.CreateMappedItem(file, repMap, mappingTarget);
 }
Example #25
0
        /// <summary>
        /// Creates an IfcPolyLine from a list of UV points.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="polylinePts">This list of UV values.</param>
        /// <returns>An IfcPolyline handle.</returns>
        public static IFCAnyHandle CreatePolyline(IFCFile file, IList<UV> polylinePts)
        {
            int numPoints = polylinePts.Count;
            if (numPoints < 2)
                return null;

            bool closed = MathUtil.IsAlmostEqual(polylinePts[0], polylinePts[numPoints - 1]);
            if (closed)
            {
                if (numPoints == 2)
                    return null;
                numPoints--;
            }

            IList<IFCAnyHandle> points = new List<IFCAnyHandle>();
            for (int ii = 0; ii < numPoints; ii++)
            {
                points.Add(CreateCartesianPoint(file, polylinePts[ii]));
            }
            if (closed)
                points.Add(points[0]);

            return IFCInstanceExporter.CreatePolyline(file, points);
        }
Example #26
0
        /// <summary>
        /// Creates IfcCartesianPoint object from a 3D point.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="point">The point</param>
        /// <returns>The IfcCartesianPoint handle.</returns>
        public static IFCAnyHandle CreateCartesianPoint(IFCFile file, XYZ point)
        {
            if (point == null)
                throw new ArgumentNullException("point");

            List<double> points = new List<double>();
            points.Add(point.X);
            points.Add(point.Y);
            points.Add(point.Z);

            return CreateCartesianPoint(file, points);
        }
Example #27
0
 /// <summary>
 /// Creates a new local placement object.
 /// </summary>
 /// <param name="file">The IFC file.</param>
 /// <param name="placementRelTo">The placement object.</param>
 /// <param name="relativePlacement">The relative placement. Null to create a identity relative placement.</param>
 /// <returns></returns>
 public static IFCAnyHandle CreateLocalPlacement(IFCFile file, IFCAnyHandle placementRelTo, IFCAnyHandle relativePlacement)
 {
     if (relativePlacement == null)
     {
         relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
     }
     return IFCInstanceExporter.CreateLocalPlacement(file, placementRelTo, relativePlacement);
 }
Example #28
0
        /// <summary>
        /// Create an IfcCreateCurveBoundedPlane given a polygonal outer boundary and 0 or more polygonal inner boundaries.
        /// </summary>
        /// <param name="file">The IFCFile.</param>
        /// <param name="newOuterLoopPoints">The list of points representating the outer boundary of the plane.</param>
        /// <param name="innerLoopPoints">The list of inner boundaries of the plane.  This list can be null.</param>
        /// <returns>The IfcCreateCurveBoundedPlane.</returns>
        public static IFCAnyHandle CreateCurveBoundedPlane(IFCFile file, IList<XYZ> newOuterLoopPoints, IList<IList<XYZ>> innerLoopPoints)
        {
            if (newOuterLoopPoints == null)
                return null;

            // We need at least 3 distinct points for the outer polygon.
            int outerSz = newOuterLoopPoints.Count;
            if (outerSz < 3)
                return null;

            // We allow the polygon to duplicate the first and last points, or not.  If the last point is duplicated, we will generally ignore it.
            bool firstIsLast = newOuterLoopPoints[0].IsAlmostEqualTo(newOuterLoopPoints[outerSz - 1]);
            if (firstIsLast && (outerSz == 3))
                return null;

            // Calculate the X direction of the plane using the first point and the next point that generates a valid direction.
            XYZ firstDir = null;
            int ii = 1;
            for (; ii < outerSz; ii++)
            {
                firstDir = (newOuterLoopPoints[ii] - newOuterLoopPoints[0]).Normalize();
                if (firstDir != null)
                    break;
            }
            if (firstDir == null)
                return null;

            // Calculate the Y direction of the plane using the first point and the next point that generates a valid direction that isn't
            // parallel to the first direction.
            XYZ secondDir = null;
            for (ii++; ii < outerSz; ii++)
            {
                secondDir = (newOuterLoopPoints[ii] - newOuterLoopPoints[0]).Normalize();
                if (secondDir == null)
                    continue;

                if (MathUtil.IsAlmostEqual(Math.Abs(firstDir.DotProduct(secondDir)), 1.0))
                    continue;

                break;
            }
            if (secondDir == null)
                return null;

            // Generate the normal of the plane, ensure it is valid.
            XYZ norm = firstDir.CrossProduct(secondDir);
            if (norm == null || norm.IsZeroLength())
                return null;

            norm = norm.Normalize();
            if (norm == null)
                return null;

            // The original secondDir was almost certainly not orthogonal to firstDir; generate an orthogonal direction.
            secondDir = norm.CrossProduct(firstDir);
            Plane projPlane = new Plane(firstDir, secondDir, newOuterLoopPoints[0]);

            if (firstIsLast)
                outerSz--;

            // Create the UV points before we create handles, to avoid deleting handles on failure.
            IList<UV> projVecData = new List<UV>();
            for (ii = 0; ii < outerSz; ii++)
            {
                UV uv = GeometryUtil.ProjectPointToPlane(projPlane, newOuterLoopPoints[ii]);
                if (uv == null)
                    return null;
                projVecData.Add(uv);
            }

            // Generate handles for outer bound.
            IList<IFCAnyHandle> polyLinePts = CreateCartesianPointList(file, projVecData);

            IFCAnyHandle outerBound = IFCInstanceExporter.CreatePolyline(file, polyLinePts);

            IFCAnyHandle origHnd = CreateCartesianPoint(file, newOuterLoopPoints[0]);
            IFCAnyHandle refHnd = CreateDirection(file, firstDir);
            IFCAnyHandle dirHnd = CreateDirection(file, norm);

            IFCAnyHandle positionHnd = IFCInstanceExporter.CreateAxis2Placement3D(file, origHnd, dirHnd, refHnd);
            IFCAnyHandle basisPlane = IFCInstanceExporter.CreatePlane(file, positionHnd);

            // We only assign innerBounds if we create any.  We expect innerBounds to be null if there aren't any created.
            ISet<IFCAnyHandle> innerBounds = null;
            if (innerLoopPoints != null)
            {
                int innerSz = innerLoopPoints.Count;
                for (ii = 0; ii < innerSz; ii++)
                {
                    IList<XYZ> currInnerLoopVecData = innerLoopPoints[ii];
                    int loopSz = currInnerLoopVecData.Count;

                    projVecData.Clear();
                    firstIsLast = currInnerLoopVecData[0].IsAlmostEqualTo(currInnerLoopVecData[outerSz - 1]);
                    
                    // Be lenient on what we find.
                    bool continueOnFailure = ((loopSz < 2) || (firstIsLast && (loopSz == 3)));
                    for (int jj = 0; jj < loopSz && !continueOnFailure; jj++)
                    {
                        UV uv = GeometryUtil.ProjectPointToPlane(projPlane, currInnerLoopVecData[jj]);
                        if (uv == null)
                            continueOnFailure = true;
                        else
                            projVecData.Add(uv);
                    }

                    // We allow for bad inners - we just ignore them.
                    if (continueOnFailure)
                        continue;

                    polyLinePts = CreateCartesianPointList(file, projVecData);
                    IFCAnyHandle polyLine = IFCInstanceExporter.CreatePolyline(file, polyLinePts);

                    if (innerBounds == null)
                        innerBounds = new HashSet<IFCAnyHandle>();
                    innerBounds.Add(polyLine);
                }
            }

            return IFCInstanceExporter.CreateCurveBoundedPlane(file, basisPlane, outerBound, innerBounds);
        }
Example #29
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);
                if (!success && RevitBuiltInParameter != BuiltInParameter.INVALID)
                    success = ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitBuiltInParameter, out val);
            }

            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;
        }
Example #30
0
        /// <summary>
        /// Creates IfcDirection object.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="realList">
        /// The list of doubles to create the direction.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateDirection(IFCFile file, IList<double> realList)
        {
            IList<double> cleanList = new List<double>();

            foreach (double measure in realList)
            {
                double ceilMeasure = Math.Ceiling(measure);
                double floorMeasure = Math.Floor(measure);

                if (MathUtil.IsAlmostEqual(measure, ceilMeasure))
                    cleanList.Add(ceilMeasure);
                else if (MathUtil.IsAlmostEqual(measure, floorMeasure))
                    cleanList.Add(floorMeasure);
                else
                    cleanList.Add(measure);
            }

            int sz = realList.Count;

            if (sz == 3)
            {
                for (int ii = 0; ii < 3; ii++)
                {
                    if (MathUtil.IsAlmostEqual(cleanList[ii], 1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[(ii + 1) % 3]) || !MathUtil.IsAlmostZero(cleanList[(ii + 2) % 3]))
                            break;
                        return ExporterIFCUtils.GetGlobal3DDirectionHandles(true)[ii];
                    }
                    else if (MathUtil.IsAlmostEqual(cleanList[ii], -1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[(ii + 1) % 3]) || !MathUtil.IsAlmostZero(cleanList[(ii + 2) % 3]))
                            break;
                        return ExporterIFCUtils.GetGlobal3DDirectionHandles(false)[ii];
                    }
                }
            }
            else if (sz == 2)
            {
                for (int ii = 0; ii < 2; ii++)
                {
                    if (MathUtil.IsAlmostEqual(cleanList[ii], 1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[1 - ii]))
                            break;
                        return ExporterIFCUtils.GetGlobal2DDirectionHandles(true)[ii];
                    }
                    else if (MathUtil.IsAlmostEqual(cleanList[ii], -1.0))
                    {
                        if (!MathUtil.IsAlmostZero(cleanList[1 - ii]))
                            break;
                        return ExporterIFCUtils.GetGlobal2DDirectionHandles(false)[ii];
                    }
                }
            }

            IFCAnyHandle directionHandle = IFCInstanceExporter.CreateDirection(file, cleanList);
            return directionHandle;
        }