Search in sources :

Example 16 with IdEObject

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);
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException)

Example 17 with IdEObject

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();
        }
    }
}
Also used : IfcSurfaceStyle(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyle) IdEObject(org.bimserver.emf.IdEObject) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcPresentationLayerAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment) IfcColourRgb(org.bimserver.models.ifc2x3tc1.IfcColourRgb) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcSurfaceStyleElementSelect(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleElementSelect) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) IfcPresentationStyleAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleAssignment) IfcPresentationStyleSelect(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleSelect) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) HashSet(java.util.HashSet) IfcSurfaceStyleRendering(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleRendering)

Example 18 with IdEObject

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();
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery)

Example 19 with IdEObject

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);
        }
    }
}
Also used : Query(org.bimserver.database.queries.om.Query) HashMap(java.util.HashMap) IdEObject(org.bimserver.emf.IdEObject) QueryPart(org.bimserver.database.queries.om.QueryPart) LittleEndianDataInputStream(com.google.common.io.LittleEndianDataInputStream) InputStream(java.io.InputStream) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) Include(org.bimserver.database.queries.om.Include) EClass(org.eclipse.emf.ecore.EClass) GeometryInfo(org.bimserver.models.geometry.GeometryInfo)

Example 20 with IdEObject

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;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerException(org.bimserver.shared.exceptions.ServerException) IdEObject(org.bimserver.emf.IdEObject) HashMap(java.util.HashMap) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

IdEObject (org.bimserver.emf.IdEObject)68 List (java.util.List)25 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)25 EClass (org.eclipse.emf.ecore.EClass)20 EReference (org.eclipse.emf.ecore.EReference)18 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)15 UserException (org.bimserver.shared.exceptions.UserException)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ArrayList (java.util.ArrayList)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)12 HashSet (java.util.HashSet)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 OldQuery (org.bimserver.database.OldQuery)9 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)9 VirtualObject (org.bimserver.shared.VirtualObject)9 EAttribute (org.eclipse.emf.ecore.EAttribute)9 Project (org.bimserver.models.store.Project)8