Ejemplo n.º 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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SampleHouseXmlSerialization()
        {
            var          w       = new Stopwatch();
            const string outPath = "..\\..\\SampleHouse4.xml";

            using (var model = new IO.Memory.MemoryModel(ef4))
            {
                w.Start();
                model.LoadStep21("SampleHouse4.ifc");
                w.Stop();
                Console.WriteLine("{0}ms to read STEP.", w.ElapsedMilliseconds);
                var instCount = model.Instances.Count;

                w.Restart();
                WriteXml(model, outPath);
                w.Stop();
                Console.WriteLine("{0}ms to write XML.", w.ElapsedMilliseconds);

                w.Restart();
                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);
                w.Stop();
                Console.WriteLine("{0}ms to validate XML.", w.ElapsedMilliseconds);

                using (var model2 = new IO.Memory.MemoryModel(ef4))
                {
                    w.Restart();
                    model2.LoadXml(outPath);
                    w.Stop();
                    Console.WriteLine("{0}ms to read XML.", w.ElapsedMilliseconds);

                    var instances  = model.Instances as IEntityCollection;
                    var instances2 = model2.Instances as IEntityCollection;
                    if (instances == null || instances2 == null)
                    {
                        throw new Exception();
                    }

                    var roots1 = model.Instances.OfType <IfcRoot>();
                    var roots2 = model2.Instances.OfType <IfcRoot>().ToList();
                    foreach (var root in roots1.Where(root => roots2.All(r => r.GlobalId != root.GlobalId)))
                    {
                        Console.WriteLine("Missing root element: {0} ({1})", root.GlobalId, root.GetType().Name);
                    }

                    foreach (var expressType in model2.Metadata.Types().Where(et => typeof(IPersistEntity).IsAssignableFrom(et.Type)))
                    {
                        var count1 = instances.OfType(expressType.Name, true).Count();
                        var count2 = instances2.OfType(expressType.Name, true).Count();

                        if (count1 != count2)
                        {
                            Console.WriteLine("Different count of {0} {1}/{2}", expressType.Name, count1, count2);
                        }
                    }

                    Assert.IsTrue(instCount == model2.Instances.Count);
                }
            }
        }
