Commit 0ce0f844 authored by Nico Mack's avatar Nico Mack

Implemented reset feature in SelectorWidget. Better handling of

preselect
parent 59630dc1
...@@ -4,6 +4,7 @@ import lu.list.itis.dkd.tui.cps.system.Import; ...@@ -4,6 +4,7 @@ import lu.list.itis.dkd.tui.cps.system.Import;
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.cps.variable.VectorVariable; import lu.list.itis.dkd.tui.cps.variable.VectorVariable;
import lu.list.itis.dkd.tui.utility.StringUtils;
import org.python.core.Py; import org.python.core.Py;
import org.python.core.PyArray; import org.python.core.PyArray;
...@@ -54,7 +55,10 @@ public class PythonExecutor extends Executor { ...@@ -54,7 +55,10 @@ public class PythonExecutor extends Executor {
engine.setErr(this.executionErrors); engine.setErr(this.executionErrors);
engine.exec("import sys"); //$NON-NLS-1$ engine.exec("import sys"); //$NON-NLS-1$
engine.exec("sys.path.append ('" + properties.getProperty(SCRIPT_ENGINE_WORKING_DIR) + "')"); //$NON-NLS-1$//$NON-NLS-2$ engine.exec(StringUtils.build("sys.path.append ('{}')", properties.getProperty(SCRIPT_ENGINE_WORKING_DIR))); //$NON-NLS-1$
// engine.exec("sys.path.append ('" + properties.getProperty(SCRIPT_ENGINE_WORKING_DIR) +
// "')"); //$NON-NLS-1$//$NON-NLS-2$
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -274,7 +278,7 @@ public class PythonExecutor extends Executor { ...@@ -274,7 +278,7 @@ public class PythonExecutor extends Executor {
} }
} else { } else {
for (PyObject item : array.asIterable()) { for (PyObject item : array.asIterable()) {
vector.add(item.__tojava__(Object.class)); vector.add(this.depythonizeObject(item));
} }
} }
vector.suspendListenerNotification(false); vector.suspendListenerNotification(false);
...@@ -451,6 +455,6 @@ public class PythonExecutor extends Executor { ...@@ -451,6 +455,6 @@ public class PythonExecutor extends Executor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void resetContext() { public void resetContext() {
// TODO figure out a way to clear engine context // TODO figure out how to reset context
} }
} }
...@@ -167,54 +167,56 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener { ...@@ -167,54 +167,56 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!"); // $NON-NLS-1$
assert newVariables != null;
this.variables = new HashMap<>();
for (Variable<?> variable : newVariables) {
NumericalVariable numeric = (NumericalVariable) variable;
this.variables.put(numeric.getName(), numeric);
variable.addListener(this);
if (dispatcher.containsKey(numeric.getName())) {
Collection<ValueCorona> displays = dispatcher.get(numeric.getName());
for (ValueCorona display : displays) {
display.setVariable(numeric);
}
} else {
LOGGER.warn("Variable {} appears not to be used by any Value Corona!", numeric.getName()); // $NON-NLS-1$
}
}
}
// public void setVariables(Collection<Variable<?>> newVariables) { // public void setVariables(Collection<Variable<?>> newVariables) {
// Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!"); // Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!"); //
// //$NON-NLS-1$ // $NON-NLS-1$
//
// assert newVariables != null;
// //
// this.variables = new HashMap<String, NumericalVariable>(); // this.variables = new HashMap<>();
// for (Variable<?> variable : newVariables) { // for (Variable<?> variable : newVariables) {
// this.variables.put(variable.getName(), (NumericalVariable) variable); // NumericalVariable numeric = (NumericalVariable) variable;
//
// this.variables.put(numeric.getName(), numeric);
// variable.addListener(this); // variable.addListener(this);
// }
// //
// List<ValueCorona> displays = this.getCoronas(ValueCorona.class); // if (dispatcher.containsKey(numeric.getName())) {
// Collection<ValueCorona> displays = dispatcher.get(numeric.getName());
// for (ValueCorona display : displays) { // for (ValueCorona display : displays) {
// Variable<?> variable = display.getVariable(); // display.setVariable(numeric);
// if (variable != null) {
// String variableName = variable.getName();
// if (this.variables.containsKey(variableName)) {
// display.setVariable(this.variables.get(variableName));
// } else {
// LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName);
// //$NON-NLS-1$
// } // }
// } else {
// LOGGER.warn("Variable {} appears not to be used by any Value Corona!", numeric.getName()); //
// $NON-NLS-1$
// } // }
// } // }
// } // }
public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!");
// $NON-NLS-1$
this.variables = new HashMap<>();
for (Variable<?> variable : newVariables) {
this.variables.put(variable.getName(), (NumericalVariable) variable);
variable.addListener(this);
}
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
String variableName = variable.getName();
if (this.variables.containsKey(variableName)) {
display.setVariable(this.variables.get(variableName));
} else {
LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName);
// $NON-NLS-1$
}
}
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@Override @Override
......
...@@ -25,6 +25,8 @@ public class SelectorWidget extends ValueWidget { ...@@ -25,6 +25,8 @@ public class SelectorWidget extends ValueWidget {
/** The currently selected position */ /** The currently selected position */
protected int currentPosition = NONE; protected int currentPosition = NONE;
protected int presetPosition = NONE; protected int presetPosition = NONE;
protected float presetAngleOffset = 0;
protected boolean isPersistent = false;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants *
...@@ -157,6 +159,18 @@ public class SelectorWidget extends ValueWidget { ...@@ -157,6 +159,18 @@ public class SelectorWidget extends ValueWidget {
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public void reset() {
if (isPersistent) {
this.selectPosition(presetPosition);
Point centre = this.getPosition();
if (centre != null) {
presetAngleOffset = (float) ((this.getCurrentAngle(currentPosition) - (centre.getAngle() - presetAngleOffset)) % TWO_PI);
}
}
}
// ---------------------------------------------------------------------------
public void setSelectedPosition(int position) { public void setSelectedPosition(int position) {
currentPosition = position; currentPosition = position;
} }
...@@ -179,9 +193,13 @@ public class SelectorWidget extends ValueWidget { ...@@ -179,9 +193,13 @@ public class SelectorWidget extends ValueWidget {
@Override @Override
public void actionMove(TangibleObject tuioObject) { public void actionMove(TangibleObject tuioObject) {
super.actionMove(tuioObject);
int position = getCurrentPosition(tuioObject.getAngle()); double angle = (tuioObject.getAngle() + presetAngleOffset) % TWO_PI;
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), (float) angle));
super.actionMove(clone);
int position = getCurrentPosition(clone.getAngle());
int widgetId = tuioObject.getObjectId(); int widgetId = tuioObject.getObjectId();
StateManager manager = states.get(widgetId); StateManager manager = states.get(widgetId);
...@@ -193,8 +211,10 @@ public class SelectorWidget extends ValueWidget { ...@@ -193,8 +211,10 @@ public class SelectorWidget extends ValueWidget {
autoFading.forEach(corona -> corona.fadeIn()); autoFading.forEach(corona -> corona.fadeIn());
} }
if (manager.isRotating() && (position != currentPosition)) { if (manager.isRotating()) {
this.selectPosition(position); if (position != currentPosition) {
this.selectPosition(position);
}
} }
} }
...@@ -210,10 +230,12 @@ public class SelectorWidget extends ValueWidget { ...@@ -210,10 +230,12 @@ public class SelectorWidget extends ValueWidget {
@Override @Override
public void actionDrop(TangibleObject tuioObject) { public void actionDrop(TangibleObject tuioObject) {
int position = (this.isPersistent(tuioObject.getObjectId())) ? currentPosition : presetPosition; isPersistent = this.isPersistent(tuioObject.getObjectId());
float angle = this.getCurrentAngle(position);
int position = (isPersistent) ? currentPosition : presetPosition;
presetAngleOffset = (isPersistent) ? (float) ((this.getCurrentAngle(position) - tuioObject.getAngle()) % TWO_PI) : 0;
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), angle)); TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), presetAngleOffset));
super.actionDrop(clone); super.actionDrop(clone);
this.selectPosition(position); this.selectPosition(position);
......
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