Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private static int GetStoreyId(IIfcElement ifcElement, List <IIfcBuildingStorey> storeys)
        {
            if (ifcElement == null)
            {
                return(-1);
            }
            var ret = -1;

            foreach (var rel in ifcElement.ContainedInStructure)
            {
                if (rel.RelatingStructure is IIfcBuildingStorey storey)
                {
                    int index = storeys.IndexOf(storey);
                    if (index == -1)
                    {
                        index = storeys.Count;
                        storeys.Add(storey);
                    }
                    ret = index;
                }
            }
            return(ret);
        }
Ejemplo n.º 3
0
        internal static List <Data> Run(Xbim.Ifc.IfcStore model)
        {
            // Specify elements
            List <IIfcWall> allWalls =
                model.Instances.OfType <IIfcWall>().ToList(); int a = allWalls.Count();

            List <IIfcOpeningElement> allOpenigs =
                model.Instances.OfType <IIfcOpeningElement>().ToList(); int b = allOpenigs.Count();

            List <IIfcBeamType> allBeams =
                model.Instances.OfType <IIfcBeamType>().ToList(); int c = allBeams.Count();

            List <IIfcColumnType> allColumns =
                model.Instances.OfType <IIfcColumnType>().ToList(); int d = allColumns.Count();

            List <IIfcElement> ifcElements =
                model.Instances.OfType <IIfcElement>().ToList(); int e = ifcElements.Count();


            // Extract geometry
            var context = new Xbim3DModelContext(model);

            context.CreateContext();
            var instances = context.ShapeInstances().ToList();
            IEnumerator <XbimShapeInstance> allShapeInstances = instances.GetEnumerator();

            List <Data> allData = new List <Data>();

            while (allShapeInstances.MoveNext())
            {
                XbimShapeInstance xbimShapeInstance = allShapeInstances.Current;
                IIfcElement       element           = ifcElements.FirstOrDefault(x => x.EntityLabel == xbimShapeInstance.IfcProductLabel);
                if (element == null)
                {
                    continue;
                }
                string name = element.Name;
                string id   = element.GlobalId;

                var ro          = xbimShapeInstance.Transformation;
                var translation = ro.Translation;
                var decompose   = ro.Decompose(out XbimVector3D scale, out XbimQuaternion rot, out XbimVector3D trans);

                Matrix <double> matrixData = DenseMatrix.OfArray(new double[, ] {
                    { ro.M11, ro.M12, ro.M13, ro.M14 },
                    { ro.M21, ro.M22, ro.M23, ro.M24 },
                    { ro.M31, ro.M32, ro.M33, ro.M34 },
                    { ro.OffsetX, ro.OffsetY, ro.OffsetZ, ro.M44 }
                });
                matrixData = matrixData.Transpose();
                //Console.WriteLine(matrixData.ToString());
                XbimRect3D  rect = xbimShapeInstance.BoundingBox;
                XbimPoint3D Min  = rect.Min;
                XbimPoint3D Max  = rect.Max;
                Data        data = new Data
                                   (
                    name,
                    id,
                    new BoundingBox(new XYZ(Min.X, Min.Y, Min.Z), new XYZ(Max.X, Max.Y, Max.Z)),
                    new XYZ(translation.X, translation.Y, translation.Z),
                    matrixData
                                   );
                allData.Add(data);
            }

            return(allData);
        }
