KiCad PCB EDA Suite
Loading...
Searching...
No Matches
spnav_viewer_plugin.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see CHANGELOG.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "spnav_viewer_plugin.h"
21
24#include <pgm_base.h>
26
28 : m_timer( this ), m_canvas( aCanvas ), m_camera( nullptr ), m_focused( true )
29{
30 m_camera = dynamic_cast<TRACK_BALL*>( aCanvas->GetCamera() );
31 m_driver = std::make_unique<LIBSPNAV_DRIVER>();
32
33 if( m_driver->Connect() )
34 {
35 m_driver->SetHandler( this );
36 Bind( wxEVT_TIMER, &SPNAV_VIEWER_PLUGIN::onPollTimer, this );
37 m_timer.Start( 10 );
38 }
39}
40
42{
43 m_timer.Stop();
44
45 if( m_driver )
46 m_driver->Disconnect();
47}
48
50{
51 m_focused = aFocus;
52}
53
55{
56 if( m_driver && m_focused )
57 m_driver->Poll();
58}
59
60void SPNAV_VIEWER_PLUGIN::OnPan( double x, double y, double z )
61{
62 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
63 {
64 float scale = 0.0005f * ( cfg->m_SpaceMouse.pan_speed / 5.0f );
65
66 if( cfg->m_SpaceMouse.reverse_pan_x )
67 x = -x;
68
69 if( cfg->m_SpaceMouse.reverse_pan_y )
70 y = -y;
71
72 if( cfg->m_SpaceMouse.reverse_zoom )
73 z = -z;
74
75 if( m_camera )
76 {
77 m_camera->Pan( SFVEC3F( x * scale, z * scale, y * scale ) );
78 m_canvas->Request_refresh();
79 }
80 }
81}
82
83void SPNAV_VIEWER_PLUGIN::OnRotate( double rx, double ry, double rz )
84{
85 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
86 {
87 float scale = 0.001f * ( cfg->m_SpaceMouse.rotate_speed / 20.0f );
88
89 if( cfg->m_SpaceMouse.reverse_rotate )
90 scale = -scale;
91
92 if( m_camera )
93 {
94 m_camera->RotateX( rx * scale );
95 m_camera->RotateY( rz * scale );
96 m_camera->RotateZ( ry * scale );
97 m_canvas->Request_refresh();
98 }
99 }
100}
101
102void SPNAV_VIEWER_PLUGIN::OnButton( int button, bool pressed )
103{
104 // Buttons are ignored for now
105 (void) button;
106 (void) pressed;
107}
Implement a canvas based on a wxGLCanvas.
CAMERA * GetCamera()
Get the canvas camera.
void SetFocus(bool aFocus=true)
void OnRotate(double rx, double ry, double rz) override
Handle rotational events.
std::unique_ptr< SPACENAV_DRIVER > m_driver
void OnPan(double x, double y, double z) override
Handle translation (pan) events.
void onPollTimer(wxTimerEvent &evt)
SPNAV_VIEWER_PLUGIN(EDA_3D_CANVAS *aCanvas)
void OnButton(int button, bool pressed) override
Handle button press/release events.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
const int scale
Declaration for a track ball camera.
glm::vec3 SFVEC3F
Definition xv3d_types.h:40