Search in sources :

Example 1 with OidProvider

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

the class GeometryGenerator method generateGeometry.

@SuppressWarnings("unchecked")
public GenerateGeometryResult generateGeometry(RenderEnginePool renderEnginePool, final PluginManager pluginManager, final DatabaseSession databaseSession, final IfcModelInterface model, final int pid, final int rid, final boolean store, GeometryCache geometryCache) throws BimserverDatabaseException, GeometryGeneratingException {
    GenerateGeometryResult generateGeometryResult = new GenerateGeometryResult();
    packageMetaData = model.getPackageMetaData();
    productClass = packageMetaData.getEClass("IfcProduct");
    productRepresentationClass = packageMetaData.getEClass("IfcProductRepresentation");
    geometryFeature = productClass.getEStructuralFeature("geometry");
    representationFeature = productClass.getEStructuralFeature("Representation");
    representationsFeature = productRepresentationClass.getEStructuralFeature("Representations");
    if (geometryCache != null && !geometryCache.isEmpty()) {
        returnCachedData(model, geometryCache, databaseSession, pid, rid);
        return null;
    }
    long start = System.nanoTime();
    String pluginName = "";
    if (model.getPackageMetaData().getSchema() == Schema.IFC4) {
        pluginName = "org.bimserver.ifc.step.serializer.Ifc4StepSerializerPlugin";
    } else if (model.getPackageMetaData().getSchema() == Schema.IFC2X3TC1) {
        pluginName = "org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializerPlugin";
    }
    try {
        final SerializerPlugin ifcSerializerPlugin = (SerializerPlugin) pluginManager.getPlugin(pluginName, true);
        if (ifcSerializerPlugin == null) {
            throw new UserException("No IFC serializer found");
        }
        int maxSimultanousThreads = Math.min(bimServer.getServerSettingsCache().getServerSettings().getRenderEngineProcesses(), Runtime.getRuntime().availableProcessors());
        maxSimultanousThreads = 1;
        final RenderEngineSettings settings = new RenderEngineSettings();
        settings.setPrecision(Precision.SINGLE);
        settings.setIndexFormat(IndexFormat.AUTO_DETECT);
        settings.setGenerateNormals(true);
        settings.setGenerateTriangles(true);
        settings.setGenerateWireFrame(false);
        final RenderEngineFilter renderEngineFilter = new RenderEngineFilter();
        if (maxSimultanousThreads == 1) {
            Runner runner = new Runner(null, renderEnginePool, databaseSession, settings, store, model, ifcSerializerPlugin, model, pid, rid, null, renderEngineFilter, generateGeometryResult);
            runner.run();
        } else {
            Set<EClass> classes = new HashSet<>();
            for (IdEObject object : model.getAllWithSubTypes(packageMetaData.getEClass("IfcProduct"))) {
                IdEObject representation = (IdEObject) object.eGet(representationFeature);
                if (representation != null && ((List<?>) representation.eGet(representationsFeature)).size() > 0) {
                    classes.add(object.eClass());
                }
            }
            if (classes.size() == 0) {
                return null;
            }
            classes.remove(packageMetaData.getEClass("IfcAnnotation"));
            classes.remove(packageMetaData.getEClass("IfcOpeningElement"));
            LOGGER.debug("Using " + maxSimultanousThreads + " processes for geometry generation");
            ThreadPoolExecutor executor = new ThreadPoolExecutor(maxSimultanousThreads, maxSimultanousThreads, 24, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(classes.size()));
            final Map<IdEObject, IdEObject> bigMap = new HashMap<IdEObject, IdEObject>();
            HideAllInversesObjectIDM idm = new HideAllInversesObjectIDM(CollectionUtils.singleSet(packageMetaData.getEPackage()), model.getPackageMetaData());
            OidProvider oidProvider = new OidProvider() {

                @Override
                public long newOid(EClass eClass) {
                    return databaseSession.newOid(eClass);
                }
            };
            for (final EClass eClass : classes) {
                final BasicIfcModel targetModel = new BasicIfcModel(model.getPackageMetaData(), null);
                ModelHelper modelHelper = new ModelHelper(bimServer.getMetaDataManager(), targetModel);
                modelHelper.setOidProvider(oidProvider);
                modelHelper.setObjectIDM(idm);
                IdEObject newOwnerHistory = modelHelper.copyBasicObjects(model, bigMap);
                for (IdEObject idEObject : model.getAll(eClass)) {
                    IdEObject newObject = modelHelper.copy(idEObject, false, ModelHelper.createObjectIdm(idEObject.eClass()));
                    modelHelper.copyDecomposes(idEObject, newOwnerHistory);
                    bigMap.put(newObject, idEObject);
                    if (packageMetaData.getEClass("IfcElement").isSuperTypeOf(eClass)) {
                        EStructuralFeature hasOpeningsFeature = idEObject.eClass().getEStructuralFeature("HasOpenings");
                        for (IdEObject ifcRelVoidsElement : ((List<IdEObject>) idEObject.eGet(hasOpeningsFeature))) {
                            bigMap.put(modelHelper.copy(ifcRelVoidsElement, false), ifcRelVoidsElement);
                            EStructuralFeature relatedOpeningElementFeature = ifcRelVoidsElement.eClass().getEStructuralFeature("RelatedOpeningElement");
                            IdEObject relatedOpeningElement = (IdEObject) ifcRelVoidsElement.eGet(relatedOpeningElementFeature);
                            if (relatedOpeningElement != null) {
                                bigMap.put(modelHelper.copy(relatedOpeningElement, false), relatedOpeningElement);
                            }
                        }
                    }
                }
                executor.submit(new Runner(eClass, renderEnginePool, databaseSession, settings, store, targetModel, ifcSerializerPlugin, model, pid, rid, bigMap, renderEngineFilter, generateGeometryResult));
            }
            executor.shutdown();
            executor.awaitTermination(24, TimeUnit.HOURS);
        }
        long end = System.nanoTime();
        LOGGER.info("Rendertime: " + ((end - start) / 1000000) + "ms, " + "Reused: " + Formatters.bytesToString(bytesSaved.get()) + ", Total: " + Formatters.bytesToString(totalBytes.get()) + ", Final: " + Formatters.bytesToString(totalBytes.get() - bytesSaved.get()));
    } catch (Exception e) {
        LOGGER.error("", e);
        throw new GeometryGeneratingException(e);
    }
    return generateGeometryResult;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EClass(org.eclipse.emf.ecore.EClass) OidProvider(org.bimserver.emf.OidProvider) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) HashSet(java.util.HashSet) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) UserException(org.bimserver.shared.exceptions.UserException) EntityNotFoundException(org.bimserver.plugins.renderengine.EntityNotFoundException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) RenderEngineFilter(org.bimserver.plugins.renderengine.RenderEngineFilter) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) RenderEngineSettings(org.bimserver.plugins.renderengine.RenderEngineSettings) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with OidProvider

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

