Search in sources :

Example 1 with BasicIfcModel

use of org.bimserver.ifc.BasicIfcModel 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, ObjectAlreadyExistsException, IfcModelInterfaceException {
    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, store);
        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>();
            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);
                IdEObject newOwnerHistory = modelHelper.copyBasicObjects(model, bigMap);
                for (IdEObject idEObject : model.getAll(eClass)) {
                    IdEObject newObject = modelHelper.copy(idEObject, false);
                    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) RenderEngineSettings(org.bimserver.plugins.renderengine.RenderEngineSettings) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with BasicIfcModel

use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.

the class BranchToExistingProjectDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
    Project oldProject = oldRevision.getProject();
    User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
        throw new UserException("User has insufficient rights to download revisions from this project");
    }
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastMetaData = null;
    for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
        IfcModel subModel = new BasicIfcModel(packageMetaData, null);
        getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.YES));
        subModel.getModelMetaData().setDate(subRevision.getDate());
        ifcModelSet.add(subModel);
        lastMetaData = packageMetaData;
    }
    IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
    try {
        model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
    } catch (MergeException e) {
        throw new UserException(e);
    }
    model.resetOids();
    // TODO
    CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), destPoid, authorization, model, comment, comment, false, -1, -1);
    return checkinDatabaseAction.execute();
}
Also used : User(org.bimserver.models.store.User) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) IfcModel(org.bimserver.ifc.IfcModel) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Example 3 with BasicIfcModel

use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.

the class TestBigModelEmfRemote method test.

@Test
public void test() {
    boolean doreuse = true;
    boolean useLowLevelCalls = false;
    try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClientInterface bimServerClient = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = null;
        if (useLowLevelCalls) {
            model = bimServerClient.newModel(newProject, true);
        } else {
            model = new BasicIfcModel(bimServerClient.getMetaDataManager().getPackageMetaData("ifc2x3tc1"), null);
        }
        RichIfcModel richIfcModel = new RichIfcModel(model, !useLowLevelCalls);
        IfcBuilding ifcBuilding = richIfcModel.createDefaultProjectStructure(0, 0, 0);
        IfcRelAggregates buildingAggregation = richIfcModel.create(IfcRelAggregates.class);
        buildingAggregation.setRelatingObject(ifcBuilding);
        for (int i = 1; i <= 200; i++) {
            IfcBuildingStorey ifcBuildingStorey = richIfcModel.create(IfcBuildingStorey.class);
            ifcBuildingStorey.setName("Storey " + i);
            ifcBuildingStorey.setCompositionType(IfcElementCompositionEnum.ELEMENT);
            ifcBuildingStorey.setElevation(3000 * i);
            IfcLocalPlacement storeyPlacement = richIfcModel.create(IfcLocalPlacement.class);
            storeyPlacement.setRelativePlacement(richIfcModel.createBasicPosition(0, 0, i * 3000));
            ifcBuildingStorey.setObjectPlacement(storeyPlacement);
            buildingAggregation.getRelatedObjects().add(ifcBuildingStorey);
            IfcRelAggregates storeyAggregation = richIfcModel.create(IfcRelAggregates.class);
            storeyAggregation.setRelatingObject(ifcBuildingStorey);
            for (int x = 1; x <= 40; x++) {
                for (int y = 1; y <= 40; y++) {
                    createSpace(richIfcModel, richIfcModel.getDefaultRepresentationContext(), storeyPlacement, storeyAggregation, x, y, doreuse);
                }
            }
        }
        long roid = -1;
        if (useLowLevelCalls) {
            roid = model.commit("Initial model");
        } else {
            Serializer serializer = new Ifc2x3tc1StepSerializer(null);
            serializer.init(model, null, true);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            serializer.writeToOutputStream(baos, null);
            java.nio.file.Files.write(Paths.get("tmp.ifc"), baos.toByteArray());
            SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
            SLongCheckinActionState checkinSync = bimServerClient.checkinSync(newProject.getOid(), "New", deserializer.getOid(), false, baos.size(), "newfile", new ByteArrayInputStream(baos.toByteArray()));
            roid = checkinSync.getRoid();
        }
        SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(roid, serializerByContentType.getOid(), new FileOutputStream(new File("created.ifc")));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) RichIfcModel(org.bimserver.utils.RichIfcModel) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SProject(org.bimserver.interfaces.objects.SProject) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding) Serializer(org.bimserver.plugins.serializers.Serializer) Ifc2x3tc1StepSerializer(org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Ifc2x3tc1StepSerializer(org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer) IfcRelAggregates(org.bimserver.models.ifc2x3tc1.IfcRelAggregates) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) File(java.io.File) Test(org.junit.Test)

