diff --git a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp index fe107b3070..274bcf3997 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp @@ -29,6 +29,7 @@ #include #include #include "eda_3d_actions.h" +#include "dialogs/panel_preview_3d_model.h" #include <3d_rendering/opengl/render_3d_opengl.h> @@ -113,10 +114,36 @@ int EDA_3D_CONTROLLER::Main( const TOOL_EVENT& aEvent ) // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { - if( evt->IsClick( BUT_RIGHT ) ) + if( evt->IsCancelInteractive() ) + { + wxWindow* canvas = m_toolMgr->GetToolHolder()->GetToolCanvas(); + wxWindow* topLevelParent = canvas->GetParent(); + + while( topLevelParent && !topLevelParent->IsTopLevel() ) + topLevelParent = topLevelParent->GetParent(); + + if( topLevelParent && dynamic_cast( topLevelParent ) ) + { + DIALOG_SHIM* dialog = static_cast( topLevelParent ); + + if( dialog->IsQuasiModal() ) + dialog->EndQuasiModal( wxID_CANCEL ); + else + dialog->EndModal( wxID_CANCEL ); + } + else + { + evt->SetPassEvent(); + } + } + else if( evt->IsClick( BUT_RIGHT ) ) + { m_menu.ShowContextMenu(); + } else + { evt->SetPassEvent(); + } } return 0; diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 29a9fa120e..fb5c1f8608 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2016 Mario Luzeiro * Copyright (C) 2015 Cirilo Bernardo * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.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 @@ -124,8 +124,10 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 ); for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } ) + { Connect( eventType, wxMenuEventHandler( PANEL_PREVIEW_3D_MODEL::OnMenuEvent ), nullptr, this ); + } #ifdef __WXOSX__ // Call layout once to get the proper button sizes after the bitmaps have been set