protected override IfcBuilding Mapping(Facility facility, IfcBuilding ifcBuilding)
        {
            #region Properties

            ifcBuilding.Name            = facility.Name;
            ifcBuilding.Description     = facility.Description;
            ifcBuilding.CompositionType = IfcElementCompositionEnum.ELEMENT;
            #endregion

            #region Default units

            Exchanger.DefaultLinearUnit   = new IfcUnitConverter(facility.LinearUnits.ToString());
            Exchanger.DefaultAreaUnit     = new IfcUnitConverter(facility.AreaUnits.ToString());
            Exchanger.DefaultVolumeUnit   = new IfcUnitConverter(facility.VolumeUnits.ToString());
            Exchanger.DefaultCurrencyUnit = facility.CurrencyUnit;

            #endregion

            #region Contacts
            if (facility.Contacts != null && facility.Contacts.Any())
            {
                var ContactMapping = Exchanger.GetOrCreateMappings <MappingContactToIfcPersonAndOrganization>();
                foreach (var contact in facility.Contacts)
                {
                    IfcPersonAndOrganization ifcPersonAndOrganization = ContactMapping.AddMapping(contact, ContactMapping.GetOrCreateTargetObject(contact.ExternalId));
                    //assign relationship
                    //create IfcActor to set CreatedBy and CreatedOn for next time ifc is imported as IfcActor is derived from IfcRoot
                    IfcActor actor = Exchanger.TargetRepository.Instances.New <IfcActor>();
                    Exchanger.SetUserHistory(actor, contact.ExternalSystem, (contact.CreatedBy == null) ? null : contact.CreatedBy.Email, (contact.CreatedOn == null) ? DateTime.Now : (DateTime)contact.CreatedOn);
                    using (OwnerHistoryEditScope context = new OwnerHistoryEditScope(Exchanger.TargetRepository, actor.OwnerHistory))
                    {
                        actor.TheActor = ifcPersonAndOrganization;
                    }
                    //assign the actor to the building
                    IfcRelAssignsToActor ifcRelAssignsToActor = Exchanger.TargetRepository.Instances.New <IfcRelAssignsToActor>();
                    Exchanger.SetUserHistory(ifcRelAssignsToActor, contact.ExternalSystem, (contact.CreatedBy == null) ? null : contact.CreatedBy.Email, (contact.CreatedOn == null) ? DateTime.Now : (DateTime)contact.CreatedOn);
                    using (OwnerHistoryEditScope context = new OwnerHistoryEditScope(Exchanger.TargetRepository, ifcRelAssignsToActor.OwnerHistory))
                    {
                        ifcRelAssignsToActor.RelatingActor = actor;
                        ifcRelAssignsToActor.RelatedObjects.Add(ifcBuilding);
                    }
                }
            }
            #endregion

            #region Categories
            if (facility.Categories != null)
            {
                foreach (var category in facility.Categories)
                {
                    Exchanger.ConvertCategoryToClassification(category, ifcBuilding);
                }
            }

            #endregion


            #region Project



            //COBie does nor require a project but Ifc does
            var ifcProject = Exchanger.TargetRepository.Instances.OfType <IfcProject>().FirstOrDefault();
            if (ifcProject == null)
            {
                ifcProject = Exchanger.TargetRepository.Instances.New <IfcProject>();
            }
            var projectMapping = Exchanger.GetOrCreateMappings <MappingProjectToIfcProject>();
            projectMapping.AddMapping(facility.Project, ifcProject);
            InitialiseUnits(ifcProject);
            #endregion

            #region Site
            //add the relationship between the site and the building if a site exists
            if (facility.Site != null)
            {
                var siteMapping = Exchanger.GetOrCreateMappings <MappingSiteToIfcSite>();
                var ifcSite     = siteMapping.AddMapping(facility.Site,
                                                         siteMapping.GetOrCreateTargetObject(facility.Site.ExternalId ?? Guid.NewGuid().ToString()));
                //add the relationship between the site and the project and the building
                ifcProject.AddSite(ifcSite);
                ifcSite.AddBuilding(ifcBuilding);
            }
            else //relate the building to the project
            {
                ifcProject.AddBuilding(ifcBuilding);
            }
            #endregion

            #region Floors
            //write out the floors if we have any
            if (facility.Floors != null)
            {
                var floorMapping = Exchanger.GetOrCreateMappings <MappingFloorToIfcBuildingStorey>();
                foreach (var floor in facility.Floors)
                {
                    var ifcFloor = floorMapping.AddMapping(floor, floorMapping.GetOrCreateTargetObject(floor.ExternalId));
                    ifcBuilding.AddToSpatialDecomposition(ifcFloor);
                }
            }
            #endregion


            #region AssetTypes
            //write out the floors if we have any
            if (facility.AssetTypes != null)
            {
                var assetTypeMapping = Exchanger.GetOrCreateMappings <MappingAssetTypeToIfcTypeObject>();
                foreach (var assetType in facility.AssetTypes.OrderBy(a => a.ExternalEntity))
                {
                    Exchanger.BeginAssetTypeInfoType();
                    assetTypeMapping.AddMapping(assetType, assetTypeMapping.GetOrCreateTargetObject(assetType.ExternalId));
                    Exchanger.EndAssetTypeInfoType();
                }
            }
            #endregion

            #region Attributes
            if (facility.Attributes != null)
            {
                foreach (var attribute in facility.Attributes)
                {
                    Exchanger.ConvertAttributeTypeToIfcObjectProperty(ifcBuilding, attribute);
                }
            }
            #endregion

            #region Zones

            if (facility.Zones != null)
            {
                var zoneTypeMapping = Exchanger.GetOrCreateMappings <MappingZoneToIfcZone>();
                foreach (var zone in facility.Zones)
                {
                    zoneTypeMapping.AddMapping(zone, zoneTypeMapping.GetOrCreateTargetObject(zone.ExternalId));
                }
            }

            #endregion

            #region Documents
            if (facility.Documents != null && facility.Documents.Any())
            {
                Exchanger.ConvertDocumentsToDocumentSelect(ifcBuilding, facility.Documents);
            }
            #endregion

            #region Add Space Geometry

            CreateSpaceProxies();

            #endregion

            return(ifcBuilding);
        }
