Beispiel #1
0
        /// <summary>
        /// Calculates covering finish value.
        /// </summary>
        /// <remarks>
        /// True for structural columns, and false for architectural ones.
        /// </remarks>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            ParameterUtil.GetStringValueFromElementOrSymbol(element, "Finish", out m_Finish);
            if (!string.IsNullOrEmpty(m_Finish))
            {
                return(true);
            }

            if (element is Ceiling)
            {
                m_Finish = string.Empty;
                ISet <ElementId> matIds = HostObjectExporter.GetFinishMaterialIds(element as HostObject);
                foreach (ElementId matId in matIds)
                {
                    string materialName = NamingUtil.GetMaterialName(element.Document, matId);
                    if (string.IsNullOrWhiteSpace(materialName))
                    {
                        continue;
                    }
                    m_Finish += materialName + ";";
                }
                return(!string.IsNullOrEmpty(m_Finish));
            }
            return(false);
        }
        /// <summary>
        /// Calculates the reference.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            ParameterUtil.GetStringValueFromElementOrSymbol(element, "Reference", out m_ReferenceName);
            if (!string.IsNullOrEmpty(m_ReferenceName))
            {
                return(true);
            }

            if (elementType == null)
            {
                m_ReferenceName = element.Name;
            }
            else
            {
                if (ExporterCacheManager.ExportOptionsCache.NamingOptions.UseFamilyAndTypeNameForReference || String.IsNullOrEmpty(elementType.Name))
                {
                    if (!String.IsNullOrEmpty(elementType.Name))
                    {
                        m_ReferenceName = String.Format("{0}:{1}", elementType.FamilyName, element.Name);
                    }
                    else
                    {
                        m_ReferenceName = elementType.FamilyName;
                    }
                }
                else
                {
                    m_ReferenceName = elementType.Name;
                }
            }
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Calculates specific zones for a space.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param>
        /// <param name="element">The element to calculate the value.</param>
        /// <param name="elementType">The element type.</param>
        /// <returns>True if the operation succeed, false otherwise.</returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            string basePropSpecZoneString = "Project Specific Zone";
            int    val = 0;

            while (++val < 1000)   // prevent infinite loop.
            {
                string propSpecZoneString;
                if (val == 1)
                {
                    propSpecZoneString = basePropSpecZoneString;
                }
                else
                {
                    propSpecZoneString = basePropSpecZoneString + " " + val;
                }

                string value;
                if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, propSpecZoneString, out value) == null) ||
                    string.IsNullOrEmpty(value))
                {
                    break;
                }

                m_SpecificZones.Add(value);
            }

            return(m_SpecificZones.Count > 0);
        }
Beispiel #4
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 not set.
            string uniformatKeyString   = "Uniformat";
            string uniformatDescription = "";
            string uniformatCode        = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, BuiltInParameter.UNIFORMAT_CODE, false, out uniformatCode) == null)
            {
                ParameterUtil.GetStringValueFromElementOrSymbol(element, "Assembly Code", out uniformatCode);
            }

            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);
            }

            if (!String.IsNullOrEmpty(uniformatCode))
            {
                InsertClassificationReference(exporterIFC, file, elemHnd, uniformatKeyString, uniformatCode, uniformatDescription, "http://www.csiorg.net/uniformat");
            }
        }
Beispiel #5
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);
            }
        }
        private static IFCAssemblyPlace GetAssemblyPlace(Element element, string ifcEnumType)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = ifcEnumType;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(IFCAssemblyPlace.NotDefined);
            }

            string newValue = NamingUtil.RemoveSpacesAndUnderscores(value);

            if (String.Compare(newValue, "SITE", true) == 0)
            {
                return(IFCAssemblyPlace.Site);
            }
            if (String.Compare(newValue, "FACTORY", true) == 0)
            {
                return(IFCAssemblyPlace.Factory);
            }

            return(IFCAssemblyPlace.NotDefined);
        }
        private static IFCPileType GetPileType(Element element, string ifcEnumType)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = ifcEnumType;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(IFCPileType.NotDefined);
            }

            string newValue = NamingUtil.RemoveSpacesAndUnderscores(value);

            if (String.Compare(newValue, "COHESION", true) == 0)
            {
                return(IFCPileType.Cohesion);
            }
            if (String.Compare(newValue, "FRICTION", true) == 0)
            {
                return(IFCPileType.Friction);
            }
            if (String.Compare(newValue, "SUPPORT", true) == 0)
            {
                return(IFCPileType.Support);
            }

            return(IFCPileType.UserDefined);
        }
