예제 #1
0
        private static string CreateWexBIM(XbimModel model, string fileName)
        {
            try
            {
                var context = new Xbim3DModelContext(model);
                context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
                var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                {
                    using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                    {
                        //Console.WriteLine("Creating " + wexBimFilename);
                        context.Write(wexBimBinaryWriter);
                        wexBimBinaryWriter.Close();
                    }
                    wexBiMfile.Close();
                }

                return(wexBimFilename);
            }
            catch (Exception ex)
            {
                Log.Error("转换xBIM文件失败:" + ex.Message, ex);
                throw;
            }
        }
예제 #2
0
        private void DoExport(object sender, RoutedEventArgs e)
        {
            var totExports = (ChkWexbim.IsChecked.HasValue && ChkWexbim.IsChecked.Value ? 1 : 0);

            if (totExports == 0)
            {
                return;
            }

            if (!Directory.Exists(TxtFolderName.Text))
            {
                try
                {
                    Directory.CreateDirectory(TxtFolderName.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Error creating directory. Select a different location.");
                    return;
                }
            }

            Cursor = Cursors.Wait;
            if (ChkWexbim.IsChecked.HasValue && ChkWexbim.IsChecked.Value)
            {
                // file preparation
                //
                var wexbimFileName = GetExportName("wexbim");
                try
                {
                    using (var wexBimFile = new FileStream(wexbimFileName, FileMode.Create))
                    {
                        using (var binaryWriter = new BinaryWriter(wexBimFile))
                        {
                            try
                            {
                                var geomContext = new Xbim3DModelContext(_mainWindow.Model);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }
                        }
                    }
                }
                catch (Exception ce)
                {
                    if (CancelAfterNotification("Error exporting Wexbim file.", ce, totExports))
                    {
                        Cursor = Cursors.Arrow;
                        return;
                    }
                }
                totExports--;
            }
            Cursor = Cursors.Arrow;
            Close();
        }
예제 #3
0
        /// <summary>
        /// Converts an Ifc File to xBIM if it does not already exists, then converts the geoemtry to Xbim format and profiles the results
        /// </summary>
        /// <param name="args"> file[.ifc, xbim]</param>

        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No Ifc or xBim file specified");
                return;
            }
            var fileName      = args[0];
            var mainStopWatch = new Stopwatch();

            mainStopWatch.Start();
            using (var model = GetModel(fileName))
            {
                if (model != null)
                {
                    var functionStack = new ConcurrentStack <Tuple <string, double> >();
                    ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState)
                    {
                        if (percentProgress == -1)
                        {
                            functionStack.Push(new Tuple <string, double>(userState.ToString(), DateTime.Now.TimeOfDay.TotalMilliseconds));
                            Logger.InfoFormat("Entering - {0}", userState.ToString());
                        }

                        else if (percentProgress == 101)
                        {
                            Tuple <string, double> func;
                            if (functionStack.TryPop(out func))
                            {
                                Logger.InfoFormat("Complete in \t\t{0:0.0} ms", DateTime.Now.TimeOfDay.TotalMilliseconds - func.Item2);
                            }
                        }
                    };
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary, progDelegate: progDelegate);

                    mainStopWatch.Stop();
                    Logger.InfoFormat("Xbim total Compile Time \t\t{0:0.0} ms", mainStopWatch.ElapsedMilliseconds);
                    var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                    using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                        {
                            var stopWatch = new Stopwatch();
                            Logger.InfoFormat("Entering -  Create wexBIM");
                            stopWatch.Start();
                            context.Write(wexBimBinaryWriter);
                            stopWatch.Stop();
                            Logger.InfoFormat("Complete - in \t\t{0:0.0} ms", stopWatch.ElapsedMilliseconds);
                            wexBimBinaryWriter.Close();
                        }
                        wexBiMfile.Close();
                    }

                    model.Close();
                }
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
예제 #4
0
        public static void ConvertFile(string ifcFileFullName, string destinationFolder, string wexBimFileName, string xbimFile)
        {
            string workingDir = destinationFolder;

            if (string.IsNullOrWhiteSpace(destinationFolder))
            {
                workingDir = Path.GetDirectoryName(ifcFileFullName);
            }
            else
            {
                workingDir = destinationFolder;
            }
            if (string.IsNullOrWhiteSpace(workingDir))
            {
                throw new ApplicationException("The destination folder not specified.");
            }
            if (!Path.IsPathRooted(workingDir))
            {
                throw new ApplicationException("The destination folder not rooted.");
            }
            if (!Directory.Exists(workingDir))
            {
                throw new ApplicationException("The destination folder not found.");
            }
            string fileName = Path.GetFileName(ifcFileFullName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            string coreDestinationFileName  = Path.Combine(workingDir, fileNameWithoutExtension);

            if (string.IsNullOrWhiteSpace(wexBimFileName))
            {
                wexBimFileName = Path.ChangeExtension(coreDestinationFileName, "wexbim");
            }
            else
            {
                wexBimFileName = Path.Combine(workingDir, Path.GetFileName(wexBimFileName));
            }
            if (string.IsNullOrWhiteSpace(xbimFile))
            {
                xbimFile = Path.ChangeExtension(coreDestinationFileName, "xbim");
            }
            else
            {
                xbimFile = Path.Combine(workingDir, Path.GetFileName(xbimFile));
            }
            using (FileStream wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(wexBimFile))
                {
                    using (XbimModel model = new XbimModel())
                    {
                        model.CreateFrom(ifcFileFullName, xbimFile, null, true, false);
                        Xbim3DModelContext geomContext = new Xbim3DModelContext(model);
                        geomContext.CreateContext(XbimGeometryType.PolyhedronBinary); // System.OutOfMemoryException Exception
                        geomContext.Write(binaryWriter);
                    }
                }
            }
        }
