Esempio n. 1
0
        public static void ConvertDpowToCobie(Stream input, CloudBlockBlob outputCobieBlob)
        {
            var temp = Path.GetTempFileName();

            try
            {
                var dpow      = PlanOfWork.Open(input);
                var facility  = new FacilityType();
                var exchanger = new XbimExchanger.DPoWToCOBieLite.DpoWtoCoBieLiteExchanger(dpow, facility);
                exchanger.Convert();

                using (var tw = File.CreateText(temp))
                {
                    CoBieLiteHelper.WriteJson(tw, facility);
                    tw.Close();
                }
                outputCobieBlob.UploadFromFile(temp, FileMode.Open);
            }
            finally
            {
                //tidy up
                if (File.Exists(temp))
                {
                    File.Delete(temp);
                }
            }
        }
        public void ConvertDPoWToCOBieLite()
        {
            var          pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "Export";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            var outputs = new List <string>();

            foreach (var stage in pow.ProjectStages)
            {
                var facility  = new FacilityType();
                var exchanger = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                exchanger.Convert();
                var output = Path.Combine(dir, stage.Name + ".json");
                outputs.Add(output);
                facility.WriteJson(output);
            }

            //check all result files exist
            foreach (var output in outputs)
            {
                Assert.IsTrue(File.Exists(output));
            }

            //try to reload to make sure serialization and deserilization works in both directions
            foreach (var output in outputs)
            {
                var facility = FacilityType.ReadJson(output);
            }
        }
Esempio n. 3
0
        public void ConvertDPoWToCOBieLite()
        {
            var dpow      = PlanOfWork.Open("NewtownHighSchool.dpow");
            var facility  = new FacilityType();
            var exchanger = new DPoWToCOBieLiteExchanger(dpow, facility);

            exchanger.Convert();
        }
Esempio n. 4
0
        private static string GetUniclassCode(DPoWObject asset, PlanOfWork pow)
        {
            var uniclass       = pow.ClassificationSystems.FirstOrDefault(c => c.Name == "Uniclass2015");
            var classification = asset.GetClassificationReferences(pow);

            foreach (var ci in classification)
            {
                var item = uniclass.ClassificationReferences.FirstOrDefault(c => c.Id == ci.Id);
                if (item != null)
                {
                    return(item.ClassificationCode);
                }
            }
            return(string.Empty);
        }
Esempio n. 5
0
        /// <summary>
        /// Perform the conversion, writing data to the provided output path
        /// </summary>
        /// <param name="outputFilePath">Path of output xml file (should have the extension .xml so the MPXJ library automatically infers the file type)</param>
        public void Convert(string outputFilePath)
        {
            // Open and parse dPOW file
            pow = PlanOfWork.OpenJson(inputFilePath);

            // Create project file
            project = new ProjectFile();

            // Insert data to project file
            InsertDataToProject();

            // Write file to mpx
            ProjectWriter mpxWriter = ProjectWriterUtility.getProjectWriter(outputFilePath);

            mpxWriter.write(project, outputFilePath);
        }
        public void LoadDPoWFromString()
        {
            //var data = File.ReadAllText("dpowData.json");
            var data     = File.ReadAllText("NewtownHighSchool.dpow");
            var settings = new JsonSerializerSettings()
            {
            };
            var dpc = new DPoWObjectConverter();

            settings.Converters.Add(dpc);
            var dpow = JsonConvert.DeserializeObject <PlanOfWork>(data, settings);

            Assert.AreEqual("Newtown High School", dpow.Project.ProjectName);
            Assert.AreEqual("dPOW Document Numbering", dpow.ClassificationSystem[0].ClassificationName);
            Assert.IsTrue(dpow.ProjectStages.Any(ps => ps.Jobs.Any(j => j.DPoWObjects.Any(t => t.GetType() == typeof(AssemblyType)))));

            var data2 = JsonConvert.SerializeObject(dpow, settings);

            //create ZONE and AssetType
            dpow.ProjectStages[1].Jobs[0].DPoWObjects.Add(new Zone()
            {
                DPoWObjectCategory = new ClassificationReference()
                {
                    ClassificationCode = "A"
                }, DPoWObjectName = "Zone A", RequiredLOD = new RequiredLOD()
                {
                    RequiredLODCode = "123"
                }
            });
            dpow.ProjectStages[1].Jobs[0].DPoWObjects.Add(new AssetType()
            {
                DPoWObjectCategory = new ClassificationReference()
                {
                    ClassificationCode = "A"
                }, DPoWObjectName = "Zone A", RequiredLOD = new RequiredLOD()
                {
                    RequiredLODCode = "123"
                }
            });

            dpow.Save("test1.dpow");
            dpow = PlanOfWork.Open("test1.dpow");

            Assert.IsTrue(dpow.ProjectStages[1].Jobs[0].DPoWObjects.Any(t => t.GetType() == typeof(Zone)));
            Assert.IsTrue(dpow.ProjectStages[1].Jobs[0].DPoWObjects.Any(t => t.GetType() == typeof(AssetType)));
        }
        public void CheckDocumentsInDPoW()
        {
            var pow = PlanOfWork.OpenJson("013-Lakeside_Restaurant.dpow");
            var num = 0;

            foreach (var stage in pow.ProjectStages ?? new List <ProjectStage>())
            {
                foreach (var documentation in stage.DocumentationSet ?? new List <Documentation>())
                {
                    if (documentation.Attributes != null)
                    {
                        num += documentation.Attributes.Count;
                    }
                }
            }
            //Assert.AreEqual(0, num);
        }
Esempio n. 8
0
        public void Dpow2CobieLite2Ifc()
        {
            var          pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "..\\..\\Export";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var d2C      = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                d2C.Convert();

                var outputIfc       = Path.Combine(dir, stage.Name + ".DPoW.ifc");
                var outputCobieJson = Path.Combine(dir, stage.Name + ".DPoW.json");
                var outputCobieXml  = Path.Combine(dir, stage.Name + ".DPoW.xml");
                facility.WriteJson(outputCobieJson);
                facility.WriteXml(outputCobieXml);
                var credentials = new XbimEditorCredentials()
                {
                    ApplicationDevelopersName = "XbimTeam",
                    ApplicationFullName       = "Xbim.Exchanger",
                    EditorsOrganisationName   = "Xbim Development Team",
                    EditorsFamilyName         = "Xbim Tester",
                    ApplicationVersion        = "3.0"
                };
                using (var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
                {
                    using (var txn = model.BeginTransaction("Convert from COBieLite"))
                    {
                        var c2Ifc = new CoBieLiteToIfcExchanger(facility, model);
                        c2Ifc.Convert();
                        txn.Commit();
                    }
                    model.SaveAs(outputIfc, IfcStorageType.Ifc);

                    if (facility.AssetTypes != null)
                    {
                        Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType <IfcTypeObject>().Count());
                    }
                }
            }
        }
        public void ConvertDPoWToAll()
        {
            var          pow = PlanOfWork.OpenJson("001-Lakeside_Restaurant.dpow");
            const string dir = "..\\..\\COBieLiteUK";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string msg;

            foreach (var stage in pow.ProjectStages)
            {
                var json = Path.Combine(dir, stage.Name + ".cobie.json");
                var xlsx = Path.Combine(dir, stage.Name + ".xlsx");
                var ifc  = Path.Combine(dir, stage.Name + ".ifc");

                var facility       = new Xbim.CobieLiteUk.Facility();
                var cobieExchanger = new DPoWToCOBieLiteUKExchanger(pow, facility, stage);
                cobieExchanger.Convert(DateTime.Now);

                facility.WriteJson(json, true);
                facility.WriteCobie(xlsx, out msg);


                //using (var ifcModel = XbimModel.CreateTemporaryModel())
                //{
                //    ifcModel.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                //    using (var txn = ifcModel.BeginTransaction("Conversion from COBie"))
                //    {
                //        ifcModel.Header.FileName.Name = stage.Name;
                //        ifcModel.ReloadModelFactors();
                //        var ifcExchanger = new XbimExchanger.COBieLiteUkToIfc.CoBieLiteUkToIfcExchanger(facility, ifcModel);
                //        ifcExchanger.Convert();
                //        txn.Commit();
                //    }
                //    ifcModel.SaveAs(ifc, XbimStorageType.IFC);
                //    ifcModel.Close();
                //}
            }
        }
