openSourceBim IfcModelService всегда был пуст при загрузке - PullRequest
0 голосов
/ 25 сентября 2019

Я пытаюсь загрузить файл Ifc4 для десериализации данных в IfcModelService.

Для этой работы я использую openSourceBIM IfcPlugin Api с использованием JsdonDeserializer.

Когда я запускаю свой код, загружаются IfcModelServiceно все атрибуты пусты, только PackageMetada.

У меня нет для этого никаких оснований, я хотел бы получить доступ к файлу Ifc для извлечения информации об элементах плана (дверь, окно, размер и т. д.)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.omb</groupId>
    <artifactId>ws-metre</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>myservice</name>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.opensourcebim/ifcplugins -->
        <dependency>
            <groupId>org.opensourcebim</groupId>
            <artifactId>ifcplugins</artifactId>
            <version>0.0.80</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Apache commons -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Java

package fr.omb.myservice;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bimserver.deserializers.JsonDeserializer;
import org.bimserver.emf.IdEObjectImpl;
import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.PackageMetaData;
import org.bimserver.emf.Schema;
import org.bimserver.ifc.step.deserializer.DetectIfcVersion;
import org.bimserver.ifc.step.serializer.Ifc4StepStreamingSerializerPlugin;
import org.bimserver.models.ifc4.Ifc4Package;
import org.bimserver.models.ifc4.IfcRoot;
import org.bimserver.models.store.DataObject;
import org.bimserver.models.store.StoreFactory;
import org.bimserver.plugins.deserializers.DeserializeException;
import org.eclipse.emf.ecore.EObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.print.DocFlavor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


@SpringBootApplication
public class IfcParserApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(IfcParserApplication.class, args);

            //extract file
            Path path = Paths.get("C:\\ToolBox\\Projets\\BIM\\IFC 4\\Ifc4File.ifc");

            JsonDeserializer deserializer = new JsonDeserializer();
            PackageMetaData packageMetaData = new PackageMetaData(Ifc4Package.eINSTANCE, Schema.IFC4, Paths.get("C:\\tmp"));
            deserializer.init(packageMetaData);

            IfcModelInterface ifcModel = deserializer.read(Files.newInputStream(path), path.toFile().getName(), FileUtils.sizeOf(path.toFile()), null);
            System.out.println("Mon modèle" + ifcModel.toString());

            for (Long oid : ifcModel.keySet()) {
                EObject eObject = ifcModel.get(oid);
                if (eObject.eClass().getEAnnotation("hidden") == null) {
                    DataObject dataObject = null;
                    if (eObject instanceof IfcRoot) {
                        IfcRoot ifcRoot = (IfcRoot)eObject;
                        String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
                        String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
                        dataObject = StoreFactory.eINSTANCE.createDataObject();
                        dataObject.setType(eObject.eClass().getName());
                        ((IdEObjectImpl)dataObject).setOid(oid);
                        dataObject.setGuid(guid);
                        dataObject.setName(name);

                        System.out.println(dataObject.getGuid());
                        System.out.println(dataObject.getName());

                    } else {
                        dataObject = StoreFactory.eINSTANCE.createDataObject();
                        dataObject.setType(eObject.eClass().getName());
                        ((IdEObjectImpl)dataObject).setOid(oid);

                        System.out.println(dataObject.getGuid());
                        System.out.println(dataObject.getName());

                    }
                }
            }

        } catch (IOException| DeserializeException dee) {
            dee.printStackTrace();
        }
    }
}
...