Exemplo n.º 1
0
        public void IfcToCoBieLiteUkTest()
        {
            string[] testFiles = new string[] { "Lakeside_Restaurant.ifc", "001-Kenton_High_School_Model.ifc", "001 Hello Wall.ifc", "Duplex_A_20110907_optimized.ifc", "NBS_LakesideRestaurant_small_optimized.ifc", "Office_A_20110811_optimized.ifc" };

            foreach (var ifcTestFile in testFiles)
            {
                using (var m = new XbimModel())
                {
                    var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                    var jsonFile     = Path.ChangeExtension(ifcTestFile, "json");
                    m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                    facilities = ifcToCoBieLiteUkExchanger.Convert();

                    foreach (var facilityType in facilities)
                    {
                        var log = new StringWriter();
                        facilityType.ValidateUK2012(log, true);

                        string msg;
                        facilityType.WriteJson(jsonFile, true);
                        facilityType.WriteCobie("..\\..\\" + System.IO.Path.ChangeExtension(ifcTestFile, ".xlsx"), out msg, "UK2012", true);


                        break;
                    }
                }
            }
        }
        private static Facility GetFacilityFromIfc(Stream file, string extension)
        {
            var temp = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);

            try
            {
                //store temporarily
                using (var fileStream = File.OpenWrite(temp))
                {
                    file.CopyTo(fileStream);
                    fileStream.Flush();
                    fileStream.Close();
                }

                using (var model = new XbimModel())
                {
                    model.CreateFrom(temp, null, null, true);

                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);

                    return(ifcToCoBieLiteUkExchanger.Convert().FirstOrDefault());
                }
            }
            //tidy up
            finally
            {
                if (File.Exists(temp))
                {
                    File.Delete(temp);
                }
            }
        }
        private static Task <Stream> ConvertIfcToCobieLiteUkAsync(IfcStore ifcStore)
        {
            return(Task.Run <Stream>(() =>
            {
                if (ifcStore.SchemaVersion == Xbim.Common.Step21.XbimSchemaVersion.Ifc2X3)
                {
                    Ifc2x3IfcEntityLabelGenerator.enrichModelWithIfcEntityLabel(ifcStore);
                }
                else
                {
                    Ifc4x1IfcEntityLabelGenerator.enrichModelWithIfcEntityLabel(ifcStore);
                }

                var memStream = new MemoryStream();

                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(ifcStore, facilities, null, null, null, EntityIdentifierMode.GloballyUniqueIds, SystemExtractionMode.System);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                var facility = facilities.ToArray()[0];

                facility.WriteXml(memStream);

                return new MemoryStream(memStream.ToArray());
            }));
        }
Exemplo n.º 4
0
        public void IfcToCoBieLiteUkTestSingleFile()
        {
            string ifcTestFile = "001 BTK Sample.ifc";

            using (var m = new XbimModel())
            {
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                var jsonFile     = Path.ChangeExtension(ifcTestFile, "json");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    string msg;
                    facilityType.WriteJson(jsonFile, true);
                    facilityType.WriteCobie("..\\..\\" + System.IO.Path.ChangeExtension(ifcTestFile, ".xlsx"), out msg, "UK2012", true);


                    break;
                }
            }
        }
Exemplo n.º 5
0
        public static List <Xbim.CobieLiteUk.Facility> SaveCobieFile(IfcStore model, string outputFile)
        {
            //Logger.LogCurrentMethod();
            var facilities = new List <Xbim.CobieLiteUk.Facility>();
            var exchange   = new IfcToCOBieLiteUkExchanger(model, facilities);

            facilities = exchange.Convert();
            foreach (var facilityType in facilities)
            {
                var jsonFile = Path.ChangeExtension(outputFile, ".cobielite.json");

                // write json
                facilityType.WriteJson(jsonFile, true);
                Assert.IsTrue(File.Exists(jsonFile));

                // write xls
                var    cobieFile = Path.ChangeExtension(outputFile, ".cobielite.xls");
                string message   = "";
                facilityType.WriteCobie(cobieFile, out message);
                if (!string.IsNullOrWhiteSpace(message))
                {
                    Console.WriteLine(message);
                }
                Assert.IsTrue(File.Exists(cobieFile));
                break;
            }
            return(facilities);
        }
 public static Facility FacilityFromModel(XbimModel model)
 {
     var facilities = new List<Facility>();
     var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
     facilities = ifcToCoBieLiteUkExchanger.Convert();
     return facilities.FirstOrDefault();
 }
Exemplo n.º 7
0
        public void IfcToCoBieLiteUkTest()
        {
            const string ifcTestFile = @"Lakeside_Restaurant.ifc";

            using (var m = IfcStore.Open(ifcTestFile))
            {
                var jsonFile   = Path.ChangeExtension(ifcTestFile, "json");
                var facilities = new List <Facility>();

                var rolefilters           = new OutPutFilters();
                const RoleFilter reqRoles = RoleFilter.Unknown; //RoleFilter.Architectural |  RoleFilter.Mechanical | RoleFilter.Electrical | RoleFilter.FireProtection | RoleFilter.Plumbing;
                rolefilters.ApplyRoleFilters(reqRoles);

                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities, null, rolefilters);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    string msg;
                    facilityType.WriteJson(jsonFile, true);
                    facilityType.WriteCobie("..\\..\\Lakeside_Restaurant.xlsx", out msg, rolefilters, "UK2012", true);


                    break;
                }
            }
        }
Exemplo n.º 8
0
        public static Facility FacilityFromModel(XbimModel model)
        {
            var facilities = new List <Facility>();
            var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);

            facilities = ifcToCoBieLiteUkExchanger.Convert();
            return(facilities.FirstOrDefault());
        }
Exemplo n.º 9
0
        public void ImportWithAssemblies()
        {
            const string ifcTestFile = @"BasicFM_wAssembly.ifc";

            using (var m = IfcStore.Open(ifcTestFile))
            {
                var facilities = new List <Facility>();

                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    AssetType assetType = facilityType.AssetTypes.Find(type => type.Name.Equals("WallType.2 IW-1"));

                    Assembly typeAssembly = assetType.AssemblyOf;
                    Assert.AreEqual("myTypeAssembly", typeAssembly.Name);
                    Assert.AreEqual("myDescription", typeAssembly.Description);
                    Assert.IsNotNull(typeAssembly.ExternalEntity);
                    Assert.IsNotNull(typeAssembly.ExternalId);
                    Assert.IsNotNull(typeAssembly.AltExternalId);
                    Assert.IsNotNull(typeAssembly.ExternalSystem);
                    Assert.IsNotNull(typeAssembly.Categories);
                    Assert.IsNotNull(typeAssembly.CreatedBy);
                    Assert.IsNotNull(typeAssembly.CreatedOn);

                    EntityKey typeChild = typeAssembly.ChildAssetsOrTypes.First();
                    Assert.AreEqual("WallType.1 AW-1", typeChild.Name);
                    Assert.AreEqual(EntityType.AssetType, typeChild.KeyType);

                    Asset component = facilityType.AssetTypes
                                      .SelectMany(type => type.Assets)
                                      .ToList()
                                      .Find(asset => asset.Name.Equals("Slab 001"));

                    Assembly componentAssembly = component.AssemblyOf;
                    Assert.AreEqual("myAssetComponentAssembly", componentAssembly.Name);
                    Assert.AreEqual("myDescription", componentAssembly.Description);
                    Assert.IsNotNull(componentAssembly.ExternalEntity);
                    Assert.IsNotNull(componentAssembly.ExternalId);
                    Assert.IsNotNull(componentAssembly.AltExternalId);
                    Assert.IsNotNull(componentAssembly.ExternalSystem);
                    Assert.IsNotNull(componentAssembly.Categories);
                    Assert.IsNotNull(componentAssembly.CreatedBy);
                    Assert.IsNotNull(componentAssembly.CreatedOn);

                    EntityKey componentChild = componentAssembly.ChildAssetsOrTypes.First();
                    Assert.AreEqual("Slab 002", componentChild.Name);
                    Assert.AreEqual(EntityType.Asset, componentChild.KeyType);

                    break;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate Facilities for a xbim or ifc type file
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="fileExt"></param>
        /// <returns></returns>
        private List <Facility> GenerateFileFacility(Params parameters, string fileExt)
        {
            var facilities = new List <Facility>();

            using (var model = new XbimModel())
            {
                if (fileExt.Equals(".xbim", StringComparison.OrdinalIgnoreCase))
                {
                    model.Open(parameters.ModelFile, XbimExtensions.XbimDBAccess.Read, Worker.ReportProgress);
                }
                else
                {
                    var xbimFile = Path.ChangeExtension(parameters.ModelFile, "xbim");
                    model.CreateFrom(parameters.ModelFile, xbimFile, Worker.ReportProgress, true, true);
                }
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities, Worker.ReportProgress, parameters.Filter, parameters.ConfigFile, parameters.ExtId, parameters.SysMode);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
            }
            return(facilities);
        }
        private static Facility GetValidated(string requirementFile)
        {
            const string ifcTestFile = @"Lakeside_Restaurant_fabric_only.ifczip";
            Facility     sub         = null;

            //create validation file from IFC
            using (var m = IfcStore.Open(ifcTestFile))
            {
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
                sub        = facilities.FirstOrDefault();
            }
            Assert.IsTrue(sub != null);
            var vd        = new FacilityValidator();
            var req       = Facility.ReadJson(requirementFile);
            var validated = vd.Validate(req, sub);

            return(validated);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            using (var m = IfcStore.Open("Lakeside_Restaurant.ifc"))
            {
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                var facilityType = facilities.FirstOrDefault();
                if (facilityType != null)
                {
                    //write the cobie data in json format
                    facilityType.WriteJson("Cobie.json", true);
                    //write the cobie data in xml format
                    facilityType.WriteXml("Cobie.xml", true);
                    //write the cobie data in spreadsheet format
                    string errMsg;
                    facilityType.WriteCobie("Cobie.xls", out errMsg);
                }
            }
        }
        private static Facility GetValidated(string requirementFile)
        {
            const string ifcTestFile = @"Lakeside_Restaurant_fabric_only.ifczip";
            Facility sub = null;

            //create validation file from IFC
            using (var m = new XbimModel())
            {
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List<Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
                sub = facilities.FirstOrDefault();
            }
            Assert.IsTrue(sub!=null);
            var vd = new FacilityValidator();
            var req = Facility.ReadJson(requirementFile);
            var validated = vd.Validate(req, sub);
            return validated;
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Generate Facilities for a xbimf federated file
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private List <Facility> GenerateFedFacility(Params parameters)
        {
            var facilities = new List <Facility>();

            try
            {
                using (var fedModel = new FederatedModel(new FileInfo(parameters.ModelFile)))
                {
                    if (fedModel.Model.IsFederation)
                    {
                        Dictionary <XbimModel, OutPutFilters>     FedFilters      = parameters.Filter.SetFedModelFilter <XbimModel>(fedModel.RefModelRoles);
                        Dictionary <RoleFilter, List <Facility> > RolesFacilities = new Dictionary <RoleFilter, List <Facility> >();
                        foreach (var item in FedFilters)
                        {
                            var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(item.Key, new List <Facility>(), Worker.ReportProgress, item.Value, parameters.ConfigFile, parameters.ExtId, parameters.SysMode);
                            ifcToCoBieLiteUkExchanger.ReportProgress.Progress = Worker.ReportProgress;
                            var rolesFacility = ifcToCoBieLiteUkExchanger.Convert();

                            //facilities.AddRange(rolesFacility);
                            if (RolesFacilities.ContainsKey(item.Value.AppliedRoles))
                            {
                                RolesFacilities[item.Value.AppliedRoles].AddRange(rolesFacility);
                            }
                            else
                            {
                                RolesFacilities.Add(item.Value.AppliedRoles, rolesFacility);
                            }
                        }
                        var fedFacilities = RolesFacilities.OrderByDescending(d => d.Key.HasFlag(RoleFilter.Architectural)).SelectMany(p => p.Value).ToList(); //pull architectural roles facilities to the top
                        //fedFacilities = RolesFacilities.Values.SelectMany(f => f).OrderByDescending(f => f.AssetTypes.Count).ToList(); //pull facility with largest number of AssetTypes to the top
                        //fedFacilities = RolesFacilities.Values.SelectMany(f => f).ToList(); //flatten value lists
                        if (fedFacilities.Any())
                        {
                            Facility baseFacility = fedFacilities.First();
                            fedFacilities.RemoveAt(0);
                            if (parameters.Log)
                            {
                                var logfile = Path.ChangeExtension(parameters.ModelFile, "merge.log");
                                using (StreamWriter sw = new StreamWriter(logfile))
                                //using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput())) //to debug console **slow**
                                {
                                    sw.AutoFlush = true;
                                    foreach (Facility mergeFacility in fedFacilities)
                                    {
                                        baseFacility.Merge(mergeFacility, sw);
                                    }
                                }
                            }
                            else
                            {
                                foreach (Facility mergeFacility in fedFacilities)
                                {
                                    baseFacility.Merge(mergeFacility, null);
                                }
                            }
                            facilities.Add(baseFacility);
                        }
                    }
                    else
                    {
                        throw new XbimException(string.Format("Model is not Federated: {0}", fedModel.FileNameXbimf));
                    }
                }
            }
            catch (ArgumentException Ex) //bad paths etc..
            {
                Worker.ReportProgress(0, Ex.Message);
            }
            catch (XbimException Ex) //not federated
            {
                Worker.ReportProgress(0, Ex.Message);
            }

            return(facilities);
        }
Exemplo n.º 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();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Generate Facilities for a xbim or ifc type file
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="fileExt"></param>
        /// <returns></returns>
        private List<Facility> GenerateFileFacility(Params parameters, string fileExt)
        {
            var facilities = new List<Facility>();
            using (var model = new XbimModel())
            {
                if (fileExt.Equals(".xbim", StringComparison.OrdinalIgnoreCase))
                {
                    model.Open(parameters.ModelFile, Xbim.XbimExtensions.XbimDBAccess.Read, Worker.ReportProgress);
                }
                else
                {
                    var xbimFile = Path.ChangeExtension(parameters.ModelFile, "xbim");
                    model.CreateFrom(parameters.ModelFile, xbimFile, Worker.ReportProgress, true, true);

                }
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities, Worker.ReportProgress, parameters.Filter, parameters.ConfigFile, parameters.ExtId, parameters.SysMode);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
            }
            return facilities;
        }
Exemplo n.º 18
0
        public void IfcToCoBieLiteUkTest()
        {
            using (var m = new XbimModel())
            {
                const string ifcTestFile = @"Lakeside_Restaurant.ifc";
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                var jsonFile = Path.ChangeExtension(ifcTestFile, "json");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List<Facility>();

                OutPutFilters rolefilters = new OutPutFilters();
                RoleFilter reqRoles = RoleFilter.Unknown; //RoleFilter.Architectural |  RoleFilter.Mechanical | RoleFilter.Electrical | RoleFilter.FireProtection | RoleFilter.Plumbing;
                rolefilters.ApplyRoleFilters(reqRoles);

                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities, null, rolefilters);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    string msg;
                    facilityType.WriteJson(jsonFile, true);
                    facilityType.WriteCobie("..\\..\\Lakeside_Restaurant.xlsx", out msg, rolefilters, "UK2012", true);


                    break;
                }
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No IIfc or xBim file specified");
                return;
            }
            var fileName = args[0];

            Console.WriteLine("Reading " + fileName);

            using (var model = GetModel(fileName))
            {
                if (model == null)
                {
                    Console.WriteLine("No model to process. Press any key to exit");
                    Console.Read();
                    return;
                }

                var context = new Xbim3DModelContext(model);
                context.CreateContext();
                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);
                        model.SaveAsWexBim(wexBimBinaryWriter);
                        wexBimBinaryWriter.Close();
                    }
                    wexBiMfile.Close();
                }
                //now do COBieExpress
                var cobie               = new MemoryModel(new EntityFactory());
                var cobieExpressFile    = Path.ChangeExtension(fileName, ".cobie");
                var cobieExpressXmlFile = Path.ChangeExtension(fileName, ".cobieXml");
                var cobieExpressZipFile = Path.ChangeExtension(fileName, ".cobieZip");
                var w = new Stopwatch();
                using (var txn = cobie.BeginTransaction("IFC data in"))
                {
                    var exchanger = new IfcToCoBieExpressExchanger(model, cobie);
                    w.Start();
                    exchanger.Convert();
                    w.Stop();
                    txn.Commit();
                }
                Console.WriteLine("COBieExpress model created in {0}ms", w.ElapsedMilliseconds);
                cobie.SaveAsStep21(File.Create(cobieExpressFile));
                cobie.SaveAsStep21Zip(File.Create(cobieExpressZipFile));
                cobie.SaveAsXml(File.Create(cobieExpressXmlFile), new XmlWriterSettings {
                    Indent = true, IndentChars = "\t"
                });


                //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");
                    var credentials = new XbimEditorCredentials()
                    {
                        ApplicationDevelopersName = "XbimTeam",
                        ApplicationFullName       = "Xbim.Exchanger",
                        EditorsOrganisationName   = "Xbim Development Team",
                        EditorsFamilyName         = "Xbim Tester",
                        ApplicationVersion        = "3.0"
                    };
                    Console.WriteLine("Creating " + dPoWFile);
                    using (
                        var ifcModel = IfcStore.Create(credentials, IfcSchemaVersion.Ifc2X3,
                                                       XbimStoreType.EsentDatabase))
                    {
                        using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                        {
                            var coBieLiteUkToIIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                            coBieLiteUkToIIfcExchanger.Convert();
                            txn.Commit();
                            //var err = model.Validate(model.Instances, Console.Out);
                        }
                        dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                        Console.WriteLine("Creating " + dPoWFile);
                        ifcModel.SaveAs(dPoWFile, IfcStorageType.Ifc);
                        ifcModel.Close();
                    }
                }
                model.Close();
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Exemplo n.º 20
0
        private List <Facility> GetFacilities(IfcStore model, CobieConversionParams parameters)
        {
            var facilities = new List <Facility>();

            if (model.IsFederation == false)
            {
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(
                    model,
                    facilities,
                    Worker.ReportProgress,
                    parameters.Filter,
                    parameters.ConfigFile,
                    parameters.ExtId,
                    parameters.SysMode
                    );
                facilities = ifcToCoBieLiteUkExchanger.Convert();
            }
            else
            {
                var roles           = model.GetFederatedFileRoles();
                var fedFilters      = parameters.Filter.SetFedModelFilter(roles);
                var rolesFacilities = new Dictionary <RoleFilter, List <Facility> >();
                foreach (var filter in fedFilters)
                {
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(
                        filter.Key.Model,
                        new List <Facility>(),
                        Worker.ReportProgress,
                        filter.Value,
                        parameters.ConfigFile,
                        parameters.ExtId,
                        parameters.SysMode
                        );
                    ifcToCoBieLiteUkExchanger.ReportProgress.Progress = Worker.ReportProgress;
                    var rolesFacility = ifcToCoBieLiteUkExchanger.Convert();

                    //facilities.AddRange(rolesFacility);
                    if (rolesFacilities.ContainsKey(filter.Value.AppliedRoles))
                    {
                        rolesFacilities[filter.Value.AppliedRoles].AddRange(rolesFacility);
                    }
                    else
                    {
                        rolesFacilities.Add(filter.Value.AppliedRoles, rolesFacility);
                    }
                }
                var fedFacilities =
                    rolesFacilities.OrderByDescending(d => d.Key.HasFlag(RoleFilter.Architectural))
                    .SelectMany(p => p.Value)
                    .ToList();
                if (!fedFacilities.Any())
                {
                    return(facilities);
                }
                var baseFacility = fedFacilities.First();
                fedFacilities.RemoveAt(0);
                if (parameters.Log)
                {
                    var logfile = Path.ChangeExtension(model.FileName, "merge.log");
                    using (var sw = new StreamWriter(logfile))
                    {
                        sw.AutoFlush = true;
                        foreach (var mergeFacility in fedFacilities)
                        {
                            baseFacility.Merge(mergeFacility, sw);
                        }
                    }
                }
                else
                {
                    foreach (var mergeFacility in fedFacilities)
                    {
                        baseFacility.Merge(mergeFacility);
                    }
                }
                facilities.Add(baseFacility);
            }
            return(facilities);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Generate Facilities for a xbimf federated file
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private List<Facility> GenerateFedFacility(Params parameters)
        {
            var facilities = new List<Facility>();
            try
            {

                if (_fedModelProxy.IsFederation)
                {
                    var fedFilters = parameters.Filter.SetFedModelFilter(GetFileRoles());
                    var rolesFacilities = new Dictionary<RoleFilter, List<Facility>>();
                    foreach (var item in fedFilters)
                    {
                        var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(item.Key, new List<Facility>(),
                            Worker.ReportProgress, item.Value, parameters.ConfigFile, parameters.ExtId,
                            parameters.SysMode);
                        ifcToCoBieLiteUkExchanger.ReportProgress.Progress = Worker.ReportProgress;
                        var rolesFacility = ifcToCoBieLiteUkExchanger.Convert();

                        //facilities.AddRange(rolesFacility);
                        if (rolesFacilities.ContainsKey(item.Value.AppliedRoles))
                        {
                            rolesFacilities[item.Value.AppliedRoles].AddRange(rolesFacility);
                        }
                        else
                        {
                            rolesFacilities.Add(item.Value.AppliedRoles, rolesFacility);
                        }

                    }
                    var fedFacilities =
                        rolesFacilities.OrderByDescending(d => d.Key.HasFlag(RoleFilter.Architectural))
                            .SelectMany(p => p.Value)
                            .ToList(); //pull architectural roles facilities to the top
                    //fedFacilities = RolesFacilities.Values.SelectMany(f => f).OrderByDescending(f => f.AssetTypes.Count).ToList(); //pull facility with largest number of AssetTypes to the top
                    //fedFacilities = RolesFacilities.Values.SelectMany(f => f).ToList(); //flatten value lists
                    if (fedFacilities.Any())
                    {
                        var baseFacility = fedFacilities.First();
                        fedFacilities.RemoveAt(0);
                        if (parameters.Log)
                        {
                            var logfile = Path.ChangeExtension(parameters.ModelFile, "merge.log");
                            using (var sw = new StreamWriter(logfile))
                                //using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput())) //to debug console **slow**
                            {
                                sw.AutoFlush = true;
                                foreach (var mergeFacility in fedFacilities)
                                {
                                    baseFacility.Merge(mergeFacility, sw);
                                }
                            }
                        }
                        else
                        {
                            foreach (var mergeFacility in fedFacilities)
                            {
                                baseFacility.Merge(mergeFacility, null);
                            }
                        }
                        facilities.Add(baseFacility);
                    }

                }
                else
                {
                    throw new XbimException("Model is not Federated:");
                }

            }
            catch (ArgumentException Ex) //bad paths etc..
            {
                Worker.ReportProgress(0, Ex.Message);
            }
            catch (XbimException Ex) //not federated
            {
                Worker.ReportProgress(0, Ex.Message);
            }

            return facilities;
        }
Exemplo n.º 22
0
        private static void ProcessFile(string fileName, ExchangeSettings settings)
        {
            var outDirectoryName = Path.GetDirectoryName(fileName);

            if (settings.OutputdDirectory != null)
            {
                outDirectoryName = settings.OutputdDirectory.FullName;
            }
            if (outDirectoryName == null)
            {
                return;
            }
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

            var w = new Stopwatch();

            w.Start();
            Console.WriteLine("Reading " + fileName);
            using (var model = GetModel(fileName))
            {
                if (model == null)
                {
                    Console.WriteLine("No model to process. Press any key to exit");
                    Console.Read();
                    return;
                }
                Console.WriteLine("Model open in {0}ms", w.ElapsedMilliseconds);

                // wexbim
                w.Restart();
                var wexBimFilename = GetSaveName(outDirectoryName, fileNameWithoutExtension, ".wexBIM");
                Console.WriteLine("Creating " + wexBimFilename);
                var context = new Xbim3DModelContext(model);
                context.CreateContext();
                using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                {
                    using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                    {
                        model.SaveAsWexBim(wexBimBinaryWriter);
                        wexBimBinaryWriter.Close();
                    }
                    wexBiMfile.Close();
                }
                Console.WriteLine("wexBIM model created in {0}ms", w.ElapsedMilliseconds);

                //now do COBieExpress
                //
                w.Restart();
                Console.WriteLine("Creating CobieExpress memoryModel...");
                var cobie               = new MemoryModel(new EntityFactoryCobieExpress());
                var cobieExpressFile    = GetSaveName(outDirectoryName, fileNameWithoutExtension, ".cobie");
                var cobieExpressXmlFile = GetSaveName(outDirectoryName, fileNameWithoutExtension, ".cobieXml");
                var cobieExpressZipFile = GetSaveName(outDirectoryName, fileNameWithoutExtension, ".cobieZip");
                using (var txn = cobie.BeginTransaction("IFC data in"))
                {
                    var exchanger = new IfcToCoBieExpressExchanger(model, cobie);
                    exchanger.Convert();
                    txn.Commit();
                }

                Console.WriteLine("COBieExpress memoryModel created and commited in {0}ms...", w.ElapsedMilliseconds);
                w.Restart();
                cobie.SaveAsStep21(File.Create(cobieExpressFile));
                cobie.SaveAsStep21Zip(File.Create(cobieExpressZipFile));
                cobie.SaveAsXml(File.Create(cobieExpressXmlFile), new XmlWriterSettings {
                    Indent = true, IndentChars = "\t"
                },
                                XbimXmlSettings.IFC4Add2);
                Console.WriteLine("3 COBieExpress files (.cobie., cobieXml and .cobieZip) saved in {0}ms",
                                  w.ElapsedMilliseconds);

                //now do the DPoW files
                //
                w.Restart();
                Console.WriteLine("Creating CobieLiteUK Model...");


                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                Console.WriteLine("{1} facilities converted in in {0}ms",
                                  w.ElapsedMilliseconds,
                                  facilities.Count
                                  );

                var multipleFacilities = facilities.Count > 1;

                for (var index = 0; index < facilities.Count; index++)
                {
                    w.Restart();
                    var facility          = facilities[index];
                    var dpowNameExtension = "DPoW";
                    if (multipleFacilities)
                    {
                        dpowNameExtension += index + 1;
                    }
                    // write json

                    var dPoWFile = GetSaveName(outDirectoryName, fileNameWithoutExtension + "_" + dpowNameExtension, ".json");
                    Console.Write("Creating " + dPoWFile + "...");
                    facility.WriteJson(dPoWFile);
                    Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);

                    // xlsx
                    var cobieFile = Path.ChangeExtension(dPoWFile, "xlsx");
                    Console.WriteLine("Creating " + cobieFile + "...");
                    string error;
                    facility.WriteCobie(cobieFile, out error);
                    Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);
                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("COBie Errors: " + error);
                        Console.ResetColor();
                    }

                    // dpow validation
                    //
                    if (!string.IsNullOrEmpty(settings.DpowRequirementFile))
                    {
                        w.Restart();
                        Console.Write("Reading DPoW requirement file: " + settings.DpowRequirementFile + "...");
                        var req = Facility.ReadJson(settings.DpowRequirementFile);
                        Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);

                        w.Restart();
                        Console.Write("Validating DPOW...");
                        var validator = new FacilityValidator();
                        var result    = validator.Validate(req, facility);
                        Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);

                        w.Restart();
                        var validationResults = Path.ChangeExtension(dPoWFile, "validationReport.xlsx");
                        Console.Write("writing validation report: " + validationResults);
                        //create report
                        using (var stream = File.Create(validationResults))
                        {
                            var report = new ExcelValidationReport();
                            report.Create(result, stream, ExcelValidationReport.SpreadSheetFormat.Xlsx);
                            stream.Close();
                        }
                        Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);
                    }

                    // now attempt basic content validation and recovery
                    //
                    w.Restart();
                    Console.WriteLine("Validating and recovering...");
                    facility.ValidateUK2012(Console.Out, true);
                    var cobieValidatedFile = Path.ChangeExtension(dPoWFile, "ValidationWithAttemptedRecovery.xlsx");
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    facility.WriteCobie(cobieValidatedFile, out error);
                    Console.ResetColor();
                    Console.WriteLine("Completed in {0}ms", w.ElapsedMilliseconds);

                    // now ifc
                    //
                    w.Restart();
                    dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                    Console.Write("Creating " + dPoWFile + "...");
                    var credentials = new XbimEditorCredentials()
                    {
                        ApplicationDevelopersName = "XbimTeam",
                        ApplicationFullName       = "Xbim.Exchanger",
                        EditorsOrganisationName   = "Xbim Development Team",
                        EditorsFamilyName         = "Xbim Tester",
                        ApplicationVersion        = global::System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()
                    };
                    using (var ifcModel = IfcStore.Create(credentials, XbimSchemaVersion.Ifc2X3, XbimStoreType.EsentDatabase))
                    {
                        using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                        {
                            var coBieLiteUkToIIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                            coBieLiteUkToIIfcExchanger.Convert();
                            txn.Commit();
                            //var err = model.Validate(model.Instances, Console.Out);
                        }
                        ifcModel.SaveAs(dPoWFile, StorageType.Ifc);
                        ifcModel.Close();
                    }
                    Console.WriteLine(" completed in {0}ms", w.ElapsedMilliseconds);
                }
                model.Close();
            }
        }