diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 8f05616062..382c9c9164 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -157,7 +157,7 @@ bool EDA_BASE_FRAME::Enable( bool enable ) #if defined(DEBUG) const char* type_id = typeid( *this ).name(); - printf( "wxFrame %s: %s\n", type_id, enable ? "enabled" : "disabled" ); + printf( "wxFrame %-28s: %s\n", type_id, enable ? "enabled" : "disabled" ); #endif return wxFrame::Enable( enable ); diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index f8236c1ac6..1d3e9b6054 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -244,8 +244,12 @@ int DIALOG_SHIM::ShowQuasiModal() if( win ) win->ReleaseMouse(); + // Get the optimal parent wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() ); + // Show the optimal parent + DBG( if( parent ) printf( "%s: optimal parent: %s\n", __func__, typeid(*parent).name() );) + ENABLE_DISABLE toggle( parent ); // quasi-modal: disable only my "optimal" parent Show( true ); diff --git a/common/kiway.cpp b/common/kiway.cpp index 8f2ebf9824..396c5cb417 100644 --- a/common/kiway.cpp +++ b/common/kiway.cpp @@ -53,7 +53,7 @@ KIWAY::KIWAY( PGM_BASE* aProgram, int aCtlBits, wxFrame* aTop ): // Any event types derived from wxCommandEvt, like wxWindowDestroyEvent, are -// propogated upwards to parent windows if not handled below. Therefor the +// propogated upwards to parent windows if not handled below. Therefore the // m_top window should receive all wxWindowDestroyEvents originating from // KIWAY_PLAYERs. It does anyways, but now player_destroy_handler eavesdrops // on that event stream looking for KIWAY_PLAYERs being closed. @@ -67,10 +67,14 @@ void KIWAY::player_destroy_handler( wxWindowDestroyEvent& event ) // if destroying one of our flock, then mark it as deceased. if( (wxWindow*) m_player[i] == w ) { - DBG(printf( "%s: marking m_player[%d] as destroyed\n", __func__, i );) + DBG(printf( "%s: m_player[%d] destroyed: %s\n", + __func__, i, TO_UTF8( m_player[i]->GetName() ) );) + m_player[i] = 0; } } + + // event.Skip(); skip to who, the wxApp? I'm the top window. } diff --git a/common/kiway_player.cpp b/common/kiway_player.cpp index ab0ae3e571..fc0415a702 100644 --- a/common/kiway_player.cpp +++ b/common/kiway_player.cpp @@ -72,7 +72,7 @@ void KIWAY_PLAYER::KiwayMailIn( KIWAY_EXPRESS& aEvent ) } -bool KIWAY_PLAYER::ShowModal( wxString* aResult ) +bool KIWAY_PLAYER::ShowModal( wxString* aResult, wxWindow* aResultantFocusWindow ) { wxASSERT_MSG( IsModal(), wxT( "ShowModal() shouldn't be called on non-modal frame" ) ); @@ -94,24 +94,30 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult ) ~NULLER() { m_what = 0; } // indeed, set it to NULL on destruction } clear_this( (void*&) m_modal_loop ); - // exception safe way to disable all frames except the modal one, - // re-enables only those that were disabled on exit - wxWindowDisabler toggle( this ); Show( true ); + SetFocus(); - WX_EVENT_LOOP event_loop; + { + // exception safe way to disable all frames except the modal one, + // re-enables only those that were disabled on exit + wxWindowDisabler toggle( this ); + + WX_EVENT_LOOP event_loop; #if wxCHECK_VERSION( 2, 9, 4 ) // 2.9.4 is only approximate. - // new code needs this, old code does it in wxEventLoop::Run() and cannot - // tolerate it here. Where that boundary is as a version number, I don't know. - // A closer look at the subversion repo for wx would tell. - wxEventLoopActivator event_loop_stacker( &event_loop ); + // new code needs this, old code does it in wxEventLoop::Run() and cannot + // tolerate it here. Where that boundary is as a version number, I don't know. + // A closer look at the subversion repo for wx would tell. + wxEventLoopActivator event_loop_stacker( &event_loop ); #endif - m_modal_loop = &event_loop; + m_modal_loop = &event_loop; - event_loop.Run(); + event_loop.Run(); + + } // End of scop for some variables. + // End nesting before setting focus below. if( aResult ) *aResult = m_modal_string; @@ -119,6 +125,16 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult ) DBG(printf( "~%s: aResult:'%s' ret:%d\n", __func__, TO_UTF8( m_modal_string ), m_modal_ret_val );) + if( aResultantFocusWindow ) + { + aResultantFocusWindow->Raise(); + + // have the final say, after wxWindowDisabler reenables my parent and + // the events settle down, set the focus + wxYield(); + aResultantFocusWindow->SetFocus(); + } + return m_modal_ret_val; } diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index cb9fcbc4ee..0ea32ac16e 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -436,13 +436,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEven void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& event ) { -#if 0 - wxString datasheet_uri = fieldValueTextCtrl->GetValue(); - ::wxLaunchDefaultBrowser( datasheet_uri ); - -#else - unsigned fieldNdx = getSelectedFieldNdx(); + if( fieldNdx == DATASHEET ) { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); @@ -455,17 +450,14 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& even KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true ); - if( frame->ShowModal( &fpid ) ) + if( frame->ShowModal( &fpid, this ) ) { - printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); + // DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); ) fieldValueTextCtrl->SetValue( fpid ); - } frame->Destroy(); } -#endif - } @@ -771,8 +763,6 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel() else m_show_datasheet_button->SetLabel( wxEmptyString ); - m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT ); - // For power symbols, the value is NOR editable, because value and pin // name must be same and can be edited only in library editor if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->IsPower() ) diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index 4036c36cb5..37831227d9 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -141,7 +142,7 @@ void LIB_EDIT_FRAME::InstallFieldsEditorDialog( wxCommandEvent& event ) DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB dlg( this, m_component ); - int abort = dlg.ShowModal(); + int abort = dlg.ShowQuasiModal(); if( abort ) return; @@ -211,7 +212,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemSelected( wxListEvent& event void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnCancelButtonClick( wxCommandEvent& event ) { - EndModal( 1 ); + EndQuasiModal( 1 ); } @@ -282,7 +283,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event m_parent->OnModify(); - EndModal( 0 ); + EndQuasiModal( 0 ); } @@ -381,8 +382,28 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& e void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::showButtonHandler( wxCommandEvent& event ) { - wxString datasheet_uri = fieldValueTextCtrl->GetValue(); - ::wxLaunchDefaultBrowser( datasheet_uri ); + unsigned fieldNdx = getSelectedFieldNdx(); + + if( fieldNdx == DATASHEET ) + { + wxString datasheet_uri = fieldValueTextCtrl->GetValue(); + ::wxLaunchDefaultBrowser( datasheet_uri ); + } + else if( fieldNdx == FOOTPRINT ) + { + // pick a footprint using the footprint picker. + wxString fpid; + + KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true ); + + if( frame->ShowModal( &fpid, this ) ) + { + // DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); ) + fieldValueTextCtrl->SetValue( fpid ); + } + + frame->Destroy(); + } } @@ -652,7 +673,14 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel() textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetSize().x ) ); - m_show_datasheet_button->Enable( fieldNdx == DATASHEET ); + m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT ); + + if( fieldNdx == DATASHEET ) + m_show_datasheet_button->SetLabel( _( "Show in Browser" ) ); + else if( fieldNdx == FOOTPRINT ) + m_show_datasheet_button->SetLabel( _( "Assign Footprint" ) ); + else + m_show_datasheet_button->SetLabel( wxEmptyString ); wxPoint coord = field.GetTextPosition(); wxPoint zero; diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.cpp index a859617859..956e092640 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.cpp @@ -9,7 +9,7 @@ /////////////////////////////////////////////////////////////////////////// -DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.fbp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.fbp index d6a0535ca9..94ef7e29cf 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.fbp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.fbp @@ -46,7 +46,7 @@ -1,-1 wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU - + DIALOG_SHIM; dialog_shim.h Field Properties diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.h b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.h index 82188f2008..fdd0464897 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.h +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.h @@ -11,6 +11,9 @@ #include #include #include +class DIALOG_SHIM; + +#include "dialog_shim.h" #include #include #include @@ -33,7 +36,7 @@ /////////////////////////////////////////////////////////////////////////////// /// Class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE /////////////////////////////////////////////////////////////////////////////// -class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE : public wxDialog +class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE : public DIALOG_SHIM { private: diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index e81d028bfa..8821cfb31e 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -79,7 +79,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( LIB_ALIAS* aPreselectedA wxString cmpname; - if( viewlibFrame->ShowModal( &cmpname ) ) + if( viewlibFrame->ShowModal( &cmpname, this ) ) { if( aUnit ) *aUnit = viewlibFrame->GetUnit(); diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index db9e8f50ce..fad9539da9 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -101,6 +101,8 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_TO_LIBVIEW, SCH_EDIT_FRAME::OnOpenLibraryViewer ) EVT_TOOL( ID_TO_PCB, SCH_EDIT_FRAME::OnOpenPcbnew ) + EVT_TOOL( ID_TO_PCB_MODULE_EDITOR, SCH_EDIT_FRAME::OnOpenPcbModuleEditor ) + EVT_TOOL( ID_TO_CVPCB, SCH_EDIT_FRAME::OnOpenCvpcb ) EVT_TOOL( ID_SHEET_SET, EDA_DRAW_FRAME::Process_PageSettings ) @@ -794,6 +796,22 @@ void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event ) } +void SCH_EDIT_FRAME::OnOpenPcbModuleEditor( wxCommandEvent& event ) +{ + if( !Kiface().IsSingle() ) + { + wxFileName fn = g_RootSheet->GetScreen()->GetFileName(); + + if( fn.IsOk() ) + { + KIWAY_PLAYER* player = Kiway().Player( FRAME_PCB_MODULE_EDITOR ); + player->Show( true ); + player->Raise(); + } + } +} + + void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) { wxFileName fn = g_RootSheet->GetScreen()->GetFileName(); diff --git a/eeschema/tool_sch.cpp b/eeschema/tool_sch.cpp index 2bbed5bd48..962ef3847f 100644 --- a/eeschema/tool_sch.cpp +++ b/eeschema/tool_sch.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -139,10 +140,8 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->AddTool( ID_TO_LIBVIEW, wxEmptyString, KiBitmap( library_browse_xpm ), HELP_RUN_LIB_VIEWER ); - m_mainToolBar->AddSeparator(); - m_mainToolBar->AddTool( ID_GET_ANNOTATE, wxEmptyString, KiBitmap( annotate_xpm ), HELP_ANNOTATE ); @@ -158,6 +157,13 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->AddSeparator(); + // The user must HAVE footprints before he can assign them. So put this before + // the CVPCB. + if( !Kiface().IsSingle() ) // if pcbnew is not a separate process + { + m_mainToolBar->AddTool( ID_TO_PCB_MODULE_EDITOR, wxEmptyString, KiBitmap( module_editor_xpm ), + _( "Footprint Editor" ) ); + } m_mainToolBar->AddTool( ID_TO_CVPCB, wxEmptyString, KiBitmap( cvpcb_xpm ), _( "Run CvPcb to associate components and footprints" ) ); diff --git a/include/id.h b/include/id.h index 0c60acd429..a243491c30 100644 --- a/include/id.h +++ b/include/id.h @@ -45,6 +45,7 @@ enum main_id { ID_TO_PCB = wxID_HIGHEST, + ID_TO_PCB_MODULE_EDITOR, ID_TO_CVPCB, ID_LOAD_PROJECT, ID_APPEND_PROJECT, diff --git a/include/kiway_player.h b/include/kiway_player.h index e62981ab54..48cfeafc4a 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -185,11 +185,12 @@ public: * event which ends the modal behavior. * * @param aResult if not NULL, indicates a place to put a resultant string. + * @param aResultantFocusWindow if not NULL, indicates what window to pass focus to on return. * * @return bool - true if frame implementation called KIWAY_PLAYER::DismissModal() * with aRetVal of true. */ - VTBL_ENTRY bool ShowModal( wxString* aResult = NULL ); + VTBL_ENTRY bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL ); //-------------------------------------------------------- diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 171351d321..852b65c3fc 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -368,7 +368,7 @@ public: */ virtual void ExecuteRemoteCommand( const char* cmdline ); - void KiwayMailIn( KIWAY_EXPRESS& aEvent ); // virtual overload from KIWAY_PLAYER + void KiwayMailIn( KIWAY_EXPRESS& aEvent ); // override virtual from KIWAY_PLAYER void OnLeftClick( wxDC* aDC, const wxPoint& aPosition ); void OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ); @@ -793,6 +793,7 @@ private: void OnLoadProject( wxCommandEvent& event ); void OnAppendProject( wxCommandEvent& event ); void OnOpenPcbnew( wxCommandEvent& event ); + void OnOpenPcbModuleEditor( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event ); void OnOpenLibraryEditor( wxCommandEvent& event ); void OnSetOptions( wxCommandEvent& event ); diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 6e66b00c55..dda500664f 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -135,7 +135,7 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser() wxString fpid; - viewer->ShowModal( &fpid ); + viewer->ShowModal( &fpid, this ); //DBG(printf("%s: fpid:'%s'\n", __func__, TO_UTF8( fpid ) );) @@ -274,7 +274,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, module->SetTimeStamp( GetNewTimeStamp() ); GetBoard()->m_Status_Pcb = 0; - // Put it on FRONT layer, // (Can be stored flipped if the lib is an archive built from a board) if( module->IsFlipped() )