Search in sources :

Example 1 with Ifc2x3tc1StepSerializer

use of org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer in project BIMserver by opensourceBIM.

the class TestBigModelEmfRemote method test.

@Test
public void test() {
    boolean doreuse = true;
    boolean useLowLevelCalls = false;
    try (BimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        BimServerClientInterface bimServerClient = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = null;
        if (useLowLevelCalls) {
            model = bimServerClient.newModel(newProject, true);
        } else {
            model = new BasicIfcModel(bimServerClient.getMetaDataManager().getPackageMetaData("ifc2x3tc1"), null);
        }
        RichIfcModel richIfcModel = new RichIfcModel(model, !useLowLevelCalls);
        IfcBuilding ifcBuilding = richIfcModel.createDefaultProjectStructure(0, 0, 0);
        IfcRelAggregates buildingAggregation = richIfcModel.create(IfcRelAggregates.class);
        buildingAggregation.setRelatingObject(ifcBuilding);
        for (int i = 1; i <= 200; i++) {
            IfcBuildingStorey ifcBuildingStorey = richIfcModel.create(IfcBuildingStorey.class);
            ifcBuildingStorey.setName("Storey " + i);
            ifcBuildingStorey.setCompositionType(IfcElementCompositionEnum.ELEMENT);
            ifcBuildingStorey.setElevation(3000 * i);
            IfcLocalPlacement storeyPlacement = richIfcModel.create(IfcLocalPlacement.class);
            storeyPlacement.setRelativePlacement(richIfcModel.createBasicPosition(0, 0, i * 3000));
            ifcBuildingStorey.setObjectPlacement(storeyPlacement);
            buildingAggregation.getRelatedObjects().add(ifcBuildingStorey);
            IfcRelAggregates storeyAggregation = richIfcModel.create(IfcRelAggregates.class);
            storeyAggregation.setRelatingObject(ifcBuildingStorey);
            for (int x = 1; x <= 40; x++) {
                for (int y = 1; y <= 40; y++) {
                    createSpace(richIfcModel, richIfcModel.getDefaultRepresentationContext(), storeyPlacement, storeyAggregation, x, y, doreuse);
                }
            }
        }
        long roid = -1;
        if (useLowLevelCalls) {
            roid = model.commit("Initial model");
        } else {
            Serializer serializer = new Ifc2x3tc1StepSerializer(null);
            serializer.init(model, null, true);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            serializer.writeToOutputStream(baos, null);
            java.nio.file.Files.write(Paths.get("tmp.ifc"), baos.toByteArray());
            SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
            SLongCheckinActionState checkinSync = bimServerClient.checkinSync(newProject.getOid(), "New", deserializer.getOid(), false, baos.size(), "newfile", new ByteArrayInputStream(baos.toByteArray()));
            roid = checkinSync.getRoid();
        }
        SSerializerPluginConfiguration serializerByContentType = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
        bimServerClient.download(roid, serializerByContentType.getOid(), new FileOutputStream(new File("created.ifc")));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) RichIfcModel(org.bimserver.utils.RichIfcModel) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SProject(org.bimserver.interfaces.objects.SProject) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding) Serializer(org.bimserver.plugins.serializers.Serializer) Ifc2x3tc1StepSerializer(org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) Ifc2x3tc1StepSerializer(org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer) IfcRelAggregates(org.bimserver.models.ifc2x3tc1.IfcRelAggregates) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) File(java.io.File) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)1 Ifc2x3tc1StepSerializer (org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializer)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SLongCheckinActionState (org.bimserver.interfaces.objects.SLongCheckinActionState)1 SProject (org.bimserver.interfaces.objects.SProject)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 IfcBuilding (org.bimserver.models.ifc2x3tc1.IfcBuilding)1 IfcBuildingStorey (org.bimserver.models.ifc2x3tc1.IfcBuildingStorey)1 IfcLocalPlacement (org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)1 IfcRelAggregates (org.bimserver.models.ifc2x3tc1.IfcRelAggregates)1 Serializer (org.bimserver.plugins.serializers.Serializer)1 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)1 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)1 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)1