use of org.bimserver.emf.PackageMetaData 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.emf.PackageMetaData 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();
}
}
use of org.bimserver.emf.PackageMetaData in project BIMserver by opensourceBIM.
the class BimServer method checkPidRid.
private int checkPidRid(DatabaseSession session, Project project, int pid, int rid) throws BimserverDatabaseException, BimserverLockConflictException {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(pid);
int removed = 0;
KeyValueStore keyValueStore = session.getKeyValueStore();
PackageMetaData packageMetaData = bimDatabase.getMetaDataManager().getPackageMetaData(project.getSchema());
for (EClass eClass : packageMetaData.getAllClasses()) {
String tableName = bimDatabase.getTableName(eClass);
if (!keyValueStore.isTransactional(session, tableName)) {
try (RecordIterator iterator = keyValueStore.getRecordIterator(tableName, buffer.array(), buffer.array(), session, true)) {
Record record = iterator.next();
while (record != null) {
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
if (keyBuffer.capacity() != 16) {
throw new BimserverDatabaseException("Unexpected key size: " + keyBuffer.capacity());
}
// pid
keyBuffer.getInt();
// oid
keyBuffer.getLong();
// rid
int recordRid = -keyBuffer.getInt();
if (recordRid > rid) {
keyValueStore.delete(tableName, record.getKey(), session);
removed++;
}
record = iterator.next();
}
}
}
}
return removed;
}
Aggregations