From 5a948e98b722b01d91bfe09734ce7b568e442a9e Mon Sep 17 00:00:00 2001 From: CHARRAS Date: Mon, 5 Nov 2007 07:07:00 +0000 Subject: [PATCH] made ADD_MENUITEM_xx static inline --- common/displlst.cpp | 2 +- common/edaappl.cpp | 2 +- common/msgpanel.cpp | 2 +- common/selcolor.cpp | 2 +- common/worksheet.cpp | 2 +- eeschema/annotate.cpp | 2 +- eeschema/component_class.cpp | 2 +- eeschema/libcmp.h | 2 +- eeschema/save_schemas.cpp | 2 +- include/hotkeys_basic.h | 2 +- include/macros.h | 177 ++++++++++++++++++++++------------- pcbnew/class_module.cpp | 2 +- pcbnew/class_track.cpp | 2 +- pcbnew/dragsegm.cpp | 3 +- todo.txt | 15 +-- 15 files changed, 132 insertions(+), 87 deletions(-) diff --git a/common/displlst.cpp b/common/displlst.cpp index 2f12a31d33..fbd4873e01 100644 --- a/common/displlst.cpp +++ b/common/displlst.cpp @@ -6,8 +6,8 @@ #include "wxstruct.h" #include "gr_basic.h" -#include "macros.h" #include "common.h" +#include "macros.h" diff --git a/common/edaappl.cpp b/common/edaappl.cpp index f17d788200..9f1a56c957 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -20,7 +20,6 @@ #include "wxstruct.h" -#include "macros.h" #include "gr_basic.h" #include "common.h" @@ -28,6 +27,7 @@ #include "id.h" #include "build_version.h" #include "hotkeys_basic.h" +#include "macros.h" #include "bitmaps.h" #include "Language.xpm" diff --git a/common/msgpanel.cpp b/common/msgpanel.cpp index 0dcf9f4b99..504ef76894 100644 --- a/common/msgpanel.cpp +++ b/common/msgpanel.cpp @@ -10,8 +10,8 @@ #include "wxstruct.h" #include "gr_basic.h" -#include "macros.h" #include "common.h" +#include "macros.h" /* table des evenements captes par un WinEDA_MsgPanel */ BEGIN_EVENT_TABLE( WinEDA_MsgPanel, wxPanel ) diff --git a/common/selcolor.cpp b/common/selcolor.cpp index 637ea731ca..c615ef81f0 100644 --- a/common/selcolor.cpp +++ b/common/selcolor.cpp @@ -7,10 +7,10 @@ #include "fctsys.h" #include "gr_basic.h" -#include "macros.h" #include "common.h" #include "colors.h" +#include "macros.h" #include "wx/statline.h" diff --git a/common/worksheet.cpp b/common/worksheet.cpp index 39907e0f1b..27b0299bba 100644 --- a/common/worksheet.cpp +++ b/common/worksheet.cpp @@ -4,9 +4,9 @@ #include "fctsys.h" #include "gr_basic.h" -#include "macros.h" #include "common.h" +#include "macros.h" #include "worksheet.h" diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index cc01c24b50..a65362422a 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -443,7 +443,7 @@ static void ComputeReferenceNumber( CmpListStruct* BaseListeCmp, int NbOfCmp ) */ { int ii, jj, LastReferenceNumber, NumberOfUnits, Unit; - char* Text, * RefText, * ValText; + const char* Text, * RefText, * ValText; CmpListStruct* ObjRef, * ObjToTest; /* Components with an invisible reference (power...) always are re-annotated*/ diff --git a/eeschema/component_class.cpp b/eeschema/component_class.cpp index f504caccaf..39c221496b 100644 --- a/eeschema/component_class.cpp +++ b/eeschema/component_class.cpp @@ -4,12 +4,12 @@ #include "fctsys.h" #include "gr_basic.h" -#include "macros.h" #include "common.h" #include "program.h" #include "libcmp.h" #include "general.h" +#include "macros.h" #include "id.h" #include "protos.h" diff --git a/eeschema/libcmp.h b/eeschema/libcmp.h index 4568badfed..ad9bfcd7f5 100644 --- a/eeschema/libcmp.h +++ b/eeschema/libcmp.h @@ -90,7 +90,7 @@ typedef enum { /* Type des Pins. si modif: modifier tableau des mgs suivant } ElectricPinType; /* Messages d'affichage du type electrique */ -eda_global wxChar* MsgPinElectricType[] +eda_global const wxChar* MsgPinElectricType[] #ifdef MAIN = { wxT( "input" ), diff --git a/eeschema/save_schemas.cpp b/eeschema/save_schemas.cpp index ebe80d2ed7..956a2e932c 100644 --- a/eeschema/save_schemas.cpp +++ b/eeschema/save_schemas.cpp @@ -34,7 +34,7 @@ bool WinEDA_SchematicFrame::SaveEEFile(SCH_SCREEN *screen, int FileSave) wxString msg; wxString Name, BakName; const wxChar **LibNames; -char * layer, *width; +const char * layer, *width; int ii, shape; bool Failed = FALSE; EDA_BaseStruct *Phead; diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index 358c0f1d32..cf589405de 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -51,7 +51,7 @@ struct Ki_HotkeyInfoSectionDescriptor public: wxString* m_SectionTag; // The section name Ki_HotkeyInfo** m_HK_InfoList; // List of Ki_HotkeyInfo pointers - char* m_Comment; // comment: will be printed in the config file + const char* m_Comment; // comment: will be printed in the config file // Info usage only }; diff --git a/include/macros.h b/include/macros.h index a1e2d6cdb1..00c9f83951 100644 --- a/include/macros.h +++ b/include/macros.h @@ -4,101 +4,152 @@ #define MACROS_H #if wxUSE_UNICODE -#define CONV_TO_UTF8(wxstring) ((const char*) wxConvCurrent->cWX2MB(wxstring)) -#define CONV_FROM_UTF8(utf8string) ( wxConvCurrent->cMB2WC(utf8string)) +#define CONV_TO_UTF8( wxstring ) ( (const char*) wxConvCurrent->cWX2MB( wxstring ) ) +#define CONV_FROM_UTF8( utf8string ) ( wxConvCurrent->cMB2WC( utf8string ) ) #else -#define CONV_TO_UTF8(wxstring) ((const char*)(wxstring.c_str())) -#define CONV_FROM_UTF8(utf8string) (utf8string) +#define CONV_TO_UTF8( wxstring ) ( (const char*) ( wxstring.c_str() ) ) +#define CONV_FROM_UTF8( utf8string ) (utf8string) #endif /* violation of C++ standard, cannot use min() and max(), i.e. in lowercase -#ifndef min -#define min(x, y) ((x) > (y) ? (y) : (x)) -#endif -#ifndef max -#define max(x, y) ((x) > (y) ? (x) : (y)) -#endif -*/ + #ifndef min + #define min(x, y) ((x) > (y) ? (y) : (x)) + #endif + #ifndef max + #define max(x, y) ((x) > (y) ? (x) : (y)) + #endif + */ #ifndef MIN -#define MIN(x, y) ((x) > (y) ? (y) : (x)) +#define MIN( x, y ) ( (x) > (y) ? (y) : (x) ) #endif #ifndef MAX -#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MAX( x, y ) ( (x) > (y) ? (x) : (y) ) #endif #ifndef ABS -#define ABS(y) ((y) >= 0 ? (y) : (-(y))) +#define ABS( y ) ( (y) >= 0 ? (y) : ( -(y) ) ) #endif -#define DEG2RAD(Deg) ((Deg) * M_PI / 180.0) -#define RAD2DEG(Rad) ((Rad) * 180.0 / M_PI) +#define DEG2RAD( Deg ) ( (Deg) * M_PI / 180.0 ) +#define RAD2DEG( Rad ) ( (Rad) * 180.0 / M_PI ) /* Normalize angle to be in the -360.0 .. 360.0 range or 0 .. 360.0: */ -#define NORMALIZE_ANGLE(Angle) { while (Angle < 0) Angle += 3600; \ - while (Angle > 3600) Angle -= 3600; } +#define NORMALIZE_ANGLE( Angle ) { while( Angle < 0 ) \ + Angle += 3600;\ + while( Angle > 3600 ) \ + Angle -= 3600; } /* Normalize angle to be in the 0.0 .. 360.0 range: */ -#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; } +#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; } /* Normalize angle to be in the -90.0 .. 90.0 range */ -#define NORMALIZE_ANGLE_90(Angle) { while (Angle < -900) Angle += 1800; \ - while (Angle > 900) Angle -= 1800; } +#define NORMALIZE_ANGLE_90( Angle ) { while( Angle < -900 ) \ + Angle += 1800;\ + while( Angle > 900 ) \ + Angle -= 1800; } -/* exchange 2 donnees */ -#define EXCHG(a,b) { typeof(a) __temp__ = (a); (a) = (b); (b) = __temp__; } +/* exchange 2 items */ +#define EXCHG( a, b ) { typeof(a)__temp__ = (a); (a) = (b); (b) = __temp__; } -/* macro for insert menuitems with a icon: */ -#define ADD_MENUITEM(menu, id, text, icon) do {\ - wxMenuItem * l_item;\ - l_item = new wxMenuItem(menu, id, text);\ - l_item->SetBitmap(icon); (menu)->Append(l_item);} while(0) +/* inline functions to insert menuitems with a icon: */ +static inline void ADD_MENUITEM( wxMenu* menu, int id, + const wxString& text, + const wxBitmap& icon ) +{ + wxMenuItem* l_item; -#define ADD_MENUITEM_WITH_HELP(menu, id, text, help, icon) do {\ - wxMenuItem * l_item;\ - l_item = new wxMenuItem(menu, id, text, help);\ - l_item->SetBitmap(icon); (menu)->Append(l_item);} while(0) + 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 ); +}; #ifdef __WINDOWS__ -#define ADD_MENUITEM_WITH_SUBMENU(menu, submenu, id, text, icon) do {\ - wxMenuItem * l_item;\ - l_item = new wxMenuItem(menu, id, text);\ - l_item->SetSubMenu(submenu);\ - l_item->SetBitmap(icon);\ - l_item->SetFont(* g_ItalicFont);\ - menu->Append(l_item);} while(0) +static inline void ADD_MENUITEM_WITH_SUBMENU( wxMenu* menu, wxMenu* submenu, + int id, const wxString& text, + const wxBitmap& icon ) +{ + extern wxFont * g_ItalicFont; + wxMenuItem* l_item; + + l_item = new wxMenuItem( menu, id, text ); + l_item->SetSubMenu( submenu ); + l_item->SetBitmap( icon ); + l_item->SetFont( *g_ItalicFont ); + 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, + const wxBitmap& icon ) +{ + extern wxFont * g_ItalicFont; + wxMenuItem* l_item; + + 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 ); +}; -#define ADD_MENUITEM_WITH_HELP_AND_SUBMENU(menu, submenu, id, text, help, icon) do {\ - wxMenuItem * l_item;\ - 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);} while(0) #else -#define ADD_MENUITEM_WITH_SUBMENU(menu, submenu, id, text, icon) do {\ - wxMenuItem * l_item;\ - l_item = new wxMenuItem(menu, id, text);\ - l_item->SetSubMenu(submenu);\ - l_item->SetBitmap(icon);\ - menu->Append(l_item);} while(0) +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, + const wxBitmap& icon ) +{ + wxMenuItem* l_item; + + l_item = new wxMenuItem( menu, id, text, help ); + l_item->SetSubMenu( submenu ); + l_item->SetBitmap( icon ); + menu->Append( l_item ); +}; -#define ADD_MENUITEM_WITH_HELP_AND_SUBMENU(menu, submenu, id, text, help, icon) do {\ - wxMenuItem * l_item;\ - l_item = new wxMenuItem(menu, id, text, help);\ - l_item->SetSubMenu(submenu);\ - l_item->SetBitmap(icon);\ - menu->Append(l_item);} while(0) #endif #ifdef __WINDOWS__ -#define SETBITMAPS(icon) item->SetBitmaps(apply_xpm, (icon)) +#define SETBITMAPS( icon ) item->SetBitmaps( apply_xpm, (icon) ) #else -#define SETBITMAPS(icon) +#define SETBITMAPS( icon ) #endif #endif /* ifdef MACRO_H */ - diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index b4b2053be3..58e5dabc4f 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -245,7 +245,7 @@ void MODULE::UnLink() { if( GetState( DELETED ) ) // A REVOIR car Pback = NULL si place en undelete { - if( g_UnDeleteStack ) + if( g_UnDeleteStackPtr ) g_UnDeleteStack[g_UnDeleteStackPtr - 1] = Next(); } else diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index d219ccde11..99c0f7059a 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -355,7 +355,7 @@ void TRACK::UnLink() { if( GetState( DELETED ) ) // A REVOIR car Pback = NULL si place en undelete { - if( g_UnDeleteStack ) + if( g_UnDeleteStackPtr ) g_UnDeleteStack[g_UnDeleteStackPtr - 1] = (BOARD_ITEM*) Pnext; } else diff --git a/pcbnew/dragsegm.cpp b/pcbnew/dragsegm.cpp index 261a77f47c..ec86ccd602 100644 --- a/pcbnew/dragsegm.cpp +++ b/pcbnew/dragsegm.cpp @@ -240,7 +240,8 @@ void EraseDragListe() pt_drag = g_DragSegmentList; for( ; pt_drag != NULL; pt_drag = NextStruct ) { - NextStruct = pt_drag->Pnext; + NextStruct = pt_drag->Pnext; + pt_drag->m_Segm->m_Flags = 0; pt_drag->m_Segm->m_Flags = 0; delete pt_drag; } diff --git a/todo.txt b/todo.txt index aaeafdebfc..73d57ad921 100644 --- a/todo.txt +++ b/todo.txt @@ -22,16 +22,6 @@ referenced. I think this would be an easier way to manage xpms. *** use BOARD_ITEM::MenuIcon() in the onrightclick.cpp -*** make the ADD_MENUITEM macros in include/macros.h be static inline functions instead -of macros. e.g. w/o argument types: -static inline void ADD_MENUITEM(menu, id, text, icon) -{ - wxMenuItem * l_item; - l_item = new wxMenuItem(menu, id, text); - l_item->SetBitmap(icon); menu->Append(l_item); -} - - *** rework zones so they are modifiable and so that the user does not need to enter tracks for thru hole pads or vias which connect to a zone. I propose a two step solution: @@ -90,4 +80,7 @@ when needed, on the fly. - +2007-Nov-4 Assigned To: nobody +asked by: jp Charras +================================================================================ +Use the collector classes in eeschema.