private void applyIDMFilter(IfcModelInterface model) {
    try {
      ObjectIDM objectIDM = cobieToolkit.getObjectIDM();
      if (objectIDM != null) {
        ArrayList<IdEObject> removeTheseObjects = new ArrayList<IdEObject>();
        for (long key : model.getObjects().keySet()) {
          IdEObject candidateObject = model.get(key);
          boolean shouldIncludeObject =
              objectIDM.shouldIncludeClass(candidateObject.eClass(), candidateObject.eClass());
          for (EStructuralFeature feature : candidateObject.eClass().getEAllStructuralFeatures()) {
            boolean shouldFollowReference =
                objectIDM.shouldFollowReference(
                    candidateObject.eClass(), candidateObject.eClass(), feature);
            if (!shouldFollowReference) {
              candidateObject.eUnset(feature);
            }
          }
          if (!shouldIncludeObject) {
            removeTheseObjects.add(candidateObject);
          }
        }
        for (IdEObject ideObject : removeTheseObjects) {
          model.remove(ideObject);
        }
      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 @SuppressWarnings("unchecked")
 private IdEObject cleanupModel(
     EClass originalEClass,
     IdEObject original,
     IfcModelInterface newModel,
     IfcModelInterface ifcModel,
     Map<IdEObject, IdEObject> converted)
     throws UserException {
   if (converted.containsKey(original)) {
     return converted.get(original);
   }
   IdEObject newObject =
       (IdEObject) original.eClass().getEPackage().getEFactoryInstance().create(original.eClass());
   ((IdEObjectImpl) newObject).setOid(original.getOid());
   converted.put(original, newObject);
   if (!(newObject instanceof WrappedValue) && !(newObject instanceof IfcGloballyUniqueId)) {
     newModel.add(newObject.getOid(), newObject);
   }
   ObjectIDM objectIDM;
   try {
     objectIDM = bimServer.getPluginManager().requireObjectIDM();
   } catch (ObjectIDMException e) {
     throw new UserException(e);
   }
   for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
     if (objectIDM.shouldFollowReference(originalEClass, original.eClass(), eStructuralFeature)) {
       Object get = original.eGet(eStructuralFeature);
       if (eStructuralFeature instanceof EAttribute) {
         if (get instanceof Double) {
           EStructuralFeature doubleStringFeature =
               original.eClass().getEStructuralFeature("wrappedValueAsString");
           if (doubleStringFeature != null) {
             Object doubleString = original.eGet(doubleStringFeature);
             newObject.eSet(doubleStringFeature, doubleString);
           } else {
             newObject.eSet(eStructuralFeature, get);
           }
         } else {
           newObject.eSet(eStructuralFeature, get);
         }
       } else if (eStructuralFeature instanceof EReference) {
         if (get == null) {
         } else {
           if (eStructuralFeature.isMany()) {
             BasicEList<EObject> list = (BasicEList<EObject>) get;
             BasicEList<EObject> toList = (BasicEList<EObject>) newObject.eGet(eStructuralFeature);
             for (Object o : list) {
               if (converted.containsKey(o)) {
                 toList.addUnique(converted.get(o));
               } else {
                 IdEObject result =
                     cleanupModel(originalEClass, (IdEObject) o, newModel, ifcModel, converted);
                 if (result != null) {
                   toList.addUnique(result);
                 }
               }
             }
           } else {
             if (converted.containsKey(get)) {
               newObject.eSet(eStructuralFeature, converted.get(get));
             } else {
               newObject.eSet(
                   eStructuralFeature,
                   cleanupModel(originalEClass, (IdEObject) get, newModel, ifcModel, converted));
             }
           }
         }
       }
     }
   }
   return newObject;
 }