예제 #5
0
        private void DoExport(object sender, RoutedEventArgs e)
        {
            var totExports = (ChkWexbim.IsChecked.HasValue && ChkWexbim.IsChecked.Value ? 1 : 0);
            if (totExports == 0)
                return;

            if (!Directory.Exists(TxtFolderName.Text))
            {
                try
                {
                    Directory.CreateDirectory(TxtFolderName.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Error creating directory. Select a different location.");
                    return;
                }
            }

            Cursor = Cursors.Wait;
            if (ChkWexbim.IsChecked.HasValue && ChkWexbim.IsChecked.Value)
            {
                // file preparation
                //
                var wexbimFileName = GetExportName("wexbim");
                try
                {
                    using (var wexBimFile = new FileStream(wexbimFileName, FileMode.Create))
                    {
                        using (var binaryWriter = new BinaryWriter(wexBimFile))
                        {
                            try
                            {
                                var geomContext = new Xbim3DModelContext(_mainWindow.Model);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }
                        }
                    }
                }
                catch (Exception ce)
                {
                    if (CancelAfterNotification("Error exporting Wexbim file.", ce, totExports))
                    {
                        Cursor = Cursors.Arrow;
                        return;
                    }
                }
                totExports--;
            }
            Cursor = Cursors.Arrow;
            Close();
        }
예제 #6
0
        private static void ExportGeometryData(string geometryFileName, Xbim3DModelContext m3DModelContext)
        {
            using (var geometryStream = new FileStream(geometryFileName, FileMode.Create))
            {
                using (var bw = new BinaryWriter(geometryStream))
                {
                    m3DModelContext.Write(bw);

                    bw.Close();
                    geometryStream.Close();
                }
            }
        }
예제 #7
0
        private static void WriteWexBim(string fnameIn)
        {
            var fNameOut = Path.ChangeExtension(fnameIn, "wexbim");

            using (var m = new XbimModel())
            {
                m.CreateFrom(fnameIn, null, null, true, true);
                var m3D = new Xbim3DModelContext(m);
                m3D.CreateContext(XbimGeometryType.PolyhedronBinary);
                using (var bw = new BinaryWriter(new FileStream(fNameOut, FileMode.Create)))
                {
                    m3D.Write(bw);
                    bw.Close();
                }
            }
        }
예제 #8
0
        private static void CreateWexBimFromIfc(XbimModel model, string ifcFileFullPath)
        {
            var wexBimFileName = Path.ChangeExtension(ifcFileFullPath, "wexbim");
            var xbimFile       = Path.ChangeExtension(ifcFileFullPath, "xbim");



            if (model != null)
            {
                var context = new Xbim3DModelContext(model);
                context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
                var wexBimFilename = Path.ChangeExtension(ifcFileFullPath, "wexBIM");
                using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                {
                    using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                    {
                        Console.WriteLine("Creating " + wexBimFilename);
                        context.Write(wexBimBinaryWriter);
                        wexBimBinaryWriter.Close();
                    }
                    wexBiMfile.Close();
                }



                //    using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                //{

                //    using (var binaryWriter = new BinaryWriter(wexBimFile))
                //    {



                //        using (var model = new XbimModel())
                //        {
                //            model.CreateFrom(ifcFileFullPath, xbimFile, null, true, false);

                //            Xbim3DModelContext geomContext = new Xbim3DModelContext(model);

                //            geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);

                //            geomContext.Write(binaryWriter);

                //        }
                //    }
            }
        }
예제 #9
0
        public void ConverIfcToWexBim()
        {
            const string ifcFileFullName = @"Lakeside_Restaurant.ifc";

            var fileName = Path.GetFileName(ifcFileFullName);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            var workingDir = Directory.GetCurrentDirectory();
            var coreFileName = Path.Combine(workingDir, fileNameWithoutExtension);
            var wexBimFileName = Path.ChangeExtension(coreFileName, "wexbim");
            var xbimFile = Path.ChangeExtension(coreFileName, "xbim");
            try
            {

                using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                {
                    using (var binaryWriter = new BinaryWriter(wexBimFile))
                    {

                        using (var model = new XbimModel())
                        {
                            try
                            {
                                model.CreateFrom(ifcFileFullName, xbimFile, null, true);
                                var geomContext = new Xbim3DModelContext(model);
                                geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                model.Close();
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }

                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Failed to process " + ifcFileFullName + " - " + e.Message);
            }
        }
예제 #10
0
        public void ConverIfcToWexBim()
        {
            const string ifcFileFullName = @"Lakeside_Restaurant.ifc";

            var fileName = Path.GetFileName(ifcFileFullName);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            var workingDir     = Directory.GetCurrentDirectory();
            var coreFileName   = Path.Combine(workingDir, fileNameWithoutExtension);
            var wexBimFileName = Path.ChangeExtension(coreFileName, "wexbim");
            var xbimFile       = Path.ChangeExtension(coreFileName, "xbim");

            try
            {
                using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                {
                    using (var binaryWriter = new BinaryWriter(wexBimFile))
                    {
                        using (var model = new XbimModel())
                        {
                            try
                            {
                                model.CreateFrom(ifcFileFullName, xbimFile, null, true);
                                var geomContext = new Xbim3DModelContext(model);
                                geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                model.Close();
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Failed to process " + ifcFileFullName + " - " + e.Message);
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No Ifc or xBim file specified");
                return;
            }
            var fileName = args[0];

            Console.WriteLine("Reading " + fileName);

            using (var model = GetModel(fileName))
            {
                if (model != null)
                {
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
                    var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                    using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                        {
                            Console.WriteLine("Creating " + wexBimFilename);
                            context.Write(wexBimBinaryWriter);
                            wexBimBinaryWriter.Close();
                        }
                        wexBiMfile.Close();
                    }
                    //now do the DPoW files
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                    var fileDirectoryName        = Path.GetDirectoryName(fileName);
                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
                    facilities = ifcToCoBieLiteUkExchanger.Convert();

                    var facilityNumber = 0;

                    foreach (var facility in facilities)
                    {
                        var dpow = "DPoW";
                        if (facilities.Count > 1)
                        {
                            dpow += ++facilityNumber;
                        }
                        // ReSharper disable AssignNullToNotNullAttribute
                        var dPoWFile = Path.Combine(fileDirectoryName, fileNameWithoutExtension + "_" + dpow);
                        // ReSharper restore AssignNullToNotNullAttribute
                        dPoWFile = Path.ChangeExtension(dPoWFile, "json");
                        Console.WriteLine("Creating " + dPoWFile);

                        facility.WriteJson(dPoWFile);
                        string cobieFile = Path.ChangeExtension(dPoWFile, "Xlsx");
                        Console.WriteLine("Creating " + cobieFile);
                        string error;
                        facility.WriteCobie(cobieFile, out error);
                        if (!string.IsNullOrWhiteSpace(error))
                        {
                            Console.WriteLine("COBie Errors: " + error);
                        }

                        dPoWFile = Path.ChangeExtension(dPoWFile, "xml");
                        Console.WriteLine("Creating " + dPoWFile);
                        // facility.WriteXml(dPoWFile);
                        var req                 = Facility.ReadJson(@"..\..\Tests\ValidationFiles\Lakeside_Restaurant-stage6-COBie.json");
                        var validator           = new FacilityValidator();
                        var result              = validator.Validate(req, facility);
                        var verificationResults = Path.ChangeExtension(dPoWFile, "verified.xlsx");
                        Console.WriteLine("Creating " + verificationResults);
                        //create report
                        using (var stream = File.Create(verificationResults))
                        {
                            var report = new ExcelValidationReport();
                            report.Create(result, stream, ExcelValidationReport.SpreadSheetFormat.Xlsx);
                            stream.Close();
                        }

                        facility.ValidateUK2012(Console.Out, true);
                        string cobieValidatedFile = Path.ChangeExtension(dPoWFile, "Validated.Xlsx");
                        facility.WriteCobie(cobieValidatedFile, out error);
                        dPoWFile = Path.ChangeExtension(dPoWFile, "xbim");
                        Console.WriteLine("Creating " + dPoWFile);
                        using (var ifcModel = XbimModel.CreateModel(dPoWFile))
                        {
                            ifcModel.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                            ifcModel.ReloadModelFactors();
                            using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                            {
                                var coBieLiteUkToIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                                coBieLiteUkToIfcExchanger.Convert();
                                txn.Commit();
                                //var err = model.Validate(model.Instances, Console.Out);
                            }
                            dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                            Console.WriteLine("Creating " + dPoWFile);
                            ifcModel.SaveAs(dPoWFile, XbimStorageType.IFC);
                            ifcModel.Close();
                        }
                    }
                    model.Close();
                }
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
예제 #12
0
        public void ReadAndWriteWexBimFile()
        {
            using (var m = new XbimModel())
            {
                m.CreateFrom("SolidTestFiles\\19 - TwoProxy.ifc", null, null, true, true);
                var m3D = new Xbim3DModelContext(m);
                m3D.CreateContext(XbimGeometryType.PolyhedronBinary);
                using (var bw = new BinaryWriter(new FileStream("test.wexBIM", FileMode.Create)))
                {
                    m3D.Write(bw);
                    bw.Close();
                }
                using (var fs = new FileStream(@"test.wexBIM", FileMode.Open, FileAccess.Read))
                {
                    using (var br = new BinaryReader(fs))
                    {
                        var magicNumber = br.ReadInt32();
                        var version = br.ReadByte();
                        var shapeCount = br.ReadInt32();
                        var vertexCount = br.ReadInt32();
                        var triangleCount = br.ReadInt32();
                        var matrixCount = br.ReadInt32();
                        var productCount = br.ReadInt32();
                        var styleCount = br.ReadInt32();
                        var meter =  br.ReadSingle();
                        Assert.IsTrue(meter>0);
                        var regionCount = br.ReadInt16();
                        for (int i = 0; i < regionCount; i++)
                        {
                            var population = br.ReadInt32();
                            var centreX = br.ReadSingle();
                            var centreY = br.ReadSingle();
                            var centreZ = br.ReadSingle();
                            var boundsBytes = br.ReadBytes(6 * sizeof(float));
                            var modelBounds = XbimRect3D.FromArray(boundsBytes);
                        }

                        for (int i = 0; i < styleCount; i++)
                        {
                            var styleId = br.ReadInt32();
                            var red = br.ReadSingle();
                            var green = br.ReadSingle();
                            var blue = br.ReadSingle();
                            var alpha = br.ReadSingle();
                        }
                        for (int i = 0; i < productCount ; i++)
                        {
                            var productLabel = br.ReadInt32();
                            var productType = br.ReadInt16();
                            var boxBytes = br.ReadBytes(6 * sizeof(float));
                            XbimRect3D bb = XbimRect3D.FromArray(boxBytes);
                        }
                        for (int i = 0; i < shapeCount; i++)
                        {
                            var shapeRepetition = br.ReadInt32();
                            Assert.IsTrue(shapeRepetition > 0);
                            if (shapeRepetition > 1)
                            {
                                for (int j = 0; j < shapeRepetition; j++)
                                {
                                    var ifcProductLabel = br.ReadInt32();
                                    var instanceTypeId = br.ReadInt16();
                                    var instanceLabel = br.ReadInt32();
                                    var styleId = br.ReadInt32();
                                    var transform = XbimMatrix3D.FromArray(br.ReadBytes(sizeof(float) * 16));
                                }
                                var triangulation = br.ReadShapeTriangulation();
                            }
                            else if (shapeRepetition == 1)
                            {
                                var ifcProductLabel = br.ReadInt32();
                                var instanceTypeId = br.ReadInt16();
                                var instanceLabel = br.ReadInt32();
                                var styleId = br.ReadInt32();
                                var triangulation = br.ReadShapeTriangulation();
                            }
                        }
                    }
                }

            }
        }
예제 #13
0
        /// <summary>
        /// Converts an Ifc File to xBIM if it does not already exists, then converts the geoemtry to Xbim format and profiles the results
        /// </summary>
        /// <param name="args"> file[.ifc, xbim]</param>
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No Ifc or xBim file specified");
                return;
            }
            var fileName = args[0];
            var mainStopWatch = new Stopwatch();
            mainStopWatch.Start();
            using (var model = GetModel(fileName))
            {
                if (model != null)
                {
                    var functionStack = new ConcurrentStack<Tuple<string,double>>();
                    ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState)
                    {
                        if (percentProgress == -1)
                        {
                            functionStack.Push(new Tuple<string,double>(userState.ToString(), DateTime.Now.TimeOfDay.TotalMilliseconds));
                            Logger.InfoFormat("Entering - {0}", userState.ToString());
                        }

                        else if (percentProgress == 101)
                        {
                            Tuple<string,double> func;
                            if(functionStack.TryPop(out func))
                                Logger.InfoFormat("Complete in \t\t{0:0.0} ms", DateTime.Now.TimeOfDay.TotalMilliseconds - func.Item2);
                        }
                    };
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary, progDelegate: progDelegate);

                    mainStopWatch.Stop();
                    Logger.InfoFormat("Xbim total Compile Time \t\t{0:0.0} ms", mainStopWatch.ElapsedMilliseconds);
                    var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                    using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                        {
                            var stopWatch = new Stopwatch();
                            Logger.InfoFormat("Entering -  Create wexBIM");
                            stopWatch.Start();
                            context.Write(wexBimBinaryWriter);
                            stopWatch.Stop();
                            Logger.InfoFormat("Complete - in \t\t{0:0.0} ms", stopWatch.ElapsedMilliseconds);
                            wexBimBinaryWriter.Close();
                        }
                        wexBiMfile.Close();
                    }

                    model.Close();
                }
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
예제 #14
0
        public static void ConvertIfcToWexbimAndCobie(Stream input, CloudBlockBlob outputWexbimBlob, CloudBlockBlob outputCobieBlob, string inputExtension)
        {
            //temp files
            var fileName       = Path.GetTempPath() + Guid.NewGuid() + inputExtension;
            var xbimFileName   = Path.ChangeExtension(fileName, ".xBIM");
            var wexBimFileName = Path.ChangeExtension(fileName, ".wexBIM");
            var cobieFileName  = Path.ChangeExtension(fileName, ".json");

            try
            {
                using (var fileStream = File.OpenWrite(fileName))
                {
                    input.CopyTo(fileStream);
                    fileStream.Flush();
                    fileStream.Close();
                    //open the model and import
                    using (var model = new XbimModel())
                    {
                        model.CreateFrom(fileName, null, null, true);
                        var m3DModelContext = new Xbim3DModelContext(model);

                        using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                        {
                            using (var bw = new BinaryWriter(wexBimFile))
                            {
                                m3DModelContext.CreateContext(XbimGeometryType.PolyhedronBinary);
                                m3DModelContext.Write(bw);
                                bw.Close();
                                wexBimFile.Close();
                                outputWexbimBlob.UploadFromFile(wexBimFileName, FileMode.Open);
                            }
                        }

                        using (var cobieFile = new FileStream(cobieFileName, FileMode.Create))
                        {
                            var helper   = new CoBieLiteHelper(model, "UniClass");
                            var facility = helper.GetFacilities().FirstOrDefault();
                            if (facility != null)
                            {
                                using (var writer = new StreamWriter(cobieFile))
                                {
                                    CoBieLiteHelper.WriteJson(writer, facility);
                                    writer.Close();
                                    outputCobieBlob.UploadFromFile(cobieFileName, FileMode.Open);
                                }
                            }
                        }

                        model.Close();
                    }
                }
            }
            finally
            {
                //tidy up
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                if (File.Exists(xbimFileName))
                {
                    File.Delete(xbimFileName);
                }
                if (File.Exists(wexBimFileName))
                {
                    File.Delete(wexBimFileName);
                }
                if (File.Exists(cobieFileName))
                {
                    File.Delete(cobieFileName);
                }
            }
        }
예제 #15
0
        public void ReadAndWriteWexBimFile()
        {
            using (var m = new XbimModel())
            {
                m.CreateFrom("SolidTestFiles\\19 - TwoProxy.ifc", null, null, true, true);
                var m3D = new Xbim3DModelContext(m);
                m3D.CreateContext(XbimGeometryType.PolyhedronBinary);
                using (var bw = new BinaryWriter(new FileStream("test.wexBIM", FileMode.Create)))
                {
                    m3D.Write(bw);
                    bw.Close();
                }
                using (var fs = new FileStream(@"test.wexBIM", FileMode.Open, FileAccess.Read))
                {
                    using (var br = new BinaryReader(fs))
                    {
                        var magicNumber   = br.ReadInt32();
                        var version       = br.ReadByte();
                        var shapeCount    = br.ReadInt32();
                        var vertexCount   = br.ReadInt32();
                        var triangleCount = br.ReadInt32();
                        var matrixCount   = br.ReadInt32();
                        var productCount  = br.ReadInt32();
                        var styleCount    = br.ReadInt32();
                        var meter         = br.ReadSingle();
                        Assert.IsTrue(meter > 0);
                        var regionCount = br.ReadInt16();
                        for (int i = 0; i < regionCount; i++)
                        {
                            var population  = br.ReadInt32();
                            var centreX     = br.ReadSingle();
                            var centreY     = br.ReadSingle();
                            var centreZ     = br.ReadSingle();
                            var boundsBytes = br.ReadBytes(6 * sizeof(float));
                            var modelBounds = XbimRect3D.FromArray(boundsBytes);
                        }

                        for (int i = 0; i < styleCount; i++)
                        {
                            var styleId = br.ReadInt32();
                            var red     = br.ReadSingle();
                            var green   = br.ReadSingle();
                            var blue    = br.ReadSingle();
                            var alpha   = br.ReadSingle();
                        }
                        for (int i = 0; i < productCount; i++)
                        {
                            var        productLabel = br.ReadInt32();
                            var        productType  = br.ReadInt16();
                            var        boxBytes     = br.ReadBytes(6 * sizeof(float));
                            XbimRect3D bb           = XbimRect3D.FromArray(boxBytes);
                        }
                        for (int i = 0; i < shapeCount; i++)
                        {
                            var shapeRepetition = br.ReadInt32();
                            Assert.IsTrue(shapeRepetition > 0);
                            if (shapeRepetition > 1)
                            {
                                for (int j = 0; j < shapeRepetition; j++)
                                {
                                    var ifcProductLabel = br.ReadInt32();
                                    var instanceTypeId  = br.ReadInt16();
                                    var instanceLabel   = br.ReadInt32();
                                    var styleId         = br.ReadInt32();
                                    var transform       = XbimMatrix3D.FromArray(br.ReadBytes(sizeof(float) * 16));
                                }
                                var triangulation = br.ReadShapeTriangulation();
                            }
                            else if (shapeRepetition == 1)
                            {
                                var ifcProductLabel = br.ReadInt32();
                                var instanceTypeId  = br.ReadInt16();
                                var instanceLabel   = br.ReadInt32();
                                var styleId         = br.ReadInt32();
                                var triangulation   = br.ReadShapeTriangulation();
                            }
                        }
                    }
                }
            }
        }
예제 #16
0
        static void Main(string[] args)
        {
            
            if (args.Length < 1)
            {
                Console.WriteLine("No Ifc or xBim file specified");
                return;
            }
            var fileName = args[0];
            Console.WriteLine("Reading " + fileName);
           
            using (var model = GetModel(fileName))
            {
                if (model != null)
                {
                   
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
                    var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                    using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                        {
                            Console.WriteLine("Creating " + wexBimFilename);
                            context.Write(wexBimBinaryWriter);
                            wexBimBinaryWriter.Close();
                        }
                        wexBiMfile.Close();
                    }
                    //now do the DPoW files
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                    var fileDirectoryName = Path.GetDirectoryName(fileName);
                    var facilities = new List<Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
                    facilities = ifcToCoBieLiteUkExchanger.Convert();
                    
                    var facilityNumber = 0;

                    foreach (var facility in facilities)
                    {
                        var dpow = "DPoW";
                        if (facilities.Count > 1) 
                            dpow += ++facilityNumber;
                        // ReSharper disable AssignNullToNotNullAttribute
                        var dPoWFile = Path.Combine(fileDirectoryName, fileNameWithoutExtension + "_" + dpow);
                        // ReSharper restore AssignNullToNotNullAttribute
                        dPoWFile = Path.ChangeExtension(dPoWFile, "json");
                        Console.WriteLine("Creating " + dPoWFile);

                        facility.WriteJson(dPoWFile);
                        string cobieFile = Path.ChangeExtension(dPoWFile, "Xlsx");
                        Console.WriteLine("Creating " + cobieFile);
                        string error;
                        facility.WriteCobie(cobieFile, out error);
                        if (!string.IsNullOrWhiteSpace(error))
                            Console.WriteLine("COBie Errors: " + error);

                        dPoWFile = Path.ChangeExtension(dPoWFile, "xml");
                        Console.WriteLine("Creating " + dPoWFile);
                       // facility.WriteXml(dPoWFile);
                        var req = Facility.ReadJson(@"..\..\Tests\ValidationFiles\Lakeside_Restaurant-stage6-COBie.json");
                        var validator = new FacilityValidator();
                        var result = validator.Validate(req, facility);
                        var verificationResults = Path.ChangeExtension(dPoWFile, "verified.xlsx");
                        Console.WriteLine("Creating " + verificationResults);
                        //create report
                        using (var stream = File.Create(verificationResults))
                        {
                            var report = new ExcelValidationReport();
                            report.Create(result, stream, ExcelValidationReport.SpreadSheetFormat.Xlsx);
                            stream.Close();
                        }

                        facility.ValidateUK2012(Console.Out,true);
                        string cobieValidatedFile = Path.ChangeExtension(dPoWFile, "Validated.Xlsx");
                        facility.WriteCobie(cobieValidatedFile, out error);
                        dPoWFile = Path.ChangeExtension(dPoWFile, "xbim");
                        Console.WriteLine("Creating " + dPoWFile);
                        using (var ifcModel = XbimModel.CreateModel(dPoWFile))
                        {
                            ifcModel.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                            ifcModel.ReloadModelFactors();
                            using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                            {
                                var coBieLiteUkToIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                                coBieLiteUkToIfcExchanger.Convert();
                                txn.Commit();
                                //var err = model.Validate(model.Instances, Console.Out);
                            }
                            dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                            Console.WriteLine("Creating " + dPoWFile);
                            ifcModel.SaveAs(dPoWFile, XbimStorageType.IFC);
                            ifcModel.Close();
                        }
                    }
                    model.Close();
                }
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
예제 #17
0
        private static void ExportGeometryData(string geometryFileName, Xbim3DModelContext m3DModelContext)
        {
            using (var geometryStream = new FileStream(geometryFileName, FileMode.Create))
            {
                using (var bw = new BinaryWriter(geometryStream))
                {
                    m3DModelContext.Write(bw);

                    bw.Close();
                    geometryStream.Close();
                }
            }
        }
예제 #18
0
 private static void WriteWexBim(string fnameIn)
 {
     var fNameOut = Path.ChangeExtension(fnameIn, "wexbim");
     using (var m = new XbimModel())
     {
         m.CreateFrom(fnameIn, null, null, true, true);
         var m3D = new Xbim3DModelContext(m);
         m3D.CreateContext(XbimGeometryType.PolyhedronBinary);
         using (var bw = new BinaryWriter(new FileStream(fNameOut, FileMode.Create)))
         {
             m3D.Write(bw);
             bw.Close();
         }
     }
 }