Example #1
0
        public FacilityType(IIfcBuilding ifcBuilding, CoBieLiteHelper helper)
            : this()
        {
            //   _ifcBuilding = ifcBuilding;
            var model = ifcBuilding.Model;

            externalEntityName  = helper.ExternalEntityName(ifcBuilding);
            externalID          = helper.ExternalEntityIdentity(ifcBuilding);
            externalSystemName  = helper.ExternalSystemName(ifcBuilding);
            FacilityName        = ifcBuilding.Name;
            FacilityDescription = ifcBuilding.Description;
            FacilityCategory    = helper.GetClassification(ifcBuilding);
            var ifcProject = model.Instances.OfType <IIfcProject>().FirstOrDefault();

            if (ifcProject != null)
            {
                ProjectAssignment = new ProjectType(ifcProject, helper);
                var ifcSite = ifcProject.SpatialStructuralElements.FirstOrDefault(p => p is IIfcSite) as IIfcSite;
                if (ifcSite != null)
                {
                    SiteAssignment = new SiteType(ifcSite, helper);
                }
                SetDefaultUnits(helper);
                FacilityDeliverablePhaseName = ifcProject.Phase;
                var storeys            = ifcBuilding.BuildingStoreys;
                var ifcBuildingStories = storeys as IList <IIfcBuildingStorey> ?? storeys.ToList();
                if (ifcBuildingStories.Any())
                {
                    Floors = new FloorCollectionType {
                        Floor = new List <FloorType>(ifcBuildingStories.Count)
                    };
                    for (int i = 0; i < ifcBuildingStories.Count; i++)
                    {
                        Floors.Add(new FloorType(ifcBuildingStories[i], helper));
                    }
                }
            }
            //Attributes
            var ifcAttributes = helper.GetAttributes(ifcBuilding);

            if (ifcAttributes != null && ifcAttributes.Any())
            {
                FacilityAttributes = new AttributeCollectionType {
                    Attribute = ifcAttributes
                }
            }
            ;

            //Zones

            var allSpaces = GetAllSpaces(ifcBuilding);
            var allZones  = GetAllZones(allSpaces, helper);
            var ifcZones  = allZones.ToArray();

            if (ifcZones.Any())
            {
                Zones = new ZoneCollectionType {
                    Zone = new List <ZoneType>(ifcZones.Length)
                };
                for (int i = 0; i < ifcZones.Length; i++)
                {
                    Zones.Add(new ZoneType(ifcZones[i], helper));
                }
            }

            //Assets
            var allAssetsinThisFacility = new HashSet <IIfcElement>(helper.GetAllAssets(ifcBuilding));

            //AssetTypes
            //Get all assets that are in this facility/building
            var allAssetTypesInThisFacility = AllAssetTypesInThisFacility(ifcBuilding, allAssetsinThisFacility, helper);

            if (allAssetTypesInThisFacility.Any())
            {
                AssetTypes = new AssetTypeCollectionType
                {
                    AssetType = new List <AssetTypeInfoType>(allAssetTypesInThisFacility.Count)
                };
                for (int i = 0; i < allAssetTypesInThisFacility.Count; i++)
                {
                    AssetTypes.Add(new AssetTypeInfoType(allAssetTypesInThisFacility[i], helper));
                }
            }

            //Systems
            var allSystemsInThisFacility = helper.SystemAssignment
                                           .Where(v => v.Value.Any(allAssetsinThisFacility.Contains))
                                           .Select(k => k.Key).ToArray();

            if (allSystemsInThisFacility.Any())
            {
                Systems = new SystemCollectionType
                {
                    System = new List <SystemType>(allSystemsInThisFacility.Length)
                };

                for (int i = 0; i < allSystemsInThisFacility.Length; i++)
                {
                    Systems.Add(new SystemType(allSystemsInThisFacility[i], helper));
                }
            }

            //Contacts
            var contacts  = helper.GetContacts();
            var ifcActors = contacts as IIfcActorSelect[] ?? contacts.ToArray();

            if (ifcActors.Any())
            {
                Contacts = new ContactCollectionType
                {
                    Contact = new List <ContactType>(ifcActors.Length)
                };

                for (int i = 0; i < ifcActors.Length; i++)
                {
                    Contacts.Add(new ContactType(ifcActors[i], helper));
                }
            }
        }