Commit ed5fb542 authored by Nico Mack's avatar Nico Mack
Browse files

Add coordinate state to SpatialVariable buildFromString method

Changed asynchronous task synchronisation to wait/notify mechanism
Moved initialValue property to Variable Base class
parent ecd415f1
...@@ -7,6 +7,7 @@ BLINK_ON_OUT_OF_RANGE_NODE=blinkOnOutOfRange ...@@ -7,6 +7,7 @@ BLINK_ON_OUT_OF_RANGE_NODE=blinkOnOutOfRange
CAPPED_DISPLAY_NODE=cappedDisplay CAPPED_DISPLAY_NODE=cappedDisplay
COLOUR_SCALE_NODE=colourScale COLOUR_SCALE_NODE=colourScale
DECIMALS_ATTRIBUTE=decimals DECIMALS_ATTRIBUTE=decimals
DEFLECTION_NODE=deflection
DISPLAY_MODE_NODE=displayMode DISPLAY_MODE_NODE=displayMode
FACE_IS_TOUCHABLE_NODE=faceIsTouchable FACE_IS_TOUCHABLE_NODE=faceIsTouchable
FOREGROUND_NODE=foreground FOREGROUND_NODE=foreground
...@@ -37,13 +38,12 @@ RELATIVE_NODE=relative ...@@ -37,13 +38,12 @@ RELATIVE_NODE=relative
REVERSED_NODE=reversed REVERSED_NODE=reversed
ROTATION_NODE=rotation ROTATION_NODE=rotation
SCALES_NODE=scales SCALES_NODE=scales
SHIFT_NODE=shift
SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius SELECTED_RADIUS_NODE=selectedRadius
STEP_SIZE_NODE=stepSize STEP_SIZE_NODE=stepSize
STRETCH_TO_FIT_NODE=stretchToFit STRETCH_TO_FIT_NODE=stretchToFit
TRACK_ROTATION_CONTINUOUSLY_NODE=trackRotationContinuously TRACK_ROTATION_CONTINUOUSLY_NODE=trackRotationContinuously
TRACK_SHIFT_CONTINUOUSLY_NODE=trackShiftContinuously TRACK_DEFLECTION_CONTINUOUSLY_NODE=trackDeflectionContinuously
TRACK_TRANSLATION_CONTINUOUSLY_NODE=trackTranslationContinuously TRACK_TRANSLATION_CONTINUOUSLY_NODE=trackTranslationContinuously
TRANSLATION_NODE=translation TRANSLATION_NODE=translation
UPPER_BOUND_RADIUS_NODE=upperBoundRadius UPPER_BOUND_RADIUS_NODE=upperBoundRadius
......
...@@ -37,6 +37,7 @@ INITIAL_ATTRIBUTE=initial ...@@ -37,6 +37,7 @@ INITIAL_ATTRIBUTE=initial
MINIMUM_ATTRIBUTE=minimum MINIMUM_ATTRIBUTE=minimum
MAXIMUM_ATTRIBUTE=maximum MAXIMUM_ATTRIBUTE=maximum
SCALE_ATTRIBUTE=scale SCALE_ATTRIBUTE=scale
STATE_ATTRIBUTE=state
DECIMALS_ATTRIBUTE=decimals DECIMALS_ATTRIBUTE=decimals
PARAMETERS_ELEMENT=parameters PARAMETERS_ELEMENT=parameters
PERIODIC_ATTRIBUTE=periodic PERIODIC_ATTRIBUTE=periodic
......
...@@ -38,13 +38,8 @@ import java.util.LinkedHashSet; ...@@ -38,13 +38,8 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
...@@ -70,11 +65,12 @@ public class Equation { ...@@ -70,11 +65,12 @@ public class Equation {
private boolean isolated; private boolean isolated;
private boolean asynchronous; private boolean asynchronous;
private boolean done;
private static final Logger LOGGER = LoggerFactory.getLogger(Equation.class.getSimpleName()); private static final Logger LOGGER = LoggerFactory.getLogger(Equation.class.getSimpleName());
private static ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(); private static ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
private ScheduledExecutorService polling; // private ScheduledExecutorService polling;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
...@@ -184,46 +180,62 @@ public class Equation { ...@@ -184,46 +180,62 @@ public class Equation {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private void asynchronousEvaluate() { private void asynchronousEvaluate() {
Future<HashMap<InputChangeListener, List<Variable<?>>>> asyncTask; // Future<HashMap<InputChangeListener, List<Variable<?>>>> asyncTask;
polling = Executors.newSingleThreadScheduledExecutor(); // polling = Executors.newSingleThreadScheduledExecutor();
Object semaphore = new Object();
done = false;
Runnable asyncTask = () -> {
try { try {
asyncTask = executor.submit(new Callable<HashMap<InputChangeListener, List<Variable<?>>>>() {
@Override
public HashMap<InputChangeListener, List<Variable<?>>> call() throws Exception {
scriptExecutor.eval(script); scriptExecutor.eval(script);
return (retrieveResults()); done = true;
synchronized (semaphore) {
semaphore.notifyAll();
} }
});
} catch (Exception exception) { } catch (Exception exception) {
LOGGER.error("Error while evaluating script {}", this.script); //$NON-NLS-1$ LOGGER.error("Error while evaluating script {}", this.script); //$NON-NLS-1$
LOGGER.error("Engine threw an exception!", exception); //$NON-NLS-1$ LOGGER.error("Engine threw an exception!", exception); //$NON-NLS-1$
return;
} }
};
executor.execute(asyncTask);
// try {
// asyncTask = executor.submit(new Callable<HashMap<InputChangeListener,
// List<Variable<?>>>>() {
// @Override
// public HashMap<InputChangeListener, List<Variable<?>>> call() throws Exception {
// scriptExecutor.eval(script);
// s
// return (retrieveResults());
// }
// });
// } catch (Exception exception) {
// LOGGER.error("Error while evaluating script {}", this.script); //$NON-NLS-1$
// LOGGER.error("Engine threw an exception!", exception); //$NON-NLS-1$
// return;
// }
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Equation Executor Thread Pool Size = {}", executor.getPoolSize()); //$NON-NLS-1$ LOGGER.debug("Equation Executor Thread Pool Size = {}", executor.getPoolSize()); //$NON-NLS-1$
} }
Runnable pollingTask = () -> { Runnable fetchingTask = () -> {
while (!asyncTask.isDone()) { while (!done) {
synchronized (semaphore) {
try { try {
TimeUnit.MILLISECONDS.sleep(1000); semaphore.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.error("Evaluation interrupted!", e); //$NON-NLS-1$
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
try {
processResults(asyncTask.get());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
LOGGER.error("Error while retrieving results!", e);
} }
polling.shutdownNow(); processResults(retrieveResults());
}; };
polling.scheduleAtFixedRate(pollingTask, 0, 1000, TimeUnit.MILLISECONDS); executor.execute(fetchingTask);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -236,12 +236,14 @@ public class EquationSystemBuilder { ...@@ -236,12 +236,14 @@ public class EquationSystemBuilder {
case EquationSystemBundle.SPATIAL_TYPE: case EquationSystemBundle.SPATIAL_TYPE:
variableClass = properties.getProperty(EquationSystemBundle.SPATIAL_VARIABLE_CLASS); variableClass = properties.getProperty(EquationSystemBundle.SPATIAL_VARIABLE_CLASS);
variable = (Variable<T>) Class.forName(variableClass) variable = (Variable<T>) Class.forName(variableClass)
.getConstructor(String.class, String.class, Point.class) .getConstructor(String.class, String.class, Point.class)
.newInstance(name, unit, null); .newInstance(name, unit, null);
if (!Strings.isNullOrEmpty(value)) if (!Strings.isNullOrEmpty(value)) {
variable.setValue(variable.valueFromString(value)); variable.setInitialValue(variable.valueFromString(value));
variable.setValue(variable.getInitialValue());
}
break; break;
case EquationSystemBundle.VECTOR_TYPE: case EquationSystemBundle.VECTOR_TYPE:
...@@ -263,7 +265,6 @@ public class EquationSystemBuilder { ...@@ -263,7 +265,6 @@ public class EquationSystemBuilder {
.newInstance(name); .newInstance(name);
if (!Strings.isNullOrEmpty(value)) if (!Strings.isNullOrEmpty(value))
variable.setValue(variable.valueFromString(value)); variable.setValue(variable.valueFromString(value));
break; break;
} }
......
...@@ -80,6 +80,7 @@ public class EquationSystemBundle extends NLS { ...@@ -80,6 +80,7 @@ public class EquationSystemBundle extends NLS {
public static String MINIMUM_ATTRIBUTE; public static String MINIMUM_ATTRIBUTE;
public static String MAXIMUM_ATTRIBUTE; public static String MAXIMUM_ATTRIBUTE;
public static String SCALE_ATTRIBUTE; public static String SCALE_ATTRIBUTE;
public static String STATE_ATTRIBUTE;
public static String DECIMALS_ATTRIBUTE; public static String DECIMALS_ATTRIBUTE;
public static String TYPE_NODE; public static String TYPE_NODE;
......
...@@ -51,7 +51,6 @@ import java.util.ArrayList; ...@@ -51,7 +51,6 @@ import java.util.ArrayList;
public class NumericalVariable extends Variable<Double> { public class NumericalVariable extends Variable<Double> {
protected double minValue; protected double minValue;
protected double maxValue; protected double maxValue;
protected double initialValue;
protected double scale; protected double scale;
protected double valueRange; protected double valueRange;
...@@ -399,23 +398,12 @@ public class NumericalVariable extends Variable<Double> { ...@@ -399,23 +398,12 @@ public class NumericalVariable extends Variable<Double> {
*/ */
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public void setInitialValue(double value) { @Override
public void setInitialValue(Double value) {
this.initialValue = Math.max(value, this.minValue); this.initialValue = Math.max(value, this.minValue);
this.initialValue = Math.min(value, this.maxValue); this.initialValue = Math.min(value, this.maxValue);
} }
// ---------------------------------------------------------------------------
/**
*
* @return the smallest difference between a given number and the next different number.
*/
// ---------------------------------------------------------------------------
public double getInitialValue() {
return this.initialValue;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** /**
* Specifies the smallest difference between a given number and the next different number. * Specifies the smallest difference between a given number and the next different number.
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
package lu.list.itis.dkd.tui.cps.variable; package lu.list.itis.dkd.tui.cps.variable;
import lu.list.itis.dkd.dbc.annotation.Nullable; import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.CoordinateStateBootstrapper;
import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle; import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle;
import lu.list.itis.dkd.tui.cps.utility.ExecutorScope; import lu.list.itis.dkd.tui.cps.utility.ExecutorScope;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.utility.Point;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -32,11 +35,9 @@ import java.util.regex.Pattern; ...@@ -32,11 +35,9 @@ import java.util.regex.Pattern;
*/ */
public class SpatialVariable extends Variable<Point> { public class SpatialVariable extends Variable<Point> {
private Point initialValue;
private static final Logger LOGGER = LoggerFactory.getLogger(SpatialVariable.class.getSimpleName()); private static final Logger LOGGER = LoggerFactory.getLogger(SpatialVariable.class.getSimpleName());
private static final Pattern SPATIAL_STRING_PATTERN = Pattern.compile("([0-9]+\\.?[0-9]*)\\s*,\\s*([0-9]+\\.?[0-9]*)(\\s*,\\s*([0-9]+\\.?[0-9]*))?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ private static final Pattern SPATIAL_STRING_PATTERN = Pattern.compile("([0-9]+\\.?[0-9]*)\\s*,\\s*([0-9]+\\.?[0-9]*)(\\s*,\\s*([0-9]+\\.?[0-9]*))?(,\\s*([a-z_]*))?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
...@@ -139,9 +140,17 @@ public class SpatialVariable extends Variable<Point> { ...@@ -139,9 +140,17 @@ public class SpatialVariable extends Variable<Point> {
a = (float) Double.parseDouble(pointMatcher.group(4)); a = (float) Double.parseDouble(pointMatcher.group(4));
} }
newPoint = new Point(x, y, a); newPoint = new Point(x, y, a);
if (pointMatcher.group(6) != null) {
CoordinateState state = CoordinateStateBootstrapper.getCoordinateState(pointMatcher.group(6), newPoint);
newPoint = new Point(x, y, a, state.getClass());
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
LOGGER.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue, e); //$NON-NLS-1$ LOGGER.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue, e); //$NON-NLS-1$
throw e; throw e;
} catch (BuildException e) {
LOGGER.error("No such coordinate state {}!", pointMatcher.group(6)); //$NON-NLS-1$
} }
} else { } else {
LOGGER.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue); //$NON-NLS-1$ LOGGER.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue); //$NON-NLS-1$
......
...@@ -40,8 +40,6 @@ import java.util.Vector; ...@@ -40,8 +40,6 @@ import java.util.Vector;
@NonNullByDefault @NonNullByDefault
public class TextVariable extends Variable<String> { public class TextVariable extends Variable<String> {
private String initialValue;
private static final Logger logger = LoggerFactory.getLogger(TextVariable.class.getSimpleName()); private static final Logger logger = LoggerFactory.getLogger(TextVariable.class.getSimpleName());
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -66,6 +66,8 @@ public abstract class Variable<V> implements Cloneable { ...@@ -66,6 +66,8 @@ public abstract class Variable<V> implements Cloneable {
protected V value; protected V value;
protected V initialValue;
protected boolean modified = true; protected boolean modified = true;
protected int suspendNotificationSemaphore = 0; protected int suspendNotificationSemaphore = 0;
...@@ -215,6 +217,14 @@ public abstract class Variable<V> implements Cloneable { ...@@ -215,6 +217,14 @@ public abstract class Variable<V> implements Cloneable {
} }
} }
public void setInitialValue(V newInitialValue) {
this.initialValue = newInitialValue;
}
public V getInitialValue() {
return this.initialValue;
}
/** /**
* Method used to set the value held by the variable from an object. * Method used to set the value held by the variable from an object.
* *
......
...@@ -40,6 +40,7 @@ public class CpsNamespace extends NLS { ...@@ -40,6 +40,7 @@ public class CpsNamespace extends NLS {
public static String FOREGROUND_NODE; public static String FOREGROUND_NODE;
public static String DECIMALS_ATTRIBUTE; public static String DECIMALS_ATTRIBUTE;
public static String DEFLECTION_NODE;
public static String DISPLAY_MODE_NODE; public static String DISPLAY_MODE_NODE;
public static String HTML_TEMPLATE_NODE; public static String HTML_TEMPLATE_NODE;
...@@ -79,7 +80,6 @@ public class CpsNamespace extends NLS { ...@@ -79,7 +80,6 @@ public class CpsNamespace extends NLS {
public static String ROTATION_NODE; public static String ROTATION_NODE;
public static String SCALES_NODE; public static String SCALES_NODE;
public static String SHIFT_NODE;
public static String SELECTED_ITEMS_VARIABLE_NODE; public static String SELECTED_ITEMS_VARIABLE_NODE;
...@@ -88,7 +88,7 @@ public class CpsNamespace extends NLS { ...@@ -88,7 +88,7 @@ public class CpsNamespace extends NLS {
public static String STRETCH_TO_FIT_NODE; public static String STRETCH_TO_FIT_NODE;
public static String TRACK_ROTATION_CONTINUOUSLY_NODE; public static String TRACK_ROTATION_CONTINUOUSLY_NODE;
public static String TRACK_SHIFT_CONTINUOUSLY_NODE; public static String TRACK_DEFLECTION_CONTINUOUSLY_NODE;
public static String TRACK_TRANSLATION_CONTINUOUSLY_NODE; public static String TRACK_TRANSLATION_CONTINUOUSLY_NODE;
public static String TRANSLATION_NODE; public static String TRANSLATION_NODE;
......
...@@ -17,6 +17,8 @@ import lu.list.itis.dkd.tui.adapter.TangibleObject; ...@@ -17,6 +17,8 @@ import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable; import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.event.TimerEvent; import lu.list.itis.dkd.tui.event.TimerEvent;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.CameraCoordinates;
import lu.list.itis.dkd.tui.utility.CoordinateState; import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper; import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper;
...@@ -44,11 +46,11 @@ import java.util.Map; ...@@ -44,11 +46,11 @@ import java.util.Map;
public class JoystickWidget extends PositionWidget { public class JoystickWidget extends PositionWidget {
protected SpatialVariable location; protected SpatialVariable location;
protected SpatialVariable shift; protected SpatialVariable deflection;
protected boolean orthogonalToOrientation; protected boolean orthogonalToOrientation;
protected boolean trackShiftContinuously; protected boolean trackDeflectionContinuously;
private StateManager shiftState; private StateManager deflectionState;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants *
...@@ -71,9 +73,9 @@ public class JoystickWidget extends PositionWidget { ...@@ -71,9 +73,9 @@ public class JoystickWidget extends PositionWidget {
public JoystickWidget(BaseJoystickWidgetBuilder<?> builder) { public JoystickWidget(BaseJoystickWidgetBuilder<?> builder) {
super(builder); super(builder);
this.location = builder.location; this.location = builder.location;
this.shift = builder.shift; this.deflection = builder.deflection;
this.orthogonalToOrientation = builder.orthogonalToOrientation; this.orthogonalToOrientation = builder.orthogonalToOrientation;
this.trackShiftContinuously = builder.trackShiftContinuously; this.trackDeflectionContinuously = builder.trackDeflectionContinuously;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -88,11 +90,7 @@ public class JoystickWidget extends PositionWidget { ...@@ -88,11 +90,7 @@ public class JoystickWidget extends PositionWidget {
if ((systemVariables != null) && systemVariables.containsKey(candidate.getName())) { if ((systemVariables != null) && systemVariables.containsKey(candidate.getName())) {
SpatialVariable spatial = Variable.castTo(systemVariables.get(candidate.getName()), SpatialVariable.class); SpatialVariable spatial = Variable.castTo(systemVariables.get(candidate.getName()), SpatialVariable.class);
if (spatial != null) { if (spatial != null) {
Point initial = candidate.getValue();
connected = spatial; connected = spatial;
if (initial != null) {
connected.setValue(initial);
}
} }
} }
return connected; return connected;
...@@ -102,9 +100,9 @@ public class JoystickWidget extends PositionWidget { ...@@ -102,9 +100,9 @@ public class JoystickWidget extends PositionWidget {
private void updateShiftFromMove(Point newPosition, boolean continuous) { private void updateShiftFromMove(Point newPosition, boolean continuous) {
if (this.shift != null) { if (this.deflection != null) {
Point origin = this.location.getValue().clone(); Point origin = this.location.getValue().clone();
Point displacement = this.shift.getValue(); Point displacement = this.deflection.getValue();
if (displacement != null) { if (displacement != null) {
CoordinateState coordinates = displacement.getState(); CoordinateState coordinates = displacement.getState();
newPosition = newPosition.toCoordinates(coordinates.getClass()); newPosition = newPosition.toCoordinates(coordinates.getClass());
...@@ -112,7 +110,7 @@ public class JoystickWidget extends PositionWidget { ...@@ -112,7 +110,7 @@ public class JoystickWidget extends PositionWidget {
Point offset = newPosition.subtract(origin, false); Point offset = newPosition.subtract(origin, false);
boolean doUpdate = false; boolean doUpdate = false;
if (modifyValueOnTranslation && (!continuous || trackShiftContinuously)) { if (modifyValueOnTranslation && (!continuous || trackDeflectionContinuously)) {
if (!Double.isNaN(this.stepSize)) { if (!Double.isNaN(this.stepSize)) {
double distance = offset.magnitude(); double distance = offset.magnitude();
doUpdate |= (distance >= this.stepSize); doUpdate |= (distance >= this.stepSize);
...@@ -130,18 +128,20 @@ public class JoystickWidget extends PositionWidget { ...@@ -130,18 +128,20 @@ public class JoystickWidget extends PositionWidget {
} }
if (doUpdate) { if (doUpdate) {
offset = PolarCoordinateHelper.rotate(offset, origin.getAngle()); Point polar = PolarCoordinateHelper.carthesianToPolar(offset);
polar.setAngle((float) AngleUtils.moduloTwoPi(-(polar.getAngle() - origin.getAngle())));
offset = PolarCoordinateHelper.polarToCarthesian(polar);
} }
} }
if (doUpdate) { if (doUpdate) {
this.shift.setValue(offset); this.deflection.setValue(offset);
if (LOGGER.isInfoEnabled()) { if (LOGGER.isInfoEnabled()) {
LOGGER.info("Shift {}", offset); //$NON-NLS-1$ LOGGER.info("Shift {}", offset); //$NON-NLS-1$
} }
} }
} else { } else {
this.shift.setValue(new Point()); this.deflection.setValue(new Point());
} }
} }
} }
...@@ -154,9 +154,13 @@ public class JoystickWidget extends PositionWidget { ...@@ -154,9 +154,13 @@ public class JoystickWidget extends PositionWidget {
@Override @Override
public void actionDrop(TangibleObject tuioObject) { public void actionDrop(TangibleObject tuioObject) {
this.location.setValue(this.getPointingLocation(tuioObject.getPosition())); Point position = this.getPointingLocation(tuioObject.getPosition());
this.shiftState = new StateManager(false); CoordinateState coordinates = this.location.getValue().getState();
this.shiftState.drop(this.location.getValue()); position = position.toCoordinates(coordinates.getClass());
this.location.setValue(position);
this.deflection.clear();
this.deflectionState = new StateManager(false);
this.deflectionState.drop(this.location.getValue());
super.actionDrop(tuioObject); super.actionDrop(tuioObject);
} }
...@@ -168,12 +172,14 @@ public class JoystickWidget extends PositionWidget { ...@@ -168,12 +172,14 @@ public class JoystickWidget extends PositionWidget {
if (modifyValueOnRotation || trackRotationContinuously) { if (modifyValueOnRotation || trackRotationContinuously) {
this.location.setAngle((double) tuioObject.getAngle()); this.location.setAngle((double) tuioObject.getAngle());
} }
super.actionMove(tuioObject.constrainedClone(this.location.getValue())); Point origin = this.location.getValue().clone();
origin = origin.toCoordinates(CameraCoordinates.class);
super.actionMove(tuioObject.constrainedClone(origin));
Point position = this.getPointingLocation(tuioObject.getPosition()); Point position = this.getPointingLocation(tuioObject.getPosition());
this.shiftState.move(position).rotate(position); this.deflectionState.move(position).rotate(position);
if (this.shiftState.isMoving() || this.shiftState.isRotating()) { if (this.deflectionState.isMoving() || this.deflectionState.isRotating()) {
this.updateShiftFromMove(position, CONTINUOUS); this.updateShiftFromMove(position, CONTINUOUS);
} }
} }
...@@ -193,10 +199,10 @@ public class JoystickWidget extends PositionWidget { ...@@ -193,10 +199,10 @@ public class JoystickWidget extends PositionWidget {
connected.add(this.location); connected.add(this.location);
} }
spatialSystemVariable = this.connectSpatialVariable(this.shift, systemVariables); spatialSystemVariable = this.connectSpatialVariable(this.deflection, systemVariables);
if (spatialSystemVariable != null) { if (spatialSystemVariable != null) {
this.shift = spatialSystemVariable; this.deflection = spatialSystemVariable;
connected.add(this.shift); connected.add(this.deflection);
} }
connected.addAll(VariableUtils.connectWithSystemVariables(this, systemVariables)); connected.addAll(VariableUtils.connectWithSystemVariables(this, systemVariables));
...@@ -212,7 +218,7 @@ public class JoystickWidget extends PositionWidget { ...@@ -212,7 +218,7 @@ public class JoystickWidget extends PositionWidget {
public List<Variable<?>> getDeclaredVariables() { public List<Variable<?>> getDeclaredVariables() {
List<Variable<?>> declared = new ArrayList<>(); List<Variable<?>> declared = new ArrayList<>();
declared.add(this.variable); declared.add(this.variable);
declared.add(this.shift); declared.add(this.deflection);
return declared; return declared;
} }
......
...@@ -25,9 +25,9 @@ import org.jdom2.Element; ...@@ -25,9 +25,9 @@ import org.jdom2.Element;
public abstract class BaseJoystickWidgetBuilder<B extends BaseJoystickWidgetBuilder<B>> extends BasePositionWidgetBuilder<B> { public abstract class BaseJoystickWidgetBuilder<B extends BaseJoystickWidgetBuilder<B>> extends BasePositionWidgetBuilder<B> {
/** */ /** */
public SpatialVariable location; public SpatialVariable location;
public SpatialVariable shift; public SpatialVariable deflection;
public boolean orthogonalToOrientation; public boolean orthogonalToOrientation;
public boolean trackShiftContinuously; public boolean trackDeflectionContinuously;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants *
...@@ -66,13 +66,13 @@ public abstract class BaseJoystickWidgetBuilder<B extends BaseJoystickWidgetBuil ...@@ -66,13 +66,13 @@ public abstract class BaseJoystickWidgetBuilder<B extends BaseJoystickWidgetBuil
Element variablesNode = rootElement.getChild(CpsNamespace.VARIABLES_NODE); Element variablesNode = rootElement.getChild(CpsNamespace.VARIABLES_NODE);
if (variablesNode != null) { if (variablesNode != null) {
this.location = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(variablesNode.getChild(CpsNamespace.LOCATION_NODE), context, callback); this.location = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(variablesNode.getChild(CpsNamespace.LOCATION_NODE), context, callback);
this.shift = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(variablesNode.getChild(CpsNamespace.SHIFT_NODE), context, callback); this.deflection = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(variablesNode.getChild(CpsNamespace.DEFLECTION_NODE), context, callback);
} else { } else {
BootstrappingUtils.logAndThrowMandatoryNodeException(variablesNode, CpsNamespace.VARIABLES_NODE); BootstrappingUtils.logAndThrowMandatoryNodeException(variablesNode, CpsNamespace.VARIABLES_NODE);
} }
this.orthogonalToOrientation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.ORTHOGONAL_TO_ORIENTATION_NODE, BootstrappingUtils.OPTIONAL, false, context); this.orthogonalToOrientation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.ORTHOGONAL_TO_ORIENTATION_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.trackShiftContinuously = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.TRACK_SHIFT_CONTINUOUSLY_NODE, BootstrappingUtils.OPTIONAL, true, context); this.trackDeflectionContinuously = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.TRACK_DEFLECTION_CONTINUOUSLY_NODE, BootstrappingUtils.OPTIONAL, true, context);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment