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

Fixes to make COPSE work with dev-nico branches of TULIP and TULIP-CPS

parent 5dc25b40
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN"> <Configuration status="WARN" packages="lu.list.itis.dkd.tui.logging">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console> </Console>
<OnScreenLog name="SplashScreen" size="1000">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</OnScreenLog>
<File name="LogFile" fileName="logs/colosseum.log" append="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="trace"> <Logger name="lu.list.itis.dkd.tui.cps" level="info">
<AppenderRef ref="LogFile" level="info"/>
</Logger>
<Logger name="com.mchange" level="warn"/>
<Root level="info">
<AppenderRef ref="Console"/> <AppenderRef ref="Console"/>
<AppenderRef ref="SplashScreen"/>
</Root> </Root>
<Logger name="lu.list.itis.dkd.tui" level="trace"/>
</Loggers> </Loggers>
</Configuration> </Configuration>
\ No newline at end of file
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
<dependency> <dependency>
<groupId>lu.list.itis.dkd.tui</groupId> <groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId> <artifactId>tulip</artifactId>
<version>2.4.0</version> <version>2.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>lu.list.itis.dkd.tui</groupId> <groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId> <artifactId>tulip-cps</artifactId>
<version>1.4.0</version> <version>1.5.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -32,7 +32,7 @@ bootstrapping.root = circuit_scenario.xml ...@@ -32,7 +32,7 @@ bootstrapping.root = circuit_scenario.xml
# Properties for the equation system # Properties for the equation system
executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.NumericalVariable
equation.system = circuit_scenario.xml equation.system = circuit_scenario.xml
scenario.description = circuit_scenario.xml scenario.description = circuit_scenario.xml
......
...@@ -33,5 +33,5 @@ bootstrapping.root = light_scenario.xml ...@@ -33,5 +33,5 @@ bootstrapping.root = light_scenario.xml
# Properties for the equation system # Properties for the equation system
executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor executor.class = lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable numeric.variable.class = lu.list.itis.dkd.tui.cps.variable.NumericalVariable
logic.variable.class = lu.list.itis.dkd.tui.cps.variable.BooleanVariable logic.variable.class = lu.list.itis.dkd.tui.cps.variable.BooleanVariable
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
<name>Lights</name> <name>Lights</name>
<variable> <variable>
<name>Lights</name> <name>Lights</name>
<unit>Watt</unit> <type>numeric</type>
<value>300</value> <initial>300</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>1</handle> <handle>1</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
<name>Hair Dryer</name> <name>Hair Dryer</name>
<variable> <variable>
<name>Dryer</name> <name>Dryer</name>
<unit>Watt</unit> <type>numeric</type>
<value>2200</value> <initial>1200</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>2</handle> <handle>2</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -94,8 +94,8 @@ ...@@ -94,8 +94,8 @@
<name>Dishwasher</name> <name>Dishwasher</name>
<variable> <variable>
<name>Dishwasher</name> <name>Dishwasher</name>
<unit>Watt</unit> <type>numeric</type>
<value>1800</value> <initial>1800</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>3</handle> <handle>3</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -132,8 +132,8 @@ ...@@ -132,8 +132,8 @@
<name>Laptop</name> <name>Laptop</name>
<variable> <variable>
<name>Laptop</name> <name>Laptop</name>
<unit>Watt</unit> <type>numeric</type>
<value>100</value> <initial>100</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>4</handle> <handle>4</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -170,8 +170,8 @@ ...@@ -170,8 +170,8 @@
<name>Smartphone</name> <name>Smartphone</name>
<variable> <variable>
<name>Smartphone</name> <name>Smartphone</name>
<unit>Watt</unit> <type>numeric</type>
<value>5</value> <initial>5</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -180,7 +180,7 @@ ...@@ -180,7 +180,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>5</handle> <handle>5</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -208,8 +208,8 @@ ...@@ -208,8 +208,8 @@
<name>Breaker</name> <name>Breaker</name>
<variable> <variable>
<name>Breaker</name> <name>Breaker</name>
<unit>A</unit> <type>numeric</type>
<value>16</value> <initial>10</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>6</handle> <handle>6</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -251,8 +251,8 @@ ...@@ -251,8 +251,8 @@
<name>Ampere</name> <name>Ampere</name>
<variable> <variable>
<name>Ampere</name> <name>Ampere</name>
<unit>A</unit> <type>numeric</type>
<value>0</value> <initial>0</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -261,7 +261,7 @@ ...@@ -261,7 +261,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>7</handle> <handle>7</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -289,8 +289,9 @@ ...@@ -289,8 +289,9 @@
<name>Load</name> <name>Load</name>
<variable> <variable>
<name>Load</name> <name>Load</name>
<type>numeric</type>
<unit>%</unit> <unit>%</unit>
<value>0</value> <initial>0</initial>
</variable> </variable>
<modifyValueOnRotation>False</modifyValueOnRotation> <modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type> <type>ValueWidget</type>
...@@ -299,7 +300,7 @@ ...@@ -299,7 +300,7 @@
</handles> </handles>
<coronas> <coronas>
<corona> <corona>
<type>Shadow</type> <type>ShapeCorona</type>
<handle>8</handle> <handle>8</handle>
<shape>Circle</shape> <shape>Circle</shape>
<drawPriority>0</drawPriority> <drawPriority>0</drawPriority>
...@@ -328,11 +329,15 @@ ...@@ -328,11 +329,15 @@
<outputs> <outputs>
<output> <output>
<name>Load</name> <name>Load</name>
<type>numeric</type>
<unit>%</unit> <unit>%</unit>
<decimals>0</decimals>
</output> </output>
<output> <output>
<name>Ampere</name> <name>Ampere</name>
<type>numeric</type>
<unit>A</unit> <unit>A</unit>
<decimals>1</decimals>
</output> </output>
</outputs> </outputs>
<equations> <equations>
...@@ -343,7 +348,6 @@ ...@@ -343,7 +348,6 @@
<name>Lights</name> <name>Lights</name>
<unit>W</unit> <unit>W</unit>
</parameter> </parameter>
<parameter> <parameter>
<name>Dryer</name> <name>Dryer</name>
<unit>W</unit> <unit>W</unit>
...@@ -365,7 +369,6 @@ ...@@ -365,7 +369,6 @@
<results> <results>
<result> <result>
<name>Ampere</name> <name>Ampere</name>
<unit>A</unit>
</result> </result>
</results> </results>
</equation> </equation>
...@@ -374,18 +377,15 @@ ...@@ -374,18 +377,15 @@
<parameters> <parameters>
<parameter> <parameter>
<name>Breaker</name> <name>Breaker</name>
<unit>A</unit>
</parameter> </parameter>
<parameter> <parameter>
<name>Ampere</name> <name>Ampere</name>
<unit>A</unit>
</parameter> </parameter>
</parameters> </parameters>
<invoke>(Ampere / Breaker) * 100</invoke> <invoke>(Ampere / Breaker) * 100</invoke>
<results> <results>
<result> <result>
<name>Load</name> <name>Load</name>
<unit>%</unit>
</result> </result>
</results> </results>
</equation> </equation>
......
...@@ -28,6 +28,7 @@ import lu.list.itis.dkd.tui.TangibleObjectManager; ...@@ -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.bootstrapping.TangibleApplicationBootstrapper;
import lu.list.itis.dkd.tui.cps.system.EquationSystemBuilder; 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.system.EquationSystemException;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
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.tangible.TangibleNumericalVariable; import lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable;
import lu.list.itis.dkd.tui.exception.BuildException; import lu.list.itis.dkd.tui.exception.BuildException;
...@@ -42,6 +43,7 @@ import com.google.common.base.Preconditions; ...@@ -42,6 +43,7 @@ import com.google.common.base.Preconditions;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
/** /**
...@@ -56,13 +58,16 @@ import java.util.Properties; ...@@ -56,13 +58,16 @@ import java.util.Properties;
public class Scenario { public class Scenario {
private Map<String, Scene> scenes; private Map<String, Scene> scenes;
private static Map<String, Variable> inputs; private static Map<String, Variable<?>> inputs;
private static Map<String, Variable> outputs; private static Map<String, Variable<?>> outputs;
private EquationSystemBuilder equationSystemBuilder; private EquationSystemBuilder equationSystemBuilder;
Properties properties; Properties properties;
private TangibleApplication tangibleApplication; private TangibleApplication tangibleApplication;
static {
System.setProperty("log4j.configurationFile", "log4j2.xml"); //$NON-NLS-1$//$NON-NLS-2$
}
/** /**
* Constructor initializing all fields. The constructor will also populate all variables and use * Constructor initializing all fields. The constructor will also populate all variables and use
...@@ -122,8 +127,10 @@ public class Scenario { ...@@ -122,8 +127,10 @@ public class Scenario {
scenes = SceneBootstrapper.getScenes(); scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes); StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance()); tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.getContentManager().initAll();
tangibleApplication.connect(); tangibleApplication.connect();
tangibleApplication.doneLoading();
} }
...@@ -134,9 +141,10 @@ public class Scenario { ...@@ -134,9 +141,10 @@ public class Scenario {
* *
*/ */
private void populateVariables() { private void populateVariables() {
for (final BaseWidget widget : TangibleObjectManager.getWidgets()) { for (final Entry<Integer, BaseWidget> entry : TangibleObjectManager.getWidgets()) {
final BaseWidget widget = entry.getValue();
if (widget instanceof ValueWidget) { if (widget instanceof ValueWidget) {
final TangibleNumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName()); final NumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName());
((ValueWidget) widget).setVariable(variable); ((ValueWidget) widget).setVariable(variable);
for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) { for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) {
...@@ -157,8 +165,8 @@ public class Scenario { ...@@ -157,8 +165,8 @@ public class Scenario {
* @return The {@link TangibleNumericalVariable} that responds to the given name or * @return The {@link TangibleNumericalVariable} that responds to the given name or
* <code>null</code> should no such variable exist. * <code>null</code> should no such variable exist.
*/ */
static @Nullable TangibleNumericalVariable retrieveVariableByName(String name) { static @Nullable NumericalVariable retrieveVariableByName(String name) {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name)); return (NumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
} }
/** /**
......
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
package lu.list.itis.dkd.tui.scenario; package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.TangibleApplication; import lu.list.itis.dkd.tui.TangibleApplication;
import lu.list.itis.dkd.tui.TangibleContentManager; import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content; import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.Drawable;
import lu.list.itis.dkd.tui.cps.system.Equation; import lu.list.itis.dkd.tui.cps.system.Equation;
import lu.list.itis.dkd.tui.cps.system.Mapping; import lu.list.itis.dkd.tui.cps.system.Mapping;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor; import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
...@@ -64,11 +66,12 @@ import javax.swing.ImageIcon; ...@@ -64,11 +66,12 @@ import javax.swing.ImageIcon;
* @version 1.0.2 * @version 1.0.2
*/ */
@NonNullByDefault @NonNullByDefault
public class Scene extends Content { public class Scene extends Content implements Drawable {
private int drawPriority = 50;
/** The equation that will evaluate the trigger condition. */ /** The equation that will evaluate the trigger condition. */
private Equation trigger; private Equation trigger;
/** All variables that will be needed to evaluate the trigger condition. */ /** 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. */ /** Variable used to easily gather the output from the trigger equation. */
private BooleanVariable triggerVariable = new BooleanVariable("Trigger", false); //$NON-NLS-1$ private BooleanVariable triggerVariable = new BooleanVariable("Trigger", false); //$NON-NLS-1$
/** The image to show when painting. */ /** The image to show when painting. */
...@@ -116,10 +119,10 @@ public class Scene extends Content { ...@@ -116,10 +119,10 @@ public class Scene extends Content {
} }
final LinkedHashSet<Variable> outputs = new LinkedHashSet<>(); final LinkedHashSet<Variable<?>> outputs = new LinkedHashSet<>();
outputs.add(triggerVariable); outputs.add(triggerVariable);
trigger = new Equation(new Mapping(variables, outputs), triggerCondition); trigger = new Equation("Trigger", new Mapping(variables, outputs), triggerCondition);
trigger.setExecutor(new JavascriptExecutor()); trigger.setExecutor(new JavascriptExecutor());
try { try {
...@@ -256,6 +259,21 @@ public class Scene extends Content { ...@@ -256,6 +259,21 @@ public class Scene extends Content {
} }
} }
/** {@inheritDoc} */
@Override
public int compareTo(@Nullable Drawable content) {
if (content == null) {
throw new NullPointerException();
}
return Integer.compare(getDrawPriority(), content.getDrawPriority());
}
/** {@inheritDoc} */
@Override
public int getDrawPriority() {
return this.getDrawPriority();
}
} }
\ No newline at end of file
...@@ -23,17 +23,13 @@ package lu.list.itis.dkd.tui.scenario; ...@@ -23,17 +23,13 @@ package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleContentManager; import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent; import lu.list.itis.dkd.tui.event.ContentEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/** /**
* @author Eric Tobias [eric.tobias@list.lu] * @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0 * @since 1.0
...@@ -43,12 +39,8 @@ import javax.script.ScriptEngineManager; ...@@ -43,12 +39,8 @@ import javax.script.ScriptEngineManager;
public class StageManager extends TangibleContentManager { public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();