private void setClassificationInverseSlots(IfcModelInterface model) {

    for (IfcRelAssociatesClassification classificationAssociation :
        model.getAllWithSubTypes(IfcRelAssociatesClassification.class)) {
      for (IfcRoot relatedObject : classificationAssociation.getRelatedObjects()) {
        if (relatedObject instanceof IfcPropertySetDefinition) {
          try {
            IfcPropertySetDefinition propertySetDefinition =
                (IfcPropertySetDefinition) relatedObject;
            if (!propertySetDefinition.getHasAssociations().contains(classificationAssociation)) {
              propertySetDefinition.getHasAssociations().add(classificationAssociation);
            }
          } catch (Exception ex) {

          }
        } else if (relatedObject instanceof IfcObjectDefinition) {
          try {
            IfcObjectDefinition objectDefinition = (IfcObjectDefinition) relatedObject;
            if (!objectDefinition.getHasAssociations().contains(classificationAssociation)) {;
            }
            objectDefinition.getHasAssociations().add(classificationAssociation);
          } catch (Exception ex) {

          }
        }
      }
    }
  }
Exemplo n.º 2
0
 /*
  * This will list all projects, select the first project with at least one
  * revision and dump the names of all walls within the last revision of that
  * project
  */
 @Test
 public void testDump() {
   try {
     ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
     ServiceInterface service = serviceMap.get(ServiceInterface.class);
     String token = serviceMap.get(AuthInterface.class).login(username, password);
     service =
         bimServer
             .getServiceFactory()
             .get(token, AccessMethod.INTERNAL)
             .get(ServiceInterface.class);
     BimDatabase database = bimServer.getDatabase();
     DatabaseSession session = database.createSession();
     SProject firstProjectWithRevisions = null;
     for (SProject project : serviceMap.getServiceInterface().getAllProjects(false, true)) {
       System.out.println(project.getName());
       if (!project.getRevisions().isEmpty() && firstProjectWithRevisions == null) {
         firstProjectWithRevisions = project;
       }
     }
     if (firstProjectWithRevisions != null) {
       long roid = firstProjectWithRevisions.getLastRevisionId();
       DownloadDatabaseAction downloadDatabaseAction =
           new DownloadDatabaseAction(
               bimServer,
               session,
               AccessMethod.INTERNAL,
               roid,
               -1,
               -1,
               ((ServiceImpl) service).getAuthorization(),
               null);
       IfcModelInterface ifcModelInterface = downloadDatabaseAction.execute();
       for (IfcWall ifcWall : ifcModelInterface.getAllWithSubTypes(IfcWall.class)) {
         System.out.println(ifcWall.getName());
       }
     }
   } catch (ServiceException e) {
     e.printStackTrace();
   } catch (BimserverDatabaseException e) {
     e.printStackTrace();
   } catch (PublicInterfaceNotFoundException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 3
0
  @Test
  public void test() {
    try {
      // New client
      BimServerClientInterface bimServerClient =
          getFactory()
              .create(new UsernamePasswordAuthenticationInfo("*****@*****.**", "admin"));

      // Create a project
      SProject project =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProject("test" + Math.random(), "ifc2x3tc1");

      // Look for a deserializer
      SDeserializerPluginConfiguration deserializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSuggestedDeserializerForExtension("ifc", project.getOid());

      bimServerClient.checkin(
          project.getOid(),
          "test",
          deserializer.getOid(),
          false,
          true,
          new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"));

      // Refresh project
      project = bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(project.getOid());

      // Load model without lazy loading (complete model at once)
      IfcModelInterface model =
          bimServerClient.getModel(project, project.getLastRevisionId(), true, false);

      String propertyName = "BooleanProperty";

      int nrWindowsFirst = 0;
      // Iterate over all projects, there should be 1
      for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
        nrWindowsFirst++;
        createProperty(window, model, propertyName, "Description of property", true);
      }

      model.commit("Added boolean properties to " + nrWindowsFirst + " windows");

      project = bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(project.getOid());
      model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
      int foundOke = 0;
      int nrWindowsSecond = 0;
      Set<Long> counted = new HashSet<Long>();
      for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
        nrWindowsSecond++;
        for (IfcRelDefines ifcRelDefines : window.getIsDefinedBy()) {
          if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
            IfcRelDefinesByProperties ifcRelDefinesByProperties =
                (IfcRelDefinesByProperties) ifcRelDefines;
            IfcPropertySetDefinition relatingPropertyDefinition =
                ifcRelDefinesByProperties.getRelatingPropertyDefinition();
            if (relatingPropertyDefinition instanceof IfcPropertySet) {
              IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
              for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
                if (ifcProperty instanceof IfcPropertySingleValue) {
                  IfcPropertySingleValue ifcPropertySingleValue =
                      (IfcPropertySingleValue) ifcProperty;
                  if (ifcPropertySingleValue.getName().equals(propertyName)) {
                    IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                    if (nominalValue instanceof IfcBoolean) {
                      if (((IfcBoolean) nominalValue).getWrappedValue() == Tristate.TRUE) {
                        if (!counted.contains(ifcPropertySingleValue.getOid())) {
                          foundOke++;
                          counted.add(ifcPropertySingleValue.getOid());
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      LOGGER.info("Windows first: " + nrWindowsFirst);
      LOGGER.info("Windows second: " + nrWindowsSecond);
      LOGGER.info("Found Oke: " + foundOke);
      if (foundOke != nrWindowsFirst) {
        fail(foundOke + " / " + nrWindowsFirst);
      }
    } catch (Throwable e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Exemplo n.º 4
0
  private static void exportBAMieClassificationReferences(
      IfcModelInterface model,
      LogHandler loggerHandler,
      ArrayList<String> documentNames,
      COBIEType.Documents documents) {
    String name;
    String createdBy;
    Calendar createdOn;
    String category;
    String approvalBy;
    String stage;
    String sheetName;
    String rowName;
    String directory;
    String extSystem;
    String extObject;
    String extIdentifier;
    String description;
    String reference;
    IfcOwnerHistory oh;
    DocumentType tempDocument;
    for (IfcDistributionElement element : model.getAllWithSubTypes(IfcDistributionElement.class)) {
      try {
        for (IfcRelAssociates relAssociates : element.getHasAssociations()) {
          if (relAssociates instanceof IfcRelAssociatesClassification) {
            category = COBieIfcUtility.getObjectClassificationCategoryString(element);
            if (ClassificationHandler.isBAMieRelAssociatesClassification(
                (IfcRelAssociatesClassification) relAssociates)) {
              name = COBieUtility.getCOBieString(element.getName());
              oh = element.getOwnerHistory();
              createdBy = COBieIfcUtility.getEmailFromOwnerHistory(oh);
              createdOn = IfcToContact.getCreatedOn(oh.getCreationDate());
              category = IfcToDocument.BAMIE_CATEGORY;
              approvalBy = IfcToDocument.ApprovalBy;
              stage = IfcToDocument.Stage;
              sheetName = COBieUtility.CobieSheetName.Component.name();
              rowName = IfcToDocument.bamieRowNameFromDistributionElement(element);
              extSystem = COBieIfcUtility.getApplicationName(oh);
              extObject = IfcToComponent.extObjectFromProduct(element);
              extIdentifier = COBieIfcUtility.extIdFromRoot(element);
              description = COBieUtility.getCOBieString(element.getName());
              reference = IfcToDocument.Reference;

              IfcClassificationReference classificationReference =
                  COBieIfcUtility.getObjectClassificationReference(element);
              directory = COBieUtility.getCOBieString(classificationReference.getLocation());

              tempDocument = documents.addNewDocument();
              tempDocument.setName(name);
              tempDocument.setCreatedBy(createdBy);
              tempDocument.setCreatedOn(createdOn);
              tempDocument.setCategory(category);
              tempDocument.setApprovalBy(approvalBy);
              tempDocument.setStage(stage);
              tempDocument.setSheetName(sheetName);
              tempDocument.setRowName(rowName);
              tempDocument.setDirectory(directory);
              tempDocument.setFile(COBieUtility.COBieNA);
              tempDocument.setExtSystem(extSystem);
              tempDocument.setExtObject(extObject);
              tempDocument.setExtIdentifier(extIdentifier);
              tempDocument.setDescription(description);
              tempDocument.setReference(reference);
              loggerHandler.rowWritten();
            }
          }
        }
      } catch (Exception ex) {

      }
    }
  }
Exemplo n.º 5
0
  @Test
  public void test() {
    try {
      // Create a new BimServerClient with authentication
      BimServerClientInterface bimServerClient =
          getFactory()
              .create(new UsernamePasswordAuthenticationInfo("*****@*****.**", "admin"));

      // Create a new project
      SProject newProject =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProject("test" + Math.random(), "ifc2x3tc1");

      // Get the appropriate deserializer
      SDeserializerPluginConfiguration deserializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSuggestedDeserializerForExtension("ifc", newProject.getOid());

      // Checkin the file
      bimServerClient.checkin(
          newProject.getOid(),
          "test",
          deserializer.getOid(),
          false,
          true,
          new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"));

      // Refresh project info
      newProject =
          bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(newProject.getOid());

      IfcModelInterface model =
          bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
      for (IfcFurnishingElement ifcFurnishingElement :
          model.getAllWithSubTypes(IfcFurnishingElement.class)) {
        IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
        if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
          IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
          IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
          if (relativePlacement != null) {
            if (relativePlacement instanceof IfcAxis2Placement3D) {
              IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
              IfcCartesianPoint location = axis2Placement3D.getLocation();
              double newValue = location.getCoordinates().get(2) + 50;
              System.out.println(
                  "Changing z value of "
                      + ifcFurnishingElement.getName()
                      + " from "
                      + location.getCoordinates().get(2)
                      + " to "
                      + newValue);
              location.getCoordinates().set(2, newValue);
            }
          }
        }
      }
      long newRoid = model.commit("Moved all furniture 50 meters up");
      SSerializerPluginConfiguration ifcSerializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSerializerByContentType("application/ifc");
      bimServerClient.download(newRoid, ifcSerializer.getOid(), new File("movedf.ifc"));
    } catch (Throwable e) {
      e.printStackTrace();
      if (e instanceof AssertionError) {
        throw (AssertionError) e;
      }
      fail(e.getMessage());
    }
  }