Search in sources :

Example 11 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class DatabaseSession method convertByteArrayToObject.

@SuppressWarnings({ "unused" })
private IdEObject convertByteArrayToObject(IdEObject idEObject, EClass originalQueryClass, EClass eClass, long oid, ByteBuffer buffer, IfcModelInterface model, int rid, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
    try {
        if (idEObject == null) {
            idEObject = createInternal(eClass, query);
            ((IdEObjectImpl) idEObject).setOid(oid);
            ((IdEObjectImpl) idEObject).setPid(query.getPid());
            if (rid == Integer.MAX_VALUE) {
                throw new BimserverDatabaseException("Database corrupt, rid cannot be " + Integer.MAX_VALUE);
            }
        }
        if (idEObject.eClass().getEAnnotation("wrapped") == null) {
            try {
                model.addAllowMultiModel(oid, idEObject);
            } catch (IfcModelInterfaceException e) {
                throw new BimserverDatabaseException(e);
            }
        }
        ((IdEObjectImpl) idEObject).setRid(rid);
        ((IdEObjectImpl) idEObject).useInverses(false);
        if (DEVELOPER_DEBUG && StorePackage.eINSTANCE == idEObject.eClass().getEPackage()) {
            LOGGER.info("Read: " + idEObject.eClass().getName() + " pid=" + query.getPid() + " oid=" + oid + " rid=" + rid);
        }
        ((IdEObjectImpl) idEObject).setLoadingState(State.LOADING);
        objectCache.put(oid, idEObject);
        int unsettedLength = model.getPackageMetaData().getUnsettedLength(eClass);
        byte[] unsetted = new byte[unsettedLength];
        buffer.get(unsetted);
        int fieldCounter = 0;
        for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
            try {
                if (model.getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
                    boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0;
                    if (isUnsetted) {
                        if (feature.isUnsettable()) {
                            idEObject.eUnset(feature);
                        } else if (feature.isMany()) {
                        // do nothing
                        } else if (feature.getDefaultValue() != null) {
                            idEObject.eSet(feature, feature.getDefaultValue());
                        }
                    } else {
                        if (!query.shouldFollowReference(originalQueryClass, eClass, feature)) {
                            // we have to do some reading to maintain a correct
                            // index
                            fakeRead(buffer, feature);
                        } else {
                            Object newValue = null;
                            if (feature.isMany()) {
                                newValue = readList(idEObject, originalQueryClass, buffer, model, query, todoList, feature);
                            } else {
                                if (feature.getEType() instanceof EEnum) {
                                    int enumOrdinal = buffer.getInt();
                                    if (enumOrdinal == -1) {
                                        newValue = null;
                                    } else {
                                        EClassifier eType = feature.getEType();
                                        EEnumLiteral enumLiteral = ((EEnumImpl) eType).getEEnumLiteral(enumOrdinal);
                                        if (enumLiteral != null) {
                                            newValue = enumLiteral.getInstance();
                                        }
                                    }
                                } else if (feature.getEType() instanceof EClass) {
                                    // EReference eReference = (EReference) feature;
                                    buffer.order(ByteOrder.LITTLE_ENDIAN);
                                    short cid = buffer.getShort();
                                    buffer.order(ByteOrder.BIG_ENDIAN);
                                    if (cid == -1) {
                                    // null, do nothing
                                    } else if (cid < 0) {
                                        // non minus one and negative cid means value is embedded in record
                                        EClass referenceClass = database.getEClassForCid((short) (-cid));
                                        if (feature.getEAnnotation("dbembed") != null) {
                                            newValue = readEmbeddedValue(feature, buffer, referenceClass, query);
                                        } else {
                                            newValue = readWrappedValue(feature, buffer, referenceClass, query);
                                        }
                                    } else if (cid > 0) {
                                        // positive cid means value is reference to other record
                                        EClass referenceClass = database.getEClassForCid(cid);
                                        if (referenceClass == null) {
                                            throw new BimserverDatabaseException("No eClass found for cid " + cid);
                                        }
                                        // readReference is going to read a long, which includes the 2 bytes for the cid
                                        buffer.position(buffer.position() - 2);
                                        newValue = readReference(originalQueryClass, buffer, model, idEObject, feature, referenceClass, query, todoList);
                                    // if (eReference.getEOpposite() != null &&
                                    // ((IdEObjectImpl)
                                    // newValue).isLoadedOrLoading()) {
                                    // newValue = null;
                                    // }
                                    }
                                } else if (feature.getEType() instanceof EDataType) {
                                    newValue = readPrimitiveValue(feature.getEType(), buffer, query);
                                }
                            }
                            if (newValue != null) {
                                idEObject.eSet(feature, newValue);
                            }
                        }
                    }
                    fieldCounter++;
                }
            } catch (StringIndexOutOfBoundsException e) {
                throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
            } catch (BufferUnderflowException e) {
                throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
            } catch (BufferOverflowException e) {
                throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
            }
        }
        ((IdEObjectImpl) idEObject).setLoaded();
        ((IdEObjectImpl) idEObject).useInverses(true);
        if (DEVELOPER_DEBUG && idEObject.getRid() > 100000 || idEObject.getRid() < -100000) {
            LOGGER.debug("Improbable rid " + idEObject.getRid() + " - " + idEObject);
        }
        return idEObject;
    } catch (BufferUnderflowException e) {
        throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
    } catch (BufferOverflowException e) {
        throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
    }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EDataType(org.eclipse.emf.ecore.EDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) EEnum(org.eclipse.emf.ecore.EEnum) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) EClass(org.eclipse.emf.ecore.EClass) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) BufferOverflowException(java.nio.BufferOverflowException) EEnumImpl(org.eclipse.emf.ecore.impl.EEnumImpl) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 12 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class SerializerFactory method create.

