Commit b65590f7 authored by charras's avatar charras
Browse files

code cleanup in project_config.cpp and some enhancements

parent 2eaa28f0
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,17 @@ KiCad ChangeLog 2009
Please add newer entries at the top, list the date and your name with
Please add newer entries at the top, list the date and your name with
email address.
email address.


2009-mar-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++All
    code cleanup in project_config.cpp.
    Now parameters common to all projects are saved on exit.
    (they are usally options like colors, draw options ...)

++pcbnew:
    added option to show or not netnames on pads and tracks


2009-mar-23 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
2009-mar-23 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
================================================================================
++pcbnew:
++pcbnew:
+25 −22
Original line number Original line Diff line number Diff line
@@ -53,7 +53,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
                      void (* aCallback) (int x0, int y0, int xf, int yf))
                      void (* aCallback) (int x0, int y0, int xf, int yf))
/****************************************************************************************************/
/****************************************************************************************************/
{
{
    int            ii, kk, char_count, AsciiCode, endcar;
    int            kk, char_count, AsciiCode;
    int            x0, y0;
    int            x0, y0;
    int            size_h, size_v, pitch;
    int            size_h, size_v, pitch;
    SH_CODE        f_cod, plume = 'U';
    SH_CODE        f_cod, plume = 'U';
@@ -62,7 +62,8 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
    int            ux0, uy0, dx, dy;    // Draw coordinate for segments to draw. also used in some other calculation
    int            ux0, uy0, dx, dy;    // Draw coordinate for segments to draw. also used in some other calculation
    int            cX, cY;              // Texte center
    int            cX, cY;              // Texte center
    int            ox, oy;              // Draw coordinates for the current char
    int            ox, oy;              // Draw coordinates for the current char
    int            coord[100];          // Buffer coordinate used to draw polylines (char shapes)
    #define        BUF_SIZE 100
    wxPoint        coord[BUF_SIZE+1];          // Buffer coordinate used to draw polylines (one char shape)
    bool           sketch_mode = false;
    bool           sketch_mode = false;
	bool		   italic_reverse = false;		// true for mirrored texts with m_Size.x < 0
	bool		   italic_reverse = false;		// true for mirrored texts with m_Size.x < 0


@@ -72,7 +73,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
    if( aWidth < 0 )
    if( aWidth < 0 )
    {
    {
        aWidth = -aWidth;
        aWidth = -aWidth;
        sketch_mode = TRUE;
        sketch_mode = true;
    }
    }
    int thickness = aWidth;
    int thickness = aWidth;
	if ( aSize.x < 0 )		// text is mirrored using size.x < 0 (mirror / Y axis)
	if ( aSize.x < 0 )		// text is mirrored using size.x < 0 (mirror / Y axis)
@@ -234,7 +235,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
        ptcar = graphic_fonte_shape[AsciiCode];  /* ptcar pointe la description
        ptcar = graphic_fonte_shape[AsciiCode];  /* ptcar pointe la description
                                                  *  du caractere a dessiner */
                                                  *  du caractere a dessiner */


        for( ii = 0, endcar = FALSE; !endcar; ptcar++ )
        int point_count;
        bool endcar;
        for( point_count = 0, endcar = false; !endcar; ptcar++ )
        {
        {
            f_cod = *ptcar;
            f_cod = *ptcar;


@@ -242,36 +245,34 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
            switch( f_cod )
            switch( f_cod )
            {
            {
            case 'X':
            case 'X':
                endcar = TRUE;    /* fin du caractere */
                endcar = true;    /* fin du caractere */
                break;
                break;


            case 'U':
            case 'U':
                if( ii && (plume == 'D' ) )
                if( point_count && (plume == 'D' ) )
                {
                {
                    if( aWidth <= 1 )
                    if( aWidth <= 1 )
                       aWidth = 0;
                       aWidth = 0;
                    if ( aCallback )
                    if ( aCallback )
                    {
                    {
                        int ik, * coordptr;
                        for( int ik = 0; ik < (point_count - 1); ik ++ )
                        coordptr = coord;
                        {
                        for( ik = 0; ik < (ii - 2); ik += 2, coordptr += 2 )
                           aCallback( coord[ik].x, coord[ik].y,
                            aCallback( *coordptr, *(coordptr + 1),
                                     coord[ik+1].x, coord[ik+1].y );
                                     *(coordptr + 2), *(coordptr + 3) );
                        }
                    }
                    }


                    else if( sketch_mode )
                    else if( sketch_mode )
                    {
                    {
                        int ik, * coordptr;
                        for( int ik = 0; ik < (point_count - 1); ik ++ )
                        coordptr = coord;
                            GRCSegm( &aPanel->m_ClipBox, aDC, coord[ik].x, coord[ik].y,
                        for( ik = 0; ik < (ii - 2); ik += 2, coordptr += 2 )
                                     coord[ik+1].x, coord[ik+1].y, aWidth, aColor );
                            GRCSegm( &aPanel->m_ClipBox, aDC, *coordptr, *(coordptr + 1),
                                     *(coordptr + 2), *(coordptr + 3), aWidth, aColor );
                    }
                    }
                    else
                    else
                        GRPoly( &aPanel->m_ClipBox, aDC, ii / 2, (wxPoint*)coord, 0,
                        GRPoly( &aPanel->m_ClipBox, aDC, point_count, coord, 0,
                                aWidth, aColor, aColor );
                                aWidth, aColor, aColor );
                }
                }
                plume = f_cod; ii = 0;
                plume = f_cod; point_count = 0;
                break;
                break;


            case 'D':
            case 'D':
@@ -295,8 +296,10 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
                    dx    = k2 + ox; dy = k1 + oy;
                    dx    = k2 + ox; dy = k1 + oy;


                    RotatePoint( &dx, &dy, cX, cY, aOrient );
                    RotatePoint( &dx, &dy, cX, cY, aOrient );
                    coord[ii++] = dx;
                    coord[point_count].x = dx;
                    coord[ii++] = dy;
                    coord[point_count].y = dy;
                    if ( point_count < BUF_SIZE-1 )
                        point_count++;
                    break;
                    break;
                }
                }
            }
            }
+1 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@


#include "appl_wxstruct.h"
#include "appl_wxstruct.h"
#include "common.h"
#include "common.h"
#include "param_config.h"
#include "worksheet.h"
#include "worksheet.h"
#include "id.h"
#include "id.h"
#include "build_version.h"
#include "build_version.h"
+289 −219
Original line number Original line Diff line number Diff line
@@ -8,10 +8,11 @@
#include "common.h"
#include "common.h"
#include "kicad_string.h"
#include "kicad_string.h"
#include "gestfich.h"
#include "gestfich.h"
#include "param_config.h"


#define CONFIG_VERSION 1
#define CONFIG_VERSION 1


#define FORCE_LOCAL_CONFIG TRUE
#define FORCE_LOCAL_CONFIG true




/*********************************************************************/
/*********************************************************************/
@@ -26,8 +27,8 @@ static bool ReCreatePrjConfig( const wxString& local_config_filename,
 *     g_Prj_Config_LocalFilename
 *     g_Prj_Config_LocalFilename
 *     g_Prj_Default_Config_FullFilename
 *     g_Prj_Default_Config_FullFilename
 * return:
 * return:
 *     TRUE si config locale
 *     true si config locale
 *     FALSE si default config
 *     false si default config
 */
 */
{
{
    // free old config
    // free old config
@@ -56,7 +57,7 @@ static bool ReCreatePrjConfig( const wxString& local_config_filename,
        g_Prj_Config->DontCreateOnDemand();
        g_Prj_Config->DontCreateOnDemand();


        if( ForceUseLocalConfig )
        if( ForceUseLocalConfig )
            return TRUE;
            return true;


        // Test de la bonne version du fichier (ou groupe) de configuration
        // Test de la bonne version du fichier (ou groupe) de configuration
        int version = -1, def_version = 0;
        int version = -1, def_version = 0;
@@ -64,7 +65,7 @@ static bool ReCreatePrjConfig( const wxString& local_config_filename,
        version = g_Prj_Config->Read( wxT( "version" ), def_version );
        version = g_Prj_Config->Read( wxT( "version" ), def_version );
        g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
        g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
        if( version > 0 )
        if( version > 0 )
            return TRUE;
            return true;
        else
        else
            delete g_Prj_Config;    // Version incorrecte
            delete g_Prj_Config;    // Version incorrecte
    }
    }
@@ -86,7 +87,7 @@ static bool ReCreatePrjConfig( const wxString& local_config_filename,


    g_Prj_Config->DontCreateOnDemand();
    g_Prj_Config->DontCreateOnDemand();


    return FALSE;
    return false;
}
}




@@ -95,9 +96,14 @@ void WinEDA_App::WriteProjectConfig( const wxString& local_config_filename,
                                     const wxString&  GroupName,
                                     const wxString&  GroupName,
                                     PARAM_CFG_BASE** List )
                                     PARAM_CFG_BASE** List )
/***************************************************************************************/
/***************************************************************************************/
/* enregistrement de la config "projet"*/

/** Function WriteProjectConfig
 *  Save the current "projet" parameters
 *  saved parameters are parameters that have the .m_Setup member set to false
 *  saving file is the .pro file project
 */
{
{
    const PARAM_CFG_BASE* pt_cfg;
    PARAM_CFG_BASE* pt_cfg;
    wxString        msg;
    wxString        msg;


    ReCreatePrjConfig( local_config_filename, GroupName,
    ReCreatePrjConfig( local_config_filename, GroupName,
@@ -114,7 +120,7 @@ void WinEDA_App::WriteProjectConfig( const wxString& local_config_filename,


    g_Prj_Config->Write( wxT( "last_client" ), msg );
    g_Prj_Config->Write( wxT( "last_client" ), msg );


    /* ecriture de la configuration */
    /* Save parameters */
    g_Prj_Config->DeleteGroup( GroupName );   // Erase all datas
    g_Prj_Config->DeleteGroup( GroupName );   // Erase all datas
    g_Prj_Config->Flush();
    g_Prj_Config->Flush();


@@ -130,109 +136,56 @@ void WinEDA_App::WriteProjectConfig( const wxString& local_config_filename,
        else
        else
            g_Prj_Config->SetPath( GroupName );
            g_Prj_Config->SetPath( GroupName );


        switch( pt_cfg->m_Type )
        {
        case PARAM_INT:
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_INT*) pt_cfg )
            if( PTCFG->m_Pt_param == NULL )
                break;

            if( pt_cfg->m_Setup )
                m_EDA_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            else
                g_Prj_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            break;

        case PARAM_SETCOLOR:
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_SETCOLOR*) pt_cfg )
            if( PTCFG->m_Pt_param == NULL )
                break;

        if( pt_cfg->m_Setup )
        if( pt_cfg->m_Setup )
                m_EDA_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            continue;
            else
                g_Prj_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            break;


        case PARAM_DOUBLE:
        if ( pt_cfg->m_Type == PARAM_COMMAND_ERASE )    // Erase all data
            #undef PTCFG
        {
            #define PTCFG ( (PARAM_CFG_DOUBLE*) pt_cfg )
            if( pt_cfg->m_Ident )
            if( PTCFG->m_Pt_param == NULL )
                g_Prj_Config->DeleteGroup( pt_cfg->m_Ident );
                break;
        }

            if( pt_cfg->m_Setup )
                m_EDA_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
        else
        else
                g_Prj_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            pt_cfg->SaveParam( g_Prj_Config );
            break;
    }

        case PARAM_BOOL:
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_BOOL*) pt_cfg )
            if( PTCFG->m_Pt_param == NULL )
                break;


            if( pt_cfg->m_Setup )
    g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
                m_EDA_Config->Write( pt_cfg->m_Ident, (int) *PTCFG->m_Pt_param );
    delete g_Prj_Config;
            else
    g_Prj_Config = NULL;
                g_Prj_Config->Write( pt_cfg->m_Ident, (int) *PTCFG->m_Pt_param );
}
            break;


        case PARAM_WXSTRING:
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_WXSTRING*) pt_cfg )
            if( PTCFG->m_Pt_param == NULL )
                break;


            if( pt_cfg->m_Setup )
