Example #1
0
 public static void CloseModel()
 {
     if (_model != null)
         _model.Close();
     _model = null;
     _cobieContext = null;
 }
Example #2
0
 public static void LoadModel(TestContext context)
 {
     if (!File.Exists(SourceFile)) throw new Exception("Cannot find file");
     _model = new XbimModel();
     _model.Open(SourceFile);
     _cobieContext = new COBieContext();
     _cobieContext.Model = _model;
 }
Example #3
0
        /// <summary>
        /// Create the xbimGC file
        /// </summary>
        /// <param name="model">IModel object</param>
        /// <param name="cacheFile">file path to write file too</param>
        /// <param name="context">Context object</param>
        private static void GenerateGeometry(XbimModel model, string cacheFile, COBieContext context)
        {
            //need to resolve gemerate geometry
            //int total = (int)model.GeometriesCount;
            ////create the geometry file

            //IEnumerable<IfcProduct> toDraw = model.Instances.OfType<IfcProduct>().Where(t => !(t is IfcFeatureElement)); //exclude openings and additions
            //XbimScene.ConvertGeometry(toDraw, delegate(int percentProgress, object userState)
            //{
            //    context.UpdateStatus("Creating Geometry File", total, (total * percentProgress / 100));
            //}, false);
          
        }
Example #4
0
        public void Should_Return_Spaces()
        {
            using (XbimModel model = new XbimModel())
            {
                model.Open(SourceFile, XbimDBAccess.ReadWrite);
                COBieContext cobieContext = new COBieContext();
                cobieContext.Model = model;

                COBieQueries cobieEngine = new COBieQueries(cobieContext);

                var spaces = cobieEngine.GetCOBieSpaceSheet();

                Assert.AreEqual(22, spaces.Rows.Count);

                FormatRows(spaces);
            }
        }
Example #5
0
		/// <summary>
		/// Constructor which also sets the Context
		/// </summary>
		/// <param name="context"></param>
		public COBieBuilder(COBieContext context) : this()
		{
            Context = context;
            GenerateCOBieData();
		}
Example #6
0
 //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);
                             }
Example #7
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");
            
            
        }
Example #8
0
        /// <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;
        }
Example #9
0
        /// <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;
        }
        public void Should_XBimSerialise()
        {
            COBieWorkbook workBook;
            COBieContext context;
            COBieBuilder builder;
            COBieWorkbook book;

            COBieBinaryDeserialiser deserialiser = new COBieBinaryDeserialiser(DuplexBinaryFile);
            workBook = deserialiser.Deserialise();

            using (COBieXBimSerialiser xBimSerialiser = new COBieXBimSerialiser(Path.ChangeExtension(DuplexBinaryFile, ".Ifc")))//Path.ChangeExtension(Path.GetFullPath(BinaryFile), ".Ifc")
            {
                xBimSerialiser.Serialise(workBook);

                context = new COBieContext(null);
                context.TemplateFileName = ExcelTemplateFile;
                context.Model = xBimSerialiser.Model;

                builder = new COBieBuilder(context);
                book = builder.Workbook;
            }

            // Assert
            Assert.AreEqual(19, book.Count);
        }
Example #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="model">IModel to read data from</param>
        public COBieQueries(COBieContext context)
        {
            _context = context;

            _attributes = new COBieSheet <COBieAttributeRow>(Constants.WORKSHEET_ATTRIBUTE); //create the attribute sheet
        }
        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.DatabaseName, ".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;
        }
