kicad/pcbnew/dialog_setup_libs.cpp

523 lines
16 KiB
C++

/////////////////////////////////////////////////////////////////////////////
// Name: dialog_pcbnew_config.cpp
// Purpose:
// Author: jean-pierre Charras
// Modified by:
// Created: 18/02/2006 16:41:57
// RCS-ID:
// Copyright: License GNU
// Licence:
/////////////////////////////////////////////////////////////////////////////
/* Handle the pcbnew libary config (library list, and default lib path)
*/
// Generated by DialogBlocks (unregistered), 18/02/2006 16:41:57
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dialog_pcbnew_config.h"
#endif
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "gr_basic.h"
#include "common.h"
#include "confirm.h"
#include "gestfich.h"
#include "pcbnew.h"
////@begin includes
////@end includes
#include "dialog_setup_libs.h"
////@begin XPM images
////@end XPM images
/*****************************************************************/
void WinEDA_PcbFrame::InstallConfigFrame( const wxPoint& pos )
/*****************************************************************/
{
KiConfigPcbnewFrame* CfgFrame = new KiConfigPcbnewFrame( this );
CfgFrame->ShowModal(); CfgFrame->Destroy();
}
/*!
* KiConfigPcbnewFrame type definition
*/
IMPLEMENT_DYNAMIC_CLASS( KiConfigPcbnewFrame, wxDialog )
/*!
* KiConfigPcbnewFrame event table definition
*/
BEGIN_EVENT_TABLE( KiConfigPcbnewFrame, wxDialog )
////@begin KiConfigPcbnewFrame event table entries
EVT_CLOSE( KiConfigPcbnewFrame::OnCloseWindow )
EVT_BUTTON( SAVE_CFG, KiConfigPcbnewFrame::OnSaveCfgClick )
EVT_BUTTON( DEL_LIB, KiConfigPcbnewFrame::OnDelLibClick )
EVT_BUTTON( ADD_LIB, KiConfigPcbnewFrame::OnAddLibClick )
EVT_BUTTON( INSERT_LIB, KiConfigPcbnewFrame::OnInsertLibClick )
////@end KiConfigPcbnewFrame event table entries
END_EVENT_TABLE()
/*!
* KiConfigPcbnewFrame constructors
*/
KiConfigPcbnewFrame::KiConfigPcbnewFrame()
{
}
KiConfigPcbnewFrame::KiConfigPcbnewFrame( WinEDA_PcbFrame* parent,
wxWindowID id,
const wxString& caption,
const wxPoint& pos,
const wxSize& size,
long style )
{
wxString title;
wxConfig* cfg = wxGetApp().m_EDA_CommonConfig;
m_Parent = parent;
m_LibModified = FALSE;
Create( parent, id, caption, pos, size, style );
title = _( "from " ) + wxGetApp().m_CurrentOptionFile;
SetTitle( title );
m_ListLibr->InsertItems( g_LibName_List, 0 );
wxString DocModuleFileName = cfg->Read( wxT( "module_doc_file" ),
wxT( "pcbnew/footprints.pdf" ) );
m_TextHelpModulesFileName->SetValue( DocModuleFileName );
}
/*!
* KiConfigPcbnewFrame creator
*/
bool KiConfigPcbnewFrame::Create( wxWindow* parent,
wxWindowID id,
const wxString& caption,
const wxPoint& pos,
const wxSize& size,
long style )
{
////@begin KiConfigPcbnewFrame member initialisation
m_FileExtList = NULL;
m_ListLibr = NULL;
m_TextLibDir = NULL;
m_TextHelpModulesFileName = NULL;
////@end KiConfigPcbnewFrame member initialisation
////@begin KiConfigPcbnewFrame creation
SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
wxDialog::Create( parent, id, caption, pos, size, style );
CreateControls();
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
Centre();
////@end KiConfigPcbnewFrame creation
return true;
}
/*!
* Control creation for KiConfigPcbnewFrame
*/
void KiConfigPcbnewFrame::CreateControls()
{
SetFont( *g_DialogFont );
////@begin KiConfigPcbnewFrame content construction
// Generated by DialogBlocks, 18/02/2006 17:19:54 (unregistered)
KiConfigPcbnewFrame* itemDialog1 = this;
wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
itemDialog1->SetSizer( itemBoxSizer2 );
wxBoxSizer* itemBoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
itemBoxSizer2->Add( itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
wxBoxSizer* itemBoxSizer4 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer3->Add( itemBoxSizer4, 0, wxGROW | wxALL, 5 );
wxButton* itemButton5 =
new wxButton( itemDialog1, SAVE_CFG, _(
"Save Cfg" ), wxDefaultPosition, wxDefaultSize, 0 );
itemButton5->SetForegroundColour( wxColour( 204, 0, 0 ) );
itemBoxSizer4->Add( itemButton5, 0, wxGROW | wxALL, 5 );
itemBoxSizer4->Add( 5, 5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
wxStaticBox* itemStaticBoxSizer7Static =
new wxStaticBox( itemDialog1, wxID_ANY, _(
"Files ext:" ) );
m_FileExtList = new wxStaticBoxSizer( itemStaticBoxSizer7Static,
wxVERTICAL );
itemBoxSizer4->Add( m_FileExtList, 0, wxGROW | wxALL, 5 );
wxBoxSizer* itemBoxSizer8 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer3->Add( itemBoxSizer8,
0,
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
5 );
wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxHORIZONTAL );
itemBoxSizer8->Add( itemBoxSizer9,
0,
wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT |
wxBOTTOM,
5 );
wxBoxSizer* itemBoxSizer10 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer9->Add( itemBoxSizer10, 0, wxALIGN_CENTER_VERTICAL, 5 );
wxBoxSizer* itemBoxSizer11 = new wxBoxSizer( wxHORIZONTAL );
itemBoxSizer10->Add( itemBoxSizer11,
0,
wxALIGN_CENTER_HORIZONTAL | wxALL,
5 );
wxButton* itemButton12 = new wxButton( itemDialog1, DEL_LIB, _(
"Del" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemButton12->SetForegroundColour( wxColour( 204, 0, 0 ) );
itemBoxSizer11->Add( itemButton12, 0, wxGROW | wxALL, 5 );
wxButton* itemButton13 = new wxButton( itemDialog1, ADD_LIB, _(
"Add" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemButton13->SetForegroundColour( wxColour( 0, 128, 0 ) );
itemBoxSizer11->Add( itemButton13, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
wxButton* itemButton14 = new wxButton( itemDialog1, INSERT_LIB, _(
"Ins" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemButton14->SetDefault();
itemButton14->SetForegroundColour( wxColour( 0, 0, 255 ) );
itemBoxSizer11->Add( itemButton14, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
wxBoxSizer* itemBoxSizer15 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer10->Add( itemBoxSizer15, 0, wxGROW | wxALL, 5 );
wxStaticText* itemStaticText16 = new wxStaticText( itemDialog1,
wxID_STATIC,
_( "Libraries" ),
wxDefaultPosition,
wxDefaultSize,
0 );
itemStaticText16->SetForegroundColour( wxColour( 204, 0, 0 ) );
itemBoxSizer15->Add( itemStaticText16,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
wxString* m_ListLibrStrings = NULL;
m_ListLibr = new wxListBox( itemDialog1,
ID_LIST_LIBS,
wxDefaultPosition,
wxSize( -1, 200 ),
0,
m_ListLibrStrings,
wxLB_SINGLE | wxSUNKEN_BORDER );
itemBoxSizer15->Add( m_ListLibr,
0,
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
5 );
wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1,
wxID_STATIC,
_( "Lib Modules Dir:" ),
wxDefaultPosition,
wxDefaultSize,
wxALIGN_LEFT );
itemStaticText18->SetForegroundColour( wxColour( 204, 0, 0 ) );
itemBoxSizer2->Add( itemStaticText18,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
m_TextLibDir = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(
"" ), wxDefaultPosition, wxDefaultSize,
0 );
itemBoxSizer2->Add( m_TextLibDir,
0,
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
5 );
wxStaticText* itemStaticText20 = new wxStaticText( itemDialog1,
wxID_STATIC,
_( "Module Doc File:" ),
wxDefaultPosition,
wxDefaultSize,
wxALIGN_LEFT );
itemStaticText20->SetForegroundColour( wxColour( 204, 0, 0 ) );
itemBoxSizer2->Add( itemStaticText20,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
m_TextHelpModulesFileName =
new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, _T(
"" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer2->Add( m_TextHelpModulesFileName,
0,
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
5 );
// Set validators
m_TextLibDir->SetValidator( wxTextValidator( wxFILTER_NONE,
&g_UserLibDirBuffer ) );
////@end KiConfigPcbnewFrame content construction
wxString msg = _( "Board ext: " ) + PcbExtBuffer;
wxStaticText* text = new wxStaticText( itemDialog1,
-1,
msg,
wxDefaultPosition,
wxDefaultSize,
0 );
m_FileExtList->Add( text,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
msg = _( "Cmp ext: " ) + NetCmpExtBuffer;
text = new wxStaticText( itemDialog1,
-1,
msg,
wxDefaultPosition,
wxDefaultSize,
0 );
m_FileExtList->Add( text,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
msg = _( "Lib ext: " ) + ModuleFileExtension;
text = new wxStaticText( itemDialog1,
-1,
msg,
wxDefaultPosition,
wxDefaultSize,
0 );
m_FileExtList->Add( text,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
msg = _( "Net ext: " ) + NetExtBuffer;
text = new wxStaticText( itemDialog1,
-1,
msg,
wxDefaultPosition,
wxDefaultSize,
0 );
m_FileExtList->Add( text,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
5 );
}
/*!
* wxEVT_CLOSE_WINDOW event handler for ID_DIALOG
*/
void KiConfigPcbnewFrame::OnCloseWindow( wxCloseEvent& event )
{
SetNewOptions();
EndModal( 0 );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for SAVE_CFG
*/
void KiConfigPcbnewFrame::OnSaveCfgClick( wxCommandEvent& event )
{
SetNewOptions();
m_Parent->Update_config( this );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for DEL_LIB
*/
void KiConfigPcbnewFrame::OnDelLibClick( wxCommandEvent& event )
{
LibDelFct( event );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ADD_LIB
*/
void KiConfigPcbnewFrame::OnAddLibClick( wxCommandEvent& event )
{
LibInsertFct( event );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for INSERT_LIB
*/
void KiConfigPcbnewFrame::OnInsertLibClick( wxCommandEvent& event )
{
LibInsertFct( event );
}
/*!
* Should we show tooltips?
*/
bool KiConfigPcbnewFrame::ShowToolTips()
{
return true;
}
/*!
* Get bitmap resources
*/
wxBitmap KiConfigPcbnewFrame::GetBitmapResource( const wxString& name )
{
// Bitmap retrieval
////@begin KiConfigPcbnewFrame bitmap retrieval
wxUnusedVar( name );
return wxNullBitmap;
////@end KiConfigPcbnewFrame bitmap retrieval
}
/*!
* Get icon resources
*/
wxIcon KiConfigPcbnewFrame::GetIconResource( const wxString& name )
{
// Icon retrieval
////@begin KiConfigPcbnewFrame icon retrieval
wxUnusedVar( name );
return wxNullIcon;
////@end KiConfigPcbnewFrame icon retrieval
}
/********************************************/
void KiConfigPcbnewFrame::SetNewOptions()
/********************************************/
{
wxConfig* cfg = wxGetApp().m_EDA_CommonConfig;
g_UserLibDirBuffer = m_TextLibDir->GetValue();
cfg->Write( wxT( "module_doc_file" ),
m_TextHelpModulesFileName->GetValue() );
}
/********************************************************/
void KiConfigPcbnewFrame::LibDelFct( wxCommandEvent& event )
/********************************************************/
{
int ii;
ii = m_ListLibr->GetSelection();
if( ii < 0 )
return;
g_LibName_List.RemoveAt( ii );
m_ListLibr->Clear();
m_ListLibr->InsertItems( g_LibName_List, 0 );
m_LibModified = TRUE;
}
/*************************************************************
* Insert or add a library to the existing library list:
* New library is put in list before (insert) or after (add)
* the selection.
*
*************************************************************/
void KiConfigPcbnewFrame::LibInsertFct( wxCommandEvent& event )
{
int ii;
wxFileName fn;
wxString tmp;
ii = m_ListLibr->GetSelection();
if( ii == wxNOT_FOUND && event.GetId() == INSERT_LIB )
ii = 0;
SetNewOptions();
wxFileDialog FilesDialog( this, _( "Foot Print Library Files" ),
wxEmptyString, wxEmptyString,
ModuleFileWildcard, wxFD_OPEN | wxFD_MULTIPLE );
if( FilesDialog.ShowModal() != wxID_OK )
return;
wxArrayString Filenames;
FilesDialog.GetPaths( Filenames );
for( unsigned jj = 0; jj < Filenames.GetCount(); jj++ )
{
fn = Filenames[jj];
/* If the library path is already in the library search paths
* list, just add the library name to the list. Otherwise, add
* the library name with the full path. */
if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) == wxNOT_FOUND )
tmp = fn.GetPathWithSep() + fn.GetName();
else
tmp = fn.GetName();
// Add or insert new library name.
if( g_LibName_List.Index( tmp, fn.IsCaseSensitive() ) == wxNOT_FOUND )
{
m_LibModified = TRUE;
if( event.GetId() == ADD_LIB )
g_LibName_List.Add( tmp );
else
g_LibName_List.Insert( tmp, ii++ );
m_ListLibr->Clear();
m_ListLibr->InsertItems( g_LibName_List, 0 );
}
else
{
wxString msg = wxT( "<" ) + tmp + wxT( "> : " ) +
_( "Library already in use" );
DisplayError( this, msg );
}
}
}