use of org.bimserver.plugins.ModelHelper in project BIMserver by opensourceBIM.
the class GetDataObjectByOidDatabaseAction method execute.
@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision virtualRevision = getRevisionByRoid(roid);
EObject eObject = null;
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastPackageMetaData = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new BasicIfcModel(packageMetaData, pidRoidMap);
int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
eObject = getDatabaseSession().get(null, oid, subModel, query);
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
if (eObject != null) {
break;
}
}
IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
if (ifcModelSet.size() > 1) {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
if (eObject == null) {
throw new UserException("Object not found in this project/revision");
}
DataObject dataObject = null;
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setName("");
dataObject.setGuid("");
}
fillDataObject(ifcModel.getObjects(), eObject, dataObject);
return dataObject;
}
use of org.bimserver.plugins.ModelHelper in project BIMserver by opensourceBIM.
the class GetDataObjectsByTypeDatabaseAction method execute.
@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
EClass eClass = getDatabaseSession().getEClassForName(packageName, className);
Revision virtualRevision = getRevisionByRoid(roid);
if (virtualRevision == null) {
throw new UserException("No revision with roid " + roid + " found");
}
Map<Integer, Long> pidRoidMap = new HashMap<>();
IfcModelSet ifcModelSet = new IfcModelSet();
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
PackageMetaData lastPackageMetaData = null;
Project project = virtualRevision.getProject();
for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1, null, Deep.NO, highestStopId);
lastPackageMetaData = packageMetaData;
IfcModelInterface subModel = getDatabaseSession().getAllOfType(packageMetaData.getEPackage().getName(), className, query);
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
if (ifcModelSet.size() > 1) {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
List<DataObject> dataObjects = new ArrayList<DataObject>();
for (Long oid : new HashSet<>(ifcModel.keySet())) {
EObject eObject = ifcModel.get(oid);
if (eClass.isInstance(eObject)) {
DataObject dataObject = StoreFactory.eINSTANCE.createDataObject();
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid("");
dataObject.setName("");
}
if (!flat) {
GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
}
dataObjects.add(dataObject);
}
}
return dataObjects;
}
use of org.bimserver.plugins.ModelHelper in project BIMserver by opensourceBIM.
the class GetDataObjectsDatabaseAction method execute.
@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision virtualRevision = getRevisionByRoid(roid);
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastPackageMetaData = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.YES, highestStopId);
getDatabaseSession().getMap(subModel, query);
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
List<DataObject> dataObjects = new ArrayList<DataObject>();
for (Long oid : ifcModel.keySet()) {
EObject eObject = ifcModel.get(oid);
if (eObject.eClass().getEAnnotation("hidden") == null) {
DataObject dataObject = null;
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot) eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl) dataObject).setOid(oid);
dataObject.setGuid("");
dataObject.setName("");
}
GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
dataObjects.add(dataObject);
}
}
return dataObjects;
}
use of org.bimserver.plugins.ModelHelper 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