2012-04-11 09:47:57 +00:00
|
|
|
#ifndef CONVERT_TO_BIU_H
|
|
|
|
#define CONVERT_TO_BIU_H
|
|
|
|
|
|
|
|
#include <config.h> // USE_PCBNEW_NANOMETRES is defined here
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file convert_to_biu.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-25 19:33:24 +00:00
|
|
|
* @brief some define and functions to convert a value in mils, decimils or mm
|
|
|
|
* to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or decimil)
|
2012-04-11 09:47:57 +00:00
|
|
|
* depending on compil option
|
|
|
|
*/
|
|
|
|
|
2012-04-25 19:33:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Scaling factor to convert mils to internal units.
|
|
|
|
#if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW)
|
|
|
|
#if defined( USE_PCBNEW_NANOMETRES )
|
|
|
|
#if defined(GERBVIEW)
|
2012-04-26 20:21:31 +00:00
|
|
|
#define MM_PER_IU 1e5 // Gerbview uses 10 micrometer.
|
2012-04-25 19:33:24 +00:00
|
|
|
#else
|
2012-04-26 20:21:31 +00:00
|
|
|
#define MM_PER_IU 1e6 // Pcbnew uses nanometers.
|
2012-04-25 19:33:24 +00:00
|
|
|
#endif
|
2012-04-26 20:21:31 +00:00
|
|
|
#define MILS_PER_IU ( MM_PER_IU * 0.0254 )
|
|
|
|
#define DECIMILS_PER_IU (MM_PER_IU * 0.00254 )
|
2012-04-25 19:33:24 +00:00
|
|
|
#else // Pcbnew in deci-mils.
|
2012-04-26 20:21:31 +00:00
|
|
|
#define DECIMILS_PER_IU 1
|
|
|
|
#define MILS_PER_IU 10.0
|
|
|
|
#define MM_PER_IU (1e4 / 25.4)
|
2012-04-25 19:33:24 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-11 09:47:57 +00:00
|
|
|
/// Convert mils to PCBNEW internal units (iu).
|
|
|
|
inline int Mils2iu( int mils )
|
|
|
|
{
|
|
|
|
#if defined( USE_PCBNEW_NANOMETRES )
|
2012-04-26 20:21:31 +00:00
|
|
|
double x = mils * MILS_PER_IU;
|
2012-04-11 15:50:17 +00:00
|
|
|
return int( x < 0 ? x - 0.5 : x + 0.5 );
|
2012-04-11 09:47:57 +00:00
|
|
|
#else
|
2012-04-26 20:21:31 +00:00
|
|
|
return mils * MILS_PER_IU;
|
2012-04-11 09:47:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Convert deci-mils to PCBNEW internal units (iu).
|
|
|
|
inline int DMils2iu( int dmils )
|
|
|
|
{
|
|
|
|
#if defined( USE_PCBNEW_NANOMETRES )
|
2012-04-26 20:21:31 +00:00
|
|
|
double x = dmils * DECIMILS_PER_IU;
|
2012-04-11 15:50:17 +00:00
|
|
|
return int( x < 0 ? x - 0.5 : x + 0.5 );
|
2012-04-11 09:47:57 +00:00
|
|
|
#else
|
|
|
|
return dmils;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-25 19:33:24 +00:00
|
|
|
#else // Eeschema and anything else.
|
2012-04-26 20:21:31 +00:00
|
|
|
#define MILS_PER_IU 1.0
|
|
|
|
#define MM_PER_IU (MILS_PER_IU / 0.0254)
|
2012-04-25 19:33:24 +00:00
|
|
|
|
2012-04-15 10:33:35 +00:00
|
|
|
inline int Mils2iu( int mils )
|
|
|
|
{
|
|
|
|
return mils;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-11 09:47:57 +00:00
|
|
|
#endif // #define CONVERT_TO_BIU_H
|