Search in sources :

Example 1 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class DatabaseSession method processTodoList.

private void processTodoList(IfcModelInterface model, TodoList todoList, QueryInterface query) throws BimserverDatabaseException {
    IdEObject idEObject = todoList.poll();
    while (idEObject != null) {
        IdEObject result = get(idEObject, idEObject.getOid(), model, query, todoList);
        if (result == null) {
            throw new BimserverDatabaseException("Object not found: " + query.getPid() + " " + query.getRid() + " " + idEObject.getOid() + " " + idEObject.eClass().getName());
        }
        if (!model.contains(result.getOid())) {
            try {
                model.addAllowMultiModel(result.getOid(), result);
            } catch (IfcModelInterfaceException e) {
                throw new BimserverDatabaseException(e);
            }
        }
        idEObject = todoList.poll();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IdEObject(org.bimserver.emf.IdEObject)

Example 2 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class AddFurniture method main.

public static void main(String[] args) {
    try {
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
        deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface furnishingModel = DeserializerUtils.readFromFile(deserializer, Paths.get("test.ifc"));
        model.fixOids(new IncrementingOidProvider());
        long oid = model.getHighestOid();
        IncrementingOidProvider oidProvider = new IncrementingOidProvider(oid + 1);
        IfcFurnishingElement picknick = (IfcFurnishingElement) furnishingModel.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
        ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), model);
        IfcProductDefinitionShape representation = (IfcProductDefinitionShape) picknick.getRepresentation();
        IfcRepresentation surfaceModel = null;
        IfcRepresentation boundingBox = null;
        for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
            IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
            if (ifcShapeRepresentation.getRepresentationType().equals("SurfaceModel")) {
                surfaceModel = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
            } else if (ifcShapeRepresentation.getRepresentationType().equals("BoundingBox")) {
                boundingBox = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
            }
        }
        IfcOwnerHistory ownerHistory = null;
        List<IfcOwnerHistory> all = model.getAll(IfcOwnerHistory.class);
        if (all.size() > 0) {
            ownerHistory = all.get(0);
        }
        for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) {
            for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) {
                for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) {
                    if (ifcObjectDefinition instanceof IfcSpace) {
                        IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition;
                        // IfcProductDefinitionShape slabRepr = (IfcProductDefinitionShape) ifcSpace.getRepresentation();
                        // IfcBoundingBox box = null;
                        // for (IfcRepresentation representation2 : slabRepr.getRepresentations()) {
                        // IfcShapeRepresentation shapeRepresentation = (IfcShapeRepresentation)representation2;
                        // if (shapeRepresentation.getRepresentationType().equals("BoundingBox")) {
                        // for (IfcRepresentationItem i2 : shapeRepresentation.getItems()) {
                        // box = (IfcBoundingBox)i2;
                        // }
                        // }
                        // }
                        IfcFurnishingElement newFurnishing = model.create(IfcFurnishingElement.class, oidProvider);
                        IfcRelContainedInSpatialStructure containedInSpatialStructure2 = model.create(IfcRelContainedInSpatialStructure.class, oidProvider);
                        containedInSpatialStructure2.setRelatingStructure(ifcBuildingStorey);
                        containedInSpatialStructure2.getRelatedElements().add(newFurnishing);
                        newFurnishing.setName("Generated");
                        newFurnishing.setGlobalId("TEST");
                        newFurnishing.setOwnerHistory(ownerHistory);
                        IfcProductDefinitionShape definitionShape = model.create(IfcProductDefinitionShape.class, oidProvider);
                        newFurnishing.setRepresentation(definitionShape);
                        definitionShape.getRepresentations().add(boundingBox);
                        definitionShape.getRepresentations().add(surfaceModel);
                        IfcLocalPlacement localPlacement = model.create(IfcLocalPlacement.class, oidProvider);
                        localPlacement.setPlacementRelTo(ifcSpace.getObjectPlacement());
                        IfcAxis2Placement3D axis2Placement3D = model.create(IfcAxis2Placement3D.class, oidProvider);
                        localPlacement.setRelativePlacement(axis2Placement3D);
                        IfcCartesianPoint pos = model.create(IfcCartesianPoint.class, oidProvider);
                        pos.getCoordinates().add(-3d);
                        pos.getCoordinates().add(+0.5d);
                        pos.getCoordinates().add(0d);
                        axis2Placement3D.setLocation(pos);
                        newFurnishing.setObjectPlacement(localPlacement);
                    }
                }
            }
        }
        model.resetExpressIds();
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(null);
        serializer.init(model, null, true);
        SerializerUtils.writeToFile(serializer, Paths.get("withfurn.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();
    }
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcObjectDefinition(org.bimserver.models.ifc2x3tc1.IfcObjectDefinition) IfcSpace(org.bimserver.models.ifc2x3tc1.IfcSpace) FileNotFoundException(java.io.FileNotFoundException) IfcOwnerHistory(org.bimserver.models.ifc2x3tc1.IfcOwnerHistory) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductDefinitionShape(org.bimserver.models.ifc2x3tc1.IfcProductDefinitionShape) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) Serializer(org.bimserver.plugins.serializers.Serializer) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) IfcRelDecomposes(org.bimserver.models.ifc2x3tc1.IfcRelDecomposes) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)

Example 3 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.

the class Visualise method main.

public static void main(String[] args) {
    PluginManager pluginManager;
    try {
        pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.requireDeserializer("application/ifc");
        Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface model1 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model1b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model2 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model2b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        model1.setObjectOids();
        model1b.setObjectOids();
        model2.setObjectOids();
        model2b.setObjectOids();
        model1.indexGuids();
        model2.indexGuids();
        model2.fixOids(new IncrementingOidProvider(model1.getHighestOid() + 1));
        IfcModel merged = new RevisionMerger(model1, model2).merge();
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration());
        serializer.init(merged, null, false);
        SerializerUtils.writeToFile(serializer, Paths.get("merged.ifc"));
        new Visualise().start(model1b, "Model 1");
        new Visualise().start(model2b, "Model 2");
        new Visualise().start(merged, "Merged");
    } catch (PluginException e1) {
        e1.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RevisionMerger(org.bimserver.merging.RevisionMerger) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModel(org.bimserver.ifc.IfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Example 4 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException 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 5 with IfcModelInterfaceException

use of org.bimserver.emf.IfcModelInterfaceException 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

IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)15 IOException (java.io.IOException)7 IdEObject (org.bimserver.emf.IdEObject)7 IfcModelInterface (org.bimserver.emf.IfcModelInterface)6 QueryException (org.bimserver.database.queries.om.QueryException)5 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)5 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)5 UserException (org.bimserver.shared.exceptions.UserException)5 ModelHelper (org.bimserver.plugins.ModelHelper)4 Serializer (org.bimserver.plugins.serializers.Serializer)4 SerializerException (org.bimserver.plugins.serializers.SerializerException)4 SerializerPlugin (org.bimserver.plugins.serializers.SerializerPlugin)4 FileNotFoundException (java.io.FileNotFoundException)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)3 Query (org.bimserver.database.queries.om.Query)3 PackageMetaData (org.bimserver.emf.PackageMetaData)3 PluginManager (org.bimserver.plugins.PluginManager)3 Deserializer (org.bimserver.plugins.deserializers.Deserializer)3 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)3