Commit 992cc5f1 authored by HennerZeller's avatar HennerZeller Committed by jean-pierre charras

Eeschema: * Preselect the currently chosen component in the browser when...

Eeschema:  * Preselect the currently chosen component in the browser when pressing the thumbnail view.
* Various smallish documentation updates in the component chooser area.
parent c7e794dc
......@@ -206,6 +206,9 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName,
LIB_ALIAS* COMPONENT_TREE_SEARCH_CONTAINER::GetSelectedAlias( int* aUnit )
{
if( tree == NULL )
return NULL;
const wxTreeItemId& select_id = tree->GetSelection();
BOOST_FOREACH( TREE_NODE* node, nodes )
......
......@@ -97,7 +97,7 @@ public:
/** Function GetSelectedAlias
*
* @param if not-NULL, the selected sub-unit is set here.
* @return the selected alias or NULL if there is none.
* @return the selected alias or NULL if there is none, or there is no tree.
*/
LIB_ALIAS* GetSelectedAlias( int* aUnit );
......
......@@ -57,16 +57,15 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( wxWindow* aParent, const wxStr
}
// After this dialog is done: return the alias that has been selected, or an
// empty string if there is none.
wxString DIALOG_CHOOSE_COMPONENT::GetSelectedAliasName( int* aUnit ) const
DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
{
LIB_ALIAS *alias = m_search_container->GetSelectedAlias( aUnit );
m_search_container->SetTree( NULL );
}
if( alias )
return alias->GetName();
return wxEmptyString;
LIB_ALIAS* DIALOG_CHOOSE_COMPONENT::GetSelectedAlias( int* aUnit ) const
{
return m_search_container->GetSelectedAlias( aUnit );
}
......@@ -178,7 +177,7 @@ void DIALOG_CHOOSE_COMPONENT::OnInterceptTreeEnter( wxKeyEvent& aEvent )
// Pressing 'Enter' within a tree will also call OnDoubleClickTreeActivation(),
// but since this is not due to the double-click and we have no way of knowing that it is
// not, we need to intercept the 'Enter' key before that to know that it is time to exit.
if ( aEvent.GetKeyCode() == WXK_RETURN )
if( aEvent.GetKeyCode() == WXK_RETURN )
EndModal( wxID_OK ); // Dialog is done.
else
aEvent.Skip(); // Let tree handle that key for navigation.
......
......@@ -27,27 +27,39 @@
#include <dialog_choose_component_base.h>
class COMPONENT_TREE_SEARCH_CONTAINER;
class LIB_ALIAS;
class LIB_COMPONENT;
class wxTreeItemId;
class DIALOG_CHOOSE_COMPONENT : public DIALOG_CHOOSE_COMPONENT_BASE
{
public:
/**
* Create dialog to choose component.
*
* @param aParent Parent window.
* @param aTitle Dialog title.
* @param aSearchContainer The tree selection search container. Needs to be pre-populated
* This dialog does not take over ownership of this object.
* @param aDeMorganConvert preferred deMorgan conversion (TODO: should happen in dialog)
*/
DIALOG_CHOOSE_COMPONENT( wxWindow* aParent, const wxString& aTitle,
COMPONENT_TREE_SEARCH_CONTAINER* aSearch_container,
COMPONENT_TREE_SEARCH_CONTAINER* aSearchContainer,
int aDeMorganConvert );
virtual ~DIALOG_CHOOSE_COMPONENT();
/** Function GetSelectedAliasName
/** Function GetSelectedAlias
* To be called after this dialog returns from ShowModal().
*
* @param aUnit if not NULL, the selected unit is filled in here.
* @return the alias that has been selected, or an empty string if there is none.
* @return the alias that has been selected, or NULL if there is none.
*/
wxString GetSelectedAliasName( int* aUnit ) const;
LIB_ALIAS* GetSelectedAlias( int* aUnit ) const;
/** Function IsExternalBrowserSelected
*
* @return true, iff the browser pressed the browsing button.
* @return true, iff the user pressed the thumbnail view of the component to
* launch the component browser.
*/
bool IsExternalBrowserSelected() const { return m_external_browser_requested; }
......
......@@ -52,8 +52,8 @@
#include <boost/foreach.hpp>
// TODO(hzeller): would be good if we could give a pre-selected component.
wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedAlias,
int* aUnit, int* aConvert )
{
wxSemaphore semaphore( 0, 1 );
wxString cmpname;
......@@ -64,7 +64,21 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
viewlibFrame->Destroy();
viewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore,
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT );
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT );
if ( aPreselectedAlias )
{
viewlibFrame->SetSelectedLibrary( aPreselectedAlias->GetLibraryName() );
viewlibFrame->SetSelectedComponent( aPreselectedAlias->GetName() );
}
if( aUnit && *aUnit > 0 )
viewlibFrame->SetUnit( *aUnit );
if( aConvert && *aConvert > 0 )
viewlibFrame->SetConvert( *aConvert );
viewlibFrame->Refresh();
// Show the library viewer frame until it is closed
// Wait for viewer closing event:
while( semaphore.TryWait() == wxSEMA_BUSY )
......@@ -74,6 +88,13 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
}
cmpname = viewlibFrame->GetSelectedComponent();
if( aUnit )
*aUnit = viewlibFrame->GetUnit();
if( aConvert )
*aConvert = viewlibFrame->GetConvert();
viewlibFrame->Destroy();
return cmpname;
......@@ -125,18 +146,13 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
if( dlg.ShowModal() == wxID_CANCEL )
return wxEmptyString;
wxString cmpName = dlg.GetSelectedAliasName( aUnit );
if( dlg.IsExternalBrowserSelected() )
{
cmpName = SelectComponentFromLibBrowser(); // Would be good if we could pre-select.
if( aUnit )
*aUnit = LIB_VIEW_FRAME::GetUnit();
wxString cmpName;
LIB_ALIAS* const alias = dlg.GetSelectedAlias( aUnit );
if ( alias )
cmpName = alias->GetName();
if( aConvert )
*aConvert = LIB_VIEW_FRAME::GetConvert();
}
if( dlg.IsExternalBrowserSelected() ) // User requested big component browser.
cmpName = SelectComponentFromLibBrowser( alias, aUnit, aConvert);
if ( !cmpName.empty() )
{
......
......@@ -402,12 +402,16 @@ void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
if( ii < 0 )
return;
wxString name = m_libList->GetString( ii );
SetSelectedLibrary( m_libList->GetString( ii ) );
}
if( m_libraryName == name )
void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
{
if( m_libraryName == aLibraryName )
return;
m_libraryName = name;
m_libraryName = aLibraryName;
ReCreateListCmp();
m_canvas->Refresh();
DisplayLibInfos();
......@@ -422,11 +426,15 @@ void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
if( ii < 0 )
return;
wxString name = m_cmpList->GetString( ii );
SetSelectedComponent( m_cmpList->GetString( ii ) );
}
if( m_entryName.CmpNoCase( name ) != 0 )
void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
{
if( m_entryName.CmpNoCase( aComponentName ) != 0 )
{
m_entryName = name;
m_entryName = aComponentName;
DisplayLibInfos();
m_unit = 1;
m_convert = 1;
......@@ -436,6 +444,7 @@ void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
}
}
void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
{
if( m_semaphore )
......@@ -480,10 +489,10 @@ void LIB_VIEW_FRAME::LoadSettings( )
cfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 100 );
// Set parameters to a reasonable value.
if ( m_libListWidth > m_FrameSize.x/2 )
if( m_libListWidth > m_FrameSize.x/2 )
m_libListWidth = m_FrameSize.x/2;
if ( m_cmpListWidth > m_FrameSize.x/2 )
if( m_cmpListWidth > m_FrameSize.x/2 )
m_cmpListWidth = m_FrameSize.x/2;
}
......
......@@ -47,29 +47,6 @@ class CMP_LIBRARY;
*/
class LIB_VIEW_FRAME : public SCH_BASE_FRAME
{
private:
wxComboBox* m_selpartBox;
// List of libraries (for selection )
wxListBox* m_libList; // The list of libs
int m_libListWidth; // Last width of the window
// List of components in the selected library
wxListBox* m_cmpList; // The list of components
int m_cmpListWidth; // Last width of the window
// Flags
wxSemaphore* m_semaphore; // != NULL if the frame must emulate a modal dialog
wxString m_configPath; // subpath for configuration
protected:
static wxString m_libraryName;
static wxString m_entryName;
static wxString m_exportToEeschemaCmpName; // When the viewer is used to select a component
// in schematic, the selected component is here
static int m_unit;
static int m_convert;
public:
LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary = NULL,
wxSemaphore* aSemaphore = NULL,
......@@ -134,11 +111,26 @@ public:
*/
void SaveSettings();
wxString& GetEntryName( void ) const { return m_entryName; }
wxString& GetSelectedComponent( void ) const { return m_exportToEeschemaCmpName; }
/**
* Set the selected library in the library window.
*
* @param aLibName name of the library to be selected.
*/
void SetSelectedLibrary( const wxString& aLibName );
/**
* Set the selected component.
*
* @param the alias name of the component to be selected.
*/
void SetSelectedComponent( const wxString& aComponentName );
const wxString& GetSelectedComponent( void ) const { return m_exportToEeschemaCmpName; }
void SetUnit( int aUnit ) { m_unit = aUnit; }
int GetUnit( void ) { return m_unit; }
static int GetUnit( void ) { return m_unit; }
static int GetConvert( void ) { return m_convert; }
void SetConvert( int aConvert ) { m_convert = aConvert; }
int GetConvert( void ) { return m_convert; }
private:
/**
......@@ -160,6 +152,33 @@ private:
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
void DClickOnCmpList( wxCommandEvent& event );
wxComboBox* m_selpartBox;
// List of libraries (for selection )
wxListBox* m_libList; // The list of libs
int m_libListWidth; // Last width of the window
// List of components in the selected library
wxListBox* m_cmpList; // The list of components
int m_cmpListWidth; // Last width of the window
// Flags
wxSemaphore* m_semaphore; // != NULL if the frame must emulate a modal dialog
wxString m_configPath; // subpath for configuration
// TODO(hzeller): looks like these members were chosen to be static to survive different
// instances of this browser and communicate it to the next instance. This looks like an
// ugly hack, and should be solved differently.
static wxString m_libraryName;
// TODO(hzeller): figure out what the difference between these is and the motivation to
// have this distinction. Shouldn't these essentially be the same ?
static wxString m_entryName;
static wxString m_exportToEeschemaCmpName; // When the viewer is used to select a component
// in schematic, the selected component is here
static int m_unit;
static int m_convert;
DECLARE_EVENT_TABLE()
};
......
......@@ -31,7 +31,7 @@ class PAGE_INFO;
class TITLE_BLOCK;
class LIB_VIEW_FRAME;
class LIB_EDIT_FRAME;
class LIB_ALIAS;
/**
* Class SCH_BASE_FRAME
......@@ -80,9 +80,15 @@ protected:
* Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened
* in modal mode.
* @param aPreslectedAlias Preselected component alias. NULL if none.
* @param aUnit Pointer to Unit-number. Input is the pre-selected unit, output
* is the finally selected unit by the user. Can be NULL.
* @param aConvert Pointer to deMorgan conversion. Input is what is pre-selected,
* output is the finally selected deMorgan type by the user.
* @return the component name
*/
wxString SelectComponentFromLibBrowser( void );
wxString SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedAlias,
int* aUnit, int* aConvert );
/**
* Function SelectComponentFromLib
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment