Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TULIP-CPS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NUI
TULIP-CPS
Commits
64f96cf6
Commit
64f96cf6
authored
Jan 18, 2016
by
Eric Tobias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor changes
parent
0393e0df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
121 deletions
+154
-121
CPS/pom.xml
CPS/pom.xml
+5
-5
CPS/src/lu/list/itis/dkd/cps/system/OctaveEquation.java
CPS/src/lu/list/itis/dkd/cps/system/OctaveEquation.java
+97
-108
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
+26
-8
CPS/src/lu/list/itis/dkd/tui/widget/builder/ValueWidgetBuilder.java
.../list/itis/dkd/tui/widget/builder/ValueWidgetBuilder.java
+26
-0
No files found.
CPS/pom.xml
View file @
64f96cf6
...
...
@@ -30,15 +30,15 @@
<artifactId>
guava
</artifactId>
<version>
19.0
</version>
</dependency>
<dependency>
<groupId>
dk.ange
</groupId>
<artifactId>
javaoctave
</artifactId>
<version>
0.6.4
</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.5-SNAPSHOT
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
CPS/src/lu/list/itis/dkd/cps/system/OctaveEquation.java
View file @
64f96cf6
/**
* Copyright CRP Henri Tudor, 2014.
* All rights reserved. If you wish to use this code for any purpose,
* please contact CRP Henri Tudor's Technology Transfer Office : tto@tudor.lu
* Copyright CRP Henri Tudor, 2014. All rights reserved. If you wish to use this code for any
* purpose, please contact CRP Henri Tudor's Technology Transfer Office : tto@tudor.lu
*/
package
lu
.
list
.
itis
.
dkd
.
cps
.
system
;
import
lu.list.itis.dkd.cps.variable.Variable
;
import
lu.list.itis.dkd.dbc.annotation.NonNullByDefault
;
import
lu.list.itis.dkd.dbc.annotation.Nullable
;
import
com.google.common.base.Preconditions
;
import
java.io.CharArrayWriter
;
import
java.util.LinkedHashSet
;
import
java.util.logging.Level
;
...
...
@@ -12,14 +17,9 @@ import java.util.logging.Logger;
import
javax.script.ScriptEngine
;
import
com.google.common.base.Preconditions
;
import
dk.ange.octave.OctaveEngine
;
import
dk.ange.octave.type.Octave
;
import
dk.ange.octave.type.OctaveDouble
;
import
lu.list.itis.dkd.cps.variable.Variable
;
import
lu.list.itis.dkd.dbc.annotation.NonNullByDefault
;
import
lu.list.itis.dkd.dbc.annotation.Nullable
;
/**
* @author Nico MACK [nico.mack@list.lu]
...
...
@@ -27,104 +27,93 @@ import lu.list.itis.dkd.dbc.annotation.Nullable;
* @version 1
*/
@NonNullByDefault
public
class
OctaveEquation
extends
Equation
{
private
OctaveMapping
mapping
,
lockedMapping
;
@Nullable
private
String
script
;
private
OctaveEngine
scriptEngine
;
private
CharArrayWriter
engineErrors
;
private
static
Logger
LOGGER
=
Logger
.
getLogger
(
OctaveEquation
.
class
.
getSimpleName
());
/**
* Constructor
* @param mapping
* The mapping of variables to take into account for the equation.
* @param script
* The mathematical representation of the equation in string form.
* Note that the names of the variables in the script must coincide with
* the names of the variables in the mapping.
*/
public
OctaveEquation
(
OctaveMapping
mapping
,
String
script
)
{
super
(
mapping
,
script
);
this
.
mapping
=
mapping
;
this
.
lockedMapping
=
mapping
;
this
.
script
=
script
;
this
.
engineErrors
=
new
CharArrayWriter
();
}
/**
* Method called to evaluate the script of the equation with
* the variables provided by the mapping.
*/
@SuppressWarnings
(
"null"
)
public
synchronized
void
evaluate
()
{
LinkedHashSet
<
Variable
>
dependentVariables
;
String
evaluationErrors
;
Preconditions
.
checkState
(
scriptEngine
!=
null
);
try
{
engineErrors
.
reset
();
scriptEngine
.
setErrorWriter
(
engineErrors
);
initParameters
();
scriptEngine
.
eval
(
this
.
script
);
}
catch
(
Exception
exception
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Error while evaluating script "
+
this
.
script
,
exception
);
}
dependentVariables
=
mapping
.
getDependentVariables
();
for
(
Variable
variable:
dependentVariables
)
{
try
{
OctaveDouble
result
=
scriptEngine
.
get
(
OctaveDouble
.
class
,
variable
.
getName
());
variable
.
setValue
(
result
.
get
(
1
));
}
catch
(
Exception
exception
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Error while retrieving variable "
+
variable
.
getName
(),
exception
);
}
}
evaluationErrors
=
engineErrors
.
toString
();
if
(
evaluationErrors
.
length
()
>
0
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"Error while evaluating equation :"
+
evaluationErrors
);
}
}
/**
* Method used to replace variables with their actual values in the formula.
* @return
* The formula with variables replaced by their values, ready for evaluation.
*/
private
void
initParameters
()
{
for
(
Variable
variable
:
lockedMapping
.
getIndependentVariables
())
{
Double
numericValue
=
Double
.
valueOf
(
variable
.
getValue
().
toString
());
scriptEngine
.
put
(
variable
.
getName
(),
Octave
.
scalar
(
numericValue
));
}
}
/**
* Method for setting the script engine to use.
* @param engine
* The {@link ScriptEngine} instance to use for
* evaluating the scripted formulas.
*/
public
void
setScriptEngine
(
OctaveEngine
engine
)
{
scriptEngine
=
engine
;
}
public
class
OctaveEquation
extends
Equation
{
private
OctaveMapping
mapping
,
lockedMapping
;
@Nullable
private
String
script
;
private
OctaveEngine
scriptEngine
;
private
CharArrayWriter
engineErrors
;
private
static
Logger
LOGGER
=
Logger
.
getLogger
(
OctaveEquation
.
class
.
getSimpleName
());
/**
* Constructor
*
* @param mapping
* The mapping of variables to take into account for the equation.
* @param script
* The mathematical representation of the equation in string form. Note that the names of
* the variables in the script must coincide with the names of the variables in the
* mapping.
*/
public
OctaveEquation
(
OctaveMapping
mapping
,
String
script
)
{
super
(
mapping
,
script
);
this
.
mapping
=
mapping
;
this
.
lockedMapping
=
mapping
;
this
.
script
=
script
;
this
.
engineErrors
=
new
CharArrayWriter
();
}
/**
* Method called to evaluate the script of the equation with the variables provided by the
* mapping.
*/
@SuppressWarnings
(
"null"
)
public
synchronized
void
evaluate
()
{
LinkedHashSet
<
Variable
>
dependentVariables
;
String
evaluationErrors
;
Preconditions
.
checkState
(
scriptEngine
!=
null
);
try
{
engineErrors
.
reset
();
scriptEngine
.
setErrorWriter
(
engineErrors
);
initParameters
();
scriptEngine
.
eval
(
this
.
script
);
}
catch
(
Exception
exception
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Error while evaluating script "
+
this
.
script
,
exception
);
}
dependentVariables
=
mapping
.
getDependentVariables
();
for
(
Variable
variable
:
dependentVariables
)
{
try
{
OctaveDouble
result
=
scriptEngine
.
get
(
OctaveDouble
.
class
,
variable
.
getName
());
variable
.
setValue
(
result
.
get
(
1
));
}
catch
(
Exception
exception
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
"Error while retrieving variable "
+
variable
.
getName
(),
exception
);
}
}
evaluationErrors
=
engineErrors
.
toString
();
if
(
evaluationErrors
.
length
()
>
0
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"Error while evaluating equation :"
+
evaluationErrors
);
}
}
/**
* Method used to replace variables with their actual values in the formula.
*
* @return The formula with variables replaced by their values, ready for evaluation.
*/
private
void
initParameters
()
{
for
(
Variable
variable
:
lockedMapping
.
getIndependentVariables
())
{
Double
numericValue
=
Double
.
valueOf
(
variable
.
getValue
().
toString
());
scriptEngine
.
put
(
variable
.
getName
(),
Octave
.
scalar
(
numericValue
));
}
}
/**
* Method for setting the script engine to use.
*
* @param engine
* The {@link ScriptEngine} instance to use for evaluating the scripted formulas.
*/
public
void
setScriptEngine
(
OctaveEngine
engine
)
{
scriptEngine
=
engine
;
}
}
\ No newline at end of file
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
View file @
64f96cf6
...
...
@@ -16,14 +16,18 @@
*/
package
lu
.
list
.
itis
.
dkd
.
tui
.
widget
;
import
lu.list.itis.dkd.cps.variable.NumericalVariable
;
import
lu.list.itis.dkd.cps.variable.
tangible.Tangible
NumericalVariable
;
import
lu.list.itis.dkd.dbc.annotation.NonNullByDefault
;
import
lu.list.itis.dkd.dbc.annotation.Nullable
;
import
lu.list.itis.dkd.tui.adapter.TangibleObject
;
import
lu.list.itis.dkd.tui.content.InformationProvider
;
import
lu.list.itis.dkd.tui.content.InformationReceiver
;
import
lu.list.itis.dkd.tui.utility.Point
;
import
lu.list.itis.dkd.tui.widget.builder.BaseValueWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.builder.ValueWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.corona.Corona
;
import
java.awt.Graphics2D
;
/**
* A simple widget that holds an integer value and may modify the value base on a rotation.
...
...
@@ -46,7 +50,7 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
/** The value of the angle that is considered as one step. */
private
double
stepSize
;
/** The variable holding the value to be stored and manipulated by the widget. */
private
NumericalVariable
variable
;
private
Tangible
NumericalVariable
variable
;
/** The base value to be set for the variable. */
private
final
double
baseValue
;
/** Whether the value held by the widget is to be modified on a rotation of a handle. */
...
...
@@ -66,7 +70,7 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
this
.
lowerStopAngle
=
builder
.
lowerStopAngle
;
this
.
upperStopAngle
=
builder
.
upperStopAngle
;
this
.
stepSize
=
builder
.
stepSize
;
this
.
setVariable
(
builder
.
variable
)
;
this
.
variable
=
builder
.
variable
;
this
.
modifyValueOnRotation
=
builder
.
modifyValueOnRotation
;
/**
...
...
@@ -105,30 +109,44 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
/** {@inheritDoc} */
@Override
public
@Nullable
Double
getInformation
(
Point
position
)
{
return
getInformation
(
);
return
variable
.
getInformation
(
position
);
}
/** {@inheritDoc} */
@Override
public
Double
getInformation
()
{
return
getVariable
().
getValue
();
return
variable
.
getInformation
();
}
/**
* Simple getter method for variable.
*
* @return The value of variable.
*/
public
NumericalVariable
getVariable
()
{
public
Tangible
NumericalVariable
getVariable
()
{
return
variable
;
}
/**
* Simple setter method for variable.
*
* @param variable
* The value to set variable to.
* The value to set variable to.
* @return
*/
public
NumericalVariable
setVariable
(
NumericalVariable
variable
)
{
public
TangibleNumericalVariable
setVariable
(
Tangible
NumericalVariable
variable
)
{
this
.
variable
=
variable
;
return
variable
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
void
paint
(
Graphics2D
canvas
)
{
for
(
Corona
corona
:
coronas
.
values
())
{
if
(
corona
instanceof
InformationReceiver
<?>)
{
((
InformationReceiver
<
String
>)
corona
).
setInformation
(
variable
.
getInformation
().
toString
());
}
}
super
.
paint
(
canvas
);
}
}
\ No newline at end of file
CPS/src/lu/list/itis/dkd/tui/widget/builder/ValueWidgetBuilder.java
View file @
64f96cf6
...
...
@@ -16,8 +16,11 @@
*/
package
lu
.
list
.
itis
.
dkd
.
tui
.
widget
.
builder
;
import
lu.list.itis.dkd.tui.exception.BuildException
;
import
lu.list.itis.dkd.tui.widget.ValueWidget
;
import
org.jdom2.Element
;
/**
* The concrete builder that will build a new instance of {@link ValueWidget} with each call to
* {@link #build()}.
...
...
@@ -28,9 +31,32 @@ import lu.list.itis.dkd.tui.widget.ValueWidget;
*/
public
final
class
ValueWidgetBuilder
extends
BaseValueWidgetBuilder
<
ValueWidgetBuilder
>
{
/**
* Simple no-arg constructor initializing all fields.
*/
public
ValueWidgetBuilder
()
{
super
();
}
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public
ValueWidgetBuilder
(
Element
rootElement
)
throws
BuildException
{
super
(
rootElement
);
}
/** {@inheritDoc} */
@Override
public
ValueWidget
build
()
{
return
new
ValueWidget
(
this
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment