コード例 #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 Ifc4TableStorageTest()
        {
            const string file    = "..\\..\\SampleHouseFromIfc.xlsx";
            var          model   = IfcStore.Open("SampleHouse4.ifc");
            var          mapping = ModelMapping.Load(Properties.Resources.IFC4SampleMapping);

            mapping.Init(model.Metadata);

            var w = new Stopwatch();

            w.Start();
            var storage = new TableStore(model, mapping);

            storage.Store(file);
            w.Stop();
            //Debug.WriteLine(@"{0}ms to store the data as a table.", w.ElapsedMilliseconds);
            Trace.WriteLine(string.Format(@"{0}ms to store the data as a table.", w.ElapsedMilliseconds));

            var loaded = new IO.Memory.MemoryModel(new Ifc4.EntityFactory());

            using (var txn = loaded.BeginTransaction("Import from XLSX"))
            {
                storage = new TableStore(loaded, mapping);
                storage.LoadFrom(file);
                txn.Commit();
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
        public void ListSerializationTests()
        {
            const string outPath = "..\\..\\ListSerializationTest.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("site"))
                {
                    var building = model.Instances.New <IfcBuilding>(b =>
                    {
                        b.GlobalId = Guid.NewGuid();
                    });

                    var storey1 = model.Instances.New <IfcBuildingStorey>(s =>
                    {
                        s.GlobalId = Guid.NewGuid();
                    });
                    var storey2 = model.Instances.New <IfcBuildingStorey>(s =>
                    {
                        s.GlobalId = Guid.NewGuid();
                    });
                    var storey3 = model.Instances.New <IfcBuildingStorey>(s =>
                    {
                        s.GlobalId = Guid.NewGuid();
                    });

                    var rel = model.Instances.New <IfcRelAggregates>(r =>
                    {
                        r.GlobalId       = Guid.NewGuid();
                        r.RelatingObject = building;
                        r.RelatedObjects.Add(storey1);
                        r.RelatedObjects.Add(storey2);
                        r.RelatedObjects.Add(storey3);
                    });

                    txn.Commit();
                }

                WriteXml(model, outPath);

                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);

                using (var model2 = new IO.Memory.MemoryModel(new EntityFactory()))
                {
                    model2.LoadXml(outPath);
                    var b = model2.Instances.FirstOrDefault <IfcBuilding>();
                    Assert.IsNotNull(b);

                    var r = b.IsDecomposedBy.FirstOrDefault();
                    Assert.IsNotNull(r);

                    var storeys = r.RelatedObjects;
                    Assert.AreEqual(3, storeys.Count);
                }
            }
        }
コード例 #5
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);
     }
 }
コード例 #6
0
 public void Issue107OnMemoryModel()
 {
     // a merged PR on issue 107 makes the memory model more tolerant of bad files.
     // an equivalent test for esent is available
     using (var model = new IO.Memory.MemoryModel(ef2x3))
     {
         model.LoadZip("TestFiles\\Issue107.zip");
         //Assert.IsTrue(errCount <= 120);
     }
 }
コード例 #7
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);
        }
コード例 #8
0
        public void ReadIFC4Xml()
        {
            var path = @"ImplicitPropertyTyping.ifcxml";

            ValidateIfc4(path);

            using (var model = new IO.Memory.MemoryModel(ef4))
            {
                model.LoadXml(path);
            }
        }
コード例 #9
0
        public void CreationOfNestedListsFromAPI()
        {
            var model = new IO.Memory.MemoryModel(ef4);

            using (var txn = model.BeginTransaction("Test"))
            {
                var pl     = model.Instances.New <IfcCartesianPointList3D>();
                var nested = pl.CoordList.GetAt(0);
                Assert.IsNotNull(nested);
                txn.RollBack();
            }
        }
コード例 #10
0
        public void ReadIFC4Xml()
        {
            var path = @"TestFiles\ImplicitPropertyTyping.ifcxml";
            var errs = ValidateIfc4(path);

            // input file should be valid XML at first
            Assert.AreEqual(0, errs);

            using (var model = new IO.Memory.MemoryModel(ef4))
            {
                model.LoadXml(path);
            }
        }