Ejemplo n.º 4
0
        protected override Asset Mapping(IIfcElement ifcElement, Asset target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity  = helper.ExternalEntityName(ifcElement);
            target.ExternalId      = helper.ExternalEntityIdentity(ifcElement);
            target.AltExternalId   = ifcElement.GlobalId;
            target.ExternalSystem  = helper.ExternalSystemName(ifcElement);
            target.Name            = ifcElement.Name;
            target.CreatedBy       = helper.GetCreatedBy(ifcElement);
            target.CreatedOn       = helper.GetCreatedOn(ifcElement);
            target.Categories      = helper.GetCategories(ifcElement);
            target.AssetIdentifier = helper.GetCoBieProperty("AssetIdentifier", ifcElement);
            target.BarCode         = helper.GetCoBieProperty("AssetBarCode", ifcElement);
            if (!string.IsNullOrWhiteSpace(ifcElement.Description))
            {
                target.Description = ifcElement.Description;
            }
            else
            {
                target.Description = helper.GetCoBieProperty("AssetSerialNumber", ifcElement);
            }
            target.InstallationDate  = helper.GetCoBieProperty <DateTime>("AssetInstallationDate", ifcElement);
            target.SerialNumber      = helper.GetCoBieProperty("AssetSerialNumber", ifcElement);
            target.TagNumber         = helper.GetCoBieProperty("AssetTagNumber", ifcElement);
            target.WarrantyStartDate = helper.GetCoBieProperty <DateTime>("AssetWarrantyStartDate", ifcElement);



            //Attributes
            target.Attributes = helper.GetAttributes(ifcElement);

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

            helper.AddDocuments(docsMappings, target, ifcElement);

            //System Assignments

            //Space Assignments
            var spatialElements = helper.GetSpaces(ifcElement);

            var ifcSpatialStructureElements = spatialElements.ToList();

            target.Spaces = new List <SpaceKey>();
            if (ifcSpatialStructureElements.Any())
            {
                foreach (var spatialElement in ifcSpatialStructureElements)
                {
                    var space = new SpaceKey {
                        Name = spatialElement.Name
                    };
                    target.Spaces.Add(space);
                }
            }
            //else //it is in nowhere land, assign it to a special space all Default External
            //{
            //    var space = new SpaceKey();
            //    space.Name = "Default External";
            //    space.KeyType = EntityType.Space;
            //    target.Spaces.Add(space);
            //}
            else // if it is part of an aggregated element, add spaces of the aggregated element
            {
                var assemblyParts = ifcElement.Model.Instances.OfType <IIfcRelAggregates>().Where(b => b.RelatedObjects.Contains(ifcElement)).FirstOrDefault();
                if (assemblyParts != null)
                {
                    ifcSpatialStructureElements = helper.GetSpaces((IIfcElement)assemblyParts.RelatingObject).ToList();
                    target.Spaces = new List <SpaceKey>();
                    if (ifcSpatialStructureElements.Any())
                    {
                        foreach (var spatialElement in ifcSpatialStructureElements)
                        {
                            var Fspace = new SpaceKey {
                                Name = spatialElement.Name
                            };
                            target.Spaces.Add(Fspace);
                        }
                    }
                }
            }


            //Issues


            return(target);
        }
Ejemplo n.º 5
0

        
    public static IElementData InstantiateCurElement(IIfcElement e)
    {
        var          go = new GameObject();
        IElementData ele;

        switch (e)
        {
        case IIfcBeam _:
            ele = go.AddComponent <BeamData>();
            break;

        case IIfcBuildingElementProxy _:
            ele = go.AddComponent <BuildingElementProxyData>();
            break;

        case IIfcColumn _:
            ele = go.AddComponent <ColumnData>();
            break;

        case IIfcCovering _:
            ele = go.AddComponent <CoveringData>();
            break;

        case IIfcCurtainWall _:
            ele = go.AddComponent <CurtainWallData>();
            break;

        case IIfcDoor _:
            ele = go.AddComponent <DoorData>();
            break;

        case IIfcFlowTerminal _:
            ele = go.AddComponent <FlowTerminalData>();
            break;

        case IIfcFooting _:
            ele = go.AddComponent <FootingData>();
            break;

        case IIfcFurnishingElement _:
            ele = go.AddComponent <FurnitureData>();
            break;

        case IIfcMember _:
            ele = go.AddComponent <MemberData>();
            break;

        case IIfcPile _:
            ele = go.AddComponent <PileData>();
            break;

        case IIfcPlate _:
            ele = go.AddComponent <PlateData>();
            break;

        case IIfcRailing _:
            ele = go.AddComponent <RailingData>();
            break;

        case IIfcRamp _:
            ele = go.AddComponent <RampData>();
            break;

        case IIfcRampFlight _:
            ele = go.AddComponent <RampFlightData>();
            break;

        case IIfcRoof _:
            ele = go.AddComponent <RoofData>();
            break;

        case IIfcSlab _:
            ele = go.AddComponent <SlabData>();
            break;

        case IIfcStair _:
            ele = go.AddComponent <StairData>();
            break;

        case IIfcStairFlight _:
            ele = go.AddComponent <StairFlightData>();
            break;

        case IIfcWall _:
            ele = go.AddComponent <WallData>();
            break;

        case IIfcWindow _:
            ele = go.AddComponent <WindowData>();
            break;

        default:
            ele = go.AddComponent <ElementData>();
            break;
        }

        if (ele != null)
        {
            ele.InitialObject(e);
        }
        return(ele);
    }
