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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "spnav_viewer_plugin.h"
25
28#include <pgm_base.h>
30
32 : m_timer( this ), m_canvas( aCanvas ), m_camera( nullptr ), m_focused( true )
33{
34 m_camera = dynamic_cast<TRACK_BALL*>( aCanvas->GetCamera() );
35 m_driver = std::make_unique<LIBSPNAV_DRIVER>();
36
37 if( m_driver->Connect() )
38 {
39 m_driver->SetHandler( this );
40 Bind( wxEVT_TIMER, &SPNAV_VIEWER_PLUGIN::onPollTimer, this );
41 m_timer.Start( 10 );
42 }
43}
44
46{
47 m_timer.Stop();
48
49 if( m_driver )
50 m_driver->Disconnect();
51}
52
54{
55 m_focused = aFocus;
56}
57
59{
60 if( m_driver && m_focused )
61 m_driver->Poll();
62}
63
64void SPNAV_VIEWER_PLUGIN::OnPan( double x, double y, double z )
65{
66 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
67 {
68 float scale = 0.0005f * ( cfg->m_SpaceMouse.pan_speed / 5.0f );
69
70 if( cfg->m_SpaceMouse.reverse_pan_x )
71 x = -x;
72
73 if( cfg->m_SpaceMouse.reverse_pan_y )
74 y = -y;
75
76 if( cfg->m_SpaceMouse.reverse_zoom )
77 z = -z;
78
79 if( m_camera )
80 {
81 m_camera->Pan( SFVEC3F( x * scale, -y * scale, z * scale ) );
82 m_canvas->Request_refresh();
83 }
84 }
85}
86
87void SPNAV_VIEWER_PLUGIN::OnRotate( double rx, double ry, double rz )
88{
89 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
90 {
91 float scale = 0.001f * ( cfg->m_SpaceMouse.rotate_speed / 5.0f );
92
93 if( cfg->m_SpaceMouse.reverse_rotate )
94 scale = -scale;
95
96 if( m_camera )
97 {
98 m_camera->RotateX( ry * scale );
99 m_camera->RotateY( rx * scale );
100 m_camera->RotateZ( rz * scale );
101 m_canvas->Request_refresh();
102 }
103 }
104}
105
106void SPNAV_VIEWER_PLUGIN::OnButton( int button, bool pressed )
107{
108 // Buttons are ignored for now
109 (void) button;
110 (void) pressed;
111}
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.
Definition pgm_base.cpp:913
see class PGM_BASE
const int scale
Declaration for a track ball camera.
glm::vec3 SFVEC3F
Definition xv3d_types.h:44