https://www.freecadweb.org/wiki/api.php?action=feedcontributions&user=Jriegel&feedformat=atom FreeCAD Documentation - User contributions [en] 2019-08-22T00:19:58Z User contributions MediaWiki 1.30.0 https://www.freecadweb.org/wiki/index.php?title=Units&diff=102744 Units 2014-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)&quot;') # 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 /> &quot;mm&quot; 1.0; // millimeter (internal standard length)<br /> &quot;m&quot; 1000.0; // meter<br /> &quot;cm&quot; 10.0; // centimeter<br /> &quot;dm&quot; 100.0; // decimeter<br /> &quot;km&quot; 1000000.0; // kilometer<br /> Imperial lenth<br /> &quot;in&quot; &quot;\&quot;&quot; 25.4; // inch<br /> &quot;ft&quot; &quot;'&quot; 304.8; // foot<br /> &quot;th&quot; 0.0254; // thou<br /> &quot;yr&quot; 914.4; // yard<br /> Metric mass<br /> &quot;kg&quot; 1.0; // kilogram (internal standard mass)<br /> &quot;g&quot; 0.001; // gram<br /> &quot;mg&quot; 0.000001; // milligram<br /> &quot;t&quot; 1000.0; // ton <br /> Imperial mass<br /> &quot;lb&quot; 0.45359237; // pound<br /> &quot;oz&quot; 0.45359237; // ounce<br /> &quot;st&quot; 6.35029318; // Stone<br /> &quot;cwt&quot; 50.80234544;// hundredweights<br /> Angle<br /> &quot;deg&quot; 1.0; // degree (internal standard angle)<br /> &quot;rad&quot; 180/M_PI; // radian <br /> &quot;gon&quot; 360.0/400.0;// gon <br /> Time<br /> &quot;s&quot; 1.0; // second (internal standard time)<br /> &quot;min&quot; 60.0; // minute<br /> &quot;h&quot; 3600.0; // hour <br /> Rest of SI<br /> &quot;A&quot; 1.0; // Ampere (internal standard electric current)<br /> &quot;K&quot; 1.0; // Kelvin (internal standard thermodynamic temperature)<br /> &quot;cd&quot; 1.0; // Candela (internal standard luminous intensity) <br /> &quot;mol&quot; 1.0; // Mole (internal standard amount of substance) <br /> Metric Volume<br /> &quot;µl&quot; 1.0; // microliter mm^3(derived standard volume)<br /> &quot;ml&quot; 1000.0; // milliliter cm^3 <br /> &quot;l&quot; 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,&quot;Tm&quot;],[1e+09,&quot;Gm&quot;],[1e+06,&quot;Mm&quot;],<br /> [1e+03,&quot;km&quot;],[1e+02,&quot;hm&quot;],[1e+01,&quot;dam&quot;],<br /> [1e+00,&quot;m&quot;],[1e-01,&quot;dm&quot;],[1e-02,&quot;cm&quot;],<br /> [1e-03,&quot;mm&quot;],[1e-06,&quot;µm&quot;],[1e-09,&quot;nm&quot;],<br /> [1e-12,&quot;pm&quot;],[1e-15,&quot;fm&quot;]<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 &lt;math&gt;\frac{initialMagnitude}{targetMagnitude}&lt;/math&gt;.<br /> <br /> The ''targetMagnitude'' is then simply obtained with the operation &lt;math&gt;\prod_{bu} targetMagnitude_{bu}^{signature_{bu}}&lt;/math&gt;, ''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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Units&diff=102743 Units 2014-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)&quot;') # 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 /> &quot;mm&quot; 1.0; // millimeter (internal standard length)<br /> &quot;m&quot; 1000.0; // meter<br /> &quot;cm&quot; 10.0; // centimeter<br /> &quot;dm&quot; 100.0; // decimeter<br /> &quot;km&quot; 1000000.0; // kilometer<br /> Imperial lenth<br /> &quot;in&quot; &quot;\&quot;&quot; 25.4; // inch<br /> &quot;fo&quot; &quot;'&quot; 304.8; // foot<br /> &quot;th&quot; 0.0254; // thou<br /> &quot;yr&quot; 914.4; // yard<br /> Metric mass<br /> &quot;kg&quot; 1.0; // kilogram (internal standard mass)<br /> &quot;g&quot; 0.001; // gram<br /> &quot;mg&quot; 0.000001; // milligram<br /> &quot;t&quot; 1000.0; // ton <br /> Imperial mass<br /> &quot;lb&quot; 0.45359237; // pound<br /> &quot;oz&quot; 0.45359237; // ounce<br /> &quot;st&quot; 6.35029318; // Stone<br /> &quot;cwt&quot; 50.80234544;// hundredweights<br /> Angle<br /> &quot;deg&quot; 1.0; // degree (internal standard angle)<br /> &quot;rad&quot; 180/M_PI; // radian <br /> &quot;gon&quot; 360.0/400.0;// gon <br /> Time<br /> &quot;s&quot; 1.0; // second (internal standard time)<br /> &quot;min&quot; 60.0; // minute<br /> &quot;h&quot; 3600.0; // hour <br /> Rest of SI<br /> &quot;A&quot; 1.0; // Ampere (internal standard electric current)<br /> &quot;K&quot; 1.0; // Kelvin (internal standard thermodynamic temperature)<br /> &quot;cd&quot; 1.0; // Candela (internal standard luminous intensity) <br /> &quot;mol&quot; 1.0; // Mole (internal standard amount of substance) <br /> Metric Volume<br /> &quot;µl&quot; 1.0; // microliter mm^3(derived standard volume)<br /> &quot;ml&quot; 1000.0; // milliliter cm^3 <br /> &quot;l&quot; 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,&quot;Tm&quot;],[1e+09,&quot;Gm&quot;],[1e+06,&quot;Mm&quot;],<br /> [1e+03,&quot;km&quot;],[1e+02,&quot;hm&quot;],[1e+01,&quot;dam&quot;],<br /> [1e+00,&quot;m&quot;],[1e-01,&quot;dm&quot;],[1e-02,&quot;cm&quot;],<br /> [1e-03,&quot;mm&quot;],[1e-06,&quot;µm&quot;],[1e-09,&quot;nm&quot;],<br /> [1e-12,&quot;pm&quot;],[1e-15,&quot;fm&quot;]<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 &lt;math&gt;\frac{initialMagnitude}{targetMagnitude}&lt;/math&gt;.<br /> <br /> The ''targetMagnitude'' is then simply obtained with the operation &lt;math&gt;\prod_{bu} targetMagnitude_{bu}^{signature_{bu}}&lt;/math&gt;, ''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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Assembly_project&diff=60772 Assembly project 2014-01-10T12:24:28Z <p>Jriegel: /* Organizing */</p> <hr /> <div>Here the project plan for the '''Assembly''' modul as part of the [[Development_roadmap]]<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> This is a software development project aimed to implement a Assembly and product creation capabilities. Its about implementing some '''core features''' into the CAD modules of FreeCAD, '''Part and Assembly'''.<br /> <br /> The development steps are planed here and tracked in the Issue tracking system to get a well formed change log: <br /> [http://apps.sourceforge.net/mantisbt/free-cad/my_view_page.php Issue tracker]<br /> <br /> == Outcome ==<br /> Aim of the project is to enable FreeCAD accomplish a design task like this one:<br /> <br /> [[Image:Gripper.jpg|400px]]<br /> <br /> This will be achived by using the '''Assembly''' to put all the different kind of<br /> parts together with constraints and stay as close as possible to the ISO 10303 specification to allow <br /> easy model exchange. <br /> <br /> Another aim is to utilize [http://en.wikipedia.org/wiki/Open_Dynamics_Engine ODE] for kinematics.<br /> <br /> == Brainstorming ==<br /> <br /> === Multi model ===<br /> [[Image:MultiModel.png|600px|right]]<br /> A key feature to real world designs is the ability to split a design <br /> into handleable pieces. Its impossible to work on all aspects of a design<br /> at the same time or alone. That is true for the geometry and also for<br /> engineering tasks like FEM or CAM. There for FreeCAD need the ability <br /> to split models. That opens some possibilities: <br /> * '''Late loading''' - Only need resources like Graphics and main memory for the piece you work on.<br /> * [http://en.wikipedia.org/wiki/Concurrent_engineering '''Concurrent engineering'''] - allows many people to work on the same design<br /> * Fine grained [http://en.wikipedia.org/wiki/Version_control '''Version control'''] - better control over various aspects of the design<br /> * and many more....<br /> <br /> A multi model design could look like that:<br /> <br /> === Project management ===<br /> Multi model means a lot of files belonging to one project, most likely under a common directory. <br /> A project file and a project browser can help organizing the files. Also <br /> it can save additional information about the project or a project website.<br /> <br /> 1. Two modes, the &quot;Simple&quot; and the &quot;Project&quot; mode. Simple mean only one document and all the assemblies and parts go in one document. If a Project is opened or created FreeCAD is in project mode.<br /> <br /> 2. Projects. The position of the FCPrj file on the drive defines a root directory. All Files below this dir are defined with relative paths to the root dir. A additional view on the left side will hold the ProjectExplorer which shows the dir tree with the handled files.<br /> This root dir is also used as root for a SVN sand box, which allows later ease sharing and Version control.<br /> External references (towards a dir outside root, a sever share or a web resource) will handled and showed separably in the ProjectExplorer (one pseudo dir for each file server or web server). This makes it possible to get a fast overview about external references and re-route them.<br /> <br /> === Copyright ===<br /> Now copyright of 3D models is a interesting field. 3D models do fall under <br /> the copyright. The copyright falls to the '''creator''' of the model. Its only possible to protect the shape, which is represented by the model,<br /> by a patent or a design patent (US).<br /> But patents cover only the creation of a physical part to earn money. <br /> As an example the [http://patft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;Sect2=HITOFF&amp;d=PALL&amp;p=1&amp;u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&amp;r=1&amp;f=G&amp;l=50&amp;s1=D464,651.PN.&amp;OS=PN/D464,651&amp;RS=PN/D464,651 Microsoft Mouse design patent].<br /> <br /> So we have to remember the creator (copyright holder) and any kind<br /> of license for each model/product/file of a design. <br /> For the license I would use the CC type licenses.<br /> http://creativecommons.org/<br /> <br /> Abbreviation Keys for CC licenses:<br /> * BY = Attribution only<br /> * BY-ND = Attribution-NoDerivatives<br /> * BY-NC-ND = Attribution-NonCommercial- NoDerivatives<br /> * BY-NC = Attribution-NonCommercial<br /> * BY-NC-SA = Attribution-NonCommercial- ShareAlike<br /> * BY-SA = Attribution-ShareAlike<br /> * PD = Dedicated to or marked as being in the public domain via one of our public domain tools, or other public domain work; adaptations of works in the public domain may be built upon and licensed by the creator under any license terms desired <br /> <br /> Additional a URL link to the full license document (in case of custom licenses)<br /> <br /> === ISO 10303 ===<br /> The ISO 10303 (STEP) is very important in this field. Its the only good standardized and widely discussed<br /> and recognized definition of product structures I know of. <br /> [[Image:Product structure modeling Process-Data diagram.gif|500px|right]]<br /> <br /> Here some links with info:<br /> * [http://en.wikipedia.org/wiki/ISO_10303 ISO 10303 on Wikipedia]<br /> * [http://www.wikistep.org/index.php/Main_Page WikiStep.org] with a lot of basic info but mostly toward STEP-NC<br /> * The [http://www.wikistep.org/index.php/Product_Basics product structure] in STEP<br /> * Some [http://www.wikistep.org/index.php/STEP_Tutorial examples] about STEP<br /> * [http://en.wikipedia.org/wiki/ISO_10303-11 ISO 10303-11] about the modeling language (EXPRESS)<br /> * [http://en.wikipedia.org/wiki/Product_Structure_Modeling A Wikipedia article] about product modeling<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part41 Overview of Part 41 -- Fundamentals of Product Description and Support]<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part44 Overview of Part 44 (edition 2) -- Product Structure Configuration]<br /> * [http://www.steptools.com/support/stdev_docs/express/ap214/index.html Examples of small AP 214 files]<br /> <br /> === Assembly constraints ===<br /> An important role in building up large models and products take the assembly constraints, which formulate <br /> certain rules how parts assemble a product. Mainly these are Fix, FaceToFace, Angle, Offset and some kind of <br /> pattern instantiation. This constraints need a specialized solver to keep them up if the parts change. <br /> This solver is fundamentally different to the Sketch solver. I think we have to go for a graph based approach on this...<br /> <br /> === Kinematics ===<br /> A further step would be to use [http://ode.org/ ODE], or similar libs, to put the parts and the assembly constraints together to <br /> do a kinematic simulation of machines. That would allow checking for collisions and exploring the conditions of <br /> a mechanical system.<br /> <br /> === Revision control ===<br /> An important point is the version control and distributed development. With multi model design we are able to <br /> split designs in smaller pieces and can distribute work among a team. For a software developer &quot;distributed&quot; and &quot;Version&quot; <br /> sounds familiar, so why not use a [http://en.wikipedia.org/wiki/Distributed_Version_Control_System DVCS]. <br /> A good comparison is [http://en.wikipedia.org/wiki/Comparison_of_revision_control_software#Technical_information here].<br /> <br /> Since we deal with big data, and data which can not be easily diffed, we are limited to those which use the snapshot persistence model.<br /> Any system storing just diffs will have grave problems with our data (personally tested with Mercurial and Catia files). <br /> After sorting out commercial and non-free, basically only [http://en.wikipedia.org/wiki/Git_%28software%29 Git] and [http://subversion.apache.org/ SVN] remains.<br /> <br /> Using Git for the task leaves us with two big frontiers:<br /> * Git is very complicated; Branching merging and tagging along a non linear development path let alone merging with remote repositories (push, pull) <br /> will put a lot of complexity in that matter. To hide it from the user will be a challenging task. <br /> * Git allow Merge and Diff handlers for certain file types; We need one for .fcstd. This handler has to examine two FreeCAD <br /> documents and show and merge differences in the objects, features and parameters. Also not easy.<br /> <br /> But using git would open a lot of possibilities even high class PLM system would dream of...<br /> <br /> == Organizing ==<br /> <br /> Here some development task needed for a decent Assembly/Product design: <br /> <br /> === Infrastructure ===<br /> <br /> the assembly will demand some changes in the base system <br /> and infrastructure layer of FreeCAD.<br /> <br /> ==== Multi model ====<br /> Multi-Model was in mind from the beginning of FreeCADs design. There fore we have a multi document<br /> interface and can load unlimited documents. But we need to upgrade especially the 3D-Viewer to handle <br /> showing more the one document in its view (Part-Trees).<br /> <br /> ==== Part-Trees ====<br /> Since in Assembly the composition of parts and sub-assemblies is the main workflow, the tools <br /> to stack (group) Parts in a tree have to be implemented. Unlike a DocumentObjectGroup the <br /> Assembly group has to deal with visibility and placement of the children. Best done by <br /> stacking ViewProvider on each other. That need a kind of ClaimChildren() interface to the <br /> ViewProviders. <br /> <br /> ==== Unified Drag/Drop/Copy/Paste interface ====<br /> A interface allow ViewProvider and Workbenches full control about Drag/Drop/Copy/Paste<br /> operations in the tree or the 3D view. <br /> <br /> ==== external resources ==== <br /> Handling of doped links (from internal or external browsers). Means <br /> loading resources over (potential) slow connections (http).<br /> <br /> === Material ===<br /> Describing material and its properties is a vital part of a CAD/CAE system. Material has a lot of properties and names heavily dependent on the field its use. E.g. FEM and mechanical engineering have different frameworks and standards to describe Material. <br /> <br /> For the Material description a special article is made: [[Material]]<br /> <br /> === Object model ===<br /> Class tree to deal with concepts needed. References, interfaces, document links, views, compounds, constraints, configurations, and many more...<br /> <br /> == STEP check loop ==<br /> Implementing a first STEP importer for more then geometry and color to check if the object model holds for a wider usage. <br /> <br /> === Assembly constraint solver ===<br /> Define a interface to a assembly constraint solver, very similar to the Sketcher solver interface.<br /> <br /> === Physics simulation interface ===<br /> Interface to allow a (external) (multi)physics simulation software to take control over the positioning <br /> of the Parts of a assembly. This would allow to use &quot;bullet&quot; or &quot;ODE&quot; to do kinematic tests and DMU.<br /> <br /> == Next actions ==<br /> <br /> * Object model<br /> * wait for the 0.12 release branch happened <br /> <br /> <br /> [[Category:Roadmap]]<br /> <br /> {{languages | {{de|Assembly_project/de}} {{es|Assembly_project/es}} {{fr|Assembly_project/fr}} {{it|Assembly_project/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=FEM_project&diff=60769 FEM project 2014-01-10T12:18:33Z <p>Jriegel: </p> <hr /> <div>&lt;translate&gt;<br /> &lt;!--T:1--&gt;<br /> This is the project plan for the FreeCAD FEM integration as part of the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles == &lt;!--T:2--&gt;<br /> <br /> == Outcome == &lt;!--T:3--&gt;<br /> Simple [[Fem_Workbench|FEM]] chain to start the matter. Which is capable of meshing a Part (automatic) and compute<br /> some standard stuff like stiffnes and frequencies. <br /> <br /> &lt;!--T:4--&gt;<br /> The framework should allow tetrahedral and hex meshes. Writing the output decks as python plugin to ease<br /> use different solver. Simple post-processing with the ability to extend by python. <br /> <br /> == Brainstorming == &lt;!--T:5--&gt;<br /> <br /> === potential Meshers === &lt;!--T:6--&gt;<br /> [[Image:Netgen.jpg|300px|right]]<br /> <br /> &lt;!--T:7--&gt;<br /> Some meshers out there<br /> * [http://www.hpfem.jku.at/netgen/ Netgen] very good mesher, LGPL with some library suport<br /> * [http://www.salome-platform.org/ Salome] complicated package, hard to get the code we need!?<br /> * [http://www.pythonocc.org/ PythonOCC] python library wrapping Salome and Netgen meshers may be the quickest and most complete way to integrate meshers<br /> <br /> === potential Solvers === &lt;!--T:8--&gt;<br /> some solver out there<br /> * [http://www.calculix.de/ Calculix] <br /> * [http://www.code-aster.org Code-Aster] very broad solver with python bindings<br /> * [http://www.pythonocc.org/ PythonOCC] python library that also offers a (currently) rough interface to Code_Aster which would also be a quick way to have a 1st working solution<br /> <br /> === calculix examples === &lt;!--T:9--&gt;<br /> * [http://dip28p.web.fc2.com/calculix/netgen2calculix/index.html gut example with contact]<br /> <br /> == Organizing == &lt;!--T:10--&gt;<br /> <br /> === Mesher === &lt;!--T:11--&gt;<br /> * Testing the mesh generators by experts<br /> * Analysing software structure and possible integration<br /> <br /> <br /> == Next actions == &lt;!--T:12--&gt;<br /> * Setting up [[Fem_Workbench]] (done)<br /> * Starting optimized visuals for SALOME mesh (ongoing)<br /> * Interface for adding post-processing information (color, displacement) to the Fem Visual. (done)<br /> * Writing a valid CalculiX INP file.<br /> * loading FRD (done)<br /> <br /> <br /> <br /> &lt;!--T:13--&gt;<br /> [[Category:Roadmap]]<br /> <br /> &lt;/translate&gt;<br /> &lt;languages/&gt;</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=MIBA&diff=60143 MIBA 2014-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(&quot;C:/Documents and Settings/jriegel/My Documents/Projects/FreeCAD/data/Blade.stp&quot;)<br /> OutDir = 'c:/temp/'<br /> Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)<br /> <br /> # creating images with different Views, Cameras and sizes<br /> for p in [&quot;PerspectiveCamera&quot;,&quot;OrthographicCamera&quot;]:<br /> Gui.SendMsgToActiveView(p)<br /> for f in [&quot;ViewAxo&quot;,&quot;ViewFront&quot;,&quot;ViewTop&quot;]:<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 + &quot;Blade_&quot; + p +&quot;_&quot; + f + &quot;_&quot; + x + &quot;_&quot; + y + &quot;.jpg&quot;,x,y,&quot;White&quot;)<br /> Gui.ActiveDocument.ActiveView.saveImage(OutDir + &quot;Blade_&quot; + p +&quot;_&quot; + f + &quot;_&quot; + x + &quot;_&quot; + y + &quot;.png&quot;,x,y,&quot;Transparent&quot;)<br /> <br /> # close active document<br /> App.closeDocument(App.ActiveDocument.Name)<br /> <br /> {{languages | {{es|MIBA/es}} {{fr|MIBA/fr}} {{it|MIBA/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=MIBA&diff=60142 MIBA 2014-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(&quot;C:/Documents and Settings/jriegel/My Documents/Projects/FreeCAD/data/Blade.stp&quot;)<br /> OutDir = 'c:/temp/'<br /> Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)<br /> <br /> # creating images with different Views, Cameras and sizes<br /> for p in [&quot;PerspectiveCamera&quot;,&quot;OrthographicCamera&quot;]:<br /> Gui.SendMsgToActiveView(p)<br /> for f in [&quot;ViewAxo&quot;,&quot;ViewFront&quot;,&quot;ViewTop&quot;]:<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 + &quot;Blade_&quot; + p +&quot;_&quot; + f + &quot;_&quot; + x + &quot;_&quot; + y + &quot;.jpg&quot;,x,y,&quot;White&quot;)<br /> Gui.ActiveDocument.ActiveView.saveImage(OutDir + &quot;Blade_&quot; + p +&quot;_&quot; + f + &quot;_&quot; + x + &quot;_&quot; + y + &quot;.png&quot;,x,y,&quot;Transparent&quot;)<br /> <br /> # close active document<br /> App.closeDocument(App.ActiveDocument.Name)<br /> <br /> {{languages | {{es|MIBA/es}} {{fr|MIBA/fr}} {{it|MIBA/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=FEM_project&diff=59867 FEM project 2014-01-07T11:52:12Z <p>Jriegel: /* Brainstorming */</p> <hr /> <div>This is the project plan for the FreeCAD FEM integration as part of the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> <br /> == Outcome ==<br /> Simple [[Fem_Workbench|FEM]] chain to start the matter. Which is capable of meshing a Part (automatic) and compute<br /> some standard stuff like stiffnes and frequencies. <br /> <br /> The framework should allow tetrahedral and hex meshes. Writing the output decks as python plugin to ease<br /> use different solver. Simple post-processing with the ability to extend by python. <br /> <br /> == Brainstorming ==<br /> <br /> === potential Meshers ===<br /> [[Image:Netgen.jpg|300px|right]]<br /> <br /> Some meshers out there<br /> * [http://www.hpfem.jku.at/netgen/ Netgen] very good mesher, LGPL with some library suport<br /> * [http://www.salome-platform.org/ Salome] complicated package, hard to get the code we need!?<br /> * [http://www.pythonocc.org/ PythonOCC] python library wrapping Salome and Netgen meshers may be the quickest and most complete way to integrate meshers<br /> === potential Solvers ===<br /> some solver out there<br /> * [http://www.calculix.de/ Calculix] <br /> * [http://www.code-aster.org Code-Aster] very broad solver with python bindings<br /> * [http://www.pythonocc.org/ PythonOCC] python library that also offers a (currently) rough interface to Code_Aster which would also be a quick way to have a 1st working solution<br /> <br /> === calculix examples ===<br /> <br /> * [http://dip28p.web.fc2.com/calculix/netgen2calculix/index.html gut example with contact]<br /> <br /> == Organizing ==<br /> <br /> === Mesher ===<br /> * Testing the mesh generators by experts<br /> * Analysing software structure and possible integration<br /> <br /> <br /> == Next actions ==<br /> <br /> * Setting up [[Fem_Workbench]] (done)<br /> * Starting optimized visuals for SALOME mesh (ongoing)<br /> * Interface for adding post-processing information (color, displacement) to the Fem Visual. <br /> <br /> <br /> [[Category:Roadmap]]<br /> <br /> {{languages | {{es|FEM_project/es}} {{fr|FEM_project/fr}} {{it|FEM_project/it}} {{ru|FEM_project/ru}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Fem_Workbench&diff=59135 Fem Workbench 2014-01-02T21:55:13Z <p>Jriegel: /* Python scripting */</p> <hr /> <div>The '''Fem Workbench''' offers data structures and commands to work with [http://en.wikipedia.org/wiki/Finite_element_method Fem meshes].<br /> <br /> <br /> == General == <br /> <br /> [[Image:FemWorkbench.jpg]]<br /> <br /> == Comand reference ==<br /> <br /> == Doing a analysis ==<br /> <br /> === Analysis types ===<br /> <br /> === creating or importing meshes/parts ===<br /> <br /> === Material definition ===<br /> Every analysis needs at least one Material object to be fully defined. The easiest is to add a FreeCAD standard material. FreeCAD comes if a set of Material definitions you can use out of the box. But you can define additinal ones very easy. The [[Material|FreeCAD material system]] allows a lot of additional values if needed. A good source to find material values is the [http://www.matweb.com/ matweb.com/] web site. <br /> <br /> == Import/Export ==<br /> <br /> == Python scripting ==<br /> <br /> === Creating meshes &quot;by hand&quot; ===<br /> <br /> ==== creation of meshes ====<br /> Creating a mesh with one Tet-10 Elements:<br /> &lt;syntaxhighlight&gt;<br /> import FreeCAD, Fem<br /> <br /> # create a empty mesh<br /> m = Fem.FemMesh()<br /> #create the nodes<br /> m.addNode(0,1,0)<br /> m.addNode(0,0,1)<br /> m.addNode(1,0,0)<br /> m.addNode(0,0,0)<br /> m.addNode(0,0.5,0.5)<br /> m.addNode(0.5,0.03,.5)<br /> m.addNode(0.5,0.5,0.03)<br /> m.addNode(0,0.5,0)<br /> m.addNode(0.03,0,0.5)<br /> m.addNode(0.5,0,0)<br /> # add the volume with the created nodes<br /> m.addVolume([1,2,3,4,5,6,7,8,9,10])<br /> <br /> Fem.show(m)<br /> &lt;/syntaxhighlight&gt;<br /> <br /> If you want to have predefined element and node numbering:<br /> <br /> &lt;syntaxhighlight&gt;<br /> <br /> m.addNode(0.0,1.0,0.0,1)<br /> <br /> m.addVolume([1,2,3,4,5,6,7,8,9,10],1)<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==== Visual handling ====<br /> <br /> Highlight some nodes on the view:<br /> &lt;syntaxhighlight&gt;<br /> import FreeCAD, Fem<br /> <br /> m = Fem.FemMesh()<br /> <br /> m.addNode(0,1,0)<br /> m.addNode(0,0,1)<br /> m.addNode(1,0,0)<br /> m.addNode(0,0,0)<br /> m.addNode(0,0.5,0.5)<br /> m.addNode(0.5,0.03,.5)<br /> m.addNode(0.5,0.5,0.03)<br /> m.addNode(0,0.5,0)<br /> m.addNode(0.03,0,0.5)<br /> m.addNode(0.5,0,0)<br /> m.addVolume([1,2,3,4,5,6,7,8,9,10])<br /> <br /> Fem.show(m)<br /> Gui.ActiveDocument.ActiveObject.HighlightedNodes = [1,2,3]<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Postprocessing colors and displacement:<br /> <br /> Highlight some nodes on the view:<br /> &lt;syntaxhighlight&gt;<br /> # set the volume 1 to red<br /> Gui.ActiveDocument.ActiveObject.ElementColor= {1:(1,0,0)}<br /> # set the node 1 and 2 to a certain Color and interpolate the survace<br /> Gui.ActiveDocument.ActiveObject.NodeColor= {1:(1,0,0),2:(1,0,0)}<br /> # set the node 1 and 2 to a certain displacement<br /> Gui.ActiveDocument.ActiveObject.NodeDisplacement= {1:FreeCAD.Vector(1,0,0),2:FreeCAD.Vector(1,0,0)}<br /> # double the factor of the displacement shown<br /> Gui.ActiveDocument.ActiveObject.animate(2.0)<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> == Element Types ==<br /> This description is based on the MED format as described [https://hammi.extra.cea.fr/static/MED/web_med/logiciels/med-2.3.1/doc/html/modele_de_donnees.html#3. here].<br /> <br /> === Segment element ===<br /> [[Image:segments.gif]]<br /> <br /> === Triangle element ===<br /> [[Image:triangles.gif]]<br /> <br /> === quadratic element ===<br /> [[Image:quadrangles.gif]]<br /> <br /> === Tetrahedron element ===<br /> [[Image:tetraedres.gif|right]]<br /> <br /> <br /> {| class=&quot;wikitable&quot; style=&quot;color:green; background-color:#ffffcc;&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;1&quot;<br /> |+ '''Tetrahedron with four or ten nodes'''<br /> |-<br /> ! Edge !! Node 1 !! Node 2 !! Middle node<br /> |-<br /> | A1 || N1 || N2 || N5<br /> |-<br /> | A2 || N2 || N3 || N6<br /> |-<br /> | A3 || N3 || N1 || N7<br /> |-<br /> | A4 || N1 || N4 || N8<br /> |-<br /> | A5 || N2 || N4 || N9<br /> |-<br /> | A6 || N3 || N4 || N10<br /> |}<br /> <br /> {| class=&quot;wikitable&quot; style=&quot;color:green; background-color:#ffffcc;&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;1&quot;<br /> |+ '''Tetrahedron Faces'''<br /> |-<br /> ! Face !! Edge 1 !! Edge 2 !! Edge 3<br /> |-<br /> | F1 || A1 || A2 || A3<br /> |-<br /> | F2 || A4 ||-A5 ||-A1<br /> |-<br /> | F3 || A5 ||-A6 ||-A2<br /> |-<br /> | F4 || A6 ||-A4 ||-A3 <br /> |}<br /> <br /> === Pyramid element ===<br /> [[Image:pyramides.gif]]<br /> <br /> === Hexahedron element ===<br /> [[Image:hexaedres.gif|right]]<br /> <br /> <br /> <br /> {| class=&quot;wikitable&quot; style=&quot;color:green; background-color:#ffffcc;&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;1&quot;<br /> |+ '''Hexahedron with eight or twenty nodes'''<br /> |-<br /> ! Edge !! Node 1 !! Node 2 !! Middle node<br /> |-<br /> | A1 || N1 || N2 || N9<br /> |-<br /> | A2 || N2 || N3 || N10<br /> |-<br /> | A3 || N3 || N4 || N11<br /> |-<br /> | A4 || N4 || N1 || N12<br /> |-<br /> | A5 || N5 || N6 || N13<br /> |-<br /> | A6 || N6 || N7 || N14<br /> |-<br /> | A7 || N7 || N7 || N15<br /> |-<br /> | A8 || N8 || N5 || N16<br /> |-<br /> | A9 || N1 || N5 || N17<br /> |-<br /> | A10|| N2 || N6 || N18<br /> |-<br /> | A11|| N3 || N7 || N19<br /> |-<br /> | A12|| N4 || N8 || N20<br /> |}<br /> <br /> {| class=&quot;wikitable&quot; style=&quot;color:green; background-color:#ffffcc;&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;1&quot;<br /> |+ '''Hexahedron faces'''<br /> |-<br /> ! Face !! Edge 1 !! Edge 2 !! Edge 3 !! Edge 4<br /> |-<br /> | F1 || A1 || A2 || A3 || A4<br /> |-<br /> | F2 ||-A8 ||-A7 ||-A6 ||-A5<br /> |-<br /> | F3 || A9 || A5 ||-A10||-A1<br /> |-<br /> | F4 || A10|| A6 ||-A11||-A2 <br /> |-<br /> | F5 || A11|| A7 ||-A12||-A3 <br /> |-<br /> | F6 || A12|| A8 ||-A9 ||-A4 <br /> |}<br /> <br /> === Pentahedron element ===<br /> [[Image:pentaedres.gif]]<br /> <br /> <br /> <br /> <br /> {{docnav|Workbenches|Part Module}}<br /> <br /> {{languages | {{de|Fem_Workbench/de}} {{fr|Fem_Workbench/fr}} {{it|Fem_Workbench/it}} }}<br /> <br /> <br /> [[Category:User Documentation]]</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=InputField&diff=55663 InputField 2013-12-16T08:17:41Z <p>Jriegel: Created page with &quot;This is the documentation of the FreeCAD 'InputField' widgets, which get used in most of the dialogs handling parameter with units. ToDo...&quot;</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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=55662 Quantity 2013-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 /> ** &quot;nm&quot; <br /> ** &quot;µm&quot; <br /> ** &quot;mm&quot; <br /> ** &quot;cm&quot; <br /> ** &quot;dm&quot; <br /> ** &quot;m&quot; <br /> ** &quot;km&quot; <br /> ** &quot;in&quot; <br /> ** &quot;ft&quot; <br /> ** &quot;thou&quot;<br /> ** &quot;mil&quot; <br /> ** &quot;yd&quot; <br /> ** &quot;mi&quot; <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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=54735 Quantity 2013-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 /> ** &quot;nm&quot; <br /> ** &quot;µm&quot; <br /> ** &quot;mm&quot; <br /> ** &quot;cm&quot; <br /> ** &quot;dm&quot; <br /> ** &quot;m&quot; <br /> ** &quot;km&quot; <br /> ** &quot;in&quot; <br /> ** &quot;ft&quot; <br /> ** &quot;thou&quot;<br /> ** &quot;mil&quot; <br /> ** &quot;yd&quot; <br /> ** &quot;mi&quot; <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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=STEP_project&diff=54731 STEP project 2013-12-12T17:41:13Z <p>Jriegel: /* general STEP */</p> <hr /> <div>This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] process. The projects are collected in the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> This is a development project to find, discuss and implement a more advanced STEP i/o in FreeCAD. <br /> <br /> == Outcome ==<br /> * reading/writing complex STEP files into Assembly data definition (with color and all the additional information).<br /> * ....<br /> <br /> == Brainstorming ==<br /> First we need to colect all the information about the matter <br /> <br /> === general STEP ===<br /> The ISO 10303 (STEP) is very important in this field. Its the only good standardized and widely discussed<br /> and recognized definition of product structures I know of. <br /> [[Image:Product structure modeling Process-Data diagram.gif|500px|right]]<br /> <br /> Here some links with info:<br /> * [http://en.wikipedia.org/wiki/ISO_10303 ISO 10303 on Wikipedia]<br /> * [http://www.wikistep.org/index.php/Main_Page WikiStep.org] with a lot of basic info but mostly toward STEP-NC<br /> * The [http://www.wikistep.org/index.php/Product_Basics product structure] in STEP<br /> * Some [http://www.wikistep.org/index.php/STEP_Tutorial examples] about STEP<br /> * [http://en.wikipedia.org/wiki/ISO_10303-11 ISO 10303-11] about the modeling language (EXPRESS)<br /> * [http://en.wikipedia.org/wiki/Product_Structure_Modeling A Wikipedia article] about product modeling<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part41 Overview of Part 41 -- Fundamentals of Product Description and Support]<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part44 Overview of Part 44 (edition 2) -- Product Structure Configuration]<br /> * [http://www.steptools.com/support/stdev_docs/express/ap214/index.html Examples of small AP 214 files]<br /> * [http://www.cax-if.org/library/index.html STEP validation models]<br /> * [http://jotneit.no/www2/www/pdm/pdm_schema/diagrams/diagram_0002.htm Interactive documentation with EXPRESS-G diagrams]<br /> * [http://stepcode.org/stepcode-use-doxygen STEPCode Doxygen docu with diagrams]<br /> <br /> === OCC step i/o information ===<br /> <br /> * [http://dev.opencascade.org/doc/overview/html/user_guides__step.html documentation on OCC step]<br /> <br /> == Organizing ==<br /> <br /> <br /> == Next actions ==<br /> <br /> * collecting information and testing OCC STEP classes<br /> <br /> <br /> [[Category:Roadmap]]</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=STEP_project&diff=54730 STEP project 2013-12-12T17:18:00Z <p>Jriegel: /* Brainstorming */</p> <hr /> <div>This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] process. The projects are collected in the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> This is a development project to find, discuss and implement a more advanced STEP i/o in FreeCAD. <br /> <br /> == Outcome ==<br /> * reading/writing complex STEP files into Assembly data definition (with color and all the additional information).<br /> * ....<br /> <br /> == Brainstorming ==<br /> First we need to colect all the information about the matter <br /> <br /> === general STEP ===<br /> The ISO 10303 (STEP) is very important in this field. Its the only good standardized and widely discussed<br /> and recognized definition of product structures I know of. <br /> [[Image:Product structure modeling Process-Data diagram.gif|500px|right]]<br /> <br /> Here some links with info:<br /> * [http://en.wikipedia.org/wiki/ISO_10303 ISO 10303 on Wikipedia]<br /> * [http://www.wikistep.org/index.php/Main_Page WikiStep.org] with a lot of basic info but mostly toward STEP-NC<br /> * The [http://www.wikistep.org/index.php/Product_Basics product structure] in STEP<br /> * Some [http://www.wikistep.org/index.php/STEP_Tutorial examples] about STEP<br /> * [http://en.wikipedia.org/wiki/ISO_10303-11 ISO 10303-11] about the modeling language (EXPRESS)<br /> * [http://en.wikipedia.org/wiki/Product_Structure_Modeling A Wikipedia article] about product modeling<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part41 Overview of Part 41 -- Fundamentals of Product Description and Support]<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part44 Overview of Part 44 (edition 2) -- Product Structure Configuration]<br /> * [http://www.steptools.com/support/stdev_docs/express/ap214/index.html Examples of small AP 214 files]<br /> * [http://www.cax-if.org/library/index.html STEP validation models]<br /> * [http://jotneit.no/www2/www/pdm/pdm_schema/diagrams/diagram_0002.htm Interactive documentation with diagrams]<br /> <br /> <br /> === OCC step i/o information ===<br /> <br /> * [http://dev.opencascade.org/doc/overview/html/user_guides__step.html documentation on OCC step]<br /> <br /> == Organizing ==<br /> <br /> <br /> == Next actions ==<br /> <br /> * collecting information and testing OCC STEP classes<br /> <br /> <br /> [[Category:Roadmap]]</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=STEP_project&diff=54729 STEP project 2013-12-12T14:16:37Z <p>Jriegel: /* Brainstorming */</p> <hr /> <div>This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] process. The projects are collected in the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> This is a development project to find, discuss and implement a more advanced STEP i/o in FreeCAD. <br /> <br /> == Outcome ==<br /> * reading/writing complex STEP files into Assembly data definition (with color and all the additional information).<br /> * ....<br /> <br /> == Brainstorming ==<br /> First we need to colect all the information about the matter <br /> <br /> === general STEP ===<br /> The ISO 10303 (STEP) is very important in this field. Its the only good standardized and widely discussed<br /> and recognized definition of product structures I know of. <br /> [[Image:Product structure modeling Process-Data diagram.gif|500px|right]]<br /> <br /> Here some links with info:<br /> * [http://en.wikipedia.org/wiki/ISO_10303 ISO 10303 on Wikipedia]<br /> * [http://www.wikistep.org/index.php/Main_Page WikiStep.org] with a lot of basic info but mostly toward STEP-NC<br /> * The [http://www.wikistep.org/index.php/Product_Basics product structure] in STEP<br /> * Some [http://www.wikistep.org/index.php/STEP_Tutorial examples] about STEP<br /> * [http://en.wikipedia.org/wiki/ISO_10303-11 ISO 10303-11] about the modeling language (EXPRESS)<br /> * [http://en.wikipedia.org/wiki/Product_Structure_Modeling A Wikipedia article] about product modeling<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part41 Overview of Part 41 -- Fundamentals of Product Description and Support]<br /> * [http://www.steptools.com/support/stdev_docs/express/step_irs/index.html#part44 Overview of Part 44 (edition 2) -- Product Structure Configuration]<br /> * [http://www.steptools.com/support/stdev_docs/express/ap214/index.html Examples of small AP 214 files]<br /> * [http://www.cax-if.org/library/index.html STEP validation models]<br /> <br /> <br /> === OCC step i/o information ===<br /> <br /> * [http://dev.opencascade.org/doc/overview/html/user_guides__step.html documentation on OCC step]<br /> <br /> == Organizing ==<br /> <br /> <br /> == Next actions ==<br /> <br /> * collecting information and testing OCC STEP classes<br /> <br /> <br /> [[Category:Roadmap]]</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=STEP_project&diff=54728 STEP project 2013-12-12T14:04:09Z <p>Jriegel: </p> <hr /> <div>This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] process. The projects are collected in the [[Development roadmap]].<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> This is a development project to find, discuss and implement a more advanced STEP i/o in FreeCAD. <br /> <br /> == Outcome ==<br /> * reading/writing complex STEP files into Assembly data definition (with color and all the additional information).<br /> * ....<br /> <br /> == Brainstorming ==<br /> First we need to colect all the information about the matter <br /> <br /> === general STEP ===<br /> <br /> === OCC step i/o information ===<br /> <br /> == Organizing ==<br /> <br /> <br /> == Next actions ==<br /> <br /> * collecting information and testing OCC STEP classes<br /> <br /> <br /> [[Category:Roadmap]]</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=54349 Quantity 2013-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 /> ** &quot;nm&quot; <br /> ** &quot;µm&quot; <br /> ** &quot;mm&quot; <br /> ** &quot;cm&quot; <br /> ** &quot;dm&quot; <br /> ** &quot;m&quot; <br /> ** &quot;km&quot; <br /> ** &quot;in&quot; <br /> ** &quot;ft&quot; <br /> ** &quot;thou&quot;<br /> ** &quot;mil&quot; <br /> ** &quot;yd&quot; <br /> ** &quot;mi&quot; <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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=STEP_project&diff=54348 STEP project 2013-12-11T06:51:08Z <p>Jriegel: Created page with &quot;This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done...&quot;</p> <hr /> <div>This template is the guideline for a FreeCAD development project. It follows the rules of the [http://en.wikipedia.org/wiki/Getting_Things_Done#Methodology Getting Things Done (GTD)] process. The projects are collected in the [[Development roadmap]].<br /> <br /> ''Lets start by looking at the Natural Planning Model. The Natural Planning Model really is nothing new. It is not some fantastic new model devised by David Allen to help us plan and manage our projects. it is however, the planning model that is recommended by David in his Getting Things Done book. The Natural Planning Model is based upon the planning that we do on a daily basis, using just our brains. For example, think of how many tasks we plan on a day by day basis that we do not even bother to write down as these are normally classed as mundane tasks. For example, getting dressed, or driving to work. All of these can be thought of tasks but we just go ahead and plan them without any thought whatsoever. We utilize the planning aspects of our brain that are conditioned for this natural type of planning.''<br /> <br /> ''You mind goes through five steps to accomplish virtually any task. These five steps are:''<br /> <br /> <br /> == Purpose and principles ==<br /> <br /> ''The first step in the model is to define '''purpose and principles'''. Think about the last time you booked a family holiday. There is always a purpose for the holiday. This could be to take a well earned break from work, to relax and spend quality time with your spouse and children, or simply to go and see a specific tourist attraction whilst on your holiday. Whatever the reason, there will have been purpose and principles for your trip. You don’t just get up one day and go on holiday, you implement stage one of the natural planning model and this is to have a purpose for the trip.''<br /> <br /> == Outcome ==<br /> ''The second step is '''outcome visioning'''. Once you had defined a purpose and the principle for your holiday, the next thing you will have done is to have a vision of the outcome, in other words, where do you want to go, when, and who with? This is classed as outcome visioning as you are thinking about the outcome of your holiday and making mental notes about what you want the outcome to be.''<br /> <br /> == Brainstorming ==<br /> ''The third step is '''brainstorming'''. This brainstorming is normally done within your mind, and also other people are usually included when the project or decision impacts upon them. For example, lets say you think about the Maldives for your holiday, but you are going in June. The brainstorming aspect will look at this and probably decide that as June is the rainy season in the Maldives, it may not be the best time to visit. This is a naturally creative aspect of your brain that helps narrow down the vision of the outcome into a definite decision. I say other people are included because for projects such as planning a holiday, you also have to take other peoples viewpoints into consideration. I am sure your spouse would have something to say if you booked the holiday with consulting, and brainstorming their viewpoints on the suitability of the trip and destination choice.<br /> ''<br /> <br /> == Organizing ==<br /> ''The next, and fourth step is '''organizing'''. Once you have generated your ideas about the project, or holiday in this case, you start to organize these ideas. For example, you may have thought about the travel agent to use for the booking, or whether to book direct, if the in-laws would like to come on the vacation also to double as baby sitters :-) etc. Your mind normally sorts and organizes these thoughts automatically.''<br /> <br /> == Next actions ==<br /> ''The last, and fifth step is to '''identify and set the next actions'''. The GTD methodology covers that the best way to get a task done, is to decide and set the next actions. We do not do tasks, we do next actions. So the best way to get your holiday booked is to decide what the next actions are. These normally would be items such as, look up the resort on the Internet, check online travel comparison sites for cheap flights and accommodation, call in and see a travel agent for their price and recommendation within the resort. Again, I would be surprised if any of you would take the time and effort to write these next actions down, but also, I would be surprised if any of you forgot these next actions. it is funny how our mind has a great way of remembering projects assigned and planning using the Natural Planning Method.''<br /> <br /> [[Category:Roadmap]]<br /> {{languages | {{es|Project_template/es}} {{fr|Project_template/fr}} {{it|Project_template/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Development_roadmap&diff=54347 Development roadmap 2013-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 '''&quot;It's done, when it's done!&quot;'''<br /> <br /> [[Category:Roadmap]]<br /> <br /> {{languages | {{es|Development_roadmap/es}} {{fr|Development_roadmap/fr}} {{it|Development_roadmap/it}} {{se|Development_roadmap/se}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=52915 Quantity 2013-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 /> ** &quot;nm&quot; <br /> ** &quot;ym&quot; <br /> ** &quot;mm&quot; <br /> ** &quot;cm&quot; <br /> ** &quot;dm&quot; <br /> ** &quot;m&quot; <br /> ** &quot;km&quot; <br /> ** &quot;in&quot; <br /> ** &quot;ft&quot; <br /> ** &quot;thou&quot;<br /> ** &quot;mil&quot; <br /> ** &quot;yd&quot; <br /> ** &quot;mi&quot; <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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=52914 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=52862 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51639 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yd&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51346 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // micro gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51345 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51344 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51343 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51342 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51341 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51338 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51337 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51336 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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') &gt; 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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51335 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51334 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=51019 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50985 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Mesh_Scripting&diff=50944 Mesh Scripting 2013-12-05T18:57:57Z <p>Jriegel: </p> <hr /> <div>=== Introduction ===<br /> <br /> First of all you have to import the Mesh module:<br /> &lt;source lang=&quot;python&quot;&gt;<br /> import Mesh<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> mesh = Mesh.Mesh()<br /> &lt;/source &gt;<br /> <br /> You can also create an object from a file<br /> <br /> &lt;source lang=&quot;python&quot;&gt;<br /> mesh = Mesh.Mesh('D:/temp/Something.stl')<br /> &lt;/source &gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source &gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> import BuildRegularGeoms<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br /> m = Mesh.Mesh(t)<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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(&quot;Mesh::Feature&quot;,&quot;Diff_Sphere_Cylinder&quot;).Mesh=diff<br /> d.recompute()<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> m.write(&quot;D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py&quot;)<br /> import SavedMesh<br /> m2 = Mesh.Mesh(SavedMesh.faces)<br /> &lt;/source&gt;<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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Mesh_Scripting&diff=50943 Mesh Scripting 2013-12-05T18:57:06Z <p>Jriegel: /* Introduction */</p> <hr /> <div>=== Introduction ===<br /> <br /> First of all you have to import the Mesh module:<br /> &lt;source lang=&quot;python&quot;&gt;<br /> import Mesh<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source &gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> import BuildRegularGeoms<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br /> m = Mesh.Mesh(t)<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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(&quot;Mesh::Feature&quot;,&quot;Diff_Sphere_Cylinder&quot;).Mesh=diff<br /> d.recompute()<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> m.write(&quot;D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py&quot;)<br /> import SavedMesh<br /> m2 = Mesh.Mesh(SavedMesh.faces)<br /> &lt;/source&gt;<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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Mesh_Scripting&diff=50940 Mesh Scripting 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source &gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> import BuildRegularGeoms<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> t = BuildRegularGeoms.Toroid(8.0, 2.0, 50) # list with several thousands triangles<br /> m = Mesh.Mesh(t)<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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(&quot;Mesh::Feature&quot;,&quot;Diff_Sphere_Cylinder&quot;).Mesh=diff<br /> d.recompute()<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> m.write(&quot;D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py&quot;)<br /> import SavedMesh<br /> m2 = Mesh.Mesh(SavedMesh.faces)<br /> &lt;/source&gt;<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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Mesh_Scripting&diff=50938 Mesh Scripting 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/source &gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<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(&quot;Mesh::Feature&quot;,&quot;Diff_Sphere_Cylinder&quot;).Mesh=diff<br /> d.recompute()<br /> &lt;/source&gt;<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 /> &lt;source lang=&quot;python&quot;&gt;<br /> m.write(&quot;D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py&quot;)<br /> import SavedMesh<br /> m2 = Mesh.Mesh(SavedMesh.faces)<br /> &lt;/source&gt;<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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Mesh_Scripting&diff=50937 Mesh Scripting 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<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 /> &lt;/python&gt;<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(&quot;Mesh::Feature&quot;,&quot;Diff_Sphere_Cylinder&quot;).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(&quot;D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py&quot;)<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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50936 Quantity 2013-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 /> &lt;source lang=&quot;python&quot;&gt;<br /> import FreeCAD<br /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50935 Quantity 2013-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 /> &lt;source lang=&quot;php&quot;&gt;<br /> import FreeCAD<br /> &lt;/source&gt;<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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50890 Quantity 2013-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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50889 Quantity 2013-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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Quantity&diff=50839 Quantity 2013-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 /> &quot;nm&quot; = Quantity(1.0e-6 ,Unit(1)); // nano meter<br /> &quot;ym&quot; = Quantity(1.0e-3 ,Unit(1)); // micro meter<br /> &quot;mm&quot; = Quantity(1.0 ,Unit(1)); // milli meter<br /> &quot;cm&quot; = Quantity(10.0 ,Unit(1)); // centi meter<br /> &quot;dm&quot; = Quantity(100.0 ,Unit(1)); // deci meter<br /> &quot;m&quot; = Quantity(1.0e3 ,Unit(1)); // meter<br /> &quot;km&quot; = Quantity(1.0e6 ,Unit(1)); // kilo meter<br /> &quot;l&quot; = Quantity(1000000.0 ,Unit(3)); // Liter dm^3<br /> <br /> &quot;yg&quot; = Quantity(1.0e-9 ,Unit(0,1)); // milli gram<br /> &quot;mg&quot; = Quantity(1.0e-6 ,Unit(0,1)); // milli gram<br /> &quot;g&quot; = Quantity(1.0e-3 ,Unit(0,1)); // gram<br /> &quot;kg&quot; = Quantity(1.0 ,Unit(0,1)); // kilo gram<br /> &quot;t&quot; = Quantity(1000.0 ,Unit(0,1)); // ton<br /> <br /> &quot;s&quot; = Quantity(1.0 ,Unit(0,0,1)); // second (internal standard time)<br /> &quot;min&quot; = Quantity(60.0 ,Unit(0,0,1)); // minute<br /> &quot;h&quot; = Quantity(3600.0 ,Unit(0,0,1)); // hour <br /> <br /> &quot;A&quot; = Quantity(1.0 ,Unit(0,0,0,1)); // Ampere (internal standard electric current)<br /> &quot;mA&quot; = Quantity(0.001 ,Unit(0,0,0,1)); // milli Ampere <br /> &quot;kA&quot; = Quantity(1000.0 ,Unit(0,0,0,1)); // kilo Ampere <br /> &quot;MA&quot; = Quantity(1.0e6 ,Unit(0,0,0,1)); // Mega Ampere <br /> <br /> &quot;K&quot; = Quantity(1.0 ,Unit(0,0,0,0,1)); // Kelvin (internal standard thermodynamic temperature)<br /> &quot;mK&quot; = Quantity(0.001 ,Unit(0,0,0,0,1)); // Kelvin <br /> &quot;yK&quot; = Quantity(0.000001 ,Unit(0,0,0,0,1)); // Kelvin <br /> <br /> &quot;mol&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,1)); // Mole (internal standard amount of substance) <br /> <br /> &quot;cd&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,1)); // Candela (internal standard luminous intensity) <br /> <br /> &quot;deg&quot; = Quantity(1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)<br /> &quot;rad&quot; = Quantity(180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian <br /> &quot;gon&quot; = Quantity(360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon <br /> <br /> &quot;in&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;\&quot;&quot; = Quantity(25.4 ,Unit(1)); // inch<br /> &quot;fo&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;'&quot; = Quantity(304.8 ,Unit(1)); // foot<br /> &quot;th&quot; = Quantity(0.0254 ,Unit(1)); // thou<br /> &quot;yr&quot; = Quantity(914.4 ,Unit(1)); // yard<br /> <br /> <br /> &quot;lb&quot; = Quantity(0.45359237 ,Unit(0,1)); // pound<br /> &quot;oz&quot; = Quantity(0.0283495231 ,Unit(0,1)); // ounce<br /> &quot;st&quot; = Quantity(6.35029318 ,Unit(0,1)); // Stone<br /> &quot;cwt&quot; = Quantity(50.80234544 ,Unit(0,1)); // hundredweights<br /> <br /> {{clear}}<br /> {{languages | {{fr|Quantity/fr}} {{it|Quantity/it}} }}</div> Jriegel https://www.freecadweb.org/wiki/index.php?title=Std_UnitsCalculator&diff=45880 Std UnitsCalculator 2013-11-30T13:04:53Z <p>Jriegel: /* Dialog */</p> <hr /> <div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -&gt; 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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Std_UnitsCalculator&diff=45879 Std UnitsCalculator 2013-11-30T13:04:34Z <p>Jriegel: </p> <hr /> <div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -&gt; 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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Std_UnitsCalculator&diff=45878 Std UnitsCalculator 2013-11-30T13:03:53Z <p>Jriegel: /* Dialog */</p> <hr /> <div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -&gt; 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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Std_UnitsCalculator&diff=45877 Std UnitsCalculator 2013-11-30T13:03:38Z <p>Jriegel: /* Synopsis */</p> <hr /> <div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -&gt; 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> Jriegel https://www.freecadweb.org/wiki/index.php?title=Std_UnitsCalculator&diff=45876 Std UnitsCalculator 2013-11-30T13:00:00Z <p>Jriegel: </p> <hr /> <div>{{GuiCommand|Name=Std_UnitsCalculator|MenuLocation=Tools -&gt; 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> Jriegel