コード例 #1
0
        public void CopyAllEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {              
                    var value = prop.PropertyInfo.GetValue(toCopy, null);
                    return value;
                };



                source.Open("BIM Logo-LetterM.xBIM");
                source.SaveAs("WithGeometry.ifc");
                using (var target = XbimModel.CreateTemporaryModel())
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances)
                        {
                            target.InsertCopy(item, copied, txn, propTransform);
                        }
                        txn.Commit();
                    }
                    target.SaveAs("WithoutGeometry.ifc");
                }
                source.Close();
                //the two files should be the same
            }
        }
コード例 #2
0
        public void CopyAllEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {
                    var value = prop.PropertyInfo.GetValue(toCopy, null);
                    return(value);
                };



                source.Open("BIM Logo-LetterM.xBIM");
                source.SaveAs("WithGeometry.ifc");
                using (var target = XbimModel.CreateTemporaryModel())
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances)
                        {
                            target.InsertCopy(item, copied, txn, propTransform);
                        }
                        txn.Commit();
                    }
                    target.SaveAs("WithoutGeometry.ifc");
                }
                source.Close();
                //the two files should be the same
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bangush/xBim-Toolkit
        //sample to show how to create a model from scratch

        static void Main(string[] args)
        {
            Logger.Debug("Creating Model...");
            XbimModel model = CreateModel("NewModel");

            if (model != null)
            {
                using (XbimReadWriteTransaction txn = model.BeginTransaction()) //start a readwrite transaction
                {
                    try
                    {
                        IfcProject project = model.Instances.New <IfcProject>(); //Project Created

                        txn.Commit();                                            //commit the changes if nothing went wrong
                    }
                    catch (Exception e)
                    {
                        Logger.DebugFormat("Error {0}\nRolling back changes.....", e.Message);
                    }
                }
                model.SaveAs("NewModel.ifc", XbimStorageType.IFC); //export as an Ifc File
                model.Close();                                     //close the model and release all resources and handles
            }

            Logger.Debug("Model Created Ended...");
            Console.ReadLine();
            // CreateProject
        }
