/// <summary> /// Create and setup objects held in the Component COBieSheet /// </summary> /// <param name="cOBieSheet">COBieSheet of COBieComponentRow to read data from</param> public void SerialiseComponent(COBieSheet <COBieComponentRow> cOBieSheet) { using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Component")) { try { int count = 1; IfcTypeObjects = Model.Instances.OfType <IfcTypeObject>(); IfcSpaces = Model.Instances.OfType <IfcSpace>(); IfcBuildingStoreys = Model.Instances.OfType <IfcBuildingStorey>(); ProgressIndicator.ReportMessage("Starting Components..."); ProgressIndicator.Initialise("Creating Components", cOBieSheet.RowCount); for (int i = 0; i < cOBieSheet.RowCount; i++) { BumpTransaction(trans, count); count++; ProgressIndicator.IncrementAndUpdate(); COBieComponentRow row = cOBieSheet[i]; AddComponent(row); } ProgressIndicator.Finalise(); trans.Commit(); } catch (Exception) { //TODO: Catch with logger? throw; } } }
/// <summary> /// Add the components and fill with data from COBieComponentRow /// </summary> /// <param name="row">COBieComponentRow holding the data</param> private void AddComponent(COBieComponentRow row) { //we are merging so check for an existing item name, assume the same item as should be the same building if (CheckIfExistOnMerge <IfcElement>(row.Name)) { return;//we have it so no need to create } //we need the ExtObject to exist to create the object //Create object using reflection var ifcElement = GetElementInstance(row.ExtObject, Model); if (ifcElement != null) { //Add Created By, Created On and ExtSystem to Owner History. SetUserHistory(ifcElement, row.ExtSystem, row.CreatedBy, row.CreatedOn); //using statement will set the Model.OwnerHistoryAddObject to ifcElement.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 (var context = new COBieXBimEditScope(Model, ifcElement.OwnerHistory)) { //Add Name var name = row.Name; if (ValidateString(name)) { ifcElement.Name = name; } //Add description if (ValidateString(row.Description)) { ifcElement.Description = row.Description; } //Add GlobalId AddGlobalId(row.ExtIdentifier, ifcElement); //Add Property Set Properties if (ValidateString(row.SerialNumber)) { AddPropertySingleValue(ifcElement, "Pset_Component", "Component Properties From COBie", "SerialNumber", "Serial Number for " + name, new IfcLabel(row.SerialNumber)); } if (ValidateString(row.InstallationDate)) { AddPropertySingleValue(ifcElement, "Pset_Component", null, "InstallationDate", "Installation Date for " + name, new IfcLabel(row.InstallationDate)); } if (ValidateString(row.WarrantyStartDate)) { AddPropertySingleValue(ifcElement, "Pset_Component", null, "WarrantyStartDate", "Warranty Start Date for " + name, new IfcLabel(row.WarrantyStartDate)); } if (ValidateString(row.TagNumber)) { AddPropertySingleValue(ifcElement, "Pset_Component", null, "TagNumber", "Tag Number for " + name, new IfcLabel(row.TagNumber)); } if (ValidateString(row.BarCode)) { AddPropertySingleValue(ifcElement, "Pset_Component", null, "BarCode", "Bar Code for " + name, new IfcLabel(row.BarCode)); } if (ValidateString(row.AssetIdentifier)) { AddPropertySingleValue(ifcElement, "Pset_Component", null, "AssetIdentifier", "Asset Identifier for " + name, new IfcLabel(row.AssetIdentifier)); } //set up relationship of the component to the type the component is if (ValidateString(row.TypeName)) { var ifcTypeObject = IfcTypeObjects.Where(to => to.Name.ToString().ToLower() == row.TypeName.ToLower()).FirstOrDefault(); if (ifcTypeObject != null) { ifcElement.AddDefiningType(ifcTypeObject); } else { ifcElement.ObjectType = row.TypeName; //no type so save type name in IfcLable property of IfcObject } } //set up relationship of the component to the space if (ValidateString(row.Space)) { AddElementRelationship(ifcElement, row.Space); } else { GetBuilding().AddElement(ifcElement); //default to building, probably give incorrect bounding box as we do not know what the element parent was } } } else { #if DEBUG Console.WriteLine("Failed to create component {0} of {1}", row.Name, row.ExtObject); #endif } }