/// <summary> /// Create the COBieBuilder, holds COBieWorkBook /// </summary> /// <param name="parameters">Params</param> /// <returns>COBieBuilder</returns> private COBieBuilder GenerateCOBieWorkBook(Params parameters) { COBieBuilder builder = null; LogBackground(String.Format("Loading model {0}...", Path.GetFileName(parameters.ModelFile))); using (var model = IfcStore.Open(parameters.ModelFile)) { // Build context var context = new COBieContext(_worker.ReportProgress); context.TemplateFileName = parameters.TemplateFile; context.Model = model; context.MapMergeRoles[model] = Roles; context.Exclude = UserFilters; Model = model; //used to check we close file on Close event //Create Scene, required for Coordinates sheet if (!SkipGeoChkBox.Checked) { GenerateGeometry(context); } // Create COBieReader LogBackground("Generating COBie data..."); builder = new COBieBuilder(context); } return(builder); }
public COBieDataAttributeBuilder(COBieContext context, COBieDataPropertySetValues propertSetValues) { Context = context; PropertSetValues = propertSetValues; //set up lists SetListsUp(); }
//Needed Geometry to test, but Steve's comment on "need to resolve generate geometry" may see GenerateGeometry change private void GenerateGeometry(COBieContext context) { //now convert the geometry XbimModel model = context.Model; int total = (int)model.Instances.CountOf <IfcProduct>(); ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { context.UpdateStatus("Creating Geometry File", total, (total * percentProgress / 100)); }; XbimMesher.GenerateGeometry(model, null, progDelegate); }
/// <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); }
/// <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> /// Create the COBieBuilder, holds COBieWorkBook /// </summary> /// <param name="parameters">Params</param> /// <returns>COBieBuilder</returns> private COBieBuilder GenerateCOBieWorkBook(Params parameters) { string xbimFile = string.Empty; string fileExt = Path.GetExtension(parameters.ModelFile); COBieBuilder builder = null; LogBackground(String.Format("Loading model {0}...", Path.GetFileName(parameters.ModelFile))); using (XbimModel model = new XbimModel()) { if ((fileExt.Equals(".xbim", StringComparison.OrdinalIgnoreCase)) || (fileExt.Equals(".xbimf", StringComparison.OrdinalIgnoreCase)) ) { xbimFile = parameters.ModelFile; model.Open(xbimFile, XbimDBAccess.ReadWrite); //model.CacheStart(); } else //ifc file { xbimFile = Path.ChangeExtension(parameters.ModelFile, "xBIM"); model.CreateFrom(parameters.ModelFile, xbimFile, _worker.ReportProgress, true, false); } //model.Open(xbimFile, XbimDBAccess.ReadWrite); // Build context COBieContext context = new COBieContext(_worker.ReportProgress); context.TemplateFileName = parameters.TemplateFile; context.Model = model; context.MapMergeRoles[model] = Roles; context.Exclude = UserFilters; Model = model; //used to check we close file on Close event //Create Scene, required for Coordinates sheet if (!SkipGeoChkBox.Checked) { GenerateGeometry(context); } // Create COBieReader LogBackground("Generating COBie data..."); builder = new COBieBuilder(context); } return(builder); }
//Needed Geometry to test, but Steve's comment on "need to resolve generate geometry" may see GenerateGeometry change private void GenerateGeometry(COBieContext context) { //now convert the geometry var model = context.Model; var total = (int)model.Instances.CountOf <IfcProduct>(); ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { context.UpdateStatus("Creating Geometry File", total, (total * percentProgress / 100)); }; var m3D = new Xbim3DModelContext(model); try { m3D.CreateContext(progDelegate: progDelegate); } catch (Exception ce) { context.UpdateStatus("Error compiling geometry\n" + ce.Message, total, 100); } }
/// <summary> /// Data Contact constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataContact(COBieContext context) : base(context) { }
/// <summary> /// Data Coordinate constructor /// </summary> /// <param name="context"></param> public COBieDataCoordinate(COBieContext context) : base(context) { }
/// <summary> /// Performs the export /// </summary> /// <returns>True on success, false on error.</returns> private bool ExportCoBie() { if (!Directory.Exists(TxtFolderName.Text)) { try { Directory.CreateDirectory(TxtFolderName.Text); } catch (Exception) { MessageBox.Show("Error creating directory. Select a different location."); return(false); } } var f = new FileInfo(Path.ChangeExtension(Model.FileName, ".xls")); var outputFile = Path.Combine(TxtFolderName.Text, f.Name); var context = new COBieContext { TemplateFileName = CoBieTemplate, Model = Model, Exclude = UserFilters }; // setting culture for thread; the current one will be restored later. CultureInfo exisitingCultureInfo = null; try { var ci = new CultureInfo("en-GB"); exisitingCultureInfo = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception ex) { Log.Error("CurrentUICulture could not be set to en-GB.", ex); } // actual export code var builder = new COBieBuilder(context); var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) { Excludes = UserFilters }; builder.Export(serialiser); // restoring culture for thread; try { if (exisitingCultureInfo != null) { Thread.CurrentThread.CurrentUICulture = exisitingCultureInfo; } } catch (Exception ex) { Log.Error("CurrentUICulture could not restored.", ex); } if (ChkOpenExcel.IsChecked.HasValue && ChkOpenExcel.IsChecked.Value) { Process.Start(outputFile); } return(true); }
/// <summary> /// Data Connection constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataConnection(COBieContext context) : base(context) { }
/// <summary> /// Data System constructor /// </summary> /// <param name="context">The context of the model being generated</param> public COBieDataSystem(COBieContext context) : base(context) { }
/// <summary> /// Data Type constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataType(COBieContext context) : base(context) { RowHashs = new Dictionary <string, bool>(); }
/// <summary> /// Data Zone constructor /// </summary> /// <param name="context">The context of the model being generated</param> public COBieDataZone(COBieContext context) : base(context) { }
/// <summary> /// Get the space name holding the element /// </summary> /// <param name="el">IfcElement to get containing space for</param> /// <param name="Model"></param> /// <param name="SpaceBoundingBoxInfo"></param> /// <param name="ifcSpaces"></param> /// <param name="Context"></param> /// <returns>Space name</returns> internal static string GetSpaceHoldingElement(IfcElement el, IfcStore Model, IEnumerable <SpaceInfo> SpaceBoundingBoxInfo, IEnumerable <IfcSpace> ifcSpaces, COBieContext Context) { string spaceName = string.Empty; int ifcSpacesId = Model.Metadata.ExpressTypeId(typeof(IfcSpace)); using (var geomStore = Model.GeometryStore) { using (var geomReader = geomStore.BeginRead()) { // see if we have space information, if not fill information list // if SpaceBoundingBoxInfo is not populated then prepare it if (!SpaceBoundingBoxInfo.Any()) { EnsureSpaceList(ifcSpaces, Model); SpaceBoundingBoxInfo = geomReader.ShapeInstances.Where(x => x.IfcTypeId == ifcSpacesId).Select(bb => new SpaceInfo() { Rectangle = bb.BoundingBox, Matrix = bb.Transformation, Name = ifcSpaces.Where(sp => (sp.EntityLabel == bb.IfcProductLabel)) .Select(sp => sp.Name.ToString()) .FirstOrDefault() } ).ToList(); } //only if we have any space information if (SpaceBoundingBoxInfo.Any()) { var t1 = geomReader.ShapeInstancesOfEntity(el).FirstOrDefault(); if (t1 == null) { return(string.Empty); } var t2 = t1.BoundingBox; var elBoundBox = t1.BoundingBox; var elWorldMatrix = t1.Transformation; //Get object space top and bottom points of the bounding box var elBoxPts = new List <XbimPoint3D> { new XbimPoint3D(elBoundBox.X, elBoundBox.Y, elBoundBox.Z), new XbimPoint3D(elBoundBox.X + elBoundBox.SizeX, elBoundBox.Y + elBoundBox.SizeY, elBoundBox.Z + elBoundBox.SizeZ), elBoundBox.Centroid() }; //convert points of the bounding box to WCS IEnumerable <XbimPoint3D> elBoxPtsWCS = elBoxPts.Select(pt => elWorldMatrix.Transform(pt)); //see if we hit any spaces spaceName = GetSpaceFromPoints(elBoxPtsWCS, SpaceBoundingBoxInfo); //if we failed to get space on min points then use the remaining corner points if (string.IsNullOrEmpty(spaceName)) { XbimPoint3D elMinPt = elBoxPts[0]; XbimPoint3D elMaxPt = elBoxPts[1]; //elBoxPts.Clear(); //already tested points in list so clear them //Extra testing on remaining corner points on the top and bottom plains elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMaxPt.Y, elMinPt.Z)); elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMinPt.Y, elMinPt.Z)); elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMaxPt.Y, elMinPt.Z)); elBoxPts.Add(new XbimPoint3D((elMaxPt.X - elMinPt.X) / 2.0, (elMaxPt.Y - elMinPt.Y) / 2.0, elMinPt.Z)); //centre face point elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMinPt.Y, elMaxPt.Z)); elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMinPt.Y, elMaxPt.Z)); elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMaxPt.Y, elMaxPt.Z)); elBoxPts.Add(new XbimPoint3D((elMaxPt.X - elMinPt.X) / 2.0, (elMaxPt.Y - elMinPt.Y) / 2.0, elMaxPt.Z)); //centre face point //convert points of the bounding box to WCS elBoxPtsWCS = elBoxPts.Select(pt => elWorldMatrix.Transform(pt)); //see if we hit any spaces spaceName = GetSpaceFromPoints(elBoxPtsWCS, SpaceBoundingBoxInfo); } if (string.IsNullOrEmpty(spaceName)) { //Get tolerance size from element, 1% of smallest side size double tol = elBoundBox.SizeX * 0.001; if ((elBoundBox.SizeY * 0.001) < tol) { tol = elBoundBox.SizeY * 0.001; } if ((elBoundBox.SizeZ * 0.001) < tol) { tol = elBoundBox.SizeZ * 0.001; } if ((tol == 0.0) && //if tol 0.0 ((Context.WorkBookUnits.LengthUnit.Equals("meters", StringComparison.OrdinalIgnoreCase)) || (Context.WorkBookUnits.LengthUnit.Equals("metres", StringComparison.OrdinalIgnoreCase)) ) ) { tol = 0.001; } spaceName = GetSpaceFromClosestPoints(elBoxPtsWCS, tol, SpaceBoundingBoxInfo); } } } } return(spaceName); }
/// <summary> /// Create the COBieBuilder, holds COBieWorkBook /// </summary> /// <param name="parameters">Params</param> /// <returns>COBieBuilder</returns> private COBieBuilder GenerateCOBieWorkBook(Params parameters) { string xbimFile = string.Empty; string fileExt = Path.GetExtension(parameters.ModelFile); COBieBuilder builder = null; LogBackground(String.Format("Loading model {0}...", Path.GetFileName(parameters.ModelFile))); using (XbimModel model = new XbimModel()) { if ((fileExt.Equals(".xbim", StringComparison.OrdinalIgnoreCase)) || (fileExt.Equals(".xbimf", StringComparison.OrdinalIgnoreCase)) ) { xbimFile = parameters.ModelFile; model.Open(xbimFile, XbimDBAccess.ReadWrite); //model.CacheStart(); } else //ifc file { xbimFile = Path.ChangeExtension(parameters.ModelFile, "xBIM"); model.CreateFrom(parameters.ModelFile, xbimFile, _worker.ReportProgress, true, false); } //model.Open(xbimFile, XbimDBAccess.ReadWrite); // Build context COBieContext context = new COBieContext(_worker.ReportProgress); context.TemplateFileName = parameters.TemplateFile; context.Model = model; context.MapMergeRoles[model] = Roles; context.Exclude = UserFilters; Model = model; //used to check we close file on Close event //Create Scene, required for Coordinates sheet if (!SkipGeoChkBox.Checked) { GenerateGeometry(context); } // Create COBieReader LogBackground("Generating COBie data..."); builder = new COBieBuilder(context); } return builder; }
/// <summary> /// Data Resource constructor /// </summary> /// <param name="context">The context of the model being generated</param> public COBieDataResource(COBieContext context) : base(context) { }
/// <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 {1} using {0} template...", Path.GetFileName(parameters.TemplateFile), parameters.IsXLSX ? "XLSX" : "XLS")); COBieXLSXSerialiser serialiser = new COBieXLSXSerialiser(parameters.ModelFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.IsXlsx = parameters.IsXLSX; serialiser.Serialise(Workbook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile)); Process.Start(serialiser.FileName); LogBackground("Finished COBie Validation"); }
protected COBieData(COBieContext context) { Context = context; _progressStatus = new COBieProgress(context); UnknownCount = 1; }
//Needed Geometry to test, but Steve's comment on "need to resolve generate geometry" may see GenerateGeometry change private void GenerateGeometry(COBieContext context) { //now convert the geometry XbimModel model = context.Model; int total = (int)model.Instances.CountOf<IfcProduct>(); ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { context.UpdateStatus("Creating Geometry File", total, (total * percentProgress / 100)); }; var m3D = new Xbim3DModelContext(model); try { m3D.CreateContext(progDelegate: progDelegate); } catch (Exception ce) { context.UpdateStatus("Error compiling geometry\n" + ce.Message, total, 100); } }
/// <summary> /// Data Assembly constructor /// </summary> public COBieDataAssembly(COBieContext context) : base(context) { }
/// <summary> /// Data Spare constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataSpare(COBieContext context) : base(context) { }
/// <summary> /// Data Floor constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataFloor(COBieContext context) : base(context) { }
/// <summary> /// Performs the export /// </summary> /// <returns>True on success, false on error.</returns> private bool ExportCoBie() { if (!Directory.Exists(TxtFolderName.Text)) { try { Directory.CreateDirectory(TxtFolderName.Text); } catch (Exception) { MessageBox.Show("Error creating directory. Select a different location."); return(false); } } var fName = Model.FileName; if (string.IsNullOrEmpty(fName)) { fName = "Unnamed"; } var f = new FileInfo(Path.ChangeExtension(fName, ".xls")); var outputFile = Path.Combine(TxtFolderName.Text, f.Name); // configure settings for exporter var ass = System.Reflection.Assembly.GetAssembly(GetType()); if (_parentWindow == null) { Log.LogError("attempt to locate DiskLess assembly without a valid IXbimXplorerPluginMasterWindow."); return(false); } var assemblyFile = _parentWindow.GetAssemblyLocation(ass); var pluginDir = new FileInfo(assemblyFile).Directory; if (pluginDir == null) { Log.LogError("Failed to determine plugin folder under IXbimXplorerPluginMasterWindow."); return(false); } var templateFileName = Path.Combine( pluginDir.FullName, CoBieTemplate); var context = new COBieContext { TemplateFileName = templateFileName, Model = Model, Exclude = UserFilters }; // setting culture for thread; the current one will be restored later. CultureInfo exisitingCultureInfo = null; try { var ci = new CultureInfo("en-GB"); exisitingCultureInfo = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception ex) { Log.LogError(0, ex, "CurrentUICulture could not be set to en-GB."); } // actual export code var builder = new COBieBuilder(context); var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) { Excludes = UserFilters }; builder.Export(serialiser); // restoring culture for thread; try { if (exisitingCultureInfo != null) { Thread.CurrentThread.CurrentUICulture = exisitingCultureInfo; } } catch (Exception ex) { Log.LogError(0, ex, "CurrentUICulture could not restored."); } if (ChkOpenExcel.IsChecked.HasValue && ChkOpenExcel.IsChecked.Value) { Process.Start(outputFile); } return(true); }
/// <summary> /// Get Space name which holds the passed in IfcElement /// </summary> /// <param name="el">Element to extract space name from</param> /// <param name="Model"></param> /// <param name="SpaceBoundingBoxInfo"></param> /// <param name="Context"></param> /// <returns>string</returns> internal static string GetComponentRelatedSpace(IfcElement el, IfcStore Model, IEnumerable <SpaceInfo> SpaceBoundingBoxInfo, COBieContext Context) { string value = ""; List <string> names = new List <string>(); if (el != null) //&& el.ContainedInStructure.Count() > 0 { var owningObjects = el.ContainedInStructure.Select(cis => cis.RelatingStructure).OfType <IfcSpace>(); //only one or zero held in ContainedInStructure foreach (IfcSpace item in owningObjects) { if (item.Name != null) { names.Add(item.Name); } } } //check for the element as a containing item of a space if (ifcRelSpaceBoundarys == null) { ifcRelSpaceBoundarys = Model.FederatedInstances.OfType <IfcRelSpaceBoundary>().Where(rsb => (rsb.RelatedBuildingElement != null)).ToList(); } var ifcSpaces = ifcRelSpaceBoundarys.Where(rsb => rsb.RelatedBuildingElement == el).Select(rsb => rsb.RelatingSpace); foreach (IfcSpace item in ifcSpaces) { if ((item.Name != null) && (!names.Contains(item.Name))) { names.Add(item.Name); } } if (names.Count > 0) //check we have some values { value = string.Join(", ", names); } //if no space is saved with the element then get from the geometry if (string.IsNullOrEmpty(value)) { value = GetSpaceHoldingElement(el, Model, SpaceBoundingBoxInfo, ifcSpaces, Context); } return(string.IsNullOrEmpty(value) ? Constants.DEFAULT_STRING : value); }
/// <summary> /// Data Issue constructor /// </summary> /// <param name="context">The context of the model being generated</param> public COBieDataIssue(COBieContext context) : base(context) { }
/// <summary> /// Data Component constructor /// </summary> /// <param name="context">The context of the model being generated</param> public COBieDataComponent(COBieContext context) : base(context) { SpaceBoundingBoxInfo = new List <SpaceInfo>(); }
/// <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> /// Data Job constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataJob(COBieContext context) : base(context) { }
/// <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> /// Data Document constructor /// </summary> public COBieDataDocument(COBieContext context) : base(context) { }
/// <summary> /// Data Facility constructor /// </summary> /// <param name="model">The context of the model being generated</param> public COBieDataFacility(COBieContext context) : base(context) { }