use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method writeList.
private void writeList(IdEObject object, ByteBuffer buffer, PackageMetaData packageMetaData, EStructuralFeature feature) throws BimserverDatabaseException {
if (feature.getEType() instanceof EEnum) {
// Aggregate relations to enums never occur... at this
// moment
} else if (feature.getEType() instanceof EClass) {
EList<?> list = (EList<?>) object.eGet(feature);
buffer.putInt(list.size());
for (Object o : list) {
if (o == null) {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
} else {
IdEObject listObject = (IdEObject) o;
if (listObject.eClass().getEAnnotation("wrapped") != null || listObject.eClass().getEStructuralFeature("wrappedValue") != null) {
writeWrappedValue(object.getPid(), object.getRid(), listObject, buffer, packageMetaData);
} else if (feature.getEAnnotation("twodimensionalarray") != null) {
EStructuralFeature lf = listObject.eClass().getEStructuralFeature("List");
writeList(listObject, buffer, packageMetaData, lf);
} else {
writeReference(object, listObject, buffer, feature);
}
}
}
} else if (feature.getEType() instanceof EDataType) {
EList<?> list = (EList<?>) object.eGet(feature);
buffer.putInt(list.size());
for (Object o : list) {
writePrimitiveValue(feature, o, buffer);
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method readList.
@SuppressWarnings("unchecked")
private Object readList(IdEObject idEObject, EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, QueryInterface query, TodoList todoList, EStructuralFeature feature) throws BimserverDatabaseException {
if (feature.getEType() instanceof EEnum) {
} else if (feature.getEType() instanceof EClass) {
if (buffer.capacity() == 1 && buffer.get(0) == -1) {
buffer.position(buffer.position() + 1);
} else {
/*
* TODO There still is a problem with this,
* when readReference (and all calls beyond
* that call) alter (by opposites) this
* list, this list can potentially grow too
* large
*
* Only can happen with non-unique
* references
*/
int listSize = buffer.getInt();
AbstractEList<Object> list = (AbstractEList<Object>) idEObject.eGet(feature);
for (int i = 0; i < listSize; i++) {
if (feature.getEAnnotation("twodimensionalarray") != null) {
IdEObjectImpl newObject = createInternal((EClass) feature.getEType(), query);
Object result = readList(newObject, originalQueryClass, buffer, model, query, todoList, newObject.eClass().getEStructuralFeature("List"));
if (result != null) {
newObject.eSet(newObject.eClass().getEStructuralFeature("List"), result);
}
list.addUnique(newObject);
} else {
IdEObject referencedObject = null;
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is
// embedded
// in record
EClass referenceClass = database.getEClassForCid((short) (-cid));
if (referenceClass == null) {
throw new BimserverDatabaseException("No class found for cid " + (-cid));
}
referencedObject = readWrappedValue(feature, buffer, referenceClass, query);
} else if (cid > 0) {
// positive cid means value is a
// reference
// to another record
EClass referenceClass = database.getEClassForCid(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("Cannot find class with cid " + cid);
}
buffer.position(buffer.position() - 2);
referencedObject = readReference(originalQueryClass, buffer, model, idEObject, feature, referenceClass, query, todoList);
}
if (referencedObject != null) {
if (!feature.getEType().isInstance(referencedObject)) {
throw new BimserverDatabaseException(referencedObject.getClass().getSimpleName() + " cannot be stored in list of type " + feature.getEType().getName() + " for feature " + feature.getName());
}
if (feature.isUnique()) {
list.add(referencedObject);
} else {
list.addUnique(referencedObject);
}
}
}
}
}
} else if (feature.getEType() instanceof EDataType) {
int listSize = buffer.getInt();
BasicEList<Object> list = new BasicEList<Object>(listSize);
for (int i = 0; i < listSize; i++) {
Object reference = readPrimitiveValue(feature.getEType(), buffer, query);
if (reference != null) {
list.addUnique(reference);
}
}
return list;
}
return null;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method get.
@SuppressWarnings("unchecked")
public <T extends IdEObject> T get(IfcModelInterface model, long oid, QueryInterface query) throws BimserverDatabaseException {
checkOpen();
TodoList todoList = new TodoList();
IdEObject idEObject = get(null, oid, model, query, todoList);
processTodoList(model, todoList, query);
return (T) idEObject;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class GeometryGenerator method returnCachedData.
private void returnCachedData(IfcModelInterface model, GeometryCache geometryCache, DatabaseSession databaseSession, int pid, int rid) throws BimserverDatabaseException {
EClass productClass = model.getPackageMetaData().getEClass("IfcProduct");
List<IdEObject> products = model.getAllWithSubTypes(productClass);
for (IdEObject ifcProduct : products) {
GeometryCacheEntry geometryCacheEntry = geometryCache.get(ifcProduct.getExpressId());
if (geometryCacheEntry != null) {
GeometryData geometryData = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryData(), pid, rid);
geometryData.setVertices(geometryCacheEntry.getVertices().array());
geometryData.setNormals(geometryCacheEntry.getNormals().array());
GeometryInfo geometryInfo = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryInfo(), pid, rid);
Vector3f min = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
min.setX(geometryCacheEntry.getGeometryInfo().getMinBounds().getX());
min.setY(geometryCacheEntry.getGeometryInfo().getMinBounds().getY());
min.setZ(geometryCacheEntry.getGeometryInfo().getMinBounds().getZ());
Vector3f max = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
max.setX(geometryCacheEntry.getGeometryInfo().getMaxBounds().getX());
max.setY(geometryCacheEntry.getGeometryInfo().getMaxBounds().getY());
max.setZ(geometryCacheEntry.getGeometryInfo().getMaxBounds().getZ());
geometryInfo.setMinBounds(min);
geometryInfo.setMaxBounds(max);
geometryInfo.setData(geometryData);
ifcProduct.eSet(ifcProduct.eClass().getEStructuralFeature("geometry"), geometryInfo);
}
}
}
use of org.bimserver.emf.IdEObject 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;
}
Aggregations