2008-10-30 10:55:46 +00:00
|
|
|
/**************************************/
|
|
|
|
/* Useful macros and inline functions */
|
|
|
|
/**************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifndef MACROS_H
|
|
|
|
#define MACROS_H
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
2007-11-05 07:07:00 +00:00
|
|
|
#define CONV_TO_UTF8( wxstring ) ( (const char*) wxConvCurrent->cWX2MB( wxstring ) )
|
|
|
|
#define CONV_FROM_UTF8( utf8string ) ( wxConvCurrent->cMB2WC( utf8string ) )
|
2007-06-05 12:10:51 +00:00
|
|
|
#else
|
2007-11-05 07:07:00 +00:00
|
|
|
#define CONV_TO_UTF8( wxstring ) ( (const char*) ( wxstring.c_str() ) )
|
|
|
|
#define CONV_FROM_UTF8( utf8string ) (utf8string)
|
2007-06-05 12:10:51 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef MIN
|
2008-10-30 20:12:29 +00:00
|
|
|
#define MIN( x, y ) ( (x) > (y) ? (y) : (x) )
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
2008-10-30 20:12:29 +00:00
|
|
|
#define MAX( x, y ) ( (x) > (y) ? (x) : (y) )
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ABS
|
2008-10-30 20:12:29 +00:00
|
|
|
#define ABS( y ) ( (y) >= 0 ? (y) : ( -(y) ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-30 19:18:56 +00:00
|
|
|
#define NEGATE(x) (x = -x)
|
2008-11-09 02:57:42 +00:00
|
|
|
/// # of elements in an arrray
|
|
|
|
#define DIM(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* Normalize angle to be in the -360.0 .. 360.0 range or 0 .. 360.0: */
|
2008-10-30 20:12:29 +00:00
|
|
|
#define NORMALIZE_ANGLE( Angle ) { while( Angle < 0 ) \
|
|
|
|
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: */
|
2008-10-30 20:12:29 +00:00
|
|
|
#define NORMALIZE_ANGLE_POS( Angle ) { while( Angle < 0 ) \
|
|
|
|
Angle += 3600;while( Angle >= 3600 ) \
|
|
|
|
Angle -= 3600; }
|
2007-11-05 07:07:00 +00:00
|
|
|
#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 */
|
2008-10-30 20:12:29 +00:00
|
|
|
#define NORMALIZE_ANGLE_90( Angle ) { while( Angle < -900 ) \
|
|
|
|
Angle += 1800;\
|
|
|
|
while( Angle > 900 ) \
|
|
|
|
Angle -= 1800; }
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
/* macro to exchange 2 items */
|
|
|
|
/*****************************/
|
|
|
|
|
|
|
|
/* this macro uses the typeof keyword
|
|
|
|
* for compilers that do not know typeof (MSVC )
|
|
|
|
* the boost libs have a workaround for the typeof problem
|
|
|
|
*/
|
|
|
|
#ifdef __MSVC__ // MSCV does not know typeof. Others def can be added here
|
|
|
|
#include "boost/typeof/typeof.hpp"
|
|
|
|
|
|
|
|
// we have to register the types used with the typeof keyword with boost
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxPoint );
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxSize );
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( wxString );
|
|
|
|
class DrawSheetLabelStruct;
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( DrawSheetLabelStruct* );
|
|
|
|
class EDA_BaseStruct;
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( EDA_BaseStruct* );
|
|
|
|
class D_PAD;
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( D_PAD* );
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( const D_PAD* );
|
|
|
|
class BOARD_ITEM;
|
|
|
|
BOOST_TYPEOF_REGISTER_TYPE( BOARD_ ITEM* );
|
|
|
|
|
|
|
|
#define typeof (expr)BOOST_TYPEOF( expr )
|
|
|
|
#endif // #ifdef __MSVC__
|
|
|
|
|
|
|
|
// here is the macro:
|
|
|
|
#define EXCHG( a, b ) { typeof(a)__temp__ = (a); (a) = (b); (b) = __temp__; }
|
2008-10-30 11:41:06 +00:00
|
|
|
|
2008-10-30 10:55:46 +00:00
|
|
|
|
|
|
|
/*****************************************************/
|
2007-11-05 07:07:00 +00:00
|
|
|
/* inline functions to insert menuitems with a icon: */
|
2008-10-30 10:55:46 +00:00
|
|
|
/*****************************************************/
|
2007-11-05 07:07:00 +00:00
|
|
|
static inline void ADD_MENUITEM( wxMenu* menu, int id,
|
|
|
|
const wxString& text,
|
2008-10-30 20:12:29 +00:00
|
|
|
const wxBitmap& icon )
|
2007-11-05 07:07:00 +00:00
|
|
|
{
|
|
|
|
wxMenuItem* l_item;
|
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void ADD_MENUITEM_WITH_HELP( wxMenu* menu, int id,
|
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
|
|
|
const wxBitmap& icon )
|
|
|
|
{
|
|
|
|
wxMenuItem* l_item;
|
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text, help );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
2007-06-25 08:05:45 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#ifdef __WINDOWS__
|
2007-11-05 07:07:00 +00:00
|
|
|
static inline void ADD_MENUITEM_WITH_SUBMENU( wxMenu* menu, wxMenu* submenu,
|
|
|
|
int id, const wxString& text,
|
|
|
|
const wxBitmap& icon )
|
|
|
|
{
|
2008-10-30 20:12:29 +00:00
|
|
|
extern wxFont* g_ItalicFont;
|
|
|
|
wxMenuItem* l_item;
|
2007-11-05 07:07:00 +00:00
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text );
|
|
|
|
l_item->SetSubMenu( submenu );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
l_item->SetFont( *g_ItalicFont );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
|
|
|
|
2008-10-30 20:12:29 +00:00
|
|
|
static inline void ADD_MENUITEM_WITH_HELP_AND_SUBMENU( wxMenu* menu,
|
|
|
|
wxMenu* submenu,
|
2007-11-05 07:07:00 +00:00
|
|
|
int id,
|
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
2008-10-30 20:12:29 +00:00
|
|
|
const wxBitmap& icon )
|
2007-11-05 07:07:00 +00:00
|
|
|
{
|
2008-10-30 20:12:29 +00:00
|
|
|
extern wxFont* g_ItalicFont;
|
|
|
|
wxMenuItem* l_item;
|
2007-11-05 07:07:00 +00:00
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text, help );
|
|
|
|
l_item->SetSubMenu( submenu );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
l_item->SetFont( *g_ItalicFont );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2007-11-05 07:07:00 +00:00
|
|
|
static inline void ADD_MENUITEM_WITH_SUBMENU( wxMenu* menu, wxMenu* submenu,
|
|
|
|
int id,
|
|
|
|
const wxString& text,
|
|
|
|
const wxBitmap& icon )
|
|
|
|
{
|
|
|
|
wxMenuItem* l_item;
|
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text );
|
|
|
|
l_item->SetSubMenu( submenu );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void ADD_MENUITEM_WITH_HELP_AND_SUBMENU( wxMenu* menu,
|
|
|
|
wxMenu* submenu,
|
|
|
|
int id,
|
|
|
|
const wxString& text,
|
|
|
|
const wxString& help,
|
2008-10-30 20:12:29 +00:00
|
|
|
const wxBitmap& icon )
|
2007-11-05 07:07:00 +00:00
|
|
|
{
|
|
|
|
wxMenuItem* l_item;
|
|
|
|
|
|
|
|
l_item = new wxMenuItem( menu, id, text, help );
|
|
|
|
l_item->SetSubMenu( submenu );
|
|
|
|
l_item->SetBitmap( icon );
|
|
|
|
menu->Append( l_item );
|
|
|
|
};
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2007-11-05 07:07:00 +00:00
|
|
|
#define SETBITMAPS( icon ) item->SetBitmaps( apply_xpm, (icon) )
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2007-11-05 07:07:00 +00:00
|
|
|
#define SETBITMAPS( icon )
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ifdef MACRO_H */
|