Skip to content

Commit

Permalink
https://github.com/opensourceBIM/IfcPlugins/issues/8
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Aug 25, 2017
1 parent 35a4d36 commit 846d1fc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion IfcPlugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<dependency>
<groupId>org.opensourcebim</groupId>
<artifactId>shared</artifactId>
<version>1.5.82-SNAPSHOT</version>
<version>1.5.86-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.bimserver.emf.IfcModelInterface;
import org.bimserver.plugins.PluginConfiguration;
import org.bimserver.plugins.PluginManagerInterface;
import org.bimserver.plugins.serializers.ProjectInfo;
import org.bimserver.plugins.serializers.SerializerException;

Expand Down
80 changes: 80 additions & 0 deletions IfcPlugins/test/org/bimserver/test/TestReadAddWrite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.bimserver.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;

import org.apache.commons.io.IOUtils;
import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.IfcModelInterfaceException;
import org.bimserver.emf.PackageMetaData;
import org.bimserver.emf.Schema;
import org.bimserver.ifc.step.deserializer.Ifc2x3tc1StepDeserializer;
import org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer;
import org.bimserver.models.ifc2x3tc1.Ifc2x3tc1Package;
import org.bimserver.models.ifc2x3tc1.IfcBuilding;
import org.bimserver.models.ifc2x3tc1.IfcElementQuantity;
import org.bimserver.models.ifc2x3tc1.IfcQuantityVolume;
import org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties;
import org.bimserver.plugins.PluginConfiguration;
import org.bimserver.plugins.deserializers.DeserializeException;
import org.bimserver.plugins.serializers.SerializerException;
import org.junit.Test;

public class TestReadAddWrite {
@Test
public void test() {
Ifc2x3tc1StepDeserializer deserializer = new Ifc2x3tc1StepDeserializer();
PackageMetaData packageMetaData = new PackageMetaData(Ifc2x3tc1Package.eINSTANCE, Schema.IFC2X3TC1, Paths.get("tmp"));
deserializer.init(packageMetaData);

try {
URL url = new URL("https://raw.githubusercontent.com/opensourceBIM/IFC-files/master/HHS%20Office/construction.ifc");
InputStream openStream = url.openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(openStream, baos);
IfcModelInterface model = deserializer.read(new ByteArrayInputStream(baos.toByteArray()), "", baos.size(), null);

// This is needed so we start with a clean slate of express id's
model.resetExpressIds();

// This is needed so we continue counting at highest already existing oid
model.fixOidCounter();

for (IfcBuilding building : model.getAllWithSubTypes(IfcBuilding.class)) {
try {
// Use createAndAdd to actually add the object to the model
IfcQuantityVolume g_volume = model.createAndAdd(IfcQuantityVolume.class);
g_volume.setName("Test Quantity");
g_volume.setVolumeValue(1000000000);

IfcElementQuantity el_gv = model.createAndAdd(IfcElementQuantity.class);
el_gv.getQuantities().add(g_volume);

IfcRelDefinesByProperties ifcRelDefinesByProperties1 = model.createAndAdd(IfcRelDefinesByProperties.class);
ifcRelDefinesByProperties1.setRelatingPropertyDefinition(el_gv);
ifcRelDefinesByProperties1.getRelatedObjects().add(building);
building.getIsDefinedBy().add(ifcRelDefinesByProperties1);
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
}
}

Ifc2x3tc1StepSerializer serializer = new Ifc2x3tc1StepSerializer(new PluginConfiguration());
serializer.init(model, null, true); // Put "true" as the last argument in order to generate new express id's
serializer.writeToFile(Paths.get("output.ifc"), null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DeserializeException e) {
e.printStackTrace();
} catch (SerializerException e) {
e.printStackTrace();
}
}
}

0 comments on commit 846d1fc

Please sign in to comment.