示例#1
0
        public void ExtractSemanticModel()
        {
            const string original = "SampleHouse4.ifc";

            using (var model = new IO.Memory.MemoryModel(new Ifc4.EntityFactory()))
            {
                model.LoadStep21(original);
                var roots = model.Instances.OfType <Ifc4.Kernel.IfcRoot>();
                using (var iModel = new IO.Memory.MemoryModel(new Ifc4.EntityFactory()))
                {
                    using (var txn = iModel.BeginTransaction("Insert copy"))
                    {
                        var mappings = new XbimInstanceHandleMap(model, iModel);
                        foreach (var root in roots)
                        {
                            iModel.InsertCopy(root, mappings, Filter, false, true);
                        }
                        txn.Commit();
                        using (var fileStream = new StreamWriter("..\\..\\SampleHouseSemantic4.ifc"))
                        {
                            iModel.SaveAsStep21(fileStream);
                        }
                    }
                }
            }
        }
示例#2
0
        public void CopyWallsOver()
        {
            const string original = "4walls1floorSite.ifc";
            const string inserted = "..\\..\\Inserted.ifc";

            PropertyTranformDelegate semanticFilter = (property, parentObject) =>
            {
                //leave out geometry and placement
                if ((property.PropertyInfo.Name == "Representation" || property.PropertyInfo.Name == "ObjectPlacement") &&
                    parentObject is IfcProduct)
                {
                    return(null);
                }

                //only bring over IsDefinedBy and IsTypedBy inverse relationships
                if (property.EntityAttribute.Order < 0 && !(
                        property.PropertyInfo.Name == "IsDefinedBy" ||
                        property.PropertyInfo.Name == "IsTypedBy"
                        ))
                {
                    return(null);
                }

                return(property.PropertyInfo.GetValue(parentObject, null));
            };

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                var errs = model.LoadStep21(original);
                Assert.AreEqual(0, errs);
                var wall = model.Instances.FirstOrDefault <IfcWall>();
                using (var iModel = new IO.Memory.MemoryModel(new EntityFactory()))
                {
                    using (var txn = iModel.BeginTransaction("Insert copy"))
                    {
                        var w = new Stopwatch();
                        w.Start();
                        iModel.InsertCopy(wall, new XbimInstanceHandleMap(model, iModel), null, true, true);
                        txn.Commit();
                        w.Stop();

                        var iWalls = iModel.Instances.OfType <IfcWall>().ToList();
                        Debug.WriteLine("Time to insert {0} walls (Overall {1} entities): {2}ms", iWalls.Count, iModel.Instances.Count, w.ElapsedMilliseconds);

                        Assert.IsTrue(iWalls.Count >= 1);
                        using (var fileStream = new StreamWriter(inserted))
                        {
                            iModel.SaveAsStep21(fileStream);
                        }
                    }
                }
            }

            CompareEntityLines(inserted, original);
        }
        public void ReadingOfNestedLists()
        {
            var model = new IO.Memory.MemoryModel(ef4);

            model.LoadStep21("IfcCartesianPointList3D.ifc");
            var pl = model.Instances.FirstOrDefault <IfcCartesianPointList3D>();

            Assert.IsNotNull(pl);
            Assert.AreEqual(3, pl.CoordList.Count);
            Assert.AreEqual(9, pl.CoordList.SelectMany(c => c).Count());

            //write new file
            using (var fileStream = new StreamWriter("..\\..\\SerializedNestedList.ifc"))
            {
                model.SaveAsStep21(fileStream);
            }
        }
示例#4
0
        public void SerializeDeserialize()
        {
            var model = CreateTestModel();

            using (var fileStream = new StreamWriter("RandomModel.cobie"))
            {
                model.SaveAsStep21(fileStream);
            }

            using (var fileStream = File.Create("RandomModel.cobieZip"))
            {
                model.SaveAsStep21Zip(fileStream);
            }

            var stepModel = new IO.Memory.MemoryModel(new EntityFactory());

            stepModel.LoadStep21("RandomModel.cobie");

            var zipModel = new IO.Memory.MemoryModel(new EntityFactory());

            zipModel.LoadZip(File.OpenRead("RandomModel.cobieZip"));

            Assert.AreEqual(model.Instances.Count, stepModel.Instances.Count);
            Assert.AreEqual(model.Instances.OfType <CobieAttribute>().Count(), stepModel.Instances.OfType <CobieAttribute>().Count());
            Assert.AreEqual(model.Instances.OfType <CobieComponent>().Count(), stepModel.Instances.OfType <CobieComponent>().Count());

            Assert.AreEqual(model.Instances.Count, zipModel.Instances.Count);
            Assert.AreEqual(model.Instances.OfType <CobieAttribute>().Count(), zipModel.Instances.OfType <CobieAttribute>().Count());
            Assert.AreEqual(model.Instances.OfType <CobieComponent>().Count(), zipModel.Instances.OfType <CobieComponent>().Count());

            //because save operation is deterministic both files should match
            var data1 = new StringWriter();

            model.SaveAsStep21(data1);

            var data2 = new StringWriter();

            stepModel.SaveAsStep21(data2);

            var str1 = data1.ToString();
            var str2 = data2.ToString();

            Assert.AreEqual(str1.Length, str2.Length);
            Assert.AreEqual(str1, str2);
        }
示例#5
0
        public void Ifc4InsertCopyTest()
        {
            using (var model = IfcStore.Open(@"Ifc4WithNestedLists.ifcZip"))
            {
                using (var iModel = new IO.Memory.MemoryModel(new Ifc4.EntityFactory()))
                {
                    using (var txn = iModel.BeginTransaction("Insert copy"))
                    {
                        var w = new Stopwatch();
                        w.Start();
                        iModel.InsertCopy(model.Instances[61828], new XbimInstanceHandleMap(model, iModel), null, true, true);
                        txn.Commit();
                        w.Stop();

                        // Debug.WriteLine("Time to insert {0} walls (Overall {1} entities): {2}ms", iWalls.Count, iModel.Instances.Count, w.ElapsedMilliseconds);

                        //Assert.IsTrue(iWalls.Count >= 1);
                    }
                    var tw = File.Create("Ifc4WithNestedListsExtract.ifc");
                    iModel.SaveAsStep21(tw);
                    tw.Close();
                }
            }
        }