コード例 #4
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall
        /// </summary>
        /// <param name="args"></param>
        public void Run()
        {
            //first create and initialise a model called Hello Wall
            Console.WriteLine("Initialising the IFC Project....");
            XbimModel model = CreateandInitModel("HelloWall");

            if (model != null)
            {
                IfcBuilding building = CreateBuilding(model, "Default Building", 2000);


                IfcWallStandardCase wall = CreateWall(model, 4000, 300, 2400);
                if (wall != null)
                {
                    AddPropertiesToWall(model, wall);
                }
                using (XbimReadWriteTransaction txn = model.BeginTransaction("Add Wall"))
                {
                    building.AddElement(wall);
                    txn.Commit();
                }

                if (wall != null)
                {
                    try
                    {
                        Console.WriteLine("Standard Wall successfully created....");
                        //write the Ifc File
                        model.SaveAs("HelloWall.ifc", XbimStorageType.IFC);
                        Console.WriteLine("HelloWall.ifc has been successfully written");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to save HelloWall.ifc");
                        Console.WriteLine(e.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Failed to initialise the model");
            }

            Console.WriteLine("Press any key to exit....");
            Console.ReadKey();
        }
コード例 #5
0
ファイル: XbimModelTest.cs プロジェクト: bnaand/xBim-Toolkit
        private static string CreateIfcXmlFile(string sourceFilePath, string targetPath = null)
        {
            string ext = Path.GetExtension(sourceFilePath);

                if (ext.ToLower() == ".ifc")
                {
                    //string ifcFilePath = Path.GetDirectoryName(sourceFilePath);
                    //string xbimFileName = ifcFilePath + "\\Temp\\" + Path.GetRandomFileName() + ".xbim";
                    //XbimFileModelServer modelServer = new XbimFileModelServer();
                    //modelServer.ImportIfc(sourceFilePath, xbimFileName);
                    //modelServer.Close();
                    //modelServer.Dispose();

                    //// now use the xbim file to create ifcXml file
                    //string ifcXmlFileName = ifcFilePath + "\\Temp\\" + Path.GetRandomFileName() + ".ifcxml";
                    //modelServer = new XbimFileModelServer(xbimFileName, FileAccess.ReadWrite);
                    //modelServer.Export(XbimStorageType.IFCXML, ifcXmlFileName);
                    //modelServer.Close();
                    //modelServer.Dispose();

                    //return ifcXmlFileName;
                }
                else if (ext.ToLower() == ".xbim")
                {
                    string xbimFilePath = Path.GetDirectoryName(sourceFilePath);
                    string ifcXmlFileName = CreateTempFile(xbimFilePath, ".ifcxml");
                    if (targetPath != null)
                        ifcXmlFileName = targetPath;
                    using (XbimModel modelServer = new XbimModel())
                    {
                        modelServer.Open(sourceFilePath);
                        modelServer.SaveAs(ifcXmlFileName, XbimStorageType.IFCXML);
                        modelServer.Close();
                    }
                    return ifcXmlFileName;
                }
                return "";
        }
コード例 #6
0
ファイル: XbimModelTest.cs プロジェクト: bnaand/xBim-Toolkit
        private static string CreateIfcFile(string sourceFilePath, string targetPath = null)
        {
            string ext = Path.GetExtension(sourceFilePath);

                if (ext.ToLower() == ".ifcxml" || ext.ToLower() == ".xml")
                {
                    string ifcFilePath = Path.GetDirectoryName(sourceFilePath);
                    string ifcFileName = CreateTempFile(ifcFilePath, ".ifc");
                    string xbimFileName = CreateTempFile(ifcFilePath, ".xbim");

                    // convert xml to xbim first
                    using (XbimModel modelServer = new XbimModel())
                    {
                        modelServer.CreateFrom(sourceFilePath, xbimFileName);
                        modelServer.Open(xbimFileName);
                        modelServer.SaveAs(ifcFileName,XbimStorageType.IFC);
                        modelServer.Close();
                    }
                    return ifcFileName;
                }
                else if (ext.ToLower() == ".xbim")
                {
                    string xbimFilePath = Path.GetDirectoryName(sourceFilePath);
                    string ifcFileName = CreateTempFile(xbimFilePath, ".ifc");
                    if (targetPath != null)
                        ifcFileName = targetPath;
                    using (XbimModel modelServer = new XbimModel())
                    {
                        modelServer.Open(sourceFilePath);
                        modelServer.SaveAs(ifcFileName, XbimStorageType.IFC);
                        modelServer.Close();
                    }
                    return ifcFileName;
                }
                return "";
        }
コード例 #7
0
        public static string GenerateIFC(HndzFrameSingleBay3D frame3D)
        {
            // create project
            HndzProject project = new HndzProject();

            project.Name                   = "Handaz Building";
            project.Description            = "Handaz Building Description";
            project.GlobalCoordinateSystem = HndzWCS.Egypt_Red_Belt;
            project.Owner                  = new Person("HANDAZ", "HANDAZ", "HANDAZ", "HANDAZ", "HANDAZ", "HANDAZ", "HANDAZ");

            //test stories
            HndzBuilding bui    = new HndzBuilding(project);
            HndzStorey   storey = new HndzStorey(bui, 0);


            if (frame3D == null)
            {
                frame3D = new HndzFrameSingleBay3D(24000, 6000, 20000, 6000, 2000, HndzLocationEnum.Cairo,
                                                   HndzRoofSlopeEnum.From1To10, HndzRoofAccessibilityEnum.Inaccessible, HndzBuildingEnclosingEnum.PartiallyEnclosed, HndzImportanceFactorEnum.II);
            }
            if (frame3D.BuildingStorey == null)
            {
                frame3D.BuildingStorey = storey;
            }
            XbimModel   model    = CreateandInitModel(frame3D.BuildingStorey.Building.Project);
            IfcBuilding building = CreateBuilding(model, frame3D.BuildingStorey.Building);

            List <IfcProduct> tt = new List <IfcProduct>();

            foreach (HndzFrameSingleBay2D frame2D in frame3D.Frames2D)
            {
                tt.Add(CreateColumn(model, frame2D.RightColumn));
                tt.Add(CreateColumn(model, frame2D.LeftColumn));
                tt.Add(CreateBeam(model, frame2D.RightBeam));
                tt.Add(CreateBeam(model, frame2D.LeftBeam));
            }
            foreach (HndzPurlin purlin in frame3D.Purlins)
            {
                tt.Add(CreateBeam(model, purlin));
            }

            List <List <IfcProduct> > temp = new List <List <IfcProduct> >();

            temp.Add(tt);

            CreateStorey(model, building, 4000, temp);
            string fileName = "Project" + frame3D.BuildingStorey.Building.Project.GlobalId;

            string filePath = IFCFileResources.wexbimPath + fileName;

            try
            {
                model.SaveAs(filePath, XbimStorageType.IFC);
                //model.SaveAs(filePath, XbimStorageType.XBIM);
                CreateWexBimFromIfc(model, filePath);
            }
            catch (Exception ex)
            {
            }
            return(fileName);
        }
コード例 #8
0
        public void TestDocExtraction()
        {
            var ifcFile = "Clinic-Handover-v12.ifc";
            var xbimFile = Path.ChangeExtension(ifcFile, "xbim");
            using (var _model = new XbimModel())
            {
                _model.CreateFrom(ifcFile, xbimFile, null, true);
                var ifcRelAssociatesDocuments = _model.Instances.OfType<IfcRelAssociatesDocument>();

                var dups = ifcRelAssociatesDocuments.GroupBy(d => d.RelatingDocument).SelectMany(grp => grp.Skip(1));
                Dictionary<IfcDocumentSelect, List<IfcRoot>> docToObjs = null;
                if (dups.Any())
                {
                    var dupsMerge = dups.GroupBy(d => d.RelatingDocument).Select(p => new { x = p.Key, y = p.SelectMany(c => c.RelatedObjects) });
                    //remove the duplicates and convert to dictionary
                    docToObjs = ifcRelAssociatesDocuments.Except(dups).ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects.ToList());

                    //add the duplicate doc referenced object lists to the original doc
                    foreach (var item in dupsMerge)
                    {
                        docToObjs[item.x] = docToObjs[item.x].Union(item.y).ToList();
                    }
                }
                else
                {
                    //no duplicates, so just convert to dictionary
                    docToObjs = ifcRelAssociatesDocuments.ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects.ToList());
                }

                //Lets set up some children documents
                using (var txn = _model.BeginTransaction("Add Documents"))
                {
                    foreach (var item in docToObjs)
                    {
                        var doc1 = item.Key as IfcDocumentInformation;
                        if (doc1 != null)
                        {
                            var docRelChild1 = _model.Instances.New<IfcDocumentInformationRelationship>();
                            docRelChild1.RelatingDocument = doc1;
                            //add child docs
                            var childDocA = CreateDocInfo(_model, "ChildDoc1a", @"c:\TestDir\Dir1");
                            var childDocB = CreateDocInfo(_model, "ChildDoc1b", @"c:\TestDir\Dir1");
                            var childDocC = CreateDocInfo(_model, "ChildDoc1c", @"c:\TestDir\Dir1");
                            docRelChild1.RelatedDocuments.Add(childDocA);
                            docRelChild1.RelatedDocuments.Add(childDocB);
                            docRelChild1.RelatedDocuments.Add(childDocC);

                            //add another layer
                            var docRelChild2 = _model.Instances.New<IfcDocumentInformationRelationship>();
                            docRelChild2.RelatingDocument = childDocA;
                            var childDoc2D = CreateDocInfo(_model, "ChildDoc2d", @"c:\TestDir\Dir1\Dir2");
                            var childDoc2E = CreateDocInfo(_model, "ChildDoc2e", @"c:\TestDir\Dir1\Dir2");
                            docRelChild2.RelatedDocuments.Add(childDoc2D);
                            docRelChild2.RelatedDocuments.Add(childDoc2E);

                            //add another layer
                            var docRelChild3 = _model.Instances.New<IfcDocumentInformationRelationship>();
                            docRelChild3.RelatingDocument = childDoc2D;
                            var childDoc3F = CreateDocInfo(_model, "ChildDoc3f", @"c:\TestDir\Dir1\Dir2\Dir3");
                            docRelChild3.RelatedDocuments.Add(childDoc3F);

                        }
                    }

                    var orphanDocA = CreateDocInfo(_model, "orphanDocA", @"c:");
                    

                    var orphanDocB = _model.Instances.New<IfcDocumentReference>();
                    orphanDocB.Name = "orphanDocB";
                    orphanDocB.Location = @"x:";
                    txn.Commit();

                    _model.SaveAs("Clinic-Handover_ChildDocs.ifc", Xbim.XbimExtensions.Interfaces.XbimStorageType.IFC);
                }


                //Get all documents information objects held in model
                var docAllInfos = _model.Instances.OfType<IfcDocumentInformation>();
                //Get the child document relationships
                var childDocRels = _model.Instances.OfType<IfcDocumentInformationRelationship>();



                //get the already attached to entity documents 
                var docInfosAttached = docToObjs.Select(Dictionary => Dictionary.Key).OfType<IfcDocumentInformation>();
                
                //see if we have any documents not attached to IfcRoot objects, but could be attached as children documents to a parent document
                var docInfosNotAttached = docAllInfos.Except(docInfosAttached);

                List<IfcDocumentInformation> docChildren = docInfosAttached.ToList(); //first check on docs attached to IfcRoot Objects
                int idx = 0;
                do
                {
                    //get the relationships that are attached to the docs already associated with an IfcRoot object on first pass, then associated with all children, drilling down until nothing found
                    docChildren = childDocRels.Where(docRel => docChildren.Contains(docRel.RelatingDocument)).SelectMany(docRel => docRel.RelatedDocuments).ToList(); //docs that are children to attached entity docs, drilling down
                    docInfosNotAttached = docInfosNotAttached.Except(docChildren); //attached by association to the root parent document, so remove from none attached document list


                } while (docChildren.Any() && (++idx < 100)); //assume that docs are not embedded deeper than 100

                Assert.IsTrue(docInfosNotAttached.Count() == 1);


                //get all the doc reference objects held in the model
                var docAllRefs = _model.Instances.OfType<IfcDocumentReference>();
                //get all attached document references
                var docRefsAttached = docToObjs.Select(Dictionary => Dictionary.Key).OfType<IfcDocumentReference>();
                //checked on direct attached to object document references
                var docRefsNotAttached = docAllRefs.Except(docRefsAttached).ToList();
                
                //Check for document references held in the IfcDocumentInformation objects
                var docRefsAttachedDocInfo = docAllInfos.Where(docInfo => docInfo.DocumentReferences != null).SelectMany(docInfo => docInfo.DocumentReferences);
                //remove from Not Attached list
                docRefsNotAttached = docRefsNotAttached.Except(docRefsAttachedDocInfo).ToList();

                Assert.IsTrue(docRefsNotAttached.Count() == 1);

                //reverse lookup to entity to list of documents
                var newDic = docToObjs
                                .SelectMany(pair => pair.Value
                                .Select(val => new { Key = val, Value = pair.Key }))
                                .GroupBy(item => item.Key)
                                .ToLookup(gr => gr.Key, gr => gr.Select(item => item.Value));

                foreach (var group in newDic)
                {
                    foreach (var item in group)
                    {
                        Assert.IsTrue(item.Count() > 0);
                        //foreach (var doc in item)
                        //{
                        //    if (doc is IfcDocumentInformation)
                        //    {
                        //        Debug.WriteLine("Doc {0}", ((IfcDocumentInformation)doc).Name);
                        //    }
                        //    else
                        //    {
                        //        Debug.WriteLine("Doc {0}", ((IfcDocumentReference)doc).Name);
                        //    }
                            
                        //} 
                    }
                }
                    
            }
        }
コード例 #9
0
        public void TestDocExtraction()
        {
            var ifcFile  = "Clinic-Handover-v12.ifc";
            var xbimFile = Path.ChangeExtension(ifcFile, "xbim");

            using (var _model = new XbimModel())
            {
                _model.CreateFrom(ifcFile, xbimFile, null, true);
                var ifcRelAssociatesDocuments = _model.Instances.OfType <IfcRelAssociatesDocument>();

                var dups = ifcRelAssociatesDocuments.GroupBy(d => d.RelatingDocument).SelectMany(grp => grp.Skip(1));
                Dictionary <IfcDocumentSelect, List <IfcRoot> > docToObjs = null;
                if (dups.Any())
                {
                    var dupsMerge = dups.GroupBy(d => d.RelatingDocument).Select(p => new { x = p.Key, y = p.SelectMany(c => c.RelatedObjects) });
                    //remove the duplicates and convert to dictionary
                    docToObjs = ifcRelAssociatesDocuments.Except(dups).ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects.ToList());

                    //add the duplicate doc referenced object lists to the original doc
                    foreach (var item in dupsMerge)
                    {
                        docToObjs[item.x] = docToObjs[item.x].Union(item.y).ToList();
                    }
                }
                else
                {
                    //no duplicates, so just convert to dictionary
                    docToObjs = ifcRelAssociatesDocuments.ToDictionary(p => p.RelatingDocument, p => p.RelatedObjects.ToList());
                }

                //Lets set up some children documents
                using (var txn = _model.BeginTransaction("Add Documents"))
                {
                    foreach (var item in docToObjs)
                    {
                        var doc1 = item.Key as IfcDocumentInformation;
                        if (doc1 != null)
                        {
                            var docRelChild1 = _model.Instances.New <IfcDocumentInformationRelationship>();
                            docRelChild1.RelatingDocument = doc1;
                            //add child docs
                            var childDocA = CreateDocInfo(_model, "ChildDoc1a", @"c:\TestDir\Dir1");
                            var childDocB = CreateDocInfo(_model, "ChildDoc1b", @"c:\TestDir\Dir1");
                            var childDocC = CreateDocInfo(_model, "ChildDoc1c", @"c:\TestDir\Dir1");
                            docRelChild1.RelatedDocuments.Add(childDocA);
                            docRelChild1.RelatedDocuments.Add(childDocB);
                            docRelChild1.RelatedDocuments.Add(childDocC);

                            //add another layer
                            var docRelChild2 = _model.Instances.New <IfcDocumentInformationRelationship>();
                            docRelChild2.RelatingDocument = childDocA;
                            var childDoc2D = CreateDocInfo(_model, "ChildDoc2d", @"c:\TestDir\Dir1\Dir2");
                            var childDoc2E = CreateDocInfo(_model, "ChildDoc2e", @"c:\TestDir\Dir1\Dir2");
                            docRelChild2.RelatedDocuments.Add(childDoc2D);
                            docRelChild2.RelatedDocuments.Add(childDoc2E);

                            //add another layer
                            var docRelChild3 = _model.Instances.New <IfcDocumentInformationRelationship>();
                            docRelChild3.RelatingDocument = childDoc2D;
                            var childDoc3F = CreateDocInfo(_model, "ChildDoc3f", @"c:\TestDir\Dir1\Dir2\Dir3");
                            docRelChild3.RelatedDocuments.Add(childDoc3F);
                        }
                    }

                    var orphanDocA = CreateDocInfo(_model, "orphanDocA", @"c:");


                    var orphanDocB = _model.Instances.New <IfcDocumentReference>();
                    orphanDocB.Name     = "orphanDocB";
                    orphanDocB.Location = @"x:";
                    txn.Commit();

                    _model.SaveAs("Clinic-Handover_ChildDocs.ifc", Xbim.XbimExtensions.Interfaces.XbimStorageType.IFC);
                }


                //Get all documents information objects held in model
                var docAllInfos = _model.Instances.OfType <IfcDocumentInformation>();
                //Get the child document relationships
                var childDocRels = _model.Instances.OfType <IfcDocumentInformationRelationship>();



                //get the already attached to entity documents
                var docInfosAttached = docToObjs.Select(Dictionary => Dictionary.Key).OfType <IfcDocumentInformation>();

                //see if we have any documents not attached to IfcRoot objects, but could be attached as children documents to a parent document
                var docInfosNotAttached = docAllInfos.Except(docInfosAttached);

                List <IfcDocumentInformation> docChildren = docInfosAttached.ToList(); //first check on docs attached to IfcRoot Objects
                int idx = 0;
                do
                {
                    //get the relationships that are attached to the docs already associated with an IfcRoot object on first pass, then associated with all children, drilling down until nothing found
                    docChildren         = childDocRels.Where(docRel => docChildren.Contains(docRel.RelatingDocument)).SelectMany(docRel => docRel.RelatedDocuments).ToList(); //docs that are children to attached entity docs, drilling down
                    docInfosNotAttached = docInfosNotAttached.Except(docChildren);                                                                                            //attached by association to the root parent document, so remove from none attached document list
                } while (docChildren.Any() && (++idx < 100));                                                                                                                 //assume that docs are not embedded deeper than 100

                Assert.IsTrue(docInfosNotAttached.Count() == 1);


                //get all the doc reference objects held in the model
                var docAllRefs = _model.Instances.OfType <IfcDocumentReference>();
                //get all attached document references
                var docRefsAttached = docToObjs.Select(Dictionary => Dictionary.Key).OfType <IfcDocumentReference>();
                //checked on direct attached to object document references
                var docRefsNotAttached = docAllRefs.Except(docRefsAttached).ToList();

                //Check for document references held in the IfcDocumentInformation objects
                var docRefsAttachedDocInfo = docAllInfos.Where(docInfo => docInfo.DocumentReferences != null).SelectMany(docInfo => docInfo.DocumentReferences);
                //remove from Not Attached list
                docRefsNotAttached = docRefsNotAttached.Except(docRefsAttachedDocInfo).ToList();

                Assert.IsTrue(docRefsNotAttached.Count() == 1);

                //reverse lookup to entity to list of documents
                var newDic = docToObjs
                             .SelectMany(pair => pair.Value
                                         .Select(val => new { Key = val, Value = pair.Key }))
                             .GroupBy(item => item.Key)
                             .ToLookup(gr => gr.Key, gr => gr.Select(item => item.Value));

                foreach (var group in newDic)
                {
                    foreach (var item in group)
                    {
                        Assert.IsTrue(item.Count() > 0);
                        //foreach (var doc in item)
                        //{
                        //    if (doc is IfcDocumentInformation)
                        //    {
                        //        Debug.WriteLine("Doc {0}", ((IfcDocumentInformation)doc).Name);
                        //    }
                        //    else
                        //    {
                        //        Debug.WriteLine("Doc {0}", ((IfcDocumentReference)doc).Name);
                        //    }

                        //}
                    }
                }
            }
        }