Dialog exchange modules: add a fp selection from the fp viewer

Fix also an issue on Windows, when using the footprint viewer or the component viewer in modal mode:
Reason: these frames (when run under the Kicad manager) have the Kicad manager as parent, and were built with wxFRAME_FLOAT_ON_PARENT style.
On windows, when the frame with style wxFRAME_FLOAT_ON_PARENT is displayed  its parent frame is brought to the foreground, on the top of the calling frame.
and stays displayed when closing the  frame in modal mode.
This issue does not happen on unix so we use now wxSTAY_ON_TOP on Windows, and wxFRAME_FLOAT_ON_PARENT on unix to simulate a dialog called by ShowModal.
This is not perfect, but at least it works.
This commit is contained in:
jean-pierre charras 2015-06-22 19:21:34 +02:00
parent e1b3a2d410
commit bf2f480b7c
7 changed files with 197 additions and 37 deletions

View File

@ -140,18 +140,6 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult, wxWindow* aResultantFocusWindow
bool KIWAY_PLAYER::Destroy()
{
// Reparent is needed on Windows to leave the modal parent on top with focus
// However it works only if the caller is a main frame, not a dialog.
// (application crashes if the new parent is a wxDialog
#ifdef __WINDOWS__
if( m_modal_resultant_parent && GetParent() != m_modal_resultant_parent )
{
EDA_BASE_FRAME* parent = dynamic_cast<EDA_BASE_FRAME*>(m_modal_resultant_parent);
if( parent )
Reparent( m_modal_resultant_parent );
}
#endif
return EDA_BASE_FRAME::Destroy();
}

View File