Ejemplo n.º 7
0
        internal static List <Data> GetHierarchialData
            (Xbim.Ifc2x3.Interfaces.IIfcObjectDefinition project, int level, List <XbimShapeInstance> allShapeInstances)
        {
            List <Data> collectedData  = new List <Data>();
            Data        data           = null;
            var         spatialElement = project as IIfcSpatialStructureElement;

            if (spatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                IEnumerable <XbimShapeInstance> allShapeEnumer = allShapeInstances.AsEnumerable <XbimShapeInstance>();

                foreach (var instance in allShapeInstances)
                {
                    var         current = instance;
                    IIfcProduct element = containedElements.FirstOrDefault(x => x.EntityLabel == current.IfcProductLabel);

                    if (element == null)
                    {
                        continue;
                    }
                    IIfcElement ifcelement = element as IIfcElement;
                    string      name       = ifcelement.Name;
                    string      id         = ifcelement.GlobalId;
                    BoundingBox bbox       = new BoundingBox(
                        new XYZ(current.BoundingBox.Min.X, current.BoundingBox.Min.Y, current.BoundingBox.Min.Z),
                        new XYZ(current.BoundingBox.Max.X, current.BoundingBox.Max.Y, current.BoundingBox.Max.Z)
                        );
                    var             transformation = current.Transformation;
                    var             translation    = transformation.Translation;
                    var             ro             = transformation;
                    Matrix <double> matrixData     = DenseMatrix.OfArray(new double[, ] {
                        { ro.M11, ro.M12, ro.M13, ro.M14 },
                        { ro.M21, ro.M22, ro.M23, ro.M24 },
                        { ro.M31, ro.M32, ro.M33, ro.M34 },
                        { ro.OffsetX, ro.OffsetY, ro.OffsetZ, ro.M44 }
                    });
                    matrixData = matrixData.Transpose();

                    data = new Data
                           (
                        name,
                        id,
                        bbox,
                        new XYZ(translation.X, translation.Y, translation.Z),
                        matrixData,
                        element.GetType().Name
                           );
                    collectedData.Add(data);
                }
            }

            foreach
            (
                var item in
                project.IsDecomposedBy
                .SelectMany(r => r.RelatedObjects)
            )
            {
                Data itemData  = new Data(item.Name, item.GlobalId);
                var  dataChild = GetHierarchialData(item, level + 1, allShapeInstances);
                if (dataChild == null)
                {
                    continue;
                }
                itemData.AddChild(dataChild);
                collectedData.Add(itemData);
            }


            return(collectedData);
        }
Ejemplo n.º 8
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);
            IIfcValue DefaultNominalValue = new IfcText("");

            foreach (IIfcSpace Space in Spaces)
            {
                Console.WriteLine($"Space: {Space.LongName}  {Space.Name}");
                Space.ObjectType = new IfcLabel("");

                var Props = GetPropsForProduct(Space);
                foreach (IIfcPropertySingleValue Prop in Props)
                {
                    if (Prop.NominalValue != null && Prop.NominalValue.Value != null)
                    {
                        Console.WriteLine($"{Prop.Name}  {Prop.NominalValue.Value}");
                    }
                }
            }

            foreach (IIfcZone Zone in Zones)
            {
                Console.WriteLine($"Zone: {Zone.LongName}  {Zone.Name}");

                var Props = GetPropsForProduct(Zone);
                foreach (IIfcPropertySingleValue Prop in Props)
                {
                    if (Prop.NominalValue != null && Prop.NominalValue.Value != null)
                    {
                        Console.WriteLine($"{Prop.Name}  {Prop.NominalValue.Value}");
                    }
                }
            }

            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)
                {
                }
            }

            if (Object != null)
            {
                // ifcRelAggregates to get spatial decomposition of spatial structure elements
                IEnumerable <IIfcObjectDefinition> ifcRelAggregates = Object.IsDecomposedBy.SelectMany(r => r.RelatedObjects);
                if (ifcRelAggregates != null)
                {
                    foreach (var SpatialStructure in ifcRelAggregates)
                    {
                    }
                }
            }

            return(Hierarchy);
        }