/*****************************************************************/
                m_EDA_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
void WinEDA_App::SaveCurrentSetupValues( PARAM_CFG_BASE** aList )
            else
/*****************************************************************/
                g_Prj_Config->Write( pt_cfg->m_Ident, *PTCFG->m_Pt_param );
            break;


        case PARAM_LIBNAME_LIST:
/** Function SaveCurrentSetupValues()
 * Save the current setup values in m_EDA_Config
 * saved parameters are parameters that have the .m_Setup member set to true
 * @param aList = array of PARAM_CFG_BASE pointers
 */
{
{
            #undef PTCFG
    PARAM_CFG_BASE* pt_cfg;
            #define PTCFG ( (PARAM_CFG_LIBNAME_LIST*) pt_cfg )
    wxString        msg;
            if( PTCFG->m_Pt_param == NULL )
                break;


            wxArrayString* libname_list = PTCFG->m_Pt_param;
    if( m_EDA_Config == NULL )
            if( libname_list == NULL )
        return;
                break;


            unsigned indexlib = 0;
    for( ; *aList != NULL; aList++ )
            wxString cle_config;
            for( ; indexlib < libname_list->GetCount(); indexlib++ )
    {
    {
                cle_config = pt_cfg->m_Ident;
        pt_cfg = *aList;
        if( pt_cfg->m_Setup == false )
            continue;


                // We use indexlib+1 because first lib name is LibName1
        if ( pt_cfg->m_Type == PARAM_COMMAND_ERASE )    // Erase all data
                cle_config << (indexlib + 1);
                g_Prj_Config->Write( cle_config,
                                     libname_list->Item( indexlib ) );
            }

            break;
        }

        case PARAM_COMMAND_ERASE:       // Erase all datas
            if( pt_cfg->m_Ident )
        {
        {
            if( pt_cfg->m_Ident )
                m_EDA_Config->DeleteGroup( pt_cfg->m_Ident );
                m_EDA_Config->DeleteGroup( pt_cfg->m_Ident );
                g_Prj_Config->DeleteGroup( pt_cfg->m_Ident );
        }
        }
            break;
        else
            pt_cfg->SaveParam( m_EDA_Config );
    }
    }
}
}


    g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
    delete g_Prj_Config;
    g_Prj_Config = NULL;
}



