예제 #1
0
  private void start() {
    try {
      File testFiles = new File("../TestData/data");
      File output = new File("output");
      PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(new File("home"));

      DeserializerPlugin ifcDeserializerPlugin = pluginManager.getFirstDeserializer("ifc", true);

      SerializerPlugin serializerPlugin =
          pluginManager.getFirstSerializerPlugin("application/collada", true);
      for (File file : testFiles.listFiles()) {
        if (file.isFile()
            && file.getName().endsWith(".ifc")
            && file.getName().equals("Vogel_Gesamt.ifc")) {
          System.out.println(file.getName());
          ProjectInfo projectInfo = new ProjectInfo();
          projectInfo.setAuthorName("test");
          projectInfo.setDescription("");

          EmfDeserializer ifcDeserializer = ifcDeserializerPlugin.createDeserializer();
          ifcDeserializer.init(pluginManager.requireSchemaDefinition());
          IfcModelInterface model = ifcDeserializer.read(file, true);

          EmfSerializer serializer = serializerPlugin.createSerializer();
          serializer.init(
              model,
              projectInfo,
              pluginManager,
              pluginManager.requireIfcEngine().createIfcEngine());
          serializer.writeToFile(new File(output, file.getName() + ".dae"));
        }
      }
    } catch (PluginException e) {
      e.printStackTrace();
    } catch (DeserializeException e) {
      e.printStackTrace();
    } catch (SerializerException e) {
      e.printStackTrace();
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public Set<T> execute()
      throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Map<Long, Revision> oidToRoidMap = new HashMap<Long, Revision>();

    // Look in the cache
    Set<EidClash> clashDetections =
        bimServer.getClashDetectionCache().getClashDetection(clashDetectionSettings);
    if (clashDetections != null) {
      return (Set<T>) clashDetections;
    }

    Project project = null;
    IfcModelSet ifcModelSet = new IfcModelSet();
    for (Revision revision : clashDetectionSettings.getRevisions()) {
      project = revision.getProject();
      for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
        IfcModel source = new IfcModel();
        getDatabaseSession()
            .getMap(
                source,
                concreteRevision.getProject().getId(),
                concreteRevision.getId(),
                true,
                null);
        source.setDate(concreteRevision.getDate());
        ifcModelSet.add(source);
        for (Long oid : source.keySet()) {
          oidToRoidMap.put(oid, revision);
        }
      }
    }
    IfcModelInterface ifcModel =
        bimServer.getMergerFactory().createMerger().merge(project, ifcModelSet, false);
    IfcModel newModel = new IfcModel();
    Map<IdEObject, IdEObject> converted = new HashMap<IdEObject, IdEObject>();
    for (IdEObject idEObject : ifcModel.getValues()) {
      if (!clashDetectionSettings.getIgnoredClasses().contains(idEObject.eClass().getName())) {
        cleanupModel(idEObject.eClass(), idEObject, newModel, ifcModel, converted);
      }
    }
    Collection<SerializerPlugin> allSerializerPlugins =
        bimServer.getPluginManager().getAllSerializerPlugins("application/ifc", true);
    if (!allSerializerPlugins.isEmpty()) {
      SerializerPlugin serializerPlugin = allSerializerPlugins.iterator().next();
      EmfSerializer ifcSerializer = serializerPlugin.createSerializer();
      try {
        try {
          ifcSerializer.init(
              newModel,
              null,
              bimServer.getPluginManager(),
              bimServer.getPluginManager().requireIfcEngine().createIfcEngine());
          byte[] bytes = ifcSerializer.getBytes();
          Plugin plugin =
              bimServer
                  .getPluginManager()
                  .getPlugin("org.bimserver.ifcengine.TNOIfcEnginePlugin", true);
          if (plugin != null && plugin instanceof IfcEnginePlugin) {
            IfcEnginePlugin ifcEnginePlugin = (IfcEnginePlugin) plugin;
            IfcEngine ifcEngine = ifcEnginePlugin.createIfcEngine();
            ifcEngine.init();
            IfcEngineModel ifcEngineModel = ifcEngine.openModel(bytes);
            try {
              Set<IfcEngineClash> clashes =
                  ifcEngineModel.findClashesWithEids(clashDetectionSettings.getMargin());

              Set<EidClash> eidClashes = new HashSet<EidClash>();
              for (IfcEngineClash clash : clashes) {
                EidClash eidClash = StoreFactory.eINSTANCE.createEidClash();
                eidClash.setEid1(clash.getEid1());
                eidClash.setEid2(clash.getEid2());
                eidClash.setName1(clash.getName1());
                eidClash.setName2(clash.getName2());
                eidClash.setType1(clash.getType1());
                eidClash.setType2(clash.getType2());
                eidClashes.add(eidClash);
              }

              // Store in cache
              bimServer
                  .getClashDetectionCache()
                  .storeClashDetection(clashDetectionSettings, eidClashes);

              for (EidClash clash : eidClashes) {
                IfcRoot object1 = (IfcRoot) newModel.get(clash.getEid1());
                clash.setName1(object1.getName());
                clash.setType1(object1.eClass().getName());
                clash.setRevision1(oidToRoidMap.get(clash.getEid1()));
                IfcRoot object2 = (IfcRoot) newModel.get(clash.getEid2());
                clash.setName2(object2.getName());
                clash.setType2(object2.eClass().getName());
                clash.setRevision2(oidToRoidMap.get(clash.getEid2()));
              }
              return (Set<T>) eidClashes;
            } finally {
              ifcEngineModel.close();
              ifcEngine.close();
            }
          }
        } catch (PluginException e) {
          LOGGER.error("", e);
        }
      } catch (SerializerException e) {
        LOGGER.error("", e);
      }
    }
    return null;
  }