Search in sources :

Example 1 with LowLevelInterface

use of org.bimserver.shared.interfaces.LowLevelInterface in project BIMserver by opensourceBIM.

the class TestSetWrappedIntegerGeometry method test.

@Test
public void test() {
    try {
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkin(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/revit_quantities.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, false);
        long tid = lowLevelInterface.startTransaction(newProject.getOid());
        IfcPropertySingleValue ifcPropertySingleValue = model.getAll(IfcPropertySingleValue.class).iterator().next();
        bimServerClient.getLowLevelInterface().setWrappedLongAttribute(tid, ifcPropertySingleValue.getOid(), "NominalValue", "IfcInteger", 12345L);
        long roid = lowLevelInterface.commitTransaction(tid, "v2");
        IfcModelInterface newModel = bimServerClient.getModel(newProject, roid, true, false, true);
        SVector3f minBounds = newModel.getModelMetaData().getMinBounds();
        SVector3f maxBounds = newModel.getModelMetaData().getMaxBounds();
        org.junit.Assert.assertNotNull(minBounds);
        org.junit.Assert.assertNotNull(maxBounds);
        bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test2.ifc"));
        bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SVector3f(org.bimserver.interfaces.objects.SVector3f) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) URL(java.net.URL) Test(org.junit.Test)

Example 2 with LowLevelInterface

use of org.bimserver.shared.interfaces.LowLevelInterface in project BIMserver by opensourceBIM.

the class TestUnsetReference method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Start a transaction
        Long tid = lowLevelInterface.startTransaction(newProject.getOid());
        Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
        Long ifcBuildingOid = lowLevelInterface.createObject(tid, "IfcBuilding", true);
        lowLevelInterface.setReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure", ifcBuildingOid);
        lowLevelInterface.commitTransaction(tid, "Initial");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        lowLevelInterface.unsetReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure");
        lowLevelInterface.commitTransaction(tid, "unset reference");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        if (lowLevelInterface.getReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure") != -1) {
            fail("Relation should be unset");
        }
        lowLevelInterface.abortTransaction(tid);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 3 with LowLevelInterface

use of org.bimserver.shared.interfaces.LowLevelInterface in project BIMserver by opensourceBIM.

the class TestCreateLists method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Start a transaction
        Long tid = lowLevelInterface.startTransaction(newProject.getOid());
        Long cartesianPointOid = lowLevelInterface.createObject(tid, "IfcCartesianPoint", false);
        double firstVal = 5.1;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", firstVal);
        double secondVal = 6.2;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", secondVal);
        double thirdVal = 7.3;
        lowLevelInterface.addDoubleAttribute(tid, cartesianPointOid, "Coordinates", thirdVal);
        // Commit the transaction
        lowLevelInterface.commitTransaction(tid, "test");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        List<Double> coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        assertTrue(coordinates.get(0) == firstVal && coordinates.get(1) == secondVal && coordinates.get(2) == thirdVal);
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        ArrayList<Double> al = new ArrayList<Double>();
        al.add(1.0);
        al.add(2.0);
        al.add(3.0);
        lowLevelInterface.setDoubleAttributes(tid, cartesianPointOid, "Coordinates", al);
        lowLevelInterface.commitTransaction(tid, "replace");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        if (coordinates.size() != 3) {
            fail("Coordinates size should be 3, it is " + coordinates.size());
        }
        assertTrue(coordinates.get(0) == 1.0 && coordinates.get(1) == 2.0 && coordinates.get(2) == 3.0);
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        lowLevelInterface.setDoubleAttributeAtIndex(tid, cartesianPointOid, "Coordinates", 1, 5.0);
        lowLevelInterface.commitTransaction(tid, "changed middle one");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        coordinates = lowLevelInterface.getDoubleAttributes(tid, cartesianPointOid, "Coordinates");
        if (coordinates.size() != 3) {
            fail("Coordinates size should be 3, it is " + coordinates.size());
        }
        assertTrue(coordinates.get(0) + ", " + coordinates.get(1) + ", " + coordinates.get(2), coordinates.get(0) == 1.0 && coordinates.get(1) == 5.0 && coordinates.get(2) == 3.0);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) ArrayList(java.util.ArrayList) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 4 with LowLevelInterface

use of org.bimserver.shared.interfaces.LowLevelInterface in project BIMserver by opensourceBIM.

the class TestGeometry method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the low level interface
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        long start = System.nanoTime();
        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"));
        // bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, Paths.get("D:\\Dropbox\\Shared\\IFC files\\ArenA 2014\\3D IFC\\arena.ifc"));
        long end = System.nanoTime();
        System.out.println(((end - start) / 1000000) + " ms");
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        int nrTriangles = 0;
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true, true);
        Assert.assertNotNull(model.getModelMetaData().getMinBounds());
        Assert.assertNotNull(model.getModelMetaData().getMaxBounds());
        for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
            GeometryInfo geometryInfo = ifcProduct.getGeometry();
            if (geometryInfo != null) {
                Vector3f minBounds = geometryInfo.getMinBounds();
                Vector3f maxBounds = geometryInfo.getMinBounds();
                Assert.assertNotNull(minBounds);
                Assert.assertNotNull(maxBounds);
                nrTriangles += geometryInfo.getPrimitiveCount();
            }
        }
        Assert.assertEquals(45260, nrTriangles);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Vector3f(org.bimserver.models.geometry.Vector3f) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 5 with LowLevelInterface

use of org.bimserver.shared.interfaces.LowLevelInterface in project BIMserver by opensourceBIM.

the class TestRemoveObject method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Start a transaction
        Long tid = lowLevelInterface.startTransaction(newProject.getOid());
        Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
        Long ifcBuildingOid = lowLevelInterface.createObject(tid, "IfcBuilding", true);
        lowLevelInterface.addReference(tid, ifcBuildingOid, "ContainsElements", ifcRelContainedInSpatialStructureOid);
        lowLevelInterface.commitTransaction(tid, "Initial");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        lowLevelInterface.removeObject(tid, ifcBuildingOid);
        lowLevelInterface.commitTransaction(tid, "removed");
        tid = lowLevelInterface.startTransaction(newProject.getOid());
        long reference = lowLevelInterface.getReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure");
        if (reference != -1) {
            fail("Should be unset (is " + reference + ")");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Aggregations

LowLevelInterface (org.bimserver.shared.interfaces.LowLevelInterface)20 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)19 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)19 Test (org.junit.Test)19 SProject (org.bimserver.interfaces.objects.SProject)18 URL (java.net.URL)5 IfcModelInterface (org.bimserver.emf.IfcModelInterface)5 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)5 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)5 IfcPropertySingleValue (org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue)3 UserException (org.bimserver.shared.exceptions.UserException)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 IdEObject (org.bimserver.emf.IdEObject)1 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)1 SVector3f (org.bimserver.interfaces.objects.SVector3f)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1 Vector3f (org.bimserver.models.geometry.Vector3f)1 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)1 IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)1