Commit 62f82c05 authored by Eric Tobias's avatar Eric Tobias
Browse files

Added scenes.

parent c6d3d18e
......@@ -2,13 +2,14 @@
<scenario>
<scenes>
<scene>
<name>Empty</name>
<name>On</name>
<image>assets/floorplan1.png</image>
<triggerCondition>Ampere &lt; Breaker</triggerCondition>
</scene>
<scene>
<name>Loaded</name>
</scene>
<scene>
<name>Overloaded</name>
<name>Off</name>
<image>assets/floorplan2.png</image>
<triggerCondition>Ampere &gt;= Breaker</triggerCondition>
</scene>
</scenes>
......@@ -39,6 +40,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -83,6 +93,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -127,6 +146,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -171,6 +199,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -215,6 +252,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -259,6 +305,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -266,7 +321,7 @@
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<upperBound>10</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<stepSize>1</stepSize>
......@@ -304,6 +359,14 @@
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -320,8 +383,8 @@
<unit>A</unit>
<value>0</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<dynamic>true</dynamic>
<modifyValueOnRotation>False</modifyValueOnRotation>
<variableIsDynamic>true</variableIsDynamic>
</object>
<object>
<type>ValueWidget</type>
......@@ -350,6 +413,14 @@
</centre>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -367,7 +438,7 @@
<value>0</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<dynamic>true</dynamic>
<variableIsDynamic>true</variableIsDynamic>
</object>
</objects>
<system>
......@@ -379,10 +450,10 @@
<equation name="PowerConsumption">
<parameters>
<parameter name="Lights" unit="W" />
<parameter name="Dryer" unit="W"/>
<parameter name="Dishwasher" unit="W"/>
<parameter name="Laptop" unit="W"/>
<parameter name="Smartphone" unit="W"/>
<parameter name="Dryer" unit="W" />
<parameter name="Dishwasher" unit="W" />
<parameter name="Laptop" unit="W" />
<parameter name="Smartphone" unit="W" />
</parameters>
<invoke>(Lights + Dryer + Dishwasher + Laptop + Smartphone) / 230</invoke>
<results>
......@@ -392,15 +463,15 @@
<equation name="CircuitLoad">
<parameters>
<parameter name="Breaker" />
<parameter name="Ampere" />
<parameter name="Breaker" unit="A" />
<parameter name="Ampere" unit="A" />
</parameters>
<invoke>(Ampere / Breaker) * 100</invoke>
<results>
<result name="Load" />
</results>
</equation>
</equations>
</system>
</scenario>
\ No newline at end of file
......@@ -55,8 +55,8 @@ public abstract class Scenario {
private Map<String, Scene> scenes;
private static StageManager stageManager = StageManager.getInstance();
private ConcurrentHashMap<String, Variable> inputs;
private ConcurrentHashMap<String, Variable> outputs;
private static ConcurrentHashMap<String, Variable> inputs;
private static ConcurrentHashMap<String, Variable> outputs;
private EquationSystemBuilder equationSystemBuilder;
private TangibleApplication tangibleApplication;
......@@ -127,8 +127,9 @@ public abstract class Scenario {
populateVariables();
scenes = SceneBootstrapper.getScenes(scenarioDescription);
stageManager.setScenes(scenes);
tangibleApplication.setContentManager(stageManager);
// TODO Stagemanager
tangibleApplication.connect();
}
......@@ -153,7 +154,7 @@ public abstract class Scenario {
* @param name
* @return
*/
private TangibleNumericalVariable findVariable(String name) {
static TangibleNumericalVariable findVariable(String name) {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
}
\ No newline at end of file
......@@ -13,35 +13,92 @@
*/
package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.cps.system.Equation;
import lu.list.itis.dkd.cps.system.Mapping;
import lu.list.itis.dkd.cps.variable.BooleanVariable;
import lu.list.itis.dkd.cps.variable.Variable;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import com.google.common.base.Splitter;
import org.jdom2.Element;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import javax.imageio.ImageIO;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
*/
@NonNullByDefault
public class Scene {
public class Scene extends Content {
private String name;
private Equation trigger;
private LinkedHashSet<Variable> variables = new LinkedHashSet<>();
private BooleanVariable triggerVariable = new BooleanVariable("Trigger", "", false); //$NON-NLS-1$ //$NON-NLS-2$
private BufferedImage scenery;
/**
* @param element
* @throws BuildException
*/
public Scene(Element element) {
this.name = element.getChildText(Externalization.NAME_NODE);
public Scene(Element element) throws BuildException {
super(element.getChildText(Externalization.NAME_NODE));
final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE);
for (final String _name : Splitter.on(Externalization.SPACE).trimResults().omitEmptyStrings().split(triggerCondition)) {
final Variable variable = Scenario.findVariable(_name);
if (null != variable) {
variables.add(variable);
}
}
trigger = new Equation(new Mapping(variables, triggerVariable), triggerCondition);
try {
final Element imageNode = element.getChild(Externalization.IMAGE_NODE);
if (null != imageNode) {
scenery = ImageIO.read(new File(imageNode.getText()));
}
} catch (final NullPointerException npe) {
throw new BuildException("The provided image path may not be empty!", npe); //$NON-NLS-1$
} catch (final IllegalArgumentException iae) {
throw new BuildException("The image could not be read from the provided location. The location should be given as absolute path, i.e.: \"C:\\My Image\\image.jpeg\"!", iae); //$NON-NLS-1$
} catch (final IOException ioe) {
throw new BuildException("The image could not be read!", ioe); //$NON-NLS-1$
}
}
/**
* Simple getter method for name.
*
* @return The value of name.
*/
public String getName() {
return name;
public Equation getTrigger() {
return trigger;
}
public boolean evaluateTrigger() {
trigger.evaluate();
return triggerVariable.getValue();
}
}
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
canvas.drawImage(scenery, 0, 0, null);
}
/** {@inheritDoc} */
@Override
public void initialise() {
// Nothing to do here!
}
}
\ No newline at end of file
......@@ -14,10 +14,16 @@
package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.content.InformationProvider;
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.HashMap;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/**
* @author Eric Tobias [eric.tobias@list.lu]
......@@ -25,11 +31,14 @@ import java.util.Map;
* @version 1.0.0
*/
@NonNullByDefault
public class StageManager {
public class StageManager extends TangibleContentManager {
private static final StageManager INSTANCE = new StageManager();
private Map<String, InformationProvider<?>> inputs = new HashMap<>();
private static Map<String, Scene> scenes;
private static ScriptEngine scriptEngine;
private StageManager() {}
private StageManager() {
scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
}
/**
* Method for returning the single instance of this manger class.
......@@ -39,4 +48,26 @@ public class StageManager {
public static StageManager getInstance() {
return INSTANCE;
}
/**
* @param scenes
*/
public static void setScenes(Map<String, Scene> _scenes) {
scenes = _scenes;
scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
}
/** {@inheritDoc} */
@Override
public void contentUpdated(ContentEvent event) {
// TODO Auto-generated method stub
}
/** {@inheritDoc} */
@Override
public Collection<Content> getDrawableContents() {
return scenes.values().stream().filter(scene -> scene.evaluateTrigger()).collect(Collectors.toList());
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
*/
package lu.list.itis.dkd.tui.scenario.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.scenario.Scene;
import org.jdom2.Document;
......@@ -20,6 +21,8 @@ import org.jdom2.Element;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Eric Tobias [eric.tobias@list.lu]
......@@ -58,7 +61,11 @@ public class SceneBootstrapper {
* @param element
*/
private static void buildScene(Element element) {
final Scene scene = new Scene(element);
scenes.put(scene.getName(), scene);
try {
final Scene scene = new Scene(element);
scenes.put(scene.getIdentifier(), scene);
} catch (final BuildException e) {
Logger.getLogger(SceneBootstrapper.class.getSimpleName()).log(Level.SEVERE, "Could not build scene!", e); //$NON-NLS-1$
}
}
}
\ 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