Commit a80f63af authored by Nico Mack's avatar Nico Mack

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

parent 5dc25b40
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Configuration status="WARN" packages="lu.list.itis.dkd.tui.logging">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</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>
<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="SplashScreen"/>
</Root>
<Logger name="lu.list.itis.dkd.tui" level="trace"/>
</Loggers>
</Configuration>
\ No newline at end of file
......@@ -28,12 +28,12 @@
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId>
<version>2.4.0</version>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>
</dependencies>
......
......@@ -32,7 +32,7 @@ bootstrapping.root = circuit_scenario.xml
# Properties for the equation system
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
scenario.description = circuit_scenario.xml
......
......@@ -33,5 +33,5 @@ bootstrapping.root = light_scenario.xml
# Properties for the equation system
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
......@@ -18,8 +18,8 @@
<name>Lights</name>
<variable>
<name>Lights</name>
<unit>Watt</unit>
<value>300</value>
<type>numeric</type>
<initial>300</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -28,7 +28,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>1</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -56,8 +56,8 @@
<name>Hair Dryer</name>
<variable>
<name>Dryer</name>
<unit>Watt</unit>
<value>2200</value>
<type>numeric</type>
<initial>1200</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -66,7 +66,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>2</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -94,8 +94,8 @@
<name>Dishwasher</name>
<variable>
<name>Dishwasher</name>
<unit>Watt</unit>
<value>1800</value>
<type>numeric</type>
<initial>1800</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -104,7 +104,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>3</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -132,8 +132,8 @@
<name>Laptop</name>
<variable>
<name>Laptop</name>
<unit>Watt</unit>
<value>100</value>
<type>numeric</type>
<initial>100</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -142,7 +142,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>4</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -170,8 +170,8 @@
<name>Smartphone</name>
<variable>
<name>Smartphone</name>
<unit>Watt</unit>
<value>5</value>
<type>numeric</type>
<initial>5</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -180,7 +180,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>5</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -208,8 +208,8 @@
<name>Breaker</name>
<variable>
<name>Breaker</name>
<unit>A</unit>
<value>16</value>
<type>numeric</type>
<initial>10</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -218,7 +218,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>6</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -251,8 +251,8 @@
<name>Ampere</name>
<variable>
<name>Ampere</name>
<unit>A</unit>
<value>0</value>
<type>numeric</type>
<initial>0</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -261,7 +261,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>7</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -289,8 +289,9 @@
<name>Load</name>
<variable>
<name>Load</name>
<type>numeric</type>
<unit>%</unit>
<value>0</value>
<initial>0</initial>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<type>ValueWidget</type>
......@@ -299,7 +300,7 @@
</handles>
<coronas>
<corona>
<type>Shadow</type>
<type>ShapeCorona</type>
<handle>8</handle>
<shape>Circle</shape>
<drawPriority>0</drawPriority>
......@@ -328,11 +329,15 @@
<outputs>
<output>
<name>Load</name>
<type>numeric</type>
<unit>%</unit>
<decimals>0</decimals>
</output>
<output>
<name>Ampere</name>
<type>numeric</type>
<unit>A</unit>
<decimals>1</decimals>
</output>
</outputs>
<equations>
......@@ -343,7 +348,6 @@
<name>Lights</name>
<unit>W</unit>
</parameter>
<parameter>
<name>Dryer</name>
<unit>W</unit>
......@@ -365,7 +369,6 @@
<results>
<result>
<name>Ampere</name>
<unit>A</unit>
</result>
</results>
</equation>
......@@ -374,18 +377,15 @@
<parameters>
<parameter>
<name>Breaker</name>
<unit>A</unit>
</parameter>
<parameter>
<name>Ampere</name>
<unit>A</unit>
</parameter>
</parameters>
<invoke>(Ampere / Breaker) * 100</invoke>
<results>
<result>
<name>Load</name>
<unit>%</unit>
</result>
</results>
</equation>
......
......@@ -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.NumericalVariable;
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;
......@@ -42,6 +43,7 @@ import com.google.common.base.Preconditions;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
/**
......@@ -56,13 +58,16 @@ 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;
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
......@@ -122,8 +127,10 @@ public class Scenario {
scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.getContentManager().initAll();
tangibleApplication.connect();
tangibleApplication.doneLoading();
}
......@@ -134,9 +141,10 @@ public class Scenario {
*
*/
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) {
final TangibleNumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName());
final NumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName());
((ValueWidget) widget).setVariable(variable);
for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) {
......@@ -157,8 +165,8 @@ public class Scenario {
* @return The {@link TangibleNumericalVariable} that responds to the given name or
* <code>null</code> should no such variable exist.
*/
static @Nullable TangibleNumericalVariable retrieveVariableByName(String name) {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
static @Nullable NumericalVariable retrieveVariableByName(String name) {
return (NumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
/**
......
......@@ -21,9 +21,11 @@
package lu.list.itis.dkd.tui.scenario;
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.TangibleContentManager;
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.Mapping;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
......@@ -64,11 +66,12 @@ import javax.swing.ImageIcon;
* @version 1.0.2
*/
@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. */
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. */
......@@ -116,10 +119,10 @@ 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);
trigger = new Equation("Trigger", new Mapping(variables, outputs), triggerCondition);
trigger.setExecutor(new JavascriptExecutor());
try {
......@@ -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;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
......@@ -43,12 +39,8 @@ import javax.script.ScriptEngineManager;
public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();
private static Map<String, Scene> scenes;
private static ScriptEngine scriptEngine;
ArrayList<Content> drawableContents = new ArrayList<>();
private StageManager() {
scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
}
private StageManager() {}
/**
* Method for returning the single instance of this manger class.
......@@ -64,9 +56,6 @@ public class StageManager extends TangibleContentManager {
*/
public static void setScenes(Map<String, Scene> _scenes) {
scenes = _scenes;
// scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
}
/** {@inheritDoc} */
......@@ -77,10 +66,19 @@ public class StageManager extends TangibleContentManager {
}
/** {@inheritDoc} */
@Override
public Collection<Content> getDrawableContents() {
drawableContents.clear();
public void initAll() {
for (final Scene scene : scenes.values()) {
this.addMapping(scene.getIdentifier(), scene);
}
}
@SuppressWarnings("unchecked")
@Override
public <T> List<T> getContent(Class<T> clazz, Integer stageId) {
final List<Scene> drawableContents = new ArrayList<>();
for (final Scene scene : scenes.values()) {
if (scene.evaluateTrigger()) {
......@@ -89,6 +87,6 @@ public class StageManager extends TangibleContentManager {
}
Collections.sort(drawableContents);
return drawableContents;
return (List<T>) drawableContents;
}
}
\ No newline at end of file
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