public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
    DatabaseSession session = bimDatabase.createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
        if (serializerPluginConfiguration != null) {
            SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (serializerPlugin != null) {
                ObjectType settings = serializerPluginConfiguration.getSettings();
                Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
                if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
                    SchemaConverterFactory converterFactory = null;
                    for (Schema schema : serializerPlugin.getSupportedSchemas()) {
                        converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
                        if (converterFactory != null) {
                            break;
                        }
                    }
                    if (converterFactory == null) {
                        throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
                    }
                    try {
                        IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
                        SchemaConverter converter = converterFactory.create(model, targetModel);
                        converter.convert();
                        model = targetModel;
                    } catch (SchemaConverterException e) {
                        throw new SerializerException(e);
                    } catch (IfcModelInterfaceException e) {
                        throw new SerializerException(e);
                    }
                }
                if (serializer != null) {
                    try {
                        ProjectInfo projectInfo = new ProjectInfo();
                        projectInfo.setName(project.getName());
                        projectInfo.setDescription(project.getDescription());
                        GeoTag geoTag = project.getGeoTag();
                        if (geoTag != null && geoTag.getEnabled()) {
                            projectInfo.setX(geoTag.getX());
                            projectInfo.setY(geoTag.getY());
                            projectInfo.setZ(geoTag.getZ());
                            projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
                        } else {
                            projectInfo.setX(4.8900);
                            projectInfo.setY(52.3700);
                        }
                        projectInfo.setAuthorName(username);
                        serializer.init(model, projectInfo, true);
                        return serializer;
                    } catch (NullPointerException e) {
                        LOGGER.error("", e);
                    }
                }
            }
        }
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    return null;
}
Also used : GeoTag(org.bimserver.models.store.GeoTag) DatabaseSession(org.bimserver.database.DatabaseSession) Schema(org.bimserver.emf.Schema) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) ObjectType(org.bimserver.models.store.ObjectType) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SchemaConverterException(org.bimserver.schemaconverter.SchemaConverterException) ProjectInfo(org.bimserver.plugins.serializers.ProjectInfo) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SchemaConverter(org.bimserver.schemaconverter.SchemaConverter) MessagingSerializer(org.bimserver.plugins.serializers.MessagingSerializer) Serializer(org.bimserver.plugins.serializers.Serializer) SchemaConverterFactory(org.bimserver.schemaconverter.SchemaConverterFactory)

Example 13 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class ClientIfcModel method loadDeep.

private void loadDeep() throws ServerException, UserException, PublicInterfaceNotFoundException, QueryException {
    if (modelState != ModelState.FULLY_LOADED && modelState != ModelState.LOADING) {
        modelState = ModelState.LOADING;
        Query query = new Query("test", getPackageMetaData());
        QueryPart queryPart = query.createQueryPart();
        queryPart.setIncludeAllFields(true);
        ObjectNode queryNode = new JsonQueryObjectModelConverter(query.getPackageMetaData()).toJson(query);
        Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), queryNode.toString(), getJsonSerializerOid(), false);
        waitForDonePreparing(topicId);
        try {
            processDownload(topicId);
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            modelState = ModelState.FULLY_LOADED;
            loadGeometry();
        } catch (IfcModelInterfaceException | IOException e) {
            LOGGER.error("", e);
        } catch (QueryException e) {
            LOGGER.error("", e);
        } catch (GeometryException e) {
            LOGGER.error("", e);
        }
    }
}
Also used : IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException)

Example 14 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException 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 15 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class TestChangeWrappedValue method start.

private void start() {
    try {
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        long poid = 2686977;
        long roid = 720899;
        SProject project = client.getServiceInterface().getProjectByPoid(poid);
        IfcModelInterface model = client.getModel(project, roid, true, false);
        for (IfcPropertySingleValue prop : model.getAll(IfcPropertySingleValue.class)) {
            // IfcValue value = ((IfcPropertySingleValue) prop).getNominalValue();
            // if(value instanceof IfcLabel){
            // System.out.println(prop.getOid() + " is " + ((IfcLabel) value).getWrappedValue() );
            // ((IfcLabel) value).setWrappedValue(((IfcLabel) value).getWrappedValue() + " changed");
            // }
            IfcLabel label = model.create(IfcLabel.class);
            label.setWrappedValue("blabla");
            prop.setNominalValue(label);
        }
        model.commit("blaat");
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    }
}
Also used : IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) IfcLabel(org.bimserver.models.ifc2x3tc1.IfcLabel) ServiceException(org.bimserver.shared.exceptions.ServiceException) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Aggregations

IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)15 IOException (java.io.IOException)7 IdEObject (org.bimserver.emf.IdEObject)7 IfcModelInterface (org.bimserver.emf.IfcModelInterface)6 QueryException (org.bimserver.database.queries.om.QueryException)5 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)5 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)5 UserException (org.bimserver.shared.exceptions.UserException)5 ModelHelper (org.bimserver.plugins.ModelHelper)4 Serializer (org.bimserver.plugins.serializers.Serializer)4 SerializerException (org.bimserver.plugins.serializers.SerializerException)4 SerializerPlugin (org.bimserver.plugins.serializers.SerializerPlugin)4 FileNotFoundException (java.io.FileNotFoundException)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)3 Query (org.bimserver.database.queries.om.Query)3 PackageMetaData (org.bimserver.emf.PackageMetaData)3 PluginManager (org.bimserver.plugins.PluginManager)3 Deserializer (org.bimserver.plugins.deserializers.Deserializer)3 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)3