Beispiel #8
0
        /// <summary>
        /// Gets IFC covering type for an element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        public static Toolkit.IFCCoveringType GetIFCCoveringType(Element element, string typeName)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = typeName;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(Toolkit.IFCCoveringType.NotDefined);
            }

            string newValue = NamingUtil.RemoveSpacesAndUnderscores(value);

            if (String.Compare(newValue, "USERDEFINED", true) == 0)
            {
                return(Toolkit.IFCCoveringType.UserDefined);
            }
            if (String.Compare(newValue, "CEILING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Ceiling);
            }
            if (String.Compare(newValue, "FLOORING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Flooring);
            }
            if (String.Compare(newValue, "CLADDING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Cladding);
            }
            if (String.Compare(newValue, "ROOFING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Roofing);
            }
            if (String.Compare(newValue, "INSULATION", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Insulation);
            }
            if (String.Compare(newValue, "MEMBRANE", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Membrane);
            }
            if (String.Compare(newValue, "SLEEVING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Sleeving);
            }
            if (String.Compare(newValue, "WRAPPING", true) == 0)
            {
                return(Toolkit.IFCCoveringType.Wrapping);
            }

            return(Toolkit.IFCCoveringType.NotDefined);
        }
Beispiel #9
0
        /// <summary>
        /// Gets IFC footing type for an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="typeName">The type name.</param>
        /// <returns>The IFCFootingType.</returns>
        public static Toolkit.IFCFootingType GetIFCFootingType(Element element, string typeName)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = typeName;
            }

            return(GetIFCFootingType(value));
        }
        /// <summary>
        /// Calculates the reference.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "FireRating", out m_FireRating) == null)
            {
                ParameterUtil.GetStringValueFromElementOrSymbol(element, "Fire Rating", out m_FireRating);
            }
            if (!string.IsNullOrEmpty(m_FireRating))
            {
                return(true);
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// Gets IFC railing type for an element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        private static Toolkit.IFCRailingType GetIFCRailingType(Element element, string typeName)
        {
            string value = null;

            if (!ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value))
            {
                value = typeName;
            }
            if (String.IsNullOrEmpty(value))
            {
                return(Toolkit.IFCRailingType.NotDefined);
            }

            string newValue = value.Replace(" ", "").Replace("_", "");

            return(GetIFCRailingTypeFromString(newValue));
        }
        /// <summary>
        /// Calculates the reference.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param>
        /// <param name="element">The element to calculate the value.</param>
        /// <param name="elementType">The element type.</param>
        /// <returns>True if the operation succeed, false otherwise.</returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType, EntryMap entryMap)
        {
            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, entryMap.RevitParameterName, out m_ReferenceName) == null)
            {
                ParameterUtil.GetStringValueFromElementOrSymbol(element, entryMap.CompatibleRevitParameterName, out m_ReferenceName);
            }
            if (!string.IsNullOrEmpty(m_ReferenceName))
            {
                return(true);
            }

            // If the element is an element type, "Reference" doesn't mean much, since IFC doesn't
            // care about the type of a type.  We'll keep the override in place in case someone wants
            // to force it, but otherwise will not export the value.
            if (element is ElementType)
            {
                return(false);
            }

            if (elementType == null)
            {
                m_ReferenceName = element.Name;
            }
            else
            {
                string elementTypeName = elementType.Name;
                if (ExporterCacheManager.ExportOptionsCache.NamingOptions.UseFamilyAndTypeNameForReference ||
                    string.IsNullOrEmpty(elementTypeName))
                {
                    if (!String.IsNullOrEmpty(elementTypeName))
                    {
                        m_ReferenceName = String.Format("{0}:{1}", elementType.FamilyName, elementTypeName);
                    }
                    else
                    {
                        m_ReferenceName = elementType.FamilyName;
                    }
                }
                else
                {
                    m_ReferenceName = elementTypeName;
                }
            }
            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// Gets IFC railing type for an element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        private static Toolkit.IFCRailingType GetIFCRailingType(Element element, string typeName)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = typeName;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(Toolkit.IFCRailingType.NotDefined);
            }

            string newValue = NamingUtil.RemoveSpacesAndUnderscores(value);

            return(GetIFCRailingTypeFromString(newValue));
        }
        /// <summary>
        /// Get the IFC type from shared parameters, from a type name, or from a default value.
        /// </summary>
        /// <typeparam name="TEnum">The type of Enum.</typeparam>
        /// <param name="element">The element.</param>
        /// <param name="typeName">The type value.</param>
        /// <param name="defaultValue">A default value that can be null.</param>
        /// <returns>The found value, or null.</returns>
        public static string GetValidIFCType <TEnum>(Element element, string typeName, string defaultValue) where TEnum : struct
        {
            string value          = null;
            bool   canUseTypeName = true;

            if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcExportType", out value) == null) && // change IFCType to consistent parameter of IfcExportType
                (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null))         // support IFCType for legacy support
            {
                canUseTypeName = false;
                value          = typeName;
            }

            if (ValidateStrEnum <TEnum>(value) == null && value != "NotDefined")
            {
                if (canUseTypeName)
                {
                    value = typeName;
                    if (ValidateStrEnum <TEnum>(value) == null)
                    {
                        value = null;
                    }
                }
                else
                {
                    value = null;
                }
            }

            if (String.IsNullOrEmpty(value))
            {
                if (!String.IsNullOrEmpty(defaultValue))
                {
                    return(defaultValue);
                }

                // We used to return "NotDefined" here.  However, that assumed that all types had "NotDefined" as a value.
                // It is better to return null.
                return(null);
            }

            return(value);
        }
