Commit f6a3ecf2 authored by Eric Tobias's avatar Eric Tobias
Browse files

Initial commit of project

parents
*.metadata
*.classpath
Scenarios/calibration.xml
Scenarios/target
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tulip-lu.list.itis.dkd.tui.scenario</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
This diff is collapsed.
cleanup.add_default_serial_version_id=false
cleanup.add_generated_serial_version_id=true
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=true
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=true
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=true
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_functional_interfaces=true
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=false
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=true
cleanup.remove_private_constructors=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup.use_type_arguments=false
cleanup_profile=_LIST
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_LIST
formatter_settings_version=12
org.eclipse.jdt.ui.exception.name=e
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=lu.list;lu.tudor;com;org;uk;java;javax;
org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.ondemandthreshold=99
org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.staticondemandthreshold=99
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * Simple getter method for ${bare_field_name}.\r\n * @return The value of ${bare_field_name}.\r\n */</template><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * Simple setter method for ${bare_field_name}.\r\n * @param ${bare_field_name}\r\n * \t\tThe value to set ${bare_field_name} to.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * Copyright Luxembourg Institute of Science and Technology, ${year}.\r\n * All rights reserved. If you wish to use this code for any purpose,\r\n * please contact the author(s).\r\n *\r\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r\n * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r\n * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r\n * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r\n * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r\n * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r\n * POSSIBILITY OF SUCH DAMAGE.\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author ${user}\r\n * @since [major].[minor]\r\n * @version [major].[minor].[micro]\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** {@inheritDoc} */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="false" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="false" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=true
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=false
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=false
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_type_arguments=false
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
function Load = CircuitLoad(Breaker, Consumption)
Load = Breaker / (Consumption / 230);
\ No newline at end of file
function Consumption = PowerConsumption(Lights, Dryer, Dishwasher, Laptop, Smartphone)
Consumption = Lights + Dryer + Dishwasher + Laptop + Smartphone;
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lu.list.itis.dkd.tui.scenario</groupId>
<artifactId>tulip-lu.list.itis.dkd.tui.scenario</artifactId>
<version>0.1.0</version>
<name>TULIP Scenario</name>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>lu.list.itis.dkd</groupId>
<artifactId>dbc-annotation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>dk.ange</groupId>
<artifactId>javaoctave</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>cps</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1280
windowHeight = 800
fullScreen = false
font = Arial
fontSize = 13
colour = BLACK
centred = false
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = scenario.xml
# Properties for the equation system
scriptEngine.executable = C:\\Octave\\Octave-4.0.0\\bin\\octave
scriptEngine.workingDir = model
equation.system = scenario.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<scenario>
<scenes>
<scene>
<name>Empty</name>
</scene>
<scene>
<name>Loaded</name>
</scene>
<scene>
<name>Overloaded</name>
</scene>
</scenes>
<tangibles>
<objects>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Lights</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Lights</name>
<unit>Watt</unit>
<value>300</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Hair Dryer</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Dryer</name>
<unit>Watt</unit>
<value>2200</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Dishwasher</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Dishwasher</name>
<unit>Watt</unit>
<value>1800</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Laptop</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Laptop</name>
<unit>Watt</unit>
<value>100</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Smartphone</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Smartphone</name>
<unit>Watt</unit>
<value>5</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
<object>
<type>ValueWidget</type>
<coronas>
<corona>
<type>Shadow</type>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
</corona>
</coronas>
<name>Breaker</name>
<definingShape></definingShape>
<networkAdapter></networkAdapter>
<lowerBound>0</lowerBound>
<upperBound>1</upperBound>
<lowerStopAngle>3,1415</lowerStopAngle>
<upperStopAngle>6,2830</upperStopAngle>
<stepSize>1</stepSize>
<variable>
<name>Breaker</name>
<unit>Ampere</unit>
<value>16</value>
</variable>
<modifyValueOnRotation>False</modifyValueOnRotation>
</object>
</objects>
</tangibles>
<system>
<outputs>
<output name="Load" />
<output name="Ampere" />
</outputs>
<equations>
<equation name="Ampere">
<parameters>
<parameter name="Consumption" />
</parameters>
<invoke>Ampere = Consumption / 230</invoke>
<results>
<result name="Ampere" />
</results>
</equation>
<equation name="Circuit Load">
<parameters>
<parameter name="Breaker" />
<parameter name="Consumption" />
</parameters>
<invoke>Load = CircuitLoad (Breaker, Consumption);</invoke>
<results>
<result name="Load" />
</results>
</equation>
</equations>
</system>
</scenario>
\ 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;
import lu.list.itis.dkd.cps.system.EquationSystemBuilder;
import lu.list.itis.dkd.cps.system.EquationSystemException;
import lu.list.itis.dkd.cps.variable.NumericalVariable;
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.TangibleObjectManager;
import lu.list.itis.dkd.tui.bootstrapping.TangibleApplicationBootstrapper;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.scenario.bootstrapping.SceneBootstrapper;
import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
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 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
*/
@NonNullByDefault
public abstract class Scenario {
private Document scenarioDescription;
private static final Logger logger = Logger.getLogger(Scenario.class.getSimpleName());
private Map<String, Scene> scenes;
private static StageManager stageManager = StageManager.getInstance();
private ConcurrentHashMap<String, Variable> inputs;
private ConcurrentHashMap<String, Variable> outputs;
private EquationSystemBuilder equationSystemBuilder;
private TangibleApplication tangibleApplication;
/**
* 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 {
try {
equationSystemBuilder = new EquationSystemBuilder(PropertiesFetcher.fetchProperties());
equationSystemBuilder.parseEquationFile(new File(PropertiesFetcher.fetchProperties().getProperty("equation.system")));
} catch (final EquationSystemException exception) {
throw new BuildException("The equation system for this scenario could not be built!", exception); //$NON-NLS-1$
}
inputs = equationSystemBuilder.getInputVariables();
outputs = equationSystemBuilder.getOutputVariables();
tangibleApplication = new TangibleApplicationBootstrapper(null);
populateVariables();
scenes = SceneBootstrapper.getScenes(scenarioDescription);
// TODO Stagemanager
tangibleApplication.connect();
}
/**
* Method used to replace the placeholder variables in each widget with the variable as
* initialized by the equation system.
*/
private void populateVariables() {
TangibleObjectManager.getWidgets().stream().filter(w -> ValueWidget.class.isInstance(w)).forEach(w -> ((ValueWidget) w).setVariable(findVariable(((ValueWidget) w).getVariable().getName())));
}
/**
* @param name
* @return
*/
private NumericalVariable findVariable(String name) {
return (NumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));