/***************************************************************************************/
/***************************************************************************************/
bool WinEDA_App::ReadProjectConfig( const wxString&  local_config_filename,
bool WinEDA_App::ReadProjectConfig( const wxString&  local_config_filename,
@@ -241,31 +194,34 @@ bool WinEDA_App::ReadProjectConfig( const wxString& local_config_filename,
                                    bool             Load_Only_if_New )
                                    bool             Load_Only_if_New )
/***************************************************************************************/
/***************************************************************************************/


/* Lecture de la config "projet"
/** Function ReadProjectConfig
 *** si Load_Only_if_New == TRUE, elle n'est lue que si elle
 *  Read the current "projet" parameters
 *** est differente de la config actuelle (dates differentes)
 *  Parameters are parameters that have the .m_Setup member set to false
 *  read file is the .pro file project
 *
 *
 * return:
 * if Load_Only_if_New == true, this file is read only if it diders from
 *     TRUE si lue.
 * the current config (different dates )
 * Met a jour en plus:
 *
 * @return      true if read.
 * Also set:
 *     wxGetApp().m_CurrentOptionFileDateAndTime
 *     wxGetApp().m_CurrentOptionFileDateAndTime
 *     wxGetApp().m_CurrentOptionFile
 *     wxGetApp().m_CurrentOptionFile
 */
 */
{
{
    const PARAM_CFG_BASE* pt_cfg;
    PARAM_CFG_BASE* pt_cfg;
    wxString        timestamp;
    wxString        timestamp;


    if( List == NULL )
    if( List == NULL )
        return FALSE;
        return false;


    ReCreatePrjConfig( local_config_filename, GroupName, FALSE );
    ReCreatePrjConfig( local_config_filename, GroupName, false );


    g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
    g_Prj_Config->SetPath( UNIX_STRING_DIR_SEP );
    timestamp = g_Prj_Config->Read( wxT( "update" ) );
    timestamp = g_Prj_Config->Read( wxT( "update" ) );
    if( Load_Only_if_New && ( !timestamp.IsEmpty() )
    if( Load_Only_if_New && ( !timestamp.IsEmpty() )
       && (timestamp == wxGetApp().m_CurrentOptionFileDateAndTime) )
       && (timestamp == wxGetApp().m_CurrentOptionFileDateAndTime) )
    {
    {
        return FALSE;
        return false;
    }
    }


    wxGetApp().m_CurrentOptionFileDateAndTime = timestamp;
    wxGetApp().m_CurrentOptionFileDateAndTime = timestamp;
@@ -289,123 +245,41 @@ bool WinEDA_App::ReadProjectConfig( const wxString& local_config_filename,
        else
        else
            g_Prj_Config->SetPath( GroupName );
            g_Prj_Config->SetPath( GroupName );


        switch( pt_cfg->m_Type )
        {
        case PARAM_INT:
        {
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_INT*) pt_cfg )
            int itmp;
            if( pt_cfg->m_Setup )
                itmp = m_EDA_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );
            else
                itmp = g_Prj_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );

            if( (itmp < PTCFG->m_Min) || (itmp > PTCFG->m_Max) )
                itmp = PTCFG->m_Default;

            *PTCFG->m_Pt_param = itmp;
            break;
        }

        case PARAM_SETCOLOR:
        {
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_SETCOLOR*) pt_cfg )
            int itmp;
        if( pt_cfg->m_Setup )
        if( pt_cfg->m_Setup )
                itmp = m_EDA_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );
            continue;
            else
                itmp = g_Prj_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );


            if( (itmp < 0) || (itmp > MAX_COLOR) )
        pt_cfg->ReadParam( g_Prj_Config );
                itmp = PTCFG->m_Default;

            *PTCFG->m_Pt_param = itmp;
            break;
    }
    }


        case PARAM_DOUBLE:
    delete g_Prj_Config;
        {
    g_Prj_Config = NULL;
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_DOUBLE*) pt_cfg )
            double ftmp = 0;
            wxString msg;
            if( pt_cfg->m_Setup )
                msg = m_EDA_Config->Read( pt_cfg->m_Ident, wxT( "" ) );
            else
                msg = g_Prj_Config->Read( pt_cfg->m_Ident, wxT( "" ) );


            if( msg.IsEmpty() )
    return true;
                ftmp = PTCFG->m_Default;
            else
            {
                msg.ToDouble( &ftmp );
                if( (ftmp < PTCFG->m_Min) || (ftmp > PTCFG->m_Max) )
                    ftmp = PTCFG->m_Default;
            }
            *PTCFG->m_Pt_param = ftmp;
            break;
}
}


        case PARAM_BOOL:
        {
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_BOOL*) pt_cfg )
            int itmp;
            if( pt_cfg->m_Setup )
                itmp = m_EDA_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );
            else
                itmp = g_Prj_Config->Read( pt_cfg->m_Ident, PTCFG->m_Default );


            *PTCFG->m_Pt_param = itmp ? TRUE : FALSE;
/***************************************************************/
            break;
void WinEDA_App::ReadCurrentSetupValues( PARAM_CFG_BASE** aList )
        }
/***************************************************************/


        case PARAM_WXSTRING:
/** Function ReadCurrentSetupValues()
 * Raed the current setup values previously saved, from m_EDA_Config
 * saved parameters are parameters that have the .m_Setup member set to true
 * @param aList = array of PARAM_CFG_BASE pointers
 */
{
{
            #undef PTCFG
    PARAM_CFG_BASE* pt_cfg;
            #define PTCFG ( (PARAM_CFG_WXSTRING*) pt_cfg )
            if( PTCFG->m_Pt_param == NULL )
                break;


            if( pt_cfg->m_Setup )
    for( ; *aList != NULL; aList++ )
                *PTCFG->m_Pt_param = m_EDA_Config->Read( pt_cfg->m_Ident );
            else
                *PTCFG->m_Pt_param = g_Prj_Config->Read( pt_cfg->m_Ident );
            break;
        }

        case PARAM_LIBNAME_LIST:
        {
            #undef PTCFG
            #define PTCFG ( (PARAM_CFG_LIBNAME_LIST*) pt_cfg )
            int indexlib = 1;       // We start indexlib to 1 because first lib name is LibName1
            wxString libname, id_lib;
            wxArrayString* libname_list = PTCFG->m_Pt_param;
            while( 1 )
    {
    {
                id_lib  = pt_cfg->m_Ident; id_lib << indexlib; indexlib++;
        pt_cfg = *aList;
                libname = g_Prj_Config->Read( id_lib, wxT( "" ) );
        if( pt_cfg->m_Setup == false )
                if( libname.IsEmpty() )
            continue;
                    break;
                libname_list->Add( libname );
            }


            break;
        pt_cfg->ReadParam( m_EDA_Config );
        }

        case PARAM_COMMAND_ERASE:
            break;
    }
    }
}
}


    delete g_Prj_Config;
    g_Prj_Config = NULL;

    return TRUE;
}



/**************************************************************/
/**************************************************************/
/* Constructeurs des descripteurs de structs de configuration */
/* Constructeurs des descripteurs de structs de configuration */
@@ -417,7 +291,7 @@ PARAM_CFG_BASE::PARAM_CFG_BASE( const wxChar* ident, const paramcfg_id type,
    m_Ident = ident;
    m_Ident = ident;
    m_Type  = type;
    m_Type  = type;
    m_Group = group;
    m_Group = group;
    m_Setup = FALSE;
    m_Setup = false;
}
}




@@ -446,6 +320,37 @@ PARAM_CFG_INT::PARAM_CFG_INT( bool Insetup, const wxChar* ident, int* ptparam,
}
}




/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_INT::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    int itmp = aConfig->Read( m_Ident, m_Default );

    if( (itmp < m_Min) || (itmp > m_Max) )
        itmp = m_Default;

    *m_Pt_param = itmp;
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_INT::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    aConfig->Write( m_Ident, *m_Pt_param );
}


/**************************************************************************/

PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR( const wxChar* ident, int* ptparam,
PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR( const wxChar* ident, int* ptparam,
                                        int default_val,
                                        int default_val,
                                        const wxChar* group ) :
                                        const wxChar* group ) :
@@ -469,6 +374,34 @@ PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR( bool Insetup,
}
}