@ -76,15 +76,35 @@ BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
END_EVENT_TABLE()
/* Note:
* LIB_VIEW_FRAME can be build in "modal mode", or as a usual frame.
* In modal mode:
* a tool to export the selected symbol is shown in the toolbar
* the style is wxSTAY_ON_TOP on Windows and wxFRAME_FLOAT_ON_PARENT on unix
* reason:
* the parent is usually the kicad window manager (not easy to change)
* On windows, when the frame with stype wxFRAME_FLOAT_ON_PARENT is displayed
* its parent frame is brought to the foreground, on the top of the calling frame.
* and stays displayed when closing the LIB_VIEW_FRAME frame.
* this issue does not happen on unix.
*
* So we use wxSTAY_ON_TOP on Windows, and wxFRAME_FLOAT_ON_PARENT on unix
* to simulate a dialog called by ShowModal.
*/
#define LIB_VIEW_FRAME_NAME wxT( "ViewlibFrame" )
LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
PART_LIB* aLibrary ) :
SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ),
wxDefaultPosition, wxDefaultSize,
aFrameType==FRAME_SCH_VIEWER ?
KICAD_DEFAULT_DRAWFRAME_STYLE :
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT,
aFrameType==FRAME_SCH_VIEWER_MODAL ?
#ifdef __WINDOWS__
KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP :
#else
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT :
#endif
KICAD_DEFAULT_DRAWFRAME_STYLE,
GetLibViewerFrameName() )
{
wxASSERT( aFrameType==FRAME_SCH_VIEWER || aFrameType==FRAME_SCH_VIEWER_MODAL );
@ -210,6 +230,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
Zoom_Automatique( false );
#endif
if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
Show( true );
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 6 2014)
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -38,6 +38,9 @@ DIALOG_EXCHANGE_MODULE_BASE::DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWi
m_OldValue->SetMaxLength( 0 );
bLeftSizer->Add( m_OldValue, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
bLeftSizer->Add( 5, 10, 1, wxEXPAND, 5 );
m_staticText8 = new wxStaticText( this, wxID_ANY, _("New footprint"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText8->Wrap( -1 );
bLeftSizer->Add( m_staticText8, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
@ -59,22 +62,25 @@ DIALOG_EXCHANGE_MODULE_BASE::DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWi
bMiddleSizer->Add( m_Selection, 0, wxALL, 5 );
bUpperSizer->Add( bMiddleSizer, 0, wxALIGN_CENTER_VERTICAL, 5 );
bUpperSizer->Add( bMiddleSizer, 0, 0, 5 );
wxBoxSizer* bRightSizer;
bRightSizer = new wxBoxSizer( wxVERTICAL );
m_OKbutton = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_OKbutton, 0, wxALL|wxEXPAND, 5 );
bRightSizer->Add( m_OKbutton, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
m_Quitbutton = new wxButton( this, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_Quitbutton, 0, wxALL|wxEXPAND, 5 );
m_buttonCmpList = new wxButton( this, wxID_ANY, _("Rebuild .cmp List"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonCmpList = new wxButton( this, wxID_ANY, _("Export .cmp List"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_buttonCmpList, 0, wxALL|wxEXPAND, 5 );
m_Browsebutton = new wxButton( this, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_Browsebutton, 0, wxALL|wxEXPAND, 5 );
m_Browsebutton = new wxButton( this, wxID_ANY, _("Browse FP List"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_Browsebutton, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
m_buttonFPViewer = new wxButton( this, wxID_ANY, _("FP Viewer"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_buttonFPViewer, 0, wxALL|wxEXPAND, 5 );
bUpperSizer->Add( bRightSizer, 0, wxALIGN_CENTER_VERTICAL, 5 );
@ -94,7 +100,6 @@ DIALOG_EXCHANGE_MODULE_BASE::DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWi
this->SetSizer( bMainSizer );
this->Layout();
bMainSizer->Fit( this );
// Connect Events
m_Selection->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::OnSelectionClicked ), NULL, this );
@ -102,6 +107,7 @@ DIALOG_EXCHANGE_MODULE_BASE::DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWi
m_Quitbutton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::OnQuit ), NULL, this );
m_buttonCmpList->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::RebuildCmpList ), NULL, this );
m_Browsebutton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::BrowseAndSelectFootprint ), NULL, this );
m_buttonFPViewer->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::ViewAndSelectFootprint ), NULL, this );
}
DIALOG_EXCHANGE_MODULE_BASE::~DIALOG_EXCHANGE_MODULE_BASE()
@ -112,5 +118,6 @@ DIALOG_EXCHANGE_MODULE_BASE::~DIALOG_EXCHANGE_MODULE_BASE()
m_Quitbutton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::OnQuit ), NULL, this );
m_buttonCmpList->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::RebuildCmpList ), NULL, this );
m_Browsebutton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::BrowseAndSelectFootprint ), NULL, this );
m_buttonFPViewer->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXCHANGE_MODULE_BASE::ViewAndSelectFootprint ), NULL, this );
}

View File

@ -44,7 +44,7 @@
<property name="minimum_size"></property>
<property name="name">DIALOG_EXCHANGE_MODULE_BASE</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="size">421,517</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Exchange Footprints</property>
@ -459,6 +459,16 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="spacer" expanded="1">
<property name="height">10</property>
<property name="permission">protected</property>
<property name="width">5</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
@ -637,7 +647,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="flag"></property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
@ -747,7 +757,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
@ -954,7 +964,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Rebuild .cmp List</property>
<property name="label">Export .cmp List</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -1009,6 +1019,94 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Browse FP List</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_Browsebutton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">BrowseAndSelectFootprint</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
@ -1042,7 +1140,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Browse</property>
<property name="label">FP Viewer</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -1050,7 +1148,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_Browsebutton</property>
<property name="name">m_buttonFPViewer</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -1071,7 +1169,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">BrowseAndSelectFootprint</event>
<event name="OnButtonClick">ViewAndSelectFootprint</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 6 2014)
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -49,6 +49,7 @@ class DIALOG_EXCHANGE_MODULE_BASE : public DIALOG_SHIM
wxButton* m_Quitbutton;
wxButton* m_buttonCmpList;
wxButton* m_Browsebutton;
wxButton* m_buttonFPViewer;
wxStaticText* m_staticTextMsg;
wxTextCtrl* m_WinMessages;
@ -58,11 +59,12 @@ class DIALOG_EXCHANGE_MODULE_BASE : public DIALOG_SHIM
virtual void OnQuit( wxCommandEvent& event ) { event.Skip(); }
virtual void RebuildCmpList( wxCommandEvent& event ) { event.Skip(); }
virtual void BrowseAndSelectFootprint( wxCommandEvent& event ) { event.Skip(); }
virtual void ViewAndSelectFootprint( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Exchange Footprints"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_EXCHANGE_MODULE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Exchange Footprints"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 421,517 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EXCHANGE_MODULE_BASE();
};

