Пример #1
0
        /// <summary>
        /// Get the Category for the IfcTypeObject
        /// </summary>
        /// <param name="type">IfcTypeObject</param>
        /// <returns>string of the category</returns>
        public string GetCategory(COBieDataPropertySetValues allPropertyValues)
        {
            string categoryRef = GetCategoryClassification(allPropertyValues.CurrentObject);

            if (!string.IsNullOrEmpty(categoryRef))
            {
                return(categoryRef);
            }

            //Try by PropertySet as fallback
            //filter list for front end category
            List <string> categoriesCode = new List <string>()
            {
                "OmniClass Table 13 Category", "OmniClass Number", "OmniClass_Number", "Assembly_Code", "Assembly Code",
                "Uniclass Code", "Uniclass_Code", "Category_Code", "Category Code", "Classification Code", "Classification_Code"
            };
            //filter list for back end category
            List <string> categoriesDesc = new List <string>()
            {
                "OmniClass Title", "OmniClass_Title", "Assembly_Description", "Assembly Description", "UniclassDescription",
                "Uniclass_Description", "Category Description", "Category_Description", "Classification Description", "Classification_Description"
            };
            List <string> categoriesTest = new List <string>();

            categoriesCode.AddRange(categoriesDesc);

            IEnumerable <IfcPropertySingleValue> properties = allPropertyValues.ObjProperties.OfType <IfcPropertySingleValue>();

            if (properties.Any())
            {
                properties = from psetval in properties
                             where categoriesTest.Contains(psetval.Name.ToString())
                             select psetval;
            }
            //second fall back on objects defined by this type, see if they hold a category on the first related object to this type
            if (!properties.Any())
            {
                Dictionary <IfcPropertySet, IEnumerable <IfcSimpleProperty> > propertysets = allPropertyValues.GetRelatedProperties(allPropertyValues.CurrentObject as IfcTypeObject);

                if (propertysets != null)
                {
                    properties = (from dic in propertysets
                                  from psetval in dic.Value
                                  where categoriesTest.Contains(psetval.Name.ToString())
                                  select psetval).OfType <IfcPropertySingleValue>();
                }
            }
            string value = "";

            if (properties.Any())
            {
                string conCatChar = " : ";

                string code        = properties.Where(p => p.NominalValue != null && categoriesCode.Contains(p.Name)).Select(p => p.NominalValue.ToString()).FirstOrDefault();
                string description = properties.Where(p => p.NominalValue != null && categoriesDesc.Contains(p.Name)).Select(p => p.NominalValue.ToString()).FirstOrDefault();
                if (!string.IsNullOrEmpty(code))
                {
                    value += code;
                }
                if (!string.IsNullOrEmpty(description))
                {
                    value += conCatChar + description;
                }
            }

            if (string.IsNullOrEmpty(value))
            {
                return(Constants.DEFAULT_STRING);
            }
            else
            {
                return(value);
            }
        }