dialog_eeschema_config.cpp 14.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
/////////////////////////////////////////////////////////////////////////////
// Name:        dialog_eeschema_config.cpp
// Purpose:     
// Author:      jean-pierre Charras
// Modified by: 
// Created:     17/02/2006 21:14:46
// RCS-ID:      
// Copyright:   License GNU
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// Generated by DialogBlocks (unregistered), 17/02/2006 21:14:46

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dialog_eeschema_config.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes
#include "fctsys.h"

#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"

#include "protos.h"
#include "netlist.h"

#include "id.h"

#include "dialog_eeschema_config.h"

////@begin XPM images
////@end XPM images

/******************************************************************/
void WinEDA_SchematicFrame::InstallConfigFrame(const wxPoint & pos)
/******************************************************************/
{
	KiConfigEeschemaFrame * CfgFrame = new KiConfigEeschemaFrame(this);
	CfgFrame->ShowModal(); CfgFrame->Destroy();
}


/*!
 * KiConfigEeschemaFrame type definition
 */

IMPLEMENT_DYNAMIC_CLASS( KiConfigEeschemaFrame, wxDialog )

/*!
 * KiConfigEeschemaFrame event table definition
 */

BEGIN_EVENT_TABLE( KiConfigEeschemaFrame, wxDialog )

////@begin KiConfigEeschemaFrame event table entries
    EVT_CLOSE( KiConfigEeschemaFrame::OnCloseWindow )

    EVT_BUTTON( SAVE_CFG, KiConfigEeschemaFrame::OnSaveCfgClick )

    EVT_LISTBOX( FORMAT_NETLIST, KiConfigEeschemaFrame::OnFormatNetlistSelected )

    EVT_BUTTON( REMOVE_LIB, KiConfigEeschemaFrame::OnRemoveLibClick )

    EVT_BUTTON( ADD_LIB, KiConfigEeschemaFrame::OnAddLibClick )

    EVT_BUTTON( INSERT_LIB, KiConfigEeschemaFrame::OnInsertLibClick )

    EVT_BUTTON( ID_LIB_PATH_SEL, KiConfigEeschemaFrame::OnLibPathSelClick )

////@end KiConfigEeschemaFrame event table entries

END_EVENT_TABLE()

/*!
 * KiConfigEeschemaFrame constructors
 */

KiConfigEeschemaFrame::KiConfigEeschemaFrame( )
{
}

KiConfigEeschemaFrame::KiConfigEeschemaFrame( WinEDA_SchematicFrame* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
wxString msg;

	m_Parent = parent;
	m_LibListChanged = FALSE;

    Create(parent, id, caption, pos, size, style);
	
	msg = _("from ") + g_EDA_Appl->m_CurrentOptionFile;
	SetTitle(msg);
	SetFormatsNetListes();
	m_ListLibr->InsertItems(g_LibName_List, 0);
	m_LibDirCtrl->SetValue( g_UserLibDirBuffer );
}

/*!
 * KiConfigEeschemaFrame creator
 */

bool KiConfigEeschemaFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin KiConfigEeschemaFrame member initialisation
    m_NetFormatBox = NULL;
    m_FileExtList = NULL;
    m_ListLibr = NULL;
    m_LibDirCtrl = NULL;
////@end KiConfigEeschemaFrame member initialisation

////@begin KiConfigEeschemaFrame creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end KiConfigEeschemaFrame creation
    return true;
}

/*!
 * Control creation for KiConfigEeschemaFrame
 */