Beispiel #15
0
        /// <summary>
        /// Get the IFC type from shared parameters, from a type name, or from a default value.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="typeName">The type value.</param>
        /// <param name="defaultValue">A default value that can be null.</param>
        /// <returns>The found value.</returns>
        public static string GetValidIFCType(Element element, string typeName, string defaultValue)
        {
            string value = null;

            if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcExportType", out value) == null) && // change IFCType to consistent parameter of IfcExportType
                (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null))         // support IFCType for legacy support
            {
                value = typeName;
            }

            if (String.IsNullOrEmpty(value))
            {
                if (!String.IsNullOrEmpty(defaultValue))
                {
                    return(defaultValue);
                }
                return("NotDefined");
            }
            return(value);
        }
        /// <summary>
        /// Generic check for the PreDefinedType string from either IfcExportAs with (.predefinedtype), or IfcExportType param, or legacy IfcType param
        /// </summary>
        /// <typeparam name="TEnum">The Enum to verify</typeparam>
        /// <param name="element"></param>
        /// <param name="ifcEnumTypeStr">Enum String if already obtained from IfcExportAs or IfcExportType</param>
        /// <returns>"NotDeined if the string is not defined as Enum</returns>
        public static TEnum GetPreDefinedType <TEnum>(Element element, string ifcEnumTypeStr) where TEnum : struct
        {
            TEnum enumValue;

            Enum.TryParse("NotDefined", true, out enumValue);

            string value = null;

            if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcExportType", out value) == null) &&
                (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null))
            {
                value = ifcEnumTypeStr;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(enumValue);
            }

            Enum.TryParse(value, true, out enumValue);
            return(enumValue);
        }
Beispiel #17
0
        /// <summary>
        /// Gets IFC footing type for an element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        public static Toolkit.IFCFootingType GetIFCFootingType(Element element, string typeName)
        {
            string value = null;

            if (!ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value))
            {
                value = typeName;
            }
            if (String.IsNullOrEmpty(value))
            {
                return(Toolkit.IFCFootingType.NotDefined);
            }

            string newValue = value.Replace(" ", "").Replace("_", "");

            if (String.Compare(newValue, "USERDEFINED", true) == 0)
            {
                return(Toolkit.IFCFootingType.UserDefined);
            }
            if (String.Compare(newValue, "FOOTINGBEAM", true) == 0)
            {
                return(Toolkit.IFCFootingType.Footing_Beam);
            }
            if (String.Compare(newValue, "PADFOOTING", true) == 0)
            {
                return(Toolkit.IFCFootingType.Pad_Footing);
            }
            if (String.Compare(newValue, "PILECAP", true) == 0)
            {
                return(Toolkit.IFCFootingType.Pile_Cap);
            }
            if (String.Compare(newValue, "STRIPFOOTING", true) == 0)
            {
                return(Toolkit.IFCFootingType.Strip_Footing);
            }

            return(Toolkit.IFCFootingType.UserDefined);
        }
Beispiel #18
0
        /// <summary>
        /// Get the IFC type from shared parameters, from a type name, or from a default value.
        /// </summary>
        /// <typeparam name="TEnum">The type of Enum.</typeparam>
        /// <param name="element">The element.</param>
        /// <param name="typeName">The type value.</param>
        /// <param name="defaultValue">A default value that can be null.</param>
        /// <returns>The found value, or null.</returns>
        public static string GetValidIFCType <TEnum>(Element element, string typeName, string defaultValue) where TEnum : struct
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcExportType", out value) != null)
            {
                if (ValidateStrEnum <TEnum>(value) != null)
                {
                    return(value);
                }
            }

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) != null)
            {
                if (ValidateStrEnum <TEnum>(value) != null)
                {
                    return(value);
                }
            }

            if (!string.IsNullOrEmpty(typeName) &&
                (string.Compare(typeName, "NotDefined", true) != 0 || string.IsNullOrEmpty(defaultValue)))
            {
                if (ValidateStrEnum <TEnum>(typeName) != null)
                {
                    return(typeName);
                }
            }

            if (!String.IsNullOrEmpty(defaultValue))
            {
                return(defaultValue);
            }

            // We used to return "NotDefined" here.  However, that assumed that all types had "NotDefined" as a value.
            // It is better to return null.
            return(null);
        }
Beispiel #19
0
        /// <summary>
        /// Collects the zone parameter values from an element.
        /// </summary>
        /// <param name="element">The element potentially containing the shared parameter information.</param>
        /// <returns>True if the zone name parameter was found, even if empty; false otherwise.</returns>
        /// <remarks>CurrentPropZoneLabels will be null if zone name parameter wasn't found,
        /// and empty if it was found but had no value.</remarks>
        public bool SetPropZoneValues(Element element)
        {
            CurrentPropZoneValues = null;

            SetPropZoneLabels();
            if (CurrentPropZoneLabels == null)
            {
                return(false);
            }

            string zoneNameLabel = GetPropZoneLabel(ZoneInfoLabel.Name);
            string zoneName;

            if (ParameterUtil.GetOptionalStringValueFromElementOrSymbol(element, zoneNameLabel, out zoneName) == null)
            {
                return(false);
            }

            CurrentPropZoneValues = new Dictionary <ZoneInfoLabel, string>();

            if (!string.IsNullOrWhiteSpace(zoneName))
            {
                CurrentPropZoneValues.Add(ZoneInfoLabel.Name, zoneName);
                foreach (KeyValuePair <ZoneInfoLabel, string> propZoneLabel in CurrentPropZoneLabels)
                {
                    if (propZoneLabel.Key == ZoneInfoLabel.Name)
                    {
                        continue;
                    }

                    string zoneValue;
                    ParameterUtil.GetStringValueFromElementOrSymbol(element, propZoneLabel.Value, out zoneValue);
                    CurrentPropZoneValues.Add(propZoneLabel.Key, zoneValue);
                }
            }

            return(true);
        }
Beispiel #20
0
        static IFCBeamType GetBeamType(Element element, string beamType)
        {
            string value = null;

            if (ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcType", out value) == null)
            {
                value = beamType;
            }

            if (String.IsNullOrEmpty(value))
            {
                return(IFCBeamType.Beam);
            }

            string newValue = NamingUtil.RemoveSpacesAndUnderscores(value);

            if (String.Compare(newValue, "USERDEFINED", true) == 0)
            {
                return(IFCBeamType.UserDefined);
            }

            return(IFCBeamType.Beam);
        }
Beispiel #21
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);
        }
Beispiel #22
0
        /// <summary>
        /// Create IfcClassification references from hardwired or custom classification code fields.
        /// </summary>
        /// <param name="exporterIFC">The exporterIFC class.</param>
        /// <param name="file">The IFC file class.</param>
        /// <param name="element">The element to export.</param>
        /// <param name="elemHnd">The corresponding IFC entity handle.</param>
        /// <returns>True if a classification or classification reference is created.</returns>
        public static bool CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd)
        {
            bool createdClassification = false;

            string         paramClassificationCode         = "";
            string         baseClassificationCodeFieldName = "ClassificationCode";
            IList <string> customClassificationCodeNames   = new List <string>();

            string classificationName        = null;
            string classificationCode        = null;
            string classificationDescription = null;

            int customPass     = 0;
            int standardPass   = 1;
            int numCustomCodes = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames.Count;

            // Note that we do the "custom" nodes first, and then the 10 standard ones.
            Element elementType = element.Document.GetElement(element.GetTypeId());

            while (standardPass <= 10)
            {
                // Create a classification, if it is not set.
                string classificationCodeFieldName = null;
                if (customPass < numCustomCodes)
                {
                    classificationCodeFieldName = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames[customPass];
                    customPass++;

                    if (string.IsNullOrWhiteSpace(classificationCodeFieldName))
                    {
                        continue;
                    }
                }
                else
                {
                    classificationCodeFieldName = baseClassificationCodeFieldName;
                    if (standardPass > 1)
                    {
                        classificationCodeFieldName += "(" + standardPass + ")";
                    }
                    standardPass++;
                }

                if (ParameterUtil.GetStringValueFromElementOrSymbol(element, elementType, classificationCodeFieldName,
                                                                    out paramClassificationCode) == null)
                {
                    continue;
                }

                parseClassificationCode(paramClassificationCode, classificationCodeFieldName, out classificationName, out classificationCode, out classificationDescription);

                if (String.IsNullOrEmpty(classificationDescription))
                {
                    if (string.Compare(classificationCodeFieldName, "Assembly Code", true) == 0)
                    {
                        ParameterUtil.GetStringValueFromElementOrSymbol(element, elementType, BuiltInParameter.UNIFORMAT_DESCRIPTION, false, out classificationDescription);
                    }
                    else if (string.Compare(classificationCodeFieldName, "OmniClass Number", true) == 0)
                    {
                        ParameterUtil.GetStringValueFromElementOrSymbol(element, elementType, BuiltInParameter.OMNICLASS_DESCRIPTION, false, out classificationDescription);
                    }
                }
                // If classificationName is empty, there is no classification to export.
                if (String.IsNullOrEmpty(classificationName))
                {
                    continue;
                }

                IFCAnyHandle classification;
                if (!ExporterCacheManager.ClassificationCache.ClassificationHandles.TryGetValue(classificationName, out classification))
                {
                    IFCClassification savedClassification = new IFCClassification();
                    if (ExporterCacheManager.ClassificationCache.ClassificationsByName.TryGetValue(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);
                        }

                        if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation))
                        {
                            ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation);
                        }
                    }
                    else
                    {
                        classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName);
                    }

                    ExporterCacheManager.ClassificationCache.ClassificationHandles.Add(classificationName, classification);
                    createdClassification = true;
                }

                string location = null;
                ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location);
                if (!String.IsNullOrEmpty(classificationCode))
                {
                    InsertClassificationReference(exporterIFC, file, elemHnd, classificationName, classificationCode, classificationDescription, location);
                    createdClassification = true;
                }
            }

            return(createdClassification);
        }
Beispiel #23
0
        /// <summary>
        /// Exports curtain object as container.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement,
                                                                ExporterIFC exporterIFC, ProductWrapper origWrapper, PlacementSetter currSetter)
        {
            if (wallElement == null)
            {
                return;
            }

            string overrideCADLayer = null;

            ParameterUtil.GetStringValueFromElementOrSymbol(wallElement, "IFCCadLayer", out overrideCADLayer);

            using (ExporterStateManager.CADLayerOverrideSetter layerSetter = new ExporterStateManager.CADLayerOverrideSetter(overrideCADLayer))
            {
                HashSet <ElementId> alreadyVisited = new HashSet <ElementId>(); // just in case.
                Options             geomOptions    = GeometryUtil.GetIFCExportGeometryOptions();
                {
                    foreach (ElementId subElemId in allSubElements)
                    {
                        using (ProductWrapper productWrapper = ProductWrapper.Create(origWrapper))
                        {
                            Element subElem = wallElement.Document.GetElement(subElemId);
                            if (subElem == null)
                            {
                                continue;
                            }

                            if (alreadyVisited.Contains(subElem.Id))
                            {
                                continue;
                            }
                            alreadyVisited.Add(subElem.Id);

                            // Respect element visibility settings.
                            if (!ElementFilteringUtil.CanExportElement(exporterIFC, subElem, false) || !ElementFilteringUtil.IsElementVisible(subElem))
                            {
                                continue;
                            }

                            GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                            if (geomElem == null)
                            {
                                continue;
                            }

                            try
                            {
                                if (subElem is FamilyInstance)
                                {
                                    string            ifcEnumType;
                                    IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, subElem, out ifcEnumType);

                                    if (subElem is Mullion)
                                    {
                                        if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                                        {
                                            ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                        }
                                        else
                                        {
                                            IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement;

                                            if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall)
                                            {
                                                // By default, panels and mullions are set to the same category as their parent.  In this case,
                                                // ask to get the exportType from the category id, since we don't want to inherit the parent class.
                                                exportType.SetValueWithPair(IFCEntityType.IfcMemberType);
                                                ifcEnumType = "MULLION";
                                            }

                                            FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subElem as Mullion, exportType, ifcEnumType, productWrapper,
                                                                                                    ElementId.InvalidElementId, null, currLocalPlacement);
                                        }
                                    }
                                    else
                                    {
                                        FamilyInstance subFamInst = subElem as FamilyInstance;

                                        if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall)
                                        {
                                            // By default, panels and mullions are set to the same category as their parent.  In this case,
                                            // ask to get the exportType from the category id, since we don't want to inherit the parent class.
                                            ElementId catId = CategoryUtil.GetSafeCategoryId(subElem);
                                            exportType = ElementFilteringUtil.GetExportTypeFromCategoryId(catId, out ifcEnumType);
                                        }


                                        if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                                        {
                                            if ((exportType.ExportInstance == IFCEntityType.UnKnown) ||
                                                (exportType.ExportInstance == IFCEntityType.IfcPlate) ||
                                                (exportType.ExportInstance == IFCEntityType.IfcMember))
                                            {
                                                exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy);
                                            }
                                        }
                                        else
                                        {
                                            if (exportType.ExportInstance == IFCEntityType.UnKnown)
                                            {
                                                ifcEnumType = "CURTAIN_PANEL";
                                                exportType.SetValueWithPair(IFCEntityType.IfcPlateType);
                                            }
                                        }

                                        IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement;
                                        using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                                        {
                                            FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper,
                                                                                                    ElementId.InvalidElementId, null, currLocalPlacement);
                                        }
                                    }
                                }
                                else if (subElem is CurtainGridLine)
                                {
                                    ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                }
                                else if (subElem is Wall)
                                {
                                    WallExporter.ExportWall(exporterIFC, null, subElem, null, geomElem, productWrapper);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ExporterUtil.IsFatalException(wallElement.Document, ex))
                                {
                                    throw ex;
                                }
                                continue;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Exports IFC type.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="type">The export type.</param>
        /// <param name="ifcEnumType">The string value represents the IFC type.</param>
        /// <param name="guid">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="applicableOccurrence">The optional data type of the entity.</param>
        /// <param name="propertySets">The property sets.</param>
        /// <param name="representationMapList">List of representations.</param>
        /// <param name="elementTag">The element tag.</param>
        /// <param name="typeName">The type name.</param>
        /// <param name="instance">The family instance.</param>
        /// <param name="symbol">The element type.</param>
        /// <returns>The handle.</returns>
        private static IFCAnyHandle ExportGenericTypeBase(IFCFile file,
                                                          IFCExportType originalType,
                                                          string ifcEnumType,
                                                          HashSet <IFCAnyHandle> propertySets,
                                                          IList <IFCAnyHandle> representationMapList,
                                                          Element instance,
                                                          ElementType symbol)
        {
            Revit.IFC.Common.Enums.IFCEntityType IFCTypeEntity;
            string typeAsString = originalType.ToString();

            // We'll accept the IFCExportType with or without "Type", but we'll append "Type" if we don't find it.
            if (string.Compare(typeAsString.Substring(typeAsString.Length - 4), "Type", true) != 0)
            {
                typeAsString += "Type";
            }

            if (!Enum.TryParse(typeAsString, out IFCTypeEntity))
            {
                return(null); // The export type is unknown IFC type entity
            }
            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcGasTerminalType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcBurnerType;
                    typeAsString  = IFCExportType.IfcBurnerType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcElectricHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcSpaceHeaterType;
                    typeAsString  = IFCExportType.IfcSpaceHeaterType.ToString();
                    break;
                }
            }
            else
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcBurnerType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcGasTerminalType;
                    typeAsString  = IFCExportType.IfcGasTerminalType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcSpaceHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcElectricHeaterType;
                    typeAsString  = IFCExportType.IfcElectricHeaterType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcDoorType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcDoorStyle;
                    break;

                case Common.Enums.IFCEntityType.IfcWindowType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcWindowStyle;
                    break;
                }
            }
            switch (IFCTypeEntity) //Use SuperType if Abstract, not all listed yet.
            {
            case Common.Enums.IFCEntityType.IfcEnergyConversionDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowControllerType:
            case Common.Enums.IFCEntityType.IfcFlowFittingType:
            case Common.Enums.IFCEntityType.IfcFlowMovingDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowSegmentType:
            case Common.Enums.IFCEntityType.IfcFlowStorageDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowTerminalType:
            case Common.Enums.IFCEntityType.IfcFlowTreatmentDeviceType:
                IFCTypeEntity = Common.Enums.IFCEntityType.IfcDistributionElementType;
                typeAsString  = "IfcDistributionElementType";
                break;
            }
            string[] typeStr              = typeAsString.Split('.');
            string   desiredTypeBase      = "Revit.IFC.Export.Toolkit.";
            string   desiredTypeBaseExtra = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? "IFC4." : string.Empty;
            string   desiredType          = desiredTypeBase + desiredTypeBaseExtra + typeStr[typeStr.Length - 1];

            object enumValue = null;

            {
                Type theEnumType = null;
                try
                {
                    // Not all entity types have enum values before IFC4.
                    theEnumType = Type.GetType(desiredType, true, true);
                }
                catch
                {
                    theEnumType = null;
                }

                if (theEnumType != null)
                {
                    try
                    {
                        // Not all entity types have "NotDefined" as an option.
                        enumValue = Enum.Parse(theEnumType, "NotDefined", true);
                    }
                    catch
                    {
                        enumValue = null;
                    }
                }

                try
                {
                    string value = null;
                    if ((ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcExportType", out value) == null) &&
                        (ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcType", out value) == null))
                    {
                        value = ifcEnumType;
                    }

                    if (theEnumType != null && !string.IsNullOrEmpty(value))
                    {
                        object enumValuePar = Enum.Parse(theEnumType, value, true);
                        enumValue = enumValuePar;
                    }
                }
                catch
                {
                    enumValue = null;
                }
            }

            string enumValueAsString = (enumValue == null) ? null : enumValue.ToString();

            return(IFCInstanceExporter.CreateGenericIFCType(IFCTypeEntity, symbol, file, propertySets, representationMapList, enumValueAsString));
        }
Beispiel #25
0
        /// <summary>
        /// Exports a roof to IfcRoof.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The roof type.</param>
        /// <param name="roof">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportRoof(ExporterIFC exporterIFC, string ifcEnumType, Element roof, GeometryElement geometryElement,
                                      ProductWrapper productWrapper)
        {
            if (roof == null || geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, roof))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        // If the roof is an in-place family, we will allow any arbitrary orientation.  While this may result in some
                        // in-place "cubes" exporting with the wrong direction, it is unlikely that an in-place family would be
                        // used for this reason in the first place.
                        ecData.PossibleExtrusionAxes   = (roof is FamilyInstance) ? IFCExtrusionAxes.TryXYZ : IFCExtrusionAxes.TryZ;
                        ecData.AreInnerRegionsOpenings = true;
                        ecData.SetLocalPlacement(placementSetter.LocalPlacement);

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(roof);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        BodyData            bodyData;
                        IFCAnyHandle        representation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, roof,
                                                                                                                        categoryId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        bool exportSlab = ecData.ScaledLength > MathUtil.Eps();

                        string       guid           = GUIDUtil.CreateGUID(roof);
                        IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        //string predefinedType = GetIFCRoofType(ifcEnumType);
                        string predefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(ifcEnumType, "NOTDEFINED", IFCEntityType.IfcRoofType.ToString());

                        IFCAnyHandle roofHnd = IFCInstanceExporter.CreateRoof(exporterIFC, roof, guid, ownerHistory,
                                                                              localPlacement, exportSlab ? null : representation, predefinedType);

                        // Export IfcRoofType
                        IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcRoof, IFCEntityType.IfcRoofType, predefinedType);
                        if (exportInfo.ExportType != IFCEntityType.UnKnown)
                        {
                            string overridePDefType;
                            if (ParameterUtil.GetStringValueFromElementOrSymbol(roof, "IfcExportType", out overridePDefType) == null) // change IFCType to consistent parameter of IfcExportType
                            {
                                if (ParameterUtil.GetStringValueFromElementOrSymbol(roof, "IfcType", out overridePDefType) == null)   // support IFCType for legacy support
                                {
                                    if (string.IsNullOrEmpty(predefinedType))
                                    {
                                        predefinedType = "NOTDEFINED";
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(overridePDefType))
                            {
                                exportInfo.ValidatedPredefinedType = overridePDefType;
                            }
                            else
                            {
                                exportInfo.ValidatedPredefinedType = predefinedType;
                            }

                            IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(roof, exportInfo, file, ownerHistory, predefinedType, productWrapper);
                            ExporterCacheManager.TypeRelationsCache.Add(typeHnd, roofHnd);
                        }

                        productWrapper.AddElement(roof, roofHnd, placementSetter.LevelInfo, ecData, true);

                        // will export its host object materials later if it is a roof
                        if (!(roof is RoofBase))
                        {
                            CategoryUtil.CreateMaterialAssociation(exporterIFC, roofHnd, bodyData.MaterialIds);
                        }

                        if (exportSlab)
                        {
                            string       slabGUID = GUIDUtil.CreateSubElementGUID(roof, (int)IFCRoofSubElements.RoofSlabStart);
                            string       slabName = IFCAnyHandleUtil.GetStringAttribute(roofHnd, "Name") + ":1";
                            IFCAnyHandle slabLocalPlacementHnd = ExporterUtil.CopyLocalPlacement(file, localPlacement);

                            IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(exporterIFC, roof, slabGUID, ownerHistory,
                                                                                  slabLocalPlacementHnd, representation, slabRoofPredefinedType);
                            IFCAnyHandleUtil.OverrideNameAttribute(slabHnd, slabName);
                            Transform offsetTransform = (bodyData != null) ? bodyData.OffsetTransform : Transform.Identity;
                            OpeningUtil.CreateOpeningsIfNecessary(slabHnd, roof, ecData, offsetTransform,
                                                                  exporterIFC, slabLocalPlacementHnd, placementSetter, productWrapper);

                            ExporterUtil.RelateObject(exporterIFC, roofHnd, slabHnd);

                            productWrapper.AddElement(null, slabHnd, placementSetter.LevelInfo, ecData, false);
                            CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, bodyData.MaterialIds);

                            // Create type
                            IFCExportInfoPair slabRoofExportType = new IFCExportInfoPair();
                            slabRoofExportType.SetValueWithPair(IFCEntityType.IfcSlab);
                            IFCAnyHandle slabRoofTypeHnd = ExporterUtil.CreateGenericTypeFromElement(roof, slabRoofExportType, exporterIFC.GetFile(), ownerHistory, slabRoofPredefinedType, productWrapper);
                            ExporterCacheManager.TypeRelationsCache.Add(slabRoofTypeHnd, slabHnd);
                        }
                    }
                    tr.Commit();
                }
            }
        }
        /// <summary>
        /// Exports IFC type.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="type">The export type.</param>
        /// <param name="ifcEnumType">The string value represents the IFC type.</param>
        /// <param name="guid">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="applicableOccurrence">The optional data type of the entity.</param>
        /// <param name="propertySets">The property sets.</param>
        /// <param name="representationMapList">List of representations.</param>
        /// <param name="elementTag">The element tag.</param>
        /// <param name="typeName">The type name.</param>
        /// <param name="instance">The family instance.</param>
        /// <param name="symbol">The element type.</param>
        /// <returns>The handle.</returns>
        private static IFCAnyHandle ExportGenericTypeBase(IFCFile file,
                                                          IFCExportType originalType,
                                                          string ifcEnumType,
                                                          string guid,
                                                          IFCAnyHandle ownerHistory,
                                                          string name,
                                                          string description,
                                                          string applicableOccurrence,
                                                          HashSet <IFCAnyHandle> propertySets,
                                                          IList <IFCAnyHandle> representationMapList,
                                                          string elementTag,
                                                          string typeName,
                                                          Element instance,
                                                          ElementType symbol)
        {
            // TODO: This routine needs to be simplified.  The long list of IFC2x3 and IFC4 calls to CreateGenericIFCType make it too easy to miss an entry.

            Revit.IFC.Common.Enums.IFCEntityType IFCTypeEntity;
            string typeAsString = originalType.ToString();

            // We'll accept the IFCExportType with or without "Type", but we'll append "Type" if we don't find it.
            if (string.Compare(typeAsString.Substring(typeAsString.Length - 4), "Type", true) != 0)
            {
                typeAsString += "Type";
            }

            if (!Enum.TryParse(typeAsString, out IFCTypeEntity))
            {
                return(null); // The export type is unknown IFC type entity
            }
            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcGasTerminalType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcBurnerType;
                    typeAsString  = IFCExportType.IfcBurnerType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcElectricHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcSpaceHeaterType;
                    typeAsString  = IFCExportType.IfcSpaceHeaterType.ToString();
                    break;
                }
            }
            else
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcBurnerType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcGasTerminalType;
                    typeAsString  = IFCExportType.IfcGasTerminalType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcSpaceHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcElectricHeaterType;
                    typeAsString  = IFCExportType.IfcElectricHeaterType.ToString();
                    break;
                }
            }

            string[] typeStr             = typeAsString.Split('.');
            string   desireTypeBase      = "Revit.IFC.Export.Toolkit.";
            string   desireTypeBaseExtra = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? ".IFC4" : string.Empty;
            string   desireType          = desireTypeBase + desireTypeBaseExtra + typeStr[typeStr.Length - 1];

            object enumValue = null;

            {
                Type theEnumType = null;
                try
                {
                    // Not all entity types have enum values before IFC4.
                    theEnumType = Type.GetType(desireType, true, true);
                }
                catch
                {
                    theEnumType = null;
                }

                if (theEnumType != null)
                {
                    try
                    {
                        // Not all entity types have "NotDefined" as an option.
                        enumValue = Enum.Parse(theEnumType, "NotDefined", true);
                    }
                    catch
                    {
                        enumValue = null;
                    }
                }

                try
                {
                    string value = null;
                    if ((ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcExportType", out value) == null) &&
                        (ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcType", out value) == null))
                    {
                        value = ifcEnumType;
                    }

                    if (theEnumType != null && !string.IsNullOrEmpty(value))
                    {
                        object enumValuePar = Enum.Parse(theEnumType, value, true);
                        enumValue = enumValuePar;
                    }
                }
                catch
                {
                    enumValue = null;
                }
            }

            string enumValueAsString = (enumValue == null) ? null : enumValue.ToString();

            return(IFCInstanceExporter.CreateGenericIFCType(IFCTypeEntity, file, guid, ownerHistory, name,
                                                            description, applicableOccurrence, propertySets, representationMapList, elementTag,
                                                            typeName, enumValueAsString));
        }
Beispiel #27
0
        /// <summary>
        /// Reads the parameter by parsing connector's description string
        /// </summary>
        /// <param name="connector">The Connector object.</param>
        /// <param name="parameterName">The name of parameter to search.</param>
        /// <returns>String assigned to parameterName.</returns>
        public static string GetConnectorParameterFromDescription(Connector connector, string parameterName)
        {
            string parameterValue = String.Empty;

            if (String.IsNullOrEmpty(parameterName) || connector == null)
            {
                return(parameterValue);
            }

            string parsedValue = String.Empty;

            // For the connectors of pipes or fittings we extract the parameters from the connector's owner
            // for others - from the connector itself
            if (!ExporterCacheManager.MEPCache.ConnectorDescriptionCache.TryGetValue(connector, out parsedValue))
            {
                Element owner = connector.Owner;
                if (owner is Pipe ||
                    owner is Duct ||
                    owner is FamilyInstance && (owner as FamilyInstance).MEPModel is MechanicalFitting)
                {
                    // Read description from the parameter with the name based on connector ID
                    int connectorId = connector.Id;
                    // ID's if pipe connectors are zero-based
                    if (owner is Pipe || owner is Duct)
                    {
                        connectorId++;
                    }

                    string descriptionParameter = "PortDescription " + connectorId.ToString();
                    ParameterUtil.GetStringValueFromElementOrSymbol(owner, descriptionParameter, out parsedValue);
                }
                else
                {
                    parsedValue = connector.Description;
                }
                ExporterCacheManager.MEPCache.ConnectorDescriptionCache.Add(connector, parsedValue);
            }


            if (String.IsNullOrEmpty(parsedValue))
            {
                return(parameterValue);
            }

            int ind = parsedValue.IndexOf(parameterName + '=');

            if (ind > -1)
            {
                parsedValue = parsedValue.Substring(ind + parameterName.Length + 1);
                if (!String.IsNullOrEmpty(parsedValue))
                {
                    int delimiterInd = parsedValue.IndexOf(',');
                    if (delimiterInd > -1)
                    {
                        parameterValue = parsedValue.Substring(0, delimiterInd);
                    }
                    else
                    {
                        parameterValue = parsedValue;
                    }
                }
            }

            return(parameterValue);
        }
Beispiel #28
0
        /// <summary>
        /// Create IfcClassification references from hardwired or custom classification code fields.
        /// </summary>
        /// <param name="exporterIFC">The exporterIFC class.</param>
        /// <param name="file">The IFC file class.</param>
        /// <param name="element">The element to export.</param>
        /// <param name="elemHnd">The corresponding IFC entity handle.</param>
        /// <returns>True if a classification or classification reference is created.</returns>
        public static bool CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd)
        {
            bool createdClassification = false;

            string         paramClassificationCode         = "";
            string         baseClassificationCodeFieldName = "ClassificationCode";
            IList <string> customClassificationCodeNames   = new List <string>();

            string classificationName        = null;
            string classificationCode        = null;
            string classificationDescription = null;

            int customPass     = 0;
            int standardPass   = 1;
            int numCustomCodes = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames.Count;

            while (standardPass <= 10)
            {
                // Create a classification, if it is not set.
                string classificationCodeFieldName = null;
                if (customPass < numCustomCodes)
                {
                    classificationCodeFieldName = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames[customPass];
                    customPass++;

                    if (string.IsNullOrWhiteSpace(classificationCodeFieldName))
                    {
                        continue;
                    }
                }
                else
                {
                    classificationCodeFieldName = baseClassificationCodeFieldName;
                    if (standardPass > 1)
                    {
                        classificationCodeFieldName += "(" + standardPass + ")";
                    }
                    standardPass++;
                }

                if (ParameterUtil.GetStringValueFromElementOrSymbol(element, classificationCodeFieldName, out paramClassificationCode) == null)
                {
                    continue;
                }

                parseClassificationCode(paramClassificationCode, classificationCodeFieldName, out classificationName, out classificationCode, out classificationDescription);

                IFCAnyHandle classification;
                if (!ExporterCacheManager.ClassificationCache.ClassificationHandles.TryGetValue(classificationName, out classification))
                {
                    IFCClassification savedClassification = new IFCClassification();
                    if (ExporterCacheManager.ClassificationCache.ClassificationsByName.TryGetValue(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);
                        }

                        if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation))
                        {
                            ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation);
                        }
                    }
                    else
                    {
                        classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName);
                    }

                    ExporterCacheManager.ClassificationCache.ClassificationHandles.Add(classificationName, classification);
                    createdClassification = true;
                }

                string location = null;
                ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location);
                if (!String.IsNullOrEmpty(classificationCode))
                {
                    InsertClassificationReference(exporterIFC, file, elemHnd, classificationName, classificationCode, classificationDescription, location);
                    createdClassification = true;
                }
            }

            return(createdClassification);
        }