Commit 5927f026 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Footprint viewer improvements and code cleaning.

* Use wxAuiManager perspective to save and load window settings which should
  allow us to start using more advanced wxAui features like detachable tool
  bars and windows.
* Remove sash size change events, event handler, and sash width clamping code
  since it didn't work all that well anyway.
* Disable the close button on the footprint view pane.
* Update the footprint list box selection when iterating the list using the
  tool bar arrow buttons.
* Merge code from modview.cpp into modview_frame.cpp and remove modview.cpp.
parent 5f0679bf
...@@ -126,7 +126,6 @@ set( PCBNEW_AUTOROUTER_SRCS ...@@ -126,7 +126,6 @@ set( PCBNEW_AUTOROUTER_SRCS
set( PCBNEW_CLASS_SRCS set( PCBNEW_CLASS_SRCS
tool_modview.cpp tool_modview.cpp
modview.cpp
modview_frame.cpp modview_frame.cpp
pcbframe.cpp pcbframe.cpp
attribut.cpp attribut.cpp
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file modview.cpp
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <dialog_helpers.h>
#include <3d_viewer.h>
#include <pcbcommon.h>
#include <macros.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <modview_frame.h>
#include <wildcards_and_files_ext.h>
#define NEXT_PART 1
#define NEW_PART 0
#define PREVIOUS_PART -1
void FOOTPRINT_VIEWER_FRAME::Process_Special_Functions( wxCommandEvent& event )
{
wxString msg;
switch( event.GetId() )
{
case ID_MODVIEW_NEXT:
SelectAndViewFootprint( NEXT_PART );
break;
case ID_MODVIEW_PREVIOUS:
SelectAndViewFootprint( PREVIOUS_PART );
break;
default:
msg << wxT( "FOOTPRINT_VIEWER_FRAME::Process_Special_Functions error: id = " )
<< event.GetId();
wxMessageBox( msg );
break;
}
}
void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{
}
bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
return true;
}
/* Displays the name of the current opened library in the caption */
void FOOTPRINT_VIEWER_FRAME::DisplayLibInfos()
{
wxString msg;
msg = _( "Library Browser" );
msg << wxT( " [" );
if( ! m_libraryName.IsEmpty() )
msg << m_libraryName;
else
msg += _( "no library selected" );
msg << wxT( "]" );
SetTitle( msg );
}
void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
{
wxString msg;
if( g_LibraryNames.GetCount() == 0 )
return;
wxArrayString headers;
headers.Add( wxT( "Library" ) );
std::vector<wxArrayString> itemsToDisplay;
// Conversion from wxArrayString to vector of ArrayString
for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ )
{
wxArrayString item;
item.Add( g_LibraryNames[i] );
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, _( "Select Current Library:" ),
headers, itemsToDisplay, m_libraryName );
if( dlg.ShowModal() != wxID_OK )
return;
if( m_libraryName == dlg.GetTextSelection() )
return;
m_libraryName = dlg.GetTextSelection();
m_footprintName.Empty();
DisplayLibInfos();
ReCreateFootprintList();
int id = m_LibList->FindString( m_libraryName );
if( id >= 0 )
m_LibList->SetSelection( id );
}
void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
{
PCB_EDIT_FRAME* parent = (PCB_EDIT_FRAME*) GetParent();
wxString libname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension;
MODULE* oldmodule = GetBoard()->m_Modules;
MODULE* module = LoadModuleFromLibrary( libname, parent->GetFootprintLibraryTable(),
false );
if( module )
{
module->SetPosition( wxPoint( 0, 0 ) );
// Only one footprint allowed: remove the previous footprint (if exists)
if( oldmodule )
{
GetBoard()->Remove( oldmodule );
delete oldmodule;
}
m_footprintName = FROM_UTF8( module->GetFPID().GetFootprintName().c_str() );
module->ClearFlags();
SetCurItem( NULL );
Zoom_Automatique( false );
m_canvas->Refresh();
Update3D_Frame();
m_FootprintList->SetStringSelection( m_footprintName );
}
}
const wxString FOOTPRINT_VIEWER_FRAME::GetSelectedLibraryFullName( void )
{
wxString fullname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension;
return fullname;
}
/* Routine to view one selected library content. */
void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
{
if( m_libraryName.IsEmpty() )
return;
int selection = m_FootprintList->FindString( m_footprintName );
if( aMode == NEXT_PART )
{
if( selection != wxNOT_FOUND && selection < (int)m_FootprintList->GetCount()-1 )
selection++;
}
if( aMode == PREVIOUS_PART )
{
if( selection != wxNOT_FOUND && selection > 0)
selection--;
}
if( selection != wxNOT_FOUND )
{
m_footprintName = m_FootprintList->GetString( selection );
SetCurItem( NULL );
// Delete the current footprint
GetBoard()->m_Modules.DeleteAll();
MODULE* footprint = GetModuleLibrary( GetSelectedLibraryFullName(), m_footprintName, true );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
Update3D_Frame();
}
DisplayLibInfos();
Zoom_Automatique( false );
m_canvas->Refresh( );
}
void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
if( !GetBoard() )
return;
m_canvas->DrawBackGround( DC );
GetBoard()->Draw( m_canvas, DC, GR_COPY );
MODULE* module = GetBoard()->m_Modules;
m_canvas->DrawCrossHair( DC );
ClearMsgPanel();
if( module )
SetMsgPanel( module );
}
...@@ -29,10 +29,12 @@ ...@@ -29,10 +29,12 @@
#include <fctsys.h> #include <fctsys.h>
#include <appl_wxstruct.h> #include <appl_wxstruct.h>
#include <gr_basic.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <3d_viewer.h> #include <3d_viewer.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <dialog_helpers.h>
#include <msgpanel.h> #include <msgpanel.h>
#include <macros.h> #include <macros.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
...@@ -52,13 +54,20 @@ ...@@ -52,13 +54,20 @@
#include <pcbnew_config.h> #include <pcbnew_config.h>
#define NEXT_PART 1
#define NEW_PART 0
#define PREVIOUS_PART -1
static wxString entryPerspective( wxT( "ModViewPerspective" ) );
/** /**
* Save previous component library viewer state. * Save previous component library viewer state.
*/ */
wxString FOOTPRINT_VIEWER_FRAME::m_libraryName; wxString FOOTPRINT_VIEWER_FRAME::m_libraryName;
wxString FOOTPRINT_VIEWER_FRAME::m_footprintName; wxString FOOTPRINT_VIEWER_FRAME::m_footprintName;
/// When the viewer is used to select a component in schematic, the selected component is here. /// When the viewer is used to select a component in schematic, the selected component is here.
wxString FOOTPRINT_VIEWER_FRAME::m_selectedFootprintName; wxString FOOTPRINT_VIEWER_FRAME::m_selectedFootprintName;
...@@ -69,19 +78,15 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME ) ...@@ -69,19 +78,15 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize ) EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize )
EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate ) EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate )
/* Sash drag events */
EVT_SASH_DRAGGED( ID_MODVIEW_LIBWINDOW, FOOTPRINT_VIEWER_FRAME::OnSashDrag )
EVT_SASH_DRAGGED( ID_MODVIEW_FOOTPRINT_WINDOW, FOOTPRINT_VIEWER_FRAME::OnSashDrag )
/* Toolbar events */ /* Toolbar events */
EVT_TOOL( ID_MODVIEW_SELECT_LIB, EVT_TOOL( ID_MODVIEW_SELECT_LIB,
FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary ) FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary )
EVT_TOOL( ID_MODVIEW_SELECT_PART, EVT_TOOL( ID_MODVIEW_SELECT_PART,
FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint ) FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
EVT_TOOL( ID_MODVIEW_NEXT, EVT_TOOL( ID_MODVIEW_NEXT,
FOOTPRINT_VIEWER_FRAME::Process_Special_Functions ) FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_PREVIOUS, EVT_TOOL( ID_MODVIEW_PREVIOUS,
FOOTPRINT_VIEWER_FRAME::Process_Special_Functions ) FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
EVT_TOOL( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, EVT_TOOL( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD,
FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint ) FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame ) EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame )
...@@ -159,31 +164,24 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -159,31 +164,24 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
ReCreateHToolbar(); ReCreateHToolbar();
ReCreateVToolbar(); ReCreateVToolbar();
wxSize size = GetClientSize(); wxSize initialSashSize( 100, -1 );
size.y -= m_MsgFrameHeight + 2;
m_LibListSize.y = -1;
wxPoint win_pos( 0, 0 );
// Creates the libraries window display // Creates the libraries window display
m_LibListWindow = m_LibListWindow =
new wxSashLayoutWindow( this, ID_MODVIEW_LIBWINDOW, win_pos, new wxSashLayoutWindow( this, ID_MODVIEW_LIBWINDOW, wxDefaultPosition,
wxDefaultSize, wxCLIP_CHILDREN | wxSW_3D, initialSashSize, wxCLIP_CHILDREN | wxSW_3D,
wxT( "LibWindow" ) ); wxT( "LibWindow" ) );
m_LibListWindow->SetOrientation( wxLAYOUT_VERTICAL ); m_LibListWindow->SetOrientation( wxLAYOUT_VERTICAL );
m_LibListWindow->SetAlignment( wxLAYOUT_LEFT ); m_LibListWindow->SetAlignment( wxLAYOUT_LEFT );
m_LibListWindow->SetSashVisible( wxSASH_RIGHT, true ); m_LibListWindow->SetSashVisible( wxSASH_RIGHT, true );
m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE ); m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_LibList = new wxListBox( m_LibListWindow, ID_MODVIEW_LIB_LIST, m_LibList = new wxListBox( m_LibListWindow, ID_MODVIEW_LIB_LIST,
wxPoint( 0, 0 ), wxDefaultSize, wxDefaultPosition, initialSashSize,
0, NULL, wxLB_HSCROLL ); 0, NULL, wxLB_HSCROLL );
// Creates the component window display // Creates the footprint window display
m_FootprintListSize.y = size.y;
win_pos.x = m_LibListSize.x;
m_FootprintListWindow = new wxSashLayoutWindow( this, ID_MODVIEW_FOOTPRINT_WINDOW, m_FootprintListWindow = new wxSashLayoutWindow( this, ID_MODVIEW_FOOTPRINT_WINDOW,
win_pos, wxDefaultSize, wxDefaultPosition, initialSashSize,
wxCLIP_CHILDREN | wxSW_3D, wxCLIP_CHILDREN | wxSW_3D,
wxT( "CmpWindow" ) ); wxT( "CmpWindow" ) );
m_FootprintListWindow->SetOrientation( wxLAYOUT_VERTICAL ); m_FootprintListWindow->SetOrientation( wxLAYOUT_VERTICAL );
...@@ -191,11 +189,10 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -191,11 +189,10 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
m_FootprintListWindow->SetSashVisible( wxSASH_RIGHT, true ); m_FootprintListWindow->SetSashVisible( wxSASH_RIGHT, true );
m_FootprintListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE ); m_FootprintListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_FootprintList = new wxListBox( m_FootprintListWindow, ID_MODVIEW_FOOTPRINT_LIST, m_FootprintList = new wxListBox( m_FootprintListWindow, ID_MODVIEW_FOOTPRINT_LIST,
wxPoint( 0, 0 ), wxDefaultSize, wxDefaultPosition, initialSashSize,
0, NULL, wxLB_HSCROLL ); 0, NULL, wxLB_HSCROLL );
ReCreateLibraryList(); ReCreateLibraryList();
DisplayLibInfos(); DisplayLibInfos();
// If a footprint was previously loaded, reload it // If a footprint was previously loaded, reload it
...@@ -215,13 +212,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -215,13 +212,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
#endif #endif
} }
if( m_canvas ) if( m_canvas )
m_canvas->SetAcceleratorTable( table ); m_canvas->SetAcceleratorTable( table );
m_auimgr.SetManagedWindow( this ); m_auimgr.SetManagedWindow( this );
EDA_PANEINFO horiz; EDA_PANEINFO horiz;
horiz.HorizontalToolbarPane(); horiz.HorizontalToolbarPane();
...@@ -234,17 +229,14 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -234,17 +229,14 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
EDA_PANEINFO mesg; EDA_PANEINFO mesg;
mesg.MessageToolbarPane(); mesg.MessageToolbarPane();
// Manage main toolbar // Manage main toolbar
m_auimgr.AddPane( m_mainToolBar, m_auimgr.AddPane( m_mainToolBar,
wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) ); wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) );
wxSize minsize( 60, -1 );
// Manage the left window (list of libraries) // Manage the left window (list of libraries)
if( m_LibListWindow ) if( m_LibListWindow )
m_auimgr.AddPane( m_LibListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_LibList" ) ). m_auimgr.AddPane( m_LibListWindow, wxAuiPaneInfo( info ).Name( wxT( "m_LibList" ) ).
Left().Row( 0 )); Left().Row( 0 ) );
// Manage the list of components) // Manage the list of components)
m_auimgr.AddPane( m_FootprintListWindow, m_auimgr.AddPane( m_FootprintListWindow,
...@@ -253,7 +245,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -253,7 +245,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
// Manage the draw panel // Manage the draw panel
m_auimgr.AddPane( m_canvas, m_auimgr.AddPane( m_canvas,
wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).Centre() ); wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).Centre().CloseButton( false ) );
// Manage the message panel // Manage the message panel
m_auimgr.AddPane( m_messagePanel, m_auimgr.AddPane( m_messagePanel,
...@@ -265,12 +257,18 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -265,12 +257,18 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
if( m_LibListWindow ) if( m_LibListWindow )
{ {
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_LibListWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_LibListWindow );
pane.MinSize( wxSize( m_LibListSize.x, -1 ) ); pane.MinSize( wxSize( 30, -1 ) );
} }
if( m_FootprintListWindow )
{
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_FootprintListWindow ); wxAuiPaneInfo& pane = m_auimgr.GetPane( m_FootprintListWindow );
pane.MinSize( wxSize( m_FootprintListSize.x, -1 ) ); pane.MinSize( wxSize( 30, -1 ) );
}
if( !m_perspective.IsEmpty() )
m_auimgr.LoadPerspective( m_perspective );
else
m_auimgr.Update(); m_auimgr.Update();
// Now Drawpanel is sized, we can use BestZoom to show the component (if any) // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
...@@ -291,18 +289,12 @@ FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME() ...@@ -291,18 +289,12 @@ FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME()
} }
/* return the frame name used when creating the frame
* used to get a reference to this frame, if exists
*/
const wxChar* FOOTPRINT_VIEWER_FRAME::GetFootprintViewerFrameName() const wxChar* FOOTPRINT_VIEWER_FRAME::GetFootprintViewerFrameName()
{ {
return FOOTPRINT_VIEWER_FRAME_NAME; return FOOTPRINT_VIEWER_FRAME_NAME;
} }
/* return a reference to the current opened Footprint viewer
* or NULL if no Footprint viewer currently opened
*/
FOOTPRINT_VIEWER_FRAME* FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer() FOOTPRINT_VIEWER_FRAME* FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer()
{ {
return (FOOTPRINT_VIEWER_FRAME*) return (FOOTPRINT_VIEWER_FRAME*)
...@@ -326,38 +318,6 @@ void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -326,38 +318,6 @@ void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
} }
void FOOTPRINT_VIEWER_FRAME::OnSashDrag( wxSashEvent& event )
{
if( event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE )
return;
m_LibListSize.y = GetClientSize().y - m_MsgFrameHeight;
m_FootprintListSize.y = m_LibListSize.y;
switch( event.GetId() )
{
case ID_MODVIEW_LIBWINDOW:
if( m_LibListWindow )
{
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_LibListWindow );
m_LibListSize.x = event.GetDragRect().width;
pane.MinSize( m_LibListSize );
m_auimgr.Update();
}
break;
case ID_MODVIEW_FOOTPRINT_WINDOW:
{
wxAuiPaneInfo& pane = m_auimgr.GetPane( m_FootprintListWindow );
m_FootprintListSize.x = event.GetDragRect().width;
pane.MinSize( m_FootprintListSize );
m_auimgr.Update();
}
break;
}
}
void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv ) void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
{ {
if( m_auimgr.GetManagedWindow() ) if( m_auimgr.GetManagedWindow() )
...@@ -588,10 +548,6 @@ void FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint( wxCommandEvent& event ) ...@@ -588,10 +548,6 @@ void FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint( wxCommandEvent& event )
} }
#define LIBLIST_WIDTH_KEY wxT( "Liblist_width" )
#define CMPLIST_WIDTH_KEY wxT( "Cmplist_width" )
void FOOTPRINT_VIEWER_FRAME::LoadSettings( ) void FOOTPRINT_VIEWER_FRAME::LoadSettings( )
{ {
wxConfig* cfg ; wxConfig* cfg ;
...@@ -601,18 +557,7 @@ void FOOTPRINT_VIEWER_FRAME::LoadSettings( ) ...@@ -601,18 +557,7 @@ void FOOTPRINT_VIEWER_FRAME::LoadSettings( )
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath ); wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
cfg = wxGetApp().GetSettings(); cfg = wxGetApp().GetSettings();
m_LibListSize.x = 150; // default width of libs list cfg->Read( entryPerspective, &m_perspective );
m_FootprintListSize.x = 150; // default width of component list
cfg->Read( LIBLIST_WIDTH_KEY, &m_LibListSize.x );
cfg->Read( CMPLIST_WIDTH_KEY, &m_FootprintListSize.x );
// Set parameters to a reasonable value.
if ( m_LibListSize.x > m_FrameSize.x/2 )
m_LibListSize.x = m_FrameSize.x/2;
if ( m_FootprintListSize.x > m_FrameSize.x/2 )
m_FootprintListSize.x = m_FrameSize.x/2;
} }
...@@ -625,10 +570,7 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings() ...@@ -625,10 +570,7 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings()
wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath ); wxConfigPathChanger cpc( wxGetApp().GetSettings(), m_configPath );
cfg = wxGetApp().GetSettings(); cfg = wxGetApp().GetSettings();
if ( m_LibListSize.x ) cfg->Write( entryPerspective, m_auimgr.SavePerspective() );
cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x );
cfg->Write( CMPLIST_WIDTH_KEY, m_FootprintListSize.x );
} }
...@@ -819,3 +761,191 @@ EDA_COLOR_T FOOTPRINT_VIEWER_FRAME::GetGridColor() const ...@@ -819,3 +761,191 @@ EDA_COLOR_T FOOTPRINT_VIEWER_FRAME::GetGridColor() const
{ {
return g_ColorsSettings.GetItemColor( GRID_VISIBLE ); return g_ColorsSettings.GetItemColor( GRID_VISIBLE );
} }
void FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList( wxCommandEvent& event )
{
wxString msg;
switch( event.GetId() )
{
case ID_MODVIEW_NEXT:
SelectAndViewFootprint( NEXT_PART );
break;
case ID_MODVIEW_PREVIOUS:
SelectAndViewFootprint( PREVIOUS_PART );
break;
default:
wxFAIL_MSG( wxT( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " ) +
event.GetId() );
}
}
void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{
}
bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
return true;
}
void FOOTPRINT_VIEWER_FRAME::DisplayLibInfos()
{
wxString msg;
msg = _( "Library Browser" );
msg << wxT( " [" );
if( ! m_libraryName.IsEmpty() )
msg << m_libraryName;
else
msg += _( "no library selected" );
msg << wxT( "]" );
SetTitle( msg );
}
void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
{
wxString msg;
if( g_LibraryNames.GetCount() == 0 )
return;
wxArrayString headers;
headers.Add( wxT( "Library" ) );
std::vector<wxArrayString> itemsToDisplay;
// Conversion from wxArrayString to vector of ArrayString
for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ )
{
wxArrayString item;
item.Add( g_LibraryNames[i] );
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, _( "Select Current Library:" ),
headers, itemsToDisplay, m_libraryName );
if( dlg.ShowModal() != wxID_OK )
return;
if( m_libraryName == dlg.GetTextSelection() )
return;
m_libraryName = dlg.GetTextSelection();
m_footprintName.Empty();
DisplayLibInfos();
ReCreateFootprintList();
int id = m_LibList->FindString( m_libraryName );
if( id >= 0 )
m_LibList->SetSelection( id );
}
void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
{
PCB_EDIT_FRAME* parent = (PCB_EDIT_FRAME*) GetParent();
wxString libname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension;
MODULE* oldmodule = GetBoard()->m_Modules;
MODULE* module = LoadModuleFromLibrary( libname, parent->GetFootprintLibraryTable(),
false );
if( module )
{
module->SetPosition( wxPoint( 0, 0 ) );
// Only one footprint allowed: remove the previous footprint (if exists)
if( oldmodule )
{
GetBoard()->Remove( oldmodule );
delete oldmodule;
}
m_footprintName = FROM_UTF8( module->GetFPID().GetFootprintName().c_str() );
module->ClearFlags();
SetCurItem( NULL );
Zoom_Automatique( false );
m_canvas->Refresh();
Update3D_Frame();
m_FootprintList->SetStringSelection( m_footprintName );
}
}
const wxString FOOTPRINT_VIEWER_FRAME::GetSelectedLibraryFullName( void )
{
wxString fullname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension;
return fullname;
}
void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
{
if( m_libraryName.IsEmpty() )
return;
int selection = m_FootprintList->FindString( m_footprintName );
if( aMode == NEXT_PART )
{
if( selection != wxNOT_FOUND && selection < (int)m_FootprintList->GetCount()-1 )
selection++;
}
if( aMode == PREVIOUS_PART )
{
if( selection != wxNOT_FOUND && selection > 0 )
selection--;
}
if( selection != wxNOT_FOUND )
{
m_FootprintList->SetSelection( selection );
m_footprintName = m_FootprintList->GetString( selection );
SetCurItem( NULL );
// Delete the current footprint
GetBoard()->m_Modules.DeleteAll();
MODULE* footprint = GetModuleLibrary( GetSelectedLibraryFullName(), m_footprintName, true );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
Update3D_Frame();
}
DisplayLibInfos();
Zoom_Automatique( false );
m_canvas->Refresh();
}
void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
if( !GetBoard() )
return;
m_canvas->DrawBackGround( DC );
GetBoard()->Draw( m_canvas, DC, GR_COPY );
MODULE* module = GetBoard()->m_Modules;
m_canvas->DrawCrossHair( DC );
ClearMsgPanel();
if( module )
SetMsgPanel( module );
}
...@@ -47,16 +47,15 @@ private: ...@@ -47,16 +47,15 @@ private:
// List of libraries (for selection ) // List of libraries (for selection )
wxSashLayoutWindow* m_LibListWindow; wxSashLayoutWindow* m_LibListWindow;
wxListBox* m_LibList; // The list of libs names wxListBox* m_LibList; // The list of libs names
wxSize m_LibListSize; // size of the window
// List of components in the selected library // List of components in the selected library
wxSashLayoutWindow* m_FootprintListWindow; wxSashLayoutWindow* m_FootprintListWindow;
wxListBox* m_FootprintList; // The list of footprint names wxListBox* m_FootprintList; // The list of footprint names
wxSize m_FootprintListSize; // size of the window
// Flags // Flags
wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog
wxString m_configPath; // subpath for configuration wxString m_configPath; // subpath for configuration
wxString m_perspective; // wxAuiManager perspective.
protected: protected:
static wxString m_libraryName; // Current selected library static wxString m_libraryName; // Current selected library
...@@ -100,13 +99,6 @@ private: ...@@ -100,13 +99,6 @@ private:
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
/**
* Function OnSashDrag
* resizes the child windows when dragging a sash window border.
*/
void OnSashDrag( wxSashEvent& event );
/** /**
* Function ReCreateLibraryList * Function ReCreateLibraryList
* *
...@@ -116,7 +108,7 @@ private: ...@@ -116,7 +108,7 @@ private:
void ReCreateLibraryList(); void ReCreateLibraryList();
void ReCreateFootprintList(); void ReCreateFootprintList();
void Process_Special_Functions( wxCommandEvent& event ); void OnIterateFootprintList( wxCommandEvent& event );
void DisplayLibInfos(); void DisplayLibInfos();
/** /**
......
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