diff --git a/CPS/src/lu/list/itis/dkd/tui/bootstrapping/DisplayWidgetBootstrapper.java b/CPS/src/lu/list/itis/dkd/tui/bootstrapping/DisplayWidgetBootstrapper.java index 9bdb1b67343b08ce17a73222954ad6e690e5e3f0..9edb31ad56b47a410c6b822b16a9482bbf37c857 100644 --- a/CPS/src/lu/list/itis/dkd/tui/bootstrapping/DisplayWidgetBootstrapper.java +++ b/CPS/src/lu/list/itis/dkd/tui/bootstrapping/DisplayWidgetBootstrapper.java @@ -144,6 +144,7 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback { /** {@inheritDoc} */ @Override public BootstrapContext reset(BootstrapContext context) { + this.index = 0; variableIterator = variables.iterator(); if (variableIterator.hasNext()) { this.variable = variableIterator.next(); diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/Equation.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/Equation.java index 6f81cf1926c066e599a399c1676a8316b8760123..59c017a4f2a2405f388510c8df094c044d224fda 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/Equation.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/Equation.java @@ -113,7 +113,7 @@ public class Equation { scriptExecutor.eval(this.script); } catch (Exception exception) { 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.toString()); //$NON-NLS-1$ } dependentVariables = mapping.getDependentVariables(); diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java index db1b80bed0bd692c825d8a900164435e9e46afc9..a5d5366b688715137f7c8ba39682fc59980fbbd2 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java @@ -69,7 +69,7 @@ public class PythonExecutor extends Executor { } engine.set(variable.getName(), array); if (LOGGER.isInfoEnabled()) { - LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ + LOGGER.info("Parameter -> {} = {}", variable.getName(), array.toString()); //$NON-NLS-1$ } } else if (Integer.class.isAssignableFrom(vector.getClassOfValues())) { @@ -84,7 +84,7 @@ public class PythonExecutor extends Executor { } engine.set(variable.getName(), array); if (LOGGER.isInfoEnabled()) { - LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ + LOGGER.info("Parameter -> {} = {}", variable.getName(), array.toString()); //$NON-NLS-1$ } } } else { diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/DisplayWidget.java b/CPS/src/lu/list/itis/dkd/tui/widget/DisplayWidget.java index a678ce5c3d131b32198ac2e3351e8d61d5bc8970..e7dc1342198308160ac12e81c476a45be91fb2eb 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/DisplayWidget.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/DisplayWidget.java @@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author nmack @@ -75,12 +76,27 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener { // *************************************************************************** // --------------------------------------------------------------------------- + public void connectWithOutputs(Map> outputs) { + for (String variableName : variables.keySet()) { + NumericalVariable variable = variables.get(variableName); + + if ((outputs != null) && outputs.containsKey(variableName)) { + Variable output = outputs.get(variableName); + if (variable.getClass().isAssignableFrom(output.getClass())) { + NumericalVariable numeric = (NumericalVariable) output; + variables.put(variableName, numeric); + } + } + } + } + public void setVariables(Collection> newVariables) { - Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$ + 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 displays = this.getCoronas(ValueCorona.class); diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java b/CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java index c68ec328ff3c7e17bb7bbd5e676ee98796caf51f..09ca425ed9fdcbbd8b1f3f72785274ca9b47c123 100755 --- a/CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java @@ -1,6 +1,7 @@ package lu.list.itis.dkd.tui.widget; import lu.list.itis.dkd.tui.adapter.TangibleObject; +import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder; import lu.list.itis.dkd.tui.widget.corona.FadingCorona; import lu.list.itis.dkd.tui.widget.corona.IndexedCorona; @@ -103,6 +104,21 @@ public class SelectorWidget extends ValueWidget { // --------------------------------------------------------------------------- + private float getCurrentAngle(int position) { + double segment = TWO_PI / numberOfPositions; + float angle = 0; + + if ((position >= 0) && (position < numberOfPositions)) { + double minrot = (position - 0.5) * segment; + double maxrot = (position + 0.5) * segment; + + angle = (float) (minrot + maxrot) / 2f; + } + return angle; + } + + // --------------------------------------------------------------------------- + private void selectPosition(int position) { if (position != currentPosition) { @@ -149,11 +165,15 @@ public class SelectorWidget extends ValueWidget { int position = getCurrentPosition(tuioObject.getAngle()); int widgetId = tuioObject.getObjectId(); - Stream autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle()); - autoFading.forEach(corona -> corona.fadeIn()); - StateManager manager = states.get(widgetId); + boolean fadeIn = manager.isMoving() || manager.isRotating(); + + if (fadeIn) { + Stream autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle()); + autoFading.forEach(corona -> corona.fadeIn()); + } + if (manager.isRotating()) { if (position != currentPosition) { this.selectPosition(position); @@ -174,7 +194,11 @@ public class SelectorWidget extends ValueWidget { @Override public void actionDrop(TangibleObject tuioObject) { int position = (this.isPersistent(tuioObject.getObjectId())) ? currentPosition : presetPosition; - super.actionDrop(tuioObject); + float angle = this.getCurrentAngle(position); + + TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), angle)); + + super.actionDrop(clone); this.selectPosition(position); } diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java b/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java index 41df2b63028063687ddc8951db31a6e7a01f636c..2fb1b4d835c5156c8f0700848ef953dde22807b8 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java @@ -144,17 +144,13 @@ public class ValueWidget extends TetherableWidget implements InformationProvider public void actionLift(TangibleObject tangibleObject) { super.actionLift(tangibleObject); - // set to 0 only if placing widget - - if (!modifyValueOnRotation) { - getVariable().setValue(0d); - } - - - else { - getVariable().setValue(initialValue); + if (!this.isPersistent(tangibleObject.getObjectId())) { + if (!modifyValueOnRotation) { + getVariable().setValue(0d); + } else { + getVariable().setValue(initialValue); + } } - } @Override diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java index 80608737b88f45b107a67f4368d91cef719eddb6..519786e8a81d405c11bf60d25175cebf89dcc2bc 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java @@ -38,10 +38,17 @@ public class ArcGraph extends ValueCorona { private double outerRadius; private int startAngle; private int arcSpan; + private boolean relative; + private double reference; + private ColorPair fillColour; private ColorPair strokeColour; private ColorPair labelColour; private ColorPair textColour; + + private ColorPair faceColour; + private ColorPair bezelColour; + private Shape labelShape; private Font textFont; private Stroke borderStroke; @@ -49,6 +56,7 @@ public class ArcGraph extends ValueCorona { private Area outer; private Area inner; private Area arc; + private Area face; private String label; private LineMetrics labelMetrics; @@ -76,12 +84,17 @@ public class ArcGraph extends ValueCorona { this.startAngle = builder.startAngle; this.arcSpan = builder.arcSpan; + this.relative = builder.relative; + this.reference = builder.reference; + this.innerRadius = builder.innerRadius; this.outerRadius = builder.outerRadius; this.fillColour = builder.fillColour; this.strokeColour = builder.strokeColour; this.labelColour = builder.labelColour; this.textColour = builder.textColour; + this.faceColour = builder.faceColour; + this.bezelColour = builder.bezelColour; this.labelShape = builder.labelShape; this.textFont = builder.textFont; @@ -91,6 +104,12 @@ public class ArcGraph extends ValueCorona { diameter = 2 * outerRadius; outer = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, diameter, diameter)); + Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE); + face = new Area(sector); + face.subtract(inner); + outer.subtract(inner); + + if (this.labelShape != null) { AffineTransform originTranslator = new AffineTransform(); @@ -102,7 +121,7 @@ public class ArcGraph extends ValueCorona { borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; - this.setInformation(this.variable.getMinValue()); + this.setInformation((relative) ? this.reference : this.variable.getMinValue()); } // --------------------------------------------------------------------------- @@ -142,6 +161,22 @@ public class ArcGraph extends ValueCorona { this.opacity = 1.0f; } + // --------------------------------------------------------------------------- + + private void switchColours(boolean isNegative) { + if (relative) { + fillColour.setSwitched(isNegative); + strokeColour.setSwitched(isNegative); + labelColour.setSwitched(isNegative); + textColour.setSwitched(isNegative); + if (faceColour != null) + faceColour.setSwitched(isNegative); + if (bezelColour != null) + bezelColour.setSwitched(isNegative); + + } + } + // --------------------------------------------------------------------------- // *************************************************************************** // * Class Body * @@ -151,10 +186,17 @@ public class ArcGraph extends ValueCorona { @Override public void setSelected(boolean selectIt) { super.setSelected(selectIt); - fillColour.setSelected(selectIt); - strokeColour.setSelected(selectIt); - labelColour.setSelected(selectIt); - textColour.setSelected(selectIt); + + if (!relative) { + fillColour.setSwitched(selectIt); + strokeColour.setSwitched(selectIt); + labelColour.setSwitched(selectIt); + textColour.setSwitched(selectIt); + if (faceColour != null) + faceColour.setSwitched(selectIt); + if (bezelColour != null) + bezelColour.setSwitched(selectIt); + } } // --------------------------------------------------------------------------- @@ -169,15 +211,28 @@ public class ArcGraph extends ValueCorona { shownValue = value; if (variable != null) { - double extend = arcSpan * (shownValue - this.variable.getMinValue()) / (this.variable.getMaxValue() - this.variable.getMinValue()); - if (extend == arcSpan) + double extend = 0; + double start = 0; + double valueRange = this.variable.getMaxValue() - this.variable.getMinValue(); + + + if (relative) { + start = startAngle + (arcSpan * (this.variable.getMaxValue() / valueRange)); + extend = arcSpan * (shownValue / valueRange); + switchColours(shownValue <= 0); + } else { + start = startAngle; + extend = arcSpan * (shownValue - this.variable.getMinValue()) / valueRange; + } + + if ((shownValue == this.variable.getMaxValue()) || (relative && (shownValue == this.variable.getMinValue()))) this.startBlinking(); else this.stopBlinking(); double diameter = 2 * outerRadius; - Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, startAngle, extend, Arc2D.PIE); + Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, start, extend, Arc2D.PIE); arc = new Area(sector); arc.subtract(inner); outer.subtract(inner); @@ -212,6 +267,18 @@ public class ArcGraph extends ValueCorona { if (this.opacity < 1.0f) localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); + if (faceColour != null) { + localCanvas.setPaint(faceColour.getColor()); + localCanvas.fill(face); + } + + if (bezelColour != null) { + localCanvas.setPaint(bezelColour.getColor()); + if (borderStroke != null) + localCanvas.setStroke(borderStroke); + localCanvas.draw(face); + } + if (fillColour != null) { localCanvas.setPaint(fillColour.getColor()); localCanvas.fill(arc); diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java index 342f265acdb645d540cdc95e988e6da98f4fff22..343181ca29d3cadf8f064b3898e394f5923b2265 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java @@ -34,11 +34,15 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { public double outerRadius; public int startAngle; public int arcSpan; + public boolean relative; + public double reference; public ColorPair fillColour; public ColorPair strokeColour; public ColorPair labelColour; public ColorPair textColour; + public ColorPair faceColour; + public ColorPair bezelColour; public int strokeWidth; public Shape labelShape; public Font textFont; @@ -86,6 +90,8 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { startAngle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context); arcSpan = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context); + relative = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.RELATIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); + reference = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.REFERENCE_NODE, BootstrappingUtils.OPTIONAL, 0d, context); innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context); outerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.OUTER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context); @@ -94,10 +100,12 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context); - fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context); - textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), context); - strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context); - labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), context); + fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context); + textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context); + strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context); + labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context); + faceColour = buildColorPair(rootElement.getChild(Externalization.FACE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context); + bezelColour = buildColorPair(rootElement.getChild(Externalization.BEZEL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context); labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback); @@ -111,11 +119,23 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { // --------------------------------------------------------------------------- - private ColorPair buildColorPair(Element rootElement, BootstrapContext context) throws BuildException { - Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context); - Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context); + private ColorPair buildColorPair(Element rootElement, boolean optional, BootstrapContext context) throws BuildException { + ColorPair color = null; - return new ColorPair(selectedColour, deselectedColour); + if (rootElement == null) + return null; + + if (!relative) { + Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, optional, null, context); + Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, optional, null, context); + color = new ColorPair(selectedColour, deselectedColour); + } else { + Color aboveColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.ABOVE_ELEMENT, optional, null, context); + Color belowColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.BELOW_ELEMENT, optional, null, context); + color = new ColorPair(belowColour, aboveColour); + } + + return color; } // ---------------------------------------------------------------------------