Search in sources :

Example 41 with PackageMetaData

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

the class ModelHelper method initObjectIdmCache.

private static void initObjectIdmCache(final MetaDataManager metaDataManager) {
    hideAllInverseMap = new HashMap<EPackage, HideAllInversesObjectIDM>();
    objectIdmCache = new HashMap<EClass, ObjectIDM>();
    for (PackageMetaData packageMetaData : metaDataManager.getAllIfc()) {
        final HideAllInversesObjectIDM hideAllInverse = new HideAllInversesObjectIDM(Collections.singleton(packageMetaData.getEPackage()), packageMetaData);
        hideAllInverseMap.put(packageMetaData.getEPackage(), hideAllInverse);
        for (final EClass onlyIncludeRepresentationForThisClass : packageMetaData.getAllSubClasses(packageMetaData.getEClass("IfcProduct"))) {
            ObjectIDM objectIdm = new ObjectIDM() {

                @Override
                public boolean shouldIncludeClass(EClass originalClass, EClass eClass) {
                    return hideAllInverse.shouldIncludeClass(originalClass, eClass);
                }

                @Override
                public boolean shouldFollowReference(EClass originalClass, EClass eClass, EStructuralFeature eStructuralFeature) {
                    if (eStructuralFeature.getName().equals("Representation") && onlyIncludeRepresentationForThisClass != eClass) {
                        return false;
                    } else {
                        if (eStructuralFeature.getName().equals("StyledByItem")) {
                            return true;
                        }
                        return hideAllInverse.shouldFollowReference(originalClass, eClass, eStructuralFeature);
                    }
                }
            };
            objectIdmCache.put(onlyIncludeRepresentationForThisClass, objectIdm);
        }
    }
    skipRepresentation = new ObjectIDM() {

        private ObjectIDM hideAllInverse = new HideAllInversesObjectIDM(hideAllInverseMap.keySet(), metaDataManager.getPackageMetaData("ifc2x3tc1"));

        @Override
        public boolean shouldIncludeClass(EClass originalClass, EClass eClass) {
            return hideAllInverse.shouldIncludeClass(originalClass, eClass);
        }

        @Override
        public boolean shouldFollowReference(EClass originalClass, EClass eClass, EStructuralFeature eStructuralFeature) {
            if (eStructuralFeature.getName().equals("Representation")) {
                return false;
            } else {
                return hideAllInverse.shouldFollowReference(originalClass, eClass, eStructuralFeature);
            }
        }
    };
}
Also used : EClass(org.eclipse.emf.ecore.EClass) PackageMetaData(org.bimserver.emf.PackageMetaData) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ObjectIDM(org.bimserver.plugins.objectidms.ObjectIDM) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) EPackage(org.eclipse.emf.ecore.EPackage)

Example 42 with PackageMetaData

use of org.bimserver.emf.PackageMetaData 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();
    }
}
Also used : Path(java.nio.file.Path) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Example 43 with PackageMetaData

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

the class BimServer method checkPidRid.

private int checkPidRid(DatabaseSession session, Project project, int pid, int rid) throws BimserverDatabaseException, BimserverLockConflictException {
    ByteBuffer buffer = ByteBuffer.allocate(4);
    buffer.putInt(pid);
    int removed = 0;
    KeyValueStore keyValueStore = session.getKeyValueStore();
    PackageMetaData packageMetaData = bimDatabase.getMetaDataManager().getPackageMetaData(project.getSchema());
    for (EClass eClass : packageMetaData.getAllClasses()) {
        String tableName = bimDatabase.getTableName(eClass);
        if (!keyValueStore.isTransactional(session, tableName)) {
            try (RecordIterator iterator = keyValueStore.getRecordIterator(tableName, buffer.array(), buffer.array(), session, true)) {
                Record record = iterator.next();
                while (record != null) {
                    ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
                    if (keyBuffer.capacity() != 16) {
                        throw new BimserverDatabaseException("Unexpected key size: " + keyBuffer.capacity());
                    }
                    // pid
                    keyBuffer.getInt();
                    // oid
                    keyBuffer.getLong();
                    // rid
                    int recordRid = -keyBuffer.getInt();
                    if (recordRid > rid) {
                        keyValueStore.delete(tableName, record.getKey(), session);
                        removed++;
                    }
                    record = iterator.next();
                }
            }
        }
    }
    return removed;
}
Also used : RecordIterator(org.bimserver.database.RecordIterator) EClass(org.eclipse.emf.ecore.EClass) PackageMetaData(org.bimserver.emf.PackageMetaData) KeyValueStore(org.bimserver.database.KeyValueStore) BerkeleyKeyValueStore(org.bimserver.database.berkeley.BerkeleyKeyValueStore) Record(org.bimserver.database.Record) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PackageMetaData (org.bimserver.emf.PackageMetaData)43 UserException (org.bimserver.shared.exceptions.UserException)30 Revision (org.bimserver.models.store.Revision)22 OldQuery (org.bimserver.database.OldQuery)17 EClass (org.eclipse.emf.ecore.EClass)17 IfcModelInterface (org.bimserver.emf.IfcModelInterface)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 Query (org.bimserver.database.queries.om.Query)13 Project (org.bimserver.models.store.Project)13 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)12 ModelHelper (org.bimserver.plugins.ModelHelper)12 QueryPart (org.bimserver.database.queries.om.QueryPart)11 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 IfcModelSet (org.bimserver.plugins.IfcModelSet)10 MergeException (org.bimserver.plugins.modelmerger.MergeException)10 User (org.bimserver.models.store.User)9 HashMap (java.util.HashMap)8 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)8 List (java.util.List)7 ServerIfcModel (org.bimserver.ServerIfcModel)7