diff --git a/src/org/ifcopenshell/ClientRunner.java b/src/org/ifcopenshell/ClientRunner.java
new file mode 100644
index 0000000..a3de060
--- /dev/null
+++ b/src/org/ifcopenshell/ClientRunner.java
@@ -0,0 +1,52 @@
+package org.ifcopenshell;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+import org.bimserver.plugins.renderengine.RenderEngineException;
+
+public class ClientRunner {
+
+ public static void main(String [] args)
+ {
+ IfcGeomServerClient client;
+
+ try {
+ client = new IfcGeomServerClient(args[0]);
+ } catch (RenderEngineException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ try {
+ client.loadModel(new FileInputStream(args[1]));
+ } catch (FileNotFoundException | RenderEngineException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ while (client.hasNext()) {
+ try {
+ IfcGeomServerClientEntity instance = client.getNext();
+ if (instance == null) {
+ System.out.println("Internal error");
+ return;
+ }
+ System.out.println(String.format("%s %s", instance.getType(), instance.getGuid()));
+ float area = instance.getExtendedDataAsFloat("TOTAL_SURFACE_AREA");
+ float volume = instance.getExtendedDataAsFloat("TOTAL_SHAPE_VOLUME");
+ if (instance.getType().equals("IfcSpace")) {
+ float walkable = instance.getExtendedDataAsFloat("WALKABLE_SURFACE_AREA");
+ System.out.println(String.format("Volume: %.2f; Area: %.2f; Walkable %.2f", volume, area, walkable));
+ } else {
+ System.out.println(String.format("Volume: %.2f; Area: %.2f", volume, area));
+ }
+ } catch (RenderEngineException e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+ System.exit(0);
+ }
+
+}
\ No newline at end of file
diff --git a/src/org/ifcopenshell/IfcGeomServerClient.java b/src/org/ifcopenshell/IfcGeomServerClient.java
index 484809c..3047957 100644
--- a/src/org/ifcopenshell/IfcGeomServerClient.java
+++ b/src/org/ifcopenshell/IfcGeomServerClient.java
@@ -1,5 +1,6 @@
package org.ifcopenshell;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -52,7 +53,25 @@ public IfcGeomServerClient(String executableFilename) throws RenderEngineExcepti
throw new RenderEngineException(e);
}
}
-
+
+ public void setDeflection(double deflection) throws RenderEngineException {
+ try {
+ Deflection d = new Deflection(deflection);
+ d.write(dos);
+ } catch (IOException e) {
+ throw new RenderEngineException(e);
+ }
+ }
+
+ public void setLayerSetSlicing(boolean enable) throws RenderEngineException {
+ try {
+ Setting s = new Setting(Setting.SettingId.APPLY_LAYERSETS, enable);
+ s.write(dos);
+ } catch (IOException e) {
+ throw new RenderEngineException(e);
+ }
+ }
+
public void loadModel(InputStream inputStream) throws RenderEngineException {
IfcModel m = new IfcModel(inputStream);
try {
@@ -63,18 +82,20 @@ public void loadModel(InputStream inputStream) throws RenderEngineException {
}
}
- private static final int HELLO = 0xff00;
- private static final int IFC_MODEL = HELLO + 1;
- private static final int GET = IFC_MODEL + 1;
- private static final int ENTITY = GET + 1;
- private static final int MORE = ENTITY + 1;
- private static final int NEXT = MORE + 1;
- private static final int BYE = NEXT + 1;
- private static final int GET_LOG = BYE + 1;
- private static final int LOG = GET_LOG + 1;
-
- private static String VERSION = "IfcOpenShell-0.5.0-dev";
-
+ private static final int HELLO = 0xff00;
+ private static final int IFC_MODEL = HELLO + 1;
+ private static final int GET = IFC_MODEL + 1;
+ private static final int ENTITY = GET + 1;
+ private static final int MORE = ENTITY + 1;
+ private static final int NEXT = MORE + 1;
+ private static final int BYE = NEXT + 1;
+ private static final int GET_LOG = BYE + 1;
+ private static final int LOG = GET_LOG + 1;
+ private static final int DEFLECTION = LOG + 1;
+ private static final int SETTING = DEFLECTION + 1;
+
+ private static String VERSION = "IfcOpenShell-0.5.0-dev-2";
+
abstract static class Command {
abstract void read_contents(LittleEndianDataInputStream s) throws IOException;
abstract void write_contents(LittleEndianDataOutputStream s) throws IOException;
@@ -279,7 +300,11 @@ static class Entity extends Command {
}
@Override
- void read_contents(LittleEndianDataInputStream s) throws IOException {
+ void read_contents(LittleEndianDataInputStream s0) throws IOException {
+ byte[] message = new byte[len];
+ s0.readFully(message, 0, len);
+ ByteArrayInputStream bis = new ByteArrayInputStream(message);
+ LittleEndianDataInputStream s = new LittleEndianDataInputStream(bis);
entity = new IfcGeomServerClientEntity(
s.readInt(),
readString(s),
@@ -292,10 +317,20 @@ void read_contents(LittleEndianDataInputStream s) throws IOException {
readFloatArray(s),
readIntArray(s),
readFloatArray(s),
- readIntArray(s)
+ readIntArray(s),
+ readRemainder(bis)
);
}
+ private String readRemainder(ByteArrayInputStream bis) {
+ if (bis.available() == 0) {
+ return null;
+ }
+ byte[] remainder = new byte[bis.available()];
+ bis.read(remainder, 0, remainder.length);
+ return new String(remainder);
+ }
+
public IfcGeomServerClientEntity getEntity() {
return entity;
}
@@ -341,7 +376,58 @@ public String getString() {
return string;
}
}
-
+
+ static class Deflection extends Command {
+ private double deflection;
+
+ Deflection(double deflection) {
+ super(DEFLECTION);
+ this.deflection = deflection;
+ }
+
+ @Override
+ void read_contents(LittleEndianDataInputStream s) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ void write_contents(LittleEndianDataOutputStream s) throws IOException {
+ s.writeDouble(deflection);
+ }
+ }
+
+ static class Setting extends Command {
+ private int id;
+ private int value;
+
+ public enum SettingId {
+ APPLY_LAYERSETS (1 << 17);
+
+ private final int id;
+ SettingId(int id) {
+ this.id = id;
+ }
+ private int getId() { return id; }
+ }
+
+ Setting(SettingId i, boolean b) {
+ super(SETTING);
+ this.id = i.getId();
+ this.value = b ? 1 : 0;
+ }
+
+ @Override
+ void read_contents(LittleEndianDataInputStream s) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ void write_contents(LittleEndianDataOutputStream s) throws IOException {
+ s.writeInt(id);
+ s.writeInt(value);
+ }
+ }
+
private void terminate() throws RenderEngineException {
hasMore = false;
if (process == null) return;
@@ -402,7 +488,8 @@ private void terminate() throws RenderEngineException {
private void askForMore() throws IOException {
hasMore = false;
- if (dis.readInt() != MORE) {
+ int readInt = dis.readInt();
+ if (readInt != MORE) {
LOGGER.error("Invalid command sequence encountered");
throw new IOException();
}
diff --git a/src/org/ifcopenshell/IfcGeomServerClientEntity.java b/src/org/ifcopenshell/IfcGeomServerClientEntity.java
index f5bed74..fe4cea9 100644
--- a/src/org/ifcopenshell/IfcGeomServerClientEntity.java
+++ b/src/org/ifcopenshell/IfcGeomServerClientEntity.java
@@ -1,6 +1,11 @@
package org.ifcopenshell;
import org.bimserver.geometry.Matrix;
+import org.bimserver.plugins.renderengine.RenderEngineException;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
public class IfcGeomServerClientEntity {
private int id;
@@ -15,11 +20,12 @@ public class IfcGeomServerClientEntity {
private int[] indices;
private float[] colors;
private int[] materialIndices;
+ private JsonObject extendedData;
public IfcGeomServerClientEntity(int id, String guid, String name,
String type, int parentId, double[] matrix, int repId,
float[] positions, float[] normals, int[] indices, float[] colors,
- int[] materialIndices) {
+ int[] materialIndices, String messageRemainder) {
super();
this.id = id;
this.guid = guid;
@@ -33,6 +39,12 @@ public IfcGeomServerClientEntity(int id, String guid, String name,
this.indices = indices;
this.colors = colors;
this.materialIndices = materialIndices;
+
+ this.extendedData = null;
+ if (messageRemainder != null && messageRemainder.length() > 0) {
+ // un-pad string
+ this.extendedData = new JsonParser().parse(messageRemainder.trim()).getAsJsonObject();
+ }
}
public int getId() {
@@ -90,4 +102,15 @@ public int getNumberOfPrimitives() {
public int getNumberOfColors() {
return colors.length / 4;
}
+
+ public float getExtendedDataAsFloat(String name) throws RenderEngineException {
+ if (this.extendedData == null) {
+ throw new RenderEngineException("No extended data for Entity " + this.guid);
+ }
+ JsonElement elem = extendedData.get(name);
+ if (elem == null) {
+ throw new RenderEngineException("No extended data entry found for " + name);
+ }
+ return elem.getAsFloat();
+ }
}
diff --git a/src/org/ifcopenshell/IfcOpenShellEngine.java b/src/org/ifcopenshell/IfcOpenShellEngine.java
index 064c33e..a91978f 100644
--- a/src/org/ifcopenshell/IfcOpenShellEngine.java
+++ b/src/org/ifcopenshell/IfcOpenShellEngine.java
@@ -40,9 +40,11 @@ public class IfcOpenShellEngine implements RenderEngine {
public static final Boolean debug = false;
private String filename;
private IfcGeomServerClient client;
+ private Double maxDeflection;
- public IfcOpenShellEngine(String fn) throws IOException {
+ public IfcOpenShellEngine(String fn, Double maxDeflection) throws IOException {
filename = fn;
+ this.maxDeflection = maxDeflection;
}
@Override
@@ -50,6 +52,7 @@ public void init() throws RenderEngineException {
LOGGER.debug("Initializing IfcOpenShell engine");
client = new IfcGeomServerClient(filename);
+ client.setDeflection(maxDeflection);
}
@Override
@@ -68,7 +71,8 @@ public RenderEngineModel openModel(InputStream inputStream) throws RenderEngineE
client = new IfcGeomServerClient(filename);
}
try {
- return new IfcOpenShellModel(client, filename, inputStream);
+ IfcOpenShellModel model = new IfcOpenShellModel(client, filename, inputStream);
+ return model;
} catch (IOException e) {
throw new RenderEngineException(e);
}
diff --git a/src/org/ifcopenshell/IfcOpenShellEnginePlugin.java b/src/org/ifcopenshell/IfcOpenShellEnginePlugin.java
index caf9deb..9106b3c 100644
--- a/src/org/ifcopenshell/IfcOpenShellEnginePlugin.java
+++ b/src/org/ifcopenshell/IfcOpenShellEnginePlugin.java
@@ -36,7 +36,12 @@
import java.util.Collections;
import org.apache.commons.io.IOUtils;
+import org.bimserver.models.store.DoubleType;
import org.bimserver.models.store.ObjectDefinition;
+import org.bimserver.models.store.ParameterDefinition;
+import org.bimserver.models.store.PrimitiveDefinition;
+import org.bimserver.models.store.PrimitiveEnum;
+import org.bimserver.models.store.StoreFactory;
import org.bimserver.plugins.PluginConfiguration;
import org.bimserver.plugins.PluginContext;
import org.bimserver.plugins.renderengine.RenderEngine;
@@ -48,6 +53,8 @@
import org.slf4j.LoggerFactory;
public class IfcOpenShellEnginePlugin implements RenderEnginePlugin {
+ private static final String MAX_DEFLECTION = "maxdeflection";
+
private static final Logger LOGGER = LoggerFactory.getLogger(IfcOpenShellEnginePlugin.class);
private boolean initialized = false;
@@ -56,7 +63,7 @@ public class IfcOpenShellEnginePlugin implements RenderEnginePlugin {
@Override
public RenderEngine createRenderEngine(PluginConfiguration pluginConfiguration, String schema) throws RenderEngineException {
try {
- return new IfcOpenShellEngine(filename);
+ return new IfcOpenShellEngine(filename, pluginConfiguration.getDouble(MAX_DEFLECTION));
} catch (IOException e) {
throw new RenderEngineException(e);
}
@@ -125,6 +132,22 @@ public void init(PluginContext pluginContext) throws PluginException {
@Override
public ObjectDefinition getSettingsDefinition() {
- return null;
+ ObjectDefinition objectDefinition = StoreFactory.eINSTANCE.createObjectDefinition();
+
+ DoubleType defaultDeflection = StoreFactory.eINSTANCE.createDoubleType();
+ defaultDeflection.setValue(1);
+
+ PrimitiveDefinition doubleType = StoreFactory.eINSTANCE.createPrimitiveDefinition();
+ doubleType.setType(PrimitiveEnum.DOUBLE);
+
+ ParameterDefinition deflectionParameter = StoreFactory.eINSTANCE.createParameterDefinition();
+ deflectionParameter.setName("Max deflection (mm)");
+ deflectionParameter.setIdentifier(MAX_DEFLECTION);
+ deflectionParameter.setDefaultValue(defaultDeflection);
+ deflectionParameter.setDescription("Maximum deflection in millimeters");
+ deflectionParameter.setType(doubleType);
+ objectDefinition.getParameters().add(deflectionParameter);
+
+ return objectDefinition;
}
}
\ No newline at end of file
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy