コード例 #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();
    }
  }
コード例 #2
0
 @Override
 public void execute(VirtualUser virtualUser)
     throws ServerException, UserException, PublicInterfaceNotFoundException {
   SRevision randomRevision = virtualUser.getRandomRevision();
   if (randomRevision != null) {
     IfcModelInterface model;
     try {
       SProject project =
           virtualUser
               .getBimServerClient()
               .getBimsie1ServiceInterface()
               .getProjectByPoid(randomRevision.getProjectId());
       model =
           virtualUser
               .getBimServerClient()
               .getModel(project, randomRevision.getOid(), true, false);
       PluginManager pluginManager = getTestFramework().getPluginManager();
       SerializerPlugin serializerPlugin =
           pluginManager.getSerializerPlugin(
               "org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
       Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration());
       model.generateMinimalExpressIds();
       serializer.init(
           model, null, pluginManager, pluginManager.requireRenderEngine(), null, false);
       serializer.writeToFile(
           new File(getTestFramework().getTestConfiguration().getOutputFolder(), "test.ifc"),
           null);
     } catch (BimServerClientException e1) {
       e1.printStackTrace();
     } catch (RenderEngineException e) {
       e.printStackTrace();
     } catch (PluginException e) {
       e.printStackTrace();
     } catch (SerializerException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #3
0
  public static void main(String[] args) {
    try {
      PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(new File("home"));
      DeserializerPlugin deserializerPlugin =
          pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);

      Deserializer deserializer = deserializerPlugin.createDeserializer(null);
      deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));

      IfcModelInterface model =
          deserializer.read(new File("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));

      deserializer = deserializerPlugin.createDeserializer(null);
      deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
      IfcModelInterface furnishingModel = deserializer.read(new File("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.requireSchemaDefinition("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, pluginManager, null, null, true);
      serializer.writeToFile(new File("withfurn.ifc"), null);
    } catch (PluginException e) {
      e.printStackTrace();
    } catch (DeserializeException e) {
      e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
      e.printStackTrace();
    } catch (SerializerException e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
  @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;
  }
コード例 #5
0
 public void updateUserSettings(DatabaseSession session, User user)
     throws BimserverLockConflictException, BimserverDatabaseException {
   UserSettings userSettings = user.getUserSettings();
   if (userSettings == null) {
     userSettings = session.create(UserSettings.class);
     user.setUserSettings(userSettings);
     session.store(user);
   }
   for (ObjectIDMPlugin objectIDMPlugin : pluginManager.getAllObjectIDMPlugins(true)) {
     ObjectIDMPluginConfiguration objectIdmPluginConfiguration =
         find(userSettings.getObjectIDMs(), objectIDMPlugin.getClass().getName());
     if (objectIdmPluginConfiguration == null) {
       objectIdmPluginConfiguration = session.create(ObjectIDMPluginConfiguration.class);
       userSettings.getObjectIDMs().add(objectIdmPluginConfiguration);
       genericPluginConversion(
           session,
           objectIDMPlugin,
           objectIdmPluginConfiguration,
           getPluginDescriptor(session, objectIDMPlugin.getClass().getName()));
     }
     if (userSettings.getDefaultObjectIDM() == null
         && objectIDMPlugin.getClass() == SchemaFieldObjectIDMPlugin.class) {
       userSettings.setDefaultObjectIDM(objectIdmPluginConfiguration);
     }
   }
   if (userSettings.getDefaultObjectIDM() == null && !userSettings.getObjectIDMs().isEmpty()) {
     userSettings.setDefaultObjectIDM(userSettings.getObjectIDMs().get(0));
   }
   for (RenderEnginePlugin ifcEnginePlugin : pluginManager.getAllRenderEnginePlugins(true)) {
     RenderEnginePluginConfiguration ifcEnginePluginConfiguration =
         find(userSettings.getRenderEngines(), ifcEnginePlugin.getClass().getName());
     if (ifcEnginePluginConfiguration == null) {
       ifcEnginePluginConfiguration = session.create(RenderEnginePluginConfiguration.class);
       userSettings.getRenderEngines().add(ifcEnginePluginConfiguration);
       genericPluginConversion(
           session,
           ifcEnginePlugin,
           ifcEnginePluginConfiguration,
           getPluginDescriptor(session, ifcEnginePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultRenderEngine() != null
         && userSettings
             .getDefaultRenderEngine()
             .getPluginDescriptor()
             .getPluginClassName()
             .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin")
         && ifcEnginePlugin
             .getClass()
             .getName()
             .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) {
       userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration);
     }
     if (userSettings.getDefaultRenderEngine() == null
         && ifcEnginePlugin
             .getClass()
             .getName()
             .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) {
       userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration);
     }
   }
   if (userSettings.getDefaultRenderEngine() == null
       && !userSettings.getRenderEngines().isEmpty()) {
     userSettings.setDefaultRenderEngine(userSettings.getRenderEngines().get(0));
   }
   Iterator<RenderEnginePluginConfiguration> iterator = userSettings.getRenderEngines().iterator();
   while (iterator.hasNext()) {
     RenderEnginePluginConfiguration next = iterator.next();
     PluginDescriptor pluginDescriptor = next.getPluginDescriptor();
     if (pluginDescriptor
         .getPluginClassName()
         .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin")) {
       iterator.remove();
     }
   }
   for (QueryEnginePlugin queryEnginePlugin : pluginManager.getAllQueryEnginePlugins(true)) {
     QueryEnginePluginConfiguration queryEnginePluginConfiguration =
         find(userSettings.getQueryengines(), queryEnginePlugin.getClass().getName());
     if (queryEnginePluginConfiguration == null) {
       queryEnginePluginConfiguration = session.create(QueryEnginePluginConfiguration.class);
       userSettings.getQueryengines().add(queryEnginePluginConfiguration);
       genericPluginConversion(
           session,
           queryEnginePlugin,
           queryEnginePluginConfiguration,
           getPluginDescriptor(session, queryEnginePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultQueryEngine() == null
         && queryEnginePlugin
             .getClass()
             .getName()
             .equals("nl.wietmazairac.bimql.BimQLQueryEnginePlugin")) {
       userSettings.setDefaultQueryEngine(queryEnginePluginConfiguration);
     }
   }
   if (userSettings.getDefaultQueryEngine() == null && !userSettings.getQueryengines().isEmpty()) {
     userSettings.setDefaultQueryEngine(userSettings.getQueryengines().get(0));
   }
   for (ModelMergerPlugin modelMergerPlugin : pluginManager.getAllModelMergerPlugins(true)) {
     ModelMergerPluginConfiguration modelMergerPluginConfiguration =
         find(userSettings.getModelmergers(), modelMergerPlugin.getClass().getName());
     if (modelMergerPluginConfiguration == null) {
       modelMergerPluginConfiguration = session.create(ModelMergerPluginConfiguration.class);
       userSettings.getModelmergers().add(modelMergerPluginConfiguration);
       genericPluginConversion(
           session,
           modelMergerPlugin,
           modelMergerPluginConfiguration,
           getPluginDescriptor(session, modelMergerPlugin.getClass().getName()));
     }
     if (userSettings.getDefaultModelMerger() == null
         && modelMergerPlugin
             .getClass()
             .getName()
             .equals("org.bimserver.merging.BasicModelMergerPlugin")) {
       userSettings.setDefaultModelMerger(modelMergerPluginConfiguration);
     }
   }
   if (userSettings.getDefaultModelMerger() == null && !userSettings.getModelmergers().isEmpty()) {
     userSettings.setDefaultModelMerger(userSettings.getModelmergers().get(0));
   }
   for (ModelComparePlugin modelComparePlugin : pluginManager.getAllModelComparePlugins(true)) {
     ModelComparePluginConfiguration modelComparePluginConfiguration =
         find(userSettings.getModelcompares(), modelComparePlugin.getClass().getName());
     if (modelComparePluginConfiguration == null) {
       modelComparePluginConfiguration = session.create(ModelComparePluginConfiguration.class);
       userSettings.getModelcompares().add(modelComparePluginConfiguration);
       genericPluginConversion(
           session,
           modelComparePlugin,
           modelComparePluginConfiguration,
           getPluginDescriptor(session, modelComparePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultModelCompare() == null
         && modelComparePlugin
             .getClass()
             .getName()
             .equals("org.bimserver.ifc.compare.GuidBasedModelComparePlugin")) {
       userSettings.setDefaultModelCompare(modelComparePluginConfiguration);
     }
   }
   if (userSettings.getDefaultModelCompare() == null
       && !userSettings.getModelcompares().isEmpty()) {
     userSettings.setDefaultModelCompare(userSettings.getModelcompares().get(0));
   }
   for (SerializerPlugin serializerPlugin : pluginManager.getAllSerializerPlugins(true)) {
     SerializerPluginConfiguration serializerPluginConfiguration =
         find(userSettings.getSerializers(), serializerPlugin.getClass().getName());
     if (serializerPluginConfiguration == null) {
       serializerPluginConfiguration = session.create(SerializerPluginConfiguration.class);
       userSettings.getSerializers().add(serializerPluginConfiguration);
       genericPluginConversion(
           session,
           serializerPlugin,
           serializerPluginConfiguration,
           getPluginDescriptor(session, serializerPlugin.getClass().getName()));
       serializerPluginConfiguration.setObjectIDM(userSettings.getDefaultObjectIDM());
       serializerPluginConfiguration.setRenderEngine(userSettings.getDefaultRenderEngine());
     }
     if (userSettings.getDefaultSerializer() == null
         && serializerPlugin
             .getClass()
             .getName()
             .equals("org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializerPlugin")) {
       userSettings.setDefaultSerializer(serializerPluginConfiguration);
     }
   }
   for (MessagingSerializerPlugin serializerPlugin :
       pluginManager.getAllMessagingSerializerPlugins(true)) {
     MessagingSerializerPluginConfiguration serializerPluginConfiguration =
         find(userSettings.getMessagingSerializerPlugins(), serializerPlugin.getClass().getName());
     if (serializerPluginConfiguration == null) {
       serializerPluginConfiguration =
           session.create(MessagingSerializerPluginConfiguration.class);
       userSettings.getMessagingSerializerPlugins().add(serializerPluginConfiguration);
       genericPluginConversion(
           session,
           serializerPlugin,
           serializerPluginConfiguration,
           getPluginDescriptor(session, serializerPlugin.getClass().getName()));
     }
   }
   if (userSettings.getDefaultSerializer() == null && !userSettings.getSerializers().isEmpty()) {
     userSettings.setDefaultSerializer(userSettings.getSerializers().get(0));
   }
   for (ServicePlugin servicePlugin : pluginManager.getAllServicePlugins(true)) {
     InternalServicePluginConfiguration internalServicePluginConfiguration =
         find(userSettings.getServices(), servicePlugin.getClass().getName());
     if (internalServicePluginConfiguration == null) {
       internalServicePluginConfiguration =
           session.create(InternalServicePluginConfiguration.class);
       userSettings.getServices().add(internalServicePluginConfiguration);
       genericPluginConversion(
           session,
           servicePlugin,
           internalServicePluginConfiguration,
           getPluginDescriptor(session, servicePlugin.getClass().getName()));
     }
     ObjectType settings = internalServicePluginConfiguration.getSettings();
     SInternalServicePluginConfiguration sInternalService =
         getSConverter().convertToSObject(internalServicePluginConfiguration);
     servicePlugin.register(
         user.getOid(), sInternalService, new org.bimserver.plugins.PluginConfiguration(settings));
   }
   for (DeserializerPlugin deserializerPlugin : pluginManager.getAllDeserializerPlugins(true)) {
     DeserializerPluginConfiguration deserializerPluginConfiguration =
         find(userSettings.getDeserializers(), deserializerPlugin.getClass().getName());
     if (deserializerPluginConfiguration == null) {
       deserializerPluginConfiguration = session.create(DeserializerPluginConfiguration.class);
       userSettings.getDeserializers().add(deserializerPluginConfiguration);
       genericPluginConversion(
           session,
           deserializerPlugin,
           deserializerPluginConfiguration,
           getPluginDescriptor(session, deserializerPlugin.getClass().getName()));
     }
   }
   session.store(userSettings);
 }