From bf2f480b7cef09b077fcbba354149e22941caf4f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 22 Jun 2015 19:21:34 +0200 Subject: [PATCH] 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. --- common/kiway_player.cpp | 12 -- eeschema/viewlib_frame.cpp | 29 ++++- .../dialogs/dialog_exchange_modules_base.cpp | 21 ++-- .../dialogs/dialog_exchange_modules_base.fbp | 112 ++++++++++++++++-- pcbnew/dialogs/dialog_exchange_modules_base.h | 6 +- pcbnew/modview_frame.cpp | 26 +++- pcbnew/xchgmod.cpp | 28 ++++- 7 files changed, 197 insertions(+), 37 deletions(-) diff --git a/common/kiway_player.cpp b/common/kiway_player.cpp index 4a1f98f088..7eb8ae2fd9 100644 --- a/common/kiway_player.cpp +++ b/common/kiway_player.cpp @@ -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(m_modal_resultant_parent); - if( parent ) - Reparent( m_modal_resultant_parent ); - } -#endif - return EDA_BASE_FRAME::Destroy(); } diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index c3088c0885..80068484c7 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -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,7 +230,8 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame Zoom_Automatique( false ); #endif - Show( true ); + if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame + Show( true ); } diff --git a/pcbnew/dialogs/dialog_exchange_modules_base.cpp b/pcbnew/dialogs/dialog_exchange_modules_base.cpp index 4fb582e87f..2341f12063 100644 --- a/pcbnew/dialogs/dialog_exchange_modules_base.cpp +++ b/pcbnew/dialogs/dialog_exchange_modules_base.cpp @@ -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 ); } diff --git a/pcbnew/dialogs/dialog_exchange_modules_base.fbp b/pcbnew/dialogs/dialog_exchange_modules_base.fbp index 38acfe7e23..b75d3776bd 100644 --- a/pcbnew/dialogs/dialog_exchange_modules_base.fbp +++ b/pcbnew/dialogs/dialog_exchange_modules_base.fbp @@ -44,7 +44,7 @@ DIALOG_EXCHANGE_MODULE_BASE - -1,-1 + 421,517 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Exchange Footprints @@ -459,6 +459,16 @@ + + 5 + wxEXPAND + 1 + + 10 + protected + 5 + + 5 wxTOP|wxRIGHT|wxLEFT @@ -637,7 +647,7 @@ 5 - wxALIGN_CENTER_VERTICAL + 0 @@ -747,7 +757,7 @@ none 5 - wxALL|wxEXPAND + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 1 @@ -954,7 +964,7 @@ 0 0 wxID_ANY - Rebuild .cmp List + Export .cmp List 0 @@ -1009,6 +1019,94 @@ + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Browse FP List + + 0 + + + 0 + + 1 + m_Browsebutton + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + BrowseAndSelectFootprint + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxALL|wxEXPAND @@ -1042,7 +1140,7 @@ 0 0 wxID_ANY - Browse + FP Viewer 0 @@ -1050,7 +1148,7 @@ 0 1 - m_Browsebutton + m_buttonFPViewer 1 @@ -1071,7 +1169,7 @@ - BrowseAndSelectFootprint + ViewAndSelectFootprint diff --git a/pcbnew/dialogs/dialog_exchange_modules_base.h b/pcbnew/dialogs/dialog_exchange_modules_base.h index a0d071d875..fa97b2d75a 100644 --- a/pcbnew/dialogs/dialog_exchange_modules_base.h +++ b/pcbnew/dialogs/dialog_exchange_modules_base.h @@ -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(); }; diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 78640c721f..62bd97b388 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -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 - Show( true ); - UseGalCanvas( parentFrame->IsGalCanvasActive() ); + + if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame + Show( true ); + } diff --git a/pcbnew/xchgmod.cpp b/pcbnew/xchgmod.cpp index 3ae43b86e2..c2f2069f41 100644 --- a/pcbnew/xchgmod.cpp +++ b/pcbnew/xchgmod.cpp @@ -43,11 +43,14 @@ #include #include #include +#include #include #include #include + + 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 ) {