public static B5dProjectNode Convert(IIfcObjectDefinition ifcObject)
        {
            var ifcObjectGuid = ifcObject.GlobalId.Value.ToString();
            var node          = B5dProjectNode.GetNodeWithIfcGuid(ifcObjectGuid);

            if (node != null)
            {
                return(node);
            }

            B5dProjectNode b5dNode = new B5dProjectNode()
            {
                TypeSpecifier = ifcObject.GetType().Name,
                Name          = ifcObject.Name,
                WhatIs        = new B5dPhysical()
                {
                    TypeSpecifier = ifcObject.GetType().Name,
                    Name          = ifcObject.Name
                }
            };

            IfcRoot b5dIfcObject = new IfcRoot()
            {
                ExternalIfcGlobalId = ifcObjectGuid,
                B5dObject           = b5dNode
            };

            return(b5dNode);
        }
示例#2
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(IIfcObjectDefinition 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();
            var result    = ItemsToExclude.Contains(objString);

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

            if (objPreDefinedProp == null)
            {
                return(false);
            }
            var objPreDefValue = objPreDefinedProp.GetValue(obj, null);

            if (objPreDefValue == null)
            {
                return(false);
            }
            var preDefType = objPreDefValue.ToString();

            if (!string.IsNullOrEmpty(preDefType))
            {
                result = !PreDefinedType[objString].Contains(preDefType.ToUpper());
            }
            return(result);
        }
示例#3
0
 private static void PrintHierarchy(IIfcObjectDefinition o, int level)
 {
     Console.WriteLine($"{GetIndent(level)}{o.Name} [{o.GetType().Name}]");
     foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
     {
         PrintHierarchy(item, level + 1);
     }
 }
示例#4
0
        /// <summary>
        ///   The method selects all IIfcSpatialStructureElement-s recursively and
        ///   creates MetaObject of them.
        /// </summary>
        /// <param name="objectDefinition">
        ///   Accepts an IIfcObjectDefinition parameter, which related elements are
        ///   then iterated in search for additional structure elements.
        /// </param>
        /// <returns>
        ///   Returns a flattened list of all MetaObject-s related to the provided
        ///   IIfcObjectDefinition.
        /// </returns>
        private static List <MetaObject> extractHierarchy(
            IIfcObjectDefinition objectDefinition,
            string parentId = null)
        {
            var metaObjects = new List <MetaObject>();

            var parentObject = new MetaObject {
                id     = objectDefinition.GlobalId,
                name   = objectDefinition.Name,
                type   = objectDefinition.GetType().Name,
                parent = parentId
            };

            metaObjects.Add(parentObject);

            var spatialElement = objectDefinition as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                var containedElements = spatialElement
                                        .ContainsElements
                                        .SelectMany(rel => rel.RelatedElements);

                foreach (var element in containedElements)
                {
                    var mo = new MetaObject {
                        id     = element.GlobalId,
                        name   = element.Name,
                        type   = element.GetType().Name,
                        parent = spatialElement.GlobalId
                    };

                    metaObjects.Add(mo);
                    extractRelatedObjects(
                        element,
                        ref metaObjects,
                        mo.id);
                }
            }

            extractRelatedObjects(
                objectDefinition,
                ref metaObjects,
                parentObject.id);

            return(metaObjects);
        }
