-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/opensourceBIM/IfcPlugins/issues/8
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |