public void OpenIfcFile() { using (var model = new XbimModel()) { model.CreateFrom("4walls1floorSite.ifc"); model.Close(); } }
/// <summary> /// Constructor /// </summary> public COBieXBimSerialiser(string fileName, ReportProgressDelegate progressHandler) { var fileNameDB = Path.ChangeExtension(fileName, ".xBIM"); XBimContext = new COBieXBimContext(XbimModel.CreateModel(fileNameDB), progressHandler) { IsMerge = false }; FileName = fileName; MergeGeometryOnly = true; }
/// <summary> /// Constructor /// </summary> /// <param name="fileName">.xBIM file name and path</param> public COBieXBimSerialiser(string fileName) { var fileNameDB = Path.ChangeExtension(fileName, ".xBIM"); XBimContext = new COBieXBimContext(XbimModel.CreateModel(fileNameDB)) { IsMerge = false }; FileName = fileName; MergeGeometryOnly = true; }
private IfcDocumentInformation CreateDocInfo(XbimModel model, string name, string location) { var docinfo = model.Instances.New <IfcDocumentInformation>(); docinfo.Name = name; var docRef = model.Instances.New <IfcDocumentReference>(); docRef.Location = location; docRef.Name = "Ref" + name + ".txt"; docinfo.DocumentReferences.Add(docRef); return(docinfo); }
public void OpenIfcXmlFileFromStream() { using (var fileStream = new FileStream("4walls1floorSite.ifcxml", FileMode.Open, FileAccess.Read)) { using (var model = new XbimModel()) { model.CreateFrom(fileStream, fileStream.Length, IfcStorageType.IfcXml, "4walls1floorSite.xbim"); model.Close(); } fileStream.Close(); } }
public void OpenIfcXmlFile() { int percent = 0; ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { percent = percentProgress; }; using (var model = new XbimModel()) { model.CreateFrom("4walls1floorSite.ifcxml", null, progDelegate); model.Close(); Assert.IsTrue(percent == 100); } }
public void CanUpgradeDbStucture() { using (var m = new Xbim.Ifc2x3.IO.XbimModel()) { m.Open(@"Persistency\Monolith_v10.xBIM", XbimDBAccess.Exclusive); Assert.AreEqual(1, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v10 should be 1"); var updated = m.EnsureGeometryTables(); Assert.AreEqual(updated, true, "Should complete returning true"); m.DeleteGeometryCache(); Assert.AreEqual(0, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v10 should be 0 after removing it."); m.Close(); } }
public void OpenIfcZipFile() { int percent = 0; ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { percent = percentProgress; }; using (var model = new XbimModel()) { var fileName = Guid.NewGuid() + ".xbim"; model.CreateFrom("TestZip.ifczip", fileName, progDelegate); model.Close(); Console.WriteLine(percent); Assert.IsTrue(percent == 100); } }
public void FileVersionIsCorrect() { var m = new Xbim.Ifc2x3.IO.XbimModel(); m.Open("Monolith-NoGeomTables.xBIM", XbimDBAccess.ReadWrite); Assert.AreEqual(0, m.GeometrySupportLevel, "GeometrySupportLevel should be 0"); m.Close(); m.Open("Monolith_Nogeom_Version1Schema.xBIM"); Assert.AreEqual(0, m.GeometrySupportLevel, "GeometrySupportLevel should be 0"); m.Close(); m.Open("Monolith_v10.xBIM"); Assert.AreEqual(1, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v10 should be 1"); m.Close(); m.Open("Monolith_v20.xBIM"); Assert.AreEqual(2, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v20 should be 2"); m.Close(); }
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); } } CreateDocInfo(_model, "orphanDocA", @"c:"); var orphanDocB = _model.Instances.New <IfcDocumentReference>(); orphanDocB.Name = "orphanDocB"; orphanDocB.Location = @"x:"; txn.Commit(); _model.SaveAs("Clinic-Handover_ChildDocs.ifc", IfcStorageType.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); // } //} } } } }