blob: 33d53c9a92148721fa6feae240c0fb179aa5be16 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.geometry.data3d.ui.impl;
import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFactory;
import org.eclipse.apogy.common.geometry.data3d.CartesianCoordinatesSet;
import org.eclipse.apogy.common.geometry.data3d.CartesianPositionCoordinates;
import org.eclipse.apogy.common.geometry.data3d.Data3DUtils;
import org.eclipse.apogy.common.geometry.data3d.ui.Activator;
import org.eclipse.apogy.common.geometry.data3d.ui.ApogyCommonGeometryData3DUIPackage;
import org.eclipse.apogy.common.geometry.data3d.ui.preferences.MRTData3DUIPreferencesConstants;
import org.eclipse.apogy.common.geometry.data3d.ui.scene_objects.CartesianCoordinatesSetSceneObject;
import org.eclipse.apogy.common.math.ApogyCommonMathFacade;
import org.eclipse.apogy.common.math.Tuple3d;
import org.eclipse.apogy.common.topology.ContentNode;
import org.eclipse.apogy.common.topology.ui.SceneObject;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.RGB;
public class CartesianCoordinatesSetPresentationCustomImpl extends CartesianCoordinatesSetPresentationImpl {
protected IPropertyChangeListener preferencesListener = null;
protected CartesianCoordinatesSetPresentationCustomImpl() {
super();
// Initializes values from preferences
applyPreferences();
// Register a listener to the preference store
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(getPreferencesListener());
}
public CartesianCoordinatesSet basicGetPointCloud() {
CartesianCoordinatesSet coordSet = null;
if (getNode() != null) {
ContentNode<?> cNode = (ContentNode<?>) getNode();
if (cNode.getContent() instanceof CartesianCoordinatesSet) {
coordSet = (CartesianCoordinatesSet) cNode.getContent();
}
}
return coordSet;
}
public int getNumberOfPoints() {
int numberOfPoints = 0;
if (getPointCloud() != null) {
numberOfPoints = getPointCloud().getPoints().size();
}
return numberOfPoints;
}
@Override
public Tuple3d basicGetCentroid() {
Data3DUtils utils = ApogyCommonGeometryData3DFactory.eINSTANCE.createData3DUtils();
CartesianPositionCoordinates centroid = utils.computeCentroid(getPointCloud());
Tuple3d point = ApogyCommonMathFacade.INSTANCE.createTuple3d(centroid.asPoint3d());
return point;
}
@Override
public void setSceneObject(SceneObject newSceneObject) {
if (newSceneObject != null && !(newSceneObject instanceof CartesianCoordinatesSetSceneObject)) {
throw new IllegalArgumentException();
}
super.setSceneObject(newSceneObject);
}
@Override
protected void initialSceneObject() {
CartesianCoordinatesSetSceneObject pointsSceneObject = (CartesianCoordinatesSetSceneObject) getSceneObject();
pointsSceneObject.setPointSize(getPointSize());
super.initialSceneObject();
}
@Override
protected void updateSceneObject(Notification notification) {
if (this.sceneObject != null) {
CartesianCoordinatesSetSceneObject pointsSceneObject = (CartesianCoordinatesSetSceneObject) this.sceneObject;
if (notification.getNotifier() instanceof CartesianCoordinatesSetPresentationCustomImpl) {
int featureID = notification.getFeatureID(CartesianCoordinatesSetPresentationCustomImpl.class);
switch (featureID) {
case ApogyCommonGeometryData3DUIPackage.CARTESIAN_COORDINATES_SET_PRESENTATION__POINT_SIZE:
pointsSceneObject.setPointSize(getPointSize());
break;
default:
break;
}
}
}
super.updateSceneObject(notification);
}
@Override
protected void applyPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
// Change color.
RGB rgb = PreferenceConverter.getColor(store,
MRTData3DUIPreferencesConstants.DEFAULT_CARTESIAN_COORD_SET_COLOR_ID);
if (rgb != null)
setColor(rgb);
// Change visibility.
setVisible(store.getBoolean(MRTData3DUIPreferencesConstants.DEFAULT_CARTESIAN_COORD_SET_VISIBILITY_ID));
// Change point size
int pointSize = store.getInt(MRTData3DUIPreferencesConstants.DEFAULT_CARTESIAN_COORD_SET_POINT_SIZE_ID);
setPointSize(pointSize);
super.applyPreferences();
}
protected IPropertyChangeListener getPreferencesListener() {
if (this.preferencesListener == null) {
this.preferencesListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
applyPreferences();
}
};
}
return this.preferencesListener;
}
} // CartesianCoordinatesSetPresentationImpl