/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_SETCOLOR::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    int itmp = aConfig->Read( m_Ident, m_Default );

    if( (itmp < 0) || (itmp > MAX_COLOR) )
        itmp = m_Default;
    *m_Pt_param = itmp;
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_SETCOLOR::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    aConfig->Write( m_Ident, *m_Pt_param );
}


PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE( const wxChar* ident, double* ptparam,
PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE( const wxChar* ident, double* ptparam,
                                    double default_val, double min, double max,
                                    double default_val, double min, double max,
                                    const wxChar* group ) :
                                    const wxChar* group ) :
@@ -498,12 +431,50 @@ PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE( bool Insetup,
}
}




/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_DOUBLE::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    double   ftmp = 0;
    wxString msg;
    msg = g_Prj_Config->Read( m_Ident, wxT( "" ) );

    if( msg.IsEmpty() )
        ftmp = m_Default;
    else
    {
        msg.ToDouble( &ftmp );
        if( (ftmp < m_Min) || (ftmp > m_Max) )
            ftmp = m_Default;
    }
    *m_Pt_param = ftmp;
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_DOUBLE::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    aConfig->Write( m_Ident, *m_Pt_param );
}


/***********************************************************************/

PARAM_CFG_BOOL::PARAM_CFG_BOOL( const wxChar* ident, bool* ptparam,
PARAM_CFG_BOOL::PARAM_CFG_BOOL( const wxChar* ident, bool* ptparam,
                                int default_val, const wxChar* group ) :
                                int default_val, const wxChar* group ) :
    PARAM_CFG_BASE( ident, PARAM_BOOL, group )
    PARAM_CFG_BASE( ident, PARAM_BOOL, group )
{
{
    m_Pt_param = ptparam;
    m_Pt_param = ptparam;
    m_Default  = default_val ? TRUE : FALSE;
    m_Default  = default_val ? true : false;
}
}




