/// <summary> /// Create and setup objects held in the Connection COBieSheet /// </summary> /// <param name="cOBieSheet">COBieSheet of COBieConnectionRow to read data from</param> public void SerialiseConnection(COBieSheet <COBieConnectionRow> cOBieSheet) { using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Connection")) { try { int count = 1; IfcElements = Model.Instances.OfType <IfcElement>(); ProgressIndicator.ReportMessage("Starting Connections..."); ProgressIndicator.Initialise("Creating Connections", cOBieSheet.RowCount); for (int i = 0; i < cOBieSheet.RowCount; i++) { BumpTransaction(trans, count); count++; ProgressIndicator.IncrementAndUpdate(); COBieConnectionRow row = cOBieSheet[i]; AddConnection(row); } ProgressIndicator.Finalise(); trans.Commit(); } catch (Exception) { //TODO: Catch with logger? throw; } } }
/// <summary> /// Add the data to the IfcRelConnectsElements object /// </summary> /// <param name="row">COBieConnectionRow holding the data</param> private void AddConnection(COBieConnectionRow row) { IfcElement relatingElement = null; IfcElement relatedElement = null; IfcRelConnectsElements ifcRelConnectsElements = null; if (ValidateString(row.RowName1)) { relatingElement = GetElement(row.RowName1); } if (ValidateString(row.RowName2)) { relatedElement = GetElement(row.RowName2); } //check on merge that we have not already created the IfcRelConnectsElements object ifcRelConnectsElements = CheckIfObjExistOnMerge <IfcRelConnectsElements>(row.Name).Where(rce => (rce.RelatingElement == relatingElement) && (rce.RelatedElement == relatedElement)).FirstOrDefault(); if (ifcRelConnectsElements != null) { return; //we have this object so return, make assumption that ports will also have exist! } if (ifcRelConnectsElements == null) { ifcRelConnectsElements = Model.Instances.New <IfcRelConnectsElements>(); } //Add Created By, Created On and ExtSystem to Owner History. SetUserHistory(ifcRelConnectsElements, row.ExtSystem, row.CreatedBy, row.CreatedOn); //using statement will set the Model.OwnerHistoryAddObject to ifcRelConnectsElements.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, ifcRelConnectsElements.OwnerHistory)) { if (ValidateString(row.Name)) { ifcRelConnectsElements.Name = row.Name; } if (ValidateString(row.ConnectionType)) { ifcRelConnectsElements.Description = row.ConnectionType; } if (relatingElement != null) { ifcRelConnectsElements.RelatingElement = relatingElement; } if (relatedElement != null) { ifcRelConnectsElements.RelatedElement = relatedElement; } //Add Ports AddRelConnectsPorts(row.RealizingElement, row.PortName1, row.PortName2, relatingElement, relatedElement); //Add GlobalId AddGlobalId(row.ExtIdentifier, ifcRelConnectsElements); if (!ValidateString(ifcRelConnectsElements.Description)) { ifcRelConnectsElements.Description = row.Description; } } }