the class DownloadQueryDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
        BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
        IfcModelInterface ifcModel = session.executeAndCommitAction(action);
        QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
        Revision revision = session.get(roid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
        if (objectIDM == null) {
            objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
        }
        if (queryEngineObject != null) {
            QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
            if (queryEnginePlugin != null) {
                QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
                final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
                ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
                modelHelper.setOidProvider(new OidProvider() {

                    private long oid = 1000000;

                    @Override
                    public long newOid(EClass eClass) {
                        return oid++;
                    }
                });
                IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {

                    @Override
                    public void error(Throwable error) {
                    }

                    @Override
                    public void warning(String warning) {
                    }

                    @Override
                    public void info(String info) {
                    }
                }, modelHelper);
                return finalResult;
            } else {
                throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new UserException("No configured query engine found with qeid " + qeid);
        }
    } catch (BimserverDatabaseException e) {
        throw new UserException(e);
    } catch (QueryEngineException e) {
        throw new UserException(e);
    } catch (PluginException e) {
        throw new UserException(e);
    } finally {
        session.close();
    }
}
Also used : ServerIfcModel(org.bimserver.ServerIfcModel) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryEngine(org.bimserver.plugins.queryengine.QueryEngine) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) OidProvider(org.bimserver.emf.OidProvider) QueryEngineException(org.bimserver.plugins.queryengine.QueryEngineException) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) Reporter(org.bimserver.plugins.Reporter) PluginException(org.bimserver.shared.exceptions.PluginException) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) Revision(org.bimserver.models.store.Revision) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 3 with OidProvider

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

the class ClientIfcModel method checkin.

public void checkin(long poid, String comment) throws ServerException, UserException, PublicInterfaceNotFoundException {
    this.fixOids(new OidProvider() {

        private long c = 1;

        @Override
        public long newOid(EClass eClass) {
            return c++;
        }
    });
    SharedJsonSerializer sharedJsonSerializer = new SharedJsonSerializer(this, false);
    SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("json", poid);
    bimServerClient.checkin(poid, comment, deserializer.getOid(), false, Flow.SYNC, -1, "test", new SerializerInputstream(sharedJsonSerializer));
}
Also used : SharedJsonSerializer(org.bimserver.emf.SharedJsonSerializer) EClass(org.eclipse.emf.ecore.EClass) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) OidProvider(org.bimserver.emf.OidProvider) SerializerInputstream(org.bimserver.plugins.serializers.SerializerInputstream)

Aggregations

OidProvider (org.bimserver.emf.OidProvider)3 EClass (org.eclipse.emf.ecore.EClass)3 ModelHelper (org.bimserver.plugins.ModelHelper)2 HideAllInversesObjectIDM (org.bimserver.plugins.objectidms.HideAllInversesObjectIDM)2 UserException (org.bimserver.shared.exceptions.UserException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 ServerIfcModel (org.bimserver.ServerIfcModel)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 PackageMetaData (org.bimserver.emf.PackageMetaData)1 SharedJsonSerializer (org.bimserver.emf.SharedJsonSerializer)1 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1