| /******************************************************************************* |
| * 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.addons.geometry.paths.ui.impl; |
| |
| import javax.vecmath.Point3d; |
| |
| import org.eclipse.apogy.addons.geometry.paths.ui.Activator; |
| import org.eclipse.apogy.addons.geometry.paths.ui.ApogyAddonsGeometryPathsUIPackage; |
| import org.eclipse.apogy.addons.geometry.paths.ui.PathPresentationMode; |
| import org.eclipse.apogy.addons.geometry.paths.ui.WayPointPathPresentation; |
| import org.eclipse.apogy.addons.geometry.paths.ui.WayPointPathSceneObject; |
| import org.eclipse.apogy.addons.geometry.paths.ui.preferences.MRTPathsPreferencesConstants; |
| import org.eclipse.apogy.common.math.ApogyCommonMathFacade; |
| import org.eclipse.apogy.common.math.Tuple3d; |
| 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 WayPointPathPresentationCustomImpl extends WayPointPathPresentationImpl { |
| |
| protected IPropertyChangeListener preferencesListener = null; |
| |
| protected WayPointPathPresentationCustomImpl() { |
| super(); |
| |
| // Applies the current preferences values. |
| applyPreferences(); |
| |
| // Register a listener to the preference store |
| Activator.getDefault().getPreferenceStore().addPropertyChangeListener(getPreferencesListener()); |
| } |
| |
| @Override |
| protected void updateSceneObject(Notification notification) { |
| WayPointPathSceneObject wayPointPathSceneObject = (WayPointPathSceneObject) this.sceneObject; |
| |
| if (notification.getNotifier() instanceof WayPointPathPresentation) { |
| int featureId = notification.getFeatureID(WayPointPathPresentation.class); |
| |
| switch (featureId) { |
| case ApogyAddonsGeometryPathsUIPackage.WAY_POINT_PATH_PRESENTATION__PRESENTATION_MODE: |
| wayPointPathSceneObject.setPathPresentationMode(this.presentationMode); |
| break; |
| |
| case ApogyAddonsGeometryPathsUIPackage.WAY_POINT_PATH_PRESENTATION__POINT_SIZE: |
| wayPointPathSceneObject.setPointSize(this.pointSize); |
| break; |
| |
| case ApogyAddonsGeometryPathsUIPackage.WAY_POINT_PATH_PRESENTATION__END_POINTS_RADIUS: |
| wayPointPathSceneObject.setEndPointsRadius(this.endPointsRadius); |
| break; |
| |
| default: |
| break; |
| } |
| } |
| |
| super.updateSceneObject(notification); |
| } |
| |
| @Override |
| public Tuple3d basicGetCentroid() { |
| Point3d point3d = new Point3d(); |
| |
| if (this.sceneObject != null) { |
| point3d = this.sceneObject.getCentroid(); |
| } |
| |
| return ApogyCommonMathFacade.INSTANCE.createTuple3d(point3d); |
| } |
| |
| @Override |
| protected void initialSceneObject() { |
| WayPointPathSceneObject object3D = (WayPointPathSceneObject) this.sceneObject; |
| object3D.setPathPresentationMode(this.presentationMode); |
| object3D.setPointSize(this.pointSize); |
| object3D.setEndPointsRadius(this.endPointsRadius); |
| |
| super.initialSceneObject(); |
| } |
| |
| private IPropertyChangeListener getPreferencesListener() { |
| if (this.preferencesListener == null) { |
| this.preferencesListener = new IPropertyChangeListener() { |
| |
| @Override |
| public void propertyChange(PropertyChangeEvent event) { |
| applyPreferences(); |
| } |
| }; |
| } |
| |
| return this.preferencesListener; |
| } |
| |
| @Override |
| protected void applyPreferences() { |
| IPreferenceStore store = Activator.getDefault().getPreferenceStore(); |
| |
| // Change color. |
| RGB rgb = PreferenceConverter.getColor(store, MRTPathsPreferencesConstants.DEFAULT_WAYPOINTPATH_COLOR_ID); |
| if (rgb != null) |
| setColor(rgb); |
| |
| // Change visibility. |
| setVisible(store.getBoolean(MRTPathsPreferencesConstants.DEFAULT_WAYPOINTPATH_VISIBILITY_ID)); |
| |
| // Change mode. |
| setPresentationMode(PathPresentationMode |
| .get(store.getInt(MRTPathsPreferencesConstants.DEFAULT_WAYPOINTPATH_PRESENTATION_MODE_ID))); |
| |
| // Change point size |
| setPointSize(store.getInt(MRTPathsPreferencesConstants.DEFAULT_WAYPOINTPATH_POINT_SIZE_ID)); |
| |
| // Change end point radius |
| setEndPointsRadius(store.getFloat(MRTPathsPreferencesConstants.DEFAULT_WAYPOINTPATH_END_POINT_RADIUS_ID)); |
| |
| super.applyPreferences(); |
| } |
| |
| } // WayPointPathPresentationImpl |