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);
        }
Exemplo n.º 2
0
        private static void PrintHierarchy(IIfcObjectDefinition o, int level, TreeNode node)
        {
            node.Text = o.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)
                {
                    var stepchild = new TreeNode {
                        Text = element.Name
                    };
                    node.Nodes.Add(stepchild);
                }
            }

            //using IfcRelAggregares to get spatial decomposition of spatial structure elements
            foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
                var child = new TreeNode()
                {
                    Text = "Null"
                };

                PrintHierarchy(item, level + 1, child);
                node.Nodes.Add(child);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public string GetCoBieProperty(string valueName, IIfcObjectDefinition ifcObjectDefinition)
        {
            XbimAttributedObject attributedObject;

            if (_attributedObjects.TryGetValue(ifcObjectDefinition, out attributedObject))
            {
                string[] propertyNames;
                if (_cobieFieldMap.TryGetValue(valueName, out propertyNames))
                {
                    foreach (var propertyName in propertyNames)
                    {
                        string value;
                        if (attributedObject.GetSimplePropertyValue(propertyName, out value))
                        {
                            return(value);
                        }
                    }
                }
                else
                {
                    throw new ArgumentException("Illegal COBie Attribute name:", valueName);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        protected void NewContainer(IIfcObjectDefinition container)
        {
            var scope = CurrentScope;

            _ContainerScope.Push(container);
            Store.NewDecomposes(scope).RelatedObjects.Add(container);
        }
Exemplo n.º 6
0
        private void PrintHierarchy(IIfcObjectDefinition o, TreeNode parentNode)
        {
            //textBox1.Text += ($"{GetIndent(level)}{o.Name} [{o.GetType().Name}]");
            var spatialElement = o as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var element in containedElements)
                {
                    parentNode.Nodes.Add(CreateNode(element));
                    //textBox1.Text += ($"{GetIndent(level)}    ->{element.Name} [{element.GetType().Name}]");
                }
            }

            foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
                spatialElement = item as IIfcSpatialStructureElement;
                if (spatialElement != null)
                {
                    TreeNode childNode = CreateNode(item);
                    parentNode.Nodes.Add(childNode);
                    PrintHierarchy(item, childNode);
                }
            }
        }
Exemplo n.º 7
0
        TreeNode CreateNode(IIfcObjectDefinition project)
        {
            TreeNode projectNode = new TreeNode(project.Name);

            projectNode.Tag = project.GlobalId;
            return(projectNode);
        }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
0
 public SpatialViewModel(IIfcProject project)
 {
     if (project == null)
     {
         throw new ArgumentNullException("project");
     }
     _model            = project.Model;
     _spatialStructure = project;
 }
