Esempio n. 1
0
		private void Initialise()
        {
			if (Context == null) { throw new InvalidOperationException("COBieReader can't initialise without a valid Context."); }
			if (Context.Model == null) { throw new ArgumentException("COBieReader context must contain a models."); }

            //set default date for this run
            Context.RunDate = DateTime.Now.ToString(Constants.DATE_FORMAT);

            // set all the properties
            COBieQueries cq = new COBieQueries(Context);

            //create pick list from the template sheet
            COBieSheet<COBiePickListsRow> CobiePickLists = null;
            if ((!string.IsNullOrEmpty(Context.TemplateFileName)) &&
                File.Exists(Context.TemplateFileName)
                )
            {
                COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(Context.TemplateFileName, Constants.WORKSHEET_PICKLISTS);
                COBieWorkbook wbook = deSerialiser.Deserialise();
                if (wbook.Count > 0) CobiePickLists = (COBieSheet<COBiePickListsRow>)wbook.FirstOrDefault();

                
            }

            
            //fall back to xml file if not in template
            string pickListFileName = "PickLists.xml";
            if ((CobiePickLists == null) &&
                File.Exists(pickListFileName)
                )
                CobiePickLists = cq.GetCOBiePickListsSheet(pickListFileName);// create pick lists from xml
            if (Context.ExcludeFromPickList)
            {
                SetExcludeComponentTypes(CobiePickLists);
                SetExcludeObjTypeTypes(CobiePickLists);
            }
            //start the Cache
            Context.Model.CacheStart();
                
            //contact sheet first as it will fill contact information lookups for other sheets
            Workbook.Add(cq.GetCOBieContactSheet());
            Workbook.Add(cq.GetCOBieFacilitySheet()); 
            Workbook.Add(cq.GetCOBieFloorSheet());
            Workbook.Add(cq.GetCOBieSpaceSheet());
            Workbook.Add(cq.GetCOBieZoneSheet()); 
            Workbook.Add(cq.GetCOBieTypeSheet());
            Workbook.Add(cq.GetCOBieComponentSheet());
            Workbook.Add(cq.GetCOBieSystemSheet(Workbook[Constants.WORKSHEET_COMPONENT].Indices)); //pass component names 
            Workbook.Add(cq.GetCOBieAssemblySheet());
            Workbook.Add(cq.GetCOBieConnectionSheet());
            Workbook.Add(cq.GetCOBieSpareSheet());
            Workbook.Add(cq.GetCOBieResourceSheet());
            Workbook.Add(cq.GetCOBieJobSheet());
            Workbook.Add(cq.GetCOBieImpactSheet());
            Workbook.Add(cq.GetCOBieDocumentSheet());
            Workbook.Add(cq.GetCOBieAttributeSheet());//we need to fill attributes here as it is populated by Components, Type, Space, Zone, Floors, Facility etc
            //#if GEOMETRY_IMPLEMENTED
            Workbook.Add(cq.GetCOBieCoordinateSheet());
            //#endif
            Workbook.Add(cq.GetCOBieIssueSheet());
            if (CobiePickLists != null)
                Workbook.Add(CobiePickLists);
            else
                Workbook.Add(new COBieSheet<COBiePickListsRow>(Constants.WORKSHEET_PICKLISTS)); //add empty pick list
           
            //clear sheet session values from context
            Context.EMails.Clear();
            

        }
Esempio n. 2
0
 /// <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;
 }
Esempio n. 3
0
        /// <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");
            
            
        }
Esempio n. 4
0
        /// <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;
        }
        public void Should_Roundtrip_XLSSerialise()
        {
            string output = Path.ChangeExtension(SourceBinaryFile, ".xls");
            ICOBieSerialiser serialiser = new COBieXLSSerialiser(output, ExcelTemplateFile);
            serialiser.Serialise(_book, null);

            Stopwatch timer = new Stopwatch();
            timer.Start();
            //TEST on COBieXLSDeserialiser
            COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(output);
            COBieWorkbook newbook = deSerialiser.Deserialise();

            timer.Stop();
            Debug.WriteLine(string.Format("COBieXLSDeserialiser Time = {0}", timer.Elapsed.TotalSeconds.ToString()));

            string newOutputFile = Root + @"\" + "RoundTrip" + Path.ChangeExtension(SourceBinaryFile, ".xls");
            ICOBieSerialiser serialiserTest = new COBieXLSSerialiser(newOutputFile, ExcelTemplateFile);

            // Assert
            Assert.AreEqual(19, newbook.Count); //with picklist

            // 19 workbooks. # rows in a selection.
        }