void KiConfigEeschemaFrame::CreateControls()
{    
	SetFont(*g_DialogFont);

////@begin KiConfigEeschemaFrame content construction
    // Generated by DialogBlocks, 10/11/2007 16:00:50 (unregistered)

    KiConfigEeschemaFrame* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|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 );
    if (KiConfigEeschemaFrame::ShowToolTips())
        itemButton5->SetToolTip(_("save current configuration setting in the local .pro file"));
    itemButton5->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer4->Add(itemButton5, 0, wxGROW|wxALL, 5);

    itemBoxSizer4->Add(5, 5, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("NetList Formats:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer4->Add(itemStaticText7, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);

    wxArrayString m_NetFormatBoxStrings;
    m_NetFormatBox = new wxListBox( itemDialog1, FORMAT_NETLIST, wxDefaultPosition, wxDefaultSize, m_NetFormatBoxStrings, wxLB_SINGLE );
    itemBoxSizer4->Add(m_NetFormatBox, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    itemBoxSizer4->Add(5, 5, 0, wxGROW|wxALL, 5);

    wxStaticBox* itemStaticBoxSizer10Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Files ext:"));
    m_FileExtList = new wxStaticBoxSizer(itemStaticBoxSizer10Static, wxVERTICAL);
    itemBoxSizer4->Add(m_FileExtList, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer3->Add(itemBoxSizer11, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer11->Add(itemBoxSizer12, 1, wxGROW, 5);

    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer12->Add(itemBoxSizer13, 0, wxGROW|wxALL, 5);

    wxButton* itemButton14 = new wxButton( itemDialog1, REMOVE_LIB, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
    if (KiConfigEeschemaFrame::ShowToolTips())
        itemButton14->SetToolTip(_("Unload the selected library"));
    itemButton14->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer13->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton15 = new wxButton( itemDialog1, ADD_LIB, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
    if (KiConfigEeschemaFrame::ShowToolTips())
        itemButton15->SetToolTip(_("Add a new library after the selected library, add load it"));
    itemButton15->SetForegroundColour(wxColour(0, 128, 0));
    itemBoxSizer13->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton16 = new wxButton( itemDialog1, INSERT_LIB, _("Ins"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton16->SetHelpText(_("Add a new library beforer the selected library, add load it"));
    if (KiConfigEeschemaFrame::ShowToolTips())
        itemButton16->SetToolTip(_("Add a new library beforer the selected library, add load it"));
    itemButton16->SetForegroundColour(wxColour(0, 0, 255));
    itemBoxSizer13->Add(itemButton16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer12->Add(itemBoxSizer17, 1, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1, wxID_STATIC, _("Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStaticText18->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

    wxArrayString m_ListLibrStrings;
    m_ListLibr = new wxListBox( itemDialog1, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, m_ListLibrStrings, wxLB_SINGLE );
    itemBoxSizer17->Add(m_ListLibr, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM|wxADJUST_MINSIZE, 5);

    wxStaticBox* itemStaticBoxSizer20Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Default library file path:"));
    wxStaticBoxSizer* itemStaticBoxSizer20 = new wxStaticBoxSizer(itemStaticBoxSizer20Static, wxHORIZONTAL);
    itemStaticBoxSizer20Static->SetForegroundColour(wxColour(206, 0, 0));
    itemBoxSizer2->Add(itemStaticBoxSizer20, 0, wxGROW|wxALL, 5);

    m_LibDirCtrl = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
    if (KiConfigEeschemaFrame::ShowToolTips())
        m_LibDirCtrl->SetToolTip(_("Default path to search libraries which have no absolute path in name,\nor a name which does not start by ./ or ../\nIf void, the default path is kicad/library"));
    itemStaticBoxSizer20->Add(m_LibDirCtrl, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    wxButton* itemButton22 = new wxButton( itemDialog1, ID_LIB_PATH_SEL, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStaticBoxSizer20->Add(itemButton22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

////@end KiConfigEeschemaFrame content construction

wxString msg = _("Cmp file Ext: ") + g_NetCmpExtBuffer;
    wxStaticText * text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Net file Ext: ") + g_NetExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Library file Ext: ") + g_LibExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Symbol file Ext: ") + g_SymbolExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Schematic file Ext: ") + g_SchExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
    
    wxArrayString NetlistNameItems;
    NetlistNameItems.Add(wxT("Pcbnew"));
    NetlistNameItems.Add(wxT("OrcadPcb2"));
    NetlistNameItems.Add(wxT("CadStar"));
    NetlistNameItems.Add(wxT("Spice"));
    msg = ReturnUserNetlistTypeName( true );
    while ( ! msg.IsEmpty() )
    {
        NetlistNameItems.Add(msg);
        msg = ReturnUserNetlistTypeName( false );
    }
    m_NetFormatBox->InsertItems(NetlistNameItems, 0);
}

/*!
 * Should we show tooltips?
 */

bool KiConfigEeschemaFrame::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap KiConfigEeschemaFrame::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin KiConfigEeschemaFrame bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end KiConfigEeschemaFrame bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon KiConfigEeschemaFrame::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin KiConfigEeschemaFrame icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end KiConfigEeschemaFrame icon retrieval
}



/**************************************************************/
void KiConfigEeschemaFrame::OnCloseWindow(wxCloseEvent & event)
/**************************************************************/
{
	ChangeSetup();
	if ( m_LibListChanged )
	{
		LoadLibraries(m_Parent);
		if ( m_Parent->m_Parent->m_ViewlibFrame )
			m_Parent->m_Parent->m_ViewlibFrame->ReCreateListLib();
	}
	EndModal(0);
}


/*********************************************/
void KiConfigEeschemaFrame::ChangeSetup()
/*********************************************/
{
	g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
	SetRealLibraryPath( wxT("library") );
}



/********************************************************/
void KiConfigEeschemaFrame::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_LibListChanged = TRUE;
}

/****************************************************************/
void KiConfigEeschemaFrame::AddOrInsertLibrary(wxCommandEvent& event)
/****************************************************************/
/* Insert or add a library to the existing library list:
	New library is put in list before (insert) or after (add)
	the selection
*/
{
int ii;
wxString FullLibName,ShortLibName, Mask;

	ii = m_ListLibr->GetSelection();
	if ( ii < 0 ) ii = 0;
	ChangeSetup();
	if( event.GetId() == ADD_LIB)
	{
		if( g_LibName_List.GetCount() != 0 ) ii ++;	/* Add after selection */
	}

	Mask = wxT("*") + g_LibExtBuffer;
	FullLibName = EDA_FileSelector( _("Library files:"),
				g_RealLibDirBuffer,		/* Chemin par defaut */
				wxEmptyString,					/* nom fichier par defaut */
				g_LibExtBuffer,		/* extension par defaut */
				Mask,				/* Masque d'affichage */
				this,
				wxFD_OPEN,
				TRUE
				);

	if ( FullLibName.IsEmpty() ) return;

	ShortLibName = MakeReducedFileName(FullLibName,g_RealLibDirBuffer,g_LibExtBuffer);

	//Add or insert new library name
	if (FindLibrary(ShortLibName) == NULL)
	{
		m_LibListChanged = TRUE;
		g_LibName_List.Insert(ShortLibName, ii);
		m_ListLibr->Clear();
		m_ListLibr->InsertItems(g_LibName_List, 0);
	}

	else DisplayError(this, _("Library already in use"));

}



/****************************************************/
void KiConfigEeschemaFrame::SetFormatsNetListes()
/****************************************************/
/* Adjust the m_NetFormatBox current selection, according to the current netlist format*/

{
	if ( g_NetFormat > (int)m_NetFormatBox->GetCount() )
		g_NetFormat = NET_TYPE_PCBNEW;
	m_NetFormatBox->SetSelection(g_NetFormat - NET_TYPE_PCBNEW);
}

/*!
 * wxEVT_COMMAND_NETLIST_SELECTED event handler for FORMAT_NETLIST
 */

void KiConfigEeschemaFrame::OnFormatNetlistSelected( wxCommandEvent& event )
{
	g_NetFormat = m_NetFormatBox->GetSelection() + NET_TYPE_PCBNEW;
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for DEL_LIB
 */

void KiConfigEeschemaFrame::OnRemoveLibClick( wxCommandEvent& event )
{
	LibDelFct(event);
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ADD_LIB
 */

void KiConfigEeschemaFrame::OnAddLibClick( wxCommandEvent& event )
{
	AddOrInsertLibrary(event);
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for INSERT_LIB
 */

void KiConfigEeschemaFrame::OnInsertLibClick( wxCommandEvent& event )
{
	AddOrInsertLibrary(event);
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for SAVE_CFG
 */

void KiConfigEeschemaFrame::OnSaveCfgClick( wxCommandEvent& event )
{
	ChangeSetup();
	m_Parent->Save_Config(this);
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_LIB_PATH_SEL
 */

void KiConfigEeschemaFrame::OnLibPathSelClick( wxCommandEvent& event )
{
wxString path = g_RealLibDirBuffer;
	
bool select = EDA_DirectorySelector(_(" Default Path for libraries"),		/* Titre de la fenetre */
					path,			/* Chemin par defaut */
					wxDD_DEFAULT_STYLE,
					this,	/* parent frame */
					wxDefaultPosition);

	if ( !select ) return;
	
	m_LibDirCtrl->SetValue(path);

}