コード例 #11
0
        public void SelectTypeSerialization()
        {
            const string outPath = "..\\..\\SelectTypeSerialization.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("Test"))
                {
                    //property has a select type Value
                    var pLabel = model.Instances.New <IfcPropertySingleValue>();
                    pLabel.Name         = "Label";
                    pLabel.NominalValue = new IfcLabel("Label value");

                    var pInteger = model.Instances.New <IfcPropertySingleValue>();
                    pInteger.Name         = "Integer";
                    pInteger.NominalValue = new IfcInteger(5);

                    var pDouble = model.Instances.New <IfcPropertySingleValue>();
                    pDouble.Name         = "Double";
                    pDouble.NominalValue = new IfcReal(5);

                    var pBoolean = model.Instances.New <IfcPropertySingleValue>();
                    pBoolean.Name         = "Boolean";
                    pBoolean.NominalValue = new IfcBoolean(true);

                    var pLogical = model.Instances.New <IfcPropertySingleValue>();
                    pLogical.Name         = "Logical";
                    pLogical.NominalValue = new IfcLogical((bool?)null);

                    WriteXml(model, outPath);
                    txn.Commit();

                    using (var model2 = new IO.Memory.MemoryModel(new EntityFactory()))
                    {
                        model2.LoadXml(outPath);
                        var props     = model2.Instances.OfType <IfcPropertySingleValue>().ToList();
                        var pLabel2   = props.FirstOrDefault(p => p.Name == "Label");
                        var pInteger2 = props.FirstOrDefault(p => p.Name == "Integer");
                        var pDouble2  = props.FirstOrDefault(p => p.Name == "Double");
                        var pBoolean2 = props.FirstOrDefault(p => p.Name == "Boolean");
                        var pLogical2 = props.FirstOrDefault(p => p.Name == "Logical");

                        Assert.IsTrue(pLabel.NominalValue.Equals(pLabel2.NominalValue));
                        Assert.IsTrue(pInteger.NominalValue.Equals(pInteger2.NominalValue));
                        Assert.IsTrue(pDouble.NominalValue.Equals(pDouble2.NominalValue));
                        Assert.IsTrue(pBoolean.NominalValue.Equals(pBoolean2.NominalValue));
                        Assert.IsTrue(pLogical.NominalValue.Equals(pLogical2.NominalValue));
                    }
                }
            }
        }
コード例 #12
0
        public void AttributesSerialization()
        {
            const string outPath = "..\\..\\StandaloneSite.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                IfcSite site;
                using (var txn = model.BeginTransaction("site"))
                {
                    site              = model.Instances.New <IfcSite>();
                    site.Name         = "Site name";
                    site.RefElevation = 100.0;
                    site.Description  = "Site description";
                    site.RefLatitude  = new List <long> {
                        1, 2, 3, 4
                    };
                    site.GlobalId = Guid.NewGuid();

                    var wall = model.Instances.New <IfcWall>();
                    wall.Name           = "Sample wall";
                    wall.GlobalId       = Guid.NewGuid();
                    wall.PredefinedType = IfcWallTypeEnum.PARTITIONING;

                    txn.Commit();
                }


                WriteXml(model, outPath);

                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);

                using (var model2 = new IO.Memory.MemoryModel(new EntityFactory()))
                {
                    model2.LoadXml(outPath);
                    var site2 = model2.Instances.FirstOrDefault <IfcSite>();
                    Assert.IsNotNull(site2);

                    var wall2 = model2.Instances.FirstOrDefault <IfcWall>();
                    Assert.IsNotNull(wall2);

                    Assert.IsTrue(site.Name == site2.Name);
                    Assert.IsTrue(site.RefElevation == site2.RefElevation);
                    Assert.IsTrue(site.Description == site2.Description);
                    Assert.IsTrue(site.RefLatitude == site2.RefLatitude);
                    Assert.IsTrue(site.GlobalId == site2.GlobalId);
                }
            }
        }
コード例 #13
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());
            }
        }