Ejemplo n.º 2
0
        protected override IfcBuilding Mapping(FacilityType facility, IfcBuilding ifcBuilding)
        {
            #region Properties

            ifcBuilding.Name            = facility.FacilityName;
            ifcBuilding.Description     = facility.FacilityDescription;
            ifcBuilding.CompositionType = IfcElementCompositionEnum.ELEMENT;
            #endregion

            #region Default units

            Exchanger.DefaultLinearUnit = facility.FacilityDefaultLinearUnitSpecified
                   ? new IfcUnitConverter(facility.FacilityDefaultLinearUnit.ToString())
                   : default(IfcUnitConverter);
            Exchanger.DefaultAreaUnit = facility.FacilityDefaultAreaUnitSpecified
                ? new IfcUnitConverter(facility.FacilityDefaultAreaUnit.ToString())
                : default(IfcUnitConverter);
            Exchanger.DefaultVolumeUnit = facility.FacilityDefaultVolumeUnitSpecified
                   ? new IfcUnitConverter(facility.FacilityDefaultVolumeUnit.ToString())
                   : default(IfcUnitConverter);
            Exchanger.DefaultCurrencyUnit = facility.FacilityDefaultCurrencyUnitSpecified
                ? (CurrencyUnitSimpleType?)facility.FacilityDefaultCurrencyUnit
                : null;

            #endregion

            var ifcProject = Exchanger.TargetRepository.Instances.OfType <IfcProject>().FirstOrDefault();


            //COBie does nor require a project but Ifc does

            if (ifcProject == null)
            {
                ifcProject = Exchanger.TargetRepository.Instances.New <IfcProject>();
            }


            #region Project
            var projectMapping = Exchanger.GetOrCreateMappings <MappingProjectTypeToIfcProject>();
            projectMapping.AddMapping(facility.ProjectAssignment, ifcProject);
            InitialiseUnits(ifcProject);

            #endregion

            #region Site
            //add the relationship between the site and the building if a site exists
            if (facility.SiteAssignment != null)
            {
                var siteMapping = Exchanger.GetOrCreateMappings <MappingSiteTypeToIfcSite>();
                var ifcSite     = siteMapping.AddMapping(facility.SiteAssignment,
                                                         siteMapping.GetOrCreateTargetObject(facility.SiteAssignment.externalID ?? Guid.NewGuid().ToString()));
                //add the relationship between the site and the project and the building
                ifcProject.AddSite(ifcSite);
                ifcSite.AddBuilding(ifcBuilding);
            }
            else     //relate the building to the project
            {
                ifcProject.AddBuilding(ifcBuilding);
            }
            #endregion

            #region Floors
            //write out the floors if we have any
            if (facility.Floors != null)
            {
                var floorMapping = Exchanger.GetOrCreateMappings <MappingFloorTypeToIfcBuildingStorey>();
                foreach (var floor in facility.Floors)
                {
                    var ifcFloor = floorMapping.AddMapping(floor, floorMapping.GetOrCreateTargetObject(floor.externalID));
                    ifcBuilding.AddToSpatialDecomposition(ifcFloor);
                }
            }
            #endregion


            #region AssetTypes
            //write out the floors if we have any
            if (facility.AssetTypes != null)
            {
                var assetTypeMapping = Exchanger.GetOrCreateMappings <MappingAssetTypeInfoTypeToIfcTypeObject>();
                foreach (var assetType in facility.AssetTypes.OrderBy(a => a.externalEntityName))
                {
                    Exchanger.BeginAssetTypeInfoType();
                    assetTypeMapping.AddMapping(assetType, assetTypeMapping.GetOrCreateTargetObject(assetType.externalID));
                    Exchanger.EndAssetTypeInfoType();
                }
            }
            #endregion

            #region Attributes
            if (facility.FacilityAttributes != null)
            {
                foreach (var attribute in facility.FacilityAttributes)
                {
                    Exchanger.ConvertAttributeTypeToIfcObjectProperty(ifcBuilding, attribute);
                }
            }
            #endregion

            #region Add Space Geometry

            CreateSpaceProxies();

            #endregion

            return(ifcBuilding);
        }
        protected override IfcBuilding Mapping(Facility facility, IfcBuilding ifcBuilding)
        {
            #region Properties

            ifcBuilding.Name            = facility.Name;
            ifcBuilding.Description     = facility.Description;
            ifcBuilding.CompositionType = IfcElementCompositionEnum.ELEMENT;
            #endregion

            #region Default units

            Exchanger.DefaultLinearUnit   = new IfcUnitConverter(facility.LinearUnits.ToString());
            Exchanger.DefaultAreaUnit     = new IfcUnitConverter(facility.AreaUnits.ToString());
            Exchanger.DefaultVolumeUnit   = new IfcUnitConverter(facility.VolumeUnits.ToString());
            Exchanger.DefaultCurrencyUnit = facility.CurrencyUnit;

            #endregion

            #region Categories
            if (facility.Categories != null)
            {
                foreach (var category in facility.Categories)
                {
                    Exchanger.ConvertCategoryToClassification(category, ifcBuilding);
                }
            }

            #endregion


            #region Project
            var projectMapping = Exchanger.GetOrCreateMappings <MappingProjectToIfcProject>();
            //COBie does nor require a project but Ifc does
            var ifcProject = Exchanger.TargetRepository.IfcProject;
            projectMapping.AddMapping(facility.Project, ifcProject);
            InitialiseUnits(ifcProject);
            #endregion

            #region Site
            //add the relationship between the site and the building if a site exists
            if (facility.Site != null)
            {
                var siteMapping = Exchanger.GetOrCreateMappings <MappingSiteToIfcSite>();
                var ifcSite     = siteMapping.AddMapping(facility.Site,
                                                         siteMapping.GetOrCreateTargetObject(facility.Site.ExternalId ?? Guid.NewGuid().ToString()));
                //add the relationship between the site and the project and the building
                ifcProject.AddSite(ifcSite);
                ifcSite.AddBuilding(ifcBuilding);
            }
            else //relate the building to the project
            {
                ifcProject.AddBuilding(ifcBuilding);
            }
            #endregion

            #region Floors
            //write out the floors if we have any
            if (facility.Floors != null)
            {
                var floorMapping = Exchanger.GetOrCreateMappings <MappingFloorToIfcBuildingStorey>();
                foreach (var floor in facility.Floors)
                {
                    var ifcFloor = floorMapping.AddMapping(floor, floorMapping.GetOrCreateTargetObject(floor.ExternalId));
                    ifcBuilding.AddToSpatialDecomposition(ifcFloor);
                }
            }
            #endregion


            #region AssetTypes
            //write out the floors if we have any
            if (facility.AssetTypes != null)
            {
                var assetTypeMapping = Exchanger.GetOrCreateMappings <MappingAssetTypeToIfcTypeObject>();
                foreach (var assetType in facility.AssetTypes.OrderBy(a => a.ExternalEntity))
                {
                    Exchanger.BeginAssetTypeInfoType();
                    assetTypeMapping.AddMapping(assetType, assetTypeMapping.GetOrCreateTargetObject(assetType.ExternalId));
                    Exchanger.EndAssetTypeInfoType();
                }
            }
            #endregion

            #region Attributes
            if (facility.Attributes != null)
            {
                foreach (var attribute in facility.Attributes)
                {
                    Exchanger.ConvertAttributeTypeToIfcObjectProperty(ifcBuilding, attribute);
                }
            }
            #endregion

            #region Zones

            if (facility.Zones != null)
            {
                var zoneTypeMapping = Exchanger.GetOrCreateMappings <MappingZoneToIfcZone>();
                foreach (var zone in facility.Zones)
                {
                    zoneTypeMapping.AddMapping(zone, zoneTypeMapping.GetOrCreateTargetObject(zone.ExternalId));
                }
            }

            #endregion


            #region Add Space Geometry

            CreateSpaceProxies();

            #endregion

            return(ifcBuilding);
        }