use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DownloadCompareDatabaseAction method setColor.
@SuppressWarnings("unchecked")
private void setColor(IfcModelInterface model, IdEObject product, IdEObject color) throws IfcModelInterfaceException {
EStructuralFeature representationFeature = product.eClass().getEStructuralFeature("Representation");
IdEObject representation = (IdEObject) product.eGet(representationFeature);
if (representation != null) {
EStructuralFeature representationsFeature = representation.eClass().getEStructuralFeature("Representations");
List<IdEObject> representations = (EList<IdEObject>) representation.eGet(representationsFeature);
for (IdEObject ifcRepresentation : representations) {
EStructuralFeature itemsFeature = ifcRepresentation.eClass().getEStructuralFeature("Items");
List<IdEObject> representationItems = (EList<IdEObject>) ifcRepresentation.eGet(itemsFeature);
EStructuralFeature representationIdentifierFeature = ifcRepresentation.eClass().getEStructuralFeature("RepresentationIdentifier");
String identifier = (String) ifcRepresentation.eGet(representationIdentifierFeature);
for (IdEObject ifcRepresentationItem : representationItems) {
EStructuralFeature styledByItemFeature = ifcRepresentationItem.eClass().getEStructuralFeature("StyledByItem");
List<IdEObject> styledByItems = (EList<IdEObject>) ifcRepresentationItem.eGet(styledByItemFeature);
if (styledByItems.isEmpty()) {
createStyledByItems(model, ifcRepresentationItem, identifier, color);
} else {
for (IdEObject ifcStyledItem : styledByItems) {
EStructuralFeature stylesFeature = ifcStyledItem.eClass().getEStructuralFeature("Styles");
List<IdEObject> styledItemStyles = (List<IdEObject>) ifcStyledItem.eGet(stylesFeature);
if (styledItemStyles.isEmpty()) {
createStyledItemStyles(model, identifier, ifcStyledItem, color);
} else {
for (IdEObject ifcPresentationStyleAssignment : styledItemStyles) {
EStructuralFeature stylesFeature2 = ifcPresentationStyleAssignment.eClass().getEStructuralFeature("Styles");
List<IdEObject> presentationStyleAssignmentStyles = (List<IdEObject>) ifcPresentationStyleAssignment.eGet(stylesFeature2);
if (presentationStyleAssignmentStyles.isEmpty()) {
createPresentationStyleAssignmentStyles(model, identifier, ifcPresentationStyleAssignment, color);
} else {
for (IdEObject ifcPresentationStyleSelect : presentationStyleAssignmentStyles) {
if (ifcPresentationStyleSelect.eClass().getName().equals("IfcSurfaceStyle")) {
EStructuralFeature stylesFeature3 = ifcPresentationStyleSelect.eClass().getEStructuralFeature("Styles");
List<IdEObject> surfaceStyleStyles = (List<IdEObject>) ifcPresentationStyleSelect.eGet(stylesFeature3);
if (surfaceStyleStyles.isEmpty()) {
createSurfaceStyleStyles(model, identifier, ifcPresentationStyleSelect, color);
} else {
boolean renderingFound = false;
for (IdEObject ifcSurfaceStyleElementSelect : surfaceStyleStyles) {
if (ifcSurfaceStyleElementSelect.eClass().getName().equals("IfcSurfaceStyleRendering")) {
renderingFound = true;
IdEObject ifcSurfaceStyleRendering = (IdEObject) ifcSurfaceStyleElementSelect;
setColour(color, ifcSurfaceStyleRendering);
}
}
if (!renderingFound) {
createSurfaceStyleStyles(model, identifier, ifcPresentationStyleSelect, color);
}
}
} else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcTextStyle")) {
EStructuralFeature textCharacterAppearanceFeature = ifcPresentationStyleSelect.eClass().getEStructuralFeature("TextCharacterAppearance");
IdEObject textCharacterAppearance = (IdEObject) ifcPresentationStyleSelect.eGet(textCharacterAppearanceFeature);
if (textCharacterAppearance.eClass().getName().equals("IfcTextStyleForDefinedFont")) {
// IfcTextStyleForDefinedFont is the only subclass of IfcCharacterStyleSelect
textCharacterAppearance.eSet(textCharacterAppearance.eClass().getEStructuralFeature("Colour"), color);
}
} else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcCurveStyle")) {
ifcPresentationStyleSelect.eSet(ifcPresentationStyleSelect.eClass().getEStructuralFeature("CurveColour"), color);
} else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcFillAreaStyle")) {
EStructuralFeature fillStylesFeature = ifcPresentationStyleSelect.eClass().getEStructuralFeature("FillStyles");
List<IdEObject> list = (List<IdEObject>) ifcPresentationStyleSelect.eGet(fillStylesFeature);
list.clear();
list.add(color);
} else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcSymbolStyle")) {
ifcPresentationStyleSelect.eSet(ifcPresentationStyleSelect.eClass().getEStructuralFeature("StyleOfSymbol"), color);
}
}
}
}
}
}
}
}
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class GetAllReadableProjectsDatabaseAction method execute.
@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(authorization.getUoid());
IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
Set<Project> result = new HashSet<Project>();
for (IdEObject idEObject : projectsModel.getValues()) {
if (idEObject instanceof Project) {
Project project = (Project) idEObject;
if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
result.add(project);
}
}
}
return result;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method getAvailableClassesInRevision.
public Set<String> getAvailableClassesInRevision(IfcModelInterface ifcModel, QueryInterface query) throws BimserverDatabaseException {
checkOpen();
try {
getMap(ifcModel, query);
Set<String> classes = new HashSet<String>();
for (IdEObject idEObject : ifcModel.getValues()) {
classes.add(idEObject.eClass().getName());
}
return classes;
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method convertObjectToByteArray.
private ByteBuffer convertObjectToByteArray(IdEObject object, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException {
int bufferSize = getExactSize(object, packageMetaData, true);
if (bufferSize > buffer.capacity()) {
LOGGER.debug("Buffer too small (" + bufferSize + ")");
buffer = ByteBuffer.allocate(bufferSize);
}
int unsettedLength = packageMetaData.getUnsettedLength(object.eClass());
byte[] unsetted = new byte[unsettedLength];
int fieldCounter = 0;
for (EStructuralFeature feature : object.eClass().getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(object.eClass(), feature)) {
if (useUnsetBit(feature, object)) {
unsetted[fieldCounter / 8] |= (1 << (fieldCounter % 8));
}
fieldCounter++;
}
}
buffer.put(unsetted);
EClass eClass = getEClassForOid(object.getOid());
if (!eClass.isSuperTypeOf(object.eClass())) {
throw new BimserverDatabaseException("Object with oid " + object.getOid() + " is a " + object.eClass().getName() + " but it's cid-part says it's a " + eClass.getName());
}
for (EStructuralFeature feature : object.eClass().getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(object.eClass(), feature)) {
if (!useUnsetBit(feature, object)) {
if (feature.isMany()) {
writeList(object, buffer, packageMetaData, feature);
} else {
Object value = object.eGet(feature);
if (feature.getEType() instanceof EEnum) {
if (value == null) {
buffer.putInt(-1);
} else {
EEnum eEnum = (EEnum) feature.getEType();
EEnumLiteral eEnumLiteral = eEnum.getEEnumLiteralByLiteral(((Enum<?>) value).toString());
if (eEnumLiteral != null) {
buffer.putInt(eEnumLiteral.getValue());
} else {
LOGGER.error(((Enum<?>) value).toString() + " not found");
buffer.putInt(-1);
}
}
} else if (feature.getEType() instanceof EClass) {
if (value == null) {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
} else {
IdEObject referencedObject = (IdEObject) value;
EClass referencedClass = referencedObject.eClass();
if (feature.getEAnnotation("dbembed") != null) {
writeEmbeddedValue(object.getPid(), object.getRid(), value, buffer, packageMetaData);
} else if (referencedClass.getEAnnotation("wrapped") != null) {
writeWrappedValue(object.getPid(), object.getRid(), value, buffer, packageMetaData);
} else {
writeReference(object, value, buffer, feature);
}
}
} else if (feature.getEType() instanceof EDataType) {
writePrimitiveValue(feature, value, buffer);
}
}
}
}
}
if (buffer.position() != bufferSize) {
throw new BimserverDatabaseException("Value buffer sizes do not match for " + object.eClass().getName() + " " + buffer.position() + "/" + bufferSize);
}
return buffer;
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method readReference.
private IdEObject readReference(EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, IdEObject object, EStructuralFeature feature, EClass eClass, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
// TODO next bit seems to make no sense, why detect a deleted record when reading a reference??
if (buffer.capacity() == 1 && buffer.get(0) == -1) {
buffer.position(buffer.position() + 1);
return null;
}
buffer.order(ByteOrder.LITTLE_ENDIAN);
long oid = buffer.getLong();
buffer.order(ByteOrder.BIG_ENDIAN);
IdEObject foundInCache = objectCache.get(oid);
if (foundInCache != null) {
return foundInCache;
}
if (model.contains(oid)) {
return model.get(oid);
}
IdEObjectImpl newObject = createInternal(eClass, query);
newObject.setOid(oid);
if (perRecordVersioning(newObject)) {
newObject.setPid(Database.STORE_PROJECT_ID);
} else {
newObject.setPid(query.getPid());
}
newObject.setRid(query.getRid());
try {
newObject.setModel(model);
} catch (IfcModelInterfaceException e) {
LOGGER.error("", e);
}
objectCache.put(oid, newObject);
if (query.isDeep() && object.eClass().getEAnnotation("wrapped") == null) {
if (feature.getEAnnotation("nolazyload") == null) {
todoList.add(newObject);
}
} else {
if (object.eClass().getEAnnotation("wrapped") == null) {
try {
model.addAllowMultiModel(oid, newObject);
} catch (IfcModelInterfaceException e) {
throw new BimserverDatabaseException(e);
}
}
}
return newObject;
}
Aggregations