Exemplo n.º 10
0
 public SpatialViewModel(IIfcSpatialStructureElement spatialStructure, IXbimViewModel parent)
 {
     if (spatialStructure == null)
     {
         throw new ArgumentNullException("spatialStructure");
     }
     _model            = spatialStructure.Model;
     _spatialStructure = spatialStructure;
     CreatingParent    = parent;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Returns an enumeration of child objects having either a decomposition relation or spatial containment
        /// relation with the argument object.
        /// </summary>
        /// <typeparam name="T">A preferred type</typeparam>
        /// <param name="o">The parent</param>
        /// <returns>An enumeration of objects of given type</returns>
        public static IEnumerable <T> Children <T>(this IIfcObjectDefinition o) where T : IIfcProduct
        {
            var productSubs = o.SubObjects <T>();

            if (o is IIfcSpatialElement s)
            {
                return(Enumerable.Concat(productSubs, s.ContainsElements.SelectMany(r => r.RelatedElements.OfType <T>())));
            }
            else
            {
                return(productSubs);
            }
        }
Exemplo n.º 12
0
        public static IIfcRelAggregates NewDecomposes(this IModel s, IIfcObjectDefinition host)
        {
            switch (s.SchemaVersion)
            {
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc2X3:
                return(s.NewIfc2x3Decomposes(host as Xbim.Ifc2x3.Kernel.IfcObjectDefinition));

            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4:
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4x1:
                return(s.NewIfc4Decomposes(host as Xbim.Ifc4.Kernel.IfcObjectDefinition));
            }
            throw new NotImplementedException($"Not implemented schema version ${s.SchemaVersion}");
        }
Exemplo n.º 13
0
        /// <summary>
        /// Returns an enumeration of parent objects having either a decomposition relation or spatial containment
        /// relation with the argument object.
        /// </summary>
        /// <typeparam name="T">A preferred type</typeparam>
        /// <param name="o">The child</param>
        /// <returns>An enumeration of parent objects</returns>
        public static IEnumerable <T> Parent <T>(this IIfcObjectDefinition o) where T : IIfcObjectDefinition
        {
            var productSupers = o.SuperObject <T>();

            if (o is IIfcProduct p)
            {
                return(Enumerable.Concat(productSupers, new IIfcProduct[] { p.IsContainedIn }.OfType <T>()).Distinct());
            }
            else
            {
                return(productSupers);
            }
        }
Exemplo n.º 14
0
        private List <IIfcObjectDefinition> PrintHierarchy(IIfcObjectDefinition Object, int level)
        {
            var Hierarchy = new List <IIfcObjectDefinition>();

            //var TypeObjects = Model.Instances.Where<IIfcTypeObject>(s=>s.EntityLabel > 0);
            var Spaces = Model.Instances.Where <IIfcSpace>(s => s.EntityLabel > 0);
            //var Zones = Model.Instances.Where<IIfcZone>(s => s.EntityLabel > 0);
            //var Doors = Model.Instances.Where<IIfcDoor>(s => s.EntityLabel > 0);
            //var Windows = Model.Instances.Where<IIfcWindow>(s => s.EntityLabel > 0);
            //var Walls = Model.Instances.Where<IIfcWall>(s => s.EntityLabel > 0);
            //var Roofs = Model.Instances.Where<IIfcRoof>(s => s.EntityLabel > 0);
            //var SlabTypes = Model.Instances.Where<IIfcSlabType>(s => s.EntityLabel > 0);

            var SpaceProps = GetPropsForProduct(Spaces.FirstOrDefault());

            IIfcElement Element = Object as IIfcElement;

            // If we're dealing with an element: Wall, Door, Window..
            // Then we'll have a direct connection to the Spatial Structure that it's contained in
            if (Element != null)
            {
                var Relation          = Element.ContainedInStructure.FirstOrDefault() as IIfcRelContainedInSpatialStructure;
                var RelatingStructure = Relation.RelatingStructure;
                Hierarchy.Add(RelatingStructure);

                Console.WriteLine();
            }



            //only spatial elements can contain building elements
            IIfcSpatialStructureElement SpatialElement = Object as IIfcSpatialStructureElement;

            if (SpatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var ContainedElements = SpatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var ContainedElement in ContainedElements)
                {
                }
            }

            //using IfcRelAggregares to get spatial decomposition of spatial structure elements
            foreach (var SpatialStructure in Object.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
            }

            return(Hierarchy);
        }
Exemplo n.º 15
0
        /// <summary>
        ///   Method extracts related objects hierarchy,
        /// then add children to metaObjects.
        /// </summary>
        /// <param name="objectDefinition">
        ///  Accepts an IIfcObjectDefinition parameter, which related elements are
        ///  then iterated in search for additional structure elements.
        /// </param>
        /// <param name="metaObjects">Reference of 'MetaObject' list</param>
        /// <param name="parentObjId">Id of parent object.</param>
        private static void extractRelatedObjects(
            IIfcObjectDefinition objectDefinition,
            ref List <MetaObject> metaObjects,
            string parentObjId)
        {
            var relatedObjects = objectDefinition
                                 .IsDecomposedBy
                                 .SelectMany(r => r.RelatedObjects);

            foreach (var item in relatedObjects)
            {
                var children = extractHierarchy(item, parentObjId);
                metaObjects.AddRange(children);
            }
        }
