use of org.bimserver.plugins.serializers.SerializerException in project BIMserver by opensourceBIM.
the class SharedJsonSerializer method write.
public boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
this.outputStream = outputStream;
try {
if (mode == Mode.HEADER) {
print("{");
IfcHeader ifcHeader = model.getModelMetaData().getIfcHeader();
if (ifcHeader != null) {
print("\"header\":");
writeObject(ifcHeader);
print("\n,");
}
print("\"objects\":[");
mode = Mode.BODY;
iterator = model.iterator();
return true;
} else if (mode == Mode.BODY) {
if (iterator.hasNext()) {
IdEObject object = iterator.next();
if (object.getOid() == -1) {
throw new SerializerException("Object cannot have oid -1 " + object.eClass().getName());
}
if (object.eClass().getEAnnotation("hidden") == null || includeHidden) {
if (!firstObject) {
print(",");
} else {
firstObject = false;
}
writeObject(object);
}
return true;
} else {
print("]");
print("}");
mode = Mode.FOOTER;
return true;
}
} else if (mode == Mode.FOOTER) {
mode = Mode.DONE;
return false;
}
} catch (Throwable e) {
throw new SerializerException(e);
}
return false;
}
use of org.bimserver.plugins.serializers.SerializerException in project BIMserver by opensourceBIM.
the class SharedJsonStreamingSerializer method write.
public boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
this.outputStream = outputStream;
try {
if (mode == Mode.HEADER) {
print("{");
if (ifcHeader != null) {
print("\"header\":");
// writeObject(ifcHeader);
print("\n,");
}
print("\"objects\":[");
mode = Mode.BODY;
return true;
} else if (mode == Mode.BODY) {
HashMapVirtualObject object = objectProvider.next();
if (object != null) {
if (object.getOid() == -1) {
throw new SerializerException("Object cannot have oid -1 " + object.eClass().getName());
}
if (object.eClass().getEAnnotation("hidden") == null || includeHidden) {
if (!firstObject) {
print(",");
} else {
firstObject = false;
}
writeObject(object);
}
return true;
} else {
print("]");
print("}");
mode = Mode.FOOTER;
return true;
}
} else if (mode == Mode.FOOTER) {
mode = Mode.DONE;
return false;
}
} catch (Throwable e) {
throw new SerializerException(e);
}
return false;
}
use of org.bimserver.plugins.serializers.SerializerException in project BIMserver by opensourceBIM.
the class ExtractFurniture method main.
public static void main(String[] args) {
try {
Path home = Paths.get("home");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
Deserializer deserializer = deserializerPlugin.createDeserializer(null);
MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
PackageMetaData packageMetaData = metaDataManager.getPackageMetaData("ifc2x3tc1");
deserializer.init(packageMetaData);
IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/ADT-FZK-Haus-2005-2006.ifc"));
model.fixOids(new IncrementingOidProvider());
IfcFurnishingElement picknick = (IfcFurnishingElement) model.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
IfcModelInterface newModel = new BasicIfcModel(packageMetaData, null);
ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), newModel);
modelHelper.copy(picknick, false);
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(null);
serializer.init(newModel, null, true);
SerializerUtils.writeToFile(serializer, Paths.get("test.ifc"));
} catch (PluginException e) {
e.printStackTrace();
} catch (DeserializeException e) {
e.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (SerializerException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.plugins.serializers.SerializerException in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer method addVerticesAccessor.
private String addVerticesAccessor(IfcProduct ifcProduct, String bufferViewName, int startPosition, int count) throws SerializerException {
if (count <= 0) {
throw new SerializerException("Count <= 0");
}
String accessorName = "accessor_vertex_" + (accessorCounter++);
GeometryData data = ifcProduct.getGeometry().getData();
ByteBuffer verticesBuffer = ByteBuffer.wrap(data.getVertices());
ObjectNode accessor = OBJECT_MAPPER.createObjectNode();
accessor.put("bufferView", bufferViewName);
accessor.put("byteOffset", startPosition);
accessor.put("byteStride", 12);
accessor.put("componentType", FLOAT);
accessor.put("count", count);
accessor.put("type", "VEC3");
verticesBuffer.order(ByteOrder.LITTLE_ENDIAN);
double[] min = { Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE };
double[] max = { -Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE };
for (int i = 0; i < verticesBuffer.capacity(); i += 3) {
for (int j = 0; j < 3; j++) {
double val = verticesBuffer.get(i + j);
if (val > max[j]) {
max[j] = val;
}
if (val < min[j]) {
min[j] = val;
}
}
}
ArrayNode minNode = OBJECT_MAPPER.createArrayNode();
minNode.add(min[0]);
minNode.add(min[1]);
minNode.add(min[2]);
ArrayNode maxNode = OBJECT_MAPPER.createArrayNode();
maxNode.add(max[0]);
maxNode.add(max[1]);
maxNode.add(max[2]);
accessor.set("min", minNode);
accessor.set("max", maxNode);
accessors.set(accessorName, accessor);
return accessorName;
}
use of org.bimserver.plugins.serializers.SerializerException in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer method addIndicesAccessor.
private String addIndicesAccessor(IfcProduct ifcProduct, String bufferViewName, int offsetBytes, int count) throws SerializerException {
if (count <= 0) {
throw new SerializerException(count + " <= 0");
}
String accessorName = "accessor_index_" + (accessorCounter++);
ObjectNode accessor = OBJECT_MAPPER.createObjectNode();
accessor.put("bufferView", bufferViewName);
accessor.put("byteOffset", offsetBytes);
accessor.put("byteStride", 0);
accessor.put("componentType", UNSIGNED_SHORT);
accessor.put("count", count);
accessor.put("type", "SCALAR");
accessors.set(accessorName, accessor);
return accessorName;
}
Aggregations