use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.
the class DatabaseSession method convertByteArrayToObject.
@SuppressWarnings({ "unused" })
private IdEObject convertByteArrayToObject(IdEObject idEObject, EClass originalQueryClass, EClass eClass, long oid, ByteBuffer buffer, IfcModelInterface model, int rid, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
try {
if (idEObject == null) {
idEObject = createInternal(eClass, query);
((IdEObjectImpl) idEObject).setOid(oid);
((IdEObjectImpl) idEObject).setPid(query.getPid());
if (rid == Integer.MAX_VALUE) {
throw new BimserverDatabaseException("Database corrupt, rid cannot be " + Integer.MAX_VALUE);
}
}
if (idEObject.eClass().getEAnnotation("wrapped") == null) {
try {
model.addAllowMultiModel(oid, idEObject);
} catch (IfcModelInterfaceException e) {
throw new BimserverDatabaseException(e);
}
}
((IdEObjectImpl) idEObject).setRid(rid);
((IdEObjectImpl) idEObject).useInverses(false);
if (DEVELOPER_DEBUG && StorePackage.eINSTANCE == idEObject.eClass().getEPackage()) {
LOGGER.info("Read: " + idEObject.eClass().getName() + " pid=" + query.getPid() + " oid=" + oid + " rid=" + rid);
}
((IdEObjectImpl) idEObject).setLoadingState(State.LOADING);
objectCache.put(oid, idEObject);
int unsettedLength = model.getPackageMetaData().getUnsettedLength(eClass);
byte[] unsetted = new byte[unsettedLength];
buffer.get(unsetted);
int fieldCounter = 0;
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
try {
if (model.getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0;
if (isUnsetted) {
if (feature.isUnsettable()) {
idEObject.eUnset(feature);
} else if (feature.isMany()) {
// do nothing
} else if (feature.getDefaultValue() != null) {
idEObject.eSet(feature, feature.getDefaultValue());
}
} else {
if (!query.shouldFollowReference(originalQueryClass, eClass, feature)) {
// we have to do some reading to maintain a correct
// index
fakeRead(buffer, feature);
} else {
Object newValue = null;
if (feature.isMany()) {
newValue = readList(idEObject, originalQueryClass, buffer, model, query, todoList, feature);
} else {
if (feature.getEType() instanceof EEnum) {
int enumOrdinal = buffer.getInt();
if (enumOrdinal == -1) {
newValue = null;
} else {
EClassifier eType = feature.getEType();
EEnumLiteral enumLiteral = ((EEnumImpl) eType).getEEnumLiteral(enumOrdinal);
if (enumLiteral != null) {
newValue = enumLiteral.getInstance();
}
}
} else if (feature.getEType() instanceof EClass) {
// EReference eReference = (EReference) feature;
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// non minus one and negative cid means value is embedded in record
EClass referenceClass = database.getEClassForCid((short) (-cid));
if (feature.getEAnnotation("dbembed") != null) {
newValue = readEmbeddedValue(feature, buffer, referenceClass, query);
} else {
newValue = readWrappedValue(feature, buffer, referenceClass, query);
}
} else if (cid > 0) {
// positive cid means value is reference to other record
EClass referenceClass = database.getEClassForCid(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("No eClass found for cid " + cid);
}
// readReference is going to read a long, which includes the 2 bytes for the cid
buffer.position(buffer.position() - 2);
newValue = readReference(originalQueryClass, buffer, model, idEObject, feature, referenceClass, query, todoList);
// if (eReference.getEOpposite() != null &&
// ((IdEObjectImpl)
// newValue).isLoadedOrLoading()) {
// newValue = null;
// }
}
} else if (feature.getEType() instanceof EDataType) {
newValue = readPrimitiveValue(feature.getEType(), buffer, query);
}
}
if (newValue != null) {
idEObject.eSet(feature, newValue);
}
}
}
fieldCounter++;
}
} catch (StringIndexOutOfBoundsException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "(" + oid + ")." + feature.getName(), e);
}
}
((IdEObjectImpl) idEObject).setLoaded();
((IdEObjectImpl) idEObject).useInverses(true);
if (DEVELOPER_DEBUG && idEObject.getRid() > 100000 || idEObject.getRid() < -100000) {
LOGGER.debug("Improbable rid " + idEObject.getRid() + " - " + idEObject);
}
return idEObject;
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
}
}
use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.
the class SerializerFactory method create.
public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
DatabaseSession session = bimDatabase.createSession();
try {
SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
if (serializerPluginConfiguration != null) {
SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (serializerPlugin != null) {
ObjectType settings = serializerPluginConfiguration.getSettings();
Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
SchemaConverterFactory converterFactory = null;
for (Schema schema : serializerPlugin.getSupportedSchemas()) {
converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
if (converterFactory != null) {
break;
}
}
if (converterFactory == null) {
throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
}
try {
IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
SchemaConverter converter = converterFactory.create(model, targetModel);
converter.convert();
model = targetModel;
} catch (SchemaConverterException e) {
throw new SerializerException(e);
} catch (IfcModelInterfaceException e) {
throw new SerializerException(e);
}
}
if (serializer != null) {
try {
ProjectInfo projectInfo = new ProjectInfo();
projectInfo.setName(project.getName());
projectInfo.setDescription(project.getDescription());
GeoTag geoTag = project.getGeoTag();
if (geoTag != null && geoTag.getEnabled()) {
projectInfo.setX(geoTag.getX());
projectInfo.setY(geoTag.getY());
projectInfo.setZ(geoTag.getZ());
projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
} else {
projectInfo.setX(4.8900);
projectInfo.setY(52.3700);
}
projectInfo.setAuthorName(username);
serializer.init(model, projectInfo, true);
return serializer;
} catch (NullPointerException e) {
LOGGER.error("", e);
}
}
}
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
return null;
}
use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.
the class ClientIfcModel method loadDeep.
private void loadDeep() throws ServerException, UserException, PublicInterfaceNotFoundException, QueryException {
if (modelState != ModelState.FULLY_LOADED && modelState != ModelState.LOADING) {
modelState = ModelState.LOADING;
Query query = new Query("test", getPackageMetaData());
QueryPart queryPart = query.createQueryPart();
queryPart.setIncludeAllFields(true);
ObjectNode queryNode = new JsonQueryObjectModelConverter(query.getPackageMetaData()).toJson(query);
Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), queryNode.toString(), getJsonSerializerOid(), false);
waitForDonePreparing(topicId);
try {
processDownload(topicId);
bimServerClient.getServiceInterface().cleanupLongAction(topicId);
modelState = ModelState.FULLY_LOADED;
loadGeometry();
} catch (IfcModelInterfaceException | IOException e) {
LOGGER.error("", e);
} catch (QueryException e) {
LOGGER.error("", e);
} catch (GeometryException e) {
LOGGER.error("", e);
}
}
}
use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.
the class ExtractFurniture method main.
public static void main(String[] args) {
try {
Path home = Paths.get("home");
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
Deserializer deserializer = deserializerPlugin.createDeserializer(null);
MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
PackageMetaData packageMetaData = metaDataManager.getPackageMetaData("ifc2x3tc1");
deserializer.init(packageMetaData);
IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/ADT-FZK-Haus-2005-2006.ifc"));
model.fixOids(new IncrementingOidProvider());
IfcFurnishingElement picknick = (IfcFurnishingElement) model.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
IfcModelInterface newModel = new BasicIfcModel(packageMetaData, null);
ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), newModel);
modelHelper.copy(picknick, false);
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(null);
serializer.init(newModel, null, true);
SerializerUtils.writeToFile(serializer, Paths.get("test.ifc"));
} catch (PluginException e) {
e.printStackTrace();
} catch (DeserializeException e) {
e.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (SerializerException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.emf.IfcModelInterfaceException in project BIMserver by opensourceBIM.
the class TestChangeWrappedValue method start.
private void start() {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
long poid = 2686977;
long roid = 720899;
SProject project = client.getServiceInterface().getProjectByPoid(poid);
IfcModelInterface model = client.getModel(project, roid, true, false);
for (IfcPropertySingleValue prop : model.getAll(IfcPropertySingleValue.class)) {
// IfcValue value = ((IfcPropertySingleValue) prop).getNominalValue();
// if(value instanceof IfcLabel){
// System.out.println(prop.getOid() + " is " + ((IfcLabel) value).getWrappedValue() );
// ((IfcLabel) value).setWrappedValue(((IfcLabel) value).getWrappedValue() + " changed");
// }
IfcLabel label = model.create(IfcLabel.class);
label.setWrappedValue("blabla");
prop.setNominalValue(label);
}
model.commit("blaat");
} catch (ServiceException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
}
}
Aggregations