use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class WaitingList method updateNode.
@SuppressWarnings("unchecked")
public void updateNode(T expressId, EClass ec, IdEObject eObject) throws DeserializeException {
for (WaitingObject waitingObject : waitingObjects.get(expressId)) {
if (waitingObject.getEReference().isMany()) {
AbstractEList<EObject> list = (AbstractEList<EObject>) waitingObject.getObject().eGet(waitingObject.getEReference());
if (waitingObject instanceof SingleWaitingObject) {
list.addUnique(eObject);
} else {
ListWaitingObject listWaitingObject = (ListWaitingObject) waitingObject;
if (((EClass) waitingObject.getEReference().getEType()).isSuperTypeOf(eObject.eClass())) {
while (list.size() <= listWaitingObject.getIndex()) {
EObject create = ec.getEPackage().getEFactoryInstance().create(eObject.eClass());
((IdEObjectImpl) create).setOid(-2);
list.addUnique(create);
}
list.setUnique(listWaitingObject.getIndex(), eObject);
} else {
throw new DeserializeException(waitingObject.getLineNumber(), "Field " + waitingObject.getEReference().getName() + " of " + waitingObject.getEReference().getEContainingClass().getName() + " cannot contain a " + eObject.eClass().getName());
}
}
} else {
if (((EClass) waitingObject.getEReference().getEType()).isSuperTypeOf(eObject.eClass())) {
waitingObject.getObject().eSet(waitingObject.getEReference(), eObject);
} else {
throw new DeserializeException(waitingObject.getLineNumber(), "Field " + waitingObject.getEReference().getName() + " of " + waitingObject.getEReference().getEContainingClass().getName() + " cannot contain a " + eObject.eClass().getName() + "/" + eObject.getOid());
}
}
}
waitingObjects.remove(expressId);
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class GuidHighlighter method highlightGuids.
private void highlightGuids(IfcModelInterface model, Set<String> highlightedGuids) {
Set<IdEObject> newObjects = new HashSet<IdEObject>();
IfcColourRgb gray = Ifc2x3tc1Factory.eINSTANCE.createIfcColourRgb();
newObjects.add(gray);
gray.setRed(0.5f);
gray.setGreen(0.5f);
gray.setBlue(0.5f);
Set<IdEObject> toDelete = new HashSet<IdEObject>();
for (IdEObject object : model.getValues()) {
if (object instanceof IfcPresentationLayerAssignment) {
toDelete.add(object);
}
}
IfcPresentationLayerAssignment notSelectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
notSelectedLayer.setName("Not Selected");
notSelectedLayer.setIdentifier("Not Selected");
newObjects.add(notSelectedLayer);
IfcPresentationLayerAssignment selectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
selectedLayer.setName("Selected");
selectedLayer.setIdentifier("Selected");
newObjects.add(selectedLayer);
for (IdEObject idEObject : model.getValues()) {
if (idEObject instanceof IfcProduct) {
IfcProduct product = (IfcProduct) idEObject;
String guid = product.getGlobalId();
boolean hide = true;
if (guid != null) {
if (highlightedGuids.contains(guid)) {
hide = false;
}
}
if (hide) {
System.out.println("Hiding " + guid);
IfcProductRepresentation representation = product.getRepresentation();
if (representation != null) {
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
notSelectedLayer.getAssignedItems().add(ifcRepresentation);
for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
notSelectedLayer.getAssignedItems().add(ifcRepresentationItem);
for (IfcStyledItem ifcStyledItem : ifcRepresentationItem.getStyledByItem()) {
for (IfcPresentationStyleAssignment ifcPresentationStyleAssignment : ifcStyledItem.getStyles()) {
for (IfcPresentationStyleSelect ifcPresentationStyleSelect : ifcPresentationStyleAssignment.getStyles()) {
if (ifcPresentationStyleSelect instanceof IfcSurfaceStyle) {
IfcSurfaceStyle ifcSurfaceStyle = (IfcSurfaceStyle) ifcPresentationStyleSelect;
for (IfcSurfaceStyleElementSelect ifcSurfaceStyleElementSelect : ifcSurfaceStyle.getStyles()) {
if (ifcSurfaceStyleElementSelect instanceof IfcSurfaceStyleRendering) {
IfcSurfaceStyleRendering ifcSurfaceStyleRendering = (IfcSurfaceStyleRendering) ifcSurfaceStyleElementSelect;
ifcSurfaceStyleRendering.setTransparency(0.98f);
ifcSurfaceStyleRendering.setDiffuseColour(gray);
ifcSurfaceStyleRendering.setReflectionColour(gray);
ifcSurfaceStyleRendering.setSpecularColour(gray);
ifcSurfaceStyleRendering.setSurfaceColour(gray);
ifcSurfaceStyleRendering.setTransmissionColour(gray);
}
}
}
}
}
}
}
}
}
} else {
System.out.println("Not hiding " + guid);
IfcProductRepresentation representation = product.getRepresentation();
if (representation != null) {
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
selectedLayer.getAssignedItems().add(ifcRepresentation);
for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
selectedLayer.getAssignedItems().add(ifcRepresentationItem);
}
}
}
}
}
}
for (IdEObject toDeleteObject : toDelete) {
model.remove(toDeleteObject);
}
for (IdEObject newObject : newObjects) {
try {
model.add(model.getHighestOid() + 1, newObject);
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method getReferences.
@SuppressWarnings("unchecked")
@Override
public List<Long> getReferences(Long tid, Long oid, String referenceName) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), null, Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
List<IdEObject> list = (List<IdEObject>) object.eGet(object.eClass().getEStructuralFeature(referenceName));
List<Long> oidList = new ArrayList<Long>();
for (IdEObject idEObject : list) {
oidList.add(idEObject.getOid());
}
return oidList;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class ClientIfcModel method loadGeometry.
private void loadGeometry() throws QueryException, ServerException, UserException, PublicInterfaceNotFoundException, IOException, GeometryException, IfcModelInterfaceException {
if (includeGeometry) {
getModelMetaData().setMinBounds(getBimServerClient().getServiceInterface().getModelMinBounds(roid));
getModelMetaData().setMaxBounds(getBimServerClient().getServiceInterface().getModelMaxBounds(roid));
Query query = new Query("test", getPackageMetaData());
QueryPart queryPart = query.createQueryPart();
Map<Long, Long> geometryInfoOidToOid = new HashMap<>();
EClass ifcProductClass = getPackageMetaData().getEClass("IfcProduct");
EStructuralFeature geometryFeature = ifcProductClass.getEStructuralFeature("geometry");
List<IdEObject> allWithSubTypes = new ArrayList<>(super.getAllWithSubTypes(ifcProductClass));
for (IdEObject ifcProduct : allWithSubTypes) {
GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
if (geometry != null) {
if (geometry.getData() == null || geometry.getData().getIndices() == null) {
queryPart.addOid(geometry.getOid());
geometryInfoOidToOid.put(geometry.getOid(), ifcProduct.getOid());
}
}
}
if (queryPart.getOids() == null) {
return;
}
EClass geometryInfoClass = getPackageMetaData().getEClassIncludingDependencies("GeometryInfo");
Include include = queryPart.createInclude();
include.addType(geometryInfoClass, false);
include.addField("data");
long serializerOid = bimServerClient.getBinaryGeometryMessagingStreamingSerializerOid();
long topicId = bimServerClient.query(query, roid, serializerOid);
// TODO use websocket notifications
waitForDonePreparing(topicId);
InputStream inputStream = bimServerClient.getDownloadData(topicId);
try {
// ByteArrayOutputStream byteArrayOutputStream = new
// ByteArrayOutputStream();
// IOUtils.copy(inputStream, byteArrayOutputStream);
processGeometryInputStream(inputStream, geometryInfoOidToOid);
} catch (Throwable e) {
e.printStackTrace();
} finally {
bimServerClient.getServiceInterface().cleanupLongAction(topicId);
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class ClientIfcModel method branch.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ClientIfcModel branch(long poid, boolean recordChanges) {
// TODO this should of course be done server side, without any copying
ClientIfcModel branch = new ClientIfcModel(bimServerClient, getPackageMetaData(), poid, recordChanges);
try {
loadDeep();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
} catch (QueryException e) {
LOGGER.error("", e);
}
Map<IdEObject, IdEObject> map = new HashMap<IdEObject, IdEObject>();
for (IdEObject sourceObject : getValues()) {
try {
IdEObjectImpl targetObject = branch.create(sourceObject.eClass());
targetObject.setLoadingState(State.LOADED);
map.put(sourceObject, targetObject);
} catch (IfcModelInterfaceException e) {
LOGGER.error("", e);
}
}
for (IdEObject sourceObject : getObjects().values()) {
IdEObject targetObject = map.get(sourceObject);
for (EStructuralFeature eStructuralFeature : sourceObject.eClass().getEAllStructuralFeatures()) {
Object sourceValue = sourceObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EReference) {
if (eStructuralFeature.isMany()) {
List sourceList = (List) sourceValue;
List targetList = (List) targetObject.eGet(eStructuralFeature);
for (Object sourceItem : sourceList) {
IdEObject e = map.get(sourceItem);
if (e != null) {
targetList.add(e);
}
}
} else {
targetObject.eSet(eStructuralFeature, map.get(sourceValue));
}
} else {
if (eStructuralFeature.isMany()) {
List sourceList = (List) sourceValue;
List targetList = (List) targetObject.eGet(eStructuralFeature);
for (Object sourceItem : sourceList) {
targetList.add(sourceItem);
}
} else {
targetObject.eSet(eStructuralFeature, sourceValue);
}
}
}
}
branch.setModelState(ModelState.FULLY_LOADED);
return branch;
}
Aggregations