https://wiki.freecad.org/api.php?action=feedcontributions&user=Jriegel&feedformat=atomFreeCAD Documentation - User contributions [en]2024-03-29T12:50:39ZUser contributionsMediaWiki 1.40.1https://wiki.freecad.org/index.php?title=Units&diff=102744Units2014-08-03T15:41:04Z<p>Jriegel: /* Supported units */</p>
<hr />
<div>Here some reading about units:<br />
*[http://en.wikipedia.org/wiki/International_System_of_Units SI system]<br />
*[http://en.wikipedia.org/wiki/Imperial_units Imperial units]<br />
*[http://en.wikipedia.org/wiki/SI_derived_unit SI derived units]<br />
*[http://en.wikipedia.org/wiki/Degree_%28angle%29 angle units]<br />
<br />
== Examples ==<br />
<br />
# -- some examples of the FreeCAD unit translation system --<br />
# make a shortcut for the examples<br />
tu = FreeCAD.Units.parseQuantity<br />
<br />
# 10 meters in internal numbers<br />
tu('10 m')<br />
# doing math<br />
tu('3/8 in')<br />
# combined stuff<br />
tu('100 km/h')<br />
# transfer to other units<br />
tu('100 km/h')/tu('m/s')<br />
# derived units (Ohm)<br />
tu('m^2*kg*s^-3*A^-2')<br />
# or<br />
tu('(m^2*kg)/(A^2*s^3)')<br />
# angles <br />
tu('2*pi rad') # full circle<br />
# as gon<br />
tu('2*pi rad') / tu('gon')<br />
# more imperial<br />
tu('1ft (3+7/16)in')<br />
# or <br />
tu('1\' (3+7/16)"') # the ' we have to escape because of python<br />
# trigonometry<br />
tu('sin(pi)')<br />
# Using translated units as parameters, this command will create a 50.8mm x 20mm x 10mm box<br />
b = Part.makeBox(tu('2in'),tu('2m')/100,10)<br />
<br />
== Supported units ==<br />
Here the defined units in FreeCAD so far. It's easy to add a new user defined unit. The definition is here[http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Base/UnitsApi.l?view=markup]. <br />
<br />
Metric length<br />
"mm" 1.0; // millimeter (internal standard length)<br />
"m" 1000.0; // meter<br />
"cm" 10.0; // centimeter<br />
"dm" 100.0; // decimeter<br />
"km" 1000000.0; // kilometer<br />
Imperial lenth<br />
"in" "\"" 25.4; // inch<br />
"ft" "'" 304.8; // foot<br />
"th" 0.0254; // thou<br />
"yr" 914.4; // yard<br />
Metric mass<br />
"kg" 1.0; // kilogram (internal standard mass)<br />
"g" 0.001; // gram<br />
"mg" 0.000001; // milligram<br />
"t" 1000.0; // ton <br />
Imperial mass<br />
"lb" 0.45359237; // pound<br />
"oz" 0.45359237; // ounce<br />
"st" 6.35029318; // Stone<br />
"cwt" 50.80234544;// hundredweights<br />
Angle<br />
"deg" 1.0; // degree (internal standard angle)<br />
"rad" 180/M_PI; // radian <br />
"gon" 360.0/400.0;// gon <br />
Time<br />
"s" 1.0; // second (internal standard time)<br />
"min" 60.0; // minute<br />
"h" 3600.0; // hour <br />
Rest of SI<br />
"A" 1.0; // Ampere (internal standard electric current)<br />
"K" 1.0; // Kelvin (internal standard thermodynamic temperature)<br />
"cd" 1.0; // Candela (internal standard luminous intensity) <br />
"mol" 1.0; // Mole (internal standard amount of substance) <br />
Metric Volume<br />
"µl" 1.0; // microliter mm^3(derived standard volume)<br />
"ml" 1000.0; // milliliter cm^3 <br />
"l" 1000000.0; // Liter dm^3<br />
<br />
== Purpose and principles: proposal of an extension of the unit management system ==<br />
<br />
An extension unit management system is proposed in the following sections, developping the concept of ''unit system'', activated during a running FreeCAD instance.<br />
The interest in defining such a new concept is to work more easily with as many type of '''physical''' units as one wants (even user-created ones), without increasing the complexity of unit management for the user, nor for FreeCAD developpers.<br />
<br />
In short, event of unit scaling are localized precisely, and carried out in a generic fashion.<br />
<br />
Achieving such a flexibility is most notably required when one starts to deal with material properties that can have very different units, difficult to manage one by one manually.<br />
<br />
The reasoning proposed allows handling the units such as described in the [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)] both from NIST.<br />
<br />
In this proposal, one first recall in [[Units#Brainstorming|Brainstorming]] section what are the possible contexts for which unit management is required.<br />
<br />
In [[Units#Organizing|Organizing]] section, we present the data model retained to achieve unit management, based on 3 objects, the ''unit'', the ''unit dictionary'', and the ''unit system''.<br />
Finally, a short API of a 4th object called the ''unit manager'' is presented as well.<br />
<br />
== Outcome ==<br />
<br />
Thanks to this extension, one aims to ease unit scaling that can occurs between different business tasks. For instance, technical drawings can be done in standard unit system, while FE modelling can be managed in an unit system more suited for it.<br />
<br />
The exchange of data between these two kind of activities become easier with this extension.<br />
<br />
== Brainstorming ==<br />
<br />
In this section are highlighted the contexts of use of such an unit management system.<br />
From these contexts, we are then able to defined its technical specifications.<br />
<br />
Essentially 2 contexts are given as example.<br />
<br />
=== Context 1: opening a data file ===<br />
<br />
This case is probably the most frequent case.<br />
You receive a file containing for instance a geometrical model, or describing a material with quite a lot of properties. The geometrical model is expressed in meters, or the material properties according the international unit system.<br />
<br />
Too bad...<br />
<br />
You are an expert FE modelling, and you usually work with millimeter for length, MegaPascal for stress, tonne for mass...<br />
<br />
In this context, unit management is required to scale data from an initial unit system defined in the input file to a user-defined target unit system.<br />
<br />
=== Context 2: switching the unit system at runtime ===<br />
<br />
In this case, you can be at the same time the guy that carries out a drawing, and the guy that will manage the FE modelling. Similarly to the previous case, the unit systems for these 2 tasks are not the same, and you need to switch the initial unit system at runtime to your favorite one.<br />
<br />
== Organizing ==<br />
<br />
=== Logic of unit scaling ===<br />
<br />
In the [[Units#Brainstorming|Brainstorming]] section have been presented 2 contexts when using unit scaling.<br />
Some items should be highlighted from these two contexts.<br />
<br />
==== Unit coherence throughout the FreeCAD running instance ====<br />
<br />
The system proposed is based on a primary assumption: the user is working in a coherent unit system.<br />
For instance, this means that if the user expresses length in millimeters, necessarily areras will be expressed in terms of squared millimeters, not squared meters.<br />
This is '''hypothesis one'''.<br />
<br />
==== Unit system ====<br />
<br />
Because of ''hypothesis one'', it is possible and relevant to define an unit system.<br />
An unit system applies to:<br />
* a running FreeCAD instance into which you are working<br />
* or it may also apply globally to the content of an input file<br />
According [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] from NIST, they are 7 physical base units.<br />
We chose to express a unit system in terms of these 7 base units.<br />
<br />
When working within an instance of FreeCAD, the user has thus to define first the unit system according to which she/he is working before she/he decides to switch to another unit system, or before importing data from an input file.<br />
<br />
This unit system will apply till the user decides to change it. If she/he does, all data with dimensions will be scaled.<br />
<br />
Considering ''hypothesis one'', all data that the user will input manually in FreeCAD are assumed to be coherent with the chosen unit system.<br />
<br />
The benefit to work with a ''unit system'' defined at a FreeCAD running instance level, or at data file level (instead of ''unit'' which are defined at the data level) is then that unit management is considerably simplified.<br />
<br />
Here are some examples of unit systems.<br />
* meter, kilogram, second, ampere, Kelvin, mole, candela<br />
* millimeter, tonne, millisecond, ampere, Kelvin, mole, candela<br />
* millimeter, kilogramme, millisecond, ampere, Kelvin, mole, candela<br />
*...<br />
<br />
==== Base and derived units ====<br />
<br />
Derived units are created by combination of base units. For instance, an acceleration (m/s) combines at the same time length and time. An interesting picture presenting the relationships between base and derived units can be seen [http://physics.nist.gov/cuu/pdf/SIDiagramColorAnnot.pdf here] also from NIST.<br />
<br />
Thanks to the definition of ''unit system'', it is possible for the user to work with any kind of derived units, without the need for FreeCAD developpers to foresee them in advance.<br />
<br />
==== Base and derived unit symbols ====<br />
<br />
According to [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)], the symbols to specify a units are officially approved. Two consequences can be highlighted from this.<br />
* it is not easy for a computer program to work with unit symbols because some are greek letters for instance. Hence they can be a bit difficult to process by a program<br />
* while some units and their symbols can be used widely, they may be not approved officially, like for instance ''tonne'' unit (see p32 of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)])<br />
<br />
To overcome these limitations and remain flexible, the proposed system favors the use of unit magnitudes instead of unit symbols, which remain nonetheless available for an ergonomy reason.<br />
<br />
=== Data model ===<br />
<br />
The three core objects of the unit management system are presented, namely the ''unit'', the ''unit dictionary'' and the ''unit system''.<br />
<br />
==== Unit ====<br />
<br />
As a foreword, it is important to highlight that a ''unit'' object in itself only indicates a '''dimension''' like length, mass, time... It doesn't specify a '''magnitude''' like meter, millimeter, kilometer... This last information is specified through the unit system.<br />
<br />
===== Dimension =====<br />
<br />
Compulsory string indicating the ''dimension'' of the unit. The ''dimension'' of the 7 base units are indicated below (from [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)]).<br />
* LENGTH<br />
* MASS<br />
* TIME<br />
* ELECTRIC CURRENT<br />
* THERMODYNAMIC TEMPERATURE<br />
* AMOUNT OF SUBSTANCE<br />
* LUMINOUS INTENSITY<br />
<br />
''Dimension'' attribute allows identifying the unit.<br />
Two units cannot share the same ''dimension''.<br />
<br />
===== Signature =====<br />
<br />
Compulsory integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
''Signature'' is the attribute thanks to which unit scaling can be achieved in a generic way.<br />
<br />
===== Symbols =====<br />
<br />
Array of [real, string] (meaning [''magnitude'', ''symbol'']) that lists all ''symbols'' known by FreeCAD.<br />
Thanks to this array, the unit scaling API becomes more ergonomic because ''symbols'' and related ''magnitudes'' are linked.<br />
<br />
This array can be extended as required.<br />
<br />
For instance, the list of ''symbols'' of the LENGTH unit, and their related ''magnitudes'' is:<br />
<br />
[1e+12,"Tm"],[1e+09,"Gm"],[1e+06,"Mm"],<br />
[1e+03,"km"],[1e+02,"hm"],[1e+01,"dam"],<br />
[1e+00,"m"],[1e-01,"dm"],[1e-02,"cm"],<br />
[1e-03,"mm"],[1e-06,"µm"],[1e-09,"nm"],<br />
[1e-12,"pm"],[1e-15,"fm"]<br />
<br />
Standard ''symbols'' can be found on [http://physics.nist.gov/cuu/Units/units.html NIST website] and p23 to 26 and p32 (''metric ton'' or ''tonne'') of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)].<br />
<br />
==== Unit dictionary ====<br />
<br />
All the units available in FreeCAD, and new ones created by the user, should be stored in ''unit dictionary'', which is an XML file (FreeCAD configuration file), so as to be retrieved when needed, i.e. when achieving unit scaling.<br />
<br />
===== Units =====<br />
<br />
Array of units, contained in the ''unit dictionary''.<br />
<br />
==== Unit system ====<br />
<br />
A ''unit system'' is the object that allows the user defining the current unit ''magnitude'' of each base units with which she/he is working.<br />
For instance, knowing that the user is working with millimeter, tonne, and second, thanks to the use of a unit system, FreeCAD can know that energy is expressed in terms of milliJoule, force in terms of Newton, and stress in terms of MegaPascal.<br />
Hence a unit system is only defined by a ''name'' (for instance ''Standard unit system'') and a ''magnitude table'' specifying for each of the 7 base units, what is its corresponding ''magnitude''.<br />
<br />
===== Name =====<br />
<br />
String allowing to the user identifying what is the unit system.<br />
<br />
===== Magnitudes =====<br />
<br />
By specifying the magnitude of the 7 base units, a unit system is defined.<br />
<br />
For instance [1e-03, 1e+03, 1, 1, 1, 1, 1], meaning millimeter, tonne, second, ampere, Kelvin, mole, candela<br />
<br />
==== Unit management API ====<br />
<br />
Only the logic of some methods is presented, in order to highlight some features.<br />
These methods could belong to an object called ''Unit manager''.<br />
<br />
===== Checking the unit dictionary =====<br />
<br />
====== isValid ======<br />
<br />
The unit dictionary can be an XML file (FreeCAD configuration file). It contains a list of defined units.<br />
Such a dictionary is required for the proposed unit management system to work.<br />
<br />
It must fulfills some conditions that should be checked before activating the unit management system.<br />
These conditions are:<br />
* check that all base units are defined<br />
* check that a ''dimension'' is not defined twice through the units<br />
* check that a ''symbol'' is not defined twice in all the existing symbols<br />
* check that the ''signatures'' of all units have all the same size<br />
* chacke that a ''standard symbol'' (for which ''magnitude'' is 1) is defined for all units<br />
<br />
====== isCompatibleWithThisSignature ======<br />
<br />
A unit dictionary defines a set of units and their known magnitudes.<br />
When managing a unit, it is relevant to check that its signature is compatible with the set of units registered in the unit dictionary, so as to process it.<br />
This check includes:<br />
* check that the input ''signature'' length is of the same size than the unit dictionary unit ''signatures''<br />
<br />
===== Scaling units =====<br />
<br />
====== scaleUnitFromSymbolToSymbol ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit by its symbol, scale the value.<br />
<br />
====== scaleUnitFromSymbolToUnitSystem ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit system, scale the value.<br />
<br />
====== scaleUnitFromUnitSystemToSymbol ======<br />
<br />
Knowing a value, an initial unit system, the target unit by its symbol, scale the value.<br />
<br />
==== Motivations for such a management: example of application ====<br />
<br />
Let's assume that we are going to setup a finite element model.<br />
To build our model, we need the mesh, material properties, and to define numerical parameters.<br />
Considering that they can be tens of material properties to manage, expressed with different units, sometimes not always very common, it is interesting for the user to only have to specify a global unit system, without caring much.<br />
<br />
FreeCAD would then just do the job.<br />
<br />
As FreeCAD developpers and FreeCAD users do not necessarily know all units that can be defined in the material property files, it is interesting to rely on a generic system.<br />
<br />
Let's assume that in such a file we have a fair number of exotic material properties expressed with exotic units, and that we want to work in a specific unit system.<br />
<br />
It is easy with the proposed extension to scale any of these properties by knowing their signatures, magnitudes, and the target unit system.<br />
<br />
<br />
For each of the properties, the scaling is obtained by multiplying the initial property value with the factor <math>\frac{initialMagnitude}{targetMagnitude}</math>.<br />
<br />
The ''targetMagnitude'' is then simply obtained with the operation <math>\prod_{bu} targetMagnitude_{bu}^{signature_{bu}}</math>, ''bu'' standing for ''base unit''.<br />
<br />
It becomes thus very easy to manage any number of properties with any kind of units with very few lines of Python.<br />
<br />
== Next actions ==<br />
<br />
* Implementing Quantity and Unit classes (mostly done)<br />
* Implementing InputField as User front end (in progress)<br />
* UnitsCalculator as test bed (in progress)<br />
* [[Quantity]] documentation (in progress)<br />
* UnitsCalculator documentation <br />
* Update Material framework to work only with Quantities<br />
* Test Cases<br />
<br />
<br />
{{languages | {{es|Units/es}} {{fr|Units/fr}} {{it|Units/it}} }}<br />
<br />
[[Category:Poweruser Documentation]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Units&diff=102743Units2014-08-03T15:40:21Z<p>Jriegel: /* Examples */</p>
<hr />
<div>Here some reading about units:<br />
*[http://en.wikipedia.org/wiki/International_System_of_Units SI system]<br />
*[http://en.wikipedia.org/wiki/Imperial_units Imperial units]<br />
*[http://en.wikipedia.org/wiki/SI_derived_unit SI derived units]<br />
*[http://en.wikipedia.org/wiki/Degree_%28angle%29 angle units]<br />
<br />
== Examples ==<br />
<br />
# -- some examples of the FreeCAD unit translation system --<br />
# make a shortcut for the examples<br />
tu = FreeCAD.Units.parseQuantity<br />
<br />
# 10 meters in internal numbers<br />
tu('10 m')<br />
# doing math<br />
tu('3/8 in')<br />
# combined stuff<br />
tu('100 km/h')<br />
# transfer to other units<br />
tu('100 km/h')/tu('m/s')<br />
# derived units (Ohm)<br />
tu('m^2*kg*s^-3*A^-2')<br />
# or<br />
tu('(m^2*kg)/(A^2*s^3)')<br />
# angles <br />
tu('2*pi rad') # full circle<br />
# as gon<br />
tu('2*pi rad') / tu('gon')<br />
# more imperial<br />
tu('1ft (3+7/16)in')<br />
# or <br />
tu('1\' (3+7/16)"') # the ' we have to escape because of python<br />
# trigonometry<br />
tu('sin(pi)')<br />
# Using translated units as parameters, this command will create a 50.8mm x 20mm x 10mm box<br />
b = Part.makeBox(tu('2in'),tu('2m')/100,10)<br />
<br />
== Supported units ==<br />
Here the defined units in FreeCAD so far. It's easy to add a new user defined unit. The definition is here[http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Base/UnitsApi.l?view=markup]. <br />
<br />
Metric length<br />
"mm" 1.0; // millimeter (internal standard length)<br />
"m" 1000.0; // meter<br />
"cm" 10.0; // centimeter<br />
"dm" 100.0; // decimeter<br />
"km" 1000000.0; // kilometer<br />
Imperial lenth<br />
"in" "\"" 25.4; // inch<br />
"fo" "'" 304.8; // foot<br />
"th" 0.0254; // thou<br />
"yr" 914.4; // yard<br />
Metric mass<br />
"kg" 1.0; // kilogram (internal standard mass)<br />
"g" 0.001; // gram<br />
"mg" 0.000001; // milligram<br />
"t" 1000.0; // ton <br />
Imperial mass<br />
"lb" 0.45359237; // pound<br />
"oz" 0.45359237; // ounce<br />
"st" 6.35029318; // Stone<br />
"cwt" 50.80234544;// hundredweights<br />
Angle<br />
"deg" 1.0; // degree (internal standard angle)<br />
"rad" 180/M_PI; // radian <br />
"gon" 360.0/400.0;// gon <br />
Time<br />
"s" 1.0; // second (internal standard time)<br />
"min" 60.0; // minute<br />
"h" 3600.0; // hour <br />
Rest of SI<br />
"A" 1.0; // Ampere (internal standard electric current)<br />
"K" 1.0; // Kelvin (internal standard thermodynamic temperature)<br />
"cd" 1.0; // Candela (internal standard luminous intensity) <br />
"mol" 1.0; // Mole (internal standard amount of substance) <br />
Metric Volume<br />
"µl" 1.0; // microliter mm^3(derived standard volume)<br />
"ml" 1000.0; // milliliter cm^3 <br />
"l" 1000000.0; // Liter dm^3<br />
<br />
== Purpose and principles: proposal of an extension of the unit management system ==<br />
<br />
An extension unit management system is proposed in the following sections, developping the concept of ''unit system'', activated during a running FreeCAD instance.<br />
The interest in defining such a new concept is to work more easily with as many type of '''physical''' units as one wants (even user-created ones), without increasing the complexity of unit management for the user, nor for FreeCAD developpers.<br />
<br />
In short, event of unit scaling are localized precisely, and carried out in a generic fashion.<br />
<br />
Achieving such a flexibility is most notably required when one starts to deal with material properties that can have very different units, difficult to manage one by one manually.<br />
<br />
The reasoning proposed allows handling the units such as described in the [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)] both from NIST.<br />
<br />
In this proposal, one first recall in [[Units#Brainstorming|Brainstorming]] section what are the possible contexts for which unit management is required.<br />
<br />
In [[Units#Organizing|Organizing]] section, we present the data model retained to achieve unit management, based on 3 objects, the ''unit'', the ''unit dictionary'', and the ''unit system''.<br />
Finally, a short API of a 4th object called the ''unit manager'' is presented as well.<br />
<br />
== Outcome ==<br />
<br />
Thanks to this extension, one aims to ease unit scaling that can occurs between different business tasks. For instance, technical drawings can be done in standard unit system, while FE modelling can be managed in an unit system more suited for it.<br />
<br />
The exchange of data between these two kind of activities become easier with this extension.<br />
<br />
== Brainstorming ==<br />
<br />
In this section are highlighted the contexts of use of such an unit management system.<br />
From these contexts, we are then able to defined its technical specifications.<br />
<br />
Essentially 2 contexts are given as example.<br />
<br />
=== Context 1: opening a data file ===<br />
<br />
This case is probably the most frequent case.<br />
You receive a file containing for instance a geometrical model, or describing a material with quite a lot of properties. The geometrical model is expressed in meters, or the material properties according the international unit system.<br />
<br />
Too bad...<br />
<br />
You are an expert FE modelling, and you usually work with millimeter for length, MegaPascal for stress, tonne for mass...<br />
<br />
In this context, unit management is required to scale data from an initial unit system defined in the input file to a user-defined target unit system.<br />
<br />
=== Context 2: switching the unit system at runtime ===<br />
<br />
In this case, you can be at the same time the guy that carries out a drawing, and the guy that will manage the FE modelling. Similarly to the previous case, the unit systems for these 2 tasks are not the same, and you need to switch the initial unit system at runtime to your favorite one.<br />
<br />
== Organizing ==<br />
<br />
=== Logic of unit scaling ===<br />
<br />
In the [[Units#Brainstorming|Brainstorming]] section have been presented 2 contexts when using unit scaling.<br />
Some items should be highlighted from these two contexts.<br />
<br />
==== Unit coherence throughout the FreeCAD running instance ====<br />
<br />
The system proposed is based on a primary assumption: the user is working in a coherent unit system.<br />
For instance, this means that if the user expresses length in millimeters, necessarily areras will be expressed in terms of squared millimeters, not squared meters.<br />
This is '''hypothesis one'''.<br />
<br />
==== Unit system ====<br />
<br />
Because of ''hypothesis one'', it is possible and relevant to define an unit system.<br />
An unit system applies to:<br />
* a running FreeCAD instance into which you are working<br />
* or it may also apply globally to the content of an input file<br />
According [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] from NIST, they are 7 physical base units.<br />
We chose to express a unit system in terms of these 7 base units.<br />
<br />
When working within an instance of FreeCAD, the user has thus to define first the unit system according to which she/he is working before she/he decides to switch to another unit system, or before importing data from an input file.<br />
<br />
This unit system will apply till the user decides to change it. If she/he does, all data with dimensions will be scaled.<br />
<br />
Considering ''hypothesis one'', all data that the user will input manually in FreeCAD are assumed to be coherent with the chosen unit system.<br />
<br />
The benefit to work with a ''unit system'' defined at a FreeCAD running instance level, or at data file level (instead of ''unit'' which are defined at the data level) is then that unit management is considerably simplified.<br />
<br />
Here are some examples of unit systems.<br />
* meter, kilogram, second, ampere, Kelvin, mole, candela<br />
* millimeter, tonne, millisecond, ampere, Kelvin, mole, candela<br />
* millimeter, kilogramme, millisecond, ampere, Kelvin, mole, candela<br />
*...<br />
<br />
==== Base and derived units ====<br />
<br />
Derived units are created by combination of base units. For instance, an acceleration (m/s) combines at the same time length and time. An interesting picture presenting the relationships between base and derived units can be seen [http://physics.nist.gov/cuu/pdf/SIDiagramColorAnnot.pdf here] also from NIST.<br />
<br />
Thanks to the definition of ''unit system'', it is possible for the user to work with any kind of derived units, without the need for FreeCAD developpers to foresee them in advance.<br />
<br />
==== Base and derived unit symbols ====<br />
<br />
According to [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)], the symbols to specify a units are officially approved. Two consequences can be highlighted from this.<br />
* it is not easy for a computer program to work with unit symbols because some are greek letters for instance. Hence they can be a bit difficult to process by a program<br />
* while some units and their symbols can be used widely, they may be not approved officially, like for instance ''tonne'' unit (see p32 of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)])<br />
<br />
To overcome these limitations and remain flexible, the proposed system favors the use of unit magnitudes instead of unit symbols, which remain nonetheless available for an ergonomy reason.<br />
<br />
=== Data model ===<br />
<br />
The three core objects of the unit management system are presented, namely the ''unit'', the ''unit dictionary'' and the ''unit system''.<br />
<br />
==== Unit ====<br />
<br />
As a foreword, it is important to highlight that a ''unit'' object in itself only indicates a '''dimension''' like length, mass, time... It doesn't specify a '''magnitude''' like meter, millimeter, kilometer... This last information is specified through the unit system.<br />
<br />
===== Dimension =====<br />
<br />
Compulsory string indicating the ''dimension'' of the unit. The ''dimension'' of the 7 base units are indicated below (from [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)]).<br />
* LENGTH<br />
* MASS<br />
* TIME<br />
* ELECTRIC CURRENT<br />
* THERMODYNAMIC TEMPERATURE<br />
* AMOUNT OF SUBSTANCE<br />
* LUMINOUS INTENSITY<br />
<br />
''Dimension'' attribute allows identifying the unit.<br />
Two units cannot share the same ''dimension''.<br />
<br />
===== Signature =====<br />
<br />
Compulsory integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
''Signature'' is the attribute thanks to which unit scaling can be achieved in a generic way.<br />
<br />
===== Symbols =====<br />
<br />
Array of [real, string] (meaning [''magnitude'', ''symbol'']) that lists all ''symbols'' known by FreeCAD.<br />
Thanks to this array, the unit scaling API becomes more ergonomic because ''symbols'' and related ''magnitudes'' are linked.<br />
<br />
This array can be extended as required.<br />
<br />
For instance, the list of ''symbols'' of the LENGTH unit, and their related ''magnitudes'' is:<br />
<br />
[1e+12,"Tm"],[1e+09,"Gm"],[1e+06,"Mm"],<br />
[1e+03,"km"],[1e+02,"hm"],[1e+01,"dam"],<br />
[1e+00,"m"],[1e-01,"dm"],[1e-02,"cm"],<br />
[1e-03,"mm"],[1e-06,"µm"],[1e-09,"nm"],<br />
[1e-12,"pm"],[1e-15,"fm"]<br />
<br />
Standard ''symbols'' can be found on [http://physics.nist.gov/cuu/Units/units.html NIST website] and p23 to 26 and p32 (''metric ton'' or ''tonne'') of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)].<br />
<br />
==== Unit dictionary ====<br />
<br />
All the units available in FreeCAD, and new ones created by the user, should be stored in ''unit dictionary'', which is an XML file (FreeCAD configuration file), so as to be retrieved when needed, i.e. when achieving unit scaling.<br />
<br />
===== Units =====<br />
<br />
Array of units, contained in the ''unit dictionary''.<br />
<br />
==== Unit system ====<br />
<br />
A ''unit system'' is the object that allows the user defining the current unit ''magnitude'' of each base units with which she/he is working.<br />
For instance, knowing that the user is working with millimeter, tonne, and second, thanks to the use of a unit system, FreeCAD can know that energy is expressed in terms of milliJoule, force in terms of Newton, and stress in terms of MegaPascal.<br />
Hence a unit system is only defined by a ''name'' (for instance ''Standard unit system'') and a ''magnitude table'' specifying for each of the 7 base units, what is its corresponding ''magnitude''.<br />
<br />
===== Name =====<br />
<br />
String allowing to the user identifying what is the unit system.<br />
<br />
===== Magnitudes =====<br />
<br />
By specifying the magnitude of the 7 base units, a unit system is defined.<br />
<br />
For instance [1e-03, 1e+03, 1, 1, 1, 1, 1], meaning millimeter, tonne, second, ampere, Kelvin, mole, candela<br />
<br />
==== Unit management API ====<br />
<br />
Only the logic of some methods is presented, in order to highlight some features.<br />
These methods could belong to an object called ''Unit manager''.<br />
<br />
===== Checking the unit dictionary =====<br />
<br />
====== isValid ======<br />
<br />
The unit dictionary can be an XML file (FreeCAD configuration file). It contains a list of defined units.<br />
Such a dictionary is required for the proposed unit management system to work.<br />
<br />
It must fulfills some conditions that should be checked before activating the unit management system.<br />
These conditions are:<br />
* check that all base units are defined<br />
* check that a ''dimension'' is not defined twice through the units<br />
* check that a ''symbol'' is not defined twice in all the existing symbols<br />
* check that the ''signatures'' of all units have all the same size<br />
* chacke that a ''standard symbol'' (for which ''magnitude'' is 1) is defined for all units<br />
<br />
====== isCompatibleWithThisSignature ======<br />
<br />
A unit dictionary defines a set of units and their known magnitudes.<br />
When managing a unit, it is relevant to check that its signature is compatible with the set of units registered in the unit dictionary, so as to process it.<br />
This check includes:<br />
* check that the input ''signature'' length is of the same size than the unit dictionary unit ''signatures''<br />
<br />
===== Scaling units =====<br />
<br />
====== scaleUnitFromSymbolToSymbol ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit by its symbol, scale the value.<br />
<br />
====== scaleUnitFromSymbolToUnitSystem ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit system, scale the value.<br />
<br />
====== scaleUnitFromUnitSystemToSymbol ======<br />
<br />
Knowing a value, an initial unit system, the target unit by its symbol, scale the value.<br />
<br />
==== Motivations for such a management: example of application ====<br />
<br />
Let's assume that we are going to setup a finite element model.<br />
To build our model, we need the mesh, material properties, and to define numerical parameters.<br />
Considering that they can be tens of material properties to manage, expressed with different units, sometimes not always very common, it is interesting for the user to only have to specify a global unit system, without caring much.<br />
<br />
FreeCAD would then just do the job.<br />
<br />
As FreeCAD developpers and FreeCAD users do not necessarily know all units that can be defined in the material property files, it is interesting to rely on a generic system.<br />
<br />
Let's assume that in such a file we have a fair number of exotic material properties expressed with exotic units, and that we want to work in a specific unit system.<br />
<br />
It is easy with the proposed extension to scale any of these properties by knowing their signatures, magnitudes, and the target unit system.<br />
<br />
<br />
For each of the properties, the scaling is obtained by multiplying the initial property value with the factor <math>\frac{initialMagnitude}{targetMagnitude}</math>.<br />
<br />
The ''targetMagnitude'' is then simply obtained with the operation <math>\prod_{bu} targetMagnitude_{bu}^{signature_{bu}}</math>, ''bu'' standing for ''base unit''.<br />
<br />
It becomes thus very easy to manage any number of properties with any kind of units with very few lines of Python.<br />
<br />
== Next actions ==<br />
<br />
* Implementing Quantity and Unit classes (mostly done)<br />
* Implementing InputField as User front end (in progress)<br />
* UnitsCalculator as test bed (in progress)<br />
* [[Quantity]] documentation (in progress)<br />
* UnitsCalculator documentation <br />
* Update Material framework to work only with Quantities<br />
* Test Cases<br />
<br />
<br />
{{languages | {{es|Units/es}} {{fr|Units/fr}} {{it|Units/it}} }}<br />
<br />
[[Category:Poweruser Documentation]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=MIBA&diff=60143MIBA2014-01-08T06:05:49Z<p>Jriegel: /* Making Miba pictures by script */</p>
<hr />
<div>== Introduction ==<br />
<br />
Miba is a way to embed information about the 3D space into a 2D image. This makes it often possible to use the 2D picture instead of a 3D viewer. By the Miba information you're able to calculate the position of a 3D location in the 2D image. That allows you to decorate the image later with arbitrary 3D information. You can take the picture in an early state (design) and use it later (e.g. Production). You do not need to know the kind of 3D data or the positions when you take the picture. So the picture is completely separated from the 3D data.<br />
<br />
A detailed specification you can find here: http://miba.juergen-riegel.net/<br />
<br />
== Miba in FreeCAD ==<br />
<br />
If you choose a file format which has an comment ability ( JPG and PNG) you can choose to write a comment or insert the MIBA information in the comment fileds (default):<br />
<br />
[[Image:Save_picture.png]]<br />
<br />
== Making Miba pictures by script ==<br />
<br />
<br />
import Part,PartGui<br />
# loading test part<br />
Part.open("C:/Documents and Settings/jriegel/My Documents/Projects/FreeCAD/data/Blade.stp")<br />
OutDir = 'c:/temp/'<br />
Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)<br />
<br />
# creating images with different Views, Cameras and sizes<br />
for p in ["PerspectiveCamera","OrthographicCamera"]:<br />
Gui.SendMsgToActiveView(p)<br />
for f in ["ViewAxo","ViewFront","ViewTop"]:<br />
Gui.SendMsgToActiveView(f)<br />
for x,y in [[500,500],[1000,3000],[3000,1000],[3000,3000],[8000,8000]]:<br />
Gui.ActiveDocument.ActiveView.saveImage(OutDir + "Blade_" + p +"_" + f + "_" + `x` + "_" + `y` + ".jpg",x,y,"White")<br />
Gui.ActiveDocument.ActiveView.saveImage(OutDir + "Blade_" + p +"_" + f + "_" + `x` + "_" + `y` + ".png",x,y,"Transparent")<br />
<br />
# close active document<br />
App.closeDocument(App.ActiveDocument.Name)<br />
<br />
{{languages | {{es|MIBA/es}} {{fr|MIBA/fr}} {{it|MIBA/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=MIBA&diff=60142MIBA2014-01-08T06:05:35Z<p>Jriegel: /* Making Miba pictures by script */</p>
<hr />
<div>== Introduction ==<br />
<br />
Miba is a way to embed information about the 3D space into a 2D image. This makes it often possible to use the 2D picture instead of a 3D viewer. By the Miba information you're able to calculate the position of a 3D location in the 2D image. That allows you to decorate the image later with arbitrary 3D information. You can take the picture in an early state (design) and use it later (e.g. Production). You do not need to know the kind of 3D data or the positions when you take the picture. So the picture is completely separated from the 3D data.<br />
<br />
A detailed specification you can find here: http://miba.juergen-riegel.net/<br />
<br />
== Miba in FreeCAD ==<br />
<br />
If you choose a file format which has an comment ability ( JPG and PNG) you can choose to write a comment or insert the MIBA information in the comment fileds (default):<br />
<br />
[[Image:Save_picture.png]]<br />
<br />
== Making Miba pictures by script ==<br />
<br />
<br />
import Part,PartGui<br />
# loading test part<br />
Part.open("C:/Documents and Settings/jriegel/My Documents/Projects/FreeCAD/data/Blade.stp")<br />
OutDir = 'c:/temp/'<br />
Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)<br />
<br />
# creating images with different Views, Cameras and sizes<br />
for p in ["PerspectiveCamera","OrthographicCamera"]:<br />
Gui.SendMsgToActiveView(p)<br />
for f in ["ViewAxo","ViewFront","ViewTop"]:<br />
Gui.SendMsgToActiveView(f)<br />
for x,y in [[500,500],[1000,3000],[3000,1000],[3000,3000],[8000,8000]]:<br />
Gui.ActiveDocument.ActiveView.saveImage(OutDir + "Blade_" + p +"_" + f + "_" + `x` + "_" + `y` + ".jpg",x,y,"White")<br />
Gui.ActiveDocument.ActiveView.saveImage(OutDir + "Blade_" + p +"_" + f + "_" + `x` + "_" + `y` + ".png",x,y,"Transparent")<br />
<br />
# close active document<br />
App.closeDocument(App.ActiveDocument.Name)<br />
<br />
{{languages | {{es|MIBA/es}} {{fr|MIBA/fr}} {{it|MIBA/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=InputField&diff=55663InputField2013-12-16T08:17:41Z<p>Jriegel: Created page with "This is the documentation of the FreeCAD 'InputField' widgets, which get used in most of the dialogs handling parameter with units. ToDo..."</p>
<hr />
<div>This is the documentation of the FreeCAD 'InputField' widgets, which get used in most of the dialogs handling parameter with units.<br />
<br />
ToDo...</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=55662Quantity2013-12-16T08:16:05Z<p>Jriegel: /* InputField */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== General ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
=== Supported units === <br />
<br />
The FreeCAD input parser supports a bunch of units and units-systmes. We do use the Greek letter for micro but also accept 'u' as a replacement.<br />
<br />
* Length<br />
** "nm" <br />
** "µm" <br />
** "mm" <br />
** "cm" <br />
** "dm" <br />
** "m" <br />
** "km" <br />
** "in" <br />
** "ft" <br />
** "thou"<br />
** "mil" <br />
** "yd" <br />
** "mi" <br />
<br />
Todo: all the rest...<br />
<br />
<br />
The detailed specification you find in the code:<br />
* Quantity lexer: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/QuantityParser.l <br />
* Quantity definitions: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/Quantity.cpp#l167<br />
<br />
== Internal representation ==<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Main docu: [[InputField]]<br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of a string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=54735Quantity2013-12-12T19:17:17Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== General ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
=== Supported units === <br />
<br />
The FreeCAD input parser supports a bunch of units and units-systmes. We do use the Greek letter for micro but also accept 'u' as a replacement.<br />
<br />
* Length<br />
** "nm" <br />
** "µm" <br />
** "mm" <br />
** "cm" <br />
** "dm" <br />
** "m" <br />
** "km" <br />
** "in" <br />
** "ft" <br />
** "thou"<br />
** "mil" <br />
** "yd" <br />
** "mi" <br />
<br />
Todo: all the rest...<br />
<br />
<br />
The detailed specification you find in the code:<br />
* Quantity lexer: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/QuantityParser.l <br />
* Quantity definitions: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/Quantity.cpp#l167<br />
<br />
== Internal representation ==<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of a string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=54349Quantity2013-12-11T10:41:45Z<p>Jriegel: /* Supported units */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== General ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
=== Supported units === <br />
<br />
The FreeCAD input parser supports a bunch of units and units-systmes. We do use the Greek letter for micro but also accept 'u' as a replacement.<br />
<br />
* Length<br />
** "nm" <br />
** "µm" <br />
** "mm" <br />
** "cm" <br />
** "dm" <br />
** "m" <br />
** "km" <br />
** "in" <br />
** "ft" <br />
** "thou"<br />
** "mil" <br />
** "yd" <br />
** "mi" <br />
<br />
Todo: all the rest...<br />
<br />
<br />
The detailed specification you find in the code:<br />
* Quantity lexer: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/QuantityParser.l <br />
* Quantity definitions: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/Quantity.cpp#l167<br />
<br />
== Internal representation ==<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of a string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Development_roadmap&diff=54347Development roadmap2013-12-11T06:49:55Z<p>Jriegel: /* Current projects */</p>
<hr />
<div>FreeCAD - though usable in many applications - is at the beginning of a long journey into CAD mainstream. There is still a lot to do to reach a state where we can compete with commercial software. <br />
<br />
This section gives an overview of what is planned and gives you the opportunity to participate or give your opinion. As we are volunteers to FreeCAD we have only a certain amount of time. So if you interested in one of the topics and willing to help, just let us know! We use the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] style for the project document. Here is the [[Project template]].<br />
<br />
* The [[Organization chart]] shows who does what in the FreeCAD universe.<br />
* You can follow issues that are currently being worked on via the bugtracker here: http://www.freecadweb.org/tracker/roadmap_page.php<br />
<br />
== Projects ==<br />
<br />
=== Current projects ===<br />
These are work in progress.<br />
<br />
* '''[[STEP project]]''' about improving and advancing the STEP support in FreeCAD<br />
* '''[[Naming project]]''' is about implementing a robust Shape referencing frame work. <br />
* '''[[FreeCAD development model project]]''' move FreeCAD to a more capable development model <br />
* '''[[Sketcher project]]''' is ongoing implementation of the constraint/parametric Sketcher<br />
* '''[[PartDesign project]]''' is the effort towards a working part-design in FreeCAD <br />
* '''[[Assembly project]]''' creates a assembly module which handle product creation, part-lists and some kinematics.<br />
* '''[[Arch Concept|Architecture project]]''' will throw the bases of a modern, parametric architectural modeling environment.<br />
* '''[[Units project]]''' finally get FreeCAD to recognize different Units and Units-systems.<br />
* '''[[Resource framework project]]''' address the user collaboration, [http://en.wikipedia.org/wiki/Product_Data_Management PDM] catalog/standard part stuff<br />
* '''[[Quality project]]''' aims to hide unfinished features and improve the documentation.<br />
* '''[[Raytracing project]]''' provide a new generic interface for external renderers for visualisation<br />
* '''[[UTF Project]]''' aims to update FreeCAD's Coin3D interface to utilise UTF Strings for better multilanguage experience with non ASCII characters<br />
<br />
=== Future projects ===<br />
Projects for the near future.<br />
<br />
* '''[[Material data model]]''' Effort to describe a material data model in FreeCAD<br />
* '''[[FEM project]]''' wants to create a [http://en.wikipedia.org/wiki/Finite_element_method FEM] module in FreeCAD.<br />
* '''[[CAM project]]''' will make the existing [http://en.wikipedia.org/wiki/Computer-aided_manufacturing CAM] stuff in FreeCAD usable.<br />
<br />
<br />
=== So far finished projects ===<br />
* '''[[Robot project]]''' A Robot simulation workbench<br />
<br />
=== Ideas ===<br />
<br />
== Release schedule ==<br />
Like in the most [http://en.wikipedia.org/wiki/FLOSS FLOSS] projects a release schedule is very rough. There will be no fixed dates and '''"It's done, when it's done!"'''<br />
<br />
[[Category:Roadmap]]<br />
<br />
{{languages | {{es|Development_roadmap/es}} {{fr|Development_roadmap/fr}} {{it|Development_roadmap/it}} {{se|Development_roadmap/se}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=52915Quantity2013-12-08T11:02:46Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== General ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
=== Supported units === <br />
<br />
The FreeCAD input parser supports a bunch of units and units-systmes. We do not use the Greek letter for micro. Instead we use y and ignore yocto. <br />
<br />
* Length<br />
** "nm" <br />
** "ym" <br />
** "mm" <br />
** "cm" <br />
** "dm" <br />
** "m" <br />
** "km" <br />
** "in" <br />
** "ft" <br />
** "thou"<br />
** "mil" <br />
** "yd" <br />
** "mi" <br />
<br />
Todo<br />
<br />
<br />
The detailed specification you find in the code:<br />
* Quantity lexer: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/QuantityParser.l <br />
* Quantity definitions: http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/Quantity.cpp#l167<br />
<br />
== Internal representation ==<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of a string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=52914Quantity2013-12-08T10:11:57Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of a string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=52862Quantity2013-12-08T09:14:28Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1ft 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 ft') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 ft')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51639Quantity2013-12-06T18:05:12Z<p>Jriegel: /* Parser supported Units */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yd" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51346Quantity2013-12-06T12:55:19Z<p>Jriegel: /* Parser supported Units */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51345Quantity2013-12-06T12:39:24Z<p>Jriegel: /* User facing values */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
The code for the schema translation you can see here:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaInternal.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaMKS.cpp<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Base/UnitsSchemaImperial1.cpp<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51344Quantity2013-12-06T12:35:38Z<p>Jriegel: /* InputField */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51343Quantity2013-12-06T12:35:19Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== InputField ==<br />
The InputField is a QLineEdit derived Qt widget to handle all kind of user interaction with Quantities and parameters. It features following properties:<br />
* parsing arbitrary value/unit input<br />
* checking on the right unit (if given) and give the user feedback<br />
* special context menu for operations on Quantities/Values<br />
* history management (save the last used values)<br />
* save often needed values as shortcut in context menu<br />
* dialing values with mouse wheel and arrow keys (tbd)<br />
* dialing with middle mouse button and mouse move (tbd)<br />
* python integration for usage in python only dialogs (tbd)<br />
<br />
The UnitsCalculator uses the InputField already. <br />
<br />
Code:<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.h<br />
* http://sourceforge.net/p/free-cad/code/ci/master/tree/src/Gui/InputField.cpp<br />
<br />
<br />
<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51342Quantity2013-12-06T12:19:01Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# You can using a point or comma as float delimiter<br />
Quantity('1,0 m') <br />
Quantity('1.0 m') <br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51341Quantity2013-12-06T12:15:17Z<p>Jriegel: /* User facing values */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
</source><br />
<br />
This does the job if you only need a string. But somethimes you need more control, e.g. if you want to have a dialog button which dial up and down. Then you need more information about the translation output. There fore the getUserPrefered() method of quantity is used:<br />
<br />
<source lang="python"><br />
Quantity('22 m').getUserPrefered() # gets a tubple:('22 m', 1000.0, 'm')<br />
Quantity('2 m').getUserPrefered() # Tuple: ('2000 mm', 1.0, 'mm')<br />
</source><br />
<br />
Here you get two more informations as a tuple of size 3. You get the string as before, plus the factor the number is translated and the raw string with only the unit chosen by the translation schema. With this information you can implement a much richer user interaction.<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51338Quantity2013-12-05T23:04:00Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 fo^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
<br />
<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51337Quantity2013-12-05T23:01:21Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
=== User facing values ===<br />
Normally in script you can use Quantity for all kind of calculation and checking, but there comes the time you have to output information to the user. You could use getValueAs() to force a certain unit, but normally the user sets his preferred unit-schema in the preferences. This unit-schema do all the translations to the representation the user likes to see. At the moment there are 3 schema implemented:<br />
* 1: Internal (mm/kg/s) <br />
* 2: MKS (m/kg/s)<br />
* 3: US customary (in/lb) <br />
There can be easily additional schemas implemented in the future...<br />
<br />
The quantity class has two possibilities to use the actual schema translation:<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# Use the translated string:<br />
Quantity('1m').UserString # '1000 mm' in 1; '1 m' in 2; and '1.09361 yr' in 3<br />
<br />
<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51336Quantity2013-12-05T22:41:27Z<p>Jriegel: /* Quantity */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
# and for sure calculation and comparison<br />
Quantity('1 Pa')* Quantity(2.0) == Quantity('2 Pa')<br />
Quantity('1 m')* Quantity('2 m') == Quantity('2 m^2')<br />
Quantity('1 m')* Quantity('2 fo') + Quantity('2 mm^2')<br />
Quantity('1 m') > Quantity('2 fo')<br />
<br />
# accessing the components<br />
Quantity('1 m').Value # get the number (allways internal system (mm/kg/s)<br />
Quantity('1 m').Unit # get the unit<br />
Quantity('1 m') == Quantity( Quantity('1 m').Value , Quantity('1 m').Unit )<br />
<br />
# translating the value into other units then the internal system (mm/kg/s)<br />
Quantity('1 km/h').getValueAs('m/s') # translate value<br />
Quantity('1 m').getValueAs(2.45,1) # translation value and unit signature<br />
Quantity('1 kPa').getValueAs(FreeCAD.Units.Pascal) # predefined standard units <br />
Quantity('1 MPa').getValueAs(Quantity('N/m^2')) # a quantity<br />
<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51335Quantity2013-12-05T22:13:12Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
<br />
</source><br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51334Quantity2013-12-05T22:12:50Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
The Unit is mainly used to descripe a certain unit-type for a parameter. There fore a special Property Type in FreeCAD can transport a Unit to check and ensure the right Unit. <br />
A Unit and a float value is called Quantity.<br />
<br />
=== Quantity ===<br />
<source lang="python"><br />
from Units import Unit,Quantity<br />
<br />
# to create a quantity you need a value (float) and a Unit<br />
Quantity(1.0,Unit(0,1)) # Mass 1.0 kg<br />
Quantity(1.0,Unit(1)) # Length 1.0 mm<br />
Quantity(1.0,Unit(-1,1,-2)) # Pressure 1.0 kg/mm*s^2<br />
Quantity(1.0,FreeCAD.Units.Pressure) # Pressure 1.0 kg/mm*s^2<br />
<br />
# you can directly give a signature<br />
Quantity(1.0,0,1) # Mass 1.0 kg<br />
Quantity(1.0,1) # Length 1.0 mm<br />
Quantity(1.0,-1,1,-2) # Pressure 1.0 kg/mm*s^2<br />
<br />
# parsing Quantitis out of an string<br />
Quantity('1.0 kg/(m*s^2)') # Pressure<br />
Quantity('1.0 Pa') # the same as combined Unit Pascale<br />
Quantity('1.0 J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Quantity('1.0 psi') # Imperial pressure<br />
Quantity('1.0 lb') # Mass<br />
Quantity('1.0 ft^2') <br />
<br />
# the quantity parser can do calculations too<br />
Quantity('360/5 deg') # splitting circle <br />
Quantity('1/16 in') # fractions<br />
Quantity('5.3*6.3 m^2') # calculating an area<br />
Quantity('1/(log(2.3)/sin(pi)*3.4)+1.8e-3 m')<br />
Quantity('1fo 3in') # imperial style<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=51019Quantity2013-12-05T20:40:49Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)') # Pressure<br />
Unit('Pa') # the same as combined Unit Pascale<br />
Unit('J') # Joul (Work,Energy) mm^2*kg/(s^2)<br />
<br />
# you can use units from all supported unit-systems<br />
Unit('psi') # Imperial pressure<br />
Unit('lb') # Mass<br />
Unit('ft^2') # Area<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50985Quantity2013-12-05T20:23:03Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
The Unit and Quantity system in FreeCAD is (as nearly everything) fully accessibly via Python. <br />
<br />
=== Unit ===<br />
The Unit class represents the Fingerprint of any physical unit. As descriped in the Basics section a vector of 8 numbers is used to represent this fingerprint. The Unit class allows the handling and calculation with this information. <br />
<br />
<source lang="python"><br />
from Units import Unit<br />
<br />
# creating a Unit with certain signature<br />
Unit(0,1) # Mass (kg)<br />
Unit(1) # Length (mm)<br />
Unit(-1,1,-2) # Pressure (kg/mm*s^2)<br />
<br />
# using predefined constats<br />
Unit(FreeCAD.Units.Length)<br />
Unit(FreeCAD.Units.Mass)<br />
Unit(FreeCAD.Units.Pressure)<br />
<br />
# parsing unit out of an string<br />
Unit('kg/(m*s^2)')<br />
<br />
# comparing units<br />
Unit(0,1) == Unit(FreeCAD.Units.Mass)<br />
<br />
# getting type of unit<br />
Unit('kg/(m*s^2)').Type == 'Pressure'<br />
<br />
# calculating<br />
Unit('kg') * Unit('m^-1*s^-2') == Unit('kg/(m*s^2)')<br />
<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Mesh_Scripting&diff=50944Mesh Scripting2013-12-05T18:57:57Z<p>Jriegel: </p>
<hr />
<div>=== Introduction ===<br />
<br />
First of all you have to import the Mesh module:<br />
<source lang="python"><br />
import Mesh<br />
</source><br />
After that you have access to the Mesh module and the Mesh class which facilitate the functions<br />
of the FreeCAD C++ Mesh-Kernel.<br />
<br />
=== Creation and Loading === <br />
<br />
To create an empty mesh object just use the standard constructor:<br />
<br />
<source lang="python"><br />
mesh = Mesh.Mesh()<br />
</source ><br />
<br />
You can also create an object from a file<br />
<br />
<source lang="python"><br />
mesh = Mesh.Mesh('D:/temp/Something.stl')<br />
</source ><br />
<br />
(A list of compatible filetypes can be found under 'Meshes' [[Feature_list#IO|here]].)<br />
<br />
Or create it out of a set of triangles described by their corner points:<br />
<br />
<source lang="python"><br />
planarMesh = [<br />
# triangle 1<br />
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],<br />
#triangle 2<br />
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],<br />
]<br />
planarMeshObject = Mesh.Mesh(planarMesh)<br />
</source ><br />
<br />
The Mesh-Kernel takes care about creating a topological correct data structure by sorting<br />
coincident points and edges together. <br />
<br />
Later on you will see how you can test and examine mesh data.<br />
<br />
=== Modeling === <br />
<br />
To create regular geometries you can use the Python script BuildRegularGeoms.py.<br />
<br />
<source lang="python"><br />
import BuildRegularGeoms<br />
</source><br />
<br />
This script provides methods to define simple rotation bodies like spheres, ellipsoids, cylinders, toroids and cones. And it also has a method to create a simple cube.<br />
To create a toroid, for instance, can be done as follows:<br />
<br />
<source lang="python"><br />
t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br />
m = Mesh.Mesh(t)<br />
</source><br />
<br />
The first two parameters define the radiuses of the toroid and the third parameter is a sub-sampling factor for how many triangles are created. The higher this value the smoother and the lower the coarser the body is.<br />
The Mesh class provides a set of boolean functions that can be used for modeling purposes. It provides union, intersection and difference of two mesh objects.<br />
<source lang="python"><br />
m1, m2 # are the input mesh objects<br />
m3 = Mesh.Mesh(m1) # create a copy of m1<br />
m3.unite(m2) # union of m1 and m2, the result is stored in m3<br />
m4 = Mesh.Mesh(m1)<br />
m4.intersect(m2) # intersection of m1 and m2<br />
m5 = Mesh.Mesh(m1)<br />
m5.difference(m2) # the difference of m1 and m2<br />
m6 = Mesh.Mesh(m2)<br />
m6.difference(m1) # the difference of m2 and m1, usually the result is different to m5<br />
Finally, a full example that computes the intersection between a sphere and a cylinder that intersects the sphere.<br />
import Mesh, BuildRegularGeoms<br />
sphere = Mesh.Mesh( BuildRegularGeoms.Sphere(5.0, 50) )<br />
cylinder = Mesh.Mesh( BuildRegularGeoms.Cylinder(2.0, 10.0, True, 1.0, 50) )<br />
diff = sphere<br />
diff.difference(cylinder)<br />
d = FreeCAD.newDocument()<br />
d.addObject("Mesh::Feature","Diff_Sphere_Cylinder").Mesh=diff<br />
d.recompute()<br />
</source><br />
<br />
=== Examining and Testing === <br />
<br />
=== Write your own Algorithms === <br />
<br />
=== Exporting === <br />
<br />
You can even write the mesh to a python module:<br />
<br />
<source lang="python"><br />
m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")<br />
import SavedMesh<br />
m2 = Mesh.Mesh(SavedMesh.faces)<br />
</source><br />
<br />
=== Gui related stuff === <br />
<br />
=== Odds and Ends === <br />
An extensive (though hard to use) source of Mesh related scripting are the unit test scripts of the Mesh-Module. <br />
In this unit tests literally all methods are called and all properties/attributes are tweaked.<br />
So if you are bold enough, take a look at the [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/App/MeshTestsApp.py?view=markup Unit Test module].<br />
<br />
{{docnav|FreeCAD Scripting Basics|Topological data scripting}}<br />
<br />
{{languages | {{cn|Mesh Scripting/cn}} {{de|Mesh Scripting/de}} {{es|Mesh Scripting/es}} {{fr|Mesh Scripting/fr}} {{it|Mesh Scripting/it}} {{jp|Mesh Scripting/jp}} {{ru|Mesh Scripting/ru}} {{se|Mesh Scripting/se}} }}<br />
<br />
[[Category:Poweruser Documentation]]<br />
[[Category:Python Code]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Mesh_Scripting&diff=50943Mesh Scripting2013-12-05T18:57:06Z<p>Jriegel: /* Introduction */</p>
<hr />
<div>=== Introduction ===<br />
<br />
First of all you have to import the Mesh module:<br />
<source lang="python"><br />
import Mesh<br />
</source><br />
After that you have access to the Mesh module and the Mesh class which facilitate the functions<br />
of the FreeCAD C++ Mesh-Kernel.<br />
<br />
=== Creation and Loading === <br />
<br />
To create an empty mesh object just use the standard constructor:<br />
mesh = Mesh.Mesh()<br />
You can also create an object from a file<br />
mesh = Mesh.Mesh('D:/temp/Something.stl')<br />
(A list of compatible filetypes can be found under 'Meshes' [[Feature_list#IO|here]].)<br />
<br />
Or create it out of a set of triangles described by their corner points:<br />
<br />
<source lang="python"><br />
planarMesh = [<br />
# triangle 1<br />
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],<br />
#triangle 2<br />
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],<br />
]<br />
planarMeshObject = Mesh.Mesh(planarMesh)<br />
</source ><br />
<br />
The Mesh-Kernel takes care about creating a topological correct data structure by sorting<br />
coincident points and edges together. <br />
<br />
Later on you will see how you can test and examine mesh data.<br />
<br />
=== Modeling === <br />
<br />
To create regular geometries you can use the Python script BuildRegularGeoms.py.<br />
<br />
<source lang="python"><br />
import BuildRegularGeoms<br />
</source><br />
<br />
This script provides methods to define simple rotation bodies like spheres, ellipsoids, cylinders, toroids and cones. And it also has a method to create a simple cube.<br />
To create a toroid, for instance, can be done as follows:<br />
<br />
<source lang="python"><br />
t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br />
m = Mesh.Mesh(t)<br />
</source><br />
<br />
The first two parameters define the radiuses of the toroid and the third parameter is a sub-sampling factor for how many triangles are created. The higher this value the smoother and the lower the coarser the body is.<br />
The Mesh class provides a set of boolean functions that can be used for modeling purposes. It provides union, intersection and difference of two mesh objects.<br />
<source lang="python"><br />
m1, m2 # are the input mesh objects<br />
m3 = Mesh.Mesh(m1) # create a copy of m1<br />
m3.unite(m2) # union of m1 and m2, the result is stored in m3<br />
m4 = Mesh.Mesh(m1)<br />
m4.intersect(m2) # intersection of m1 and m2<br />
m5 = Mesh.Mesh(m1)<br />
m5.difference(m2) # the difference of m1 and m2<br />
m6 = Mesh.Mesh(m2)<br />
m6.difference(m1) # the difference of m2 and m1, usually the result is different to m5<br />
Finally, a full example that computes the intersection between a sphere and a cylinder that intersects the sphere.<br />
import Mesh, BuildRegularGeoms<br />
sphere = Mesh.Mesh( BuildRegularGeoms.Sphere(5.0, 50) )<br />
cylinder = Mesh.Mesh( BuildRegularGeoms.Cylinder(2.0, 10.0, True, 1.0, 50) )<br />
diff = sphere<br />
diff.difference(cylinder)<br />
d = FreeCAD.newDocument()<br />
d.addObject("Mesh::Feature","Diff_Sphere_Cylinder").Mesh=diff<br />
d.recompute()<br />
</source><br />
<br />
=== Examining and Testing === <br />
<br />
=== Write your own Algorithms === <br />
<br />
=== Exporting === <br />
<br />
You can even write the mesh to a python module:<br />
<br />
<source lang="python"><br />
m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")<br />
import SavedMesh<br />
m2 = Mesh.Mesh(SavedMesh.faces)<br />
</source><br />
<br />
=== Gui related stuff === <br />
<br />
=== Odds and Ends === <br />
An extensive (though hard to use) source of Mesh related scripting are the unit test scripts of the Mesh-Module. <br />
In this unit tests literally all methods are called and all properties/attributes are tweaked.<br />
So if you are bold enough, take a look at the [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/App/MeshTestsApp.py?view=markup Unit Test module].<br />
<br />
{{docnav|FreeCAD Scripting Basics|Topological data scripting}}<br />
<br />
{{languages | {{cn|Mesh Scripting/cn}} {{de|Mesh Scripting/de}} {{es|Mesh Scripting/es}} {{fr|Mesh Scripting/fr}} {{it|Mesh Scripting/it}} {{jp|Mesh Scripting/jp}} {{ru|Mesh Scripting/ru}} {{se|Mesh Scripting/se}} }}<br />
<br />
[[Category:Poweruser Documentation]]<br />
[[Category:Python Code]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Mesh_Scripting&diff=50940Mesh Scripting2013-12-05T18:55:45Z<p>Jriegel: /* Modeling */</p>
<hr />
<div>=== Introduction ===<br />
<br />
First of all you have to import the Mesh module:<br />
import Mesh<br />
After that you have access to the Mesh module and the Mesh class which facilitate the functions<br />
of the FreeCAD C++ Mesh-Kernel.<br />
<br />
=== Creation and Loading === <br />
<br />
To create an empty mesh object just use the standard constructor:<br />
mesh = Mesh.Mesh()<br />
You can also create an object from a file<br />
mesh = Mesh.Mesh('D:/temp/Something.stl')<br />
(A list of compatible filetypes can be found under 'Meshes' [[Feature_list#IO|here]].)<br />
<br />
Or create it out of a set of triangles described by their corner points:<br />
<br />
<source lang="python"><br />
planarMesh = [<br />
# triangle 1<br />
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],<br />
#triangle 2<br />
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],<br />
]<br />
planarMeshObject = Mesh.Mesh(planarMesh)<br />
</source ><br />
<br />
The Mesh-Kernel takes care about creating a topological correct data structure by sorting<br />
coincident points and edges together. <br />
<br />
Later on you will see how you can test and examine mesh data.<br />
<br />
=== Modeling === <br />
<br />
To create regular geometries you can use the Python script BuildRegularGeoms.py.<br />
<br />
<source lang="python"><br />
import BuildRegularGeoms<br />
</source><br />
<br />
This script provides methods to define simple rotation bodies like spheres, ellipsoids, cylinders, toroids and cones. And it also has a method to create a simple cube.<br />
To create a toroid, for instance, can be done as follows:<br />
<br />
<source lang="python"><br />
t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br />
m = Mesh.Mesh(t)<br />
</source><br />
<br />
The first two parameters define the radiuses of the toroid and the third parameter is a sub-sampling factor for how many triangles are created. The higher this value the smoother and the lower the coarser the body is.<br />
The Mesh class provides a set of boolean functions that can be used for modeling purposes. It provides union, intersection and difference of two mesh objects.<br />
<source lang="python"><br />
m1, m2 # are the input mesh objects<br />
m3 = Mesh.Mesh(m1) # create a copy of m1<br />
m3.unite(m2) # union of m1 and m2, the result is stored in m3<br />
m4 = Mesh.Mesh(m1)<br />
m4.intersect(m2) # intersection of m1 and m2<br />
m5 = Mesh.Mesh(m1)<br />
m5.difference(m2) # the difference of m1 and m2<br />
m6 = Mesh.Mesh(m2)<br />
m6.difference(m1) # the difference of m2 and m1, usually the result is different to m5<br />
Finally, a full example that computes the intersection between a sphere and a cylinder that intersects the sphere.<br />
import Mesh, BuildRegularGeoms<br />
sphere = Mesh.Mesh( BuildRegularGeoms.Sphere(5.0, 50) )<br />
cylinder = Mesh.Mesh( BuildRegularGeoms.Cylinder(2.0, 10.0, True, 1.0, 50) )<br />
diff = sphere<br />
diff.difference(cylinder)<br />
d = FreeCAD.newDocument()<br />
d.addObject("Mesh::Feature","Diff_Sphere_Cylinder").Mesh=diff<br />
d.recompute()<br />
</source><br />
<br />
=== Examining and Testing === <br />
<br />
=== Write your own Algorithms === <br />
<br />
=== Exporting === <br />
<br />
You can even write the mesh to a python module:<br />
<br />
<source lang="python"><br />
m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")<br />
import SavedMesh<br />
m2 = Mesh.Mesh(SavedMesh.faces)<br />
</source><br />
<br />
=== Gui related stuff === <br />
<br />
=== Odds and Ends === <br />
An extensive (though hard to use) source of Mesh related scripting are the unit test scripts of the Mesh-Module. <br />
In this unit tests literally all methods are called and all properties/attributes are tweaked.<br />
So if you are bold enough, take a look at the [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/App/MeshTestsApp.py?view=markup Unit Test module].<br />
<br />
{{docnav|FreeCAD Scripting Basics|Topological data scripting}}<br />
<br />
{{languages | {{cn|Mesh Scripting/cn}} {{de|Mesh Scripting/de}} {{es|Mesh Scripting/es}} {{fr|Mesh Scripting/fr}} {{it|Mesh Scripting/it}} {{jp|Mesh Scripting/jp}} {{ru|Mesh Scripting/ru}} {{se|Mesh Scripting/se}} }}<br />
<br />
[[Category:Poweruser Documentation]]<br />
[[Category:Python Code]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Mesh_Scripting&diff=50938Mesh Scripting2013-12-05T18:54:52Z<p>Jriegel: </p>
<hr />
<div>=== Introduction ===<br />
<br />
First of all you have to import the Mesh module:<br />
import Mesh<br />
After that you have access to the Mesh module and the Mesh class which facilitate the functions<br />
of the FreeCAD C++ Mesh-Kernel.<br />
<br />
=== Creation and Loading === <br />
<br />
To create an empty mesh object just use the standard constructor:<br />
mesh = Mesh.Mesh()<br />
You can also create an object from a file<br />
mesh = Mesh.Mesh('D:/temp/Something.stl')<br />
(A list of compatible filetypes can be found under 'Meshes' [[Feature_list#IO|here]].)<br />
<br />
Or create it out of a set of triangles described by their corner points:<br />
<br />
<source lang="python"><br />
planarMesh = [<br />
# triangle 1<br />
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],<br />
#triangle 2<br />
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],<br />
]<br />
planarMeshObject = Mesh.Mesh(planarMesh)<br />
</source ><br />
<br />
The Mesh-Kernel takes care about creating a topological correct data structure by sorting<br />
coincident points and edges together. <br />
<br />
Later on you will see how you can test and examine mesh data.<br />
<br />
=== Modeling === <br />
<br />
To create regular geometries you can use the Python script BuildRegularGeoms.py.<br />
import BuildRegularGeoms<br />
This script provides methods to define simple rotation bodies like spheres, ellipsoids, cylinders, toroids and cones. And it also has a method to create a simple cube.<br />
To create a toroid, for instance, can be done as follows:<br />
t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br />
m = Mesh.Mesh(t)<br />
<br />
The first two parameters define the radiuses of the toroid and the third parameter is a sub-sampling factor for how many triangles are created. The higher this value the smoother and the lower the coarser the body is.<br />
The Mesh class provides a set of boolean functions that can be used for modeling purposes. It provides union, intersection and difference of two mesh objects.<br />
<source lang="python"><br />
m1, m2 # are the input mesh objects<br />
m3 = Mesh.Mesh(m1) # create a copy of m1<br />
m3.unite(m2) # union of m1 and m2, the result is stored in m3<br />
m4 = Mesh.Mesh(m1)<br />
m4.intersect(m2) # intersection of m1 and m2<br />
m5 = Mesh.Mesh(m1)<br />
m5.difference(m2) # the difference of m1 and m2<br />
m6 = Mesh.Mesh(m2)<br />
m6.difference(m1) # the difference of m2 and m1, usually the result is different to m5<br />
Finally, a full example that computes the intersection between a sphere and a cylinder that intersects the sphere.<br />
import Mesh, BuildRegularGeoms<br />
sphere = Mesh.Mesh( BuildRegularGeoms.Sphere(5.0, 50) )<br />
cylinder = Mesh.Mesh( BuildRegularGeoms.Cylinder(2.0, 10.0, True, 1.0, 50) )<br />
diff = sphere<br />
diff.difference(cylinder)<br />
d = FreeCAD.newDocument()<br />
d.addObject("Mesh::Feature","Diff_Sphere_Cylinder").Mesh=diff<br />
d.recompute()<br />
</source><br />
=== Examining and Testing === <br />
<br />
=== Write your own Algorithms === <br />
<br />
=== Exporting === <br />
<br />
You can even write the mesh to a python module:<br />
<br />
<source lang="python"><br />
m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")<br />
import SavedMesh<br />
m2 = Mesh.Mesh(SavedMesh.faces)<br />
</source><br />
<br />
=== Gui related stuff === <br />
<br />
=== Odds and Ends === <br />
An extensive (though hard to use) source of Mesh related scripting are the unit test scripts of the Mesh-Module. <br />
In this unit tests literally all methods are called and all properties/attributes are tweaked.<br />
So if you are bold enough, take a look at the [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/App/MeshTestsApp.py?view=markup Unit Test module].<br />
<br />
{{docnav|FreeCAD Scripting Basics|Topological data scripting}}<br />
<br />
{{languages | {{cn|Mesh Scripting/cn}} {{de|Mesh Scripting/de}} {{es|Mesh Scripting/es}} {{fr|Mesh Scripting/fr}} {{it|Mesh Scripting/it}} {{jp|Mesh Scripting/jp}} {{ru|Mesh Scripting/ru}} {{se|Mesh Scripting/se}} }}<br />
<br />
[[Category:Poweruser Documentation]]<br />
[[Category:Python Code]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Mesh_Scripting&diff=50937Mesh Scripting2013-12-05T18:52:51Z<p>Jriegel: </p>
<hr />
<div>=== Introduction ===<br />
<br />
First of all you have to import the Mesh module:<br />
import Mesh<br />
After that you have access to the Mesh module and the Mesh class which facilitate the functions<br />
of the FreeCAD C++ Mesh-Kernel.<br />
<br />
=== Creation and Loading === <br />
<br />
To create an empty mesh object just use the standard constructor:<br />
mesh = Mesh.Mesh()<br />
You can also create an object from a file<br />
mesh = Mesh.Mesh('D:/temp/Something.stl')<br />
(A list of compatible filetypes can be found under 'Meshes' [[Feature_list#IO|here]].)<br />
<br />
Or create it out of a set of triangles described by their corner points:<br />
<br />
<source lang="python"><br />
planarMesh = [<br />
# triangle 1<br />
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],<br />
#triangle 2<br />
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],<br />
]<br />
planarMeshObject = Mesh.Mesh(planarMesh)<br />
</python><br />
<br />
The Mesh-Kernel takes care about creating a topological correct data structure by sorting<br />
coincident points and edges together. <br />
<br />
Later on you will see how you can test and examine mesh data.<br />
<br />
=== Modeling === <br />
<br />
To create regular geometries you can use the Python script BuildRegularGeoms.py.<br />
import BuildRegularGeoms<br />
This script provides methods to define simple rotation bodies like spheres, ellipsoids, cylinders, toroids and cones. And it also has a method to create a simple cube.<br />
To create a toroid, for instance, can be done as follows:<br />
t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br />
m = Mesh.Mesh(t)<br />
<br />
The first two parameters define the radiuses of the toroid and the third parameter is a sub-sampling factor for how many triangles are created. The higher this value the smoother and the lower the coarser the body is.<br />
The Mesh class provides a set of boolean functions that can be used for modeling purposes. It provides union, intersection and difference of two mesh objects.<br />
m1, m2 # are the input mesh objects<br />
m3 = Mesh.Mesh(m1) # create a copy of m1<br />
m3.unite(m2) # union of m1 and m2, the result is stored in m3<br />
m4 = Mesh.Mesh(m1)<br />
m4.intersect(m2) # intersection of m1 and m2<br />
m5 = Mesh.Mesh(m1)<br />
m5.difference(m2) # the difference of m1 and m2<br />
m6 = Mesh.Mesh(m2)<br />
m6.difference(m1) # the difference of m2 and m1, usually the result is different to m5<br />
Finally, a full example that computes the intersection between a sphere and a cylinder that intersects the sphere.<br />
import Mesh, BuildRegularGeoms<br />
sphere = Mesh.Mesh( BuildRegularGeoms.Sphere(5.0, 50) )<br />
cylinder = Mesh.Mesh( BuildRegularGeoms.Cylinder(2.0, 10.0, True, 1.0, 50) )<br />
diff = sphere<br />
diff.difference(cylinder)<br />
d = FreeCAD.newDocument()<br />
d.addObject("Mesh::Feature","Diff_Sphere_Cylinder").Mesh=diff<br />
d.recompute()<br />
<br />
=== Examining and Testing === <br />
<br />
=== Write your own Algorithms === <br />
<br />
=== Exporting === <br />
<br />
You can even write the mesh to a python module:<br />
m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")<br />
import SavedMesh<br />
m2 = Mesh.Mesh(SavedMesh.faces)<br />
<br />
=== Gui related stuff === <br />
<br />
=== Odds and Ends === <br />
An extensive (though hard to use) source of Mesh related scripting are the unit test scripts of the Mesh-Module. <br />
In this unit tests literally all methods are called and all properties/attributes are tweaked.<br />
So if you are bold enough, take a look at the [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/App/MeshTestsApp.py?view=markup Unit Test module].<br />
<br />
{{docnav|FreeCAD Scripting Basics|Topological data scripting}}<br />
<br />
{{languages | {{cn|Mesh Scripting/cn}} {{de|Mesh Scripting/de}} {{es|Mesh Scripting/es}} {{fr|Mesh Scripting/fr}} {{it|Mesh Scripting/it}} {{jp|Mesh Scripting/jp}} {{ru|Mesh Scripting/ru}} {{se|Mesh Scripting/se}} }}<br />
<br />
[[Category:Poweruser Documentation]]<br />
[[Category:Python Code]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50936Quantity2013-12-05T18:51:13Z<p>Jriegel: /* Python scripting */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<source lang="python"><br />
import FreeCAD<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50935Quantity2013-12-05T18:50:55Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<source lang="php"><br />
import FreeCAD<br />
</source><br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50890Quantity2013-12-05T18:42:31Z<p>Jriegel: /* Basics */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|750px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50889Quantity2013-12-05T18:42:16Z<p>Jriegel: /* Basics */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|650px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=50839Quantity2013-12-05T18:15:37Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. It is used throughout all of FreeCAD to handle parameters and all other kind of input/output. <br />
<br />
== Basics ==<br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mix-up. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|800px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is physically dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
Often you are in need of calculating units from one system to another. For example you have old parameter tables with wired units. In that cases FreeCAD offers a conversion tool called Units-Calculator which helps in translating units. <br />
<br />
Its description in detail is here:<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" = Quantity(1.0e-6 ,Unit(1)); // nano meter<br />
"ym" = Quantity(1.0e-3 ,Unit(1)); // micro meter<br />
"mm" = Quantity(1.0 ,Unit(1)); // milli meter<br />
"cm" = Quantity(10.0 ,Unit(1)); // centi meter<br />
"dm" = Quantity(100.0 ,Unit(1)); // deci meter<br />
"m" = Quantity(1.0e3 ,Unit(1)); // meter<br />
"km" = Quantity(1.0e6 ,Unit(1)); // kilo meter<br />
"l" = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br />
<br />
"yg" = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br />
"mg" = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br />
"g" = Quantity(1.0e-3 ,Unit(0,1)); // gram<br />
"kg" = Quantity(1.0 ,Unit(0,1)); // kilo gram<br />
"t" = Quantity(1000.0 ,Unit(0,1)); // ton<br />
<br />
"s" = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br />
"min" = Quantity(60.0 ,Unit(0,0,1)); // minute<br />
"h" = Quantity(3600.0 ,Unit(0,0,1)); // hour <br />
<br />
"A" = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br />
"mA" = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br />
"kA" = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br />
"MA" = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br />
<br />
"K" = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br />
"mK" = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br />
"yK" = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br />
<br />
"mol" = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br />
<br />
"cd" = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br />
<br />
"deg" = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br />
"rad" = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br />
"gon" = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br />
<br />
"in" = Quantity(25.4 ,Unit(1)); // inch<br />
"\"" = Quantity(25.4 ,Unit(1)); // inch<br />
"fo" = Quantity(304.8 ,Unit(1)); // foot<br />
"'" = Quantity(304.8 ,Unit(1)); // foot<br />
"th" = Quantity(0.0254 ,Unit(1)); // thou<br />
"yr" = Quantity(914.4 ,Unit(1)); // yard<br />
<br />
<br />
"lb" = Quantity(0.45359237 ,Unit(0,1)); // pound<br />
"oz" = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br />
"st" = Quantity(6.35029318 ,Unit(0,1)); // Stone<br />
"cwt" = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br />
<br />
{{clear}}<br />
{{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=45880Std UnitsCalculator2013-11-30T13:04:53Z<p>Jriegel: /* Dialog */</p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units.<br />
==== Synopsis ====<br />
The first field defines a a value and a corresponding unit (what kind of units get recognized you can see in the [[Quantity]] description). In the second field you specify the resulting unit. The third field present the result. Pressing return in field one or two will add the result of the calculation to the log area for later usage.<br />
<br />
If one of the fields get red in the background means an error occourd. Either the parser gets and error in the unit expression or the source and target unit do not fit. Hovering over an red input field shows you the error string. <br />
<br />
The Copy button copies the result into the Clipboard, so you can use it in any other dialog of FreeCAD. <br />
<br />
The dialog is a non-modal dialog and can stay open as long as you want. It do not block the rest of FreeCAD.<br />
<br />
==== Dialog ====<br />
[[File:Units_Calculator_it.png]]<br />
<br />
The Dialog with the three fields and the log area. <br />
<br />
{{clear}}<br />
{{languages | {{fr|Std_UnitsCalculator/fr}} {{it|Std_UnitsCalculator/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=45879Std UnitsCalculator2013-11-30T13:04:34Z<p>Jriegel: </p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units.<br />
==== Synopsis ====<br />
The first field defines a a value and a corresponding unit (what kind of units get recognized you can see in the [[Quantity]] description). In the second field you specify the resulting unit. The third field present the result. Pressing return in field one or two will add the result of the calculation to the log area for later usage.<br />
<br />
If one of the fields get red in the background means an error occourd. Either the parser gets and error in the unit expression or the source and target unit do not fit. Hovering over an red input field shows you the error string. <br />
<br />
The Copy button copies the result into the Clipboard, so you can use it in any other dialog of FreeCAD. <br />
<br />
The dialog is a non-modal dialog and can stay open as long as you want. It do not block the rest of FreeCAD.<br />
<br />
==== Dialog ====<br />
[[File:Units_Calculator_it.png|left]]<br />
<br />
The Dialog with the three fields and the log area. <br />
<br />
{{clear}}<br />
{{languages | {{fr|Std_UnitsCalculator/fr}} {{it|Std_UnitsCalculator/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=45878Std UnitsCalculator2013-11-30T13:03:53Z<p>Jriegel: /* Dialog */</p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
<br />
==== Synopsis ====<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units. <br />
<br />
The first field defines a a value and a corresponding unit (what kind of units get recognized you can see in the [[Quantity]] description). In the second field you specify the resulting unit. The third field present the result. Pressing return in field one or two will add the result of the calculation to the log area for later usage.<br />
<br />
If one of the fields get red in the background means an error occourd. Either the parser gets and error in the unit expression or the source and target unit do not fit. Hovering over an red input field shows you the error string. <br />
<br />
The Copy button copies the result into the Clipboard, so you can use it in any other dialog of FreeCAD. <br />
<br />
The dialog is a non-modal dialog and can stay open as long as you want. It do not block the rest of FreeCAD.<br />
<br />
==== Dialog ====<br />
[[File:Units_Calculator_it.png|left]]<br />
<br />
The Dialog with the three fields and the log area. <br />
<br />
{{clear}}<br />
{{languages | {{fr|Std_UnitsCalculator/fr}} {{it|Std_UnitsCalculator/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=45877Std UnitsCalculator2013-11-30T13:03:38Z<p>Jriegel: /* Synopsis */</p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
<br />
==== Synopsis ====<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units. <br />
<br />
The first field defines a a value and a corresponding unit (what kind of units get recognized you can see in the [[Quantity]] description). In the second field you specify the resulting unit. The third field present the result. Pressing return in field one or two will add the result of the calculation to the log area for later usage.<br />
<br />
If one of the fields get red in the background means an error occourd. Either the parser gets and error in the unit expression or the source and target unit do not fit. Hovering over an red input field shows you the error string. <br />
<br />
The Copy button copies the result into the Clipboard, so you can use it in any other dialog of FreeCAD. <br />
<br />
The dialog is a non-modal dialog and can stay open as long as you want. It do not block the rest of FreeCAD.<br />
<br />
==== Dialog ====<br />
[[File:Units_Calculator_it.png|left]]<br />
The Dialog with the three fields and the log area. <br />
<br />
{{clear}}<br />
{{languages | {{fr|Std_UnitsCalculator/fr}} {{it|Std_UnitsCalculator/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=45876Std UnitsCalculator2013-11-30T13:00:00Z<p>Jriegel: </p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
<br />
==== Synopsis ====<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units. <br />
<br />
The first field defines a a value and a corresponding unit (what kind of units get recognized you can see in the [[Quantity]] description). In the second field you specify the resulting unit. The third field present the result. Pressing return in field one or two will add the result of the calculation to the log area for later usage. <br />
<br />
<br />
==== Dialog ====<br />
[[File:Units_Calculator_it.png|left]]<br />
The Dialog with the three fields and the log area. <br />
<br />
{{clear}}<br />
{{languages | {{fr|Std_UnitsCalculator/fr}} {{it|Std_UnitsCalculator/it}} }}</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=42903Quantity2013-11-10T13:19:49Z<p>Jriegel: /* Basics */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. <br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mixup. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
== Basics ==<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg|800px]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is phisicaly dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" yylval = Quantity(1.0e-6 ,Unit(1)); return UNIT; // nano meter<br />
"ym" yylval = Quantity(1.0e-3 ,Unit(1)); return UNIT; // micro meter<br />
"mm" yylval = Quantity(1.0 ,Unit(1)); return UNIT; // milli meter<br />
"cm" yylval = Quantity(10.0 ,Unit(1)); return UNIT; // centi meter<br />
"dm" yylval = Quantity(100.0 ,Unit(1)); return UNIT; // deci meter<br />
"m" yylval = Quantity(1.0e3 ,Unit(1)); return UNIT; // meter<br />
"km" yylval = Quantity(1.0e6 ,Unit(1)); return UNIT; // kilo meter<br />
"l" yylval = Quantity(1000000.0 ,Unit(3)); return UNIT; // Liter dm^3<br />
<br />
"yg" yylval = Quantity(1.0e-9 ,Unit(0,1)); return UNIT; // milli gram<br />
"mg" yylval = Quantity(1.0e-6 ,Unit(0,1)); return UNIT; // milli gram<br />
"g" yylval = Quantity(1.0e-3 ,Unit(0,1)); return UNIT; // gram<br />
"kg" yylval = Quantity(1.0 ,Unit(0,1)); return UNIT; // kilo gram<br />
"t" yylval = Quantity(1000.0 ,Unit(0,1)); return UNIT; // ton<br />
<br />
"s" yylval = Quantity(1.0 ,Unit(0,0,1)); return UNIT; // second (internal standard time)<br />
"min" yylval = Quantity(60.0 ,Unit(0,0,1)); return UNIT; // minute<br />
"h" yylval = Quantity(3600.0 ,Unit(0,0,1)); return UNIT; // hour <br />
<br />
"A" yylval = Quantity(1.0 ,Unit(0,0,0,1)); return UNIT; // Ampere (internal standard electric current)<br />
"mA" yylval = Quantity(0.001 ,Unit(0,0,0,1)); return UNIT; // milli Ampere <br />
"kA" yylval = Quantity(1000.0 ,Unit(0,0,0,1)); return UNIT; // kilo Ampere <br />
"MA" yylval = Quantity(1.0e6 ,Unit(0,0,0,1)); return UNIT; // Mega Ampere <br />
<br />
"K" yylval = Quantity(1.0 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin (internal standard thermodynamic temperature)<br />
"mK" yylval = Quantity(0.001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin <br />
"yK" yylval = Quantity(0.000001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin <br />
<br />
"mol" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,1)); return UNIT; // Mole (internal standard amount of substance) <br />
<br />
"cd" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); return UNIT; // Candela (internal standard luminous intensity) <br />
<br />
"deg" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // degree (internal standard angle)<br />
"rad" yylval = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // radian <br />
"gon" yylval = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // gon <br />
<br />
"in" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch<br />
"\"" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch<br />
"fo" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot<br />
"'" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot<br />
"th" yylval = Quantity(0.0254 ,Unit(1)); return UNIT; // thou<br />
"yr" yylval = Quantity(914.4 ,Unit(1)); return UNIT; // yard<br />
<br />
<br />
"lb" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // pound<br />
"oz" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // ounce<br />
"st" yylval = Quantity(6.35029318 ,Unit(0,1)); return UNIT; // Stone<br />
"cwt" yylval = Quantity(50.80234544 ,Unit(0,1)); return UNIT; // hundredweights</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=42902Quantity2013-11-10T13:18:26Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. <br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mixup. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
== Basics ==<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is phisicaly dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==<br />
<br />
<br />
== Appendix == <br />
<br />
=== Parser supported Units ===<br />
Although all physical units can be described with the seven SI units, most of the units used in technical areas are common combined units (like Pa = N/m^2 Pascal ). There fore the units parser in FreeCAD support lot of SI and Imperial combined units. This units are defined in src/Base/QuantityParser.l file and can be further advanced in the future. <br />
<br />
<br />
"nm" yylval = Quantity(1.0e-6 ,Unit(1)); return UNIT; // nano meter<br />
"ym" yylval = Quantity(1.0e-3 ,Unit(1)); return UNIT; // micro meter<br />
"mm" yylval = Quantity(1.0 ,Unit(1)); return UNIT; // milli meter<br />
"cm" yylval = Quantity(10.0 ,Unit(1)); return UNIT; // centi meter<br />
"dm" yylval = Quantity(100.0 ,Unit(1)); return UNIT; // deci meter<br />
"m" yylval = Quantity(1.0e3 ,Unit(1)); return UNIT; // meter<br />
"km" yylval = Quantity(1.0e6 ,Unit(1)); return UNIT; // kilo meter<br />
"l" yylval = Quantity(1000000.0 ,Unit(3)); return UNIT; // Liter dm^3<br />
<br />
"yg" yylval = Quantity(1.0e-9 ,Unit(0,1)); return UNIT; // milli gram<br />
"mg" yylval = Quantity(1.0e-6 ,Unit(0,1)); return UNIT; // milli gram<br />
"g" yylval = Quantity(1.0e-3 ,Unit(0,1)); return UNIT; // gram<br />
"kg" yylval = Quantity(1.0 ,Unit(0,1)); return UNIT; // kilo gram<br />
"t" yylval = Quantity(1000.0 ,Unit(0,1)); return UNIT; // ton<br />
<br />
"s" yylval = Quantity(1.0 ,Unit(0,0,1)); return UNIT; // second (internal standard time)<br />
"min" yylval = Quantity(60.0 ,Unit(0,0,1)); return UNIT; // minute<br />
"h" yylval = Quantity(3600.0 ,Unit(0,0,1)); return UNIT; // hour <br />
<br />
"A" yylval = Quantity(1.0 ,Unit(0,0,0,1)); return UNIT; // Ampere (internal standard electric current)<br />
"mA" yylval = Quantity(0.001 ,Unit(0,0,0,1)); return UNIT; // milli Ampere <br />
"kA" yylval = Quantity(1000.0 ,Unit(0,0,0,1)); return UNIT; // kilo Ampere <br />
"MA" yylval = Quantity(1.0e6 ,Unit(0,0,0,1)); return UNIT; // Mega Ampere <br />
<br />
"K" yylval = Quantity(1.0 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin (internal standard thermodynamic temperature)<br />
"mK" yylval = Quantity(0.001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin <br />
"yK" yylval = Quantity(0.000001 ,Unit(0,0,0,0,1)); return UNIT; // Kelvin <br />
<br />
"mol" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,1)); return UNIT; // Mole (internal standard amount of substance) <br />
<br />
"cd" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); return UNIT; // Candela (internal standard luminous intensity) <br />
<br />
"deg" yylval = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // degree (internal standard angle)<br />
"rad" yylval = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // radian <br />
"gon" yylval = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); return UNIT; // gon <br />
<br />
"in" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch<br />
"\"" yylval = Quantity(25.4 ,Unit(1)); return UNIT; // inch<br />
"fo" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot<br />
"'" yylval = Quantity(304.8 ,Unit(1)); return UNIT; // foot<br />
"th" yylval = Quantity(0.0254 ,Unit(1)); return UNIT; // thou<br />
"yr" yylval = Quantity(914.4 ,Unit(1)); return UNIT; // yard<br />
<br />
<br />
"lb" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // pound<br />
"oz" yylval = Quantity(0.45359237 ,Unit(0,1)); return UNIT; // ounce<br />
"st" yylval = Quantity(6.35029318 ,Unit(0,1)); return UNIT; // Stone<br />
"cwt" yylval = Quantity(50.80234544 ,Unit(0,1)); return UNIT; // hundredweights</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=42778Quantity2013-11-08T17:16:33Z<p>Jriegel: </p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. <br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mixup. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
== Basics ==<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is phisicaly dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.<br />
<br />
== Units calculator ==<br />
<br />
[[Std_UnitsCalculator]]<br />
<br />
== Python scripting ==</div>Jriegelhttps://wiki.freecad.org/index.php?title=Std_UnitsCalculator&diff=42777Std UnitsCalculator2013-11-08T17:14:01Z<p>Jriegel: Created page with "{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}} ==== Synopsis ==== Opens the unit calculator dialog, which allo..."</p>
<hr />
<div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -> Unit calculator...|Workbenches=All|SeeAlso=...}}<br />
<br />
<br />
==== Synopsis ====<br />
<br />
Opens the unit calculator dialog, which allow to transform Quantities into different units.<br />
<br />
<br />
==== Dialog ====</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=42768Quantity2013-11-08T16:07:16Z<p>Jriegel: /* Basics */</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. <br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mixup. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
== Basics ==<br />
<br />
All physical units can be expressed as a combination of the seven [http://en.wikipedia.org/wiki/International_System_of_Units SI-Units]:<br />
<br />
<br />
[[File:SI-Derived-Units.jpg]]<br />
<br />
<br />
An easy way to express a Unit is a integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
Since angle is phisicaly dimensionless, but never the less important to a CAD system we add one more virtual unit for Angle. This makes a vector of 8 in the FreeCAD unit signature.</div>Jriegelhttps://wiki.freecad.org/index.php?title=File:SI-Derived-Units.jpg&diff=42730File:SI-Derived-Units.jpg2013-11-08T15:57:09Z<p>Jriegel: Overview of the SI-derived units</p>
<hr />
<div>Overview of the SI-derived units</div>Jriegelhttps://wiki.freecad.org/index.php?title=Quantity&diff=42720Quantity2013-11-08T15:54:05Z<p>Jriegel: Created page with "The Quantity is a combination of a floating point number and an Unit. In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can ari..."</p>
<hr />
<div>The Quantity is a combination of a floating point number and an Unit. <br />
<br />
In a CAD or CAE system its very important to keep track on the unit of an value. Lot of trouble can arise when mixing up units or calculating results in different unit systems. One famous disaster is the [http://en.wikipedia.org/wiki/Mars_Climate_Orbiter#Cause_of_failure crash of the Mars Climate Orbiter] through out a unit mixup. Even in the same unit-system the units come in lots of different flavors always tailored to the field of use. Simple examples are e.g. velocity in km/h (cars), m/s (robotics) or mm/minute (milling). A CAD system have to keep reliably track of units. Also it has to calculate with them and check on the right unit for special parameters. <br />
<br />
For that reason the FreeCAD Quantity framework was created. It includes all the code and objects to deal with units, unit calculations, user input, conversion in other unit systems and the pretty output of units and values. In the long run no parameter in FreeCAD should be just a number. <br />
<br />
== Basics ==</div>Jriegelhttps://wiki.freecad.org/index.php?title=Units&diff=42667Units2013-11-08T15:05:14Z<p>Jriegel: /* Next actions */</p>
<hr />
<div>Here some reading about units:<br />
*[http://en.wikipedia.org/wiki/International_System_of_Units SI system]<br />
*[http://en.wikipedia.org/wiki/Imperial_units Imperial units]<br />
*[http://en.wikipedia.org/wiki/SI_derived_unit SI derived units]<br />
*[http://en.wikipedia.org/wiki/Degree_%28angle%29 angle units]<br />
<br />
== Examples ==<br />
<br />
# -- some examples of the FreeCAD unit translation system --<br />
# make a shortcut for the examples<br />
tu = App.Units.translateUnit<br />
<br />
# 10 meters in internal numbers<br />
tu('10 m')<br />
# doing math<br />
tu('3/8 in')<br />
# combined stuff<br />
tu('100 km/h')<br />
# transfer to other units<br />
tu('100 km/h')/tu('m/s')<br />
# derived units (Ohm)<br />
tu('m^2*kg*s^-3*A^-2')<br />
# or<br />
tu('(m^2*kg)/(A^2*s^3)')<br />
# angles <br />
tu('2*pi rad') # full circle<br />
# as gon<br />
tu('2*pi rad') / tu('gon')<br />
# more imperial<br />
tu('1fo+(3+7/16)in')<br />
# or <br />
tu('1\'+(3+7/16)"') # the ' we have to escape because of python<br />
# trigonometry<br />
tu('sin(pi)')<br />
# Using translated units as parameters, this command will create a 50.8mm x 20mm x 10mm box<br />
b = Part.makeBox(tu('2in'),tu('2m')/100,10)<br />
<br />
== Supported units ==<br />
Here the defined units in FreeCAD so far. It's easy to add a new user defined unit. The definition is here[http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Base/UnitsApi.l?view=markup]. <br />
<br />
Metric length<br />
"mm" 1.0; // millimeter (internal standard length)<br />
"m" 1000.0; // meter<br />
"cm" 10.0; // centimeter<br />
"dm" 100.0; // decimeter<br />
"km" 1000000.0; // kilometer<br />
Imperial lenth<br />
"in" "\"" 25.4; // inch<br />
"fo" "'" 304.8; // foot<br />
"th" 0.0254; // thou<br />
"yr" 914.4; // yard<br />
Metric mass<br />
"kg" 1.0; // kilogram (internal standard mass)<br />
"g" 0.001; // gram<br />
"mg" 0.000001; // milligram<br />
"t" 1000.0; // ton <br />
Imperial mass<br />
"lb" 0.45359237; // pound<br />
"oz" 0.45359237; // ounce<br />
"st" 6.35029318; // Stone<br />
"cwt" 50.80234544;// hundredweights<br />
Angle<br />
"deg" 1.0; // degree (internal standard angle)<br />
"rad" 180/M_PI; // radian <br />
"gon" 360.0/400.0;// gon <br />
Time<br />
"s" 1.0; // second (internal standard time)<br />
"min" 60.0; // minute<br />
"h" 3600.0; // hour <br />
Rest of SI<br />
"A" 1.0; // Ampere (internal standard electric current)<br />
"K" 1.0; // Kelvin (internal standard thermodynamic temperature)<br />
"cd" 1.0; // Candela (internal standard luminous intensity) <br />
"mol" 1.0; // Mole (internal standard amount of substance) <br />
Metric Volume<br />
"yl" 1.0; // microliter mm^3(derived standard volume)<br />
"ml" 1000.0; // milliliter cm^3 <br />
"l" 1000000.0; // Liter dm^3<br />
<br />
== Purpose and principles: proposal of an extension of the unit management system ==<br />
<br />
An extension unit management system is proposed in the following sections, developping the concept of ''unit system'', activated during a running FreeCAD instance.<br />
The interest in defining such a new concept is to work more easily with as many type of '''physical''' units as one wants (even user-created ones), without increasing the complexity of unit management for the user, nor for FreeCAD developpers.<br />
<br />
In short, event of unit scaling are localized precisely, and carried out in a generic fashion.<br />
<br />
Achieving such a flexibility is most notably required when one starts to deal with material properties that can have very different units, difficult to manage one by one manually.<br />
<br />
The reasoning proposed allows handling the units such as described in the [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)] both from NIST.<br />
<br />
In this proposal, one first recall in [[Units#Brainstorming|Brainstorming]] section what are the possible contexts for which unit management is required.<br />
<br />
In [[Units#Organizing|Organizing]] section, we present the data model retained to achieve unit management, based on 3 objects, the ''unit'', the ''unit dictionary'', and the ''unit system''.<br />
Finally, a short API of a 4th object called the ''unit manager'' is presented as well.<br />
<br />
== Outcome ==<br />
<br />
Thanks to this extension, one aims to ease unit scaling that can occurs between different business tasks. For instance, technical drawings can be done in standard unit system, while FE modelling can be managed in an unit system more suited for it.<br />
<br />
The exchange of data between these two kind of activities become easier with this extension.<br />
<br />
== Brainstorming ==<br />
<br />
In this section are highlighted the contexts of use of such an unit management system.<br />
From these contexts, we are then able to defined its technical specifications.<br />
<br />
Essentially 2 contexts are given as example.<br />
<br />
=== Context 1: opening a data file ===<br />
<br />
This case is probably the most frequent case.<br />
You receive a file containing for instance a geometrical model, or describing a material with quite a lot of properties. The geometrical model is expressed in meters, or the material properties according the international unit system.<br />
<br />
Too bad...<br />
<br />
You are an expert FE modelling, and you usually work with millimeter for length, MegaPascal for stress, tonne for mass...<br />
<br />
In this context, unit management is required to scale data from an initial unit system defined in the input file to a user-defined target unit system.<br />
<br />
=== Context 2: switching the unit system at runtime ===<br />
<br />
In this case, you can be at the same time the guy that carries out a drawing, and the guy that will manage the FE modelling. Similarly to the previous case, the unit systems for these 2 tasks are not the same, and you need to switch the initial unit system at runtime to your favorite one.<br />
<br />
== Organizing ==<br />
<br />
=== Logic of unit scaling ===<br />
<br />
In the [[Units#Brainstorming|Brainstorming]] section have been presented 2 contexts when using unit scaling.<br />
Some items should be highlighted from these two contexts.<br />
<br />
==== Unit coherence throughout the FreeCAD running instance ====<br />
<br />
The system proposed is based on a primary assumption: the user is working in a coherent unit system.<br />
For instance, this means that if the user expresses length in millimeters, necessarily areras will be expressed in terms of squared millimeters, not squared meters.<br />
This is '''hypothesis one'''.<br />
<br />
==== Unit system ====<br />
<br />
Because of ''hypothesis one'', it is possible and relevant to define an unit system.<br />
An unit system applies to:<br />
* a running FreeCAD instance into which you are working<br />
* or it may also apply globally to the content of an input file<br />
According [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] from NIST, they are 7 physical base units.<br />
We chose to express a unit system in terms of these 7 base units.<br />
<br />
When working within an instance of FreeCAD, the user has thus to define first the unit system according to which she/he is working before she/he decides to switch to another unit system, or before importing data from an input file.<br />
<br />
This unit system will apply till the user decides to change it. If she/he does, all data with dimensions will be scaled.<br />
<br />
Considering ''hypothesis one'', all data that the user will input manually in FreeCAD are assumed to be coherent with the chosen unit system.<br />
<br />
The benefit to work with a ''unit system'' defined at a FreeCAD running instance level, or at data file level (instead of ''unit'' which are defined at the data level) is then that unit management is considerably simplified.<br />
<br />
Here are some examples of unit systems.<br />
* meter, kilogram, second, ampere, Kelvin, mole, candela<br />
* millimeter, tonne, millisecond, ampere, Kelvin, mole, candela<br />
* millimeter, kilogramme, millisecond, ampere, Kelvin, mole, candela<br />
*...<br />
<br />
==== Base and derived units ====<br />
<br />
Derived units are created by combination of base units. For instance, an acceleration (m/s) combines at the same time length and time. An interesting picture presenting the relationships between base and derived units can be seen [http://physics.nist.gov/cuu/pdf/SIDiagramColorAnnot.pdf here] also from NIST.<br />
<br />
Thanks to the definition of ''unit system'', it is possible for the user to work with any kind of derived units, without the need for FreeCAD developpers to foresee them in advance.<br />
<br />
==== Base and derived unit symbols ====<br />
<br />
According to [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)], the symbols to specify a units are officially approved. Two consequences can be highlighted from this.<br />
* it is not easy for a computer program to work with unit symbols because some are greek letters for instance. Hence they can be a bit difficult to process by a program<br />
* while some units and their symbols can be used widely, they may be not approved officially, like for instance ''tonne'' unit (see p32 of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)])<br />
<br />
To overcome these limitations and remain flexible, the proposed system favors the use of unit magnitudes instead of unit symbols, which remain nonetheless available for an ergonomy reason.<br />
<br />
=== Data model ===<br />
<br />
The three core objects of the unit management system are presented, namely the ''unit'', the ''unit dictionary'' and the ''unit system''.<br />
<br />
==== Unit ====<br />
<br />
As a foreword, it is important to highlight that a ''unit'' object in itself only indicates a '''dimension''' like length, mass, time... It doesn't specify a '''magnitude''' like meter, millimeter, kilometer... This last information is specified through the unit system.<br />
<br />
===== Dimension =====<br />
<br />
Compulsory string indicating the ''dimension'' of the unit. The ''dimension'' of the 7 base units are indicated below (from [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)]).<br />
* LENGTH<br />
* MASS<br />
* TIME<br />
* ELECTRIC CURRENT<br />
* THERMODYNAMIC TEMPERATURE<br />
* AMOUNT OF SUBSTANCE<br />
* LUMINOUS INTENSITY<br />
<br />
''Dimension'' attribute allows identifying the unit.<br />
Two units cannot share the same ''dimension''.<br />
<br />
===== Signature =====<br />
<br />
Compulsory integer array of size 7 (number of base units) that defines what the unit is.<br />
The signature of the 7 base units are:<br />
* LENGTH: [1,0,0,0,0,0,0]<br />
* MASS: [0,1,0,0,0,0,0]<br />
* TIME: [0,0,1,0,0,0,0]<br />
* ELECTRIC CURRENT: [0,0,0,1,0,0,0]<br />
* THERMODYNAMIC TEMPERATURE: [0,0,0,0,1,0,0]<br />
* AMOUNT OF SUBSTANCE: [0,0,0,0,0,1,0]<br />
* LUMINOUS INTENSITY: [0,0,0,0,0,0,1]<br />
<br />
From these 7 units, we are then able to express all derived units defined in [http://physics.nist.gov/cuu/pdf/sp811.pdf Guide for the Use of the International System of Units (SI)] and create new ones as needed such as for instance:<br />
* MASS DENSITY: [-3,1,0,0,0,0,0]<br />
* AREA: [0,2,0,0,0,0,0]<br />
<br />
''Signature'' is the attribute thanks to which unit scaling can be achieved in a generic way.<br />
<br />
===== Symbols =====<br />
<br />
Array of [real, string] (meaning [''magnitude'', ''symbol'']) that lists all ''symbols'' known by FreeCAD.<br />
Thanks to this array, the unit scaling API becomes more ergonomic because ''symbols'' and related ''magnitudes'' are linked.<br />
<br />
This array can be extended as required.<br />
<br />
For instance, the list of ''symbols'' of the LENGTH unit, and their related ''magnitudes'' is:<br />
<br />
[1e+12,"Tm"],[1e+09,"Gm"],[1e+06,"Mm"],<br />
[1e+03,"km"],[1e+02,"hm"],[1e+01,"dam"],<br />
[1e+00,"m"],[1e-01,"dm"],[1e-02,"cm"],<br />
[1e-03,"mm"],[1e-06,"ym"],[1e-09,"nm"],<br />
[1e-12,"pm"],[1e-15,"fm"]<br />
<br />
Standard ''symbols'' can be found on [http://physics.nist.gov/cuu/Units/units.html NIST website] and p23 to 26 and p32 (''metric ton'' or ''tonne'') of [http://physics.nist.gov/Pubs/SP330/sp330.pdf The International System of Units (SI)].<br />
<br />
==== Unit dictionary ====<br />
<br />
All the units available in FreeCAD, and new ones created by the user, should be stored in ''unit dictionary'', which is an XML file (FreeCAD configuration file), so as to be retrieved when needed, i.e. when achieving unit scaling.<br />
<br />
===== Units =====<br />
<br />
Array of units, contained in the ''unit dictionary''.<br />
<br />
==== Unit system ====<br />
<br />
A ''unit system'' is the object that allows the user defining the current unit ''magnitude'' of each base units with which she/he is working.<br />
For instance, knowing that the user is working with millimeter, tonne, and second, thanks to the use of a unit system, FreeCAD can know that energy is expressed in terms of milliJoule, force in terms of Newton, and stress in terms of MegaPascal.<br />
Hence a unit system is only defined by a ''name'' (for instance ''Standard unit system'') and a ''magnitude table'' specifying for each of the 7 base units, what is its corresponding ''magnitude''.<br />
<br />
===== Name =====<br />
<br />
String allowing to the user identifying what is the unit system.<br />
<br />
===== Magnitudes =====<br />
<br />
By specifying the magnitude of the 7 base units, a unit system is defined.<br />
<br />
For instance [1e-03, 1e+03, 1, 1, 1, 1, 1], meaning millimeter, tonne, second, ampere, Kelvin, mole, candela<br />
<br />
==== Unit management API ====<br />
<br />
Only the logic of some methods is presented, in order to highlight some features.<br />
These methods could belong to an object called ''Unit manager''.<br />
<br />
===== Checking the unit dictionary =====<br />
<br />
====== isValid ======<br />
<br />
The unit dictionary can be an XML file (FreeCAD configuration file). It contains a list of defined units.<br />
Such a dictionary is required for the proposed unit management system to work.<br />
<br />
It must fulfills some conditions that should be checked before activating the unit management system.<br />
These conditions are:<br />
* check that all base units are defined<br />
* check that a ''dimension'' is not defined twice through the units<br />
* check that a ''symbol'' is not defined twice in all the existing symbols<br />
* check that the ''signatures'' of all units have all the same size<br />
* chacke that a ''standard symbol'' (for which ''magnitude'' is 1) is defined for all units<br />
<br />
====== isCompatibleWithThisSignature ======<br />
<br />
A unit dictionary defines a set of units and their known magnitudes.<br />
When managing a unit, it is relevant to check that its signature is compatible with the set of units registered in the unit dictionary, so as to process it.<br />
This check includes:<br />
* check that the input ''signature'' length is of the same size than the unit dictionary unit ''signatures''<br />
<br />
===== Scaling units =====<br />
<br />
====== scaleUnitFromSymbolToSymbol ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit by its symbol, scale the value.<br />
<br />
====== scaleUnitFromSymbolToUnitSystem ======<br />
<br />
Knowing a value, an initial unit by its symbol, the target unit system, scale the value.<br />
<br />
====== scaleUnitFromUnitSystemToSymbol ======<br />
<br />
Knowing a value, an initial unit system, the target unit by its symbol, scale the value.<br />
<br />
==== Motivations for such a management: example of application ====<br />
<br />
Let's assume that we are going to setup a finite element model.<br />
To build our model, we need the mesh, material properties, and to define numerical parameters.<br />
Considering that they can be tens of material properties to manage, expressed with different units, sometimes not always very common, it is interesting for the user to only have to specify a global unit system, without caring much.<br />
<br />
FreeCAD would then just do the job.<br />
<br />
As FreeCAD developpers and FreeCAD users do not necessarily know all units that can be defined in the material property files, it is interesting to rely on a generic system.<br />
<br />
Let's assume that in such a file we have a fair number of exotic material properties expressed with exotic units, and that we want to work in a specific unit system.<br />
<br />
It is easy with the proposed extension to scale any of these properties by knowing their signatures, magnitudes, and the target unit system.<br />
<br />
<br />
For each of the properties, the scaling is obtained by multiplying the initial property value with the factor <math>\frac{initialMagnitude}{targetMagnitude}</math>.<br />
<br />
The ''targetMagnitude'' is then simply obtained with the operation <math>\prod_{bu} targetMagnitude_{bu}^{signature_{bu}}</math>, ''bu'' standing for ''base unit''.<br />
<br />
It becomes thus very easy to manage any number of properties with any kind of units with very few lines of Python.<br />
<br />
== Next actions ==<br />
<br />
* Implementing Quantity and Unit classes (mostly done)<br />
* Implementing InputField as User front end (in progress)<br />
* UnitsCalculator as test bed (in progress)<br />
* [[Quantity]] documentation (in progress)<br />
* UnitsCalculator documentation <br />
* Update Material framework to work only with Quantities<br />
* Test Cases<br />
<br />
<br />
{{languages | {{es|Units/es}} {{fr|Units/fr}} {{it|Units/it}} }}<br />
<br />
[[Category:Poweruser Documentation]]</div>Jriegelhttps://wiki.freecad.org/index.php?title=Material&diff=40746Material2013-08-08T13:35:33Z<p>Jriegel: /* Mechanical */</p>
<hr />
<div>This page is about the material data system in FreeCAD. <br />
<br />
== Abstract == <br />
Since it is hard, or even impossible, to define a fixed or complete set of material properties, we go a more open way. Every object in FreeCAD which <br />
has to deal with material will have a Property named "Material", which is a key/value list that can hold an infinite number of material properties. Since this is a very open and extensible way to deal with such data, it also holds the danger of chaos. Therefore this page defines some rules and basic properties for dealing with such material-property-maps.<br />
<br />
== Rules ==<br />
<br />
Every property set has only one mandatory entry which is "Name". This is the primary key of the material. The rest of the material properties are optional or can be retrieved out of a material DB. <br />
<br />
Property names (key) are ordered by strings separated by underscores. The first substring is named by the application or standard, the following can be used to further group the properties. The Values can also be grouped by underscores, e.g. to separate different sorts of steel. Examples: <br />
* Name=Steel_Cast<br />
* SpecificWeight=7.85 (at 20° in kg/mm3)<br />
* EN10027_name = S235JR+AR (steel standard EN 10027-1)<br />
* FEM_YoungsModulus = xx ( in mm−1·kg·s−2<br />
* FEM_YoungsModulus_Z<br />
* FEM_YoungsModulus_X<br />
<br />
Each property has a human readably description on this Material page, with links to further information (e.g. Wikipedia). <br />
<br />
For each property a unit has to be defined, based on the FreeCAD internal unit mm-kg-s! That allows consistent usage and translation. <br />
<br />
The key (name) and the value of the property uses only ASCII characters (7-bit). The keys are written in Camel-Case but interpreted case-insensitive. <br />
<br />
The underscores allow later a tree view property editor/viewer which allow folding.<br />
<br />
== Tools ==<br />
There are some good resources out there handle materials more easy:<br />
* [http://www.dimensionengine.com/ Units calculater] to get your material information in the Unit needed for FreeCAD<br />
* [http://www.matweb.com/ http://www.matweb.com/] free Material database with thousands of material values<br />
<br />
== Material Database ==<br />
<br />
Given that above standard is implemented, it would be stupid to store all the properties again and again to objects. Basically we can build up a Material DB with the Name as a primary key. So if you have no special needs for your material, you just define e.g. Name=Steel and FreeCAD can retrieve all properties from that DB. Every additional property you set in the map overrides the one from the DB. <br />
<br />
In the future we can host that DB somwhere in the Web and build up a general OpenSource material DB.<br />
<br />
At the moment I think of a compiled in mini dataset with a set of "basic" materials and its basic properties and a SQLite based full version.<br />
<br />
== Material.py ==<br />
Since handling material-properties is a tedious work we should implement a Python front-end module calls Material.py. This will be the place to implement all kind of helper methods for material handling.<br />
* Calculation of Mass out of Volume and Density<br />
* Translation in different unit systems<br />
* Calculation needed in special application (e.g. FEM)<br />
* and anything else we don't know yet :)<br />
<br />
The module should be implemented that way it can run in FreeCAD or stand alone on the command line (material-property-map has be given as python map).<br />
<br />
== The FreeCAD material card file format ==<br />
<br />
Working with materials means often import/export material-definitions. There fore a file format is needed. Since we have only key/value form, we can use a simple and easy to read and parse file format. There fore the [http://en.wikipedia.org/wiki/INI_file ini-file] format is chosen. Its standardized and there are already parser available. E.g the [http://docs.python.org/2/library/configparser.html Config parser module in python]. <br />
<br />
Each material definition reside in a file with the ending .FCMat. Some of this files are part of the FreeCAD source and get compiled into the binary. This is to save overhead in distribution and access. But also files can be placed and searched on different places to allow additional non-standard material definitions. <br />
<br />
=== Examples ===<br />
<br />
; last modified 1 April 2001 by John Doe<br />
<br />
Name=Steel_Cast<br />
Father=Steel<br />
Source=Some material book everyone knows (or not) ;Some comment<br />
<br />
[EN10027]<br />
; steel standard EN 10027-1<br />
Name=S235JR+AR <br />
<br />
[Graphic]<br />
Color_Emissiv = 255,255,255<br />
<br />
== Material properties ==<br />
Here now the description of agreed material-properties. Feel free to add a subsection for the material-properties of you field of expertise. <br />
<br />
=== General ===<br />
<br />
{| border="1" style="text-align:left; width:80%;"<br />
|+ General material properties<br />
|-<br />
! property name<br />
! Description<br />
! Unit/Data-Type<br />
|-<br />
! Name<br />
| Unique name of the property, following the rules described above || ASCII string 7-bit<br />
|-<br />
! Father<br />
| Name of the material group this material belongs to. If defined this material inherits all the father properties. That means if not defined the father properties will be used. || ASCII string 7-bit<br />
|-<br />
! Description<br />
| A placeholder for a longer description of the material || ASCII string 7-bit<br />
|-<br />
! SpecificWeight<br />
| The specific weight (also known as the unit weight) is the weight per unit volume of a material. see: [http://en.wikipedia.org/wiki/Specific_weight Specific_weight] || kg/mm^3<br />
|-<br />
! Vendor<br />
| Specifies the brand or vendor of the material || ASCII string 7-bit<br />
|-<br />
! ProductURL<br />
| An URL where to find more information about the material || ASCII string 7-bit<br />
|-<br />
! SpecificPrice<br />
| The price per unit of this material. Units can vary a lot (USD/m³, EUR/piece, etc...) || ASCII string 7-bit<br />
|}<br />
<br />
'''ToDos:''' add some properties with an ordering system for materials (metal, alloy, mineral, wood, ....)<br />
<br />
=== Mechanical ===<br />
<br />
{| border="1" style="text-align:left; width:80%;"<br />
|+ Material properties used in mechanical engineering <br />
|-<br />
! property name<br />
! Description<br />
! Unit/Data-Type<br />
|-<br />
! YoungsModulus<br />
| Young's modulus, also known as the tensile modulus or elastic modulus, is a measure of the stiffness of an elastic material and is a quantity used to characterize materials. See: [http://en.wikipedia.org/wiki/Young%27s_modulus Young's modulus]<br />
|| kg*mm^-1*s^-2 (kPa) <br />
|-<br />
!UltimateTensileStrength<br />
| Des...<br />
|| N'*mm^-2 (kPa)<br />
|-<br />
!Hardness<br />
| Des...<br />
|| <br />
|-<br />
! EN-10027-1<br />
| In case of steel material the [http://en.wikipedia.org/wiki/Steel_grades Steel grade] as defined in the [http://en.wikipedia.org/wiki/European_Committee_for_Standardization European standard] No. 10027-1. || string ASCII 7-bit <br />
|}<br />
<br />
'''ToDos:''' further add properties needed for mechanical design.<br />
<br />
=== Graphical ===<br />
This section defines material-properties which are related to the visual appearance of the material. The <br />
<br />
{| border="1" style="text-align:left; width:80%;"<br />
|+ visual appearance <br />
|-<br />
! property name<br />
! Description<br />
! Unit/Data-Type<br />
|-<br />
! AmbientColor<br />
| Ambient color in the Coin3D color model|| float,float,float range: 0.0-1.0<br />
|-<br />
! DiffuseColor<br />
| Diffuse color in the Coin3D color model|| float,float,float range: 0.0-1.0<br />
|-<br />
! SpecularColor<br />
| Specular color in the Coin3D color model|| float,float,float range: 0.0-1.0<br />
|-<br />
! EmissiveColor<br />
| Emissive color in the Coin3D color model|| float,float,float range: 0.0-1.0<br />
|-<br />
! Shininess<br />
| Ambient color in the Coin3D color model|| float range: 0.0-1.0<br />
|-<br />
! Transparency<br />
| Ambient color in the Coin3D color model|| float range: 0.0-1.0<br />
|-<br />
! VertxShader<br />
| Vertex shader program as defined in [http://de.wikipedia.org/wiki/OpenGL_Shading_Language GlSl] || Multi line string ASCII 7-bit<br />
|-<br />
! FragmentShader<br />
| Fragment shader program as defined in [http://de.wikipedia.org/wiki/OpenGL_Shading_Language GlSl] || Multi line string ASCII 7-bit<br />
|}<br />
<br />
<br />
<br />
=== Finite Element Method ===<br />
<br />
'''ToDos:''' Build up collection of FEM material properties.<br />
<br />
=== Computational Fluid Dynamics ===<br />
<br />
'''ToDos:''' Build up collection of CFM material properties.<br />
<br />
=== Architecture and BIM ===<br />
<br />
{| border="1" style="text-align:left; width:80%;"<br />
|+ Material properties used in architectural design <br />
|-<br />
! property name<br />
! Description<br />
! Unit/Data-Type<br />
|-<br />
! StandardFormat<br />
| The standard specification system used in this material (ASTM, MasterFormat, CSI, OmniClass, etc...)|| String ASCII 7-bit<br />
|-<br />
! StandardCode<br />
| The specific code of this material in the above standard format|| String ASCII 7-bit<br />
|-<br />
! FireStandard<br />
| The fire rating standard used in the material|| String ASCII 7-bit<br />
|-<br />
! FireClass<br />
| The [http://en.wikipedia.org/wiki/Fire-resistance_rating fire resistance class] of the material in the above standard|| String ASCII 7-bit<br />
|-<br />
! ThermalConductivity<br />
| The [http://en.wikipedia.org/wiki/Thermal_conductivity thermal conductivity (R or lambda coefficient)] that indicates the capacity to transfer heat of a material || W/m²K<br />
|-<br />
! SoundTransmission<br />
| The sound transmission coefficient of this material || W/m²K<br />
|-<br />
! Finish<br />
| The type of finishing/coating of this material|| String ASCII 7-bit<br />
|-<br />
! Color<br />
| The color of this material|| String ASCII 7-bit<br />
|-<br />
! UnitsArea<br />
| The number of units of this material necessary to fill a certain area|| String ASCII 7-bit<br />
|}<br />
'''ToDos:''' add sustainability & LEED properties<br />
<br />
[[Category:Roadmap]]<br />
<br />
{{languages | {{it|Material/it}} }}</div>Jriegel