Search in sources :

Example 1 with IfcProject

use of org.bimserver.models.ifc2x3tc1.IfcProject in project BIMserver by opensourceBIM.

the class CommandLine method run.

@Override
public void run() {
    reader = new BufferedReader(new InputStreamReader(System.in));
    running = true;
    try {
        while (running) {
            try {
                String line = reader.readLine();
                if (line == null) {
                    Thread.sleep(50);
                    continue;
                }
                if (line.equalsIgnoreCase("exit")) {
                    bimServer.stop();
                    return;
                } else if (line.startsWith("dumpmodel")) {
                    try {
                        long roid = Long.parseLong(line.substring(9).trim());
                        DatabaseSession databaseSession = bimServer.getDatabase().createSession();
                        try {
                            DownloadDatabaseAction downloadDatabaseAction = new DownloadDatabaseAction(bimServer, databaseSession, AccessMethod.INTERNAL, roid, -1, -1, new SystemAuthorization(1, TimeUnit.HOURS), null);
                            IfcModelInterface model = downloadDatabaseAction.execute();
                            LOGGER.info("Model size: " + model.size());
                            List<IfcWall> walls = model.getAll(IfcWall.class);
                            List<IfcProject> projects = model.getAll(IfcProject.class);
                            List<IfcSlab> slabs = model.getAll(IfcSlab.class);
                            List<IfcWindow> windows = model.getAll(IfcWindow.class);
                            LOGGER.info("Walls: " + walls.size());
                            LOGGER.info("Windows: " + windows.size());
                            LOGGER.info("Projects: " + projects.size());
                            LOGGER.info("Slabs: " + slabs.size());
                        } catch (UserException e) {
                            LOGGER.error("", e);
                        } catch (BimserverLockConflictException e) {
                            LOGGER.error("", e);
                        } catch (BimserverDatabaseException e) {
                            LOGGER.error("", e);
                        } finally {
                            databaseSession.close();
                        }
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equalsIgnoreCase("dump")) {
                    LOGGER.info("Dumping all thread's track traces...");
                    LOGGER.info("");
                    Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
                    for (Thread t : allStackTraces.keySet()) {
                        LOGGER.info(t.getName());
                        StackTraceElement[] stackTraceElements = allStackTraces.get(t);
                        for (StackTraceElement stackTraceElement : stackTraceElements) {
                            LOGGER.info("\t" + stackTraceElement.getClassName() + ":" + stackTraceElement.getLineNumber() + "." + stackTraceElement.getMethodName());
                        }
                        LOGGER.info("");
                    }
                    LOGGER.info("Done printing stack traces");
                    LOGGER.info("");
                    Thread.sleep(10000);
                } else if (line.equals("migrate")) {
                    try {
                        bimServer.getDatabase().getMigrator().migrate();
                        bimServer.getServerInfoManager().update();
                    } catch (MigrationException e) {
                        LOGGER.error("", e);
                    } catch (InconsistentModelsException e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equals("clearendpoints")) {
                    bimServer.getEndPointManager().clear();
                } else if (line.startsWith("showall")) {
                    KeyValueStore keyValueStore = ((Database) bimServer.getDatabase()).getKeyValueStore();
                    Set<String> allTableNames = keyValueStore.getAllTableNames();
                    long total = 0;
                    for (String tableName : allTableNames) {
                        long size = keyValueStore.count(tableName);
                        total += size;
                        if (size != 0) {
                            LOGGER.info(tableName + " " + size);
                        }
                    }
                    LOGGER.info("total: " + total);
                } else {
                    LOGGER.info("Unknown command");
                }
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    } catch (InterruptedException e) {
    }
}
Also used : InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) Set(java.util.Set) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) KeyValueStore(org.bimserver.database.KeyValueStore) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) DownloadDatabaseAction(org.bimserver.database.actions.DownloadDatabaseAction) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) MigrationException(org.bimserver.database.migrations.MigrationException) UserException(org.bimserver.shared.exceptions.UserException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) IfcSlab(org.bimserver.models.ifc2x3tc1.IfcSlab) MigrationException(org.bimserver.database.migrations.MigrationException) BufferedReader(java.io.BufferedReader) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 2 with IfcProject