Example 4 with BasicIfcModel

use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.

the class AdminServiceImpl method regenerateGeometry.

@Override
public void regenerateGeometry(Long croid) throws ServerException, UserException {
    LOGGER.info("Regenerating geometry for concrete revision" + croid);
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        // Normally we wouldn't be allowed to change existing data
        session.setOverwriteEnabled(true);
        ConcreteRevision concreteRevision = session.get(StorePackage.eINSTANCE.getConcreteRevision(), croid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
        session.getMap(model, new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1));
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        UserSettings userSettings = user.getUserSettings();
        RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
        if (defaultRenderEngine == null) {
            throw new BimBotsException("No default render engine has been selected for this user", BimBotDefaultErrorCode.NO_RENDER_ENGINE);
        }
        RenderEnginePool pool = getBimServer().getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), getBimServer().getPluginSettingsCache().getPluginSettings(defaultRenderEngine.getOid()));
        new GeometryGenerator(getBimServer()).generateGeometry(pool, getBimServer().getPluginManager(), session, model, concreteRevision.getProject().getId(), concreteRevision.getId(), true, null);
        session.commit();
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) DatabaseSession(org.bimserver.database.DatabaseSession) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) UserSettings(org.bimserver.models.store.UserSettings) GeometryGenerator(org.bimserver.GeometryGenerator) BimBotsException(org.bimserver.bimbots.BimBotsException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) ConcreteRevision(org.bimserver.models.store.ConcreteRevision)

Example 5 with BasicIfcModel

use of org.bimserver.ifc.BasicIfcModel in project BIMserver by opensourceBIM.

the class BranchToNewProjectDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
    Project oldProject = oldRevision.getProject();
    final User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
        throw new UserException("User has insufficient rights to download revisions from this project");
    }
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastMetaData = null;
    for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
        if (lastMetaData != null && lastMetaData != packageMetaData) {
            throw new UserException("Branching not possible for revision with multiple schemas");
        }
        IfcModel subModel = new BasicIfcModel(packageMetaData, null);
        getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.NO));
        subModel.getModelMetaData().setDate(subRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
    try {
        model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
    } catch (MergeException e) {
        throw new UserException(e);
    }
    model.resetOids();
    final Project newProject = new AddProjectDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), projectName, "ifc2x3tc1", authorization).execute();
    // TODO
    CheckinDatabaseAction createCheckinAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), newProject.getOid(), authorization, model, comment, comment, false, -1, -1);
    return createCheckinAction.execute();
}
Also used : User(org.bimserver.models.store.User) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) IfcModel(org.bimserver.ifc.IfcModel) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

BasicIfcModel (org.bimserver.ifc.BasicIfcModel)11 IfcModelInterface (org.bimserver.emf.IfcModelInterface)9 PackageMetaData (org.bimserver.emf.PackageMetaData)8 OldQuery (org.bimserver.database.OldQuery)7 UserException (org.bimserver.shared.exceptions.UserException)7 ModelHelper (org.bimserver.plugins.ModelHelper)6 IfcModel (org.bimserver.ifc.IfcModel)5 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)5 Revision (org.bimserver.models.store.Revision)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 IfcModelSet (org.bimserver.plugins.IfcModelSet)4 MergeException (org.bimserver.plugins.modelmerger.MergeException)4 DatabaseSession (org.bimserver.database.DatabaseSession)3 IdEObject (org.bimserver.emf.IdEObject)3 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)3 Project (org.bimserver.models.store.Project)3 User (org.bimserver.models.store.User)3 Serializer (org.bimserver.plugins.serializers.Serializer)3 SerializerPlugin (org.bimserver.plugins.serializers.SerializerPlugin)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2