2011-09-01 12:54:34 +00:00
|
|
|
/**
|
|
|
|
* @file macros.h
|
|
|
|
* @brief This file contains miscellaneous helper definitions and functions.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifndef MACROS_H
|
|
|
|
#define MACROS_H
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-10-20 20:24:26 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
|
2011-02-02 15:31:48 +00:00
|
|
|
/**
|
|
|
|
* Macro TO_UTF8
|
|
|
|
* converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
|
|
|
|
* wxstring is a wxString, not a wxT() or _(). The scope of the return value
|
|
|
|
* is very limited and volatile, but can be used with printf() style functions well.
|
|
|
|
*/
|
|
|
|
#define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
|
|
|
|
|
|
|
|
/**
|
2013-03-31 13:27:46 +00:00
|
|
|
* function FROM_UTF8
|
2011-02-02 15:31:48 +00:00
|
|
|
* converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
|
|
|
|
*/
|
2011-03-02 11:03:06 +00:00
|
|
|
//#define FROM_UTF8( cstring ) wxString::FromUTF8( cstring )
|
2011-03-24 00:15:33 +00:00
|
|
|
static inline wxString FROM_UTF8( const char* cstring )
|
2011-03-02 11:03:06 +00:00
|
|
|
{
|
|
|
|
wxString line = wxString::FromUTF8( cstring );
|
2011-09-01 12:54:34 +00:00
|
|
|
|
2011-03-02 11:03:06 +00:00
|
|
|
if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
|
|
|
|
line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
|
2011-09-01 12:54:34 +00:00
|
|
|
|
2011-03-02 11:03:06 +00:00
|
|
|
return line;
|
|
|
|
}
|
2011-03-24 00:15:33 +00:00
|
|
|
|
2009-04-17 06:23:07 +00:00
|
|
|
/**
|
|
|
|
* Function GetChars
|
2010-08-03 02:13:33 +00:00
|
|
|
* returns a wxChar* to the actual character data within a wxString, and is
|
|
|
|
* helpful for passing strings to wxString::Printf(wxT("%s"), GetChars(wxString) )
|
|
|
|
* <p>
|
2010-12-14 15:56:30 +00:00
|
|
|
* wxChar is defined to be
|
|
|
|
* <ul>
|
2010-08-03 02:13:33 +00:00
|
|
|
* <li> standard C style char when wxUSE_UNICODE==0 </li>
|
|
|
|
* <li> wchar_t when wxUSE_UNICODE==1 (the default). </li>
|
2010-12-14 15:56:30 +00:00
|
|
|
* </ul>
|
2010-08-03 02:13:33 +00:00
|
|
|
* i.e. it depends on how the wxWidgets library was compiled. There was a period
|
|
|
|
* during the development of wxWidgets 2.9 when GetData() was missing, so this
|
|
|
|
* function was used to provide insulation from that design change. It may
|
|
|
|
* no longer be needed, and is harmless. GetData() seems to be an acceptable
|
|
|
|
* alternative in all cases now.
|
2009-04-17 06:23:07 +00:00
|
|
|
*/
|
2010-08-03 02:13:33 +00:00
|
|
|
static inline const wxChar* GetChars( const wxString& s )
|
2009-04-17 06:23:07 +00:00
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
|
|
|
return (const wxChar*) s.c_str();
|
2009-04-17 06:23:07 +00:00
|
|
|
#else
|
|
|
|
return s.GetData();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-29 10:35:11 +00:00
|
|
|
#define NEGATE( x ) (x = -x)
|
|
|
|
|
2011-08-29 19:50:05 +00:00
|
|
|
/// # of elements in an array
|
2010-01-29 23:55:49 +00:00
|
|
|
#define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t
|
2008-11-09 02:57:42 +00:00
|
|
|
|
|
|
|
|
2008-10-30 20:12:29 +00:00
|
|
|
#define DEG2RAD( Deg ) ( (Deg) * M_PI / 180.0 )
|
|
|
|
#define RAD2DEG( Rad ) ( (Rad) * 180.0 / M_PI )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-05 17:28:55 +00:00
|
|
|
// Normalize angle to be in the -360.0 .. 360.0:
|
2011-09-01 12:54:34 +00:00
|
|
|
#define NORMALIZE_ANGLE_360( Angle ) { \
|
|
|
|
while( Angle < -3600 ) \
|
|
|
|
Angle += 3600; \
|
|
|
|
while( Angle > 3600 ) \
|
|
|
|
Angle -= 3600; }
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* Normalize angle to be in the 0.0 .. 360.0 range: */
|
2011-09-01 12:54:34 +00:00
|
|
|
#define NORMALIZE_ANGLE_POS( Angle ) { \
|
|
|
|
while( Angle < 0 ) \
|
|
|
|
Angle += 3600; \
|
|
|
|
while( Angle >= 3600 ) \
|
|
|
|
Angle -= 3600; }
|
|
|
|
|
|
|
|
#define NEGATE_AND_NORMALIZE_ANGLE_POS( Angle ) { \
|
|
|
|
Angle = -Angle; \
|
|
|
|
while( Angle < 0 ) \
|
|
|
|
Angle += 3600; \
|
|
|
|
while( Angle >= 3600 ) \
|
|
|
|
Angle -= 3600; }
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-07-30 11:15:54 +00:00
|
|
|
/* Normalize angle to be in the -90.0 .. 90.0 range */
|
2011-09-01 12:54:34 +00:00
|
|
|
#define NORMALIZE_ANGLE_90( Angle ) { \
|
|
|
|
while( Angle < -900 ) \
|
|
|
|
Angle += 1800; \
|
|
|
|
while( Angle > 900 ) \
|
|
|
|
Angle -= 1800; }
|
2008-10-30 20:12:29 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/* Normalize angle to be in the -180.0 .. 180.0 range */
|
2011-09-01 12:54:34 +00:00
|
|
|
#define NORMALIZE_ANGLE_180( Angle ) { \
|
|
|
|
while( Angle <= -1800 ) \
|
|
|
|
Angle += 3600; \
|
|
|
|
while( Angle > 1800 ) \
|
|
|
|
Angle -= 3600; }
|
2008-10-30 20:12:29 +00:00
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
/* macro to exchange 2 items */
|
|
|
|
/*****************************/
|
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
/*
|
|
|
|
* The EXCHG macro uses BOOST_TYPEOF for compilers that do not have native
|
|
|
|
* typeof support (MSVC). Please do not attempt to qualify these macros
|
|
|
|
* within #ifdef compiler definitions pragmas. BOOST_TYPEOF is smart enough
|
|
|
|
* to check for native typeof support and use it instead of it's own
|
|
|
|
* implementation. These macros effectively compile to nothing on platforms
|
|
|
|
* with native typeof support.
|
2008-10-30 20:12:29 +00:00
|
|
|
*/
|
2009-05-21 17:42:42 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <boost/typeof/typeof.hpp>
|
2008-10-30 20:12:29 +00:00
|
|
|
|
|
|
|
// we have to register the types used with the typeof keyword with boost
|
2010-10-04 12:58:07 +00:00
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxPoint )
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxSize )
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxString )
|
2008-10-30 20:12:29 +00:00
|
|
|
class DrawSheetLabelStruct;
|
2010-10-04 12:58:07 +00:00
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( DrawSheetLabelStruct* )
|
2010-12-08 20:12:46 +00:00
|
|
|
class EDA_ITEM;
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( EDA_ITEM* )
|
2008-10-30 20:12:29 +00:00
|
|
|
class D_PAD;
|
2010-10-04 12:58:07 +00:00
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( D_PAD* )
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( const D_PAD* )
|
2008-10-30 20:12:29 +00:00
|
|
|
class BOARD_ITEM;
|
2010-10-04 12:58:07 +00:00
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( BOARD_ITEM* )
|
2008-10-30 20:12:29 +00:00
|
|
|
|
2009-12-29 10:35:11 +00:00
|
|
|
#define EXCHG( a, b ) { BOOST_TYPEOF( a ) __temp__ = (a); \
|
2011-08-29 19:50:05 +00:00
|
|
|
(a) = (b); \
|
2009-05-21 17:42:42 +00:00
|
|
|
(b) = __temp__; }
|
2008-10-30 11:41:06 +00:00
|
|
|
|
2008-10-30 10:55:46 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif /* ifdef MACRO_H */
|