Commit 847d09e0 authored by Nathan Bonnemberger's avatar Nathan Bonnemberger
Browse files

Template_scenario usable with generic Variable type ;...

Template_scenario usable with generic Variable type ; SpatialVariable/PositionWidget still not functionnal
parent 39a7ade5
......@@ -9,12 +9,6 @@
<triggerCondition>output &gt; 100</triggerCondition> <!-- Condition: &gt; &lt; == != &amp;&amp; -->
<drawPriority>0</drawPriority> <!-- Smaller drawing priority is occluded by bigger drawing priority -->
</scene>
<scene>
<name>Background1</name> <!-- The name of the scene -->
<image>assets/green_zone.jpg</image> <!-- The image file name: needs to be 1920x1080 px -->
<triggerCondition>x1 &gt; 0.5</triggerCondition> <!-- Condition: &gt; &lt; == != &amp;&amp; -->
<drawPriority>0</drawPriority> <!-- Smaller drawing priority is occluded by bigger drawing priority -->
</scene>
</scenes>
<objects>
<!-- Template Widget: Copy for each widget -->
......@@ -32,6 +26,7 @@
</handles>
<variable>
<name>variable</name> <!-- name of the variable/widget -->
<type>numeric</type>
<value>0</value> <!-- value (for placement widget) -->
<unit>gr</unit> <!-- unit -->
</variable>
......@@ -91,57 +86,7 @@
</corona>
</coronas>
</object>
<object>
<type>PositionWidget</type>
<name>Placement</name>
<scaleX>2</scaleX>
<stepXSize>20</stepXSize>
<modifyValueOnTranslation>true</modifyValueOnTranslation>
<leftMostBound>0</leftMostBound>
<rightMostBound>1920</rightMostBound>
<handles>
<handle>1</handle>
</handles>
<variable>
<name>x1</name>
<value>4</value>
<unit>px</unit>
</variable>
<coronas>
<!-- Template TextBox -->
<corona>
<handle>1</handle> <!-- Marker ID: needs to be the same for a same widget -->
<type>TextBox</type>
<drawPriority>275</drawPriority> <!-- needs to be different for each corona -->
<rotateWithHandle>false</rotateWithHandle> <!-- if true it rotates with the object -->
<lineWidth>200</lineWidth> <!-- width of one line in pixel -->
<font>Arial-20</font> <!-- Font and size -->
<centred>true</centred> <!-- if true is centered -->
<text></text> <!-- insert here text it should show some -->
<assignable>true</assignable> <!-- if true it shows the value of the variable, otherwise it shows the content of the "text" field -->
<initialTranslation>
<x>-2</x><y>51</y><z>0</z> <!-- in pixel -->
<state>ScreenCoordinates</state>
</initialTranslation>
</corona>
<corona>
<handle>1</handle> <!-- Marker ID: needs to be the same for a same widget -->
<type>ConditionalCorona</type>
<drawPriority>276</drawPriority> <!-- needs to be different for each corona -->
<rotateWithHandle>false</rotateWithHandle> <!-- if true it rotates with the object -->
<image>assets/green_zone.jpg</image> <!-- The image file name -->
<triggerCondition>false</triggerCondition> <!-- Condition: &gt; &lt; == != &amp;&amp; -->
<spinOnCoronaCentre>true</spinOnCoronaCentre>
<triggers>
<trigger>x1</trigger> <!-- insert each variable you use for the trigger condition -->
</triggers>
<initialTranslation>
<x>-158</x><y>-141</y><z>0</z> <!-- in pixel -->
<state>ScreenCoordinates</state>
</initialTranslation>
</corona>
</coronas>
</object>
</objects>
<system>
<outputs>
......@@ -170,21 +115,6 @@
</result>
</results>
</equation>
<equation> <!-- copy for each equation -->
<name>all</name> <!-- name of the equation -->
<invoke>x1 + 0</invoke> <!-- equation -->
<parameters>
<parameter> <!-- copy for each of the variables needed in the equation -->
<name>x1</name> <!-- insert variable name -->
<unit>px</unit> <!-- unit of the variable -->
</parameter>
</parameters>
<results>
<result>
<name>all</name> <!-- insert output variable name -->
</result>
</results>
</equation>
</equations>
</system>
</scenario>
\ No newline at end of file
......@@ -28,6 +28,7 @@ import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.bootstrapping.TangibleApplicationBootstrapper;
import lu.list.itis.dkd.tui.cps.system.EquationSystemBuilder;
import lu.list.itis.dkd.tui.cps.system.EquationSystemException;
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.tangible.TangibleNumericalVariable;
import lu.list.itis.dkd.tui.exception.BuildException;
......@@ -56,8 +57,8 @@ import java.util.Properties;
public class Scenario {
private Map<String, Scene> scenes;
private static Map<String, Variable> inputs;
private static Map<String, Variable> outputs;
private static Map<String, Variable<?>> inputs;
private static Map<String, Variable<?>> outputs;
private EquationSystemBuilder equationSystemBuilder;
Properties properties;
......@@ -144,7 +145,7 @@ public class Scenario {
}
}
if (widget instanceof PositionWidget) {
final TangibleNumericalVariable variable = retrieveVariableByName(((PositionWidget) widget).getVariable().getName());
final SpatialVariable variable = retrieveSpatialVariableByName(((PositionWidget) widget).getVariable().getName());
((PositionWidget) widget).setVariable(variable);
for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) {
......@@ -166,6 +167,18 @@ public class Scenario {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
/**
* Method used to find a spatial variable given its name in either input or output maps.
*
* @param name
* The name of the variable to find.
* @return The {@link SpatialVariable} that responds to the given name or <code>null</code>
* should no such variable exist.
*/
static @Nullable SpatialVariable retrieveSpatialVariableByName(String name) {
return (SpatialVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
/**
* Entry point for the application.
*
......
......@@ -68,7 +68,7 @@ public class Scene extends Content {
/** The equation that will evaluate the trigger condition. */
private Equation trigger;
/** All variables that will be needed to evaluate the trigger condition. */
private LinkedHashSet<Variable> variables = new LinkedHashSet<>();
private LinkedHashSet<Variable<?>> variables = new LinkedHashSet<>();
/** Variable used to easily gather the output from the trigger equation. */
private BooleanVariable triggerVariable = new BooleanVariable("Trigger", false); //$NON-NLS-1$
/** The image to show when painting. */
......@@ -103,7 +103,7 @@ public class Scene extends Content {
while (variableMatcher.find()) {
final String _name = variableMatcher.group(1);
final Variable variable = Scenario.retrieveVariableByName(_name);
final Variable<?> variable = Scenario.retrieveVariableByName(_name);
if (null != variable) {
variables.add(variable);
......@@ -116,10 +116,12 @@ public class Scene extends Content {
}
final LinkedHashSet<Variable> outputs = new LinkedHashSet<>();
final LinkedHashSet<Variable<?>> outputs = new LinkedHashSet<>();
outputs.add(triggerVariable);
trigger = new Equation(new Mapping(variables, outputs), triggerCondition);
// TODO: find a way to automatically give a meaningful name to the Equation objects (for now
// just number)
trigger = new Equation("#13", new Mapping(variables, outputs), triggerCondition); //$NON-NLS-1$
trigger.setExecutor(new JavascriptExecutor());
try {
......
......@@ -12,18 +12,27 @@
<object>
<type>PositionWidget</type>
<name>Placement</name>
<scaleX>1</scaleX>
<scaleX>1.0</scaleX>
<scaleY>1.0</scaleY>
<stepXSize>0.1</stepXSize>
<stepYSize>0.1</stepYSize>
<modifyValueOnTranslation>true</modifyValueOnTranslation>
<leftMostBound>0</leftMostBound>
<rightMostBound>1</rightMostBound>
<leftMostBound>0.0</leftMostBound>
<rightMostBound>1.0</rightMostBound>
<downMostBound>0.0</downMostBound>
<upMostBound>1.0</upMostBound>
<handles>
<handle>1</handle>
</handles>
<variable>
<name>x</name>
<value>0</value>
<unit>px</unit>
<name>pos</name>
<type>spatial</type>
<position>
<x>0</x>
<y>0</y>
<z>0</z>
<state>ScreenCoordinates</state>
</position>
</variable>
<coronas>
<!-- Template TextBox -->
......@@ -50,13 +59,13 @@
<image>assets/green_zone.jpg</image> <!-- The image file name -->
<spinOnCoronaCentre>true</spinOnCoronaCentre>
<triggers>
<trigger>x</trigger> <!-- insert each variable you use for the trigger condition -->
<trigger>pos</trigger> <!-- insert each variable you use for the trigger condition -->
</triggers>
<initialTranslation>
<x>-158</x><y>-141</y><z>0</z> <!-- in pixel -->
<state>ScreenCoordinates</state>
</initialTranslation>
<triggerCondition>x &gt; 0.5</triggerCondition> <!-- Condition: &gt; &lt; == != &amp;&amp; -->
<triggerCondition>pos &gt; 0.5</triggerCondition> <!-- Condition: &gt; &lt; == != &amp;&amp; -->
</corona>
</coronas>
</object>
......@@ -73,11 +82,11 @@
<equations>
<equation> <!-- copy for each equation -->
<name>all</name> <!-- name of the equation -->
<invoke>x + 0</invoke> <!-- equation -->
<invoke>pos + 0</invoke> <!-- equation -->
<parameters>
<parameter> <!-- copy for each of the variables needed in the equation -->
<name>x</name> <!-- insert variable name -->
<unit>px</unit> <!-- unit of the variable -->
<name>pos</name> <!-- insert variable name -->
<unit></unit> <!-- unit of the variable -->
</parameter>
</parameters>
<results>
......
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