Commit 5e2baecf authored by Valérie Maquil's avatar Valérie Maquil
Browse files

adaptations made for new versions of TULIP-CPS

parent 61f80da1
# Properties for the Logger # Properties for the Logger
logger.event.output.location = log.txt logger.event.output.location = log.txt
logger.event.output.enabled = false logger.event.output.enabled = false
logger.level = ALL logger.level = ALL
logger.event.configuration = logger.xml logger.event.configuration = logger.xml
# Widget IDs to be mapped # Widget IDs to be mapped
# Properties for calibrating the interface # Properties for calibrating the interface
frameTitle = NUI Application frameTitle = NUI Application
windowWidth = 1920 windowWidth = 1920
windowHeight = 1080 windowHeight = 1080
fullScreen = false fullScreen = false
font = Arial font = Arial
fontSize = 13 fontSize = 13
colour = BLACK colour = BLACK
centred = false centred = false
# Properties for the calibration of the object manager # Properties for the calibration of the object manager
#The value below is best left at or above 1024 #The value below is best left at or above 1024
cursor.id.remapping.constant = 1024 cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load. # The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName # Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file. # The location and name of the root bootstrapping file.
bootstrapping.root = light_scenario.xml bootstrapping.root = light_scenario.xml
# Properties for the equation system # Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe #scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model #scriptEngine.workingDir = model
equation.system = light_scenario.xml executor.class=lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor
scenario.description = light_scenario.xml variable.class=lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
equation.system = light_scenario.xml
scenario.description = light_scenario.xml
/** /**
* Copyright Luxembourg Institute of Science and Technology, 2016. * Copyright Luxembourg Institute of Science and Technology, 2016.
* *
* This file is part of TULIP. * This file is part of TULIP.
* *
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3, * TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST * as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license. * proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
* *
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it * For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software * under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License. * Foundation, version 3 of the License.
* *
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If * You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. * not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/ */
package lu.list.itis.dkd.tui.scenario; package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable; import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.TangibleApplication; import lu.list.itis.dkd.tui.TangibleApplication;
import lu.list.itis.dkd.tui.TangibleObjectManager; import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.bootstrapping.TangibleApplicationBootstrapper; 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.EquationSystemBuilder;
import lu.list.itis.dkd.tui.cps.system.EquationSystemException; import lu.list.itis.dkd.tui.cps.system.EquationSystemException;
import lu.list.itis.dkd.tui.cps.variable.Variable; 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.cps.variable.tangible.TangibleNumericalVariable;
import lu.list.itis.dkd.tui.exception.BuildException; import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.scenario.bootstrapping.SceneBootstrapper; import lu.list.itis.dkd.tui.scenario.bootstrapping.SceneBootstrapper;
import lu.list.itis.dkd.tui.utility.PropertiesFetcher; import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
import lu.list.itis.dkd.tui.widget.BaseWidget; import lu.list.itis.dkd.tui.widget.BaseWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget; import lu.list.itis.dkd.tui.widget.ValueWidget;
import lu.list.itis.dkd.tui.widget.corona.ConditionalCorona; import lu.list.itis.dkd.tui.widget.corona.ConditionalCorona;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
* Class used to run a tangible scenario. It uses bootstrappers to initialize all the necessary * Class used to run a tangible scenario. It uses bootstrappers to initialize all the necessary
* components from an XML file. * components from an XML file.
* *
* @author Eric Tobias [eric.tobias@list.lu] * @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0 * @since 1.0
* @version 1.1.2 * @version 1.1.2
*/ */
@NonNullByDefault @NonNullByDefault
public class Scenario { public class Scenario {
private Map<String, Scene> scenes; private Map<String, Scene> scenes;
private static Map<String, Variable> inputs; private static Map<String, Variable> inputs;
private static Map<String, Variable> outputs; private static Map<String, Variable> outputs;
private EquationSystemBuilder equationSystemBuilder; private EquationSystemBuilder equationSystemBuilder;
Properties properties; Properties properties;
private TangibleApplication tangibleApplication; private TangibleApplication tangibleApplication;
/** /**
* Constructor initializing all fields. The constructor will also populate all variables and use * 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 * a bootstrapper to initialize a {@link TangibleApplication} and a {@link StageManager} to
* manage all scenes reacting to inputs and outputs. * manage all scenes reacting to inputs and outputs.
* *
* @throws BuildException * @throws BuildException
* thrown when the provided URI could not be interpreted and, hence, the scenario * thrown when the provided URI could not be interpreted and, hence, the scenario
* description document loaded. * description document loaded.
*/ */
public Scenario(String file) throws BuildException { public Scenario(String file) throws BuildException {
try { properties = PropertiesFetcher.fetchProperties(file);
equationSystemBuilder = new EquationSystemBuilder(); try {
equationSystemBuilder.parseEquationFile(new File(PropertiesFetcher.fetchProperties(file).getProperty("equation.system"))); //$NON-NLS-1$ equationSystemBuilder = new EquationSystemBuilder(properties);
} catch (final EquationSystemException exception) { equationSystemBuilder.parseEquationFile(new File(properties.getProperty("equation.system"))); //$NON-NLS-1$
throw new BuildException("The equation system for this scenario could not be built!", exception); //$NON-NLS-1$ } 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(); inputs = equationSystemBuilder.getInputVariables();
outputs = equationSystemBuilder.getOutputVariables();
tangibleApplication = new TangibleApplicationBootstrapper(file);
tangibleApplication = new TangibleApplicationBootstrapper(file);
populateVariables();
populateVariables();
scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes); scenes = SceneBootstrapper.getScenes();
tangibleApplication.setContentManager(StageManager.getInstance()); StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.connect();
} tangibleApplication.connect();
}
public Scenario(String file, String filename) throws BuildException {
public Scenario(String file, String filename) throws BuildException {
properties = PropertiesFetcher.fetchProperties(file);
properties.setProperty("equation.system", filename); //$NON-NLS-1$ properties = PropertiesFetcher.fetchProperties(file);
properties.setProperty("bootstrapping.root", filename); //$NON-NLS-1$ properties.setProperty("equation.system", filename); //$NON-NLS-1$
properties.setProperty("scenario.description", filename); //$NON-NLS-1$ properties.setProperty("bootstrapping.root", filename); //$NON-NLS-1$
properties.setProperty("scenario.description", filename); //$NON-NLS-1$
try {
equationSystemBuilder = new EquationSystemBuilder(); try {
equationSystemBuilder.parseEquationFile(new File(properties.getProperty("equation.system"))); //$NON-NLS-1$ equationSystemBuilder = new EquationSystemBuilder(properties);
} catch (final EquationSystemException exception) { equationSystemBuilder.parseEquationFile(new File(properties.getProperty("equation.system"))); //$NON-NLS-1$
throw new BuildException("The equation system for this scenario could not be built!", exception); //$NON-NLS-1$ } 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(); inputs = equationSystemBuilder.getInputVariables();
outputs = equationSystemBuilder.getOutputVariables();
tangibleApplication = new TangibleApplicationBootstrapper(file);
tangibleApplication = new TangibleApplicationBootstrapper(file);
populateVariables();
populateVariables();
scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes); scenes = SceneBootstrapper.getScenes();
tangibleApplication.setContentManager(StageManager.getInstance()); StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.connect();
} tangibleApplication.connect();
}
/**
* Method used to replace the placeholder variables in each widget with the variable as /**
* initialized by the equation system. The method will also set all trigger variables of * Method used to replace the placeholder variables in each widget with the variable as
* conditional corona with the variables for the given trigger names. * initialized by the equation system. The method will also set all trigger variables of
* * conditional corona with the variables for the given trigger names.
*/ *
private void populateVariables() { */
for (final BaseWidget widget : TangibleObjectManager.getWidgets()) { private void populateVariables() {
if (widget instanceof ValueWidget) { for (final BaseWidget widget : TangibleObjectManager.getWidgets()) {
final TangibleNumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName()); if (widget instanceof ValueWidget) {
((ValueWidget) widget).setVariable(variable); final TangibleNumericalVariable variable = retrieveVariableByName(((ValueWidget) widget).getVariable().getName());
((ValueWidget) widget).setVariable(variable);
for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) {
corona.getTriggers().forEach(trigger -> corona.addVariable(retrieveVariableByName(trigger))); for (final ConditionalCorona corona : widget.getCoronas(ConditionalCorona.class)) {
} corona.getTriggers().forEach(trigger -> corona.addVariable(retrieveVariableByName(trigger)));
} }
} }
} }
}
/**
* Method used to find a variable given its name in either input or output maps. /**
* * Method used to find a variable given its name in either input or output maps.
* @param name *
* The name of the variable to find. * @param name
* @return The {@link TangibleNumericalVariable} that responds to the given name or * The name of the variable to find.
* <code>null</code> should no such variable exist. * @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 TangibleNumericalVariable retrieveVariableByName(String name) {
} return (TangibleNumericalVariable) (inputs.get(name) == null ? outputs.get(name) : inputs.get(name));
}
/**
* Entry point for the application. /**
* * Entry point for the application.
* @param args *
* This must be empty, no arguments are accepted. * @param args
* @throws BuildException * This must be empty, no arguments are accepted.
*/ * @throws BuildException
public static void main(String[] args) throws BuildException { */
Preconditions.checkArgument(args.length == 1, "1 parameter needed"); //$NON-NLS-1$ public static void main(String[] args) throws BuildException {
@SuppressWarnings("unused") Preconditions.checkArgument(args.length == 1, "1 parameter needed"); //$NON-NLS-1$
final Scenario scenario = new Scenario(args[0]); @SuppressWarnings("unused")
} final Scenario scenario = new Scenario(args[0]);
}
} }
\ No newline at end of file
...@@ -96,10 +96,12 @@ public class Scene extends Content { ...@@ -96,10 +96,12 @@ public class Scene extends Content {
final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE); final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE);
for (final String _name : Splitter.on(Externalization.SPACE).trimResults().omitEmptyStrings().split(triggerCondition)) { for (final String _name : Splitter.on(Externalization.SPACE).trimResults().omitEmptyStrings().split(triggerCondition)) {
// System.out.println(_name);
final Variable variable = Scenario.retrieveVariableByName(_name); final Variable variable = Scenario.retrieveVariableByName(_name);
if (null != variable) { if (null != variable) {
variables.add(variable); variables.add(variable);
} }
} }
...@@ -108,7 +110,10 @@ public class Scene extends Content { ...@@ -108,7 +110,10 @@ public class Scene extends Content {
variables.add(triggerVariable); variables.add(triggerVariable);
} }
trigger = new Equation(new Mapping(variables, triggerVariable), triggerCondition); final LinkedHashSet<Variable> triggerVariables = new LinkedHashSet<Variable>();
// trigger = new Equation(new Mapping(variables, triggerVariable), triggerCondition);
triggerVariables.add(triggerVariable);
trigger = new Equation(new Mapping(variables, triggerVariables), triggerCondition);
try { try {
final Element imageNode = element.getChild(Externalization.IMAGE_ELEMENT); final Element imageNode = element.getChild(Externalization.IMAGE_ELEMENT);
......
/** /**
* Copyright Luxembourg Institute of Science and Technology, 2016. * Copyright Luxembourg Institute of Science and Technology, 2016.
* *
* This file is part of TULIP. * This file is part of TULIP.
* *
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3, * TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST * as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license. * proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
* *
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it * For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software * under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License. * Foundation, version 3 of the License.
* *
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If * You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. * not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/ */
package lu.list.itis.dkd.tui.scenario; package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleContentManager; import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.content.Content; import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent; import lu.list.itis.dkd.tui.cps.system.executor.Executor;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
import java.util.ArrayList; import lu.list.itis.dkd.tui.event.ContentEvent;
import java.util.Collection;
import java.util.Collections; import java.util.ArrayList;
import java.util.Map; import java.util.Collection;
import java.util.Collections;
import javax.script.ScriptEngine; import java.util.Map;
import javax.script.ScriptEngineManager;
/**
/** * @author Eric Tobias [eric.tobias@list.lu]
* @author Eric Tobias [eric.tobias@list.lu] * @since 1.0
* @since 1.0 * @version 1.0.0
* @version 1.0.0 */
*/ @NonNullByDefault
@NonNullByDefault public class StageManager extends TangibleContentManager {
public class StageManager extends TangibleContentManager { private static final StageManager INSTANCE = new StageManager();
private static final StageManager INSTANCE = new StageManager(); private static Map<String, Scene> scenes;
private static Map<String, Scene> scenes; // private static ScriptEngine scriptEngine;
private static ScriptEngine scriptEngine; private static Executor scriptEngine;
ArrayList<Content> drawableContents = new ArrayList<>(); ArrayList<Content> drawableContents = new ArrayList<>();
private StageManager() { private StageManager() {
scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$ scriptEngine = new JavascriptExecutor();
} // scriptEngine = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
}
/**
* Method for returning the single instance of this manger class. /**
* * Method for returning the single instance of this manger class.
* @return The unique instance of this manager implementing the Singleton pattern. *
*/ * @return The unique instance of this manager implementing the Singleton pattern.
public static StageManager getInstance() { */
return INSTANCE; public static StageManager getInstance() {
} return INSTANCE;
}
/**
* @param _scenes /**
*/ * @param _scenes
public static void setScenes(Map<String, Scene> _scenes) { */
scenes = _scenes; public static void setScenes(Map<String, Scene> _scenes) {
scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine)); scenes = _scenes;
// scenes.values().forEach(scene -> scene.getTrigger().setScriptEngine(scriptEngine));
scenes.values().forEach(scene -> scene.getTrigger().setExecutor(scriptEngine));
}
/** {@inheritDoc} */ }
@Override
public void contentUpdated(ContentEvent event) { /** {@inheritDoc} */
// This particular stage manager is not driven by the content. It is the variables tied to @Override
// the content that change underlying conditions to draw the stage. public void contentUpdated(ContentEvent event) {
// This particular stage manager is not driven by the content. It is the variables tied to
} // the content that change underlying conditions to draw the stage.
/** {@inheritDoc} */ }
@Override
public Collection<Content> getDrawableContents() { /** {@inheritDoc} */
drawableContents.clear(); @Override
public Collection<Content> getDrawableContents() {
for (final Scene scene : scenes.values()) { drawableContents.clear();
if (scene.evaluateTrigger()) {
drawableContents.add(scene); for (final Scene scene : scenes.values()) {
} if (scene.evaluateTrigger()) {
} drawableContents.add(scene);
Collections.sort(drawableContents); }
return drawableContents; }
Collections.sort(drawableContents);
return 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