« Units management » : différence entre les versions

De GENIUS
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
 
(10 versions intermédiaires par le même utilisateur non affichées)
Ligne 6 : Ligne 6 :
</syntaxhighlight>
</syntaxhighlight>


In case of using [{{PathCurrentJavaDoc}}/fr/cnes/genius/unit/GMetricUnit.html|GMetricUnit], when we define a unit for a real value, it is stored automatically in the computer memory in '''International System (IS)''' (m, kg, rad …).
Since V1.7, a static factory method is available to simplify the creation of such tabel. We may write:
<syntaxhighlight lang="java">
GUnit[] unitDis = GUnitFactory.getGUnitArray("km", "nmi");
</syntaxhighlight>


<syntaxhighlight lang="java">                  
In case of using [{{PathCurrentJavaDoc}}/fr/cnes/genius/unit/GMetricUnit.html GMetricUnit], when we define a unit for a real value, it is stored automatically in the computer memory in '''International System (IS)''' (m, kg, rad …).
 
<syntaxhighlight lang="java">
dist  = new GEntryReal("Distance", 1000., unitDis); // Initialization with 1000 meters.
dist  = new GEntryReal("Distance", 1000., unitDis); // Initialization with 1000 meters.
</syntaxhighlight>
</syntaxhighlight>
Ligne 14 : Ligne 19 :
Thus, in that case, we may have a difference between what it is displayed (for example 1.0 km) and what it is actually stored in the memory (1000.).
Thus, in that case, we may have a difference between what it is displayed (for example 1.0 km) and what it is actually stored in the memory (1000.).


[[File:Units.jpg]]
[[File:Units.png]]


To get the value stored in memory (same for an integer even if there is no units for it), we will use the <font color=#4169E1>getValue()</font> method:
To get the value stored in memory (same for an integer even if there is no units for it), we will use the <font color=#4169E1>getValue()</font> method:
Ligne 21 : Ligne 26 :
double val = dist.getValue(); // Allways in IS
double val = dist.getValue(); // Allways in IS
</syntaxhighlight>
</syntaxhighlight>
== Available units ==


The basic '''IS''' units given by default by <font color=#556B2F>'''GENIUS'''</font> are the following:
The basic '''IS''' units given by default by <font color=#556B2F>'''GENIUS'''</font> are the following:
Ligne 51 : Ligne 58 :
* minutes = 60 s => '''mn'''
* minutes = 60 s => '''mn'''
* hour = 3600 s => '''h'''
* hour = 3600 s => '''h'''
* day = 86400 => '''j'''
* day = 86400 => '''j''' or '''d'''
* month = 1/12 year => '''mo'''
* year = 365.25 days => '''a''' or '''y'''


It is also possible to use coefficients:
It is also possible to use coefficients:
Ligne 76 : Ligne 85 :
* "'''%'''" to "'''‰'''" (using [{{PathCurrentJavaDoc}}/fr/cnes/genius/unit/GPercentUnit.html GPercentUnit]).
* "'''%'''" to "'''‰'''" (using [{{PathCurrentJavaDoc}}/fr/cnes/genius/unit/GPercentUnit.html GPercentUnit]).


== How to enter directly a unit ==
Even if a unit is not proposed in the dedicated menu ("'''km'''" and "'''nmi'''" in the previous example), it is possible to enter a compatible unit with the following syntax:
[[File:Units2.png]]
Thus, it will take into account 0.01 meter in memory and will display the value with the current displayed unit.
[[File:Units3.png]]


[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[GContainer|Go to the next page →]]
[[GContainer|Go to the next page →]]

Dernière version du 14 novembre 2019 à 08:58

Units are managed with the GUnit class or more directly with GMetricUnit.

// To display a menu allowing to display kilometers (km) or Nautic Miles (nmi)
GUnit[] unitDis = { new GMetricUnit ("km") , new GMetricUnit ("nmi") };

Since V1.7, a static factory method is available to simplify the creation of such tabel. We may write:

GUnit[] unitDis = GUnitFactory.getGUnitArray("km", "nmi");

In case of using GMetricUnit, when we define a unit for a real value, it is stored automatically in the computer memory in International System (IS) (m, kg, rad …).

dist  = new GEntryReal("Distance", 1000., unitDis); // Initialization with 1000 meters.

Thus, in that case, we may have a difference between what it is displayed (for example 1.0 km) and what it is actually stored in the memory (1000.).

Units.png

To get the value stored in memory (same for an integer even if there is no units for it), we will use the getValue() method:

double val = dist.getValue(); // Allways in IS

Available units

The basic IS units given by default by GENIUS are the following:

  • kilogram (kg)
  • meter (m)
  • second (s)
  • Amper (A)

Of course, GENIUS proposes also angular units with radian (rad) for IS to be convertible in degree (deg).

Then, it is possible to get composed units using "." for multiplication, "/" for division or "^'" for power (a negative power is enabled). Thus, we may have kg.m/s^2 (or kg.m.s^-2) as a composed unit.

Allways about composed units, GENIUS proposes the following ones:

  • Steradians (m2.m-2) => sr
  • Hertz (s-1) => Hz
  • Newton (kg.m.s-2) => N
  • Pascal (N.m-2) => Pa
  • Joules (N.m) => J
  • Watt (J.s-1) => W
  • Coulomb (A.s) => C
  • Volt (W.A-1) => V
  • Farad (C.V-1) => F
  • Ohm (V.A-1) => R

For more facilities, these units have also been added:

  • gramm = 0.001*kg => g
  • ton = 1000 kg => t
  • minutes = 60 s => mn
  • hour = 3600 s => h
  • day = 86400 => j or d
  • month = 1/12 year => mo
  • year = 365.25 days => a or y

It is also possible to use coefficients:

  • T: Tera = 1012
  • G : Giga = 109
  • M: Mega = 106
  • k: kilo = 103
  • h: hecto = 102
  • da: deca = 10
  • d: deci = 10-1
  • c: centi = 10-2
  • m: mili = 10-3
  • u: micro = 10-6
  • n: nano = 10-9
  • p: pico = 10-12

Note that for mass values, these coefficient will be applied on "g" and not "kg".

So, we could have something as mg.dam/mn^2 ... for something equivalent as (1/36)10-6 Newtons !

At last, for not proportional conversions, GENIUS proposes anyway to convert:

How to enter directly a unit

Even if a unit is not proposed in the dedicated menu ("km" and "nmi" in the previous example), it is possible to enter a compatible unit with the following syntax:

Units2.png

Thus, it will take into account 0.01 meter in memory and will display the value with the current displayed unit.

Units3.png

Return to the introduction ↑ Go to the next page →