コード例 #14
0
        public void Ifc4HeaderSerialization()
        {
            const string outPath = "..\\..\\HeaderSampleIfc4.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                model.Header.FileName.Name = "Sample model";
                model.Header.FileName.AuthorName.Add("Martin");
                model.Header.FileName.AuthorizationMailingAddress.Add("*****@*****.**");
                model.Header.FileName.AuthorizationName = "Martin Cerny, xBIM Team";
                model.Header.FileName.Organization.Add("xBIM Team");
                model.Header.FileName.OriginatingSystem   = "xBIM Toolkit";
                model.Header.FileName.PreprocessorVersion = "4.0";
                model.Header.FileName.TimeStamp           = DateTime.Now.ToString("s");
                model.Header.FileDescription.Description.Add("xBIM Team Model View Definition");
                model.Header.FileDescription.ImplementationLevel = "1.0";

                using (var xml = XmlWriter.Create(outPath, new XmlWriterSettings {
                    Indent = true
                }))
                {
                    var writer = new XbimXmlWriter4(configuration.IFC4Add1);
                    writer.Write(model, xml);
                    xml.Close();
                }

                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);
            }

            //read it back and validate it is the same
            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                model.LoadXml(outPath);

                Assert.IsTrue(model.Header.FileName.Name == "Sample model");
                Assert.IsTrue(model.Header.FileName.OriginatingSystem == "xBIM Toolkit");
                Assert.IsTrue(model.Header.FileName.PreprocessorVersion == "4.0");
            }

            //check version info
            using (var file = File.OpenRead(outPath))
            {
                var header = XbimXmlReader4.ReadHeader(file);
                Assert.AreEqual("IFC4, IFC4Add1", header.SchemaVersion);
            }
        }
コード例 #15
0
        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 == "");
                    }
                }
            }
        }
コード例 #16
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);
            }
        }
コード例 #17
0
        private IO.Memory.MemoryModel CreateTestModel()
        {
            var model = new IO.Memory.MemoryModel(new EntityFactory());

            using (var txn = model.BeginTransaction("Model creation"))
            {
                var facility = model.Instances.New <CobieFacility>(f =>
                {
                    f.Name = "Testing facility";
                    f.Attributes.Add(model.Instances.New <CobieAttribute>(a =>
                    {
                        a.Name  = "Attribute A";
                        a.Value = new BooleanValue(true);
                    }));
                    f.Attributes.Add(model.Instances.New <CobieAttribute>(a =>
                    {
                        a.Name  = "Attribute B";
                        a.Value = new StringValue("Example value");
                    }));
                    f.Attributes.Add(model.Instances.New <CobieAttribute>(a =>
                    {
                        a.Name  = "Attribute C";
                        a.Value = (DateTimeValue)DateTime.Now;
                    }));

                    f.Created = model.Instances.New <CobieCreatedInfo>(ci =>
                    {
                        ci.CreatedOn = DateTime.Now;
                        ci.CreatedBy = model.Instances.New <CobieContact>(c =>
                        {
                            c.FamilyName = "Cerny";
                            c.GivenName  = "Martin";
                            c.Email      = "*****@*****.**";
                        });
                    });

                    GenerateAttributes(f, 8);
                });

                AddContacts(model);
                AddFloorsAndSpaces(facility);
                txn.Commit();
            }

            return(model);
        }
コード例 #18
0
        public void RectangularListSerialization()
        {
            const string outPath = "..\\..\\IfcCartesianPointList3D.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("Rect"))
                {
                    var pl = model.Instances.New <IfcCartesianPointList3D>();
                    var a1 = pl.CoordList.GetAt(0);
                    var a2 = pl.CoordList.GetAt(1);
                    var a3 = pl.CoordList.GetAt(2);

                    a1.Add(1.0);
                    a1.Add(2.0);
                    a1.Add(3.0);
                    a2.Add(4.0);
                    a2.Add(5.0);
                    a2.Add(6.0);
                    a3.Add(7.0);
                    a3.Add(8.0);
                    a3.Add(9.0);

                    txn.Commit();
                }


                WriteXml(model, outPath);
                var errs = ValidateIfc4(outPath);

                Assert.AreEqual(0, errs);

                var xmlString = File.ReadAllText(outPath);
                Assert.IsTrue(xmlString.Contains("CoordList=\"1 2 3 4 5 6 7 8 9\""));
            }

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                model.LoadXml(outPath);
                var list = model.Instances.FirstOrDefault <IfcCartesianPointList3D>();
                Assert.IsNotNull(list);

                Assert.AreEqual(3, list.CoordList.Count);
            }
        }