@@ -515,11 +486,38 @@ PARAM_CFG_BOOL::PARAM_CFG_BOOL( bool Insetup,
    PARAM_CFG_BASE( ident, PARAM_BOOL, group )
    PARAM_CFG_BASE( ident, PARAM_BOOL, group )
{
{
    m_Pt_param = ptparam;
    m_Pt_param = ptparam;
    m_Default  = default_val ? TRUE : FALSE;
    m_Default  = default_val ? true : false;
    m_Setup    = Insetup;
    m_Setup    = Insetup;
}
}




/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_BOOL::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    int itmp = aConfig->Read( m_Ident, (int) m_Default );

    *m_Pt_param = itmp ? true : false;
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_BOOL::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    aConfig->Write( m_Ident, *m_Pt_param );
}


/*********************************************************************/
PARAM_CFG_WXSTRING::PARAM_CFG_WXSTRING( const wxChar* ident,
PARAM_CFG_WXSTRING::PARAM_CFG_WXSTRING( const wxChar* ident,
                                        wxString*     ptparam,
                                        wxString*     ptparam,
                                        const wxChar* group ) :
                                        const wxChar* group ) :
@@ -539,6 +537,31 @@ PARAM_CFG_WXSTRING::PARAM_CFG_WXSTRING( bool Insetup, const wxChar* ident,
}
}




/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_WXSTRING::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    *m_Pt_param = aConfig->Read( m_Ident );
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_WXSTRING::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    aConfig->Write( m_Ident, *m_Pt_param );
}


/***************************************************************************/
PARAM_CFG_LIBNAME_LIST::PARAM_CFG_LIBNAME_LIST( const wxChar*  ident,
PARAM_CFG_LIBNAME_LIST::PARAM_CFG_LIBNAME_LIST( const wxChar*  ident,
                                                wxArrayString* ptparam,
                                                wxArrayString* ptparam,
                                                const wxChar*  group ) :
                                                const wxChar*  group ) :
@@ -546,3 +569,50 @@ PARAM_CFG_LIBNAME_LIST::PARAM_CFG_LIBNAME_LIST( const wxChar* ident,
{
{
    m_Pt_param = ptparam;
    m_Pt_param = ptparam;
}
}


/** ReadParam
 * read the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that store the parameter
 */
void PARAM_CFG_LIBNAME_LIST::ReadParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    int            indexlib = 1; // We start indexlib to 1 because first lib name is LibName1
    wxString       libname, id_lib;
    wxArrayString* libname_list = m_Pt_param;
    while( 1 )
    {
        id_lib = m_Ident;
        id_lib << indexlib;
        indexlib++;
        libname = aConfig->Read( id_lib, wxT( "" ) );
        if( libname.IsEmpty() )
            break;
        libname_list->Add( libname );
    }
}


/** SaveParam
 * the the value of parameter thi stored in aConfig
 * @param aConfig = the wxConfigBase that can store the parameter
 */
void PARAM_CFG_LIBNAME_LIST::SaveParam( wxConfigBase* aConfig )
{
    if( m_Pt_param == NULL || aConfig == NULL )
        return;
    wxArrayString* libname_list = m_Pt_param;

    unsigned       indexlib = 0;
    wxString       cle_config;
    for( ; indexlib < libname_list->GetCount(); indexlib++ )
    {
        cle_config = m_Ident;

        // We use indexlib+1 because first lib name is LibName1
        cle_config << (indexlib + 1);
        aConfig->Write( cle_config, libname_list->Item( indexlib ) );
    }
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,8 @@
#define eda_global extern
#define eda_global extern
#endif
#endif


#include "param_config.h"

#define INSETUP TRUE
#define INSETUP TRUE


#define GROUP wxT("/cvpcb")
#define GROUP wxT("/cvpcb")
Loading