blob: f642c0ce370143a734e2f37b9ef69b36ff71d68d [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,
* Sebastien Gemme - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.topology.ui.viewer;
import org.eclipse.apogy.common.math.ApogyCommonMathFacade;
import org.eclipse.apogy.common.math.Tuple3d;
import org.eclipse.apogy.common.topology.ui.viewer.preferences.TopologyViewerLightingPreferenceConstants;
import org.eclipse.apogy.common.topology.ui.viewer.preferences.TopologyViewerPreferencesConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the central singleton for the TopologyUi editor plugin. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public final class Activator extends AbstractUIPlugin implements BundleActivator, IPropertyChangeListener {
private static final Logger Logger = LoggerFactory.getLogger(Activator.class);
public static final String ID = "org.eclipse.apogy.common.topology.ui.viewer";
private static BundleContext context;
private static TopologyViewerRegistry topologyViewerRegistry = null;
private boolean antialiasing = true;
private int maximumFrameRate = 15;
private RGB ambientLightColor = new RGB(255, 255, 255);
private Tuple3d ambientLightDirection = null;
private double navigationLinearLowSpeedFactor = 1.0;
private double navigationLinearHighSpeedFactor = 10.0;
// The shared instance
private static Activator plugin;
public Activator() {
plugin = this;
getPreferenceStore().addPropertyChangeListener(this);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
@Override
public void start(BundleContext context) throws Exception {
Activator.context = context;
// Get the values from the store
this.antialiasing = getPreferenceStore().getBoolean(TopologyViewerPreferencesConstants.VIEWER_ANTI_ALIASING_ID);
this.maximumFrameRate = getPreferenceStore()
.getInt(TopologyViewerPreferencesConstants.VIEWER_MAX_FRAME_RATE_ID);
this.navigationLinearLowSpeedFactor = getPreferenceStore()
.getDouble(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_LOW_SPEED_FACTOR_ID);
this.navigationLinearHighSpeedFactor = getPreferenceStore()
.getDouble(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_HIGH_SPEED_FACTOR_ID);
this.ambientLightColor = PreferenceConverter.getColor(getPreferenceStore(),
TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_COLOR_ID);
this.ambientLightDirection = fromString(
getPreferenceStore().getString(TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_DIRECTION_ID));
}
@Override
public void stop(BundleContext context) throws Exception {
getPreferenceStore().removePropertyChangeListener(this);
context = null;
}
public static BundleContext getBundleContext() {
return context;
}
public static TopologyViewerRegistry getTopologyViewerRegistry() {
if (topologyViewerRegistry == null) {
topologyViewerRegistry = ApogyCommonTopologyUIViewerFactory.eINSTANCE.createTopologyViewerRegistry();
}
return topologyViewerRegistry;
}
public double getNavigationLinearLowSpeedFactor() {
return this.navigationLinearLowSpeedFactor;
}
public double getNavigationLinearHighSpeedFactor() {
return this.navigationLinearHighSpeedFactor;
}
public int getMaximumFrameRate() {
return this.maximumFrameRate;
}
public boolean isAntialiasing() {
return this.antialiasing;
}
public RGB getAmbientLightColor() {
return this.ambientLightColor;
}
public Tuple3d getAmbientLightDirection() {
if (this.ambientLightDirection == null) {
this.ambientLightDirection = fromString(getPreferenceStore()
.getString(TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_DIRECTION_ID));
}
return this.ambientLightDirection;
}
@Override
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
String propertyID = event.getProperty();
try {
if (propertyID.equals(TopologyViewerPreferencesConstants.VIEWER_ANTI_ALIASING_ID)) {
this.antialiasing = store.getBoolean(TopologyViewerPreferencesConstants.VIEWER_ANTI_ALIASING_ID);
Logger.info("Antialiasing changed to <" + this.antialiasing + ">.");
} else if (propertyID.equals(TopologyViewerPreferencesConstants.VIEWER_MAX_FRAME_RATE_ID)) {
this.maximumFrameRate = store.getInt(TopologyViewerPreferencesConstants.VIEWER_MAX_FRAME_RATE_ID);
Logger.info("Maximum Frame Rate set to <" + this.maximumFrameRate + "> fps.");
} else if (propertyID.equals(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_HIGH_SPEED_FACTOR_ID)) {
this.navigationLinearHighSpeedFactor = store
.getDouble(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_HIGH_SPEED_FACTOR_ID);
Logger.info("Updated Linear High Speed to <" + this.navigationLinearHighSpeedFactor + ">.");
} else if (propertyID.equals(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_LOW_SPEED_FACTOR_ID)) {
this.navigationLinearLowSpeedFactor = store
.getDouble(TopologyViewerPreferencesConstants.DEFAULT_LINEAR_LOW_SPEED_FACTOR_ID);
Logger.info("Updated Linear Low Speed to <" + this.navigationLinearLowSpeedFactor + ">.");
} else if (propertyID.equals(TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_COLOR_ID)) {
this.ambientLightColor = PreferenceConverter.getColor(getPreferenceStore(),
TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_COLOR_ID);
Logger.info("Updated Ambient Light Color to <" + this.ambientLightColor + ">.");
} else if (propertyID.equals(TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_DIRECTION_ID)) {
Tuple3d dir = fromString(
store.getString(TopologyViewerLightingPreferenceConstants.AMBIENT_LIGHT_DIRECTION_ID));
if (dir != null) {
this.ambientLightDirection = dir;
Logger.info("Updated Ambient Light Direction to <" + this.ambientLightColor + ">.");
}
}
} catch (Throwable t) {
Logger.error(t.getMessage(), t);
}
}
private Tuple3d fromString(String string) {
Tuple3d direction = null;
if (string != null) {
String[] items = string.split(",");
if (items.length >= 3) {
double x = Double.parseDouble(items[0].trim());
double y = Double.parseDouble(items[1].trim());
double z = Double.parseDouble(items[2].trim());
direction = ApogyCommonMathFacade.INSTANCE.createTuple3d(x, y, z);
}
}
return direction;
}
}