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;
}
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();
}
}
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));
}
Aggregations