public Xbim.CobieLiteUk.System mapSystem(IIfcSystem ifcSystem, Xbim.CobieLiteUk.System target)
        {
            target.ExternalEntity = Helper.ExternalEntityName(ifcSystem);
            target.ExternalId     = Helper.ExternalEntityIdentity(ifcSystem);
            target.AltExternalId  = ifcSystem.GlobalId;
            target.ExternalSystem = Helper.GetCreatingApplication(ifcSystem);
            target.Name           = ifcSystem.Name;
            target.Description    = ifcSystem.Description;
            target.Categories     = Helper.GetCategories(ifcSystem);
            target.Attributes     = Helper.GetAttributes(ifcSystem);

            IEnumerable <IIfcDocumentSelect> documentEnumerable = Helper.GetDocuments(ifcSystem);

            List <Document> documents = new List <Document>();
            List <string>   UsedNames = new List <string>();

            foreach (var ifcDocumentSelect in documentEnumerable)
            {
                if (ifcDocumentSelect is IIfcDocumentReference)
                {
                    var ifcDocumentReference = ifcDocumentSelect as IIfcDocumentReference;
                    if (ifcDocumentReference != null)
                    {
                        Document document = ConvertToDocument(ifcDocumentReference, ifcDocumentReference.ReferencedDocument, UsedNames);
                        documents.Add(document);
                    }
                }
            }

            target.Documents = documents;

            return(target);
        }
Example #2
0
        private void CleanupSystems(Facility facility)
        {
            List <Xbim.CobieLiteUk.System> systems = System.Linq.Enumerable.ToList(facility.Get <Xbim.CobieLiteUk.System>());

            Xbim.CobieLiteUk.System defaultSystem = systems.Find(system => system.Name.Equals("Default system"));
            if (defaultSystem != null)
            {
                systems.Remove(defaultSystem);
                facility.Systems = systems;
            }
        }
        protected override Xbim.CobieLiteUk.System Mapping(IIfcPropertySet pSet, Xbim.CobieLiteUk.System target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

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

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

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

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

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

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

            helper.AddDocuments(docsMappings, target, pSet);

            //TODO:
            //System Issues

            return(target);
        }
Example #4
0
        private void MapSystems(IfcStore ifcStore, LibalIfcToCOBieLiteUkExchanger ifcToCoBieLiteUkExchanger, Facility facility)
        {
            var systemDictionary = Enumerable.ToList(ifcStore.Instances.OfType <IIfcRelAssignsToGroup>())
                                   .Where(r => (r.RelatingGroup is IIfcSystem) && !(r.RelatingGroup is IIfcZone))
                                   .ToDictionary(k => (IIfcSystem)k.RelatingGroup, v => v.RelatedObjects);

            facility.Systems = new List <Xbim.CobieLiteUk.System>();
            foreach (var keyValue in systemDictionary)
            {
                Xbim.CobieLiteUk.System mappedSystem = ifcToCoBieLiteUkExchanger.mapSystem(keyValue.Key, new Xbim.CobieLiteUk.System());
                facility.Systems.Add(mappedSystem);
            }

            var SystemAssignmentSet = ifcStore.Instances.OfType <IIfcRelAssignsToGroup>().Where(r => r.RelatingGroup is IIfcSystem)
                                      .Distinct(new IfcRelAssignsToGroupRelatedGroupObjCompare());

            var ret = SystemAssignmentSet.ToDictionary(k => (IIfcSystem)k.RelatingGroup, v => v.RelatedObjects);

            foreach (var systemAssignment in ret)
            {
                var name = systemAssignment.Key.Name;
                Xbim.CobieLiteUk.System foundSystem = facility.Systems.Find(system => system.Name.Equals(name));
                if (foundSystem != null)
                {
                    IItemSet <IIfcObjectDefinition> components = systemAssignment.Value;

                    foreach (var component in components)
                    {
                        if (!(component is IIfcSystem))
                        {
                            var assetKey = new AssetKey();
                            assetKey.Name = component.Name;
                            List <AssetKey> systemComponents = foundSystem.Components != null
                                ? foundSystem.Components
                                : new List <AssetKey>();
                            systemComponents.Add(assetKey);
                            foundSystem.Components = systemComponents;
                        }
                    }
                }
            }
        }
Example #5
0
        protected override Xbim.CobieLiteUk.System Mapping(IIfcSystem ifcSystem, Xbim.CobieLiteUk.System target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity = helper.ExternalEntityName(ifcSystem);
            target.ExternalId     = helper.ExternalEntityIdentity(ifcSystem);
            target.AltExternalId  = ifcSystem.GlobalId;
            target.ExternalSystem = helper.ExternalSystemName(ifcSystem);
            target.Name           = ifcSystem.Name;
            target.Description    = ifcSystem.Description;
            target.CreatedBy      = helper.GetCreatedBy(ifcSystem);
            target.CreatedOn      = helper.GetCreatedOn(ifcSystem);
            target.Categories     = helper.GetCategories(ifcSystem);
            //Add Assets
            var systemAssignments    = helper.GetSystemAssignments(ifcSystem);
            var ifcObjectDefinitions = systemAssignments as IList <IIfcObjectDefinition> ?? systemAssignments.ToList();

            if (ifcObjectDefinitions.Any())
            {
                target.Components = new List <AssetKey>();
                foreach (var ifcObjectDefinition in ifcObjectDefinitions)
                {
                    var assetKey = new AssetKey {
                        Name = ifcObjectDefinition.Name
                    };
                    target.Components.Add(assetKey);
                }
            }

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

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

            helper.AddDocuments(docsMappings, target, ifcSystem);

            //TODO:
            //System Issues
            return(target);
        }
        protected override Facility Mapping(IIfcBuilding ifcBuilding, Facility facility)
        {
            //Reset to prevent freezing in cases of various facilities
            Exchanger.ReportProgress.Reset();
            //Helper should do 10% of progress
            Exchanger.ReportProgress.NextStage(4, 42, string.Format("Creating Facility {0}", ifcBuilding.Name != null ? ifcBuilding.Name.ToString() : string.Empty));//finish progress at 42%
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;
            var model  = ifcBuilding.Model;

            facility.ExternalEntity = helper.ExternalEntityName(ifcBuilding);
            facility.ExternalId     = helper.ExternalEntityIdentity(ifcBuilding);
            facility.AltExternalId  = ifcBuilding.GlobalId;
            facility.ExternalSystem = helper.ExternalSystemName(ifcBuilding);
            facility.Name           = helper.GetFacilityName(ifcBuilding);
            facility.Description    = ifcBuilding.Description;
            facility.CreatedBy      = helper.GetCreatedBy(ifcBuilding);
            facility.CreatedOn      = helper.GetCreatedOn(ifcBuilding);
            facility.Categories     = helper.GetCategories(ifcBuilding);
            var ifcProject = model.Instances.OfType <IIfcProject>().FirstOrDefault();

            if (ifcProject != null)
            {
                if (facility.Categories == null) //use the project Categories instead
                {
                    facility.Categories = helper.GetCategories(ifcProject);
                }
                facility.Project = new Project();
                var projectMapping = Exchanger.GetOrCreateMappings <MappingIfcProjectToProject>();
                projectMapping.AddMapping(ifcProject, facility.Project);
                Exchanger.ReportProgress.IncrementAndUpdate();
                var ifcSite     = ifcProject.Sites.FirstOrDefault();
                var siteMapping = Exchanger.GetOrCreateMappings <MappingIfcSiteToSite>();

                //Facility Attributes
                facility.Attributes = helper.GetAttributes(ifcBuilding);

                if (ifcSite != null)
                {
                    facility.Site = new Site();
                    siteMapping.AddMapping(ifcSite, facility.Site);

                    if (ifcSite.RefLatitude.HasValue && ifcSite.RefLongitude.HasValue)
                    {
                        facility.Attributes.Add(helper.MakeAttribute(ifcSite, "RefLatitude", ifcSite.RefLatitude.Value.AsDouble));
                        facility.Attributes.Add(helper.MakeAttribute(ifcSite, "RefLongtitude", ifcSite.RefLongitude.Value.AsDouble));
                    }
                }
                else //create a default "External area"
                {
                    facility.Site = new Site
                    {
                        Description = "Default area if no site has been defined in the model",
                        Name        = "Default"
                    };
                }
                Exchanger.ReportProgress.IncrementAndUpdate();
                facility.AreaUnits    = helper.ModelAreaUnit ?? AreaUnit.notdefined;
                facility.LinearUnits  = helper.ModelLinearUnit ?? LinearUnit.notdefined;
                facility.VolumeUnits  = helper.ModelVolumeUnit ?? VolumeUnit.notdefined;
                facility.CurrencyUnit = helper.ModelCurrencyUnit ?? CurrencyUnit.notdefined;

                var storeys     = ifcBuilding.BuildingStoreys;
                var cobieFloors = storeys.Cast <IIfcSpatialStructureElement>().ToList();
                if (ifcSite != null)
                {
                    cobieFloors.Add(ifcSite);
                }
                Exchanger.ReportProgress.IncrementAndUpdate();
                if (ifcBuilding != null)
                {
                    cobieFloors.Add(ifcBuilding);
                }
                Exchanger.ReportProgress.IncrementAndUpdate();
                facility.Floors = new List <Floor>(cobieFloors.Count);
                Exchanger.ReportProgress.NextStage(cobieFloors.Count, 50); //finish progress at 50%
                var floorMappings = Exchanger.GetOrCreateMappings <MappingIfcSpatialStructureElementToFloor>();
                for (int i = 0; i < cobieFloors.Count; i++)
                {
                    var floor = new Floor();
                    floor = floorMappings.AddMapping(cobieFloors[i], floor);
                    facility.Floors.Add(floor);
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
            }


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

            helper.AddDocuments(docsMappings, facility, ifcBuilding);
            if (helper.OrphanDocs.Any())
            {
                foreach (var docSel in helper.OrphanDocs)
                {
                    List <Document> docs = docsMappings.MappingMulti(docSel);
                    facility.Documents.AddRange(docs);
                }
            }

            //Zones

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

            if (ifcZones.Any())
            {
                Exchanger.ReportProgress.NextStage(ifcZones.Count(), 65); //finish progress at 65%
                facility.Zones = new List <Zone>(ifcZones.Length);
                var zoneMappings = Exchanger.GetOrCreateMappings <MappingIfcZoneToZone>();
                for (int i = 0; i < ifcZones.Length; i++)
                {
                    var zone = new Zone();
                    zone = zoneMappings.AddMapping(ifcZones[i], zone);
                    facility.Zones.Add(zone);
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
            }

            //Assets
            //  var allIfcElementsinThisFacility = new HashSet<IfcElement>(helper.GetAllAssets(ifcBuilding));

            //AssetTypes
            //Get all assets that are in this facility/building
            //Asset Types are groups of assets that share a common typology
            //Some types are defined explicitly in the ifc file some have to be inferred

            var allIfcTypes = helper.DefiningTypeObjectMap.OrderBy(t => t.Key.Name);

            if (allIfcTypes.Any())
            {
                Exchanger.ReportProgress.NextStage(allIfcTypes.Count(), 90); //finish progress at 90%
                facility.AssetTypes = new List <AssetType>();
                var assetTypeMappings = Exchanger.GetOrCreateMappings <MappingXbimIfcProxyTypeObjectToAssetType>();
                foreach (var elementsByType in allIfcTypes)
                {
                    if (elementsByType.Value.Any())
                    {
                        var assetType = new AssetType();
                        assetType = assetTypeMappings.AddMapping(elementsByType.Key, assetType);
                        facility.AssetTypes.Add(assetType);
                        Exchanger.ReportProgress.IncrementAndUpdate();
                    }
                }
            }

            //Systems

            facility.Systems = new List <Xbim.CobieLiteUk.System>();

            if (helper.SystemMode.HasFlag(SystemExtractionMode.System) && helper.SystemAssignment.Any())
            {
                var systemMappings = Exchanger.GetOrCreateMappings <MappingIfcSystemToSystem>();
                Exchanger.ReportProgress.NextStage(helper.SystemAssignment.Keys.Count(), 95); //finish progress at 95%
                foreach (var ifcSystem in helper.SystemAssignment.Keys)
                {
                    var system = new Xbim.CobieLiteUk.System();
                    system = systemMappings.AddMapping(ifcSystem, system);
                    facility.Systems.Add(system);
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
            }

            //Get systems via propertySets
            if (helper.SystemMode.HasFlag(SystemExtractionMode.PropertyMaps) && helper.SystemViaPropAssignment.Any())
            {
                var systemMappings = Exchanger.GetOrCreateMappings <MappingSystemViaIfcPropertyToSystem>();
                Exchanger.ReportProgress.NextStage(helper.SystemAssignment.Keys.Count(), 96); //finish progress at 95%
                foreach (var ifcPropSet in helper.SystemViaPropAssignment.Keys)
                {
                    var system = new Xbim.CobieLiteUk.System();
                    system = systemMappings.AddMapping(ifcPropSet, system);
                    var init = facility.Systems.Where(sys => sys.Name.Equals(system.Name, netSystem.StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                    if (init != null)
                    {
                        var idx = facility.Systems.IndexOf(init);
                        facility.Systems[idx].Components = facility.Systems[idx].Components.Concat(system.Components).Distinct(new AssetKeyCompare()).ToList();
                    }
                    else
                    {
                        facility.Systems.Add(system);
                    }
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
            }


            //Contacts
            var ifcActorSelects = helper.Contacts;

            if (ifcActorSelects != null && ifcActorSelects.Any())
            {
                Exchanger.ReportProgress.NextStage(ifcActorSelects.Count(), 97); //finish progress at 97%
                var cobieContacts   = new List <Contact>(ifcActorSelects.Count());
                var contactMappings = Exchanger.GetOrCreateMappings <MappingIfcActorToContact>();
                foreach (var actor in ifcActorSelects)
                {
                    var contact = new Contact();
                    contact = contactMappings.AddMapping(actor, contact);
                    cobieContacts.Add(contact);
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
                facility.Contacts = cobieContacts.Distinct(new ContactComparer()).ToList();
            }

            //assign all unallocated spaces to a zone
            var spaces            = facility.Get <Space>().ToList();
            var zones             = facility.Zones ?? new List <Zone>();
            var unAllocatedSpaces = spaces.Where(space => !zones.Any(z => z.Spaces != null && z.Spaces.Select(s => s.Name).Contains(space.Name)));

            Exchanger.ReportProgress.NextStage(unAllocatedSpaces.Count(), 98); //finish progress at 98%
            var defaultZone = helper.CreateXbimDefaultZone();

            foreach (var space in unAllocatedSpaces)
            {
                if (facility.Zones == null)
                {
                    facility.Zones = new List <Zone>();
                }

                defaultZone.Spaces.Add(new SpaceKey {
                    Name = space.Name
                });
                Exchanger.ReportProgress.IncrementAndUpdate();
            }
            if (facility.Zones != null)
            {
                facility.Zones.Add(defaultZone);
            }

            //assign all assets that are not in a system to the default
            if (helper.SystemMode.HasFlag(SystemExtractionMode.Types))
            {
                var assetTypes             = facility.Get <AssetType>().ToList();
                var systemsWritten         = facility.Get <Xbim.CobieLiteUk.System>();
                var assetsAssignedToSystem = new HashSet <string>(systemsWritten.SelectMany(s => s.Components).Select(a => a.Name));
                var systems       = facility.Systems ?? new List <Xbim.CobieLiteUk.System>();
                var defaultSystem = helper.CreateUndefinedSystem();
                Exchanger.ReportProgress.NextStage(assetTypes.Count(), 100); //finish progress at 100%
                //go over all unasigned assets
                foreach (var assetType in assetTypes)
                {
                    Xbim.CobieLiteUk.System assetTypeSystem = null;
                    foreach (var asset in assetType.Assets.Where(a => !assetsAssignedToSystem.Contains(a.Name)))
                    {
                        if (assetTypeSystem == null)
                        {
                            assetTypeSystem      = helper.CreateUndefinedSystem();
                            assetTypeSystem.Name = string.Format("Type System {0} ", assetType.Name);
                        }
                        assetTypeSystem.Components.Add(new AssetKey {
                            Name = asset.Name
                        });
                    }

                    //add to tle list only if it is not null
                    if (assetTypeSystem == null)
                    {
                        continue;
                    }
                    if (facility.Systems == null)
                    {
                        facility.Systems = new List <Xbim.CobieLiteUk.System>();
                    }
                    facility.Systems.Add(assetTypeSystem);
                    Exchanger.ReportProgress.IncrementAndUpdate();
                }
            }


            //write out contacts created in the process
            if (helper.SundryContacts.Any())
            {
                if (facility.Contacts == null)
                {
                    facility.Contacts = new List <Contact>();
                }
                facility.Contacts.AddRange(helper.SundryContacts.Values);
            }

            helper.SundryContacts.Clear();          //clear ready for processing next facility

            Exchanger.ReportProgress.Finalise(500); //finish with 500 millisecond delay

            return(facility);
        }
Example #7
0
        protected override FacilityType Mapping(PlanOfWork source, FacilityType target)
        {
            //convert attributes
            base.Mapping(source, target);

            target.ExternalId     = source.Id.ToString();
            target.ExternalSystem = "DPoW";

            //convert contacts and roles (roles are contacts with ContactCategory == 'Role')
            ConvertContacts(source, target);
            ConvertRoles(source, target);

            //convert fafility related information
            ConvertFacility(source, target);

            //convert project with units
            ConvertProject(source, target);



            //convert DPoW objects and related jobs from the specified stage
            var stage = Exchanger.Context as Xbim.DPoW.ProjectStage ?? source.Project.GetCurrentProjectStage(source);

            if (stage != null)
            {
                //convert all documents
                ConvertDocumentationSet(stage.DocumentationSet, target);

                //convert all asset types
                ConvertAssetTypes(stage.AssetTypes, target);

                //Convert all assembly types
                ConvertAssemblyTypes(stage.AssemblyTypes, stage);

                //convert all spaces into default floor
                ConvertSpaces(stage.SpaceTypes, target);

                //convert free stage attributes
                //add project free attributes to facility
                var stageAttrs = stage.GetCOBieAttributes(target.CreatedOn, target.CreatedBy.Email);
                var attrs      = stageAttrs as Attribute[] ?? stageAttrs.ToArray();
                if (attrs.Any())
                {
                    foreach (var attr in attrs)
                    {
                        attr.ExternalEntity = "ProjectStageAttributes";
                    }
                    if (target.Attributes == null)
                    {
                        target.Attributes = new List <Attribute>();
                    }
                    target.Attributes.AddRange(attrs);
                }

                //convert stage
                var stMapping = Exchanger.GetOrCreateMappings <MappingProjectStageToProjectStage>();
                var tStage    = stMapping.GetOrCreateTargetObject(stage.Id.ToString());
                stMapping.AddMapping(stage, tStage);
                if (target.Stages == null)
                {
                    target.Stages = new List <ProjectStage>();
                }
                target.Stages.Add(tStage);
            }



            //make sure all components live in at least one default system
            foreach (var assetType in target.AssetTypes ?? new List <AssetType>())
            {
                if (assetType.Assets == null)
                {
                    continue;
                }
                foreach (var asset in assetType.Assets)
                {
                    if (target.Systems == null)
                    {
                        target.Systems = new List <Xbim.CobieLiteUk.System>();
                    }
                    var isInSystem = target.Systems.Any(system => system.Components != null && system.Components.Any(k => k.Name == asset.Name));
                    if (isInSystem)
                    {
                        continue;
                    }

                    var defaultSystem = target.Systems.FirstOrDefault(s => s.Name == "Default system");
                    if (defaultSystem == null)
                    {
                        defaultSystem = new Xbim.CobieLiteUk.System {
                            Name = "Default system"
                        };
                        target.Systems.Add(defaultSystem);
                    }
                    if (defaultSystem.Components == null)
                    {
                        defaultSystem.Components = new List <AssetKey>();
                    }
                    defaultSystem.Components.Add(new AssetKey {
                        Name = asset.Name
                    });
                }
            }

            return(target);
        }