Ejemplo n.º 1
0
 private static bool X_GetTitle(IfcPropertySet prop, out string title)
 {
     // Default-Wert
     title = "Error";
     // Sanity Check
     if (prop == null)
     {
         return(false);
     }
     // Falls ArchiCAD Property
     if (prop.Attributes.Any(attr => attr.Value == "ArchiCADProperties"))
     {
         // Falls Bibliothekselement (z.b. Fenster)
         if (prop.Attributes.Any(attr => attr.Name == "Bibliothekselement-Name"))
         {
             // Dann ist das der Name
             title = Regex.Replace(prop.Attributes.First(attr => attr.Name == "Bibliothekselement-Name").Value, @"(1|2|3|4|5|6|7|8|9|0|-)", "");
             return(true);
         }
         else
         {
             // Sonst ist Element ID Name
             title = Regex.Replace(prop.Attributes.First(attr => attr.Name == "Element ID").Value, @"(1|2|3|4|5|6|7|8|9|0|-)", "");
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
    Material readAppearanceFromPropertySet(IfcPropertySet prop_set)
    {
        Material mat = new Material(sampleMat);

        foreach (IfcProperty prop in prop_set.HasProperties)
        {
            if (prop == null)
            {
                continue;
            }
            IfcComplexProperty complex_prop = (IfcComplexProperty)prop;
            //IfcComplexProperty complex_prop = (IfcComplexProperty)prop;
            if (complex_prop != null)
            {
                if (complex_prop.UsageName == null)
                {
                    continue;
                }
                if (complex_prop.UsageName.Value.ToString().Equals("Color"))
                {
                    Color diff_color = readIfcComplexPropertyColor(complex_prop);
                    mat.color = diff_color;
                }
            }
        }
        return(mat);
    }
Ejemplo n.º 3
0
        public static Dictionary <IfcLabel, Dictionary <IfcIdentifier, IfcValue> > GetAllPropertySingleValues(this Xbim.Ifc2x3.Kernel.IfcObject obj)
        {
            Dictionary <IfcLabel, Dictionary <IfcIdentifier, IfcValue> > result = new Dictionary <IfcLabel, Dictionary <IfcIdentifier, IfcValue> >();
            IEnumerable <IfcRelDefinesByProperties> relations = obj.IsDefinedByProperties.OfType <IfcRelDefinesByProperties>();

            foreach (IfcRelDefinesByProperties rel in relations)
            {
                Dictionary <IfcIdentifier, IfcValue> value = new Dictionary <IfcIdentifier, IfcValue>();
                IfcLabel       psetName = rel.RelatingPropertyDefinition.Name ?? null;
                IfcPropertySet pSet     = rel.RelatingPropertyDefinition as IfcPropertySet;
                if (pSet == null)
                {
                    continue;
                }
                foreach (IfcProperty prop in pSet.HasProperties)
                {
                    IfcPropertySingleValue singleVal = prop as IfcPropertySingleValue;
                    if (singleVal == null)
                    {
                        continue;
                    }
                    value.Add(prop.Name, singleVal.NominalValue);
                }
                if (!result.ContainsKey(psetName))
                {
                    result.Add(psetName, value);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set values for attribute sheet
        /// </summary>
        /// <param name="ifcTypeObject">ifcObject to extract properties from</param>
        /// <param name="_attributes">The attribute Sheet to add the properties to its rows</param>
        public void PopulateAttributesRows(IfcTypeObject ifcTypeObject)
        {
            if (PropertSetValues.PSetFilterOn) //we have a property set filter set in the PropertSetValues class, so reset to retrieve all property sets for this object
            {
                PropertSetValues.SetAllPropertyValues(ifcTypeObject);
            }

            foreach (KeyValuePair <IfcPropertySet, IEnumerable <IfcSimpleProperty> > pairValues in PropertSetValues.MapPsetToProps)
            {
                IfcPropertySet ps = pairValues.Key; //get Property Set
                //get all property attached to the property set
                //check property set exclude list
                if (!string.IsNullOrEmpty(ps.Name))
                {
                    if (ExcludeAttributePropertySetNames.Count() > 0)
                    {
                        if (ExcludeAttributePropertySetNames.Contains(ps.Name))
                        {
                            continue; //skip this loop iteration if property set name matches exclude list item
                        }
                    }
                }

                IEnumerable <IfcSimpleProperty> pSVs = pairValues.Value; //Get Property SetAttribSheet Property Single Values
                //filter on ExcludePropertyValueNames and ExcludePropertyValueNamesWildcard
                pSVs = FilterRows(pSVs);
                //fill in the data to the attribute rows
                ProcessAttributeRow(ps, pSVs);
            }
        }
Ejemplo n.º 5
0
 private void AddPropertySet(IfcPropertySet pSet)
 {
     if (pSet == null)
     {
         return;
     }
     foreach (var item in pSet.HasProperties.OfType <IfcPropertySingleValue>()) //only handle simple properties
     {
         var val = "";
         if (item.NominalValue != null)
         {
             var nomVal = (ExpressType)(item.NominalValue);
             val = nomVal.Value != null
                 ? nomVal.Value.ToString()
                 : item.NominalValue.ToString();
         }
         _properties.Add(new PropertyItem
         {
             IfcLabel        = item.EntityLabel,
             PropertySetName = pSet.Name,
             Name            = item.Name,
             Value           = val
         });
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Category method for property sets
        /// </summary>
        /// <param name="propSet">IfcPropertySet</param>
        /// <returns>Category as string </returns>
        protected string GetCategory(IfcPropertySet propSet)
        {
            IEnumerable <IfcClassificationReference> cats = from IRAC in propSet.HasAssociations
                                                            where IRAC is IfcRelAssociatesClassification &&
                                                            ((IfcRelAssociatesClassification)IRAC).RelatingClassification is IfcClassificationReference
                                                            select((IfcRelAssociatesClassification)IRAC).RelatingClassification as IfcClassificationReference;

            IfcClassificationReference cat = cats.FirstOrDefault();

            if (cat != null)
            {
                return(cat.Name.ToString());
            }
            //Try by PropertySet as fallback
            var query = from props in propSet.HasProperties
                        where props.Name.ToString() == "OmniClass Table 13 Category" || props.Name.ToString() == "Category Code"
                        select props.ToString().TrimEnd();

            string val = query.FirstOrDefault();

            if (!String.IsNullOrEmpty(val))
            {
                return(val);
            }
            return(Constants.DEFAULT_STRING);
        }
        private static CcManufacturerProduct GetProductFromPset(Document document, IfcPropertySet pset)
        {
            CcManufacturerProduct prd = null;

            var reldefprop = document.IfcXmlDocument.Items.OfType <IfcRelDefinesByProperties>();

            //.Where(ele => ele.RelatingPropertyDefinition.Item..RelatingTemplate.Ref == pset.Id);

            foreach (IfcRelDefinesByProperties reldef in reldefprop)
            {
                IfcPropertySet settemp = reldef.RelatingPropertyDefinition.Item as IfcPropertySet;
                if (settemp != null && settemp.Ref == pset.Id)
                {
                    var relobj = document.IfcXmlDocument.Items.OfType <IfcElement>()
                                 .Where(ele => ele.Id == reldef.RelatedObjects.Ref);

                    List <IfcElement> eles = relobj.ToList();
                    if (eles != null && eles.Count > 0)
                    {
                        prd             = new CcManufacturerProduct();
                        prd.Name        = eles[0].Name;
                        prd.Description = eles[0].Description;
                        break;
                    }
                }
            }

            return(prd);
        }
Ejemplo n.º 8
0
        public static IfcPropertySingleValue SetPropertySingleValue(this Xbim.Ifc2x3.Kernel.IfcTypeObject obj, string pSetName, string propertyName, IfcValue value)
        {
            IfcPropertySet         pset     = GetPropertySet(obj, pSetName);
            IfcPropertySingleValue property = null;
            IModel model = null;

            if (pset == null)
            {
                //if (value == null) return;
                IPersistIfcEntity ent = obj as IPersistIfcEntity;
                model     = ent != null? ent.ModelOf : obj.ModelOf;
                pset      = model.Instances.New <IfcPropertySet>();
                pset.Name = pSetName;
                obj.AddPropertySet(pset);
            }

            //change existing property of the same name from the property set
            IfcPropertySingleValue singleVal = GetPropertySingleValue(obj, pSetName, propertyName);

            if (singleVal != null)
            {
                property = singleVal;
                singleVal.NominalValue = value;
            }
            else
            {
                //if (value == null) return;
                IPersistIfcEntity ent = obj as IPersistIfcEntity;
                model    = ent != null ? ent.ModelOf : obj.ModelOf;
                property = model.Instances.New <IfcPropertySingleValue>(psv => { psv.Name = propertyName; psv.NominalValue = value; });
                pset.HasProperties.Add(property);
            }
            return(property);
        }
Ejemplo n.º 9
0
 private static void X_AddDescription(IfcPropertySet prop, ref List <string> descList)
 {
     // Falls Property interessant ist
     if (_ifcPropertyFilter.Contains(prop.Attributes.FirstOrDefault(attr => attr.Name == "Name").Value))
     {
         // Filtern nach den Attributen die erlaubt sind
         var filtered = prop.Attributes.Join(_generalFilter, attr => attr.Name, fltr => fltr, (attr, fltr) => attr.Name + ": " + attr.Value);
         // Tridify Bug
         foreach (var filter in _compontentFilter)
         {
             var attr = prop.Attributes.FirstOrDefault(curr => curr.Name == filter);
             if (attr.Name != null)
             {
                 filtered = filtered.Append(attr.Name + ": " + attr.Value);
             }
         }
         // Tridify Bug
         foreach (var filter in _matPropertiesFilter)
         {
             var attr = prop.Attributes.FirstOrDefault(curr => curr.Name == filter.Item1);
             if (attr.Name != null)
             {
                 filtered = filtered.Append(filter.Item2 + ": " + attr.Value);
             }
         }
         filtered = filtered.Concat(prop.Attributes.Join(_stairFilter, attr => attr.Name, fltr => fltr.Item1, (attr, fltr) => fltr.Item2 + ": " + attr.Value));
         filtered = filtered.Concat(prop.Attributes.Join(_archiCADFilter, attr => attr.Name, fltr => fltr, (attr, fltr) => attr.Name + ": " + attr.Value));
         // Hinzufuegen, fertig
         descList.AddRange(filtered);
     }
 }
Ejemplo n.º 10
0
        public static IfcPropertySingleValue SetPropertySingleValue(this Xbim.Ifc2x3.Kernel.IfcObject obj, string pSetName, string propertyName, IfcValue value)
        {
            IfcPropertySet pset  = GetPropertySet(obj, pSetName);
            IModel         model = null;

            if (pset == null)
            {
                model     = obj.ModelOf;
                pset      = model.Instances.New <IfcPropertySet>();
                pset.Name = pSetName;
                IfcRelDefinesByProperties relDef = model.Instances.New <IfcRelDefinesByProperties>();
                relDef.RelatingPropertyDefinition = pset;
                relDef.RelatedObjects.Add(obj);
            }

            //change existing property of the same name from the property set
            IfcPropertySingleValue singleVal = GetPropertySingleValue(obj, pSetName, propertyName);

            if (singleVal != null)
            {
                singleVal.NominalValue = value;
            }
            else
            {
                model     = obj.ModelOf;
                singleVal = model.Instances.New <IfcPropertySingleValue>(psv => { psv.Name = propertyName; psv.NominalValue = value; });
                pset.HasProperties.Add(singleVal);
            }

            return(singleVal);
        }
Ejemplo n.º 11
0
        public static IfcPropertyTableValue GetPropertyTableValue(this Xbim.Ifc2x3.Kernel.IfcObject obj, string pSetName, string propertyTableName)
        {
            IfcPropertySet pset = GetPropertySet(obj, pSetName);

            if (pset != null)
            {
                return(pset.HasProperties.Where <IfcPropertyTableValue>(p => p.Name == propertyTableName).FirstOrDefault());
            }
            return(null);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds an existing property set to the objecty, NB no check is done for duplicate psets
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="pSet"></param>
        public static void AddPropertySet(this IfcObject obj, IfcPropertySet pSet)
        {
            IModel model = obj.ModelOf;
            IfcRelDefinesByProperties relDef = model.Instances.OfType <IfcRelDefinesByProperties>().Where(r => r.RelatingPropertyDefinition == pSet).FirstOrDefault();;

            if (relDef == null)
            {
                relDef = model.Instances.New <IfcRelDefinesByProperties>();
                relDef.RelatingPropertyDefinition = pSet;
            }
            relDef.RelatedObjects.Add(obj);
        }
Ejemplo n.º 13
0
        public static void RemovePropertySingleValue(this Xbim.Ifc2x3.Kernel.IfcObject obj, string pSetName, string propertyName)
        {
            IfcPropertySet pset = GetPropertySet(obj, pSetName);

            if (pset != null)
            {
                IfcPropertySingleValue singleValue = pset.HasProperties.Where <IfcPropertySingleValue>(p => p.Name == propertyName).FirstOrDefault();
                if (singleValue != null)
                {
                    pset.HasProperties.Remove(singleValue);
                }
            }
        }
        public static int GetPSetHash(this IfcPropertySet pSet)
        {
            if (pSet == null)
            {
                return(0);
            }
            var result = pSet.GetType().GetHashCode();

            foreach (var item in pSet.HasProperties)
            {
                result += GetPropertyHash(item);
            }
            return(result);
        }
        private static IfcPropertySet GetPropertySet(Document document, string reference)
        {
            IfcPropertySet psettemp = null;
            var            pset     = document.IfcXmlDocument.Items.OfType <IfcPropertySet>()
                                      .Where(ele => ele.Id == reference);

            List <IfcPropertySet> setlist = pset.ToList();

            if (setlist != null && setlist.Count > 0)
            {
                psettemp = setlist[0];
            }
            return(psettemp);
        }
Ejemplo n.º 16
0
        public static VType GetPropertySingleValue <VType>(this Xbim.Ifc2x3.Kernel.IfcObject obj, string pSetName, string propertyName) where VType : IfcValue
        {
            IfcPropertySet pset = GetPropertySet(obj, pSetName);

            if (pset != null)
            {
                IfcPropertySingleValue pVal = pset.HasProperties.Where <IfcPropertySingleValue>(p => p.Name == propertyName).FirstOrDefault();
                if (pVal != null && typeof(VType).IsAssignableFrom(pVal.NominalValue.GetType()))
                {
                    return((VType)pVal.NominalValue);
                }
            }
            return(default(VType));
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            DatabaseIfc db = new DatabaseIfc(ModelView.Ifc4X3NotAssigned);

            db.Factory.Options.GenerateOwnerHistory = false;

            IfcProject        project        = new IfcProject(db, "DemoProject");
            IfcProjectLibrary projectLibrary = new IfcProjectLibrary(db, "ClassificationLibrary");

            project.AddDeclared(projectLibrary);

            IfcClassification classification = new IfcClassification(db, "MyClassification");

            new IfcRelAssociatesClassification(classification, projectLibrary);

            IfcClassificationReference buildingElements = new IfcClassificationReference(classification)
            {
                Identification = "100", Name = "BuildingElements"
            };
            IfcClassificationReference walls = new IfcClassificationReference(buildingElements)
            {
                Identification = "100.100", Name = "Walls"
            };
            IfcClassificationReference partionWalls = new IfcClassificationReference(walls)
            {
                Identification = "100.100.002", Name = "PartiionWalls"
            };

            IfcSimplePropertyTemplate simplePropertyTemplate = new IfcSimplePropertyTemplate(db, "IsExternal")
            {
                GlobalId = "3Yss80qXKHuO00025QrE$V", PrimaryMeasureType = "IfcBoolean"
            };
            IfcPropertySetTemplate psetTemplate = new IfcPropertySetTemplate("Pset_WallCommon", simplePropertyTemplate)
            {
                GlobalId = "2VWFE0qXKHuO00025QrE$V"
            };

            IfcPropertySingleValue psv  = new IfcPropertySingleValue(db, "IsExternal", new IfcBoolean(false));
            IfcPropertySet         pset = new IfcPropertySet("Pset_WallCommon", psv);

            new IfcRelDefinesByTemplate(pset, psetTemplate);

            new IfcRelAssociatesClassification(partionWalls, pset);

            DirectoryInfo di = Directory.GetParent(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            di = Directory.GetParent(di.FullName);
            db.WriteFile(Path.Combine(di.FullName, "TestClassification.ifc"));
        }
Ejemplo n.º 18
0
        public static void SetPropertyTableItemValue(this Xbim.Ifc2x3.Kernel.IfcObject obj, string pSetName, string propertyTableName, IfcValue definingValue, IfcValue definedValue, IfcUnit definingUnit, IfcUnit definedUnit)
        {
            IfcPropertySet pset  = GetPropertySet(obj, pSetName);
            IModel         model = null;

            if (pset == null)
            {
                model     = obj.ModelOf;
                pset      = model.Instances.New <IfcPropertySet>();
                pset.Name = pSetName;
                IfcRelDefinesByProperties relDef = model.Instances.New <IfcRelDefinesByProperties>();
                relDef.RelatingPropertyDefinition = pset;
                relDef.RelatedObjects.Add(obj);
            }
            IfcPropertyTableValue table = GetPropertyTableValue(obj, pSetName, propertyTableName);

            if (table == null)
            {
                model = obj.ModelOf;
                table = model.Instances.New <IfcPropertyTableValue>(tb => { tb.Name = propertyTableName; });
                pset.HasProperties.Add(table);
                table.DefinedUnit  = definedUnit;
                table.DefiningUnit = definingUnit;
            }
            if (table.DefiningUnit != definingUnit || table.DefinedUnit != definedUnit)
            {
                throw new Exception("Inconsistent definition of the units in the property table.");
            }

            IfcValue itemValue = GetPropertyTableItemValue(obj, pSetName, propertyTableName, definingValue);

            if (itemValue != null)
            {
                itemValue = definedValue;
            }
            else
            {
                //if (table.DefiningValues == null) table.DefiningValues = new XbimList<IfcValue>();
                table.DefiningValues.Add(definingValue);
                //if (table.DefinedValues == null) table.DefinedValues = new XbimList<IfcValue>();
                table.DefinedValues.Add(definedValue);

                //check of integrity
                if (table.DefinedValues.Count != table.DefiningValues.Count)
                {
                    throw new Exception("Inconsistent state of the property table. Number of defined and defining values are not the same.");
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get IfcPropertySet first associated object
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        private IfcRoot GetAssociatedObject (IfcPropertySet ps)
        {
            if ((ps.PropertyDefinitionOf.FirstOrDefault() != null) &&
                (ps.PropertyDefinitionOf.First().RelatedObjects.FirstOrDefault() != null)
                )
            {
                return ps.PropertyDefinitionOf.First().RelatedObjects.First();
            }
            if (ps.DefinesType.FirstOrDefault() != null) 
            {
                return ps.DefinesType.FirstOrDefault();
            }

            return null;
        }
        protected override Xbim.COBieLiteUK.System Mapping(IfcPropertySet pSet, Xbim.COBieLiteUK.System target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            //Add Assets
            var systemAssignments = helper.GetSystemAssignments(pSet);

            var    ifcObjectDefinitions = systemAssignments as IList <IfcObjectDefinition> ?? systemAssignments.ToList();
            string name = string.Empty;

            if (ifcObjectDefinitions.Any())
            {
                name = GetSystemName(helper, ifcObjectDefinitions);

                target.Components = new List <AssetKey>();
                foreach (var ifcObjectDefinition in ifcObjectDefinitions)
                {
                    var assetKey = new AssetKey {
                        Name = ifcObjectDefinition.Name
                    };
                    if (!target.Components.Contains(assetKey))
                    {
                        target.Components.Add(assetKey);
                    }
                }
            }
            target.ExternalEntity = helper.ExternalEntityName(pSet);
            target.ExternalId     = helper.ExternalEntityIdentity(pSet);
            target.ExternalSystem = helper.ExternalSystemName(pSet);
            target.Name           = string.IsNullOrEmpty(name) ? "Unknown" : name;
            target.Description    = string.IsNullOrEmpty(pSet.Description) ? name : pSet.Description.ToString();
            target.CreatedBy      = helper.GetCreatedBy(pSet);
            target.CreatedOn      = helper.GetCreatedOn(pSet);
            target.Categories     = helper.GetCategories(pSet);

            //Attributes, no attributes from PSet as Pset is the attributes, assume that component attributes are extracted by each component anyway
            //target.Attributes = helper.GetAttributes(pSet);

            //Documents
            var docsMappings = Exchanger.GetOrCreateMappings <MappingIfcDocumentSelectToDocument>();

            helper.AddDocuments(docsMappings, target, pSet);

            //TODO:
            //System Issues

            return(target);
        }
Ejemplo n.º 21
0
        public static List <IfcPropertySet> GetAllPropertySets(this Xbim.Ifc2x3.Kernel.IfcObject obj)
        {
            List <IfcPropertySet> result = new List <IfcPropertySet>();
            IEnumerable <IfcRelDefinesByProperties> rels = obj.IsDefinedByProperties;

            foreach (IfcRelDefinesByProperties rel in rels)
            {
                IfcPropertySet pSet = rel.RelatingPropertyDefinition as IfcPropertySet;
                if (pSet != null)
                {
                    result.Add(pSet);
                }
            }

            return(result);
        }
Ejemplo n.º 22
0
        public static void SetPropertyTableItemValue(this Xbim.Ifc2x3.Kernel.IfcTypeObject obj, string pSetName, string propertyTableName, IfcValue definingValue, IfcValue definedValue, IfcUnit definingUnit, IfcUnit definedUnit)
        {
            IfcPropertySet pset  = GetPropertySet(obj, pSetName);
            IModel         model = null;

            if (pset == null)
            {
                IPersistIfcEntity ent = obj as IPersistIfcEntity;
                model     = ent != null ? ent.ModelOf : obj.ModelOf;
                pset      = model.Instances.New <IfcPropertySet>();
                pset.Name = pSetName;
                obj.AddPropertySet(pset);
            }
            IfcPropertyTableValue table = GetPropertyTableValue(obj, pSetName, propertyTableName);

            if (table == null)
            {
                IPersistIfcEntity ent = obj as IPersistIfcEntity;
                model = ent != null ? ent.ModelOf : obj.ModelOf;
                table = model.Instances.New <IfcPropertyTableValue>(tb => { tb.Name = propertyTableName; });
                pset.HasProperties.Add(table);
                table.DefinedUnit  = definedUnit;
                table.DefiningUnit = definingUnit;
            }
            if (table.DefiningUnit != definingUnit || table.DefinedUnit != definedUnit)
            {
                throw new Exception("Inconsistent definition of the units in the property table.");
            }

            IfcValue itemValue = GetPropertyTableItemValue(obj, pSetName, propertyTableName, definingValue);

            if (itemValue != null)
            {
                itemValue = definedValue;
            }
            else
            {
                table.DefiningValues.Add(definingValue);
                table.DefinedValues.Add(definedValue);

                //check of integrity
                if (table.DefinedValues.Count != table.DefiningValues.Count)
                {
                    throw new Exception("Inconsistent state of the property table. Number of defined and defining values are not the same.");
                }
            }
        }
Ejemplo n.º 23
0
        internal void checkProperty(IfcObjectDefinition obj, string psetName, string propertyName, bool permitType, HashSet <String> allowableStrings)
        {
            IfcPropertySingleValue propertySingleValue = null;

            if (!string.IsNullOrEmpty(psetName))
            {
                IfcPropertySet propertySet = null;
                if (obj is IfcObject ifcObject)
                {
                    propertySet = ifcObject.FindPropertySet(psetName, permitType) as IfcPropertySet;
                }
                else
                {
                    propertySet = obj.FindPropertySet(psetName) as IfcPropertySet;
                }
                if (propertySet == null)
                {
                    System.Diagnostics.Debug.WriteLine("Test Fail " + obj.GlobalId + " " + obj.Name + " missing pset " + psetName);
                    return;
                }
                propertySingleValue = propertySet.FindProperty(propertyName) as IfcPropertySingleValue;
            }
            else
            {
                propertySingleValue = obj.FindProperty(propertyName) as IfcPropertySingleValue;
            }
            if (propertySingleValue == null)
            {
                System.Diagnostics.Debug.WriteLine("Test Fail " + obj.GlobalId + " " + obj.Name + " missing property " + propertyName);
                return;
            }
            if (propertySingleValue.NominalValue == null)
            {
                System.Diagnostics.Debug.WriteLine("Test Fail " + obj.GlobalId + " " + obj.Name + " property " + propertyName + " has no value!");
                return;
            }
            if (allowableStrings.Count > 0)
            {
                string propertyValue = propertySingleValue.NominalValue.ValueString;
                if (!allowableStrings.Contains(propertyValue))
                {
                    System.Diagnostics.Debug.WriteLine("Test Fail " + obj.GlobalId + " " + obj.Name + " property " + propertyName + " has unacceptable value :" + propertyValue);
                    return;
                }
            }
        }
Ejemplo n.º 24
0
            private static int psetsOrder(IfcPropertySet x, IfcPropertySet y)
            {
                if (x.Name == null && y.Name != null)
                {
                    return(-1);
                }
                if (x.Name != null && y.Name == null)
                {
                    return(1);
                }
                if (x.Name == null && y.Name == null)
                {
                    return(0);
                }

                return(x.Name.ToString().CompareTo(y.Name.ToString()));
            }
Ejemplo n.º 25
0
        protected BbPropertySet(string name)
        {
            IfcPropertySet = new IfcPropertySet
            {
                Name = name,
                GlobalId = IfcGloballyUniqueId.NewGuid(),
                OwnerHistory = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                HasProperties = new List<IfcProperty>(),
            };

            IfcRelDefinesByProperties = new IfcRelDefinesByProperties
            {
                GlobalId = IfcGloballyUniqueId.NewGuid(),
                OwnerHistory = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                RelatedObjects = new List<IfcObject>(),
                RelatingPropertyDefinition = IfcPropertySet,
            };
        }
Ejemplo n.º 26
0
        bool HasPropertyLikeExternalTrue(IfcWall wall)
        {
            //get relations property
            IEnumerable <IfcRelDefinesByProperties> rels = wall.IsDefinedByProperties;

            foreach (var rel in rels)
            {
                //get property set
                IfcPropertySet pSet = rel.RelatingPropertyDefinition as IfcPropertySet;
                if (pSet == null)
                {
                    continue;
                }
                foreach (IfcProperty prop in pSet.HasProperties)
                {
                    //get properties
                    IfcPropertySingleValue singleVal = prop as IfcPropertySingleValue;
                    if (singleVal == null)
                    {
                        continue;
                    }
                    if (singleVal.Name == "Wall Function")
                    {
                        //check value of the property
                        IfcValue val = singleVal.NominalValue;
                        if (val.UnderlyingSystemType == typeof(int))
                        {
                            if ((int)val.Value == 1)
                            {
                                return(true);
                            }
                        }
                        else if (val.UnderlyingSystemType == typeof(int?))
                        {
                            if ((int?)val.Value == 1)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 27
0
 private bool ComparePSets(IfcPropertySet baseline, IfcPropertySet revision)
 {
     if (baseline.Name != revision.Name)
     {
         return(false);
     }
     if (baseline.HasProperties.Count != revision.HasProperties.Count)
     {
         return(false);
     }
     foreach (var prop in baseline.HasProperties)
     {
         if (!HasEquivalent(prop, revision))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 28
0
        protected BbPropertySet(string name)
        {
            IfcPropertySet = new IfcPropertySet
            {
                Name          = name,
                GlobalId      = IfcGloballyUniqueId.NewGuid(),
                OwnerHistory  = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                HasProperties = new List <IfcProperty>(),
            };


            IfcRelDefinesByProperties = new IfcRelDefinesByProperties
            {
                GlobalId                   = IfcGloballyUniqueId.NewGuid(),
                OwnerHistory               = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                RelatedObjects             = new List <IfcObject>(),
                RelatingPropertyDefinition = IfcPropertySet,
            };
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Check if property set exists on object when in merge, if not merge just create property set
        /// </summary>
        /// <param name="pSetName">Property set name</param>
        /// <returns>IfcPropertySet</returns>
        private IfcPropertySet CheckIfExistOnMerge(string extObject, string extIdentifier)
        {
            string         pSetName       = string.Empty;
            IfcPropertySet ifcPropertySet = null;

            //check that the GlobalId is not holding the property set name
            if ((ValidateString(extIdentifier)) &&
                (!ValidGlobalId(extIdentifier))
                )
            {
                pSetName      = extIdentifier;
                extIdentifier = null;           //force new Guid
            }
            else if (ValidateString(extObject)) //check we have a valid string
            {
                pSetName = extObject;
            }
            else
            {
                pSetName = null;
            }

            if (CurrentObject is IfcObject)
            {
                ifcPropertySet = (CurrentObject as IfcObject).GetPropertySet(pSetName);
                if (ifcPropertySet == null)
                {
                    ifcPropertySet = AddPropertySet((IfcObject)CurrentObject, pSetName, "");
                }
            }
            else if (CurrentObject is IfcTypeObject)
            {
                ifcPropertySet = (CurrentObject as IfcTypeObject).GetPropertySet(pSetName);
                if (ifcPropertySet == null)
                {
                    ifcPropertySet = AddPropertySet((IfcTypeObject)CurrentObject, pSetName, "");
                }
            }
            //Add GlobalId

            AddGlobalId(extIdentifier, ifcPropertySet);
            return(ifcPropertySet);
        }
        private void FillPropertyData()
        {
            if (_properties.Count > 0)
            {
                return;                        //don't fill unless empty
            }
            //now the property sets for any
            IfcObject ifcObj = _entity as IfcObject;

            if (ifcObj != null)
            {
                foreach (IfcRelDefinesByProperties relDef in ifcObj.IsDefinedByProperties)
                {
                    IfcPropertySet pSet = relDef.RelatingPropertyDefinition as IfcPropertySet;
                    if (pSet != null)
                    {
                        foreach (var item in pSet.HasProperties.OfType <IfcPropertySingleValue>()) //only handle simple properties
                        {
                            string val = "";
                            if (item.NominalValue != null)
                            {
                                var nomVal = (ExpressType)(item.NominalValue);
                                if (nomVal.Value != null)
                                {
                                    val = nomVal.Value.ToString(); // value (not ToPart21) for visualisation
                                }
                                else
                                {
                                    val = item.NominalValue.ToString();
                                }
                            }
                            _properties.Add(new PropertyItem()
                            {
                                PropertySetName = pSet.Name,
                                Name            = item.Name,
                                Value           = val
                            });
                        }
                    }
                }
            }
        }
        private static List <IfcPropertySet> GetPropertySetsForTemplateReference(Document document, string refToPsetTemplate)
        {
            List <IfcPropertySet> _psets = new List <IfcPropertySet>();

            var teldeftempl = document.IfcXmlDocument.Items.OfType <IfcRelDefinesByTemplate>()
                              .Where(ele => ele.RelatingTemplate.Ref == refToPsetTemplate);

            foreach (IfcRelDefinesByTemplate relDefYbTemp in teldeftempl)
            {
                foreach (IfcPropertySet pset in relDefYbTemp.RelatedPropertySets.Items)
                {
                    IfcPropertySet tempset = GetPropertySet(document, pset.Ref);
                    if (tempset != null)
                    {
                        _psets.Add(tempset);
                    }
                }
            }
            return(_psets);
        }
 private void AddPropertySet(IfcPropertySet pSet)
 {
     if (pSet == null)
         return;
     foreach (var item in pSet.HasProperties.OfType<IfcPropertySingleValue>()) //only handle simple properties
     {
         var val = "";
         if (item.NominalValue != null)
         {
             var nomVal = (ExpressType) (item.NominalValue);
             val = nomVal.Value != null
                 ? nomVal.Value.ToString()
                 : item.NominalValue.ToString();
         }
         _properties.Add(new PropertyItem
         {
             IfcLabel = item.EntityLabel,
             PropertySetName = pSet.Name,
             Name = item.Name,
             Value = val
         });
     }
 }
        /// <summary>
        /// Add Rows to the attribute sheet
        /// </summary>
        /// <param name="_attributes">The attribute Sheet to add the properties to its rows</param>
        /// <param name="propertySet">IfcPropertySet which is holding the IfcPropertySingleValue</param>
        /// <param name="propertySetValues">IEnumerable list of IfcPropertySingleValue to extract to the attribute sheet</param>
        private void ProcessAttributeRow(IfcPropertySet propertySet, IEnumerable<IfcSimpleProperty> propertySetValues)
        {
            //construct the rows
            foreach (IfcSimpleProperty propertySetSimpleProperty in propertySetValues)
            {
                if (propertySetSimpleProperty != null)
                {
                    string value = "";
                    string name = propertySetSimpleProperty.Name.ToString();
                    string extIdentifier = null;
                    string extObject = null;
                    


                    if (string.IsNullOrEmpty(name))
                    {
#if DEBUGATT
                        Console.WriteLine("Excluded attribute has no name");
#endif

                        continue; //skip to next loop item
                    }

                    IEnumerable<COBieAttributeRow> TestRow = _attributes.Rows.Where(r => r.Name == name && r.SheetName == RowParameters["Sheet"] && r.RowName == RowParameters["Name"]);
                    if (TestRow.Any()) continue; //skip to next loop item

                    //check what type we of property we have
                    IfcPropertySingleValue ifcPropertySingleValue = propertySetSimpleProperty as IfcPropertySingleValue;
                    //get value
                    if (ifcPropertySingleValue != null)
                    {
                        if (ifcPropertySingleValue.NominalValue != null)
                        {
                            value = ifcPropertySingleValue.NominalValue.Value != null ? ifcPropertySingleValue.NominalValue.Value.ToString() : string.Empty;
                            double num;
                            if (double.TryParse(value, out num)) value = num.ToString();
                            if ((string.IsNullOrEmpty(value)) || (string.Compare(value, ifcPropertySingleValue.Name.ToString(), true) == 0) || (string.Compare(value, "default", true) == 0))
                            {
#if DEBUGATT
                                Console.WriteLine("Excluded attribute {0}, has no value", name);
#endif
                                continue; //skip to next loop item
                            }

                        }

                    }

                    COBieAttributeRow attribute = new COBieAttributeRow(_attributes);
                    attribute.Unit = Constants.DEFAULT_STRING; //set initially to default, saves the else statements
                    attribute.AllowedValues = Constants.DEFAULT_STRING;
                    attribute.Description = Constants.DEFAULT_STRING;

                    if (ifcPropertySingleValue != null) //as we can skip on ifcPropertySingleValue we need to split ifcPropertySingleValue testing
                    {
                        if ((ifcPropertySingleValue.Unit != null))
                        {
                            attribute.Unit = COBieData<COBieAttributeRow>.GetUnitName(ifcPropertySingleValue.Unit);
                            
                        }
                    }

                    //Process properties that are not IfcPropertySingleValue
                    IfcPropertyEnumeratedValue ifcPropertyEnumeratedValue = propertySetSimpleProperty as IfcPropertyEnumeratedValue;
                    if (ifcPropertyEnumeratedValue != null)
                    {
                        string EnumValuesHeld = "";
                        if (ifcPropertyEnumeratedValue.EnumerationValues != null)
                        {
                            value = COBieData<COBieAttributeRow>.GetEnumerationValues(ifcPropertyEnumeratedValue.EnumerationValues);
                        }

                        //get  the unit and all possible values held in the Enumeration
                        if (ifcPropertyEnumeratedValue.EnumerationReference != null)
                        {
                            if (ifcPropertyEnumeratedValue.EnumerationReference.Unit != null)
                            {
                                attribute.Unit = COBieData<COBieAttributeRow>.GetUnitName(ifcPropertyEnumeratedValue.EnumerationReference.Unit);
                            }
                            EnumValuesHeld = COBieData<COBieAttributeRow>.GetEnumerationValues(ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues);
                            if (!string.IsNullOrEmpty(EnumValuesHeld)) attribute.AllowedValues = EnumValuesHeld;
                        }
                        //change the extIdentifier to the property set name and extObject to the property type
                        extIdentifier = propertySet.Name;
                        extObject = propertySetSimpleProperty.GetType().Name;
                    }

                    IfcPropertyBoundedValue ifcPropertyBoundedValue = propertySetSimpleProperty as IfcPropertyBoundedValue;
                    if (ifcPropertyBoundedValue != null)
                    {
                        //combine upper and lower into the value field
                        if (ifcPropertyBoundedValue.UpperBoundValue != null)
                            value = ifcPropertyBoundedValue.UpperBoundValue.ToString();
                        if (ifcPropertyBoundedValue.LowerBoundValue != null)
                        {
                            if (!string.IsNullOrEmpty(value))
                                value += " : " + ifcPropertyBoundedValue.LowerBoundValue.ToString();
                            else
                                value = ifcPropertyBoundedValue.LowerBoundValue.ToString();
                        }

                        if ((ifcPropertyBoundedValue.Unit != null))
                        {
                            attribute.Unit = COBieData<COBieAttributeRow>.GetUnitName(ifcPropertyBoundedValue.Unit);
                        }
                        //change the extIdentifier to the property set name and extObject to the property type
                        extIdentifier = propertySet.Name;
                        extObject = propertySetSimpleProperty.GetType().Name;
                    }

                    IfcPropertyTableValue ifcPropertyTableValue = propertySetSimpleProperty as IfcPropertyTableValue;
                    if (ifcPropertyTableValue != null)
                    {
                        if ((ifcPropertyTableValue.DefiningValues != null) &&
                            (ifcPropertyTableValue.DefinedValues != null) &&
                            (ifcPropertyTableValue.DefiningValues.Count() == ifcPropertyTableValue.DefinedValues.Count())
                            )
                        {
                            StringBuilder cellValue = new StringBuilder();
                            int i = 0;
                            foreach (var item in ifcPropertyTableValue.DefiningValues)
                            {
                                cellValue.Append("(");
                                cellValue.Append(item.ToString());
                                cellValue.Append(":");
                                cellValue.Append(ifcPropertyTableValue.DefinedValues[i].ToString());
                                cellValue.Append(")");
                                i++;
                            }
                            value = cellValue.ToString();
                            //get the unit definition
                            string cellUnit = "";
                            if (ifcPropertyTableValue.DefiningUnit != null)
                                cellUnit = COBieData<COBieAttributeRow>.GetUnitName(ifcPropertyTableValue.DefiningUnit);
                            else
                                cellUnit = "Unknown";
                            cellUnit += ":";
                            if (ifcPropertyTableValue.DefinedUnit != null)
                                cellUnit += COBieData<COBieAttributeRow>.GetUnitName(ifcPropertyTableValue.DefinedUnit);
                            else
                                cellUnit += "Unknown";
                            attribute.Unit = cellUnit;
                            if (!string.IsNullOrEmpty(ifcPropertyTableValue.Expression))
                                attribute.AllowedValues = ifcPropertyTableValue.Expression;
                        }
                        else
                        {
                            throw new ArgumentException("ProcessAttributeRow: IfcPropertyTableValue has unequal column numbers");
                        }
                        //change the extIdentifier to the property set name and extObject to the property type
                        extIdentifier = propertySet.Name;
                        extObject = propertySetSimpleProperty.GetType().Name;
                    }

                    IfcPropertyReferenceValue ifcPropertyReferenceValue = propertySetSimpleProperty as IfcPropertyReferenceValue;
                    if (ifcPropertyReferenceValue != null)
                    {
                        if (ifcPropertyReferenceValue.UsageName != null)
                            attribute.Description = (string.IsNullOrEmpty(ifcPropertyReferenceValue.UsageName.ToString())) ? Constants.DEFAULT_STRING : ifcPropertyReferenceValue.UsageName.ToString();

                        if (ifcPropertyReferenceValue.PropertyReference != null)
                        {
                            value = ifcPropertyReferenceValue.PropertyReference.ToString();
                            attribute.Unit = ifcPropertyReferenceValue.PropertyReference.GetType().Name;
                        }

                    }
                    IfcPropertyListValue ifcPropertyListValue = propertySetSimpleProperty as IfcPropertyListValue;
                    if (ifcPropertyListValue != null)
                    {
                        if (ifcPropertyListValue.ListValues != null)
                        {
                            value = COBieData<COBieAttributeRow>.GetEnumerationValues(ifcPropertyListValue.ListValues);
                        }

                        //get  the unit and all possible values held in the Enumeration
                        if (ifcPropertyListValue.Unit != null)
                            attribute.Unit = COBieData<COBieAttributeRow>.GetUnitName(ifcPropertyListValue.Unit);

                        //change the extIdentifier to the property set name and extObject to the property type
                        extIdentifier = propertySet.Name;
                        extObject = propertySetSimpleProperty.GetType().Name;
                    }


                    attribute.Name = propertySetSimpleProperty.Name.ToString();

                    //Get category
                    string cat = GetCategory(propertySet);
                    attribute.Category = (cat == Constants.DEFAULT_STRING) ? "Requirement" : cat;
                    
                    attribute.ExtIdentifier = string.IsNullOrEmpty(extIdentifier) ? propertySet.GlobalId.ToString() : extIdentifier;
                    if (string.IsNullOrEmpty(attribute.ExtIdentifier)) 
                        attribute.ExtIdentifier = Constants.DEFAULT_STRING;

                    attribute.ExtObject = string.IsNullOrEmpty(extObject) ? propertySet.Name.ToString() : extObject;
                    if (string.IsNullOrEmpty(attribute.ExtObject)) 
                        attribute.ExtObject = Constants.DEFAULT_STRING;

                    //passed properties from the sheet
                    attribute.SheetName = RowParameters["Sheet"];
                    attribute.RowName = RowParameters["Name"];
                    string createdBy = COBieData<COBieAttributeRow>.GetEmail( propertySet.OwnerHistory.OwningUser.TheOrganization, propertySet.OwnerHistory.OwningUser.ThePerson);
                    attribute.CreatedBy = (createdBy.Contains("unknown")) ? RowParameters["CreatedBy"] : createdBy; //check for incorrect made up email, if so then use parent CreatedBy
                    string onDate = COBieData<COBieAttributeRow>.GetCreatedOnDate(propertySet.OwnerHistory);
                    attribute.CreatedOn = (string.IsNullOrEmpty(onDate)) ? RowParameters["CreatedOn"] : onDate;
                    attribute.ExtSystem = (propertySet.OwnerHistory.OwningApplication != null) ? propertySet.OwnerHistory.OwningApplication.ApplicationFullName.ToString() : RowParameters["ExtSystem"];
                    if (string.IsNullOrEmpty(attribute.ExtSystem))
                        attribute.ExtSystem = Constants.DEFAULT_STRING;
                    
                    //value = NumberValueCheck(value, attribute);
                    attribute.Value = string.IsNullOrEmpty(value) ? Constants.DEFAULT_STRING : value;

                    attribute.Description = propertySetSimpleProperty.Description.ToString();
                    if (string.IsNullOrEmpty(attribute.Description)) //if no description then just use name property
                    {
                        attribute.Description = attribute.Name;
                    }

                    _attributes.AddRow(attribute);
                }
            }
        }
        /// <summary>
        /// Get Category method for property sets
        /// </summary>
        /// <param name="propSet">IfcPropertySet</param>
        /// <returns>Category as string </returns>
        protected string GetCategory(IfcPropertySet propSet)
        {
            IEnumerable<IfcClassificationReference> cats = from IRAC in propSet.HasAssociations
                                                           where IRAC is IfcRelAssociatesClassification
                                                           && ((IfcRelAssociatesClassification)IRAC).RelatingClassification is IfcClassificationReference
                                                           select ((IfcRelAssociatesClassification)IRAC).RelatingClassification as IfcClassificationReference;
            IfcClassificationReference cat = cats.FirstOrDefault();
            if (cat != null)
            {
                return cat.Name.ToString();
            }
            //Try by PropertySet as fallback
            var query = from props in propSet.HasProperties
                        where props.Name.ToString() == "OmniClass Table 13 Category" || props.Name.ToString() == "Category Code"
                        select props.ToString().TrimEnd();
            string val = query.FirstOrDefault();

            if (!String.IsNullOrEmpty(val))
            {
                return val;
            }
            return Constants.DEFAULT_STRING;
        }