Commit 2e3ac759 authored by Eric Tobias's avatar Eric Tobias
Browse files

Added rotation functionality to value widget. Beta version.

Modified all scenarios to work with rotations.
Fixed text box coronas
parent e658d133
......@@ -2,8 +2,10 @@
<scenario>
<scenes>
<scene>
<name>Empty</name>
</scene>
<name>Background</name>
<image>assets/floorplan1.png</image>
<triggerCondition>true</triggerCondition>
</scene>
</scenes>
<objects>
......@@ -33,6 +35,16 @@
<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>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -41,13 +53,13 @@
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>10</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<lowerStopAngle>0</lowerStopAngle>
<upperStopAngle>6.28318530718</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>IncandescentLightBulbs</name>
<unit>piece</unit>
<value>1</value>
<value>0</value>
</variable>
<modifyValueOnRotation>True</modifyValueOnRotation>
</object>
......@@ -76,7 +88,17 @@
<y>0</y>
<z>0</z>
</centre>
<drawPriority>2</drawPriority>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
......@@ -85,13 +107,13 @@
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>10</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<lowerStopAngle>0</lowerStopAngle>
<upperStopAngle>6.28318530718</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>CompactFluorescents</name>
<unit>piece</unit>
<value>1</value>
<value>0</value>
</variable>
<modifyValueOnRotation>True</modifyValueOnRotation>
</object>
......@@ -120,22 +142,32 @@
<y>0</y>
<z>0</z>
</centre>
<drawPriority>3</drawPriority>
<drawPriority>1</drawPriority>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
</coronas>
<name>LightEmittingDiodes</name>
<name>LED</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>10</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<lowerStopAngle>0</lowerStopAngle>
<upperStopAngle>6.28318530718</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>LightEmittingDiodes</name>
<name>LED</name>
<unit>piece</unit>
<value>1</value>
<value>0</value>
</variable>
<modifyValueOnRotation>True</modifyValueOnRotation>
</object>
......@@ -165,7 +197,15 @@
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
<rotateWithHandle>false</rotateWithHandle>
<lineWidth>100</lineWidth>
<font>Arial-20</font>
<initialTranslation>
<x>0</x>
<y>50</y>
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<text>Banana</text>
</corona>
</coronas>
......@@ -174,8 +214,8 @@
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<lowerStopAngle>0</lowerStopAngle>
<upperStopAngle>6.28318530718</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Watts</name>
......@@ -212,19 +252,27 @@
</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>
<rotateWithHandle>false</rotateWithHandle>
<text>Banana</text>
</corona>
</coronas>
<name>Costs</name>
<name>Cost</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3.1415</lowerStopAngle>
<upperStopAngle>6.2830</upperStopAngle>
<lowerStopAngle>0</lowerStopAngle>
<upperStopAngle>6.28318530718</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Costs</name>
<name>Cost</name>
<unit></unit>
<value>0</value>
</variable>
......@@ -235,30 +283,30 @@
<system>
<outputs>
<output name="Watts" unit="W" />
<output name="Costs" unit="€" />
<output name="Cost" unit="€" />
</outputs>
<equations>
<equation name="PowerConsumption">
<parameters>
<parameter name="IncandescentLightBulbs" unit="pieces"/>
<parameter name="CompactFluorescents" unit="pieces"/>
<parameter name="LightEmittingDiodes" unit="pieces"/>
<parameter name="LED" unit="pieces"/>
</parameters>
<invoke>(60*IncandescentLightBulbs) + (14*CompactFluorescents) + (7*LightEmittingDiodes)</invoke>
<invoke>(60*IncandescentLightBulbs) + (14*CompactFluorescents) + (7*LED)</invoke>
<results>
<result name="Watts" />
</results>
</equation>
<equation name="Costs">
<equation name="Cost">
<parameters>
<parameter name="IncandescentLightBulbs" unit="pieces"/>
<parameter name="CompactFluorescents" unit="pieces"/>
<parameter name="LightEmittingDiodes" unit="pieces"/>
<parameter name="LED" unit="pieces"/>
</parameters>
<invoke>(10*IncandescentLightBulbs) + (2*CompactFluorescents) + (1*LightEmittingDiodes)</invoke>
<invoke>(10*IncandescentLightBulbs) + (2*CompactFluorescents) + (1*LED)</invoke>
<results>
<result name="Costs" />
<result name="Cost" />
</results>
</equation>
......
......@@ -27,9 +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 = 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 = scenario.xml
\ No newline at end of file
equation.system = light_scenario.xml
scenario.description = light_scenario.xml
\ No newline at end of file
......@@ -48,6 +48,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -101,6 +102,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -154,6 +156,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -207,6 +210,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -260,6 +264,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -313,6 +318,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -366,6 +372,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......@@ -420,6 +427,7 @@
<z>0</z>
<state>ScreenCoordinates</state>
</initialTranslation>
<rotateWithHandle>false</rotateWithHandle>
<centred>true</centred>
<text>Banana</text>
</corona>
......
......@@ -27,33 +27,24 @@ import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget;
import com.google.common.base.Strings;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import com.google.common.base.Preconditions;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.0
* @version 1.0.2
*/
@NonNullByDefault
public abstract class Scenario {
private Document scenarioDescription;
public class Scenario {
private static final Logger logger = Logger.getLogger(Scenario.class.getSimpleName());
private Map<String, Scene> scenes;
private static StageManager stageManager = StageManager.getInstance();
private static ConcurrentHashMap<String, Variable> inputs;
private static ConcurrentHashMap<String, Variable> outputs;
......@@ -65,53 +56,11 @@ public abstract class Scenario {
/**
* Constructor initializing all fields.
*
* @param scenarioDescription
* A document containing the scenario's formal description.
* @throws BuildException
* thrown when the provided URI could not be interpreted and, hence, the scenario
* description document loaded.
*/
public Scenario(Document scenarioDescription) throws BuildException {
this.scenarioDescription = scenarioDescription;
initializeScenario();
}
/**
* Constructor initializing all fields.
*
* @param fileUri
* The URI of the document containing the scenario's formal description.
* @throws BuildException
* thrown when the provided URI could not be interpreted and, hence, the scenario
* description document loaded.
*/
public Scenario(String fileUri) throws BuildException {
if (Strings.isNullOrEmpty(fileUri)) {
throw new BuildException("The provided file URI may not be null or empty!"); //$NON-NLS-1$
}
final SAXBuilder builder = new SAXBuilder();
final File xmlFile = new File(fileUri);
try {
this.scenarioDescription = builder.build(xmlFile);
} catch (IOException | JDOMException e) {
logger.log(Level.SEVERE, "Error occured while trying to process scenario description file!", e); //$NON-NLS-1$
throw new BuildException("The document containing the scenario description could not be processed!", e); //$NON-NLS-1$
}
initializeScenario();
}
/**
* Method used by the constructors to initialize all fields by using the provided scenario
* description.
*
* @throws BuildException
* Thrown when the underlying tangible application cannot be build.
*/
private void initializeScenario() throws BuildException {
public Scenario() throws BuildException {
try {
equationSystemBuilder = new EquationSystemBuilder(PropertiesFetcher.fetchProperties());
equationSystemBuilder.parseEquationFile(new File(PropertiesFetcher.fetchProperties().getProperty("equation.system"))); //$NON-NLS-1$
......@@ -126,13 +75,14 @@ public abstract class Scenario {
populateVariables();
scenes = SceneBootstrapper.getScenes(scenarioDescription);
stageManager.setScenes(scenes);
tangibleApplication.setContentManager(stageManager);
scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.connect();
}
/**
* Method used to replace the placeholder variables in each widget with the variable as
* initialized by the equation system.
......@@ -144,10 +94,6 @@ public abstract class Scenario {
((ValueWidget) widget).setVariable(variable);
}
}
// TangibleObjectManager.getWidgets().stream().filter(w ->
// ValueWidget.class.isInstance(w)).forEach(w -> ((ValueWidget)
// w).setVariable(findVariable(((ValueWidget) w).getVariable().getName())));
}
/**
......@@ -157,4 +103,17 @@ public abstract class Scenario {
static TangibleNumericalVariable findVariable(String name) {
return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
/**
* Entry point for the application.
*
* @param args
* This must be empty, no arguments are accepted.
* @throws BuildException
*/
public static void main(String[] args) throws BuildException {
Preconditions.checkArgument(args.length == 0, "No parameters are accepted!"); //$NON-NLS-1$
final Scenario scenario = new Scenario();
}
}
\ No newline at end of file
......@@ -64,6 +64,10 @@ public class Scene extends Content {
}
}
if (variables.isEmpty()) {
variables.add(triggerVariable);
}
trigger = new Equation(new Mapping(variables, triggerVariable), triggerCondition);
try {
......
......@@ -15,10 +15,15 @@ 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.utility.PropertiesFetcher;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
......@@ -31,7 +36,10 @@ import java.util.logging.Logger;
*/
public class SceneBootstrapper {
private static final Logger logger = Logger.getLogger(SceneBootstrapper.class.getSimpleName());
private static Map<String, Scene> scenes = new HashMap<>();
private static Document scenarioDescription;
/**
* Method called to initialize all scenes from a provided XML file. The method will populate the
......@@ -47,10 +55,21 @@ public class SceneBootstrapper {
}
/**
* @param scenarioDescription
* @return
* @throws BuildException
*/
public static Map<String, Scene> getScenes(Document scenarioDescription) {
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$
try {
scenarioDescription = builder.build(xmlFile);
} catch (IOException | JDOMException e) {
logger.log(Level.SEVERE, "Error occured while trying to process scenario description file!", e); //$NON-NLS-1$
throw new BuildException("The document containing the scenario description could not be processed!", e); //$NON-NLS-1$
}
bootstrapScenes(scenarioDescription);
return scenes;
}
......
/**
* 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.circuit;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.scenario.Scenario;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import java.io.File;
import java.io.IOException;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class CircuitScenario extends Scenario {
/**
* @param scenarioDescription
* @throws BuildException
*/
public CircuitScenario(Document scenarioDescription) throws BuildException {
super(scenarioDescription);
}
/**
* @param fileUri
* @throws BuildException
*/
public CircuitScenario(String fileUri) throws BuildException {
super(fileUri);
}
/**
* @param args
* @throws IOException
* @throws JDOMException
* @throws BuildException
*/
public static void main(String[] args) throws BuildException, JDOMException, IOException {
final SAXBuilder builder = new SAXBuilder();
final File xmlFile = new File("scenario.xml");
final CircuitScenario scenario = new CircuitScenario(builder.build(xmlFile));
}
}
\ No newline at end of file
/**
* 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.lights;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.scenario.Scenario;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import java.io.File;
import java.io.IOException;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class LightScenario extends Scenario {
/**
* @param scenarioDescription
* @throws BuildException
*/
public LightScenario(Document scenarioDescription) throws BuildException {
super(scenarioDescription);
}
/**
* @param fileUri
* @throws BuildException
*/
public LightScenario(String fileUri) throws BuildException {
super(fileUri);
}
/**
* @param args
* @throws IOException
* @throws JDOMException
* @throws BuildException
*/
public static void main(String[] args) throws BuildException, JDOMException, IOException {
final SAXBuilder builder = new SAXBuilder();
final File xmlFile = new File("light_scenario.xml");
final LightScenario scenario = new LightScenario(builder.build(xmlFile));
}
}
\ 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