Search in sources :

Example 21 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class StreamingGeometryGenerator method placement3DToMatrix.

// Pretty sure this is working correctly
@SuppressWarnings("unchecked")
public double[] placement3DToMatrix(HashMapVirtualObject ifcAxis2Placement3D) {
    EReference refDirectionFeature = packageMetaData.getEReference("IfcAxis2Placement3D", "RefDirection");
    HashMapVirtualObject location = ifcAxis2Placement3D.getDirectFeature(packageMetaData.getEReference("IfcPlacement", "Location"));
    if (ifcAxis2Placement3D.getDirectFeature(packageMetaData.getEReference("IfcAxis2Placement3D", "Axis")) != null && ifcAxis2Placement3D.getDirectFeature(refDirectionFeature) != null) {
        HashMapVirtualObject axis = ifcAxis2Placement3D.getDirectFeature(packageMetaData.getEReference("IfcAxis2Placement3D", "Axis"));
        HashMapVirtualObject direction = ifcAxis2Placement3D.getDirectFeature(refDirectionFeature);
        List<Double> axisDirectionRatios = (List<Double>) axis.get("DirectionRatios");
        List<Double> directionDirectionRatios = (List<Double>) direction.get("DirectionRatios");
        List<Double> locationCoordinates = (List<Double>) location.get("Coordinates");
        double[] cross = Vector.crossProduct(new double[] { axisDirectionRatios.get(0), axisDirectionRatios.get(1), axisDirectionRatios.get(2), 1 }, new double[] { directionDirectionRatios.get(0), directionDirectionRatios.get(1), directionDirectionRatios.get(2), 1 });
        return new double[] { directionDirectionRatios.get(0), directionDirectionRatios.get(1), directionDirectionRatios.get(2), 0, cross[0], cross[1], cross[2], 0, axisDirectionRatios.get(0), axisDirectionRatios.get(1), axisDirectionRatios.get(2), 0, locationCoordinates.get(0), locationCoordinates.get(1), locationCoordinates.get(2), 1 };
    } else if (location != null) {
        List<Double> locationCoordinates = (List<Double>) location.get("Coordinates");
        return new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, locationCoordinates.get(0), locationCoordinates.get(1), locationCoordinates.get(2), 1 };
    }
    return Matrix.identity();
}
Also used : HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 22 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class RevisionMerger method fixNonGuidObjects.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void fixNonGuidObjects() throws IfcModelInterfaceException {
    Set<List> clearedLists = new HashSet<List>();
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                Object referencedObject = idEObject.eGet(eReference);
                if (eReference.isMany()) {
                    List list = (List) referencedObject;
                    List newList = (List) resultModel.getByGuid(guid).eGet(eReference);
                    boolean listIsCleared = false;
                    for (Object o : list) {
                        if (!(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
                            if (!listIsCleared) {
                                newList.clear();
                                listIsCleared = true;
                            }
                            IdEObject referencedIDEObject = (IdEObject) o;
                            if (resultModel.contains(referencedIDEObject.getOid())) {
                                newList.add(resultModel.get(referencedIDEObject.getOid()));
                            } else {
                                IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
                                newList.add(smartCopy);
                            }
                        }
                    }
                } else {
                    if (referencedObject == null) {
                        if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                            IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                            if (eReference.getEOpposite().isMany()) {
                                List l = (List) x.eGet(eReference.getEOpposite());
                                if (!clearedLists.contains(l)) {
                                    clearedLists.add(l);
                                    l.clear();
                                }
                            } else {
                                x.eSet(eReference.getEOpposite(), null);
                            }
                        }
                        resultModel.getByGuid(guid).eSet(eReference, null);
                    } else {
                        if (!(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
                            IdEObject referencedIDEObject = (IdEObject) referencedObject;
                            if (resultModel.contains(referencedIDEObject.getOid())) {
                                if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                                    IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                                    if (eReference.getEOpposite().isMany()) {
                                        List l = (List) x.eGet(eReference.getEOpposite());
                                        if (!clearedLists.contains(l)) {
                                            clearedLists.add(l);
                                            l.clear();
                                        }
                                    } else {
                                        x.eSet(eReference.getEOpposite(), null);
                                    }
                                }
                                resultModel.getByGuid(guid).eSet(eReference, resultModel.get(referencedIDEObject.getOid()));
                            } else {
                                IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
                                if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                                    IdEObject re = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                                    if (eReference.getEOpposite().isMany()) {
                                        List l = (List) re.eGet(eReference.getEOpposite());
                                        if (!clearedLists.contains(l)) {
                                            clearedLists.add(l);
                                            l.clear();
                                        }
                                    } else {
                                        re.eSet(eReference.getEOpposite(), null);
                                    }
                                }
                                resultModel.getByGuid(guid).eSet(eReference, smartCopy);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) List(java.util.List) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Example 23 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class RevisionMerger method copy.

@SuppressWarnings({ "unchecked", "rawtypes" })
private IdEObject copy(IfcModel target, IdEObject idEObject, boolean limitToNonGuids) throws IfcModelInterfaceException {
    if (target.contains(idEObject.getOid())) {
        return target.get(idEObject.getOid());
    }
    IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
    ((IdEObjectImpl) newObject).setOid(idEObject.getOid());
    if (newObject.getOid() != -1) {
        target.add(newObject.getOid(), newObject);
    }
    for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
        newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
    }
    for (EReference eReference : newObject.eClass().getEAllReferences()) {
        Object referencedObject = idEObject.eGet(eReference);
        if (referencedObject instanceof IdEObject) {
            IdEObject refEObject = (IdEObject) referencedObject;
            if (!limitToNonGuids || !(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
                newObject.eSet(eReference, copy(target, refEObject, limitToNonGuids));
            }
        } else if (referencedObject instanceof List) {
            List list = (List) referencedObject;
            List newList = (List) newObject.eGet(eReference);
            for (Object o : list) {
                if (!limitToNonGuids || !(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
                    IdEObject listObject = (IdEObject) o;
                    IdEObject smartCopy = copy(target, listObject, limitToNonGuids);
                    if (!newList.contains(smartCopy)) {
                        newList.add(smartCopy);
                    }
                }
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EAttribute(org.eclipse.emf.ecore.EAttribute) IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 24 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class AbstractSchemaConverter method copy.

@SuppressWarnings("unchecked")
protected IdEObject copy(IdEObject original) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
    if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
        return null;
    }
    if (converted.containsKey(original)) {
        return converted.get(original);
    }
    if (original.eClass().getName().equals("GeometryInfo") || original.eClass().getName().equals("GeometryData") || original.eClass().getName().equals("Vector3f")) {
        return null;
    }
    EClass eClass = (EClass) target.getPackageMetaData().getEPackage().getEClassifier(original.eClass().getName());
    if (eClass == null) {
        LOGGER.info("No class " + original.eClass().getName() + " in " + target.getPackageMetaData().getEPackage().getName());
        return null;
    }
    IdEObject newObject = (IdEObject) eClass.getEPackage().getEFactoryInstance().create(eClass);
    ((IdEObjectImpl) newObject).setOid(original.getOid());
    converted.put(original, newObject);
    if (newObject.eClass().getEAnnotation("wrapped") == null) {
        target.add(newObject.getOid(), newObject);
    }
    for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
        EStructuralFeature targetFeature = newObject.eClass().getEStructuralFeature(eStructuralFeature.getName());
        if (targetFeature == null) {
            continue;
        }
        Object get = original.eGet(eStructuralFeature);
        if (eStructuralFeature instanceof EAttribute) {
            if (get instanceof Double) {
                EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString");
                EStructuralFeature targetDoubleStringFeature = newObject.eClass().getEStructuralFeature("wrappedValueAsString");
                if (doubleStringFeature != null && targetDoubleStringFeature != null) {
                    Object doubleString = original.eGet(doubleStringFeature);
                    newObject.eSet(targetDoubleStringFeature, doubleString);
                } else {
                    newObject.eSet(targetFeature, get);
                }
            } else {
                if (eStructuralFeature.getEType() instanceof EEnum) {
                    EEnum targetEnum = (EEnum) targetFeature.getEType();
                    EEnumLiteral newLiteral = targetEnum.getEEnumLiteral(get.toString());
                    if (newLiteral != null) {
                        newObject.eSet(targetFeature, newLiteral.getInstance());
                    }
                } else {
                    if (targetFeature instanceof EAttribute) {
                        newObject.eSet(targetFeature, get);
                    }
                }
            }
        } else if (eStructuralFeature instanceof EReference) {
            if (get == null) {
            } else {
                if (eStructuralFeature.isMany()) {
                    EList<EObject> list = (EList<EObject>) get;
                    AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(targetFeature);
                    if (toList != null) {
                        for (Object o : list) {
                            IdEObject ref = (IdEObject) o;
                            if (targetFeature.getEType().isInstance(ref)) {
                                if (converted.containsKey(o)) {
                                    toList.addUnique(converted.get(o));
                                } else {
                                    IdEObject result = copy((IdEObject) o);
                                    if (result != null) {
                                        toList.addUnique(result);
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (targetFeature.isMany()) {
                        LOGGER.info("Different multiplicity");
                    } else {
                        if (converted.containsKey(get)) {
                            newObject.eSet(targetFeature, converted.get(get));
                        } else {
                            newObject.eSet(targetFeature, copy((IdEObject) get));
                        }
                    }
                }
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EReference(org.eclipse.emf.ecore.EReference)

Example 25 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class GetDataObjectByOidDatabaseAction method fillDataObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void fillDataObject(BiMap<? extends Long, ? extends EObject> mapResult, EObject eObject, DataObject dataObject) {
    for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
        Object eGet = eObject.eGet(eStructuralFeature);
        if (eStructuralFeature.getEAnnotation("hidden") == null) {
            if (eStructuralFeature instanceof EAttribute) {
                if (eStructuralFeature.isMany()) {
                    ListDataValue listDataValue = StoreFactory.eINSTANCE.createListDataValue();
                    listDataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(listDataValue);
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                        EStructuralFeature asStringFeature = eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                        List list = (List) eObject.eGet(asStringFeature);
                        for (Object o : list) {
                            SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            dataValue.setStringValue(o.toString());
                            listDataValue.getValues().add(dataValue);
                        }
                    } else {
                        if (eGet != null) {
                            List list = (List) eGet;
                            for (Object o : list) {
                                SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                if (eGet != null) {
                                    dataValue.setStringValue(o.toString());
                                } else {
                                    dataValue.setStringValue(null);
                                }
                                listDataValue.getValues().add(dataValue);
                            }
                        }
                    }
                } else {
                    SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                    if (eObject.eIsSet(eStructuralFeature)) {
                        if (eGet instanceof byte[]) {
                            dataValue.setStringValue(new String(((byte[]) eGet), Charsets.UTF_8));
                        } else {
                            dataValue.setStringValue(eGet.toString());
                        }
                    } else {
                        dataValue.setStringValue(null);
                    }
                    dataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(dataValue);
                }
            } else if (eStructuralFeature instanceof EReference) {
                if (eStructuralFeature.isMany()) {
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
                        List list = (List) eObject.eGet(eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString"));
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataValue.setFieldName(eStructuralFeature.getName());
                        dataObject.getValues().add(dataValue);
                        for (Object o : list) {
                            SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            simpleDataValue.setStringValue(o.toString());
                            dataValue.getValues().add(simpleDataValue);
                        }
                    } else {
                        EList<? extends EObject> list = (EList<EObject>) eGet;
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataObject.getValues().add(dataValue);
                        dataValue.setFieldName(eStructuralFeature.getName());
                        for (EObject item : list) {
                            if (item.eClass().getEAnnotation("wrapped") != null) {
                                EObject referenceEObject = item;
                                SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                simpleDataValue.setStringValue(referenceEObject.eGet(referenceEObject.eClass().getEStructuralFeature("wrappedValue")).toString());
                                dataValue.getValues().add(simpleDataValue);
                            } else {
                                Long oid = ((IdEObject) item).getOid();
                                ReferenceDataValue referenceDataValue = StoreFactory.eINSTANCE.createReferenceDataValue();
                                if (item instanceof IfcRoot) {
                                    IfcRoot ifcRoot = (IfcRoot) item;
                                    String guid = ifcRoot.getGlobalId();
                                    referenceDataValue.setGuid(guid);
                                }
                                referenceDataValue.setTypeName(item.eClass().getName());
                                ((IdEObjectImpl) referenceDataValue).setOid(oid);
                                dataValue.getValues().add(referenceDataValue);
                            }
                        }
                    }
                } else {
                    EObject eObject2 = (EObject) eGet;
                    if (eObject2 != null) {
                        if (eObject2.eClass().getEAnnotation("wrapped") != null) {
                            EObject referenceEObject = (EObject) eGet;
                            SimpleDataValue e = StoreFactory.eINSTANCE.createSimpleDataValue();
                            EStructuralFeature wrappedValueFeature = referenceEObject.eClass().getEStructuralFeature("wrappedValue");
                            Object eGet2 = referenceEObject.eGet(wrappedValueFeature);
                            // } else {
                            if (eGet2 != null) {
                                e.setStringValue(eGet2.toString());
                            } else {
                                e.setStringValue(null);
                            }
                            // }
                            e.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(e);
                        } else {
                            Long oid = ((IdEObject) eObject2).getOid();
                            ReferenceDataValue reference = StoreFactory.eINSTANCE.createReferenceDataValue();
                            if (eObject2 instanceof IfcRoot) {
                                IfcRoot ifcRoot = (IfcRoot) eObject2;
                                String guid = ifcRoot.getGlobalId();
                                reference.setGuid(guid);
                            }
                            reference.setTypeName(eObject2.eClass().getName());
                            ((IdEObjectImpl) reference).setOid(oid);
                            reference.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(reference);
                        }
                    }
                }
            }
        }
    }
}
Also used : ListDataValue(org.bimserver.models.store.ListDataValue) SimpleDataValue(org.bimserver.models.store.SimpleDataValue) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) ReferenceDataValue(org.bimserver.models.store.ReferenceDataValue) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.bimserver.models.store.DataObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10