예제 #1
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;
        }
예제 #2
0
        /// <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;
        }
        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);
        }