kicad/pcbnew/pcbcfg.cpp

221 lines
6.7 KiB
C++
Raw Normal View History

2008-02-19 00:35:45 +00:00
/***********************************/
/** pcbcfg() : configuration **/
/***********************************/
/* lit ou met a jour la configuration de PCBNEW */
#include "fctsys.h"
#include "common.h"
#include "pcbnew.h"
#include "pcbplot.h"
#include "pcbcfg.h"
#include "worksheet.h"
#include "id.h"
#include "hotkeys_basic.h"
#include "hotkeys.h"
#include "protos.h"
/* Routines Locales */
/* Variables locales */
2008-02-19 00:35:45 +00:00
#define HOTKEY_FILENAME wxT( "pcbnew" )
/***********************************************************/
2008-02-19 00:35:45 +00:00
void WinEDA_PcbFrame::Process_Config( wxCommandEvent& event )
/***********************************************************/
{
2008-02-19 00:35:45 +00:00
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
wxString FullFileName;
DrawPanel->PrepareGraphicContext( &dc );
pos = GetPosition();
pos.x += 20;
pos.y += 20;
switch( id )
{
case ID_COLORS_SETUP:
DisplayColorSetupFrame( this, pos );
break;
case ID_CONFIG_REQ: // Creation de la fenetre de configuration
InstallConfigFrame( pos );
break;
case ID_PCB_TRACK_SIZE_SETUP:
case ID_PCB_LOOK_SETUP:
case ID_OPTIONS_SETUP:
case ID_PCB_DRAWINGS_WIDTHS_SETUP:
InstallPcbOptionsFrame( pos, &dc, id );
break;
case ID_PCB_PAD_SETUP:
InstallPadOptionsFrame( NULL, NULL, pos );
break;
case ID_CONFIG_SAVE:
Update_config( this );
break;
case ID_CONFIG_READ:
FullFileName = GetScreen()->m_FileName.AfterLast( '/' );
ChangeFileNameExt( FullFileName, g_Prj_Config_Filename_ext );
FullFileName = EDA_FileSelector( _( "Read config file" ),
wxPathOnly( GetScreen()->m_FileName ), /* Chemin par defaut */
FullFileName, /* nom fichier par defaut */
g_Prj_Config_Filename_ext, /* extension par defaut */
FullFileName, /* Masque d'affichage */
this,
wxFD_OPEN,
TRUE /* ne change pas de repertoire courant */
);
if( FullFileName.IsEmpty() )
break;
if( !wxFileExists( FullFileName ) )
{
wxString msg;
msg.Printf( _( "File %s not found" ), FullFileName.GetData() );
DisplayError( this, msg ); break;
}
Read_Config( FullFileName );
break;
case ID_PREFERENCES_CREATE_CONFIG_HOTKEYS:
FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
FullFileName += HOTKEY_FILENAME;
FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
WriteHotkeyConfigFile( FullFileName, s_Pcbnew_Editor_Hokeys_Descr, true );
break;
case ID_PREFERENCES_READ_CONFIG_HOTKEYS:
Read_Hotkey_Config( this, true );
break;
case ID_PREFERENCES_EDIT_CONFIG_HOTKEYS:
{
FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
FullFileName += HOTKEY_FILENAME;
FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
wxString editorname = GetEditorName();
if( !editorname.IsEmpty() )
ExecuteFile( this, editorname, FullFileName );
break;
}
case ID_PREFERENCES_HOTKEY_PATH_IS_HOME:
case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD:
HandleHotkeyConfigMenuSelection( this, id );
break;
case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: // Display Current hotkey list for eeschema
DisplayHotkeyList( this, s_Board_Editor_Hokeys_Descr );
break;
default:
DisplayError( this, wxT( "WinEDA_PcbFrame::Process_Config internal error" ) );
}
}
/***************************************************************/
2008-02-19 00:35:45 +00:00
bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose )
/***************************************************************/
2008-02-19 00:35:45 +00:00
/*
* Read the hotkey files config for pcbnew and module_edit
2008-02-19 00:35:45 +00:00
*/
{
2008-02-19 00:35:45 +00:00
wxString FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
FullFileName += HOTKEY_FILENAME;
FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
return frame->ReadHotkeyConfigFile( FullFileName, s_Pcbnew_Editor_Hokeys_Descr, verbose );
}
/**************************************************************************/
2008-02-19 00:35:45 +00:00
bool Read_Config( const wxString& project_name )
/*************************************************************************/
2008-02-19 00:35:45 +00:00
/* lit la configuration, si elle n'a pas deja ete lue
* 1 - lit <nom fichier brd>.pro
* 2 - si non trouve lit <chemin de *.exe>/kicad.pro
* 3 - si non trouve: init des variables aux valeurs par defaut
*
* Retourne TRUE si lu, FALSE si config non lue ou non modifi<EFBFBD>e
*/
{
2008-02-19 00:35:45 +00:00
wxString FullFileName;
int ii;
2008-02-19 00:35:45 +00:00
g_Prj_Config_Filename_ext = wxT( ".pro" );
FullFileName = project_name;
ChangeFileNameExt( FullFileName, g_Prj_Config_Filename_ext );
2008-02-19 00:35:45 +00:00
/* Init des valeurs par defaut */
g_LibName_List.Clear();
2008-02-19 00:35:45 +00:00
g_EDA_Appl->ReadProjectConfig( FullFileName,
GROUP, ParamCfgList, FALSE );
2008-02-19 00:35:45 +00:00
/* Traitement des variables particulieres: */
2008-02-19 00:35:45 +00:00
SetRealLibraryPath( wxT( "modules" ) );
2008-02-19 00:35:45 +00:00
if( ScreenPcb )
{
ScreenPcb->m_Diviseur_Grille = Pcbdiv_grille;
ScreenPcb->m_UserGrid = g_UserGrid;
ScreenPcb->m_UserGridUnit = g_UserGrid_Unit;
}
2008-02-19 00:35:45 +00:00
g_DesignSettings.m_TrackWidthHistory[0] = g_DesignSettings.m_CurrentTrackWidth;
g_DesignSettings.m_ViaSizeHistory[0] = g_DesignSettings.m_CurrentViaSize;
for( ii = 1; ii < HISTORY_NUMBER; ii++ )
{
g_DesignSettings.m_TrackWidthHistory[ii] = 0;
g_DesignSettings.m_ViaSizeHistory[ii] = 0;
}
2008-02-19 00:35:45 +00:00
return TRUE;
}
2008-02-19 00:35:45 +00:00
/**********************************************************/
2008-02-19 00:35:45 +00:00
void WinEDA_PcbFrame::Update_config( wxWindow* displayframe )
/***********************************************************/
/* enregistrement de la config */
{
2008-02-19 00:35:45 +00:00
wxString FullFileName;
wxString mask;
mask = wxT( "*" ) + g_Prj_Config_Filename_ext;
FullFileName = GetScreen()->m_FileName.AfterLast( '/' );
ChangeFileNameExt( FullFileName, g_Prj_Config_Filename_ext );
FullFileName = EDA_FileSelector( _( "Save preferences" ),
wxPathOnly( GetScreen()->m_FileName ), /* Chemin par defaut */
FullFileName, /* nom fichier par defaut */
g_Prj_Config_Filename_ext, /* extension par defaut */
mask, /* Masque d'affichage */
displayframe,
wxFD_SAVE,
TRUE
);
if( FullFileName.IsEmpty() )
return;
Pcbdiv_grille = GetScreen()->m_Diviseur_Grille;
/* ecriture de la configuration */
g_EDA_Appl->WriteProjectConfig( FullFileName, wxT( "/pcbnew" ), ParamCfgList );
}