Browse Source
Work on internal (nano)metric length units started.
Work on internal (nano)metric length units started.
Added configuartion option KICAD_NANOMETRIC for this. * With option set to false: * - it should work and compile as usual - some values are saved with decimal point (which should be backward/forward compatible as old versions should just drop fractional part) * With option set to true: * - lengths in Global Design Rules should be settable 1nm steps. FROM/TO_LEGACY_LU(_DBL) macros introduced for easy interconnection between old and new units.pull/1/head
14 changed files with 703 additions and 67 deletions
-
7CMakeLists.txt
-
127common/common.cpp
-
12include/class_board_design_settings.h
-
27include/common.h
-
62include/length.h
-
58include/lengthpcb.h
-
309include/limited_int.h
-
10pcbnew/class_board_design_settings.cpp
-
16pcbnew/class_netclass.cpp
-
54pcbnew/dialogs/dialog_design_rules.cpp
-
2pcbnew/dialogs/dialog_design_rules_base.cpp
-
15pcbnew/dialogs/dialog_drc.cpp
-
35pcbnew/drc.cpp
-
36pcbnew/ioascii.cpp
@ -0,0 +1,58 @@ |
|||
/** |
|||
* @file lengthpcb.h |
|||
* @brief Length definitions for PCBNEW. |
|||
*/ |
|||
|
|||
#ifndef LENGTHPCB_H_INCLUDED |
|||
#define LENGTHPCB_H_INCLUDED 1 |
|||
|
|||
#ifdef KICAD_NANOMETRE |
|||
#include "length.h" |
|||
|
|||
/* switched type! */ |
|||
typedef LENGTH< LIMITED_INT< int >, 1 > LENGTH_PCB; |
|||
typedef LENGTH< double, 1 > LENGTH_PCB_DBL; |
|||
|
|||
/* Transition macros. they are used for unit conversion between |
|||
* nanometre scale and old (0.1 mil) scale */ |
|||
|
|||
#define PCB_LEGACY_INCH_SCALE 10000 |
|||
#define PCB_LEGACY_UNIT( T ) ( LENGTH_UNITS< T >::inch() / PCB_LEGACY_INCH_SCALE ) |
|||
|
|||
#define TO_LEGACY_LU( x ) \ |
|||
( LENGTH_PCB( x ) / PCB_LEGACY_UNIT( LENGTH_PCB ) ) |
|||
#define TO_LEGACY_LU_DBL( x ) \ |
|||
( LENGTH_PCB_DBL( x ) / PCB_LEGACY_UNIT( LENGTH_PCB_DBL ) ) |
|||
|
|||
static LENGTH_PCB from_legacy_lu( int x ) { |
|||
return x * PCB_LEGACY_UNIT( LENGTH_PCB ); |
|||
} |
|||
static LENGTH_PCB from_legacy_lu( double x ) { |
|||
return LENGTH_PCB( x * PCB_LEGACY_UNIT( LENGTH_PCB_DBL ) ); |
|||
} |
|||
|
|||
static LENGTH_PCB_DBL from_legacy_lu_dbl( double x ) { |
|||
return x * LENGTH_UNITS< LENGTH_PCB_DBL >::inch() / PCB_LEGACY_INCH_SCALE; |
|||
} |
|||
|
|||
#define FROM_LEGACY_LU( x ) ( from_legacy_lu( x ) ) |
|||
#define FROM_LEGACY_LU_DBL( x ) ( from_legacy_lu_dbl( x ) ) |
|||
|
|||
|
|||
#else |
|||
|
|||
typedef int LENGTH_PCB; |
|||
typedef double LENGTH_PCB_DBL; |
|||
|
|||
/* transition macro stubs */ |
|||
|
|||
#define TO_LEGACY_LU( x ) ( x ) |
|||
#define TO_LEGACY_LU_DBL( x ) ( double( x ) ) |
|||
|
|||
#define FROM_LEGACY_LU( x ) ( x ) |
|||
#define FROM_LEGACY_LU_DBL( x ) ( double( x ) ) |
|||
|
|||
#endif |
|||
|
|||
|
|||
#endif /* def LENGTHPCB_H_INCLUDED */ |
|||
@ -0,0 +1,309 @@ |
|||
/** |
|||
* @file limited_int.h |
|||
* @brief Integer class catching overflows. |
|||
*/ |
|||
|
|||
/* sorry if it is not styled correctly, i'll work on it further */ |
|||
|
|||
#ifndef LIMITED_INT_H_INCLUDED |
|||
#define LIMITED_INT_H_INCLUDED 1 |
|||
|
|||
#include <limits> |
|||
#include <assert.h> |
|||
#include <math.h> |
|||
|
|||
template < typename T = int > class LIMITED_INT { |
|||
private: |
|||
T m_Value; |
|||
public: |
|||
LIMITED_INT( void ) : m_Value() { |
|||
} |
|||
template<typename V> LIMITED_INT( const LIMITED_INT< V >& orig ) |
|||
: m_Value( orig.m_Value ) |
|||
{ |
|||
assert(std::numeric_limits<T>::min() <= orig.m_Value); |
|||
assert(orig.m_Value <= std::numeric_limits<T>::max()); |
|||
} |
|||
template<typename V> LIMITED_INT( const double v ) |
|||
: m_Value( floor(v+0.5) ) |
|||
{ |
|||
assert(std::numeric_limits<T>::min() <= v); |
|||
assert(v <= std::numeric_limits<T>::max()); |
|||
} |
|||
LIMITED_INT( T v ): m_Value( v ) |
|||
{ |
|||
} |
|||
|
|||
operator T( void ) const |
|||
{ |
|||
return m_Value; |
|||
} |
|||
operator double( void ) const |
|||
{ |
|||
return ( double )m_Value; |
|||
} |
|||
|
|||
LIMITED_INT<T> & operator = ( LIMITED_INT< T > src ) |
|||
{ |
|||
m_Value = src.m_Value; |
|||
return *this; |
|||
} |
|||
LIMITED_INT<T> & operator = ( T src ) |
|||
{ |
|||
m_Value = src; |
|||
return *this; |
|||
} |
|||
/*************************/ |
|||
/* comparisons and tests */ |
|||
/*************************/ |
|||
bool operator ! (void) const { |
|||
return !m_Value; |
|||
} |
|||
|
|||
bool operator == ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
return m_Value == y.m_Value; |
|||
} |
|||
bool operator == ( const T y ) const |
|||
{ |
|||
return m_Value == y; |
|||
} |
|||
friend bool operator == ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x == y.m_Value; |
|||
} |
|||
|
|||
bool operator != ( const LIMITED_INT<T> &y ) const |
|||
{ |
|||
return m_Value != y.m_Value; |
|||
} |
|||
bool operator != ( const T y ) const |
|||
{ |
|||
return m_Value != y; |
|||
} |
|||
friend bool operator != ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x != y.m_Value; |
|||
} |
|||
|
|||
bool operator < ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
return m_Value < y.m_Value; |
|||
} |
|||
bool operator < ( const T y ) const |
|||
{ |
|||
return m_Value < y; |
|||
} |
|||
friend bool operator < ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x < y.m_Value; |
|||
} |
|||
|
|||
bool operator >= ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
return m_Value >= y.m_Value; |
|||
} |
|||
bool operator >= ( const T y ) const |
|||
{ |
|||
return m_Value >= y; |
|||
} |
|||
friend bool operator >= ( const T x, const LIMITED_INT<T> &y ) |
|||
{ |
|||
return x >= y.m_Value; |
|||
} |
|||
|
|||
bool operator > ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
return m_Value > y.m_Value; |
|||
} |
|||
bool operator > ( const T y ) const |
|||
{ |
|||
return m_Value > y; |
|||
} |
|||
friend bool operator > ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x > y.m_Value; |
|||
} |
|||
|
|||
bool operator <= ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
return m_Value <= y.m_Value; |
|||
} |
|||
bool operator <= ( const T y ) const |
|||
{ |
|||
return m_Value <= y; |
|||
} |
|||
friend bool operator <= ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x <= y.m_Value; |
|||
} |
|||
|
|||
/*************************/ |
|||
/* basic arithmetic */ |
|||
/*************************/ |
|||
LIMITED_INT< T > operator + ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
assert( !( 0 < m_Value ) || y.m_Value <= std::numeric_limits< T >::max() - m_Value ); |
|||
assert( !( m_Value < 0 ) || std::numeric_limits< T >::min() - m_Value <= y.m_Value ); |
|||
return m_Value + y.m_Value; |
|||
} |
|||
LIMITED_INT< T > operator + ( const T y ) const |
|||
{ |
|||
return *this + LIMITED_INT< T >( y ); |
|||
} |
|||
friend LIMITED_INT< T > operator + ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return LIMITED_INT< T >( x ) + y; |
|||
} |
|||
double operator + ( const double y ) const |
|||
{ |
|||
return double( m_Value ) + y; |
|||
} |
|||
friend double operator + ( const double x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x + double( y.m_Value ); |
|||
} |
|||
|
|||
LIMITED_INT< T > operator - ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
assert( !( 0 < m_Value ) || m_Value - std::numeric_limits< T >::max() <= y.m_Value ); |
|||
assert( !( m_Value < 0 ) || y.m_Value <= m_Value - std::numeric_limits< T >::min() ); |
|||
return m_Value - y.m_Value; |
|||
} |
|||
LIMITED_INT< T > operator - ( const T y ) const |
|||
{ |
|||
return *this - LIMITED_INT< T >( y ); |
|||
} |
|||
friend LIMITED_INT< T > operator - ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return LIMITED_INT< T >( x ) - y; |
|||
} |
|||
double operator - ( const double y ) const |
|||
{ |
|||
return double( m_Value ) - y; |
|||
} |
|||
friend double operator - ( const double x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x - double( y.m_Value ); |
|||
} |
|||
|
|||
LIMITED_INT< T > operator * ( const LIMITED_INT< T > &y ) const |
|||
{ |
|||
assert( !( 0 < m_Value && 0 < y.m_Value ) |
|||
|| y.m_Value <= std::numeric_limits<T>::max() / m_Value ); |
|||
assert( !( 0 < m_Value && y.m_Value < 0 ) |
|||
|| std::numeric_limits<T>::min() / m_Value <= y.m_Value ); |
|||
assert( !( m_Value < 0 && 0 < y.m_Value ) |
|||
|| std::numeric_limits<T>::min() / y.m_Value <= m_Value ); |
|||
assert( !( m_Value < 0 && y.m_Value < 0 ) |
|||
|| std::numeric_limits<T>::max() / m_Value <= y.m_Value ); |
|||
return m_Value * y.m_Value; |
|||
} |
|||
LIMITED_INT<T> operator * ( const T y) const |
|||
{ |
|||
return *this * LIMITED_INT< T >( y ); |
|||
} |
|||
friend LIMITED_INT< T > operator *( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return LIMITED_INT< T >( x ) * y; |
|||
} |
|||
double operator * ( const double y ) const |
|||
{ |
|||
return double( m_Value ) * y; |
|||
} |
|||
friend double operator * ( const double x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x * double( y.m_Value ); |
|||
} |
|||
|
|||
LIMITED_INT<T> operator / ( const LIMITED_INT<T> &y ) const |
|||
{ |
|||
assert( !( -1 == y.m_Value ) |
|||
|| -std::numeric_limits< T >::max() <= m_Value ); |
|||
return m_Value / y.m_Value; |
|||
} |
|||
LIMITED_INT<T> operator / ( const T y ) const |
|||
{ |
|||
return *this / LIMITED_INT<T>(y); |
|||
} |
|||
friend LIMITED_INT< T > operator / ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return LIMITED_INT< T >( x ) / y; |
|||
} |
|||
double operator / ( const double y ) const |
|||
{ |
|||
return double( m_Value ) / y; |
|||
} |
|||
friend double operator / ( const double x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return x / double( y.m_Value ); |
|||
} |
|||
|
|||
LIMITED_INT<T> operator % ( const LIMITED_INT<T> &y ) const |
|||
{ |
|||
return m_Value % y.m_Value; |
|||
} |
|||
LIMITED_INT<T> operator % ( const T y ) const |
|||
{ |
|||
return *this % LIMITED_INT<T>(y); |
|||
} |
|||
friend LIMITED_INT< T > operator % ( const T x, const LIMITED_INT< T > &y ) |
|||
{ |
|||
return LIMITED_INT< T >( x ) % y; |
|||
} |
|||
/*************************/ |
|||
/* assignment arithmetic */ |
|||
/*************************/ |
|||
LIMITED_INT< T >& operator += ( const LIMITED_INT< T > &y ) |
|||
{ |
|||
*this = *this + y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator += ( const T y ) |
|||
{ |
|||
*this = *this + y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator ++ ( void ) |
|||
{ |
|||
*this = *this + 1; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator -= ( const LIMITED_INT< T > &y ) |
|||
{ |
|||
*this = *this - y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator -= ( const T y ) |
|||
{ |
|||
*this = *this - y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator -- ( void ) |
|||
{ |
|||
*this = *this - 1; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator *= ( const LIMITED_INT< T > &y ) |
|||
{ |
|||
*this = *this * y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator *= ( const T y ) |
|||
{ |
|||
*this = *this * y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator /= ( const LIMITED_INT< T > &y ) |
|||
{ |
|||
*this = *this / y; |
|||
return *this; |
|||
} |
|||
LIMITED_INT< T >& operator /= ( const T y ) |
|||
{ |
|||
*this = *this / y; |
|||
return *this; |
|||
} |
|||
}; |
|||
|
|||
#endif /* def LIMITED_INT_H_INCLUDED*/ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue