2007-06-05 12:10:51 +00:00
|
|
|
/*********************************/
|
2009-10-16 17:18:23 +00:00
|
|
|
/* get_component_dialog.cpp */
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "macros.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "wxstruct.h"
|
2009-10-16 17:18:23 +00:00
|
|
|
#include "get_component_dialog.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Show a dialog frame to choose a name from an history list, or a new name */
|
|
|
|
/* to select a component or a module */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
static unsigned s_HistoryMaxCount = 8; // Max number of items displayed in history list
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( WinEDA_SelectCmp, wxDialog )
|
|
|
|
EVT_BUTTON( ID_ACCEPT_NAME, WinEDA_SelectCmp::Accept )
|
|
|
|
EVT_BUTTON( ID_ACCEPT_KEYWORD, WinEDA_SelectCmp::Accept )
|
|
|
|
EVT_BUTTON( ID_CANCEL, WinEDA_SelectCmp::Accept )
|
|
|
|
EVT_BUTTON( ID_LIST_ALL, WinEDA_SelectCmp::Accept )
|
|
|
|
EVT_BUTTON( ID_EXTRA_TOOL, WinEDA_SelectCmp::GetExtraSelection )
|
|
|
|
EVT_LISTBOX( ID_SEL_BY_LISTBOX, WinEDA_SelectCmp::Accept )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
/*
|
|
|
|
* Dialog frame to choose a component or a footprint
|
|
|
|
* This dialog shows an history of last selected items
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
|
|
|
|
const wxPoint& framepos,
|
|
|
|
wxArrayString& HistoryList,
|
|
|
|
const wxString& Title,
|
|
|
|
bool show_extra_tool ) :
|
|
|
|
wxDialog( parent, -1, Title, framepos, wxDefaultSize, DIALOG_STYLE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxButton* Button;
|
|
|
|
wxStaticText* Text;
|
|
|
|
|
|
|
|
m_AuxTool = show_extra_tool;
|
2009-10-16 17:18:23 +00:00
|
|
|
m_GetExtraFunction = false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( MainBoxSizer );
|
|
|
|
|
|
|
|
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
MainBoxSizer->Add( LeftBoxSizer,
|
|
|
|
0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALL | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
|
|
|
|
|
|
|
|
Text = new wxStaticText( this, -1, _( "Name:" ) );
|
|
|
|
LeftBoxSizer->Add( Text, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5 );
|
|
|
|
|
2009-10-17 06:23:18 +00:00
|
|
|
m_TextCtrl = new wxTextCtrl( this, ID_ENTER_NAME, m_Text );
|
2009-04-05 20:49:15 +00:00
|
|
|
m_TextCtrl->SetInsertionPoint( 1 );
|
2010-01-29 17:19:13 +00:00
|
|
|
m_TextCtrl->SetFocus();
|
2009-04-05 20:49:15 +00:00
|
|
|
LeftBoxSizer->Add( m_TextCtrl,
|
|
|
|
0,
|
|
|
|
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
|
|
|
|
Text = new wxStaticText( this, -1, _( "History list:" ) );
|
|
|
|
LeftBoxSizer->Add( Text, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5 );
|
|
|
|
|
|
|
|
m_List = new wxListBox( this, ID_SEL_BY_LISTBOX, wxDefaultPosition,
|
|
|
|
wxSize( 220, -1 ), HistoryList, wxLB_SINGLE );
|
|
|
|
LeftBoxSizer->Add( m_List,
|
|
|
|
0,
|
|
|
|
wxGROW | wxLEFT | wxRIGHT | wxBOTTOM | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
|
|
|
|
Button = new wxButton( this, ID_ACCEPT_NAME, _( "OK" ) );
|
|
|
|
Button->SetDefault();
|
|
|
|
RightBoxSizer->Add( Button,
|
|
|
|
0,
|
|
|
|
wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM,
|
|
|
|
5 );
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
Button = new wxButton( this, ID_ACCEPT_KEYWORD, _( "Search by Keyword" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
|
|
|
|
|
|
|
Button = new wxButton( this, ID_CANCEL, _( "Cancel" ) );
|
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
|
|
|
|
|
|
|
Button = new wxButton( this, ID_LIST_ALL, _( "List All" ) );
|
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#ifndef __WXMAC__
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_AuxTool ) /* The selection can be done by an extra function */
|
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
Button = new wxButton( this, ID_EXTRA_TOOL, _( "Select by Browser" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
void WinEDA_SelectCmp::Accept( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
int id = wxID_OK;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_SEL_BY_LISTBOX:
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text = m_List->GetStringSelection();
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ACCEPT_NAME:
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text = m_TextCtrl->GetValue();
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ACCEPT_KEYWORD:
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text = wxT( "= " ) + m_TextCtrl->GetValue();
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_CANCEL:
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text = wxEmptyString;
|
|
|
|
id = wxID_CANCEL;
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIST_ALL:
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text = wxT( "*" );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Text.Trim( false ); // Remove blanks at beginning
|
|
|
|
m_Text.Trim( true ); // Remove blanks at end
|
|
|
|
|
|
|
|
if( IsModal() )
|
|
|
|
EndModal( id );
|
|
|
|
else
|
|
|
|
Close( id );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
/* Get the component name by the extra function */
|
2009-04-05 20:49:15 +00:00
|
|
|
void WinEDA_SelectCmp::GetExtraSelection( wxCommandEvent& event )
|
2009-10-16 17:18:23 +00:00
|
|
|
{
|
|
|
|
m_GetExtraFunction = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
if( IsModal() )
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
else
|
|
|
|
Close( wxID_OK );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString WinEDA_SelectCmp::GetComponentName( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
return m_Text;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
void WinEDA_SelectCmp::SetComponentName( const wxString& name )
|
|
|
|
{
|
|
|
|
if( m_TextCtrl )
|
|
|
|
m_TextCtrl->SetValue( name );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
wxPoint GetComponentDialogPosition( void )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
wxPoint pos;
|
2009-04-05 20:49:15 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
pos = wxGetMousePosition();
|
2009-04-05 20:49:15 +00:00
|
|
|
wxClientDisplayRect( &x, &y, &w, &h );
|
2009-10-16 17:18:23 +00:00
|
|
|
pos.x -= 100;
|
|
|
|
pos.y -= 50;
|
|
|
|
if( pos.x < x )
|
|
|
|
pos.x = x;
|
|
|
|
if( pos.y < y )
|
|
|
|
pos.y = y;
|
|
|
|
if( pos.x < x )
|
|
|
|
pos.x = x;
|
2009-04-05 20:49:15 +00:00
|
|
|
x += w - 350;
|
2009-10-16 17:18:23 +00:00
|
|
|
if( pos.x > x )
|
|
|
|
pos.x = x;
|
|
|
|
if( pos.y < y )
|
|
|
|
pos.y = y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
return pos;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
/*
|
|
|
|
* Add the string "Name" to the history list HistoryList
|
2009-04-05 20:49:15 +00:00
|
|
|
*/
|
2009-10-16 17:18:23 +00:00
|
|
|
void AddHistoryComponentName( wxArrayString& HistoryList, const wxString& Name )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int ii, c_max;
|
|
|
|
|
|
|
|
if( HistoryList.GetCount() > 0 )
|
|
|
|
{
|
|
|
|
if( Name == HistoryList[0] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* remove an old identical selection if exists */
|
|
|
|
for( ii = 1; (unsigned) ii < HistoryList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
if( Name == HistoryList[ii] )
|
|
|
|
{
|
|
|
|
HistoryList.RemoveAt( ii ); ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shift the list */
|
|
|
|
if( HistoryList.GetCount() < s_HistoryMaxCount )
|
|
|
|
HistoryList.Add( wxT( "" ) );
|
|
|
|
|
|
|
|
c_max = HistoryList.GetCount() - 2;
|
|
|
|
for( ii = c_max; ii >= 0; ii-- )
|
|
|
|
HistoryList[ii + 1] = HistoryList[ii];
|
|
|
|
|
|
|
|
/* Add the new name at the beginning of the history list */
|
|
|
|
HistoryList[0] = Name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
HistoryList.Add( Name );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|