示例#5
0
        /// <summary>
        ///   The method selects all IIfcSpatialStructureElement-s recursively and
        ///   creates MetaObject of them.
        /// </summary>
        /// <param name="objectDefinition">
        ///   Accepts an IIfcObjectDefinition parameter, which related elements are
        ///   then iterated in search for additional structure elements.
        /// </param>
        /// <returns>
        ///   Returns a flattened list of all MetaObject-s related to the provided
        ///   IIfcObjectDefinition.
        /// </returns>
        private static List <MetaObject> ExtractHierarchy(IIfcObjectDefinition
                                                          objectDefinition)
        {
            var metaObjects = new List <MetaObject>();

            var parentObject = new MetaObject {
                Id   = objectDefinition.GlobalId,
                Name = objectDefinition.Name,
                Type = objectDefinition.GetType().Name
            };

            metaObjects.Add(parentObject);

            var spatialElement = objectDefinition as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                var containedElements = spatialElement
                                        .ContainsElements
                                        .SelectMany(rel => rel.RelatedElements);

                foreach (var element in containedElements)
                {
                    var mo = new MetaObject {
                        Id     = element.GlobalId,
                        Name   = element.Name,
                        Type   = element.GetType().Name,
                        Parent = spatialElement.GlobalId
                    };
                    metaObjects.Add(mo);
                }
            }

            var relatedObjects = objectDefinition
                                 .IsDecomposedBy
                                 .SelectMany(r => r.RelatedObjects);

            foreach (var item in relatedObjects)
            {
                var children = ExtractHierarchy(item);
                metaObjects.AddRange(children);
            }

            return(metaObjects);
        }
        private List <SpatialStructureModel> PrintHierarchy(IIfcObjectDefinition o, int level, List <SpatialStructureModel> list, int?parentId)
        {
            SpatialStructureModel model = new SpatialStructureModel();

            model.Id       = Convert.ToInt32(o.EntityLabel);
            model.Name     = o.Name + " [" + o.GetType().Name + "]";
            model.ParentId = parentId;

            list.Add(model);
            // list += string.Format("{0}{1}{2} [{3}]", GetIndent(level), o.EntityLabel, o.Name, o.GetType().Name) + System.Environment.NewLine;

            //only spatial elements can contain building elements
            var spatialElement = o as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var element in containedElements)
                {
                    SpatialStructureModel model2 = new SpatialStructureModel();
                    model2.Id       = Convert.ToInt32(element.EntityLabel);
                    model2.Name     = element.Name + " [" + element.GetType().Name + "]";
                    model2.ParentId = Convert.ToInt32(o.EntityLabel);


                    list.Add(model2);
                    // list += string.Format("{0}    ->{1} {2} [{3}]", GetIndent(level), element.EntityLabel, element.Name, element.GetType().Name) + System.Environment.NewLine;
                }
            }

            //using IfcRelAggregares to get spatial decomposition of spatial structure elements
            foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
                list = PrintHierarchy(item, level + 1, list, Convert.ToInt32(o.EntityLabel));
            }

            return(list);
        }
示例#7
0
        private static void PrintHierarchy(IIfcObjectDefinition o, int level, Dictionary <string, IfcSpace> spaceidset, Dictionary <string, IfcBuildingStorey> storeyidset, List <XbimShapeInstance> _shapes, int number_OF_Walls, Xbim3DModelContext mod_context)
        {
            Console.WriteLine($"{GetIndent(level)}{" >> " + o.Name} [{o.GetType().Name}{ " | #" + o.EntityLabel  }] {"\n"}");
            var item = o.IsDecomposedBy.SelectMany(r => r.RelatedObjects);

            foreach (var i in item)
            {
                var id = i.GlobalId.ToString();

                //Console.WriteLine("------------------Matches found :" + _si.ShapeGeometryLabel.ToString());

                PrintHierarchy(i, level + 2, spaceidset, storeyidset, _shapes, number_OF_Walls, mod_context);

                //Console.WriteLine("Instance ID: " + eid);

                if (spaceidset.ContainsKey(id))
                {
                    IfcSpace spacenode;
                    spaceidset.TryGetValue(id, out spacenode);
                    var spacenodelelems = spacenode.GetContainedElements();

                    if (spacenodelelems.Count() > 0)
                    {
                        Console.WriteLine($"{GetIndent(level + 4)}" + "OBJECTS FOUND UNDER SPACE ARE: \n");
                        foreach (var sne in spacenodelelems)
                        {
                            var parent = sne.IsContainedIn;
                            var eid    = sne.EntityLabel.ToString();

                            Console.WriteLine($"{GetIndent(level + 5)}{" --> " + sne.Name} [{sne.GetType().Name}{ " | #" + sne.EntityLabel }{" | PARENT : #" + parent.EntityLabel}]");
                            Console.WriteLine(sne.EntityLabel);
                            var si = _shapes.Find(x => x.IfcProductLabel.ToString() == eid);
                            //Console.WriteLine("------------------Matches found :" + si.ShapeGeometryLabel.ToString());
                            getgeometry(si, mod_context);
                        }
                    }
                }

                else if (storeyidset.ContainsKey(id))
                {
                    IfcBuildingStorey bsnode;
                    storeyidset.TryGetValue(id, out bsnode);
                    var bsnodelelems = bsnode.GetContainedElements();

                    if (bsnodelelems.Count() > 0)
                    {
                        Console.WriteLine($"{GetIndent(level + 4)}" + "OTHER OBJECTS FOUND UNDER STOREY ARE: \n");
                        foreach (var bsne in bsnodelelems)
                        {
                            var parent = bsne.IsContainedIn;
                            var eid    = bsne.EntityLabel.ToString();

                            Console.WriteLine($"{GetIndent(level + 5)}{" --> " + bsne.Name} [{bsne.GetType().Name}{ " | #" + bsne.EntityLabel } {" | PARENT : #" + parent.EntityLabel }]");
                            Console.WriteLine("]]]]]]]]]]" + bsne.EntityLabel);

                            var si = _shapes.Find(x => x.IfcProductLabel.ToString() == eid);

                            xmlWriter.WriteStartElement("Wall");
                            xmlWriter.WriteAttributeString("ID", bsne.EntityLabel.ToString());

                            //xmlWriter.WriteString(bsne.EntityLabel.ToString());

                            getgeometry(si, mod_context, bsne.EntityLabel, number_OF_Walls);
                            //this is fo
                            //   xmlWriter.WriteEndElement();
                            // xmlWriter.WriteWhitespace("\n");
                        }
                    }
                }


                /***************************************************************************/
            }
        }
        /// <summary />
        /// <param name="pSetDef"></param>
        public void AddPropertySetDefinition(IIfcPropertySetDefinition pSetDef)
        {
            if (string.IsNullOrWhiteSpace(pSetDef.Name))
            {
                Logger.LogWarning("Property Set Definition: #{entityId}, has no defined name. It has been ignored", pSetDef.EntityLabel);
                return;
            }
            if (_propertySets.ContainsKey(pSetDef.Name))
            {
                Logger.LogWarning("Property Set Definition: #{psetId}={psetName}, is duplicated in Entity #{entityId}={entityType}. Duplicate ignored",
                                  pSetDef.EntityLabel, pSetDef.Name, _ifcObject.EntityLabel, _ifcObject.GetType().Name);
                return;
            }
            _propertySets.Add(pSetDef.Name, pSetDef);
            var propertySet = pSetDef as IIfcPropertySet;
            var quantitySet = pSetDef as IIfcElementQuantity;

            if (propertySet != null)
            {
                foreach (var prop in propertySet.HasProperties)
                {
                    var uniquePropertyName = pSetDef.Name + "." + prop.Name;
                    if (_properties.ContainsKey(uniquePropertyName))
                    {
                        Logger.LogWarning("Property: #{propId}={psetName}.{propName}, is duplicated in Entity #{entityId}={entityType}. 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))
                    {
                        Logger.LogWarning("Quantity: #{qtyId}={psetName}.{qtyName}, is duplicated in Entity #{entityId}={entityType}. Duplicate ignored",
                                          quantity.EntityLabel, pSetDef.Name, quantity.Name, _ifcObject.EntityLabel, _ifcObject.GetType().Name);
                        continue;
                    }
                    _quantities[pSetDef.Name + "." + quantity.Name] = quantity;
                }
            }
        }
示例#9
0
        private static void PrintHierarchy(IIfcObjectDefinition o, int level)
        {
            Console.WriteLine(string.Format("{0}{1} [{2}]", GetIndent(level), o.Name, o.GetType().Name));

            //only spatial elements can contain building elements
            var spatialElement = o as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var element in containedElements)
                {
                    Console.WriteLine(string.Format("{0}    ->{1} [{2}]", GetIndent(level), element.Name, element.GetType().Name));
                }
            }

            //using IfcRelAggregares to get spatial decomposition of spatial structure elements
            foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
                PrintHierarchy(item, level + 1);
            }
        }
示例#10
0
        public void AddPropertySetDefinition(IIfcPropertySetDefinition pSetDef)
        {
            if (!pSetDef.Name.HasValue || string.IsNullOrWhiteSpace(pSetDef.Name))
            {
                CoBieLiteHelper.Logger.WarnFormat("Property Set Definition: #{0}, has no defined name. It has been ignored", pSetDef.EntityLabel);
                return;
            }
            if (_propertySets.ContainsKey(pSetDef.Name))
            {
                CoBieLiteHelper.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 IIfcPropertySet;
            var quantitySet = pSetDef as IIfcElementQuantity;

            if (propertySet != null)
            {
                foreach (var prop in propertySet.HasProperties)
                {
                    var uniquePropertyName = pSetDef.Name + "." + prop.Name;
                    if (_properties.ContainsKey(uniquePropertyName))
                    {
                        CoBieLiteHelper.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))
                    {
                        CoBieLiteHelper.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;
                }
            }
        }