Example #13
0
        public void ExportCOBie(string path, string template)
        {
            string outputFile = Path.ChangeExtension(path, ".xls"); //enforce xls
            FilterValues UserFilters = new FilterValues();//COBie Class filters, set to initial defaults
            // Build context
            COBieContext context = new COBieContext();
            context.TemplateFileName = template;
            context.Model = _model;
            //set filter option
            context.Exclude = UserFilters;

            //set the UI language to get correct resource file for template
            //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-"))
            //{
            try
            {
                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB");
                System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            }
            catch (Exception)
            {
                //to nothing Default culture will still be used

            }

            COBieBuilder builder = new COBieBuilder(context);
            COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName);

            serialiser.Excludes = UserFilters;
            builder.Export(serialiser);
        }
        public void Should_BinarySerialiser()
        {
            COBieWorkbook workBook;
            COBieContext context;
            COBieBuilder builder;

            context = new COBieContext(null);
            context.TemplateFileName = ExcelTemplateFile;

            using (XbimModel model = new XbimModel())
            {
                model.Open(DuplexFile, XbimDBAccess.ReadWrite, delegate(int percentProgress, object userState)
                {
                    Console.Write("\rReading File {1} {0}", percentProgress, DuplexFile);
                });
                context.Model = model;

                builder = new COBieBuilder(context);
                workBook = builder.Workbook;
                COBieBinarySerialiser serialiser = new COBieBinarySerialiser(DuplexBinaryFile);
                serialiser.Serialise(workBook);
            }
            double bytes = 0;
            if (File.Exists(DuplexBinaryFile))
            {
                FileInfo fileInfo = new FileInfo(DuplexBinaryFile);
                bytes = fileInfo.Length;
            }

            Assert.IsTrue(File.Exists(DuplexBinaryFile));
        }
 /// <summary>
 /// Create the xbimGC file
 /// </summary>
 /// <param name="model">IModel object</param>
 /// <param name="context">Context object</param>
 private static void GenerateGeometry(COBieContext context)
 {
     //now convert the geometry
     int total = (int)context.Model.Instances.CountOf<IfcProduct>(); //get all products for this model to place in return graph
     XbimMesher.GenerateGeometry(context.Model, null, delegate(int percentProgress, object userState)
     {
         context.UpdateStatus("Creating Geometry", total, (total * percentProgress / 100));
     });
 }
Example #16
0
 /// <summary>
 /// Constructor which also sets the Context
 /// </summary>
 /// <param name="context"></param>
 public COBieBuilder(COBieContext context) : this()
 {
     Context = context;
     GenerateCOBieData();
 }
        private void ExportCOBieCmdExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            string outputFile = Path.ChangeExtension(Model.DatabaseName, ".xls");

            // Build context
            COBieContext context = new COBieContext();
            context.TemplateFileName = COBieTemplate;
            context.Model = Model;
            //set filter option
            context.Exclude = UserFilters;

            //set the UI language to get correct resource file for template
            //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-"))
            //{
            try
            {
                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB");
                System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            }
            catch (Exception)
            {
                //to nothing Default culture will still be used

            }

            COBieBuilder builder = new COBieBuilder(context);
            COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName);
            serialiser.Excludes = UserFilters;
            builder.Export(serialiser);
            Process.Start(outputFile);
        }
Example #18
0
        /// <summary>
        /// Constructor 
        /// </summary>
        /// <param name="model">IModel to read data from</param>
        public COBieQueries(COBieContext context)
        {
            _context = context;

            _attributes = new COBieSheet<COBieAttributeRow>(Constants.WORKSHEET_ATTRIBUTE); //create the attribute sheet
        }
        private void ExportCoBieCmdExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var outputFile = Path.ChangeExtension(Model.DatabaseName, ".xls");

            // Build context
            var context = new COBieContext();
            context.TemplateFileName = CoBieTemplate;
            context.Model = Model;
            //set filter option
            context.Exclude = UserFilters;

            //set the UI language to get correct resource file for template
            //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-"))
            //{
            try
            {
                var ci = new CultureInfo("en-GB");
                Thread.CurrentThread.CurrentUICulture = ci;
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                //to nothing Default culture will still be used
            }

            var builder = new COBieBuilder(context);
            var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) {Excludes = UserFilters};
            builder.Export(serialiser);
            Process.Start(outputFile);
        }
        public void Should_BinarySerialiser_with_roles()
        {
            COBieWorkbook workBook, workBook2;
            COBieContext context;
            COBieBuilder builder;

            context = new COBieContext(null);
            context.TemplateFileName = ExcelTemplateFile;

            using (XbimModel model = new XbimModel())
            {
                model.Open(DuplexFile, XbimDBAccess.ReadWrite, delegate(int percentProgress, object userState)
                {
                    Console.Write("\rReading File {1} {0}", percentProgress, DuplexFile);
                });
                context.Model = model;
                context.MapMergeRoles[model] = COBieMergeRoles.Mechanical;

                builder = new COBieBuilder(context);
                workBook = builder.Workbook;
                COBieBinarySerialiser serialiser = new COBieBinarySerialiser(DuplexBinaryFile);
                serialiser.Serialise(workBook);

                COBieBinaryDeserialiser deserialiser = new COBieBinaryDeserialiser(DuplexBinaryFile);
                workBook2 = deserialiser.Deserialise();

            }

            Assert.IsTrue(workBook2[Constants.WORKSHEET_COMPONENT].RemovedRows.Count() > 0);
        }