/// <summary>
        /// Create and setup IfcSite object
        /// </summary>
        /// <param name="row">COBieFacilityRow object to read data from</param>
        /// <returns>IfcSite object</returns>
        private void CreateSite(COBieFacilityRow row)
        {
            IfcSite ifcSite = Model.Instances.New <IfcSite>();

            //set owner history
            SetNewOwnerHistory(ifcSite, row.ExternalSystem, Model.DefaultOwningUser, row.CreatedOn);
            //using statement will set the Model.OwnerHistoryAddObject to ifcSite.OwnerHistory as OwnerHistoryAddObject is used upon any property changes,
            //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement
            using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcSite.OwnerHistory))
            {
                AddGlobalId(row.ExternalSiteIdentifier, ifcSite);
                if (ValidateString(row.SiteName))
                {
                    ifcSite.Name = row.SiteName;
                }
                ifcSite.CompositionType = IfcElementCompositionEnum.ELEMENT;
                IfcLocalPlacement lp = Model.Instances.New <IfcLocalPlacement>();
                lp.RelativePlacement    = WCS;
                ifcSite.ObjectPlacement = lp;

                if (ValidateString(row.SiteDescription))
                {
                    ifcSite.Description = row.SiteDescription;
                }
            }
        }
        /// <summary>
        /// Set the area measure to the building
        /// </summary>
        /// <param name="ifcBuilding">Building object</param>
        /// <param name="row">COBieFacilityRow object holding data</param>
        private void SetAreaMeasure(IfcBuilding ifcBuilding, COBieFacilityRow row)
        {
            IfcSIUnit ifcSIUnitArea = null;

            if (ValidateString(row.AreaUnits))
            {
                ifcSIUnitArea = GetSIUnit(row.AreaUnits);
            }
            string areaMeasure = string.Empty;

            if (ValidateString(row.AreaMeasurement))
            {
                areaMeasure = row.AreaMeasurement;
            }

            IfcQuantityArea IfcQuantityArea = Model.Instances.New <IfcQuantityArea>(qa =>
            {
                qa.Unit        = ifcSIUnitArea;
                qa.Name        = "AreaMeasure";
                qa.Description = "Created to maintain COBie information";
            });
            IfcElementQuantity ifcElementQuantity = Model.Instances.New <IfcElementQuantity>(eq =>
            {
                eq.Quantities.Add(IfcQuantityArea);
                eq.MethodOfMeasurement = areaMeasure;
                eq.Description         = "Created to maintain COBie information";
            });
            IfcRelDefinesByProperties ifcRelDefinesByProperties = Model.Instances.New <IfcRelDefinesByProperties>(rdbp =>
            {
                rdbp.RelatedObjects.Add(ifcBuilding);
                rdbp.RelatingPropertyDefinition = ifcElementQuantity;
                rdbp.Description = "Created to maintain COBie information";
            });
        }
        /// <summary>
        /// Create and setup the IfcBuilding building object
        /// </summary>
        /// <param name="row">COBieFacilityRow object to read data from</param>
        private void CreateBuilding(COBieFacilityRow row)
        {
            IfcBuilding ifcBuilding = Model.Instances.New <IfcBuilding>();

            SetNewOwnerHistory(ifcBuilding, row.ExternalSystem, Model.DefaultOwningUser, row.CreatedOn);

            //using statement will set the Model.OwnerHistoryAddObject to ifcBuilding.OwnerHistory as OwnerHistoryAddObject is used upon any property changes,
            //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement
            using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcBuilding.OwnerHistory))
            {
                AddGlobalId(row.ExternalFacilityIdentifier, ifcBuilding);
                if (ValidateString(row.Name))
                {
                    ifcBuilding.Name = row.Name;
                }
                //add category
                AddCategory(row.Category, ifcBuilding);

                if (ValidateString(row.Description))
                {
                    ifcBuilding.Description = row.Description;
                }
                if (ValidateString(row.AreaMeasurement))
                {
                    SetAreaMeasure(ifcBuilding, row);
                }

                ifcBuilding.CompositionType = IfcElementCompositionEnum.ELEMENT;
                IfcLocalPlacement lp = Model.Instances.New <IfcLocalPlacement>();
                lp.RelativePlacement        = WCS;
                lp.PlacementRelTo           = GetSite().ObjectPlacement;
                ifcBuilding.ObjectPlacement = lp;
            }
        }
        /// <summary>
        /// SetUp the Model Project Object
        /// </summary>
        /// <param name="row">COBieFacilityRow object to read data from</param>
        private void SetUpProject(COBieFacilityRow row)
        {
            IfcProject ifcProject = Model.IfcProject;

            ifcProject.Initialize(ProjectUnits.SIUnitsUK);
            SetOwnerHistory(ifcProject, row.ExternalSystem, Model.DefaultOwningUser, row.CreatedOn);
            //using statement will set the Model.OwnerHistoryAddObject to ifcProject.OwnerHistory as OwnerHistoryAddObject is used upon any property changes,
            //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement
            using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcProject.OwnerHistory))
            {
                if (ValidateString(row.ProjectName))
                {
                    ifcProject.Name = row.ProjectName;
                }

                if (ValidateString(row.ProjectDescription))
                {
                    ifcProject.Description = row.ProjectDescription;
                }
                if (ValidateString(row.Phase))
                {
                    ifcProject.Phase = row.Phase;
                }
                if (ValidateString(row.LinearUnits))
                {
                    SetUnitToProject(IfcUnitEnum.LENGTHUNIT, row.LinearUnits);
                }

                AddGlobalId(row.ExternalProjectIdentifier, ifcProject);


                if (ValidateString(row.AreaUnits))
                {
                    SetUnitToProject(IfcUnitEnum.AREAUNIT, row.AreaUnits);
                }

                if (ValidateString(row.VolumeUnits))
                {
                    SetUnitToProject(IfcUnitEnum.VOLUMEUNIT, row.VolumeUnits);
                }

                if (ValidateString(row.CurrencyUnit))
                {
                    SetMonetaryUnit(row.CurrencyUnit);
                }
            }
        }
        /// <summary>
        /// Create and setup objects held in the Facility COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieFacilityRows to read data from</param>
        public void SerialiseFacility(COBieSheet <COBieFacilityRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Facility"))
            {
                try
                {
                    ProgressIndicator.ReportMessage("Starting Facility...");
                    ProgressIndicator.Initialise("Creating Facility", 3);

                    //Assume we have only one site and one building to a project
                    COBieFacilityRow row = cOBieSheet[0];
                    ProgressIndicator.IncrementAndUpdate();
                    SetUpProject(row);

                    ProgressIndicator.IncrementAndUpdate();
                    CreateSite(row);

                    ProgressIndicator.IncrementAndUpdate();
                    CreateBuilding(row);

                    //set up relationships
                    GetSite().AddBuilding(GetBuilding());
                    Model.IfcProject.AddSite(GetSite());

                    ProgressIndicator.Finalise();


                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Example #6
0
        /// <summary>
        /// set the default IfcPersonAndOrganization in the Model
        /// </summary>
        public void SetDefaultUser()
        {
            COBieSheet <COBieFacilityRow> facilityRow = (COBieSheet <COBieFacilityRow>)WorkBook[Constants.WORKSHEET_FACILITY];

            if (facilityRow.RowCount > 0)
            {
                COBieFacilityRow row = facilityRow[0]; //use first row supported on facility sheet

                string defaultUser = "";
                if ((!string.IsNullOrEmpty(row.CreatedBy)) || (row.CreatedBy != Constants.DEFAULT_STRING))
                {
                    defaultUser = row.CreatedBy;
                }
                COBieSheet <COBieContactRow> contacts = (COBieSheet <COBieContactRow>)WorkBook[Constants.WORKSHEET_CONTACT];
                for (int i = 0; i < contacts.RowCount; i++)
                {
                    if (contacts[i].Email == defaultUser)
                    {
                        CreatePersonAndOrganization(contacts[i], Model.DefaultOwningUser);
                        break;
                    }
                }
            }
        }