Validity controls : Différence entre versions

De Wiki
Aller à : navigation, rechercher
(Page créée avec « TBW ... Return to the introduction ↑ Go to the next page → »)
 
Ligne 1 : Ligne 1 :
TBW ...
+
<font color=#556B2F>'''GENIUS'''</font> gives the possibility to manage validity intervals (consistent with <font color=#556B2F>'''SIRIUS'''</font> requirements):
 +
  * Only for [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GEntryReal.html GEntryReal], [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GEntryInt.html GEntryInt], [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GEntryRealVector.html GEntryRealVector] et [{{PathCurrentJavaDoc}}/fr/cnes/genius/highLevel/GEntryIntVector.html GEntryIntVector] widgets
 +
* Possibility to get an error and/or warning information
 +
* For real values, these validity controls of course take into account units management
 +
 
 +
To do it, we will have to instantiate a [{{PathCurrentJavaDoc}}/fr/cnes/genius/interval/GInterval.html GInterval] object. The example below shows how to create an [0.,100.] validity interval.
 +
 
 +
<syntaxhighlight lang="java">
 +
GInterval myInterval = new GInterval(0., 100.);
 +
</syntaxhighlight>
 +
 
 +
It is possible to precise if the interval is opened or closed on each side (by default it is inclusive): below, we define the validity interval as [0., 100.[.
 +
 
 +
<syntaxhighlight lang="java">
 +
GInterval myInterval = new GInterval(0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);
 +
</syntaxhighlight>
 +
 
 +
At last, it is possible to add an intermediate "warning" interval meaning that the value is OK but to be careful with it:
 +
 
 +
<syntaxhighlight lang="java">
 +
GInterval myInterval = new GInterval(10.,  90., GInterval.Rule.EXCLUSIVE, GInterval.Rule.EXCLUSIVE,
 +
                                      0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);
 +
</syntaxhighlight>
 +
 
 +
With that example, the data will be OK if included in the [0.,100.] interval but a warning message will appear if the data will be comprised in the [0.,10.[ or ]90.,100.] intervals.
 +
 
 +
Note that we can use the infinity definitions given by the Java language to define, for example the [0,∞[ interval:
 +
 
 +
<syntaxhighlight lang="java">
 +
GInterval myInterval = new GInterval(0., Double.POSITIVE_INFINITY);
 +
</syntaxhighlight>
 +
 
 +
At last, in case of an data out of the validity interval (or the warning one), a tooltip is available when the mouse will stay above the input field (see below).
 +
 
 +
[[File:ValidityControls.jpg]]
 +
 
 +
The corresponding code is the following one:
 +
 
 +
<syntaxhighlight lang="java">
 +
GUnit[] unitDuration = {new GMetricUnit("mn"), new GMetricUnit("s")};
 +
GUnit[] unitThrust = {new GMetricUnit("N")};
 +
GUnit[] unitIsp = {new GMetricUnit("s")};
 +
 
 +
// Error control validity
 +
durationIhm =  new GEntryReal("Duration:", val1, unitDuration);
 +
durationIhm.addInterval( new GInterval(0., Double.POSITIVE_INFINITY) );
 +
 
 +
// No validity control
 +
thrustIhm =  new GEntryReal("Thrust:", val2, unitThrust);
 +
 
 +
// Error and warning control validity
 +
// Error if ]-Inf,200[ or[400,+Inf[
 +
// Warning if [200,250[ or[350,400[
 +
// OK if[250,350[
 +
ispIhm    =  new GEntryReal("Isp:", val3, unitIsp);
 +
ispIhm.addInterval( new GInterval(250., 350., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
 +
                                  200., 400., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE) );
 +
</syntaxhighlight>
 +
 
 +
== Status management ==
 +
 
 +
This validity interval check is not only a graphical one. Indeed, we may also get the status of a widget using the <font color=#4169E1>getStatus()</font> method. This method will return a <font color=#4169E1>GStatus</font> enumeration : <font color=#4169E1>GStatus.OK</font>, <font color=#4169E1>GStatus.WARN</font> or <font color=#4169E1>GStatus.ERR</font>.
 +
 
 +
Moreover, from 1.4 version, it is now possible to use a mechanism allowing to globally manage the whole data status. This mechanism uses the <font color=#4169E1>GCondensedStatusInterface</font> as explained below.
 +
 
 +
First, the widgets in which we want to test data validity must implement this interface and thus we have to define the <font color=#4169E1>updateCondensedStatus</font> method where we will check the data to be considered:
 +
 
 +
<syntaxhighlight lang="java">
 +
public class TestForCondensedStatusWidget extends GPanel implements GCondensedStatusInterface {
 +
 +
    private final GEntryReal valAngle;
 +
    private final GEntryReal valDist;
 +
 
 +
    public final GInterval angleInterval =
 +
        new GInterval(30., 60., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
 +
                      0., 90., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);
 +
    public final GInterval distInterval =
 +
        new GInterval(100.e+3, 1000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE,
 +
                        0.,  36000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);
 +
 +
    public TestForCondensedStatusWidget() throws GIntervalException {
 +
        valAngle = new GEntryReal("Angle entry", 45.);
 +
        valAngle.addGInterval(angleInterval);
 +
        valDist = new GEntryReal("Distance entry", 500.e+3);
 +
        valDist.addGInterval(distInterval);
 +
    }
 +
 
 +
...
 +
 
 +
    @Override
 +
    public void updateCondensedStatus(GCondensedStatus arg0) {
 +
        // valAngle and valDist are checked
 +
        arg0.update(valAngle, valDist);
 +
    }
 +
 
 +
}
 +
</syntaxhighlight>
 +
 
 +
Then, to test the global status (for example just before launching an execution), we only have to write something like this:
 +
 
 +
<syntaxhighlight lang="java">
 +
    TestForCondensedStatusWidget widget = new TestForCondensedStatusWidget();
 +
   
 +
    ...
 +
 
 +
    GCondensedStatus status = new GCondensedStatus(widget);
 +
   
 +
    // We print the global status ...
 +
    System.out.println("Global status: "+status.getStatus());
 +
   
 +
    // We print the list of data with an ERROR status ...
 +
    for (int i = 0; i < status.getErrorComponentList().size(); i++) {
 +
        System.out.println("Error on "+status.getErrorComponentList().get(i).getNameInConfigFile());
 +
    }
 +
 
 +
    // We print the list of data with a WARNING status ...
 +
        for (int i = 0; i < status.getWarningComponentList().size(); i++) {
 +
        System.out.println("Warning on "+status.getWarningComponentList().get(i).getNameInConfigFile());
 +
    }
 +
 
 +
</syntaxhighlight>
 +
 
  
 
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
 
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
 
[[Menu_bar|Go to the next page →]]
 
[[Menu_bar|Go to the next page →]]

Version du 5 mai 2017 à 10:36

GENIUS gives the possibility to manage validity intervals (consistent with SIRIUS requirements):

 * Only for GEntryReal, GEntryInt, GEntryRealVector et GEntryIntVector widgets
  • Possibility to get an error and/or warning information
  • For real values, these validity controls of course take into account units management

To do it, we will have to instantiate a GInterval object. The example below shows how to create an [0.,100.] validity interval.

GInterval myInterval = new GInterval(0., 100.);

It is possible to precise if the interval is opened or closed on each side (by default it is inclusive): below, we define the validity interval as [0., 100.[.

GInterval myInterval = new GInterval(0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);

At last, it is possible to add an intermediate "warning" interval meaning that the value is OK but to be careful with it:

GInterval myInterval = new GInterval(10.,  90., GInterval.Rule.EXCLUSIVE, GInterval.Rule.EXCLUSIVE,
                                      0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);

With that example, the data will be OK if included in the [0.,100.] interval but a warning message will appear if the data will be comprised in the [0.,10.[ or ]90.,100.] intervals.

Note that we can use the infinity definitions given by the Java language to define, for example the [0,∞[ interval:

GInterval myInterval = new GInterval(0., Double.POSITIVE_INFINITY);

At last, in case of an data out of the validity interval (or the warning one), a tooltip is available when the mouse will stay above the input field (see below).

ValidityControls.jpg

The corresponding code is the following one:

GUnit[] unitDuration = {new GMetricUnit("mn"), new GMetricUnit("s")};
GUnit[] unitThrust = {new GMetricUnit("N")};
GUnit[] unitIsp = {new GMetricUnit("s")};
 
// Error control validity
durationIhm =  new GEntryReal("Duration:", val1, unitDuration);
durationIhm.addInterval( new GInterval(0., Double.POSITIVE_INFINITY) );
 
// No validity control
thrustIhm =  new GEntryReal("Thrust:", val2, unitThrust);
 
// Error and warning control validity
// Error if ]-Inf,200[ or[400,+Inf[
// Warning if [200,250[ or[350,400[
// OK if[250,350[
ispIhm    =  new GEntryReal("Isp:", val3, unitIsp);
ispIhm.addInterval( new GInterval(250., 350., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
                                  200., 400., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE) );

Status management

This validity interval check is not only a graphical one. Indeed, we may also get the status of a widget using the getStatus() method. This method will return a GStatus enumeration : GStatus.OK, GStatus.WARN or GStatus.ERR.

Moreover, from 1.4 version, it is now possible to use a mechanism allowing to globally manage the whole data status. This mechanism uses the GCondensedStatusInterface as explained below.

First, the widgets in which we want to test data validity must implement this interface and thus we have to define the updateCondensedStatus method where we will check the data to be considered:

public class TestForCondensedStatusWidget extends GPanel implements GCondensedStatusInterface {
 
    private final GEntryReal valAngle;
    private final GEntryReal valDist;
 
    public final GInterval angleInterval =
        new GInterval(30., 60., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
                       0., 90., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);
    public final GInterval distInterval =
        new GInterval(100.e+3, 1000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE,
                        0.,   36000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);
 
    public TestForCondensedStatusWidget() throws GIntervalException {
        valAngle = new GEntryReal("Angle entry", 45.);
        valAngle.addGInterval(angleInterval);
        valDist = new GEntryReal("Distance entry", 500.e+3);
        valDist.addGInterval(distInterval);
    }
 
...
 
    @Override
    public void updateCondensedStatus(GCondensedStatus arg0) {
        // valAngle and valDist are checked
        arg0.update(valAngle, valDist);	
    }
 
}

Then, to test the global status (for example just before launching an execution), we only have to write something like this:

    TestForCondensedStatusWidget widget = new TestForCondensedStatusWidget();
 
    ...
 
    GCondensedStatus status = new GCondensedStatus(widget);
 
    // We print the global status ...
    System.out.println("Global status: "+status.getStatus());
 
    // We print the list of data with an ERROR status ...
    for (int i = 0; i < status.getErrorComponentList().size(); i++) {
        System.out.println("Error on "+status.getErrorComponentList().get(i).getNameInConfigFile());				
    }
 
    // We print the list of data with a WARNING status ...
        for (int i = 0; i < status.getWarningComponentList().size(); i++) {
        System.out.println("Warning on "+status.getWarningComponentList().get(i).getNameInConfigFile());				
    }


Return to the introduction ↑ Go to the next page →