Exemplo n.º 16
0
        public List <AttributeType> GetAttributes(IIfcObjectDefinition ifcObjectDefinition)
        {
            XbimAttributedObject attributedObject;

            if (_attributedObjects.TryGetValue(ifcObjectDefinition, out attributedObject))
            {
                //var properties = attributedObject.Properties.Where(kv=>!_cobieProperties.Contains(kv.Key)); //exclude the properties we have written as COBie value
                //var keyValuePairs = properties as KeyValuePair<string, IIfcProperty>[] ?? properties.ToArray();
                //if (keyValuePairs.Length>0)
                //{
                //    var attributeCollection = new List<AttributeType>(keyValuePairs.Length);
                //    for (int i = 0; i < keyValuePairs.Length; i++)
                //    {

                //        var property = keyValuePairs[i].Value;
                //        var splitName = keyValuePairs[i].Key.Split('.');
                //        var pSetName = splitName[0];
                //        var attributeType = XbimAttributedObject.ConvertToAttributeType(property);
                //        attributeType.propertySetName = pSetName;
                //        //var pSetDef = attributedObject.GetPropertySetDefinition(pSetName);
                //        //if (pSetDef != null)
                //        //    attributeType.externalID = ExternalEntityIdentity(pSetDef);
                //        attributeCollection.Add(attributeType);
                //    }
                //    return attributeCollection;
                //}
                var properties    = attributedObject.Properties;
                var keyValuePairs = properties.ToArray();
                if (keyValuePairs.Length > 0)
                {
                    var attributeCollection = new List <AttributeType>(keyValuePairs.Length);
                    for (int i = 0; i < keyValuePairs.Length; i++)
                    {
                        var property      = keyValuePairs[i].Value;
                        var splitName     = keyValuePairs[i].Key.Split('.');
                        var pSetName      = splitName[0];
                        var attributeType = XbimAttributedObject.ConvertToAttributeType(property);
                        attributeType.propertySetName = pSetName;
                        //var pSetDef = attributedObject.GetPropertySetDefinition(pSetName);
                        //if (pSetDef != null)
                        //    attributeType.externalID = ExternalEntityIdentity(pSetDef);
                        attributeCollection.Add(attributeType);
                    }
                    return(attributeCollection);
                }
            }
            return(null);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public static void AddBuildingElement(
            IIfcObjectDefinition site,
            IIfcObjectDefinition building)
        {
            IEnumerable <IIfcRelAggregates> decomposition = site.IsDecomposedBy;

            if (decomposition.Count() == 0) //none defined create the relationship
            {
                IIfcRelAggregates relSub = site.Model.Instances.New <IfcRelAggregates>();
                relSub.RelatingObject = site;
                relSub.RelatedObjects.Add(building);
            }
            else
            {
                decomposition.First().RelatedObjects.Add(building);
            }
        }
Exemplo n.º 19
0
    /// <summary>
    /// 递归获取IfcObject的空间结构
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="cur"></param>
    /// <returns></returns>
    private static ISpatialData GetSpatialSturctureData(IIfcObjectDefinition parent, IIfcObjectDefinition cur)
    {
        ISpatialData sp = default;

        var spatialElement = cur as IIfcSpatialStructureElement;

        if (spatialElement != null)
        {
            //获得spatialElement的spatialData
            sp = InstaniateCurSpatial(spatialElement);
            if (sp != null)
            {
                spatialDatas.Add(sp);
                //使用 IfcRelContainedInSpatialElement 获取包含的元素
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                if (containedElements.Count() > 0)
                {
                    foreach (var element in containedElements)
                    {
                        //查找到相应的productData
                        var prod = productDatas.Find(p => p.ProductGeometryData.productLabel == element.EntityLabel);

                        if (prod == null)
                        {
                            var go = new GameObject();
                            var pd = go.AddComponent <ProductData>();
                            pd.ProductGeometryData = new BimProduct(element.EntityLabel, (short)element.EntityLabel);
                            SetProductData(pd, element);
                            sp.AddProduct(pd);
                            SetDecomposeProduct(pd, element.IsDecomposedBy);
                        }
                        else
                        {
                            SetProductData((ProductData)prod, element);
                            sp.AddProduct(prod);
                        }
                    }
                }
            }
        }
        foreach (var item in cur.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
        {
            sp.AddSpatial(GetSpatialSturctureData(cur, item));
        }
        return(sp);
    }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
    private static SpatialData GetSpatialStructure(IIfcObjectDefinition current)
    {
        SpatialData sp             = default;
        var         spatialElement = current as IIfcSpatialStructureElement;

        if (spatialElement != null)
        {
            sp = InstantiateCurrentSpatial(spatialElement);
            if (sp != null)
            {
                PublicValue.spatialStructures.Add(sp);
                //考虑一下select需不需要
                //疑问,IIfcSpatialStructureElement的ContainsElements和IIfcObjectDefinition的DecomposedBy是不是一致的
                var containedElements = spatialElement.ContainsElements.SelectMany(e => e.RelatedElements);
                if (containedElements.Count() > 0)
                {
                    foreach (var element in containedElements)
                    {
                        //需要和public value的productsData生成的地方联系起来看看有没有可以优化的地方
                        var prod = PublicValue.productsData.Find(p => p.BimProduct.entityLabel == element.EntityLabel);
                        if (prod == null)
                        {
                            var go = new GameObject();
                            prod = go.AddComponent <ProductData>();
                            //考虑一下这种情况实际上只用到了BimProduct的Label
                            prod.BimProduct = new BimProduct(element.EntityLabel, (short)element.EntityLabel);
                            //这里和小泽写的不太一样
                            ///prod.SetProductData(element);
                            //sp.SubProducts.Add(prod);
                            prod.SetDecomposedProducts(element.IsDecomposedBy);
                        }
                        prod.SetProductData(element);
                        sp.SubProducts.Add(prod);
                    }
                }
            }
        }
        foreach (var item in current.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
        {
            sp.SubSpatialData.Add(GetSpatialStructure(item));
        }
        return(sp);
    }
Exemplo n.º 22
0
        public B5dProjectNode BuildTree(B5dObject b5dParent, IIfcObjectDefinition ifcParent, IIfcObjectDefinition ifcChild)
        {
            B5dProjectNode b5dChild = IfcObjectConverter.Convert(ifcChild);

            if (ifcChild is IIfcProject)
            {
                currentProject = b5dChild;
            }
            else
            {
                GltfRef.TryCreatingGltfRef(ifcChild.GlobalId.ToString(), currentProject, b5dChild);
            }


            if (b5dParent != null)
            {
                B5dProjectNodeChild ChildRelationship = B5dProjectNodeChild.CreateNodeChildRelation(b5dParent, b5dChild);
            }

            if (ifcChild is IIfcObject ifcObject)
            {
                // Use containsElements to recursively create nodes for Window, Door, Slab, Wall etc
                foreach (var ifcSpatialElement in RelContainedInSpatialStructure.GetElementsIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialElement);
                }

                // Use isDecomposedy to recursively create nodes for Project, Site, Building, Story and Space
                foreach (var ifcSpatialStructure in RelAggregates.GetSpatialStructuresIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialStructure);
                }

                // Use isDefinedBy to convert all of the ifcProperties
                PropertyConverter.ConvertProperties(ifcObject, b5dChild);
            }

            return(b5dChild);
        }
        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);
        }
    /// <summary>
    /// return spatial structure of cur IfcObject
    /// </summary>
    /// <param name="father"></param>
    /// <param name="cur"></param>
    /// <returns></returns>
    private static ISpatialData GetSpatialSturcture(IIfcObjectDefinition cur)
    {
        ISpatialData spd = default;

        //whether cur is spatial structure or not
        if (cur is IIfcSpatialStructureElement spatialElement)
        {
            //get spatialElement's spatialData
            spd = InstantiateCurSpatial(spatialElement);
            if (spd != null)
            {
                //get elements by using IfcRelContainedInSpatialElement
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                if (containedElements.Count() > 0)
                {
                    foreach (var element in containedElements)
                    {
                        if (element is IIfcElement)
                        {
                            var eled = InstantiateCurElement(element as IIfcElement);
                            spd.AddRelatedObjects(eled);
                            if (element.IsDecomposedBy != null && element.IsDecomposedBy.Count() > 0)
                            {
                                eled.SetDecomposeProduct(element.IsDecomposedBy);
                            }
                        }
                    }
                }
            }
        }

        //use IfcRelAggregares to obtain sub spatial structure
        foreach (var item in cur.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
        {
            spd.AddRelatedObjects(GetSpatialSturcture(item));
        }
        return(spd);
    }
Exemplo n.º 25
0
        //TODO: Check function below, see if it works!
        /// <summary>
        /// filter on IfcObjectDefinition objects
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="checkType"></param>
        /// <returns>bool true = exclude</returns>
        public bool ObjFilter(IIfcObjectDefinition obj, bool checkType = true)
        {
            bool exclude = false;

            if (obj is IIfcProduct)
            {
                exclude = IfcProductFilter.ItemsFilter(obj);
                //check the element is not defined by a type which is excluded, by default if no type, then no element included
                if (!exclude && checkType)
                {
                    var objType = Enumerable.OfType <IIfcRelDefinesByType>(((IIfcProduct)obj).IsDefinedBy).Select(rdbt => rdbt.RelatingType).FirstOrDefault(); //assuming only one IfcRelDefinesByType
                    if (objType != null)                                                                                                                       //if no type defined lets include it for now
                    {
                        exclude = IfcTypeObjectFilter.ItemsFilter(objType);
                    }
                }
            }
            else if (obj is IIfcTypeProduct)
            {
                exclude = IfcTypeObjectFilter.ItemsFilter(obj);
            }
            return(FlipResult ? !exclude : exclude);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Help method. Recursively visited elements
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="elemProperties"></param>
        private static void Process(IIfcObjectDefinition obj, ref LinkedList <NameValueCollection> elemProperties)
        {
            // try cast the obj to spatial structure element which contains geometry infomation
            var spatialElement = obj as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                elemProperties.AddLast(ExtractPropertiesForElement(spatialElement));

                // process element contained in this spartial structure element
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var element in containedElements)
                {
                    elemProperties.AddLast(ExtractPropertiesForElement(element));
                }
            }

            // process elements that are associated with this spatial element
            foreach (var item in obj.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
                Process(item, ref elemProperties);
            }
        }