コード例 #19
0
        public void InMemoryGeometryStoreMultiThreadTest()
        {
            using (var model = new IO.Memory.MemoryModel(ef4))
            {
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    Parallel.For(0, 100, i =>
                    {
                        //ADD A GEOMETRY SHAPE
                        var geomData = new XbimShapeGeometry()
                        {
                            IfcShapeLabel  = 1,
                            Format         = XbimGeometryType.BoundingBox,
                            GeometryHash   = 0,
                            LOD            = XbimLOD.LOD100,
                            ReferenceCount = 1,
                            ShapeData      = "2123",
                            BoundingBox    = XbimRect3D.Empty
                        };
                        var shapeGeomLabel = txn.AddShapeGeometry(geomData);
                    });

                    Parallel.For(0, 100, i =>
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                    });

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
            }
        }
コード例 #20
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);
        }
コード例 #21
0
        public void NonRectangularListSerialization()
        {
            const string outPath = "..\\..\\IfcStructuralLoadConfiguration.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("Rect"))
                {
                    var slc = model.Instances.New <IfcStructuralLoadConfiguration>();
                    var a1  = slc.Locations.GetAt(0);
                    var a2  = slc.Locations.GetAt(1);
                    var a3  = slc.Locations.GetAt(2);

                    a1.Add(1.0);
                    a1.Add(2.0);
                    a2.Add(4.0);
                    a2.Add(5.0);
                    a3.Add(7.0);
                    a3.Add(8.0);

                    slc.Values.Add(model.Instances.New <IfcStructuralLoadLinearForce>());
                    slc.Values.Add(model.Instances.New <IfcStructuralLoadLinearForce>());
                    slc.Values.Add(model.Instances.New <IfcStructuralLoadLinearForce>());

                    txn.Commit();
                }


                WriteXml(model, outPath);
                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);

                var xmlString = File.ReadAllText(outPath);
                Assert.IsTrue(xmlString.Contains("pos=\"0 0\""));
                Assert.IsTrue(xmlString.Contains("pos=\"0 1\""));
                Assert.IsTrue(xmlString.Contains("pos=\"1 0\""));
                Assert.IsTrue(xmlString.Contains("pos=\"1 1\""));
                Assert.IsTrue(xmlString.Contains("pos=\"2 0\""));
                Assert.IsTrue(xmlString.Contains("pos=\"2 1\""));
            }
        }
コード例 #22
0
        public void CheckSchemaVersions()
        {
            #region Memory Models
            using (var model = new IO.Memory.MemoryModel(new Ifc2x3.EntityFactoryIfc2x3()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc2X3);
            }
            using (var model = new IO.Memory.MemoryModel(new Ifc4.EntityFactoryIfc4()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc4);
            }
            using (var model = new IO.Memory.MemoryModel(new Ifc4.EntityFactoryIfc4x1()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc4x1);
            }

            #endregion
            #region Esent Models
            using (var model = new IO.Esent.EsentModel(new Ifc2x3.EntityFactoryIfc2x3()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc2X3);
            }
            using (var model = new IO.Esent.EsentModel(new Ifc4.EntityFactoryIfc4()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc4);
            }
            using (var model = new IO.Esent.EsentModel(new Ifc4.EntityFactoryIfc4x1()))
            {
                var iModel = model as IModel;
                Assert.IsTrue(model.SchemaVersion == XbimSchemaVersion.Ifc4x1);
            }

            #endregion
        }
コード例 #23
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);
            }
        }
コード例 #24
0
        public void AttributeIndexGetSet()
        {
            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("Creation"))
                {
                    var component = model.Instances.New <CobieComponent>(c => c.Name = "Boiler");
                    var bCode     = component["BarCode"];
                    Assert.IsNull(bCode);

                    const int bc = 15789123;
                    component["BarCode"] = (IntegerValue)bc;
                    Assert.IsNotNull(component.Attributes.FirstOrDefault(a => a.Name == "BarCode"));

                    bCode = component["BarCode"];
                    Assert.IsNotNull(bCode);
                    Assert.IsTrue(bCode.Equals((IntegerValue)bc));

                    component["BarCode"] = (IntegerValue)5;
                    Assert.IsTrue(component["BarCode"].Equals((IntegerValue)5));

                    const string myPropName = "My property set.My property";
                    var          myProp     = component[myPropName];
                    Assert.IsNull(myProp);
                    component[myPropName] = (StringValue)"Testing value";
                    var myAttr =
                        component.Attributes.FirstOrDefault(
                            a => a.Name == "My property" && a.PropertySet.Name == "My property set");
                    Assert.IsNotNull(myAttr);

                    myProp = component[myPropName];
                    Assert.IsNotNull(myProp);
                    Assert.IsTrue(myProp.Equals((StringValue)"Testing value"));

                    txn.Commit();
                }
            }
        }
コード例 #25
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();
                }
            }
        }
コード例 #26
0
        public void Ifc4PSetsTest()
        {
            const string file  = "PSetsSample.xlsx";
            var          model = new IO.Memory.MemoryModel(new Ifc4.EntityFactory());

            using (var txn = model.BeginTransaction("Sample data"))
            {
                model.EntityNew += entity =>
                {
                    var root = entity as IfcRoot;
                    if (root != null)
                    {
                        root.GlobalId = Guid.NewGuid();
                    }
                };
                var slab = model.Instances.New <IfcSlab>(s => s.Name = "Tremendous slab");
                model.Instances.New <IfcRelDefinesByProperties>(r =>
                {
                    r.RelatedObjects.Add(slab);
                    r.RelatingPropertyDefinition = model.Instances.New <IfcPropertySet>(ps =>
                    {
                        ps.Name = "Slab properties A";
                        ps.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                        {
                            p.Name         = "Property AA";
                            p.NominalValue = new IfcLengthMeasure(5.5);
                        }));
                        ps.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                        {
                            p.Name         = "Property AB";
                            p.NominalValue = new IfcLogical(true);
                        }));
                    });
                });
                model.Instances.New <IfcRelDefinesByProperties>(r =>
                {
                    r.RelatedObjects.Add(slab);
                    r.RelatingPropertyDefinition = model.Instances.New <IfcPropertySet>(ps =>
                    {
                        ps.Name = "Slab properties B";
                        ps.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                        {
                            p.Name         = "Property BA";
                            p.NominalValue = new IfcInteger(5);
                        }));
                        ps.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                        {
                            p.Name         = "Property BB";
                            p.NominalValue = new IfcLabel("LabellebaL");
                        }));
                    });
                });
                txn.Commit();
            }


            var mapping = ModelMapping.Load(Properties.Resources.IFC4SampleMapping);

            mapping.Init(model.Metadata);

            var w = new Stopwatch();

            w.Start();
            var storage = new TableStore(model, mapping);

            storage.Store(file);
            w.Stop();
            //Debug.WriteLine(@"{0}ms to store the data as a table.", w.ElapsedMilliseconds);
            Trace.WriteLine(string.Format(@"{0}ms to store the data as a table.", w.ElapsedMilliseconds));

            var loaded = new IO.Memory.MemoryModel(new Ifc4.EntityFactory());

            using (var txn = loaded.BeginTransaction("Import from XLSX"))
            {
                storage = new TableStore(loaded, mapping);
                storage.LoadFrom(file);
                txn.Commit();
            }

            var sl = loaded.Instances.FirstOrDefault <IfcSlab>();

            Assert.IsNotNull(sl);

            var rels = sl.IsDefinedBy.ToList();

            Assert.AreEqual(2, rels.Count);

            foreach (var rel in rels)
            {
                var pSet = rel.RelatingPropertyDefinition as IfcPropertySet;
                Assert.IsNotNull(pSet);
                Assert.IsNotNull(pSet.Name);

                if (pSet.Name == "Slab properties A")
                {
                    var propA = pSet.HasProperties.OfType <IfcPropertySingleValue>().First(p => p.Name == "Property AA");
                    Assert.IsNotNull(propA);
                    Assert.IsNotNull(propA.NominalValue);
                    Assert.IsTrue(Math.Abs((IfcLengthMeasure)propA.NominalValue - 5.5) < 1e-9);
                    var propB = pSet.HasProperties.OfType <IfcPropertySingleValue>().First(p => p.Name == "Property AB");
                    Assert.IsNotNull(propB);
                    Assert.IsNotNull(propB.NominalValue);
                    Assert.IsTrue(((IfcLogical)propB.NominalValue).Equals((IfcLogical)true));
                }
                if (pSet.Name == "Slab properties B")
                {
                    var propA = pSet.HasProperties.OfType <IfcPropertySingleValue>().First(p => p.Name == "Property BA");
                    Assert.IsNotNull(propA);
                    Assert.IsNotNull(propA.NominalValue);
                    Assert.IsTrue(((IfcInteger)propA.NominalValue).Equals((IfcInteger)5));
                    var propB = pSet.HasProperties.OfType <IfcPropertySingleValue>().First(p => p.Name == "Property BB");
                    Assert.IsNotNull(propB);
                    Assert.IsNotNull(propB.NominalValue);
                    Assert.IsTrue(((IfcLabel)propB.NominalValue).Equals((IfcLabel)"LabellebaL"));
                }
            }
        }
