Search in sources :

Example 6 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot 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;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerIfcModel(org.bimserver.ServerIfcModel) ModelHelper(org.bimserver.plugins.ModelHelper) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) ArrayList(java.util.ArrayList) OldQuery(org.bimserver.database.OldQuery) ServerIfcModel(org.bimserver.ServerIfcModel) IfcModel(org.bimserver.ifc.IfcModel) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) EObject(org.eclipse.emf.ecore.EObject) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Example 7 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class TestSetString method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/WallOnly.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        long tid = lowLevelInterface.startTransaction(newProject.getOid());
        IfcRoot wall = (IfcRoot) model.getByGuid("3Ep4r0uuX5ywPYOUG2H2A4");
        bimServerClient.getLowLevelInterface().setStringAttribute(tid, wall.getOid(), "Name", "Test 12345");
        long roid = lowLevelInterface.commitTransaction(tid, "v2");
        bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) URL(java.net.URL) Test(org.junit.Test)

Example 8 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class RevisionMerger method copyAttributesGuidObjectsAndAddNewObjects.

private void copyAttributesGuidObjectsAndAddNewObjects() throws IfcModelInterfaceException, ObjectAlreadyExistsException {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            IfcRoot ifcRoot = (IfcRoot) idEObject;
            String guid = ifcRoot.getGlobalId();
            if (resultModel.containsGuid(guid)) {
                // LOGGER.info("Updating attributes for object " + idEObject.eClass().getName() + " " + guid);
                IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
                for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
                    Object newValue = idEObject.eGet(eAttribute);
                    oldObject.eSet(eAttribute, newValue);
                }
            } else {
                // LOGGER.info("Adding new GUID object " + idEObject.eClass().getName() + " " + guid);
                IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
                ((IdEObjectImpl) newObject).setOid(idEObject.getOid());
                ((IfcRoot) newObject).setGlobalId(newGuid(guid));
                for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
                    newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
                }
                resultModel.add(newObject.getOid(), newObject);
            }
        }
    }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EAttribute(org.eclipse.emf.ecore.EAttribute) IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IdEObject(org.bimserver.emf.IdEObject)

Example 9 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class RevisionMerger method updateReferences.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateReferences() {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                Object referencedObject = idEObject.eGet(eReference);
                if (referencedObject instanceof IfcRoot) {
                    String referencedGuid = ((IfcRoot) referencedObject).getGlobalId();
                    IfcRoot newObject = (IfcRoot) resultModel.getByGuid(referencedGuid);
                    oldObject.eSet(eReference, newObject);
                // LOGGER.info("Fixing reference from " + guid + " to " + referencedGuid);
                } else if (referencedObject instanceof List) {
                    List referencedList = (List) referencedObject;
                    List oldReferencedList = (List) oldObject.eGet(eReference);
                    for (Object object : referencedList) {
                        if (object instanceof IfcRoot) {
                            IfcRoot referencedItem = (IfcRoot) object;
                            String itemGuid = referencedItem.getGlobalId();
                            oldReferencedList.add(resultModel.getByGuid(itemGuid));
                        // LOGGER.info("Fixing list reference from " + guid + " to " + itemGuid);
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 10 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class RevisionMerger method fixExplicitNullReferences.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void fixExplicitNullReferences() {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                if (eReference.isMany()) {
                    List list = (List) idEObject.eGet(eReference);
                    List oldList = (List) resultModel.getByGuid(guid).eGet(eReference);
                    Set<Object> guidsToRemove = new HashSet<Object>();
                    for (Object o : oldList) {
                        if (o instanceof IfcRoot) {
                            String referredGuid = ((IfcRoot) o).getGlobalId();
                            if (newModel.containsGuid(referredGuid)) {
                                boolean found = false;
                                for (Object q : list) {
                                    if (q instanceof IfcRoot) {
                                        String qGuid = ((IfcRoot) q).getGlobalId();
                                        if (qGuid.equals(referredGuid)) {
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found) {
                                    guidsToRemove.add(referredGuid);
                                }
                            }
                        }
                    }
                    if (!guidsToRemove.isEmpty()) {
                        // LOGGER.info("Removing list references");
                        oldList.removeAll(guidsToRemove);
                    }
                } else {
                    if (idEObject.eGet(eReference) == null) {
                        Object eGet = resultModel.getByGuid(guid).eGet(eReference);
                        if (eGet != null) {
                            if (eGet instanceof IfcRoot) {
                                String oldGuid = ((IfcRoot) eGet).getGlobalId();
                                if (newModel.containsGuid(oldGuid)) {
                                    // LOGGER.info("Settings explicit null reference");
                                    resultModel.getByGuid(guid).eSet(eReference, null);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) List(java.util.List) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Aggregations

IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)10 IdEObject (org.bimserver.emf.IdEObject)7 List (java.util.List)5 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)5 EReference (org.eclipse.emf.ecore.EReference)5 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 DataObject (org.bimserver.models.store.DataObject)4 EObject (org.eclipse.emf.ecore.EObject)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 OldQuery (org.bimserver.database.OldQuery)3 PackageMetaData (org.bimserver.emf.PackageMetaData)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3 Revision (org.bimserver.models.store.Revision)3 IfcModelSet (org.bimserver.plugins.IfcModelSet)3 ModelHelper (org.bimserver.plugins.ModelHelper)3 MergeException (org.bimserver.plugins.modelmerger.MergeException)3 UserException (org.bimserver.shared.exceptions.UserException)3 EAttribute (org.eclipse.emf.ecore.EAttribute)3 ArrayList (java.util.ArrayList)2