/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> /// <param name="workbook"></param> /// <param name="validationTemplate"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("COBie", "COBieXLSXSerialiser.Serialise does not accept null as the COBie data parameter."); } if (!File.Exists(TemplateFileName)) { throw new Exception("COBie creation error. Could not locate template file " + TemplateFileName); } // Load template file FileStream excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); ExcelWorkbook = IsXlsx ? new XSSFWorkbook(excelFile) as IWorkbook : new HSSFWorkbook(excelFile, true) as IWorkbook; CreateCellStyles(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, validationTemplate); ReportRules(); using (FileStream exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { ExcelWorkbook.Write(exportFile); } }
/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> /// <param name="cobie"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("COBie", "COBieXLSSerialiser.Serialise does not accept null as the COBie data parameter."); } if (!File.Exists(TemplateFileName)) throw new Exception("COBie creation error. Could not locate template file " + TemplateFileName); // Load template file FileStream excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); XlsWorkbook = new HSSFWorkbook(excelFile, true); CreateFormats(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, ValidationTemplate); ReportRules(); using (FileStream exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { XlsWorkbook.Write(exportFile); } }
/// <summary> /// Constructs a class representing the relationships between a Foreign Key column and its Primary key column elsewhere in the /// workbook /// </summary> /// <param name="workbook">The COBie Workbook holding all the sheets</param> /// <param name="column">The foreign key column</param> public COBieColumnRelationship(COBieWorkbook workbook, COBieColumn column) { if(workbook == null) throw new ArgumentNullException("workbook"); if (column.KeyType != COBieKeyType.ForeignKey && column.KeyType != COBieKeyType.CompoundKey_ForeignKey) throw new ArgumentException(String.Format("Column '{0}' is not a foreign key column", column.ColumnName)); if (string.IsNullOrEmpty(column.ReferenceColumnName)) throw new ArgumentException(errorMessage); string[] sheetRefInfo = column.ReferenceColumnName.Split('.'); if (sheetRefInfo.Length != 2) throw new ArgumentException(errorMessage); SheetName = sheetRefInfo[0]; ColumnName = sheetRefInfo[1]; Sheet = workbook[SheetName]; if(Sheet == null) throw new ArgumentException(String.Format("Sheet '{0}' was not found in the workbook", SheetName)); if (Sheet.Indices.ContainsKey(ColumnName) == false) throw new ArgumentException(String.Format("Column '{0}' was not found in the '{1}' workbook", ColumnName, SheetName)); }
/// <summary> /// Constructor to do all sheets /// </summary> /// <param name="file"></param> public COBieXLSDeserialiser(string file) { SheetNames = new List<string>(); WorkBook = new COBieWorkbook(); FileName = file; GetSheetNames();//get all required sheets from Constants class }
/// <summary> /// Constructor to do all sheets /// </summary> /// <param name="file"></param> public COBieXLSDeserialiser(string file) { SheetNames = new List <string>(); WorkBook = new COBieWorkbook(); FileName = file; GetSheetNames();//get all required sheets from Constants class }
/// <summary> /// Create XLS file from ifc/xbim files /// </summary> /// <param name="parameters">Params</param> private void GenerateFederatedCOBieFile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null) { string outputFile = Path.ChangeExtension(parameters.ModelFile, ".xls"); Stopwatch timer = new Stopwatch(); timer.Start(); COBieWorkbook fedWorkBook = GenerateFederatedCOBieWorkBook(parameters); timer.Stop(); LogBackground(String.Format("Time to generate Federated COBie data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); // Export LogBackground(String.Format("Formatting as {1} using {0} template...", Path.GetFileName(parameters.TemplateFile), parameters.IsXLSX ? "XLSX" : "XLS")); COBieXLSXSerialiser serialiser = new COBieXLSXSerialiser(outputFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.IsXlsx = parameters.IsXLSX; serialiser.Serialise(fedWorkBook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", outputFile)); Process.Start(serialiser.FileName); LogBackground("Finished Federation COBie Generation"); }
/// <summary> /// Create IFC file from XLS file /// </summary> /// <param name="parameters">Params</param> /// <returns>Created file name</returns> private string GenerateIFCFile(Params parameters) { string outputFile; LogBackground(String.Format("Reading {0}....", parameters.ModelFile)); COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile); COBieWorkbook newbook = deSerialiser.Deserialise(); LogBackground("Creating xBim objects..."); Stopwatch timer = new Stopwatch(); timer.Start(); outputFile = Path.GetFileNameWithoutExtension(parameters.ModelFile) + "-COBieToIFC.ifc"; outputFile = Path.GetDirectoryName(parameters.ModelFile) + "\\" + outputFile; using (COBieXBimSerialiser xBimSerialiser = new COBieXBimSerialiser(outputFile, _worker.ReportProgress)) { xBimSerialiser.Serialise(newbook); timer.Stop(); LogBackground(String.Format("Time to generate XBim COBie data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); } LogBackground(String.Format("Finished {0} Generation", outputFile)); return(outputFile); }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> /// <param name="validationTemplate"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { Create(workbook); if (!string.IsNullOrEmpty(FileName)) { Save(); } }
public COBieWorkbook Deserialise() { BinaryFormatter formatter = new BinaryFormatter(); COBieWorkbook workBook = null; using (Stream stream = new FileStream(_file, FileMode.Open, FileAccess.Read, FileShare.None)) { workBook = (COBieWorkbook)formatter.Deserialize(stream); } workBook.CreateIndices(); return(workBook); }
/// <summary> /// Create the COBieBuilder, holds COBieWorkBook /// </summary> /// <param name="parameters">Params</param> /// <returns>COBieBuilder</returns> private COBieWorkbook GenerateFederatedCOBieWorkBook(Params parameters) { var xbimFile = parameters.ModelFile; COBieBuilder builder = null; COBieWorkbook fedWorkBook = null; var workbooks = new List <COBieWorkbook>(); LogBackground(String.Format("Loading federated model {0}...", xbimFile)); using (var model = IfcStore.Open(xbimFile)) { Model = model; //used to check we close file on Close event // Build context on the XBimF model to link roles var context = new COBieContext(_worker.ReportProgress) { TemplateFileName = parameters.TemplateFile, Model = model, Exclude = UserFilters }; foreach (var modelRoles in context.MapMergeRoles) { var refModel = modelRoles.Key; var roles = modelRoles.Value; var refContext = new COBieContext(_worker.ReportProgress) { TemplateFileName = parameters.TemplateFile, Model = (IfcStore)refModel }; refContext.MapMergeRoles[refModel] = roles; refContext.Exclude = UserFilters; // Create COBieReader LogBackground("Generating COBie data..."); builder = new COBieBuilder(refContext); workbooks.Add(builder.Workbook); } } if (workbooks.Count > 1) { var fedCOBie = new FederateCOBie(_worker.ReportProgress); fedWorkBook = fedCOBie.Merge(workbooks); } else if (workbooks.Count == 1) { fedWorkBook = workbooks[0]; } return(fedWorkBook); }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim"); } BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(_file, FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, workbook); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim"); } BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(_file, FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, workbook); } }
/// <summary> /// Create the COBieBuilder, holds COBieWorkBook /// </summary> /// <param name="parameters">Params</param> /// <returns>COBieBuilder</returns> private COBieWorkbook GenerateFederatedCOBieWorkBook(Params parameters) { string xbimFile = parameters.ModelFile; COBieBuilder builder = null; COBieWorkbook fedWorkBook = null; List <COBieWorkbook> workbooks = new List <COBieWorkbook>(); LogBackground(String.Format("Loading federated model {0}...", xbimFile)); using (XbimModel model = new XbimModel()) { model.Open(xbimFile, XbimDBAccess.ReadWrite); Model = model; //used to check we close file on Close event // Build context on the XBimF model to link roles COBieContext context = new COBieContext(_worker.ReportProgress); context.TemplateFileName = parameters.TemplateFile; context.Model = model; context.Exclude = UserFilters; foreach (var ModelRoles in context.MapMergeRoles) { XbimModel refModel = ModelRoles.Key; COBieMergeRoles roles = ModelRoles.Value; COBieContext refContext = new COBieContext(_worker.ReportProgress); refContext.TemplateFileName = parameters.TemplateFile; refContext.Model = refModel; refContext.MapMergeRoles[refModel] = roles; refContext.Exclude = UserFilters; // Create COBieReader LogBackground("Generating COBie data..."); builder = new COBieBuilder(refContext); workbooks.Add(builder.Workbook); } } if (workbooks.Count > 1) { FederateCOBie fedCOBie = new FederateCOBie(_worker.ReportProgress); fedWorkBook = fedCOBie.Merge(workbooks); } else if (workbooks.Count == 1) { fedWorkBook = workbooks[0]; } return(fedWorkBook); }
/// <summary> /// Build Error lists on workbook /// </summary> /// <param name="fedWorkBook"></param> private void PopulateErrors(COBieWorkbook fedWorkBook) { cOBieProgress.Initialise("Validating Workbooks", fedWorkBook.Count, 0); cOBieProgress.ReportMessage("Building Indices..."); fedWorkBook.CreateIndices(); cOBieProgress.ReportMessage("Building Indices...Finished"); // Validate the workbook cOBieProgress.ReportMessage("Starting Validation..."); fedWorkBook.Validate(ErrorRowStartIndex, null, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar cOBieProgress.IncrementAndUpdate(); }); cOBieProgress.ReportMessage("Finished Validation"); cOBieProgress.Finalise(); }
/// <summary> /// Generate a COBieWorkbook from ifc/xbim/xls files /// </summary> /// <param name="parameters">MergeParams</param> /// <returns>COBieWorkbook</returns> private COBieWorkbook GetWorkBook(MergeParams parameters) { string mainFile = parameters.ModelFile; string mainExt = Path.GetExtension(mainFile).ToLower(); COBieWorkbook workBook = null; if (mainExt == ".xls") { COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(mainFile); workBook = deSerialiser.Deserialise(); } else if ((mainExt == ".ifc") || (mainExt == ".xbim")) { COBieBuilder builder = GenerateCOBieWorkBook(parameters); workBook = builder.Workbook; } return(workBook); }
/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "COBieXLSSerialiser.Serialise does not accept null as the COBieWorkbook data parameter."); } if (!File.Exists(TemplateFileName)) { var di = new DirectoryInfo("."); var msg = string.Format( "COBie creation error. Could not locate template file '{0}' from executing folder '{1}'", TemplateFileName, di.FullName); var e = new FileNotFoundException(msg, TemplateFileName); Log.LogError(0, e, "COBie creation error.Could not locate template file '{template}' from executing folder '{folder}'", TemplateFileName, di.FullName); throw e; } // Load template file var excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); XlsWorkbook = new HSSFWorkbook(excelFile, true); CreateFormats(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, validationTemplate); ReportRules(); using (var exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { XlsWorkbook.Write(exportFile); } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { var errorsSheet = XlsWorkbook.GetSheet(ErrorsSheet) ?? XlsWorkbook.CreateSheet(ErrorsSheet); ICOBieSheetValidationTemplate sheetValidator = null; foreach (var sheet in workbook.OrderBy(w => w.SheetName)) { if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (validationTemplate != null && validationTemplate.Sheet.ContainsKey(sheet.SheetName)) { sheetValidator = validationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, sheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim.COBie.Serialisers.COBieJSONSerialiser.Serialise(COBieWorkbook) does not accept null as the workbook parameter"); } FileName += ".json"; using (FileStream stream = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { StreamWriter writer = new StreamWriter(stream); // Serialise Workbook to JSON and write to file stream new Newtonsoft.Json.JsonSerializer().Serialize(writer, workbook); writer.Flush(); writer.Close(); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim.COBie.Serialisers.COBieJSONSerialiser.Serialise(COBieWorkbook) does not accept null as the workbook parameter"); } FileName += ".json"; using (FileStream stream = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { StreamWriter writer = new StreamWriter(stream); // Serialise Workbook to JSON and write to file stream new Newtonsoft.Json.JsonSerializer().Serialize(writer, workbook); writer.Flush(); writer.Close(); } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { ISheet errorsSheet = ExcelWorkbook.GetSheet(ErrorsSheet) ?? ExcelWorkbook.CreateSheet(ErrorsSheet); //if we are validating here then ensure we have Indices on each sheet //workbook.CreateIndices(); ICOBieSheetValidationTemplate SheetValidator = null; foreach (var sheet in workbook.OrderBy(w => w.SheetName)) { if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (ValidationTemplate != null && ValidationTemplate.Sheet.ContainsKey(sheet.SheetName)) { SheetValidator = ValidationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, SheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
/// <summary> /// Merge the workbooks together into a single federated workbook /// </summary> /// <param name="workbooks">List of Workbooks</param> /// <returns>Federated COBie Workbook</returns> public COBieWorkbook Merge(List <COBieWorkbook> workbooks) { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif COBieWorkbook fedWorkbook = new COBieWorkbook(); int index = 0; foreach (COBieWorkbook workbook in workbooks) { index++; foreach (ICOBieSheet <COBieRow> worksheet in workbook) { ICOBieSheet <COBieRow> fedSheet = fedWorkbook[worksheet.SheetName]; if (fedSheet == null) { fedSheet = worksheet.CreateEmptySheet(); //create sheet as it does not exist fedWorkbook.Add(fedSheet); } else if (worksheet.SheetName == Constants.WORKSHEET_PICKLISTS) { continue; //we have already added a pick list so jump on to next sheet } //copy the removed rows to the federated sheet if (worksheet.RemovedRows != null) { foreach (var row in worksheet.RemovedRows) { fedSheet.AddRemovedRow(row); } } cOBieProgress.Initialise(string.Format("Federate workbook {0}, Merging {1}", index, worksheet.SheetName), worksheet.RowCount); bool copy = (worksheet.SheetName == Constants.WORKSHEET_COORDINATE); //copy rows to federated sheet, or add to removed rows if duplicate for (int i = 0; i < worksheet.RowCount; i++) { cOBieProgress.IncrementAndUpdate(); if (copy) //copy the coordinate sheet without any removals { fedSheet.AddRow(worksheet[i]); } else { string hash = worksheet[i].RowMergeHashValue; if (!fedSheet.HasMergeHashCode(hash, true)) { fedSheet.AddRow(worksheet[i]); } else { fedSheet.AddRemovedRow(worksheet[i]); } } } //cOBieProgress.Finalise(); } } fedWorkbook.SetInitialHashCode();//set the initial row hash value to compare against for row changes PopulateErrors(fedWorkbook); #if DEBUG timer.Stop(); Console.WriteLine(String.Format("Time to federate COBie = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); #endif return(fedWorkbook); }
public static void LoadModel(TestContext context) { COBieBinaryDeserialiser deserialiser = new COBieBinaryDeserialiser(BinaryFile); _book = deserialiser.Deserialise(); }
/// <summary> /// Merge the workbooks together into a single federated workbook /// </summary> /// <param name="workbooks">List of Workbooks</param> /// <returns>Federated COBie Workbook</returns> public COBieWorkbook Merge(List<COBieWorkbook> workbooks) { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif COBieWorkbook fedWorkbook = new COBieWorkbook(); int index = 0; foreach (COBieWorkbook workbook in workbooks) { index++; foreach (ICOBieSheet<COBieRow> worksheet in workbook) { ICOBieSheet<COBieRow> fedSheet = fedWorkbook[worksheet.SheetName]; if (fedSheet == null) { fedSheet = CreateSheet(worksheet.SheetName); //create sheet as it does not exist fedWorkbook.Add(fedSheet); } else if (worksheet.SheetName == Constants.WORKSHEET_PICKLISTS) { continue; //we have already added a pick list so jump on to next sheet } //copy the removed rows to the federated sheet if (worksheet.RemovedRows != null) { foreach (var row in worksheet.RemovedRows) { fedSheet.AddRemovedRow(row); } } cOBieProgress.Initialise(string.Format("Federate workbook {0}, Merging {1}", index, worksheet.SheetName), worksheet.RowCount); bool copy = (worksheet.SheetName == Constants.WORKSHEET_COORDINATE); //copy rows to federated sheet, or add to removed rows if duplicate for (int i = 0; i < worksheet.RowCount; i++) { cOBieProgress.IncrementAndUpdate(); if (copy) //copy the coordinate sheet without any removals { fedSheet.AddRow(worksheet[i]); } else { string hash = worksheet[i].RowMergeHashValue; if (!fedSheet.HasMergeHashCode(hash, true)) { fedSheet.AddRow(worksheet[i]); } else { fedSheet.AddRemovedRow(worksheet[i]); } } } //cOBieProgress.Finalise(); } } fedWorkbook.SetInitialHashCode();//set the initial row hash value to compare against for row changes PopulateErrors(fedWorkbook); #if DEBUG timer.Stop(); Console.WriteLine(String.Format("Time to federate COBie = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); #endif return fedWorkbook; }
/// <summary> /// Build Error lists on workbook /// </summary> /// <param name="fedWorkBook"></param> private void PopulateErrors(COBieWorkbook fedWorkBook) { try { cOBieProgress.Initialise("Validating Workbooks", fedWorkBook.Count, 0); cOBieProgress.ReportMessage("Building Indices..."); fedWorkBook.CreateIndices(); cOBieProgress.ReportMessage("Building Indices...Finished"); // Validate the workbook cOBieProgress.ReportMessage("Starting Validation..."); fedWorkBook.Validate(ErrorRowStartIndex, null, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar cOBieProgress.IncrementAndUpdate(); }); cOBieProgress.ReportMessage("Finished Validation"); cOBieProgress.Finalise(); } catch (Exception) { // TODO: Handle throw; } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { ISheet errorsSheet = ExcelWorkbook.GetSheet(ErrorsSheet) ?? ExcelWorkbook.CreateSheet(ErrorsSheet); //if we are validating here then ensure we have Indices on each sheet //workbook.CreateIndices(); ICOBieSheetValidationTemplate SheetValidator = null; foreach(var sheet in workbook.OrderBy(w=>w.SheetName)) { if(sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (ValidationTemplate != null && ValidationTemplate.Sheet.ContainsKey(sheet.SheetName)) { SheetValidator = ValidationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, SheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { Create(workbook); if (!string.IsNullOrEmpty(FileName)) { Save(); } }
/// <summary> /// Validate XLS file for COBie errors, also will swap templates if required /// </summary> /// <param name="parameters">Params</param> /// <returns>Created file name</returns> private void ValidateXLSfile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null) { //read xls file LogBackground(String.Format("Reading {0}....", parameters.ModelFile)); COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile); COBieWorkbook Workbook = deSerialiser.Deserialise(); //extract pick list from the template sheet and swap into workbook (US / UK) LogBackground("Swapping PickList from template..."); COBieSheet <COBiePickListsRow> CobiePickLists = null; if ((!string.IsNullOrEmpty(parameters.TemplateFile)) && File.Exists(parameters.TemplateFile) ) { //extract the pick list sheet from template COBieXLSDeserialiser deSerialiserPickList = new COBieXLSDeserialiser(parameters.TemplateFile, Constants.WORKSHEET_PICKLISTS); COBieWorkbook wbookPickList = deSerialiserPickList.Deserialise(); if (wbookPickList.Count > 0) { CobiePickLists = (COBieSheet <COBiePickListsRow>)wbookPickList.FirstOrDefault(); } //check the workbook last sheet is a pick list if (Workbook.LastOrDefault() is COBieSheet <COBiePickListsRow> ) { //remove original pick list and replace with templates Workbook.RemoveAt(Workbook.Count - 1); Workbook.Add(CobiePickLists); } else { LogBackground("Failed to Swap PickList from template..."); } } COBieContext context = new COBieContext(_worker.ReportProgress); COBieProgress progress = new COBieProgress(context); context.Exclude = UserFilters; //Validate progress.Initialise("Validating Workbooks", Workbook.Count, 0); progress.ReportMessage("Building Indices..."); foreach (ICOBieSheet <COBieRow> item in Workbook) { item.BuildIndices(); } progress.ReportMessage("Building Indices...Finished"); // Validate the workbook progress.ReportMessage("Starting Validation..."); Workbook.Validate(ErrorRowIndexBase.RowTwo, null, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar progress.IncrementAndUpdate(); }); progress.ReportMessage("Finished Validation"); progress.Finalise(); // Export LogBackground(String.Format("Formatting as XLS using {0} template...", Path.GetFileName(parameters.TemplateFile))); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(parameters.ModelFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.Serialise(Workbook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile)); Process.Start(parameters.ModelFile); LogBackground("Finished COBie Validation"); }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Create(COBieWorkbook workbook) { XBimContext.Reset(); //clear out the dictionaries XBimContext.WorkBook = workbook; ModelSetUp(); COBieXBimContact xBimContact = new COBieXBimContact(XBimContext); xBimContact.SerialiseContacts((COBieSheet<COBieContactRow>)WorkBook[Constants.WORKSHEET_CONTACT]); COBieXBimFacility xBimFacility = new COBieXBimFacility(XBimContext); xBimFacility.SerialiseFacility((COBieSheet<COBieFacilityRow>)WorkBook[Constants.WORKSHEET_FACILITY]); COBieXBimFloor xBimFloor = new COBieXBimFloor(XBimContext); xBimFloor.SerialiseFloor((COBieSheet<COBieFloorRow>)WorkBook[Constants.WORKSHEET_FLOOR]); COBieXBimSpace xBimSpace = new COBieXBimSpace(XBimContext); xBimSpace.SerialiseSpace((COBieSheet<COBieSpaceRow>)WorkBook[Constants.WORKSHEET_SPACE]); COBieXBimZone xBimZone = new COBieXBimZone(XBimContext); xBimZone.SerialiseZone((COBieSheet<COBieZoneRow>)WorkBook[Constants.WORKSHEET_ZONE]); COBieXBimType xBimType = new COBieXBimType(XBimContext); xBimType.SerialiseType((COBieSheet<COBieTypeRow>)WorkBook[Constants.WORKSHEET_TYPE]); COBieXBimComponent xBimComponent = new COBieXBimComponent(XBimContext); xBimComponent.SerialiseComponent((COBieSheet<COBieComponentRow>)WorkBook[Constants.WORKSHEET_COMPONENT]); COBieXBimSystem xBimSystem = new COBieXBimSystem(XBimContext); xBimSystem.SerialiseSystem((COBieSheet<COBieSystemRow>)WorkBook[Constants.WORKSHEET_SYSTEM]); COBieXBimAssembly xBimAssembly = new COBieXBimAssembly(XBimContext); xBimAssembly.SerialiseAssembly((COBieSheet<COBieAssemblyRow>)WorkBook[Constants.WORKSHEET_ASSEMBLY]); COBieXBimConnection xBimConnection = new COBieXBimConnection(XBimContext); xBimConnection.SerialiseConnection((COBieSheet<COBieConnectionRow>)WorkBook[Constants.WORKSHEET_CONNECTION]); COBieXBimSpare xBimSpare = new COBieXBimSpare(XBimContext); xBimSpare.SerialiseSpare((COBieSheet<COBieSpareRow>)WorkBook[Constants.WORKSHEET_SPARE]); COBieXBimResource xBimResource = new COBieXBimResource(XBimContext); xBimResource.SerialiseResource((COBieSheet<COBieResourceRow>)WorkBook[Constants.WORKSHEET_RESOURCE]); COBieXBimJob xBimJob = new COBieXBimJob(XBimContext); xBimJob.SerialiseJob((COBieSheet<COBieJobRow>)WorkBook[Constants.WORKSHEET_JOB]); COBieXBimImpact xBimImpact = new COBieXBimImpact(XBimContext); xBimImpact.SerialiseImpact((COBieSheet<COBieImpactRow>)WorkBook[Constants.WORKSHEET_IMPACT]); COBieXBimDocument xBimDocument = new COBieXBimDocument(XBimContext); xBimDocument.SerialiseDocument((COBieSheet<COBieDocumentRow>)WorkBook[Constants.WORKSHEET_DOCUMENT]); COBieXBimAttribute xBimAttribute = new COBieXBimAttribute(XBimContext); xBimAttribute.SerialiseAttribute((COBieSheet<COBieAttributeRow>)WorkBook[Constants.WORKSHEET_ATTRIBUTE]); COBieXBimCoordinate xBimCoordinate = new COBieXBimCoordinate(XBimContext); xBimCoordinate.SerialiseCoordinate((COBieSheet<COBieCoordinateRow>)WorkBook[Constants.WORKSHEET_COORDINATE]); COBieXBimIssue xBimIssue = new COBieXBimIssue(XBimContext); xBimIssue.SerialiseIssue((COBieSheet<COBieIssueRow>)WorkBook[Constants.WORKSHEET_ISSUE]); }
/// <summary> /// XBim Merge /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Merge(COBieWorkbook workbook) { XBimContext.IsMerge = true; //flag as a merge XBimContext.WorkBook = workbook; if (!MergeGeometryOnly) { var xBimContact = new COBieXBimContact(XBimContext); xBimContact.SerialiseContacts((COBieSheet <COBieContactRow>)WorkBook[Constants.WORKSHEET_CONTACT]); } //Make the assumption we are merging on the same building //COBieXBimFacility xBimFacility = new COBieXBimFacility(XBimContext); //xBimFacility.SerialiseFacility((COBieSheet<COBieFacilityRow>)WorkBook[Constants.WORKSHEET_FACILITY]); var xBimFloor = new COBieXBimFloor(XBimContext); xBimFloor.SerialiseFloor((COBieSheet <COBieFloorRow>)WorkBook[Constants.WORKSHEET_FLOOR]); var xBimSpace = new COBieXBimSpace(XBimContext); xBimSpace.SerialiseSpace((COBieSheet <COBieSpaceRow>)WorkBook[Constants.WORKSHEET_SPACE]); if (!MergeGeometryOnly) { var xBimZone = new COBieXBimZone(XBimContext); xBimZone.SerialiseZone((COBieSheet <COBieZoneRow>)WorkBook[Constants.WORKSHEET_ZONE]); } var xBimType = new COBieXBimType(XBimContext); xBimType.SerialiseType((COBieSheet <COBieTypeRow>)WorkBook[Constants.WORKSHEET_TYPE]); var xBimComponent = new COBieXBimComponent(XBimContext); xBimComponent.SerialiseComponent((COBieSheet <COBieComponentRow>)WorkBook[Constants.WORKSHEET_COMPONENT]); if (!MergeGeometryOnly) { var xBimSystem = new COBieXBimSystem(XBimContext); xBimSystem.SerialiseSystem((COBieSheet <COBieSystemRow>)WorkBook[Constants.WORKSHEET_SYSTEM]); var xBimAssembly = new COBieXBimAssembly(XBimContext); xBimAssembly.SerialiseAssembly((COBieSheet <COBieAssemblyRow>)WorkBook[Constants.WORKSHEET_ASSEMBLY]); var xBimConnection = new COBieXBimConnection(XBimContext); xBimConnection.SerialiseConnection((COBieSheet <COBieConnectionRow>)WorkBook[Constants.WORKSHEET_CONNECTION]); var xBimSpare = new COBieXBimSpare(XBimContext); xBimSpare.SerialiseSpare((COBieSheet <COBieSpareRow>)WorkBook[Constants.WORKSHEET_SPARE]); var xBimResource = new COBieXBimResource(XBimContext); xBimResource.SerialiseResource((COBieSheet <COBieResourceRow>)WorkBook[Constants.WORKSHEET_RESOURCE]); var xBimJob = new COBieXBimJob(XBimContext); xBimJob.SerialiseJob((COBieSheet <COBieJobRow>)WorkBook[Constants.WORKSHEET_JOB]); var xBimImpact = new COBieXBimImpact(XBimContext); xBimImpact.SerialiseImpact((COBieSheet <COBieImpactRow>)WorkBook[Constants.WORKSHEET_IMPACT]); var xBimDocument = new COBieXBimDocument(XBimContext); xBimDocument.SerialiseDocument((COBieSheet <COBieDocumentRow>)WorkBook[Constants.WORKSHEET_DOCUMENT]); var xBimAttribute = new COBieXBimAttribute(XBimContext); xBimAttribute.SerialiseAttribute((COBieSheet <COBieAttributeRow>)WorkBook[Constants.WORKSHEET_ATTRIBUTE]); } var xBimCoordinate = new COBieXBimCoordinate(XBimContext); xBimCoordinate.SerialiseCoordinate((COBieSheet <COBieCoordinateRow>)WorkBook[Constants.WORKSHEET_COORDINATE]); if (!MergeGeometryOnly) { var xBimIssue = new COBieXBimIssue(XBimContext); xBimIssue.SerialiseIssue((COBieSheet <COBieIssueRow>)WorkBook[Constants.WORKSHEET_ISSUE]); } }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Create(COBieWorkbook workbook) { XBimContext.Reset(); //clear out the dictionaries XBimContext.WorkBook = workbook; ModelSetUp(); var xBimContact = new COBieXBimContact(XBimContext); xBimContact.SerialiseContacts((COBieSheet <COBieContactRow>)WorkBook[Constants.WORKSHEET_CONTACT]); var xBimFacility = new COBieXBimFacility(XBimContext); xBimFacility.SerialiseFacility((COBieSheet <COBieFacilityRow>)WorkBook[Constants.WORKSHEET_FACILITY]); var xBimFloor = new COBieXBimFloor(XBimContext); xBimFloor.SerialiseFloor((COBieSheet <COBieFloorRow>)WorkBook[Constants.WORKSHEET_FLOOR]); var xBimSpace = new COBieXBimSpace(XBimContext); xBimSpace.SerialiseSpace((COBieSheet <COBieSpaceRow>)WorkBook[Constants.WORKSHEET_SPACE]); var xBimZone = new COBieXBimZone(XBimContext); xBimZone.SerialiseZone((COBieSheet <COBieZoneRow>)WorkBook[Constants.WORKSHEET_ZONE]); var xBimType = new COBieXBimType(XBimContext); xBimType.SerialiseType((COBieSheet <COBieTypeRow>)WorkBook[Constants.WORKSHEET_TYPE]); var xBimComponent = new COBieXBimComponent(XBimContext); xBimComponent.SerialiseComponent((COBieSheet <COBieComponentRow>)WorkBook[Constants.WORKSHEET_COMPONENT]); var xBimSystem = new COBieXBimSystem(XBimContext); xBimSystem.SerialiseSystem((COBieSheet <COBieSystemRow>)WorkBook[Constants.WORKSHEET_SYSTEM]); var xBimAssembly = new COBieXBimAssembly(XBimContext); xBimAssembly.SerialiseAssembly((COBieSheet <COBieAssemblyRow>)WorkBook[Constants.WORKSHEET_ASSEMBLY]); var xBimConnection = new COBieXBimConnection(XBimContext); xBimConnection.SerialiseConnection((COBieSheet <COBieConnectionRow>)WorkBook[Constants.WORKSHEET_CONNECTION]); var xBimSpare = new COBieXBimSpare(XBimContext); xBimSpare.SerialiseSpare((COBieSheet <COBieSpareRow>)WorkBook[Constants.WORKSHEET_SPARE]); var xBimResource = new COBieXBimResource(XBimContext); xBimResource.SerialiseResource((COBieSheet <COBieResourceRow>)WorkBook[Constants.WORKSHEET_RESOURCE]); var xBimJob = new COBieXBimJob(XBimContext); xBimJob.SerialiseJob((COBieSheet <COBieJobRow>)WorkBook[Constants.WORKSHEET_JOB]); var xBimImpact = new COBieXBimImpact(XBimContext); xBimImpact.SerialiseImpact((COBieSheet <COBieImpactRow>)WorkBook[Constants.WORKSHEET_IMPACT]); var xBimDocument = new COBieXBimDocument(XBimContext); xBimDocument.SerialiseDocument((COBieSheet <COBieDocumentRow>)WorkBook[Constants.WORKSHEET_DOCUMENT]); var xBimAttribute = new COBieXBimAttribute(XBimContext); xBimAttribute.SerialiseAttribute((COBieSheet <COBieAttributeRow>)WorkBook[Constants.WORKSHEET_ATTRIBUTE]); var xBimCoordinate = new COBieXBimCoordinate(XBimContext); xBimCoordinate.SerialiseCoordinate((COBieSheet <COBieCoordinateRow>)WorkBook[Constants.WORKSHEET_COORDINATE]); var xBimIssue = new COBieXBimIssue(XBimContext); xBimIssue.SerialiseIssue((COBieSheet <COBieIssueRow>)WorkBook[Constants.WORKSHEET_ISSUE]); }
private void ResetWorksheets() { Workbook = new COBieWorkbook(); }
/// <summary> /// Merge COBie data files /// </summary> /// <param name="parameters">MergeParams</param> /// <returns>Created file name</returns> private string MergeCOBieFiles(MergeParams parameters) { List <string> mergeList = new List <string>(); mergeList.AddRange(parameters.MergeItemsList); string outputFile = string.Empty; if (mergeList.Count > 0) { Stopwatch timer = new Stopwatch(); timer.Start(); string mainFile = mergeList.First(); mergeList.RemoveAt(0); if (!File.Exists(mainFile)) { LogBackground(String.Format("File {0} doesn't exist. cannot merge as main file not found", mainFile)); return(string.Empty); } outputFile = Path.GetFileNameWithoutExtension(mainFile) + "-COBieMergeToIFC.ifc"; outputFile = Path.GetDirectoryName(mainFile) + "\\" + outputFile; parameters.ModelFile = mainFile; using (COBieXBimSerialiser xBimSerialiser = new COBieXBimSerialiser(outputFile, _worker.ReportProgress)) { LogBackground(String.Format("Reading main file {0}....", Path.GetFileName(mainFile))); COBieWorkbook mainWorkBook = GetWorkBook(parameters); LogBackground(String.Format("Writing main file {0} to {1}....", Path.GetFileName(mainFile), Path.GetFileName(outputFile))); xBimSerialiser.Create(mainWorkBook); xBimSerialiser.MergeGeometryOnly = GeoOnlyChkBox.Checked; foreach (string mergeFile in mergeList) { if (File.Exists(mergeFile)) { string mergExt = Path.GetExtension(mergeFile).ToLower(); LogBackground(String.Format("Reading file to merge {0}....", Path.GetFileName(mergeFile))); parameters.ModelFile = mergeFile; COBieWorkbook mergeWorkBook = GetWorkBook(parameters); LogBackground(String.Format("Writing merge file {0} into {1}....", Path.GetFileName(mergeFile), Path.GetFileName(outputFile))); xBimSerialiser.Merge(mergeWorkBook); } else { LogBackground(String.Format("File {0} doesn't exist. skipping merge on this file", mergeFile)); } } timer.Stop(); LogBackground(String.Format("Time to generate XBim COBie data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); LogBackground(String.Format("Creating file {0}....", Path.GetFileName(outputFile))); xBimSerialiser.Save(); } LogBackground(String.Format("Finished Generating {0}", outputFile)); } return(outputFile); }
/// <summary> /// XBim Merge /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Merge(COBieWorkbook workbook) { XBimContext.IsMerge = true; //flag as a merge XBimContext.WorkBook = workbook; if (!MergeGeometryOnly) { COBieXBimContact xBimContact = new COBieXBimContact(XBimContext); xBimContact.SerialiseContacts((COBieSheet<COBieContactRow>)WorkBook[Constants.WORKSHEET_CONTACT]); } //Make the assumption we are merging on the same building //COBieXBimFacility xBimFacility = new COBieXBimFacility(XBimContext); //xBimFacility.SerialiseFacility((COBieSheet<COBieFacilityRow>)WorkBook[Constants.WORKSHEET_FACILITY]); COBieXBimFloor xBimFloor = new COBieXBimFloor(XBimContext); xBimFloor.SerialiseFloor((COBieSheet<COBieFloorRow>)WorkBook[Constants.WORKSHEET_FLOOR]); COBieXBimSpace xBimSpace = new COBieXBimSpace(XBimContext); xBimSpace.SerialiseSpace((COBieSheet<COBieSpaceRow>)WorkBook[Constants.WORKSHEET_SPACE]); if (!MergeGeometryOnly) { COBieXBimZone xBimZone = new COBieXBimZone(XBimContext); xBimZone.SerialiseZone((COBieSheet<COBieZoneRow>)WorkBook[Constants.WORKSHEET_ZONE]); } COBieXBimType xBimType = new COBieXBimType(XBimContext); xBimType.SerialiseType((COBieSheet<COBieTypeRow>)WorkBook[Constants.WORKSHEET_TYPE]); COBieXBimComponent xBimComponent = new COBieXBimComponent(XBimContext); xBimComponent.SerialiseComponent((COBieSheet<COBieComponentRow>)WorkBook[Constants.WORKSHEET_COMPONENT]); if (!MergeGeometryOnly) { COBieXBimSystem xBimSystem = new COBieXBimSystem(XBimContext); xBimSystem.SerialiseSystem((COBieSheet<COBieSystemRow>)WorkBook[Constants.WORKSHEET_SYSTEM]); COBieXBimAssembly xBimAssembly = new COBieXBimAssembly(XBimContext); xBimAssembly.SerialiseAssembly((COBieSheet<COBieAssemblyRow>)WorkBook[Constants.WORKSHEET_ASSEMBLY]); COBieXBimConnection xBimConnection = new COBieXBimConnection(XBimContext); xBimConnection.SerialiseConnection((COBieSheet<COBieConnectionRow>)WorkBook[Constants.WORKSHEET_CONNECTION]); COBieXBimSpare xBimSpare = new COBieXBimSpare(XBimContext); xBimSpare.SerialiseSpare((COBieSheet<COBieSpareRow>)WorkBook[Constants.WORKSHEET_SPARE]); COBieXBimResource xBimResource = new COBieXBimResource(XBimContext); xBimResource.SerialiseResource((COBieSheet<COBieResourceRow>)WorkBook[Constants.WORKSHEET_RESOURCE]); COBieXBimJob xBimJob = new COBieXBimJob(XBimContext); xBimJob.SerialiseJob((COBieSheet<COBieJobRow>)WorkBook[Constants.WORKSHEET_JOB]); COBieXBimImpact xBimImpact = new COBieXBimImpact(XBimContext); xBimImpact.SerialiseImpact((COBieSheet<COBieImpactRow>)WorkBook[Constants.WORKSHEET_IMPACT]); COBieXBimDocument xBimDocument = new COBieXBimDocument(XBimContext); xBimDocument.SerialiseDocument((COBieSheet<COBieDocumentRow>)WorkBook[Constants.WORKSHEET_DOCUMENT]); COBieXBimAttribute xBimAttribute = new COBieXBimAttribute(XBimContext); xBimAttribute.SerialiseAttribute((COBieSheet<COBieAttributeRow>)WorkBook[Constants.WORKSHEET_ATTRIBUTE]); } COBieXBimCoordinate xBimCoordinate = new COBieXBimCoordinate(XBimContext); xBimCoordinate.SerialiseCoordinate((COBieSheet<COBieCoordinateRow>)WorkBook[Constants.WORKSHEET_COORDINATE]); if (!MergeGeometryOnly) { COBieXBimIssue xBimIssue = new COBieXBimIssue(XBimContext); xBimIssue.SerialiseIssue((COBieSheet<COBieIssueRow>)WorkBook[Constants.WORKSHEET_ISSUE]); } }