Ejemplo n.º 3
0
 public void LowerCaseExponentTest()
 {
     using (var model = new IO.Memory.MemoryModel(ef2x3))
     {
         var errs = model.LoadStep21("TestFiles\\RealWithExponent.ifc");
         Assert.IsTrue(errs == 0);
         Assert.IsTrue(model.Instances.Count == 1);
     }
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void LoadIfc4Test()
        {
            using (var model = new IO.Memory.MemoryModel(ef4))
            {
                model.LoadStep21("SampleHouse4.ifc");
                var project = model.Instances.FirstOrDefault <IfcProject>();
                Assert.IsNotNull(project);
                Assert.IsNotNull(project.Name);

                var walls = model.Instances.OfType <IfcWall>();
                var doors = model.Instances.OfType <IfcDoor>();
                Assert.IsTrue(walls.Any());
                Assert.IsTrue(doors.Any());
            }
        }
        public void LogTest()
        {
            using (var model = new IO.Memory.MemoryModel(new EntityFactoryIfc2x3()))
            {
                model.LoadStep21("TestFiles\\4walls1floorSite.ifc");
                using (var txn = model.BeginTransaction("Log test"))
                {
                    using (var log = new TransactionLog(txn))
                    {
                        var wall = model.Instances.FirstOrDefault <IIfcWall>();
                        var name = wall.Name.ToString();
                        Assert.IsNotNull(wall);
                        Assert.IsFalse(log.Changes.Any());

                        wall.Name = "New name";
                        var changes = log.Changes.ToList();
                        Assert.IsTrue(changes.Count == 1);
                        var change = changes.FirstOrDefault();
                        Assert.IsNotNull(change);
                        Assert.IsTrue(change.ChangeType == ChangeType.Modified);
                        Assert.IsTrue(change.CurrentEntity != change.OriginalEntity);
                        var propChanges = change.ChangedProperties.ToList();
                        Assert.IsTrue(propChanges.Count == 1);
                        var pChange = propChanges.FirstOrDefault();
                        Assert.IsNotNull(pChange);
                        Assert.IsTrue(pChange.Name == "Name");
                        Assert.IsTrue(pChange.CurrentValue == "'New name'");
                        Assert.IsTrue(pChange.OriginalValue == "'" + name + "'");

                        model.Delete(wall);
                        Assert.IsTrue(change.ChangeType == ChangeType.Deleted);
                        Assert.IsTrue(!change.ChangedProperties.Any());
                        Assert.IsTrue(change.CurrentEntity == "");

                        wall   = model.Instances.New <IfcWall>();
                        change = log.Changes.FirstOrDefault(c => c.Entity.Equals(wall));
                        Assert.IsNotNull(change);

                        wall.Name           = "Some name";
                        wall.PredefinedType = IfcWallTypeEnum.STANDARD;
                        wall.GlobalId       = Guid.NewGuid().ToPart21();
                        Assert.IsTrue(change.ChangeType == ChangeType.New);
                        Assert.IsTrue(change.OriginalEntity == "");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void ScanningTheFile()
        {
            const string file = "TestFiles\\mapped-shape-with-transformation.ifc";

            using (var stream = File.OpenRead(file))
            {
                var s = new Scanner(stream);
                int t;
                do
                {
                    t = s.yylex();
                    var v = s.yytext;
                    Console.WriteLine(@"{0}: {1}", (Tokens)t, v);
                } while (t != (int)Tokens.EOF);
            }

            using (var model = new IO.Memory.MemoryModel(new EntityFactoryIfc4()))
            {
                var errs = model.LoadStep21(file);
                Assert.AreEqual(0, errs);
            }
        }
        public void CompleteProductInsert()
        {
            const string original = "TestFiles\\4walls1floorSite.ifc";

            using (var model = new IO.Memory.MemoryModel(ef2x3))
            {
                var errs = model.LoadStep21(original);
                Assert.AreEqual(0, errs);
                using (model.BeginEntityCaching())
                    using (model.BeginInverseCaching())
                    {
                        var products = model.Instances.OfType <IfcProduct>();
                        using (var iModel = new IO.Memory.MemoryModel(ef2x3))
                        {
                            var map = new XbimInstanceHandleMap(model, iModel);
                            using (var txn = iModel.BeginTransaction("Insert copy"))
                            {
                                var w = new Stopwatch();
                                w.Start();
                                iModel.InsertCopy(products, true, false, map);
                                txn.Commit();
                                w.Stop();

                                var copies = Path.ChangeExtension(original, ".copy.ifc");
                                using (var f = File.Create(copies))
                                {
                                    iModel.SaveAsIfc(f);
                                    f.Close();
                                }
                            }

                            // use all caching we can for this
                            using (iModel.BeginEntityCaching())
                                using (iModel.BeginInverseCaching())
                                {
                                    // number of products should be the same
                                    var origProdCount = model.Instances.CountOf <IfcProduct>();
                                    var prodCount     = iModel.Instances.CountOf <IfcProduct>();
                                    Assert.AreEqual(origProdCount, prodCount);

                                    // number of geometry representations should be the same
                                    var origRepCount = model.Instances.CountOf <IfcProductRepresentation>();
                                    var repCount     = model.Instances.CountOf <IfcProductRepresentation>();
                                    Assert.AreEqual(origRepCount, repCount);

                                    // number of geometry representations should be the same
                                    var origRepItemCount = model.Instances.CountOf <IfcRepresentationItem>();
                                    var repItemCount     = model.Instances.CountOf <IfcRepresentationItem>();
                                    Assert.AreEqual(origRepItemCount, repItemCount);

                                    // number of representation items in every product should be the same
                                    foreach (var product in model.Instances.OfType <IfcProduct>())
                                    {
                                        var iProduct = map[new XbimInstanceHandle(product)].GetEntity() as IfcProduct;

                                        var count  = product.Representation?.Representations.SelectMany(r => r.Items).Count();
                                        var iCount = iProduct.Representation?.Representations.SelectMany(r => r.Items).Count();

                                        Assert.AreEqual(count, iCount);
                                    }
                                }
                        }
                    }
            }
        }