use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class TestReadProperties method test.
@Test
public void test() {
try {
// New client
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Create a project
SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Look for a deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
// Checkin file
bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
// Refresh project
project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
// Load model without lazy loading (complete model at once)
IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
// Iterate over all projects, there should be 1
for (IfcProject ifcProject : model.getAllWithSubTypes(IfcProject.class)) {
for (IfcRelDefines ifcRelDefines : ifcProject.getIsDefinedBy()) {
if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
IfcPropertySetDefinition relatingPropertyDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
if (relatingPropertyDefinition instanceof IfcPropertySet) {
IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
if (ifcProperty instanceof IfcPropertySingleValue) {
IfcPropertySingleValue ifcPropertySingleValue = (IfcPropertySingleValue) ifcProperty;
IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
String stringValue = "";
if (nominalValue instanceof IfcLabel) {
stringValue = ((IfcLabel) nominalValue).getWrappedValue();
} else if (nominalValue instanceof IfcIdentifier) {
stringValue = ((IfcIdentifier) nominalValue).getWrappedValue();
} else if (nominalValue instanceof IfcAreaMeasure) {
stringValue = "" + ((IfcAreaMeasure) nominalValue).getWrappedValue();
}
if (ifcPropertySingleValue.getName().equals("ConstructionMode")) {
if (!stringValue.equals("Massivbau")) {
fail("Massivbau expected");
}
} else if (ifcPropertySingleValue.getName().equals("BuildingPermitId")) {
if (!stringValue.equals("4711")) {
fail("4711 expected");
}
} else if (ifcPropertySingleValue.getName().equals("GrossAreaPlanned")) {
if (stringValue == null || !stringValue.equals("1000.0")) {
fail("1000. expected");
}
}
System.out.println(ifcPropertySingleValue.getName() + ": " + stringValue);
}
}
}
}
}
}
} catch (Throwable e) {
if (!(e instanceof AssertionError)) {
fail(e.getMessage());
}
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class TestReadTrim method test.
@Test
public void test() {
try {
// Create a new BimServerClient with authentication
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Create a new project
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Get the appropriate deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
// Checkin the file
bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/TST.ifc"));
// Refresh project info
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
for (IfcTrimmedCurve ifcTrimmedCurve : model.getAllWithSubTypes(IfcTrimmedCurve.class)) {
for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim1()) {
if (ifcTrimmingSelect instanceof IfcParameterValue) {
IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
System.out.println("Trim1: " + ifcParameterValue.getWrappedValue());
}
}
for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim2()) {
if (ifcTrimmingSelect instanceof IfcParameterValue) {
IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
System.out.println("Trim2: " + ifcParameterValue.getWrappedValue());
}
}
}
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof AssertionError) {
throw (AssertionError) e;
}
fail(e.getMessage());
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class TestRemoveReferenceList method test.
// This test makes no sense, since getContainedInStructure is a Set (unordered)
@Test
public void test() {
try {
// Create a new BimServerClient with authentication
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Get the service interface
bimServerClient.getSettingsInterface().setGenerateGeometryOnCheckin(false);
// Create a new project
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
IfcModelInterface model = bimServerClient.newModel(newProject, true);
IfcFurnishingElement furnishingElement = model.create(IfcFurnishingElement.class);
furnishingElement.setName("Furnishing 1");
IfcRelContainedInSpatialStructure link1 = model.create(IfcRelContainedInSpatialStructure.class);
link1.setName("link1");
IfcRelContainedInSpatialStructure link2 = model.create(IfcRelContainedInSpatialStructure.class);
link2.setName("link2");
IfcRelContainedInSpatialStructure link3 = model.create(IfcRelContainedInSpatialStructure.class);
link3.setName("link3");
link1.getRelatedElements().add(furnishingElement);
link2.getRelatedElements().add(furnishingElement);
link3.getRelatedElements().add(furnishingElement);
model.commit("initial");
// refresh
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
bimServerClient.download(newProject.getLastRevisionId(), bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc").getOid(), Paths.get("testX.ifc"));
model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
if (ifcFurnishingElement.getContainedInStructure().size() != 3) {
fail("Size should be 3, is " + ifcFurnishingElement.getContainedInStructure().size());
}
// Remove the middle one
IfcRelContainedInSpatialStructure middleOne = null;
for (IfcRelContainedInSpatialStructure rel : ifcFurnishingElement.getContainedInStructure()) {
if (rel.getName().equals("link2")) {
middleOne = rel;
break;
}
}
ifcFurnishingElement.getContainedInStructure().remove(middleOne);
}
model.commit("removed middle link");
// refresh
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
assertTrue("Size should be 2, is " + ifcFurnishingElement.getContainedInStructure().size(), ifcFurnishingElement.getContainedInStructure().size() == 2);
assertEquals("link", "link1", ifcFurnishingElement.getContainedInStructure().get(0).getName());
assertEquals("link", "link3", ifcFurnishingElement.getContainedInStructure().get(1).getName());
}
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof AssertionError) {
throw (AssertionError) e;
}
fail(e.getMessage());
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class Visualise method main.
public static void main(String[] args) {
PluginManager pluginManager;
try {
pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
DeserializerPlugin deserializerPlugin = pluginManager.requireDeserializer("application/ifc");
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface model1 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
IfcModelInterface model1b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
IfcModelInterface model2 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
IfcModelInterface model2b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
model1.setObjectOids();
model1b.setObjectOids();
model2.setObjectOids();
model2b.setObjectOids();
model1.indexGuids();
model2.indexGuids();
model2.fixOids(new IncrementingOidProvider(model1.getHighestOid() + 1));
IfcModel merged = new RevisionMerger(model1, model2).merge();
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration());
serializer.init(merged, null, false);
SerializerUtils.writeToFile(serializer, Paths.get("merged.ifc"));
new Visualise().start(model1b, "Model 1");
new Visualise().start(model2b, "Model 2");
new Visualise().start(merged, "Merged");
} catch (PluginException e1) {
e1.printStackTrace();
} catch (SerializerException e) {
e.printStackTrace();
} catch (DeserializeException e) {
e.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.
the class GuidHighlighterTester method readModel.
public IfcModelInterface readModel(Path file) {
PluginManager pluginManager;
try {
pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
try {
IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, file);
return model;
} catch (Exception e) {
e.printStackTrace();
}
} catch (PluginException e1) {
e1.printStackTrace();
}
return null;
}
Aggregations