You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. /**
  2. * @file lengthpcb.h
  3. * @brief Length definitions for PCBNEW.
  4. */
  5. #ifndef LENGTHPCB_H_INCLUDED
  6. #define LENGTHPCB_H_INCLUDED 1
  7. #ifdef KICAD_NANOMETRE
  8. #include "length.h"
  9. /* switched type! */
  10. typedef LENGTH< LIMITED_INT< int >, 1 > LENGTH_PCB;
  11. typedef LENGTH< double, 1 > LENGTH_PCB_DBL;
  12. /* Transition macros. they are used for unit conversion between
  13. * nanometre scale and old (0.1 mil) scale */
  14. #define PCB_LEGACY_INCH_SCALE 10000
  15. #define PCB_LEGACY_UNIT( T ) ( LENGTH_UNITS< T >::inch() / PCB_LEGACY_INCH_SCALE )
  16. #define TO_LEGACY_LU( x ) \
  17. ( LENGTH_PCB( x ) / PCB_LEGACY_UNIT( LENGTH_PCB ) )
  18. #define TO_LEGACY_LU_DBL( x ) \
  19. ( LENGTH_PCB_DBL( x ) / PCB_LEGACY_UNIT( LENGTH_PCB_DBL ) )
  20. static LENGTH_PCB from_legacy_lu( int x ) {
  21. return x * PCB_LEGACY_UNIT( LENGTH_PCB );
  22. }
  23. static LENGTH_PCB from_legacy_lu( double x ) {
  24. return LENGTH_PCB( x * PCB_LEGACY_UNIT( LENGTH_PCB_DBL ) );
  25. }
  26. static LENGTH_PCB_DBL from_legacy_lu_dbl( double x ) {
  27. return x * LENGTH_UNITS< LENGTH_PCB_DBL >::inch() / PCB_LEGACY_INCH_SCALE;
  28. }
  29. #define FROM_LEGACY_LU( x ) ( from_legacy_lu( x ) )
  30. #define FROM_LEGACY_LU_DBL( x ) ( from_legacy_lu_dbl( x ) )
  31. #define ZERO_LENGTH ( LENGTH_PCB::zero() )
  32. #else
  33. typedef int LENGTH_PCB;
  34. typedef double LENGTH_PCB_DBL;
  35. /* transition macro stubs */
  36. #define TO_LEGACY_LU( x ) ( x )
  37. #define TO_LEGACY_LU_DBL( x ) ( double( x ) )
  38. #define FROM_LEGACY_LU( x ) ( x )
  39. #define FROM_LEGACY_LU_DBL( x ) ( double( x ) )
  40. #define ZERO_LENGTH 0
  41. #endif
  42. #endif /* def LENGTHPCB_H_INCLUDED */