use of org.bimserver.models.ifc2x3tc1.IfcProject in project BIMserver by opensourceBIM.

the class TestReadProperties method test.

@Test
public void test() {
    try {
        // New client
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
        // Iterate over all projects, there should be 1
        for (IfcProject ifcProject : model.getAllWithSubTypes(IfcProject.class)) {
            for (IfcRelDefines ifcRelDefines : ifcProject.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;
                                IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                                String stringValue = "";
                                if (nominalValue instanceof IfcLabel) {
                                    stringValue = ((IfcLabel) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcIdentifier) {
                                    stringValue = ((IfcIdentifier) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcAreaMeasure) {
                                    stringValue = "" + ((IfcAreaMeasure) nominalValue).getWrappedValue();
                                }
                                if (ifcPropertySingleValue.getName().equals("ConstructionMode")) {
                                    if (!stringValue.equals("Massivbau")) {
                                        fail("Massivbau expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("BuildingPermitId")) {
                                    if (!stringValue.equals("4711")) {
                                        fail("4711 expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("GrossAreaPlanned")) {
                                    if (stringValue == null || !stringValue.equals("1000.0")) {
                                        fail("1000. expected");
                                    }
                                }
                                System.out.println(ifcPropertySingleValue.getName() + ": " + stringValue);
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        if (!(e instanceof AssertionError)) {
            fail(e.getMessage());
        }
    }
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcValue(org.bimserver.models.ifc2x3tc1.IfcValue) IfcProperty(org.bimserver.models.ifc2x3tc1.IfcProperty) IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcAreaMeasure(org.bimserver.models.ifc2x3tc1.IfcAreaMeasure) SProject(org.bimserver.interfaces.objects.SProject) IfcRelDefinesByProperties(org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties) URL(java.net.URL) IfcRelDefines(org.bimserver.models.ifc2x3tc1.IfcRelDefines) IfcLabel(org.bimserver.models.ifc2x3tc1.IfcLabel) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcPropertySet(org.bimserver.models.ifc2x3tc1.IfcPropertySet) IfcPropertySetDefinition(org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition) IfcIdentifier(org.bimserver.models.ifc2x3tc1.IfcIdentifier) Test(org.junit.Test)

Example 3 with IfcProject

use of org.bimserver.models.ifc2x3tc1.IfcProject in project BIMserver by opensourceBIM.

the class RevisionMerger method merge.

public IfcModel merge() throws IfcModelInterfaceException {
    for (IdEObject idEObject : oldModel.getValues()) {
        copy(resultModel, idEObject, false);
    }
    resultModel.indexGuids();
    newModel.fixOids(new IncrementingOidProvider(resultModel.getHighestOid() + 1));
    copyAttributesGuidObjectsAndAddNewObjects();
    updateReferences();
    fixExplicitNullReferences();
    fixNonGuidObjects();
    TracingGarbageCollector tracingGarbageCollector = new TracingGarbageCollector(resultModel);
    Set<IdEObject> rootObjects = new HashSet<IdEObject>();
    for (IdEObject idEObject : resultModel.getValues()) {
        if (idEObject instanceof IfcProject) {
            rootObjects.add(idEObject);
        }
    }
    tracingGarbageCollector.mark(rootObjects);
    tracingGarbageCollector.sweep();
    return resultModel;
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IdEObject(org.bimserver.emf.IdEObject) TracingGarbageCollector(org.bimserver.ifc.TracingGarbageCollector) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) HashSet(java.util.HashSet)

Example 4 with IfcProject

use of org.bimserver.models.ifc2x3tc1.IfcProject in project BIMserver by opensourceBIM.

the class IfcUtils method getLengthUnitPrefix.

public static float getLengthUnitPrefix(IfcModelInterface model) {
    float lengthUnitPrefix = 1.0f;
    boolean prefixFound = false;
    for (IfcProject ifcProject : model.getAll(IfcProject.class)) {
        IfcUnitAssignment unitsInContext = ifcProject.getUnitsInContext();
        if (unitsInContext != null) {
            EList<IfcUnit> units = unitsInContext.getUnits();
            for (IfcUnit unit : units) {
                if (unit instanceof IfcSIUnit) {
                    IfcSIUnit ifcSIUnit = (IfcSIUnit) unit;
                    IfcUnitEnum unitType = ifcSIUnit.getUnitType();
                    if (unitType == IfcUnitEnum.LENGTHUNIT) {
                        IfcSIPrefix prefix = ifcSIUnit.getPrefix();
                        if (prefix != null) {
                            prefixFound = true;
                            switch(prefix) {
                                case EXA:
                                    lengthUnitPrefix = 1.0e18f;
                                    break;
                                case PETA:
                                    lengthUnitPrefix = 1.0e15f;
                                    break;
                                case TERA:
                                    lengthUnitPrefix = 1.0e12f;
                                    break;
                                case GIGA:
                                    lengthUnitPrefix = 1.0e9f;
                                    break;
                                case MEGA:
                                    lengthUnitPrefix = 1.0e6f;
                                    break;
                                case KILO:
                                    lengthUnitPrefix = 1.0e3f;
                                    break;
                                case HECTO:
                                    lengthUnitPrefix = 1.0e2f;
                                    break;
                                case DECA:
                                    lengthUnitPrefix = 1.0e1f;
                                    break;
                                case DECI:
                                    lengthUnitPrefix = 1.0e-1f;
                                    break;
                                case CENTI:
                                    lengthUnitPrefix = 1.0e-2f;
                                    break;
                                case MILLI:
                                    lengthUnitPrefix = 1.0e-3f;
                                    break;
                                case MICRO:
                                    lengthUnitPrefix = 1.0e-6f;
                                    break;
                                case NANO:
                                    lengthUnitPrefix = 1.0e-9f;
                                    break;
                                case PICO:
                                    lengthUnitPrefix = 1.0e-12f;
                                    break;
                                case FEMTO:
                                    lengthUnitPrefix = 1.0e-15f;
                                    break;
                                case ATTO:
                                    lengthUnitPrefix = 1.0e-18f;
                                    break;
                                case NULL:
                                    break;
                            }
                            break;
                        }
                    }
                }
            }
        }
        if (prefixFound)
            break;
    }
    return lengthUnitPrefix;
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcUnitAssignment(org.bimserver.models.ifc2x3tc1.IfcUnitAssignment) IfcSIUnit(org.bimserver.models.ifc2x3tc1.IfcSIUnit) IfcUnitEnum(org.bimserver.models.ifc2x3tc1.IfcUnitEnum) IfcUnit(org.bimserver.models.ifc2x3tc1.IfcUnit) IfcSIPrefix(org.bimserver.models.ifc2x3tc1.IfcSIPrefix)

Example 5 with IfcProject

use of org.bimserver.models.ifc2x3tc1.IfcProject in project BIMserver by opensourceBIM.

the class RichIfcModel method createDefaultProjectStructure.

public IfcBuilding createDefaultProjectStructure() throws IfcModelInterfaceException {
    IfcPerson person = create(IfcPerson.class);
    IfcOrganization organization = create(IfcOrganization.class);
    organization.setName("Required");
    IfcPersonAndOrganization owningUser = create(IfcPersonAndOrganization.class);
    owningUser.setTheOrganization(organization);
    owningUser.setThePerson(person);
    IfcOrganization developer = create(IfcOrganization.class);
    developer.setName("Required");
    IfcApplication application = create(IfcApplication.class);
    application.setApplicationDeveloper(developer);
    application.setApplicationFullName("Required");
    application.setApplicationIdentifier("Required");
    application.setVersion("1.0");
    IfcOwnerHistory ownerHistory = create(IfcOwnerHistory.class);
    ownerHistory.setChangeAction(IfcChangeActionEnum.ADDED);
    ownerHistory.setCreationDate(System.currentTimeMillis() / 1000);
    ownerHistory.setOwningApplication(application);
    ownerHistory.setOwningUser(owningUser);
    setDefaultOwnerHistory(ownerHistory);
    IfcAxis2Placement3D contextAxisPlacement = create(IfcAxis2Placement3D.class);
    contextAxisPlacement.setLocation(createIfcCartesianPoint(0, 0, 0));
    IfcGeometricRepresentationContext representationContext = create(IfcGeometricRepresentationContext.class);
    representationContext.setCoordinateSpaceDimension(3);
    representationContext.setPrecision(0.00001);
    representationContext.setWorldCoordinateSystem(contextAxisPlacement);
    representationContext.setContextType("Model");
    setDefaultRepresentationContext(representationContext);
    IfcUnitAssignment ifcUnitAssigment = create(IfcUnitAssignment.class);
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.CUBIC_METRE));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.RADIAN));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.STERADIAN));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.MASSUNIT, IfcSIPrefix.NULL, IfcSIUnitName.GRAM));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.TIMEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.SECOND));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIPrefix.NULL, IfcSIUnitName.DEGREE_CELSIUS));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIPrefix.NULL, IfcSIUnitName.LUMEN));
    IfcProject ifcProject = create(IfcProject.class);
    ifcProject.getRepresentationContexts().add(representationContext);
    ifcProject.setUnitsInContext(ifcUnitAssigment);
    ifcProject.setName("Demo Project");
    IfcSite ifcSite = create(IfcSite.class);
    ifcSite.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcSite.setName("Default site");
    IfcBuilding ifcBuilding = create(IfcBuilding.class);
    ifcBuilding.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcBuilding.setName("Default building");
    addDecomposes(ifcProject, ifcSite);
    addDecomposes(ifcSite, ifcBuilding);
    return ifcBuilding;
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcOrganization(org.bimserver.models.ifc2x3tc1.IfcOrganization) IfcSite(org.bimserver.models.ifc2x3tc1.IfcSite) IfcUnitAssignment(org.bimserver.models.ifc2x3tc1.IfcUnitAssignment) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcGeometricRepresentationContext(org.bimserver.models.ifc2x3tc1.IfcGeometricRepresentationContext) IfcPerson(org.bimserver.models.ifc2x3tc1.IfcPerson) IfcApplication(org.bimserver.models.ifc2x3tc1.IfcApplication) IfcOwnerHistory(org.bimserver.models.ifc2x3tc1.IfcOwnerHistory) IfcPersonAndOrganization(org.bimserver.models.ifc2x3tc1.IfcPersonAndOrganization) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding)

Aggregations

IfcProject (org.bimserver.models.ifc2x3tc1.IfcProject)5 IfcModelInterface (org.bimserver.emf.IfcModelInterface)2 IfcUnitAssignment (org.bimserver.models.ifc2x3tc1.IfcUnitAssignment)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 KeyValueStore (org.bimserver.database.KeyValueStore)1 DownloadDatabaseAction (org.bimserver.database.actions.DownloadDatabaseAction)1 InconsistentModelsException (org.bimserver.database.migrations.InconsistentModelsException)1 MigrationException (org.bimserver.database.migrations.MigrationException)1 IdEObject (org.bimserver.emf.IdEObject)1 TracingGarbageCollector (org.bimserver.ifc.TracingGarbageCollector)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SProject (org.bimserver.interfaces.objects.SProject)1