Esempio n. 1
0
        //TODO: Check function below, see if it works!
        /// <summary>
        /// Test for IfcObjectDefinition exists in IfcToExclude type lists
        /// </summary>
        /// <param name="obj">IfcObjectDefinition object</param>
        /// <returns>bool, true = exclude</returns>
        public bool ItemsFilter(IfcObjectDefinition obj)
        {
            if (ItemsToExclude.Count == 0)
            {
                return(false);                           //nothing to test against
            }
            var  objType   = obj.GetType();
            var  objString = objType.Name.ToUpper(); //obj.ToString().ToUpper(); //or this might work, obj.IfcType().IfcTypeEnum.ToString();
            bool result    = ItemsToExclude.Contains(objString);

            if (!result && (PreDefinedType.ContainsKey(objString)))
            {
                var objPreDefinedProp = objType.GetProperty("PredefinedType");

                if (objPreDefinedProp != null)
                {
                    var objPreDefValue = objPreDefinedProp.GetValue(obj, null);

                    if (objPreDefValue != null)
                    {
                        var preDefType = objPreDefValue.ToString();
                        if (!string.IsNullOrEmpty(preDefType))
                        {
                            result = !PreDefinedType[objString].Contains(preDefType.ToUpper());
                        }
                    }
                }
            }
            return(result);
        }
        internal IfcPropertySetDefinition GetOrCreatePropertySetDefinition(IfcObjectDefinition ifcObjectDefinition, string propertySetName)
        {
            List <IfcPropertySetDefinition> propertySetDefinitionList;

            if (!_objectsToPropertySets.TryGetValue(ifcObjectDefinition, out propertySetDefinitionList))
            {
                propertySetDefinitionList = new List <IfcPropertySetDefinition>();
                _objectsToPropertySets.Add(ifcObjectDefinition, propertySetDefinitionList);
            }
            var propertySet = propertySetDefinitionList.Find(p => p.Name == propertySetName);

            if (propertySet == null)
            {
                //simplistic way to decide if this should be a quantity, IFC 4 specifies the name starts with QTO, under 2x3 most vendors have gone for BaseQuantities
                if (propertySetName != null && (propertySetName.StartsWith("qto_", true, CultureInfo.InvariantCulture) ||
                                                propertySetName.StartsWith("basequantities", true,
                                                                           CultureInfo.InvariantCulture)))
                {
                    var quantitySet = TargetRepository.Instances.New <IfcElementQuantity>();
                    propertySetDefinitionList.Add(quantitySet);
                    quantitySet.Name = propertySetName;
                    var ifcObject     = ifcObjectDefinition as IfcObject;
                    var ifcTypeObject = ifcObjectDefinition as IfcTypeObject;
                    if (ifcObject != null)
                    {
                        var relDef = TargetRepository.Instances.New <IfcRelDefinesByProperties>();
                        relDef.RelatingPropertyDefinition = quantitySet;
                        relDef.RelatedObjects.Add(ifcObject);
                    }
                    else if (ifcTypeObject != null)
                    {
                        if (ifcTypeObject.HasPropertySets == null)
                        {
                            ifcTypeObject.CreateHasPropertySets();
                        }
                        ifcTypeObject.HasPropertySets.Add(quantitySet);
                    }
                    else
                    {
                        throw new Exception("Invalid object type " + ifcObjectDefinition.GetType().Name);
                    }

                    propertySet = quantitySet;
                }
                else //it is a normal property set
                {
                    propertySet = TargetRepository.Instances.New <IfcPropertySet>();
                    propertySetDefinitionList.Add(propertySet);
                    propertySet.Name = propertySetName;
                    var ifcObject     = ifcObjectDefinition as IfcObject;
                    var ifcTypeObject = ifcObjectDefinition as IfcTypeObject;
                    if (ifcObject != null)
                    {
                        var relDef = TargetRepository.Instances.New <IfcRelDefinesByProperties>();
                        relDef.RelatingPropertyDefinition = propertySet;
                        relDef.RelatedObjects.Add(ifcObject);
                    }
                    else if (ifcTypeObject != null)
                    {
                        if (ifcTypeObject.HasPropertySets == null)
                        {
                            ifcTypeObject.CreateHasPropertySets();
                        }
                        ifcTypeObject.HasPropertySets.Add(propertySet);
                    }
                    else
                    {
                        throw new Exception("Invalid object type " + ifcObjectDefinition.GetType().Name);
                    }
                }
            }
            return(propertySet);
        }
        /// <summary />
        /// <param name="pSetDef"></param>
        public void AddPropertySetDefinition(IfcPropertySetDefinition pSetDef)
        {
            if (!pSetDef.Name.HasValue || string.IsNullOrWhiteSpace(pSetDef.Name))
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Property Set Definition: #{0}, has no defined name. It has been ignored", pSetDef.EntityLabel);
                return;
            }
            if (_propertySets.ContainsKey(pSetDef.Name))
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Property Set Definition: #{0}={1}, is duplicated in Entity #{2}={3}. Duplicate ignored", pSetDef.EntityLabel, pSetDef.Name, _ifcObject.EntityLabel, _ifcObject.GetType().Name);
                return;
            }
            _propertySets.Add(pSetDef.Name, pSetDef);
            var propertySet = pSetDef as IfcPropertySet;
            var quantitySet = pSetDef as IfcElementQuantity;

            if (propertySet != null)
            {
                foreach (var prop in propertySet.HasProperties)
                {
                    var uniquePropertyName = pSetDef.Name + "." + prop.Name;
                    if (_properties.ContainsKey(uniquePropertyName))
                    {
                        CoBieLiteUkHelper.Logger.WarnFormat("Property: #{0}={1}.{2}, is duplicated in Entity #{3}={4}. Duplicate ignored", prop.EntityLabel, pSetDef.Name, prop.Name, _ifcObject.EntityLabel, _ifcObject.GetType().Name);
                        continue;
                    }
                    _properties[uniquePropertyName] = prop;
                }
            }
            else if (quantitySet != null)
            {
                foreach (var quantity in quantitySet.Quantities)
                {
                    if (_quantities.ContainsKey(pSetDef.Name + "." + quantity.Name))
                    {
                        CoBieLiteUkHelper.Logger.WarnFormat("Quantity: #{0}={1}.{2}, is duplicated in Entity #{3}={4}. Duplicate ignored", quantity.EntityLabel, pSetDef.Name, quantity.Name, _ifcObject.EntityLabel, _ifcObject.GetType().Name);
                        continue;
                    }
                    _quantities[pSetDef.Name + "." + quantity.Name] = quantity;
                }
            }
        }
Esempio n. 4
0
        //TODO: Check function below, see if it works!
        /// <summary>
        /// Test for IfcObjectDefinition exists in IfcToExclude type lists
        /// </summary>
        /// <param name="obj">IfcObjectDefinition object</param>
        /// <returns>bool, true = exclude</returns>
        public bool ItemsFilter(IfcObjectDefinition obj)
        {
            if (ItemsToExclude.Count == 0) return false; //nothing to test against

            var objType = obj.GetType();
            var objString = objType.Name.ToUpper(); //obj.ToString().ToUpper(); //or this might work, obj.IfcType().IfcTypeEnum.ToString();
            bool result = ItemsToExclude.Contains(objString);
            
            if (!result && (PreDefinedType.ContainsKey(objString)))
            {
                var objPreDefinedProp = objType.GetProperty("PredefinedType");
            
                if (objPreDefinedProp != null)
                {

                    var objPreDefValue = objPreDefinedProp.GetValue(obj,null);

                    if (objPreDefValue != null)
                    {
                        var preDefType = objPreDefValue.ToString();
                        if (!string.IsNullOrEmpty(preDefType))
                        {
                            result = !PreDefinedType[objString].Contains(preDefType.ToUpper());
                        } 
                    }
                }
            }
            return result;
        }