Skip to content

Commit

Permalink
Functionality to open a model from a stream added
Browse files Browse the repository at this point in the history
Additional index properies added to make all inverse relationships indexed
InsertCopy of model changed to retain consistent entity labels from source to target model
  • Loading branch information
Steve Lockley committed Sep 9, 2015
1 parent d8c48c7 commit e6a03ee
Show file tree
Hide file tree
Showing 65 changed files with 5,983 additions and 280 deletions.
Binary file modified SharedFileVersionInfo.cs
Binary file not shown.
2 changes: 2 additions & 0 deletions Xbim.Common/XbimExtensions/Interfaces/IModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ public interface IModel
/// </summary>
object Tag { get; set; }
IGeometryManager GeometryManager { get; set; }

bool AutoAddOwnerHistory { get; }
}
}
88 changes: 88 additions & 0 deletions Xbim.Essentials.Tests/BasicModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xbim.IO;
using System.IO;
using Xbim.XbimExtensions.Interfaces;

namespace Xbim.Essentials.Tests
{
[TestClass]
[DeploymentItem(@"TestSourceFiles\")]
public class BasicModelTests
{
[TestMethod]
public void OpenIfcFile()
{
using (var model = new XbimModel())
{
model.CreateFrom("4walls1floorSite.ifc");
model.Close();
}

}

[TestMethod]
public void OpenIfcZipFile()
{
using (var model = new XbimModel())
{
model.CreateFrom("4walls1floorSite.ifczip");
model.Close();
}

}
[TestMethod]
public void OpenIfcXmlFile()
{
using (var model = new XbimModel())
{
model.CreateFrom("4walls1floorSite.ifcxml");
model.Close();
}

}
[TestMethod]
public void OpenIfcFileFromStream()
{
using (var fileStream = new FileStream("4walls1floorSite.ifc", FileMode.Open,FileAccess.Read))
{
using (var model = new XbimModel())
{
model.CreateFrom(fileStream, XbimStorageType.IFC, "4walls1floorSite.xbim",null,true);
model.Close();
}
fileStream.Close();
}

}

[TestMethod]
public void OpenIfcZipFileFromStream()
{
using (var fileStream = new FileStream("4walls1floorSite.ifczip", FileMode.Open, FileAccess.Read))
{
using (var model = new XbimModel())
{
model.CreateFrom(fileStream, XbimStorageType.IFC, "4walls1floorSite.xbim");
model.Close();
}
fileStream.Close();
}

}
[TestMethod]
public void OpenIfcXmlFileFromStream()
{
using (var fileStream = new FileStream("4walls1floorSite.ifcxml", FileMode.Open, FileAccess.Read))
{
using (var model = new XbimModel())
{
model.CreateFrom(fileStream, XbimStorageType.IFC, "4walls1floorSite.xbim");
model.Close();
}
fileStream.Close();
}

}
}
}
102 changes: 102 additions & 0 deletions Xbim.Essentials.Tests/ModelFilterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xbim.IO;
using Xbim.Ifc2x3.Kernel;
using Xbim.Ifc2x3.GeometryResource;
using System.IO;

namespace Xbim.Essentials.Tests
{
[TestClass]
[DeploymentItem(@"TestSourceFiles\")]
public class ModelFilterTest
{
[TestMethod]
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
}
}

[TestMethod]
public void ExtractIfcGeometryEntitiesTest()
{
using (var source = new XbimModel())
{
PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
{

if (typeof(IfcProduct).IsAssignableFrom(toCopy.GetType()))
{
if (prop.PropertyInfo.Name == "ObjectPlacement" || prop.PropertyInfo.Name == "Representation")
return null;
}
if(typeof(IfcTypeProduct).IsAssignableFrom(toCopy.GetType()))
{
if (prop.PropertyInfo.Name == "RepresentationMaps" )
return null;
}
return prop.PropertyInfo.GetValue(toCopy, null);//just pass through the value
};

//source.Open("BIM Logo-LetterM.xBIM");
//source.SaveAs("WithGeometry.ifc");
string modelName = @"4walls1floorSite";
string xbimModelName = Path.ChangeExtension(modelName,"xbim");

source.CreateFrom( Path.ChangeExtension(modelName,"ifc"), null, null, true);

using (var target = XbimModel.CreateModel(Path.ChangeExtension(modelName + "_NoGeom", "xbim")))
{
target.AutoAddOwnerHistory = false;
using (var txn = target.BeginTransaction())
{
var copied = new XbimInstanceHandleMap(source, target);

foreach (var item in source.Instances.OfType<IfcRoot>())
{
target.InsertCopy(item, copied, txn, propTransform, false);
}
txn.Commit();
}

target.SaveAs(Path.ChangeExtension(modelName + "_NoGeom", "ifc"));
target.Close();

}

source.Close();
// XbimModel.Compact(Path.ChangeExtension(modelName + "_NoGeom", "xbim"), Path.ChangeExtension(modelName + "_NoGeom_Compacted", "xbim"));
//the two files should be the same
}
}
}
}
Loading

0 comments on commit e6a03ee

Please sign in to comment.