From 07767585c32b3ff51583533953e7bea162a4af94 Mon Sep 17 00:00:00 2001 From: charras Date: Thu, 30 Oct 2008 20:12:29 +0000 Subject: [PATCH] better code compatibility with others compilers (MSVC) --- 3d-viewer/CMakeLists.txt | 3 +- change_log.txt | 4 ++ common/CMakeLists.txt | 3 ++ common/base_struct.cpp | 3 -- common/common.cpp | 12 ++++++ cvpcb/CMakeLists.txt | 1 + eeschema/CMakeLists.txt | 2 +- gerbview/CMakeLists.txt | 1 + include/common.h | 16 ++++++-- include/macros.h | 83 ++++++++++++++++++++++++++-------------- kicad/CMakeLists.txt | 4 ++ 11 files changed, 94 insertions(+), 38 deletions(-) diff --git a/3d-viewer/CMakeLists.txt b/3d-viewer/CMakeLists.txt index 9350c8a2f4..472a74bd38 100644 --- a/3d-viewer/CMakeLists.txt +++ b/3d-viewer/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DPCBNEW) -include_directories(../pcbnew +include_directories(${Boost_INCLUDE_DIR} + ../pcbnew ../polygon) set(3D-VIEWER_SRCS diff --git a/change_log.txt b/change_log.txt index 53ddb89d02..67962fc464 100644 --- a/change_log.txt +++ b/change_log.txt @@ -10,6 +10,10 @@ email address. ================================================================================ ++All Use double instead float when possible, ande code cleaning. + Some changes for a better code compatibility with others compliers (MSVC) + (__MSVC__ must be defined when using MSVC) + (double round(double) and typeof unkown in MSVC) + Note: I cannot test kicad under MSVC. 2008-Oct-19 UPDATE Dick Hollenbeck diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index f3d644af30..c4985834ab 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,3 +1,6 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${Boost_INCLUDE_DIR} + ) set(COMMON_SRCS about_kicad.cpp base_screen.cpp diff --git a/common/base_struct.cpp b/common/base_struct.cpp index 9b1f8ac379..d6766a610b 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -7,14 +7,11 @@ /* Fichier base_struct.cpp */ #include "fctsys.h" -#include "gr_basic.h" #include "trigo.h" -#include "macros.h" #include "common.h" #include "wxstruct.h" #include "base_struct.h" #include "grfonte.h" - #include "macros.h" enum textbox { diff --git a/common/common.cpp b/common/common.cpp index 80824de85c..95509f6322 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -555,3 +555,15 @@ wxString& operator <<( wxString& aString, const wxPoint& aPos ) return aString; } + + +#ifdef __MSVC__ // compilers that does not have the round function (posix) +/* return the nearest rounded ( equivalent to the nearest integer value) + * from aNumber + */ +double round( double aNumber ) +{ + return floor( aNumber + 0.5 ); +} +#endif + diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index bcfeab765c..f8a0c85d9c 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DCVPCB) include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${Boost_INCLUDE_DIR} ../3d-viewer ../pcbnew ../polygon) diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 7e53869e7a..e2face971e 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -1,7 +1,7 @@ add_definitions(-DEESCHEMA) include_directories(${CMAKE_CURRENT_SOURCE_DIR} -# ${Boost_INCLUDE_DIR} + ${Boost_INCLUDE_DIR} ) set(EESCHEMA_SRCS diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index abc25d55f0..cdffc898b7 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DGERBVIEW -DPCBNEW) include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${Boost_INCLUDE_DIR} ../3d-viewer ../cvpcb ../pcbnew diff --git a/include/common.h b/include/common.h index 7fb6ce645a..979d48f919 100644 --- a/include/common.h +++ b/include/common.h @@ -405,12 +405,20 @@ wxString& operator <<( wxString& aString, const wxPoint& aPoint ); bool ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC ); + +/** + * Function ReturnPcbLayerName + * @return a wxString containing the name of the layer number "layer_number". + * @param layer_number the layer number of the layer + * @param is_filename if TRUE, the name can be used for a file name (not internatinalized, no space) + */ wxString ReturnPcbLayerName( int layer_number, bool is_filename = FALSE ); -/* Return the name of the layer number "layer_number". - * if "is_filename" == TRUE, the name can be used for a file name - * (not internatinalized, no space)*/ - +#ifdef __MSVC__ // compilers that does not have the round function (posix) +/* return the near rounded (like the equivalent integer value) from aNumber +*/ +double round( double aNumber ); +#endif /**************/ /* DRAWTXT.CPP */ diff --git a/include/macros.h b/include/macros.h index 800c86877d..c00da4269d 100644 --- a/include/macros.h +++ b/include/macros.h @@ -15,46 +15,71 @@ #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 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; } -/****************************************/ -/* inline functions to exchange 2 items */ -/****************************************/ +/*****************************/ +/* macro to exchange 2 items */ +/*****************************/ -#define EXCHG( a, b ) { typeof(a) __temp__ = (a); (a) = (b); (b) = __temp__; } +/* 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__; } /*****************************************************/ @@ -62,7 +87,7 @@ /*****************************************************/ static inline void ADD_MENUITEM( wxMenu* menu, int id, const wxString& text, - const wxBitmap& icon ) + const wxBitmap& icon ) { wxMenuItem* l_item; @@ -88,8 +113,8 @@ 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; + extern wxFont* g_ItalicFont; + wxMenuItem* l_item; l_item = new wxMenuItem( menu, id, text ); l_item->SetSubMenu( submenu ); @@ -98,15 +123,15 @@ static inline void ADD_MENUITEM_WITH_SUBMENU( wxMenu* menu, wxMenu* submenu, menu->Append( l_item ); }; -static inline void ADD_MENUITEM_WITH_HELP_AND_SUBMENU( wxMenu* menu, - wxMenu* submenu, +static inline void ADD_MENUITEM_WITH_HELP_AND_SUBMENU( wxMenu* menu, + wxMenu* submenu, int id, const wxString& text, const wxString& help, - const wxBitmap& icon ) + const wxBitmap& icon ) { - extern wxFont * g_ItalicFont; - wxMenuItem* l_item; + extern wxFont* g_ItalicFont; + wxMenuItem* l_item; l_item = new wxMenuItem( menu, id, text, help ); l_item->SetSubMenu( submenu ); @@ -134,7 +159,7 @@ static inline void ADD_MENUITEM_WITH_HELP_AND_SUBMENU( wxMenu* menu, int id, const wxString& text, const wxString& help, - const wxBitmap& icon ) + const wxBitmap& icon ) { wxMenuItem* l_item; diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index cd1359ea62..96a32ed1bc 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -1,5 +1,9 @@ add_definitions(-DKICAD) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${Boost_INCLUDE_DIR} + ) + set(KICAD_SRCS buildmnu.cpp commandframe.cpp