Exemple #1
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);
        }
Exemple #2
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);
        }