From e15ad9350f1ecdd29a5d3c6e42162e2f0c49ff84 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 28 Jul 2016 14:07:35 +0200 Subject: [PATCH] Fix issue from rev 6994 "Run DRC" from plot dialog crashes on Linux. --- pcbnew/dialogs/dialog_drc.cpp | 39 ++++++++++++++++++++++------------ pcbnew/dialogs/dialog_plot.cpp | 6 +++--- pcbnew/drc.cpp | 30 ++++++++++++++++++++------ pcbnew/drc_stuff.h | 15 +++++++++---- pcbnew/edit.cpp | 4 +++- 5 files changed, 66 insertions(+), 28 deletions(-) diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 4ec69cc199..0fdaf37cad 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -69,7 +69,7 @@ void DIALOG_DRC_CONTROL::OnActivateDlg( wxActivateEvent& event ) // in lists SetReturnCode( wxID_CANCEL ); Close(); - m_tester->DestroyDialog( wxID_CANCEL ); + m_tester->DestroyDRCDialog( wxID_CANCEL ); return; } @@ -300,7 +300,9 @@ void DIALOG_DRC_CONTROL::OnOkClick( wxCommandEvent& event ) SetReturnCode( wxID_OK ); SetDrcParmeters(); - m_tester->DestroyDialog( wxID_OK ); + // The dialog can be modal or not modal. + // Leave the DRC caller destroy (or not) the dialog + m_tester->DestroyDRCDialog( wxID_OK ); } @@ -308,7 +310,9 @@ void DIALOG_DRC_CONTROL::OnCancelClick( wxCommandEvent& event ) { SetReturnCode( wxID_CANCEL ); - m_tester->DestroyDialog( wxID_CANCEL ); + // The dialog can be modal or not modal. + // Leave the DRC caller destroy (or not) the dialog + m_tester->DestroyDRCDialog( wxID_CANCEL ); } @@ -342,13 +346,16 @@ void DIALOG_DRC_CONTROL::OnLeftDClickClearance( wxMouseEvent& event ) m_brdEditor->CursorGoto( item->GetPointA() ); m_brdEditor->GetGalCanvas()->GetView()->SetCenter( VECTOR2D( item->GetPointA() ) ); - // turn control over to m_brdEditor, hide this DIALOG_DRC_CONTROL window, - // no destruction so we can preserve listbox cursor - Show( false ); + if( !IsModal() ) + { + // turn control over to m_brdEditor, hide this DIALOG_DRC_CONTROL window, + // no destruction so we can preserve listbox cursor + Show( false ); - // We do not want the clarification popup window. - // when releasing the left button in the main window - m_brdEditor->SkipNextLeftButtonReleaseEvent(); + // We do not want the clarification popup window. + // when releasing the left button in the main window + m_brdEditor->SkipNextLeftButtonReleaseEvent(); + } } } } @@ -395,7 +402,8 @@ void DIALOG_DRC_CONTROL::OnPopupMenu( wxCommandEvent& event ) m_brdEditor->CursorGoto( pos ); m_brdEditor->GetGalCanvas()->GetView()->SetCenter( VECTOR2D( item->GetPointA() ) ); - Show( false ); + if( !IsModal() ) + Show( false ); } } @@ -475,11 +483,14 @@ void DIALOG_DRC_CONTROL::OnLeftDClickUnconnected( wxMouseEvent& event ) m_brdEditor->CursorGoto( item->GetPointA() ); m_brdEditor->GetGalCanvas()->GetView()->SetCenter( VECTOR2D( item->GetPointA() ) ); - Show( false ); + if( !IsModal() ) + { + Show( false ); - // We do not want the clarification popup window. - // when releasing the left button in the main window - m_brdEditor->SkipNextLeftButtonReleaseEvent(); + // We do not want the clarification popup window. + // when releasing the left button in the main window + m_brdEditor->SkipNextLeftButtonReleaseEvent(); + } } } } diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 976e080190..fe648bd44e 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -823,10 +823,10 @@ void DIALOG_PLOT::onRunDRC( wxCommandEvent& event ) { // First close an existing dialog if open // (low probability, but can happen) - parent->GetDrcController()->DestroyDialog( wxID_OK ); + parent->GetDrcController()->DestroyDRCDialog( wxID_OK ); - // Open a new drc dialod, with the right parent frame - parent->GetDrcController()->ShowDialog( this ); + // Open a new drc dialod, with the right parent frame, and in Modal Mode + parent->GetDrcController()->ShowDRCDialog( this ); } } diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index 84df89604b..c2c6e1a8a6 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -53,8 +53,20 @@ #include -void DRC::ShowDialog( wxWindow* aParent ) +void DRC::ShowDRCDialog( wxWindow* aParent ) { + bool show_dlg_modal = true; + + // the dialog needs a parent frame. if it is not specified, this is + // the PCB editor frame specified in DRC class. + if( aParent == NULL ) + { + // if any parent is specified, the dialog is modal. + // if this is the default PCB editor frame, it is not modal + show_dlg_modal = false; + aParent = m_pcbEditorFrame; + } + if( !m_drcDialog ) { m_pcbEditorFrame->GetToolManager()->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -62,15 +74,21 @@ void DRC::ShowDialog( wxWindow* aParent ) updatePointers(); m_drcDialog->SetRptSettings( m_doCreateRptFile, m_rptFilename); - } - else - updatePointers(); - m_drcDialog->Show( true ); + if( show_dlg_modal ) + m_drcDialog->ShowModal(); + else + m_drcDialog->Show( true ); + } + else // The dialog is just not visible (because the user has double clicked on an error item) + { + updatePointers(); + m_drcDialog->Show( true ); + } } -void DRC::DestroyDialog( int aReason ) +void DRC::DestroyDRCDialog( int aReason ) { if( m_drcDialog ) { diff --git a/pcbnew/drc_stuff.h b/pcbnew/drc_stuff.h index a8d378ff5d..9a5e147403 100644 --- a/pcbnew/drc_stuff.h +++ b/pcbnew/drc_stuff.h @@ -437,22 +437,29 @@ public: /** - * Function ShowDialog + * Function ShowDRCDialog * opens a dialog and prompts the user, then if a test run button is * clicked, runs the test(s) and creates the MARKERS. The dialog is only * created if it is not already in existence. * @param aParent is the parent window for wxWidgets. Usually the PCB editor frame * but can be an other dialog + * if aParent == NULL (default), the parent will be the PCB editor frame + * and the dialog will be not modal (just float on parent + * if aParent is specified, the dialog will be modal. + * The modal mode is mandatory if the dialog is created from an other dialog, not + * from the PCB editor frame */ - void ShowDialog( wxWindow* aParent ); + void ShowDRCDialog( wxWindow* aParent = NULL ); /** - * Function DestroyDialog + * Function DestroyDRCDialog * deletes this ui dialog box and zeros out its pointer to remember * the state of the dialog's existence. * @param aReason Indication of which button was clicked to cause the destruction. + * if aReason == wxID_OK, design parameters values which can be entered from the dialog will bbe saved + * in design parameters list */ - void DestroyDialog( int aReason ); + void DestroyDRCDialog( int aReason ); /** diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index d74f033e41..01c92e8fa8 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -294,7 +294,9 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_DRC_CONTROL: - m_drc->ShowDialog( this ); + // Shows the DRC dialog in non modal mode, to allows board edition + // with the DRC dialog opened and showing errors. + m_drc->ShowDRCDialog(); break; case ID_GET_NETLIST: