use of org.bimserver.plugins.objectidms.HideAllInversesObjectIDM 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.plugins.objectidms.HideAllInversesObjectIDM in project BIMserver by opensourceBIM.
the class AddFurniture method main.
public static void main(String[] args) {
try {
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
Deserializer deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface furnishingModel = DeserializerUtils.readFromFile(deserializer, Paths.get("test.ifc"));
model.fixOids(new IncrementingOidProvider());
long oid = model.getHighestOid();
IncrementingOidProvider oidProvider = new IncrementingOidProvider(oid + 1);
IfcFurnishingElement picknick = (IfcFurnishingElement) furnishingModel.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), model);
IfcProductDefinitionShape representation = (IfcProductDefinitionShape) picknick.getRepresentation();
IfcRepresentation surfaceModel = null;
IfcRepresentation boundingBox = null;
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
if (ifcShapeRepresentation.getRepresentationType().equals("SurfaceModel")) {
surfaceModel = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
} else if (ifcShapeRepresentation.getRepresentationType().equals("BoundingBox")) {
boundingBox = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
}
}
IfcOwnerHistory ownerHistory = null;
List<IfcOwnerHistory> all = model.getAll(IfcOwnerHistory.class);
if (all.size() > 0) {
ownerHistory = all.get(0);
}
for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) {
for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) {
for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) {
if (ifcObjectDefinition instanceof IfcSpace) {
IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition;
// IfcProductDefinitionShape slabRepr = (IfcProductDefinitionShape) ifcSpace.getRepresentation();
// IfcBoundingBox box = null;
// for (IfcRepresentation representation2 : slabRepr.getRepresentations()) {
// IfcShapeRepresentation shapeRepresentation = (IfcShapeRepresentation)representation2;
// if (shapeRepresentation.getRepresentationType().equals("BoundingBox")) {
// for (IfcRepresentationItem i2 : shapeRepresentation.getItems()) {
// box = (IfcBoundingBox)i2;
// }
// }
// }
IfcFurnishingElement newFurnishing = model.create(IfcFurnishingElement.class, oidProvider);
IfcRelContainedInSpatialStructure containedInSpatialStructure2 = model.create(IfcRelContainedInSpatialStructure.class, oidProvider);
containedInSpatialStructure2.setRelatingStructure(ifcBuildingStorey);
containedInSpatialStructure2.getRelatedElements().add(newFurnishing);
newFurnishing.setName("Generated");
newFurnishing.setGlobalId("TEST");
newFurnishing.setOwnerHistory(ownerHistory);
IfcProductDefinitionShape definitionShape = model.create(IfcProductDefinitionShape.class, oidProvider);
newFurnishing.setRepresentation(definitionShape);
definitionShape.getRepresentations().add(boundingBox);
definitionShape.getRepresentations().add(surfaceModel);
IfcLocalPlacement localPlacement = model.create(IfcLocalPlacement.class, oidProvider);
localPlacement.setPlacementRelTo(ifcSpace.getObjectPlacement());
IfcAxis2Placement3D axis2Placement3D = model.create(IfcAxis2Placement3D.class, oidProvider);
localPlacement.setRelativePlacement(axis2Placement3D);
IfcCartesianPoint pos = model.create(IfcCartesianPoint.class, oidProvider);
pos.getCoordinates().add(-3d);
pos.getCoordinates().add(+0.5d);
pos.getCoordinates().add(0d);
axis2Placement3D.setLocation(pos);
newFurnishing.setObjectPlacement(localPlacement);
}
}
}
}
model.resetExpressIds();
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(null);
serializer.init(model, null, true);
SerializerUtils.writeToFile(serializer, Paths.get("withfurn.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();
}
}
use of org.bimserver.plugins.objectidms.HideAllInversesObjectIDM 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.plugins.objectidms.HideAllInversesObjectIDM in project BIMserver by opensourceBIM.
the class ModelHelper method initObjectIdmCache.
private static void initObjectIdmCache(final MetaDataManager metaDataManager) {
hideAllInverseMap = new HashMap<EPackage, HideAllInversesObjectIDM>();
objectIdmCache = new HashMap<EClass, ObjectIDM>();
for (PackageMetaData packageMetaData : metaDataManager.getAllIfc()) {
final HideAllInversesObjectIDM hideAllInverse = new HideAllInversesObjectIDM(Collections.singleton(packageMetaData.getEPackage()), packageMetaData);
hideAllInverseMap.put(packageMetaData.getEPackage(), hideAllInverse);
for (final EClass onlyIncludeRepresentationForThisClass : packageMetaData.getAllSubClasses(packageMetaData.getEClass("IfcProduct"))) {
ObjectIDM objectIdm = new ObjectIDM() {
@Override
public boolean shouldIncludeClass(EClass originalClass, EClass eClass) {
return hideAllInverse.shouldIncludeClass(originalClass, eClass);
}
@Override
public boolean shouldFollowReference(EClass originalClass, EClass eClass, EStructuralFeature eStructuralFeature) {
if (eStructuralFeature.getName().equals("Representation") && onlyIncludeRepresentationForThisClass != eClass) {
return false;
} else {
if (eStructuralFeature.getName().equals("StyledByItem")) {
return true;
}
return hideAllInverse.shouldFollowReference(originalClass, eClass, eStructuralFeature);
}
}
};
objectIdmCache.put(onlyIncludeRepresentationForThisClass, objectIdm);
}
}
skipRepresentation = new ObjectIDM() {
private ObjectIDM hideAllInverse = new HideAllInversesObjectIDM(hideAllInverseMap.keySet(), metaDataManager.getPackageMetaData("ifc2x3tc1"));
@Override
public boolean shouldIncludeClass(EClass originalClass, EClass eClass) {
return hideAllInverse.shouldIncludeClass(originalClass, eClass);
}
@Override
public boolean shouldFollowReference(EClass originalClass, EClass eClass, EStructuralFeature eStructuralFeature) {
if (eStructuralFeature.getName().equals("Representation")) {
return false;
} else {
return hideAllInverse.shouldFollowReference(originalClass, eClass, eStructuralFeature);
}
}
};
}
use of org.bimserver.plugins.objectidms.HideAllInversesObjectIDM 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();
}
}
Aggregations