Enable 3D mouse support in Footprint viewer.

The 3D mouse support is  moved from PCB_EDIT_FRAME to PCB_BASE_FRAME.
This allows all PCB_BASE_FRAME derived windows to have 3D mouse enabled
2D navigation support.
This commit is contained in:
markus-bonk 2021-10-25 14:18:48 +02:00 committed by Wayne Stambaugh
parent 8e43409d27
commit b263e89dfe
4 changed files with 46 additions and 48 deletions

View File

@ -62,9 +62,9 @@ class FP_LIB_TABLE;
class PCBNEW_SETTINGS;
class FOOTPRINT_EDITOR_SETTINGS;
struct MAGNETIC_SETTINGS;
class NL_PCBNEW_PLUGIN;
class PROGRESS_REPORTER;
wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent );
/**
@ -384,6 +384,8 @@ public:
protected:
bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
void handleActivateEvent( wxActivateEvent& aEvent ) override;
/**
* Attempts to load \a aFootprintId from the footprint library table.
*
@ -402,6 +404,9 @@ protected:
PCB_DISPLAY_OPTIONS m_displayOptions;
PCB_ORIGIN_TRANSFORMS m_originTransforms;
PCBNEW_SETTINGS* m_settings; // No ownership, just a shortcut
private:
NL_PCBNEW_PLUGIN* m_spaceMouse;
};
#endif // PCB_BASE_FRAME_H

View File

@ -59,6 +59,10 @@
#include "cleanup_item.h"
#include <zoom_defines.h>
#if defined( KICAD_USE_3DCONNEXION )
#include <navlib/nl_pcbnew_plugin.h>
#endif
using KIGFX::RENDER_SETTINGS;
using KIGFX::PCB_RENDER_SETTINGS;
@ -66,10 +70,9 @@ wxDEFINE_EVENT( BOARD_CHANGED, wxCommandEvent );
PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
long aStyle, const wxString & aFrameName ) :
long aStyle, const wxString& aFrameName ) :
EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
m_pcb( nullptr ),
m_originTransforms( *this )
m_pcb( nullptr ), m_originTransforms( *this ), m_spaceMouse( nullptr )
{
m_settings = static_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
}
@ -77,6 +80,11 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
PCB_BASE_FRAME::~PCB_BASE_FRAME()
{
#if defined( KICAD_USE_3DCONNEXION )
if( m_spaceMouse != nullptr )
delete m_spaceMouse;
#endif
// Ensure m_canvasType is up to date, to save it in config
m_canvasType = GetCanvas()->GetBackend();
@ -97,6 +105,19 @@ bool PCB_BASE_FRAME::canCloseWindow( wxCloseEvent& aEvent )
}
void PCB_BASE_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
{
EDA_DRAW_FRAME::handleActivateEvent( aEvent );
#if defined( KICAD_USE_3DCONNEXION )
if( m_spaceMouse != nullptr )
{
m_spaceMouse->SetFocus( aEvent.GetActive() );
}
#endif
}
EDA_3D_VIEWER_FRAME* PCB_BASE_FRAME::Get3DViewerFrame()
{
wxWindow* frame = FindWindowByName( QUALIFIED_VIEWER3D_FRAMENAME( this ) );
@ -919,6 +940,20 @@ void PCB_BASE_FRAME::ActivateGalCanvas()
view->RecacheAllItems();
canvas->SetEventDispatcher( m_toolDispatcher );
canvas->StartDrawing();
#if defined( KICAD_USE_3DCONNEXION )
try
{
if( m_spaceMouse == nullptr )
{
m_spaceMouse = new NL_PCBNEW_PLUGIN( GetCanvas() );
}
}
catch( const std::system_error& e )
{
wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
}
#endif
}

View File

@ -108,17 +108,13 @@
#include <wx/filedlg.h>
#if defined( KICAD_USE_3DCONNEXION )
#include <navlib/nl_pcbnew_plugin.h>
#endif
using namespace std::placeholders;
BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, PCB_EDIT_FRAME::OnSockRequestServer )
EVT_SOCKET( ID_EDA_SOCKET_EVENT, PCB_EDIT_FRAME::OnSockRequest )
EVT_ACTIVATE( PCB_EDIT_FRAME::OnActivate )
EVT_CHOICE( ID_ON_ZOOM_SELECT, PCB_EDIT_FRAME::OnSelectZoom )
EVT_CHOICE( ID_ON_GRID_SELECT, PCB_EDIT_FRAME::OnSelectGrid )
@ -182,7 +178,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ),
wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
PCB_EDIT_FRAME_NAME ),
m_exportNetlistAction( nullptr ), m_findDialog( nullptr ), m_spaceMouse( nullptr )
m_exportNetlistAction( nullptr ), m_findDialog( nullptr )
{
m_maximizeByDefault = true;
m_showBorderAndTitleBlock = true; // true to display sheet references
@ -372,17 +368,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// if( !appK2S.FileExists() )
// GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
#if defined( KICAD_USE_3DCONNEXION )
try
{
m_spaceMouse = new NL_PCBNEW_PLUGIN( canvas );
}
catch( const std::system_error& e )
{
wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
}
#endif
// AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
#ifdef __WXMAC__
if( Kiface().IsSingle() )
@ -427,11 +412,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
{
#if defined( KICAD_USE_3DCONNEXION )
if( m_spaceMouse != nullptr )
delete m_spaceMouse;
#endif
if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
{
// Stop the timer during destruction early to avoid potential event race conditions (that do happen on windows)
@ -1261,19 +1241,6 @@ void PCB_EDIT_FRAME::OnDisplayOptionsChanged()
}
void PCB_EDIT_FRAME::OnActivate( wxActivateEvent& aEvent )
{
#if defined( KICAD_USE_3DCONNEXION )
if( m_spaceMouse != nullptr )
{
m_spaceMouse->SetFocus( aEvent.GetActive() );
}
#endif
aEvent.Skip(); // required under wxMAC
}
bool PCB_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
{
return GetBoard()->IsElementVisible( aElement );

View File

@ -57,7 +57,6 @@ class FP_LIB_TABLE;
class BOARD_NETLIST_UPDATER;
class ACTION_MENU;
class TOOL_ACTION;
class NL_PCBNEW_PLUGIN;
enum LAST_PATH_TYPE : unsigned int;
@ -738,13 +737,6 @@ protected:
*/
void OnActionPluginMenu( wxCommandEvent& aEvent);
/**
* Sent when a window or application is being activated or deactivated.
*
* @param aEvent sent by wx
*/
void OnActivate( wxActivateEvent& aEvent );
/**
* Launched by the button when an action is called.
*
@ -825,7 +817,6 @@ private:
wxTimer* m_eventCounterTimer;
NL_PCBNEW_PLUGIN* m_spaceMouse;
};
#endif // __PCB_EDIT_FRAME_H__