Exemplo n.º 27
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);
            }
        }
Exemplo n.º 28
0
        public List <IIfcObjectDefinition> GetHierarchy(IIfcObjectDefinition Object)
        {
            var Hierarchy = PrintHierarchy(Object, 0);

            return(Hierarchy);
        }
Exemplo n.º 29
0
        public void processClassificationItems()
        {
            List <string> arrGuid    = new List <string>();
            List <string> arrClName  = new List <string>();
            List <string> arrClCode  = new List <string>();
            List <string> arrTGuid   = new List <string>();
            List <string> arrTClName = new List <string>();
            List <string> arrTClCode = new List <string>();

            string currStep = "Insert Classification records";

            List <string> className                   = new List <string>();
            List <string> classSource                 = new List <string>();
            List <OracleParameterStatus> classSPS     = new List <OracleParameterStatus>();
            List <string> classEdition                = new List <string>();
            List <string> classEdDate                 = new List <string>();
            List <OracleParameterStatus> classEdDPS   = new List <OracleParameterStatus>();
            List <string> classItemCode               = new List <string>();
            List <string> classItemName               = new List <string>();
            List <OracleParameterStatus> classItemNPS = new List <OracleParameterStatus>();
            List <string> classItemLocation           = new List <string>();
            List <OracleParameterStatus> classItemLPS = new List <OracleParameterStatus>();

            DBOperation.beginTransaction();

            OracleCommand command  = new OracleCommand(" ", DBOperation.DBConn);
            OracleCommand command2 = new OracleCommand(" ", DBOperation.DBConn);
            OracleCommand command3 = new OracleCommand(" ", DBOperation.DBConn);

            string sqlStmt = "Insert into " + DBOperation.formatTabName("BIMRL_CLASSIFICATION") + " (ClassificationName, ClassificationSource, "
                             + "ClassificationEdition, ClassificationEditionDate, ClassificationItemCode, ClassificationItemName, ClassificationItemLocation) Values "
                             + "(:1, :2, :3, to_date(:4, 'DD-MM-YYYY'), :5, :6, :7)";

            command.CommandText = sqlStmt;

            OracleParameter[] Param = new OracleParameter[7];
            for (int i = 0; i < 7; i++)
            {
                Param[i]           = command.Parameters.Add(i.ToString(), OracleDbType.Varchar2);
                Param[i].Direction = ParameterDirection.Input;
            }

            string sqlStmt2 = "Insert into " + DBOperation.formatTabName("BIMRL_ELEMCLASSIFICATION") + " (ElementID, ClassificationName, ClassificationItemCode) "
                              + " Values (:1, :2, :3)";

            command2.CommandText = sqlStmt2;

            OracleParameter[] Param2 = new OracleParameter[3];
            for (int i = 0; i < 3; i++)
            {
                Param2[i]           = command2.Parameters.Add(i.ToString(), OracleDbType.Varchar2);
                Param2[i].Direction = ParameterDirection.Input;
            }

            string sqlStmt3 = "Insert into " + DBOperation.formatTabName("BIMRL_TYPCLASSIFICATION") + " (ElementID, ClassificationName, ClassificationItemCode) "
                              + " Values (:1, :2, :3)";

            command3.CommandText = sqlStmt3;

            OracleParameter[] Param3 = new OracleParameter[3];
            for (int i = 0; i < 3; i++)
            {
                Param3[i]           = command3.Parameters.Add(i.ToString(), OracleDbType.Varchar2);
                Param3[i].Direction = ParameterDirection.Input;
            }

            IEnumerable <IIfcRelAssociatesClassification> relClasses = _model.Instances.OfType <IIfcRelAssociatesClassification>();

            foreach (IIfcRelAssociatesClassification relClass in relClasses)
            {
                if (!(relClass.RelatingClassification is IIfcClassificationReference))
                {
                    continue; // We only deal with IfcClassificationReference here
                }
                IIfcClassificationReference classRef = relClass.RelatingClassification as IIfcClassificationReference;
                Xbim.Ifc2x3.Interfaces.IIfcClassificationReference classRef2x3 = relClass.RelatingClassification as Xbim.Ifc2x3.Interfaces.IIfcClassificationReference;

                string itemLocation = string.Empty;
                if (classRef.Location != null)
                {
                    itemLocation = classRef.Location;
                }

                string itemRef = string.Empty;
                if (classRef2x3 != null)
                {
                    if (classRef2x3.ItemReference == null)
                    {
                        continue;
                    }
                    itemRef = classRef2x3.ItemReference;
                }
                else
                {
                    if (classRef.Identification == null)
                    {
                        continue;
                    }
                    itemRef = classRef.Identification;
                }

                string itemName = string.Empty;
                if (classRef.Name != null)
                {
                    itemName = classRef.Name;
                }

                string refName    = string.Empty;
                string refEdition = string.Empty;
                string refSource  = string.Empty;
                string refEdDate  = string.Empty;
                if (classRef.ReferencedSource == null)
                {
                    refName    = "Default Classification";
                    refEdition = "Default Edition";
                }
                else
                {
                    if (classRef.ReferencedSource is IIfcClassification)
                    {
                        IIfcClassification theRefSource = classRef.ReferencedSource as IIfcClassification;
                        refName    = theRefSource.Name;
                        refEdition = theRefSource.Edition;
                        refSource  = theRefSource.Source;
                        if (theRefSource.EditionDate != null)
                        {
                            refEdDate = theRefSource.EditionDate.Value.ToString();
                        }
                    }
                    else
                    {
                        IIfcClassificationReference theRefSource = classRef.ReferencedSource as IIfcClassificationReference;
                        refSource = theRefSource.Identification;
                        refName   = theRefSource.Name;
                    }
                }

                Tuple <string, string> bimrlClass = new Tuple <string, string>(refName, itemRef); // PK for BIMRL_CLASSIFICATION
                if (!_refBIMRLCommon.ClassificationSetExist(bimrlClass))
                {
                    // Record not in DB yet, insert
                    className.Add(refName);
                    classSource.Add(refSource);
                    classEdition.Add(refEdition);
                    classEdDate.Add(refEdDate);
                    if (string.IsNullOrEmpty(refEdDate))
                    {
                        classEdDPS.Add(OracleParameterStatus.NullInsert);
                    }
                    else
                    {
                        classEdDPS.Add(OracleParameterStatus.Success);
                    }
                    classItemCode.Add(itemRef);
                    classItemName.Add(itemName);
                    if (string.IsNullOrEmpty(itemName))
                    {
                        classItemNPS.Add(OracleParameterStatus.NullInsert);
                    }
                    else
                    {
                        classItemNPS.Add(OracleParameterStatus.Success);
                    }
                    classItemLocation.Add(itemLocation);
                    if (string.IsNullOrEmpty(itemName))
                    {
                        classItemLPS.Add(OracleParameterStatus.NullInsert);
                    }
                    else
                    {
                        classItemLPS.Add(OracleParameterStatus.Success);
                    }

                    // Add into Hashset, so that we do not have to insert duplicate record
                    _refBIMRLCommon.ClassificationSetAdd(bimrlClass);
                }

                IEnumerable <IIfcDefinitionSelect> relObjects = relClass.RelatedObjects;
                foreach (IIfcDefinitionSelect relObjSel in relObjects)
                {
                    IIfcObjectDefinition relObj = relObjSel as IIfcObjectDefinition;
                    if (relObj is IIfcTypeObject)
                    {
                        arrTGuid.Add(relObj.GlobalId.ToString());
                        arrTClName.Add(refName);
                        arrTClCode.Add(itemRef);
                    }
                    else if (relObj is IIfcObject)
                    {
                        arrGuid.Add(relObj.GlobalId.ToString());
                        arrClName.Add(refName);
                        arrClCode.Add(itemRef);
                    }
                }

                if ((className.Count + arrGuid.Count + arrTGuid.Count) >= DBOperation.commitInterval)
                {
                    int commandStatus;

                    try
                    {
                        // for BIMRL_CLASSIFICATION
                        if (className.Count > 0)
                        {
                            Param[0].Value           = className.ToArray();
                            Param[1].Value           = classSource.ToArray();
                            Param[1].ArrayBindStatus = classSPS.ToArray();
                            Param[2].Value           = classEdition.ToArray();
                            Param[3].Value           = classEdDate.ToArray();
                            Param[3].ArrayBindStatus = classEdDPS.ToArray();
                            Param[4].Value           = classItemCode.ToArray();
                            Param[5].Value           = classItemName.ToArray();
                            Param[5].ArrayBindStatus = classItemNPS.ToArray();
                            Param[6].Value           = classItemLocation.ToArray();
                            Param[6].ArrayBindStatus = classItemLPS.ToArray();
                            for (int i = 0; i < 6; i++)
                            {
                                Param[i].Size = className.Count;
                            }
                            command.ArrayBindCount = className.Count;

                            currStep      = sqlStmt;
                            commandStatus = command.ExecuteNonQuery();
                        }

                        // for BIMRL_ELEMCLASSIFICATION
                        if (arrGuid.Count > 0)
                        {
                            Param2[0].Value = arrGuid.ToArray();
                            Param2[1].Value = arrClName.ToArray();
                            Param2[2].Value = arrClCode.ToArray();
                            for (int i = 0; i < 3; i++)
                            {
                                Param[i].Size = arrGuid.Count;
                            }
                            command2.ArrayBindCount = arrGuid.Count;

                            currStep      = sqlStmt2;
                            commandStatus = command2.ExecuteNonQuery();
                        }

                        // for BIMRL_TYPCLASSIFICATION
                        if (arrTGuid.Count > 0)
                        {
                            Param3[0].Value = arrTGuid.ToArray();
                            Param3[1].Value = arrTClName.ToArray();
                            Param3[2].Value = arrTClCode.ToArray();
                            for (int i = 0; i < 3; i++)
                            {
                                Param3[i].Size = arrTGuid.Count;
                            }
                            command3.ArrayBindCount = arrTGuid.Count;

                            currStep      = sqlStmt3;
                            commandStatus = command3.ExecuteNonQuery();
                        }

                        DBOperation.commitTransaction();

                        className.Clear();
                        classSource.Clear();
                        classSPS.Clear();
                        classEdition.Clear();
                        classEdDate.Clear();
                        classEdDPS.Clear();
                        classItemCode.Clear();
                        classItemName.Clear();
                        classItemNPS.Clear();
                        classItemLocation.Clear();
                        classItemLPS.Clear();

                        arrGuid.Clear();
                        arrClCode.Clear();
                        arrClName.Clear();

                        arrTGuid.Clear();
                        arrTClCode.Clear();
                        arrTClName.Clear();
                    }
                    catch (OracleException e)
                    {
                        string excStr = "%%Insert Error - " + e.Message + "\n\t" + currStep;
                        _refBIMRLCommon.StackPushIgnorableError(excStr);

                        className.Clear();
                        classSource.Clear();
                        classSPS.Clear();
                        classEdition.Clear();
                        classEdDate.Clear();
                        classEdDPS.Clear();
                        classItemCode.Clear();
                        classItemName.Clear();
                        classItemNPS.Clear();
                        classItemLocation.Clear();
                        classItemLPS.Clear();

                        arrGuid.Clear();
                        arrClCode.Clear();
                        arrClName.Clear();

                        arrTGuid.Clear();
                        arrTClCode.Clear();
                        arrTClName.Clear();

                        continue;
                    }
                    catch (SystemException e)
                    {
                        string excStr = "%%Insert Error - " + e.Message + "\n\t" + currStep;
                        _refBIMRLCommon.StackPushIgnorableError(excStr);
                    }
                }
            }

            if ((className.Count + arrGuid.Count + arrTGuid.Count) > 0)
            {
                int commandStatus;

                try
                {
                    // for BIMRL_CLASSIFICATION
                    if (className.Count > 0)
                    {
                        Param[0].Value           = className.ToArray();
                        Param[1].Value           = classSource.ToArray();
                        Param[1].ArrayBindStatus = classSPS.ToArray();
                        Param[2].Value           = classEdition.ToArray();
                        Param[3].Value           = classEdDate.ToArray();
                        Param[3].ArrayBindStatus = classEdDPS.ToArray();
                        Param[4].Value           = classItemCode.ToArray();
                        Param[5].Value           = classItemName.ToArray();
                        Param[5].ArrayBindStatus = classItemNPS.ToArray();
                        Param[6].Value           = classItemLocation.ToArray();
                        Param[6].ArrayBindStatus = classItemLPS.ToArray();
                        for (int i = 0; i < 6; i++)
                        {
                            Param[i].Size = className.Count;
                        }
                        command.ArrayBindCount = className.Count;

                        currStep      = sqlStmt;
                        commandStatus = command.ExecuteNonQuery();
                    }

                    // for BIMRL_ELEMCLASSIFICATION
                    if (arrGuid.Count > 0)
                    {
                        Param2[0].Value = arrGuid.ToArray();
                        Param2[1].Value = arrClName.ToArray();
                        Param2[2].Value = arrClCode.ToArray();
                        for (int i = 0; i < 3; i++)
                        {
                            Param[i].Size = arrGuid.Count;
                        }
                        command2.ArrayBindCount = arrGuid.Count;

                        currStep      = sqlStmt2;
                        commandStatus = command2.ExecuteNonQuery();
                    }

                    // for BIMRL_TYPCLASSIFICATION
                    if (arrTGuid.Count > 0)
                    {
                        Param3[0].Value = arrTGuid.ToArray();
                        Param3[1].Value = arrTClName.ToArray();
                        Param3[2].Value = arrTClCode.ToArray();
                        for (int i = 0; i < 3; i++)
                        {
                            Param3[i].Size = arrTGuid.Count;
                        }
                        command3.ArrayBindCount = arrTGuid.Count;

                        currStep      = sqlStmt3;
                        commandStatus = command3.ExecuteNonQuery();
                    }

                    DBOperation.commitTransaction();
                }

                catch (OracleException e)
                {
                    string excStr = "%%Insert Error - " + e.Message + "\n\t" + currStep;
                    _refBIMRLCommon.StackPushIgnorableError(excStr);
                }
                catch (SystemException e)
                {
                    string excStr = "%%Insert Error - " + e.Message + "\n\t" + currStep;
                    _refBIMRLCommon.StackPushError(excStr);
                    throw;
                }
            }

            DBOperation.commitTransaction();
            command.Dispose();
            command2.Dispose();
            command3.Dispose();
        }
Exemplo n.º 30
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");
                        }
                    }
                }


                /***************************************************************************/
            }
        }