View File

@ -96,6 +96,22 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
END_EVENT_TABLE()
/* Note:
* FOOTPRINT_VIEWER_FRAME can be build in "modal mode", or as a usual frame.
* In modal mode:
* a tool to export the selected footprint is shown in the toolbar
* the style is wxSTAY_ON_TOP on Windows and wxFRAME_FLOAT_ON_PARENT on unix
* reason:
* the parent is usually the kicad window manager (not easy to change)
* On windows, when the frame with stype wxFRAME_FLOAT_ON_PARENT is displayed
* its parent frame is brought to the foreground, on the top of the calling frame.
* and stays displayed when closing the FOOTPRINT_VIEWER_FRAME frame.
* this issue does not happen on unix
*
* So we use wxSTAY_ON_TOP on Windows, and wxFRAME_FLOAT_ON_PARENT on unix
* to simulate a dialog called by ShowModal.
*/
#define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" )
@ -104,7 +120,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
wxDefaultPosition, wxDefaultSize,
aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
#ifdef __WINDOWS__
KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP :
#else
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT :
#endif
KICAD_DEFAULT_DRAWFRAME_STYLE,
GetFootprintViewerFrameName() )
{
@ -257,9 +277,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
Zoom_Automatique( false );
#endif
UseGalCanvas( parentFrame->IsGalCanvasActive() );
if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
Show( true );
UseGalCanvas( parentFrame->IsGalCanvasActive() );
}

View File

@ -43,11 +43,14 @@
#include <pcbnew.h>
#include <dialog_exchange_modules_base.h>
#include <wildcards_and_files_ext.h>
#include <kiway.h>
#include <boost/bind.hpp>
#include <tool/tool_manager.h>
#include <tools/common_actions.h>
static bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName );
class DIALOG_EXCHANGE_MODULE : public DIALOG_EXCHANGE_MODULE_BASE
@ -66,6 +69,7 @@ private:
void OnOkClick( wxCommandEvent& event );
void OnQuit( wxCommandEvent& event );
void BrowseAndSelectFootprint( wxCommandEvent& event );
void ViewAndSelectFootprint( wxCommandEvent& event );
void RebuildCmpList( wxCommandEvent& event );
void init();
@ -95,14 +99,15 @@ void PCB_EDIT_FRAME::InstallExchangeModuleFrame( MODULE* Module )
{
DIALOG_EXCHANGE_MODULE dialog( this, Module );
dialog.ShowModal();
dialog.ShowQuasiModal();
}
void DIALOG_EXCHANGE_MODULE::OnQuit( wxCommandEvent& event )
{
m_selectionMode = m_Selection->GetSelection();
EndModal( 0 );
Show( false );
EndQuasiModal( wxID_CANCEL );
}
@ -501,7 +506,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
/*
* Displays the list of modules in library name and select 1 name.
* Displays the list of modules in library name and select a footprint.
*/
void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event )
{
@ -514,6 +519,23 @@ void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event )
m_NewModule->SetValue( newname );
}
/*
* Displays the footprint viewer to select a footprint.
*/
void DIALOG_EXCHANGE_MODULE::ViewAndSelectFootprint( wxCommandEvent& event )
{
wxString newname;
KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true );
if( frame->ShowModal( &newname, this ) )
{
m_NewModule->SetValue( newname );
}
frame->Destroy();
}
void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
{