コード例 #27
0
        public void PropertySetDefinitionSetSerialization()
        {
            const string outPath = "..\\..\\IfcPropertySetDefinitionSet.xml";

            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                using (var txn = model.BeginTransaction("IfcPropertySetDefinitionSet"))
                {
                    var pSet1 = model.Instances.New <IfcPropertySet>(p =>
                    {
                        p.Name     = "pSet_1";
                        p.GlobalId = Guid.NewGuid();
                        p.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(s => s.Name = "Property"));
                    });
                    var pSet2 = model.Instances.New <IfcPropertySet>(p =>
                    {
                        p.Name     = "pSet_2";
                        p.GlobalId = Guid.NewGuid();
                        p.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(s => s.Name = "Property"));
                    });
                    var pSet3 = model.Instances.New <IfcPropertySet>(p =>
                    {
                        p.Name     = "pSet_3";
                        p.GlobalId = Guid.NewGuid();
                        p.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(s => s.Name = "Property"));
                    });

                    var set = new IfcPropertySetDefinitionSet(new List <IfcPropertySetDefinition> {
                        pSet1, pSet2, pSet3
                    });
                    var wall = model.Instances.New <IfcWall>(w =>
                    {
                        w.Name     = "Sample wall";
                        w.GlobalId = Guid.NewGuid();
                    });

                    model.Instances.New <IfcRelDefinesByProperties>(r =>
                    {
                        r.RelatingPropertyDefinition = set;
                        r.RelatedObjects.Add(wall);
                        r.GlobalId = Guid.NewGuid();
                    });

                    txn.Commit();
                }


                WriteXml(model, outPath);
                var errs = ValidateIfc4(outPath);
                Assert.AreEqual(0, errs);

                WriteJSON(model, "..\\..\\properties.json");


                using (var model2 = new IO.Memory.MemoryModel(new EntityFactory()))
                {
                    model2.LoadXml(outPath);
                    var wall = model2.Instances.FirstOrDefault <IfcWall>();

                    Assert.IsNotNull(wall.IsDefinedBy.FirstOrDefault());
                    var pSetSet =
                        (IfcPropertySetDefinitionSet)wall.IsDefinedBy.FirstOrDefault().RelatingPropertyDefinition;
                    var vals = pSetSet.Value as List <IfcPropertySetDefinition>;
                    Assert.IsNotNull(vals);
                    Assert.IsTrue(vals.Count == 3);
                }
            }
        }
コード例 #28
0
        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);
                                    }
                                }
                        }
                    }
            }
        }