Commit 2251beb7 authored by Eric Tobias's avatar Eric Tobias
Browse files

Changed scenarios to load directly from property file

parent f0af5e68
......@@ -5,7 +5,7 @@
<name>Background</name>
<image>assets/floorplan1.png</image>
<triggerCondition>true</triggerCondition>
</scene>
</scene>
</scenes>
<objects>
......@@ -39,7 +39,7 @@
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<y>120</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
......@@ -47,6 +47,30 @@
<centred>true</centred>
<text>Banana</text>
</corona>
<corona>
<type>Gauge</type>
<handle>1</handle>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
<initialTranslation>
<x>-100</x>
<y>-100</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<drawPriority>2</drawPriority>
<width>200</width>
<height>200</height>
<lowerBound>0</lowerBound>
<upperBound>10</upperBound>
<scale>1</scale>
<title>Incandescent Lights</title>
<unit>pieces</unit>
<rotateWithHandle>false</rotateWithHandle>
</corona>
</coronas>
<name>IncandescentLightBulbs</name>
<definingShape></definingShape>
......@@ -185,7 +209,7 @@
<y>0</y>
<z>0</z>
</centre>
<shape>Circle</shape>
<shape>RoundedSquare</shape>
<drawPriority>0</drawPriority>
</corona>
<corona>
......@@ -207,6 +231,7 @@
<state>ScreenCoordinates</state>
</initialTranslation>
<text>Banana</text>
<centred>true</centred>
</corona>
</coronas>
<name>Watts</name>
......@@ -222,7 +247,7 @@
<unit>W</unit>
<value>0</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<modifyValueOnRotation>False</modifyValueOnRotation>
<dynamic>true</dynamic>
</object>
<object>
......@@ -239,7 +264,7 @@
<y>0</y>
<z>0</z>
</centre>
<shape>Circle</shape>
<shape>RoundedSquare</shape>
<drawPriority>0</drawPriority>
</corona>
<corona>
......@@ -259,6 +284,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<centred>true</centred>
<rotateWithHandle>false</rotateWithHandle>
<text>Banana</text>
</corona>
......@@ -276,7 +302,7 @@
<unit></unit>
<value>0</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
<modifyValueOnRotation>False</modifyValueOnRotation>
<dynamic>true</dynamic>
</object>
</objects>
......@@ -288,9 +314,9 @@
<equations>
<equation name="PowerConsumption">
<parameters>
<parameter name="IncandescentLightBulbs" unit="pieces"/>
<parameter name="CompactFluorescents" unit="pieces"/>
<parameter name="LED" unit="pieces"/>
<parameter name="IncandescentLightBulbs" unit="pieces" />
<parameter name="CompactFluorescents" unit="pieces" />
<parameter name="LED" unit="pieces" />
</parameters>
<invoke>(60*IncandescentLightBulbs) + (14*CompactFluorescents) + (7*LED)</invoke>
<results>
......@@ -300,16 +326,16 @@
<equation name="Cost">
<parameters>
<parameter name="IncandescentLightBulbs" unit="pieces"/>
<parameter name="CompactFluorescents" unit="pieces"/>
<parameter name="LED" unit="pieces"/>
<parameter name="IncandescentLightBulbs" unit="pieces" />
<parameter name="CompactFluorescents" unit="pieces" />
<parameter name="LED" unit="pieces" />
</parameters>
<invoke>(10*IncandescentLightBulbs) + (2*CompactFluorescents) + (1*LED)</invoke>
<results>
<result name="Cost" />
</results>
</equation>
</equations>
</system>
</scenario>
\ No newline at end of file
function Load = CircuitLoad(Breaker, Lights, Dryer, Dishwasher, Laptop, Smartphone)
Load = Breaker / ((Lights + Dryer + Dishwasher + Laptop + Smartphone) / 230);
\ No newline at end of file
function Ampere = PowerConsumption(Lights, Dryer, Dishwasher, Laptop, Smartphone)
Ampere = (Lights + Dryer + Dishwasher + Laptop + Smartphone) / 230;
\ No newline at end of file
......@@ -27,10 +27,10 @@ cursor.id.remapping.constant = 1024
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = food_scenario.xml
bootstrapping.root = light_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
equation.system = food_scenario.xml
scenario.description = food_scenario.xml
\ No newline at end of file
equation.system = light_scenario.xml
scenario.description = light_scenario.xml
\ No newline at end of file
......@@ -18,6 +18,7 @@ import lu.list.itis.dkd.cps.system.EquationSystemException;
import lu.list.itis.dkd.cps.variable.Variable;
import lu.list.itis.dkd.cps.variable.tangible.TangibleNumericalVariable;
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.TangibleObjectManager;
import lu.list.itis.dkd.tui.bootstrapping.TangibleApplicationBootstrapper;
......@@ -32,18 +33,17 @@ import com.google.common.base.Preconditions;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
/**
* Class used to run a tangible scenario. It uses bootstrappers to initialize all the necessary
* components from an XML file.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.2
*/
@NonNullByDefault
public class Scenario {
private static final Logger logger = Logger.getLogger(Scenario.class.getSimpleName());
private Map<String, Scene> scenes;
private static ConcurrentHashMap<String, Variable> inputs;
......@@ -54,7 +54,9 @@ public class Scenario {
/**
* Constructor initializing all fields.
* Constructor initializing all fields. The constructor will also populate all variables and use
* a bootstrapper to initialize a {@link TangibleApplication} and a {@link StageManager} to
* manage all scenes reacting to inputs and outputs.
*
* @throws BuildException
* thrown when the provided URI could not be interpreted and, hence, the scenario
......@@ -97,10 +99,14 @@ public class Scenario {
}
/**
* Method used to find a variable given its name in either input or output maps.
*
* @param name
* @return
* The name of the variable to find.
* @return The {@link TangibleNumericalVariable} that responds to the given name or
* <code>null</code> should no such variable exist.
*/
static TangibleNumericalVariable findVariable(String name) {
static @Nullable TangibleNumericalVariable findVariable(String name) {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
......@@ -114,6 +120,7 @@ public class Scenario {
public static void main(String[] args) throws BuildException {
Preconditions.checkArgument(args.length == 0, "No parameters are accepted!"); //$NON-NLS-1$
@SuppressWarnings("unused")
final Scenario scenario = new Scenario();
}
}
\ No newline at end of file
......@@ -18,6 +18,8 @@ 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.TangibleApplication;
import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
......@@ -35,19 +37,28 @@ import java.util.LinkedHashSet;
import javax.imageio.ImageIO;
/**
* Class holding all the necessary bits to play a scene in response to a particular trigger
* condition. The class extends {@link Content} and can, thus, easily be managed by a
* {@link TangibleApplication}, respectively its {@link TangibleContentManager}.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
*/
@NonNullByDefault
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<>();
/** Variable used to easily gather the output from the trigger equation. */
private BooleanVariable triggerVariable = new BooleanVariable("Trigger", "", false); //$NON-NLS-1$ //$NON-NLS-2$
/** The image to show when painting. */
private BufferedImage scenery;
/**
* Constructor initializing all fields.
*
* @param element
* @throws BuildException
*/
......@@ -64,6 +75,7 @@ public class Scene extends Content {
}
}
// TODO This needs to be solved more elegantly.
if (variables.isEmpty()) {
variables.add(triggerVariable);
}
......
......@@ -15,6 +15,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 lu.list.itis.dkd.tui.scenario.utility.Externalization;
import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
import org.jdom2.Document;
......@@ -30,6 +31,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Class used to bootstrap scenes as read from an XML file specified in a properties file.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
......@@ -49,19 +52,26 @@ public class SceneBootstrapper {
* The document containing the scene description.
*/
private static void bootstrapScenes(Document document) {
final Element sceneRootNode = document.getRootElement().getChild("scenes");
final Element sceneRootNode = document.getRootElement().getChild(Externalization.SCENES_NOCE);
sceneRootNode.getChildren("scene").forEach(element -> buildScene(element));
sceneRootNode.getChildren(Externalization.SCENE_NODE).forEach(element -> buildScene(element));
}
/**
* @return
* Method called to read all scenes from a scenario document specified using the properties
* file. The method will build the XML document and search for specific nodes to issue calls to
* build all scenes.
*
* @return A map containing all scenes correctly specified in the XML document keyed by their
* scene name.
*
* @throws BuildException
* Thrown when the scenario description document could not be build.
*/
public static Map<String, Scene> getScenes() throws BuildException {
final SAXBuilder builder = new SAXBuilder();
final File xmlFile = new File(PropertiesFetcher.fetchProperties().getProperty("scenario.description")); //$NON-NLS-1$
final File xmlFile = new File(PropertiesFetcher.fetchProperties().getProperty(Externalization.SCENARIO_DESCRIPTION_PROPERTY));
try {
scenarioDescription = builder.build(xmlFile);
......@@ -78,6 +88,8 @@ public class SceneBootstrapper {
* Method used to build individual scenes from an XML element.
*
* @param element
* The element containing all necessary information, as child elements, to build a scene.
* @see Scene
*/
private static void buildScene(Element element) {
try {
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2016. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.scenario.utility;
import org.eclipse.osgi.util.NLS;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
*/
@SuppressWarnings({"javadoc", "nls"})
public class Externalization extends NLS {
private static final String BUNDLE_NAME = "lu.list.itis.dkd.tui.scenario.utility.externalization";
public static String SCENE_NODE;
public static String SCENARIO_DESCRIPTION_PROPERTY;
public static String SCENES_NOCE;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Externalization.class);
}
private Externalization() {}
}
SCENE_NODE=scene
SCENARIO_DESCRIPTION_PROPERTY=scenario.description
SCENES_NOCE=scenes
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