Search in sources :

Example 21 with SerializerException

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;
}
Also used : IfcHeader(org.bimserver.models.store.IfcHeader) SerializerException(org.bimserver.plugins.serializers.SerializerException)

Example 22 with SerializerException

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;
}
Also used : HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) SerializerException(org.bimserver.plugins.serializers.SerializerException)

Example 23 with SerializerException

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();
    }
}
Also used : Path(java.nio.file.Path) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Example 24 with SerializerException

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GeometryData(org.bimserver.models.geometry.GeometryData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SerializerException(org.bimserver.plugins.serializers.SerializerException) ByteBuffer(java.nio.ByteBuffer)

Example 25 with SerializerException

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SerializerException(org.bimserver.plugins.serializers.SerializerException)

Aggregations

SerializerException (org.bimserver.plugins.serializers.SerializerException)26 IOException (java.io.IOException)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 UserException (org.bimserver.shared.exceptions.UserException)6 Serializer (org.bimserver.plugins.serializers.Serializer)5 FileNotFoundException (java.io.FileNotFoundException)4 ByteBuffer (java.nio.ByteBuffer)4 DataHandler (javax.activation.DataHandler)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)4 GeometryData (org.bimserver.models.geometry.GeometryData)4 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)4 SerializerPlugin (org.bimserver.plugins.serializers.SerializerPlugin)4 PluginException (org.bimserver.shared.exceptions.PluginException)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 DataSource (javax.activation.DataSource)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 IfcModelInterface (org.bimserver.emf.IfcModelInterface)3 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)3