Esempio n. 10
0
        public void Dpow2CobieLite2Ifc()
        {
            var          pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "..\\..\\Export";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var d2C      = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                d2C.Convert();

                var outputIfc       = Path.Combine(dir, stage.Name + ".DPoW.ifc");
                var outputCobieJson = Path.Combine(dir, stage.Name + ".DPoW.json");
                var outputCobieXml  = Path.Combine(dir, stage.Name + ".DPoW.xml");
                facility.WriteJson(outputCobieJson);
                facility.WriteXml(outputCobieXml);

                using (var model = XbimModel.CreateTemporaryModel())
                {
                    model.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                    model.ReloadModelFactors();
                    using (var txn = model.BeginTransaction("Convert from COBieLite"))
                    {
                        var c2Ifc = new CoBieLiteToIfcExchanger(facility, model);
                        c2Ifc.Convert();
                        txn.Commit();
                    }
                    model.SaveAs(outputIfc, XbimStorageType.IFC);

                    if (facility.AssetTypes != null)
                    {
                        Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType <IfcTypeObject>().Count());
                    }
                }
            }
        }
Esempio n. 11
0
        public static IEnumerable <Category> GetEncodedClassification(this PlanOfWork pow, IEnumerable <Guid> classificationReferenceIds, string suffix = "")
        {
            var ids = classificationReferenceIds != null?classificationReferenceIds.ToArray() : new Guid[]
            {
            };
            var idsNum = ids.Length;

            if (idsNum == 0)
            {
                yield break;
            }

            var processedCount = 0;

            //itterate over ids and get it all together
            foreach (var classification in pow.ClassificationSystems)
            {
                foreach (var reference in classification.ClassificationReferences)
                {
                    if (!ids.Contains(reference.Id))
                    {
                        continue;
                    }

                    yield return(new Category
                    {
                        Classification = classification.Name,
                        Code = reference.ClassificationCode + (String.IsNullOrEmpty(suffix) ? "" : "/" + suffix),
                        Description = reference.ClassificationDescription
                    });

                    //optimization: stop processing if all reference ids were found already.
                    processedCount++;
                    if (processedCount == ids.Length)
                    {
                        break;
                    }
                }
            }
        }
        public void ConvertDPoWToCOBieLite()
        {
            //var pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            var          pow = PlanOfWork.OpenJson("013-Lakeside_Restaurant.dpow");
            const string dir = "..\\..\\COBieLiteUK";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            var    outputs = new List <string>();
            string msg;

            foreach (var stage in pow.ProjectStages)
            {
                var facility  = new Xbim.CobieLiteUk.Facility();
                var exchanger = new DPoWToCOBieLiteUKExchanger(pow, facility, stage);
                exchanger.Convert();
                var output = Path.Combine(dir, stage.Name + ".cobieliteUK.json");
                var xls    = Path.Combine(dir, stage.Name + ".xlsx");
                outputs.Add(output);
                facility.WriteJson(output, true);
                facility.WriteCobie(xls, out msg);
            }

            //check all result files exist
            foreach (var output in outputs)
            {
                Assert.IsTrue(File.Exists(output));
            }

            //try to reload to make sure serialization and deserilization works in both directions
            foreach (var output in outputs)
            {
                var facility = Xbim.CobieLiteUk.Facility.ReadJson(output);
            }
        }
Esempio n. 13
0
        public static string GetEncodedClassification(this PlanOfWork pow, IEnumerable <Guid> classificationReferenceIds, string suffix = "")
        {
            var ids = classificationReferenceIds != null?classificationReferenceIds.ToArray() : new Guid[]
            {
            };
            var idsNum = ids.Length;

            if (idsNum == 0)
            {
                return(null);
            }

            var result         = "";
            var processedCount = 0;

            //itterate over ids and get it all together
            foreach (var classification in pow.ClassificationSystems)
            {
                foreach (var reference in classification.ClassificationReferences)
                {
                    if (!ids.Contains(reference.Id))
                    {
                        continue;
                    }

                    result += String.Format("{0}:{1}:{2}|", classification.Name, reference.ClassificationCode,
                                            suffix);

                    processedCount++;
                    if (processedCount == ids.Length)
                    {
                        break;
                    }
                }
            }
            return(result.Trim('|'));
        }