You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

674 lines
21 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014-2019 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <view/wx_view_controls.h>
  26. #include <worksheet_viewitem.h>
  27. #include <gal/graphics_abstraction_layer.h>
  28. #include <sch_draw_panel.h>
  29. #include <sch_view.h>
  30. #include <sch_painter.h>
  31. #include <sch_edit_frame.h>
  32. #include <preview_items/selection_area.h>
  33. #include <functional>
  34. #include <sch_sheet.h>
  35. #include <pgm_base.h>
  36. using namespace std::placeholders;
  37. // Events used by EDA_DRAW_PANEL
  38. BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledCanvas )
  39. EVT_CHAR( SCH_DRAW_PANEL::OnKeyEvent )
  40. EVT_CHAR_HOOK( SCH_DRAW_PANEL::OnCharHook )
  41. EVT_PAINT( SCH_DRAW_PANEL::onPaint )
  42. END_EVENT_TABLE()
  43. SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
  44. const wxPoint& aPosition, const wxSize& aSize,
  45. KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
  46. EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ),
  47. m_parent( aParentWindow )
  48. {
  49. m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
  50. m_showCrossHair = true;
  51. m_view = new KIGFX::SCH_VIEW( true, dynamic_cast<SCH_BASE_FRAME*>( aParentWindow ) );
  52. m_view->SetGAL( m_gal );
  53. m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
  54. m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
  55. m_view->SetPainter( m_painter.get() );
  56. m_view->SetScaleLimits( 50.0, 0.05 ); // This fixes the zoom in and zoom out limits
  57. m_view->SetMirror( false, false );
  58. // Early initialization of the canvas background color,
  59. // before any OnPaint event is fired for the canvas using a wrong bg color
  60. auto settings = m_painter->GetSettings();
  61. m_gal->SetClearColor( settings->GetBackgroundColor() );
  62. setDefaultLayerOrder();
  63. setDefaultLayerDeps();
  64. view()->UpdateAllLayersOrder();
  65. // View controls is the first in the event handler chain, so the Tool Framework operates
  66. // on updated viewport data.
  67. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  68. const wxEventType events[] =
  69. {
  70. wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
  71. wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
  72. wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
  73. wxEVT_MOTION, wxEVT_MOUSEWHEEL,
  74. };
  75. for( auto e : events )
  76. Connect( e, wxMouseEventHandler( SCH_DRAW_PANEL::OnMouseEvent ), NULL, this );
  77. Connect( wxEVT_CHAR, wxKeyEventHandler( SCH_DRAW_PANEL::OnKeyEvent ), NULL, this );
  78. Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( SCH_DRAW_PANEL::OnCharHook ), NULL, this );
  79. Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
  80. Pgm().CommonSettings()->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
  81. Pgm().CommonSettings()->Read( ENBL_AUTO_PAN_KEY, &m_enableAutoPan, true );
  82. m_canStartBlock = -1; // Command block can start if >= 0
  83. m_abortRequest = false;
  84. m_ignoreMouseEvents = false;
  85. // Be sure a mouse release button event will be ignored when creating the canvas
  86. // if the mouse click was not made inside the canvas (can happen sometimes, when
  87. // launching a editor from a double click made in another frame)
  88. m_ignoreNextLeftButtonRelease = true;
  89. m_mouseCaptureCallback = NULL;
  90. m_endMouseCaptureCallback = NULL;
  91. m_enableBlockCommands = false;
  92. m_minDragEventCount = 0;
  93. m_cursorLevel = 0;
  94. m_PrintIsMirrored = false;
  95. m_doubleClickInterval = 250;
  96. m_viewControls->SetSnapping( true );
  97. SetEvtHandlerEnabled( true );
  98. SetFocus();
  99. Show( true );
  100. Raise();
  101. StartDrawing();
  102. }
  103. SCH_DRAW_PANEL::~SCH_DRAW_PANEL()
  104. {
  105. }
  106. void SCH_DRAW_PANEL::DisplayComponent( const LIB_PART* aComponent )
  107. {
  108. view()->Clear();
  109. view()->DisplayComponent( const_cast<LIB_PART*>(aComponent) );
  110. }
  111. void SCH_DRAW_PANEL::DisplaySheet( const SCH_SCREEN *aScreen )
  112. {
  113. view()->Clear();
  114. if( aScreen )
  115. view()->DisplaySheet( const_cast<SCH_SCREEN*>( aScreen ) );
  116. }
  117. void SCH_DRAW_PANEL::setDefaultLayerOrder()
  118. {
  119. for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
  120. {
  121. LAYER_NUM layer = SCH_LAYER_ORDER[i];
  122. wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
  123. m_view->SetLayerOrder( layer, i );
  124. }
  125. }
  126. bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType )
  127. {
  128. VECTOR2D grid_size = m_gal->GetGridSize();
  129. bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
  130. setDefaultLayerDeps();
  131. m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
  132. // Keep grid size and grid visibility:
  133. m_gal->SetGridSize( grid_size );
  134. SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParent() );
  135. if( frame )
  136. m_gal->SetGridVisibility( frame->IsGridVisible() );
  137. Refresh();
  138. return rv;
  139. }
  140. void SCH_DRAW_PANEL::SetEnableMousewheelPan( bool aEnable )
  141. {
  142. m_enableMousewheelPan = aEnable;
  143. if( GetParent()->IsGalCanvasActive() )
  144. GetParent()->GetGalCanvas()->GetViewControls()->EnableMousewheelPan( aEnable );
  145. }
  146. void SCH_DRAW_PANEL::SetEnableAutoPan( bool aEnable )
  147. {
  148. EDA_DRAW_PANEL::SetEnableAutoPan( aEnable );
  149. if( GetParent()->IsGalCanvasActive() )
  150. GetParent()->GetGalCanvas()->GetViewControls()->EnableAutoPan( aEnable );
  151. }
  152. void SCH_DRAW_PANEL::SetAutoPanRequest( bool aEnable )
  153. {
  154. wxCHECK( GetParent()->IsGalCanvasActive(), /*void*/ );
  155. GetParent()->GetGalCanvas()->GetViewControls()->SetAutoPan( aEnable );
  156. }
  157. void SCH_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable )
  158. {
  159. m_enableZoomNoCenter = aEnable;
  160. if( GetParent()->IsGalCanvasActive() )
  161. GetParent()->GetGalCanvas()->GetViewControls()->EnableCursorWarping( !aEnable );
  162. }
  163. void SCH_DRAW_PANEL::setDefaultLayerDeps()
  164. {
  165. // caching makes no sense for Cairo and other software renderers
  166. auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
  167. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  168. m_view->SetLayerTarget( i, target );
  169. // Bitmaps are draw on a non cached GAL layer:
  170. m_view->SetLayerTarget( LAYER_DRAW_BITMAPS , KIGFX::TARGET_NONCACHED );
  171. // Some draw layers need specific settings
  172. m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
  173. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
  174. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
  175. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
  176. m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED );
  177. m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
  178. }
  179. KIGFX::SCH_VIEW* SCH_DRAW_PANEL::view() const
  180. {
  181. return static_cast<KIGFX::SCH_VIEW*>( m_view );
  182. }
  183. BASE_SCREEN* SCH_DRAW_PANEL::GetScreen()
  184. {
  185. return GetParent()->GetScreen();
  186. }
  187. EDA_DRAW_FRAME* SCH_DRAW_PANEL::GetParent() const
  188. {
  189. return static_cast<EDA_DRAW_FRAME*>(m_parent); // static_cast<SCH_EDIT_FRAME*> (m_parent);
  190. }
  191. void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
  192. {
  193. int localbutt = 0;
  194. BASE_SCREEN* screen = GetScreen();
  195. auto controls = GetViewControls();
  196. auto vmp = VECTOR2I( controls->GetMousePosition() );
  197. wxPoint mousePos ( vmp.x, vmp.y );
  198. event.Skip();
  199. if( !screen )
  200. return;
  201. /* Adjust value to filter mouse displacement before consider the drag
  202. * mouse is really a drag command, not just a movement while click
  203. */
  204. #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5
  205. if( event.Leaving() )
  206. m_canStartBlock = -1;
  207. if( !IsMouseCaptured() && !controls->GetSettings().m_cursorCaptured )
  208. SetAutoPanRequest( false );
  209. if( GetParent()->IsActive() )
  210. SetFocus();
  211. else
  212. return;
  213. if( !event.IsButton() && !event.Moving() && !event.Dragging() )
  214. return;
  215. if( event.RightUp() )
  216. {
  217. OnRightClick( event );
  218. return;
  219. }
  220. if( m_ignoreMouseEvents )
  221. return;
  222. if( event.LeftDown() )
  223. localbutt = GR_M_LEFT_DOWN;
  224. if( event.ButtonDClick( 1 ) )
  225. localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
  226. if( event.MiddleDown() )
  227. localbutt = GR_M_MIDDLE_DOWN;
  228. // Compute the cursor position in drawing (logical) units.
  229. //GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) );
  230. int kbstat = 0;
  231. if( event.ShiftDown() )
  232. kbstat |= GR_KB_SHIFT;
  233. if( event.ControlDown() )
  234. kbstat |= GR_KB_CTRL;
  235. if( event.AltDown() )
  236. kbstat |= GR_KB_ALT;
  237. // Calling Double Click and Click functions :
  238. if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
  239. {
  240. GetParent()->OnLeftDClick( nullptr, mousePos );
  241. // inhibit a response to the mouse left button release,
  242. // because we have a double click, and we do not want a new
  243. // OnLeftClick command at end of this Double Click
  244. m_ignoreNextLeftButtonRelease = true;
  245. }
  246. else if( event.LeftUp() )
  247. {
  248. // A block command is in progress: a left up is the end of block
  249. // or this is the end of a double click, already seen
  250. // Note also m_ignoreNextLeftButtonRelease can be set by
  251. // the call to OnLeftClick(), so do not change it after calling OnLeftClick
  252. bool ignoreEvt = m_ignoreNextLeftButtonRelease;
  253. m_ignoreNextLeftButtonRelease = false;
  254. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt )
  255. GetParent()->OnLeftClick( nullptr, mousePos );
  256. }
  257. else if( !event.LeftIsDown() )
  258. {
  259. /* be sure there is a response to a left button release command
  260. * even when a LeftUp event is not seen. This happens when a
  261. * double click opens a dialog box, and the release mouse button
  262. * is made when the dialog box is opened.
  263. */
  264. m_ignoreNextLeftButtonRelease = false;
  265. }
  266. if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) )
  267. {
  268. m_PanStartCenter = GetParent()->GetScrollCenterPosition();
  269. m_PanStartEventPosition = event.GetPosition();
  270. CrossHairOff( );
  271. SetCurrentCursor( wxCURSOR_SIZING );
  272. }
  273. if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) )
  274. {
  275. CrossHairOn();
  276. SetDefaultCursor();
  277. }
  278. if( event.MiddleIsDown() )
  279. {
  280. // already managed by EDA_DRAW_PANEL_GAL mouse event handler.
  281. return;
  282. }
  283. // Calling the general function on mouse changes (and pseudo key commands)
  284. GetParent()->GeneralControl( nullptr, mousePos );
  285. /*******************************/
  286. /* Control of block commands : */
  287. /*******************************/
  288. // Command block can't start if mouse is dragging a new panel
  289. static SCH_DRAW_PANEL* lastPanel;
  290. if( lastPanel != this )
  291. {
  292. m_minDragEventCount = 0;
  293. m_canStartBlock = -1;
  294. }
  295. /* A new command block can start after a release buttons
  296. * and if the drag is enough
  297. * This is to avoid a false start block when a dialog box is dismissed,
  298. * or when changing panels in hierarchy navigation
  299. * or when clicking while and moving mouse
  300. */
  301. if( !event.LeftIsDown() && !event.MiddleIsDown() )
  302. {
  303. m_minDragEventCount = 0;
  304. m_canStartBlock = 0;
  305. /* Remember the last cursor position when a drag mouse starts
  306. * this is the last position ** before ** clicking a button
  307. * this is useful to start a block command from the point where the
  308. * mouse was clicked first
  309. * (a filter creates a delay for the real block command start, and
  310. * we must remember this point)
  311. */
  312. m_CursorStartPos = GetParent()->GetCrossHairPosition();
  313. }
  314. if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) )
  315. {
  316. if( !screen->IsBlockActive() )
  317. {
  318. screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
  319. }
  320. if( event.LeftDown() )
  321. {
  322. if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
  323. {
  324. SetAutoPanRequest( false );
  325. GetParent()->HandleBlockPlace( nullptr );
  326. m_ignoreNextLeftButtonRelease = true;
  327. }
  328. }
  329. else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() )
  330. {
  331. // Mouse is dragging: if no block in progress, start a block command.
  332. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
  333. {
  334. // Start a block command
  335. int cmd_type = kbstat;
  336. // A block command is started if the drag is enough. A small
  337. // drag is ignored (it is certainly a little mouse move when
  338. // clicking) not really a drag mouse
  339. if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
  340. m_minDragEventCount++;
  341. else
  342. {
  343. auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0;
  344. DBG(printf("start block\n");)
  345. if( !GetParent()->HandleBlockBegin( nullptr, cmd_type, m_CursorStartPos, cmd ) )
  346. {
  347. // should not occur: error
  348. GetParent()->DisplayToolMsg(
  349. wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
  350. }
  351. else
  352. {
  353. SetAutoPanRequest( true );
  354. SetCursor( wxCURSOR_SIZING );
  355. }
  356. }
  357. }
  358. }
  359. if( event.ButtonUp( wxMOUSE_BTN_LEFT ) )
  360. {
  361. /* Release the mouse button: end of block.
  362. * The command can finish (DELETE) or have a next command (MOVE,
  363. * COPY). However the block command is canceled if the block
  364. * size is small because a block command filtering is already
  365. * made, this case happens, but only when the on grid cursor has
  366. * not moved.
  367. */
  368. #define BLOCK_MINSIZE_LIMIT 1
  369. bool BlockIsSmall =
  370. ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT )
  371. && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT );
  372. if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall )
  373. {
  374. if( m_endMouseCaptureCallback )
  375. {
  376. m_endMouseCaptureCallback( this, nullptr );
  377. SetAutoPanRequest( false );
  378. }
  379. //SetCursor( (wxStockCursor) m_currentCursor );
  380. }
  381. else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END )
  382. {
  383. SetAutoPanRequest( false );
  384. GetParent()->HandleBlockEnd( nullptr );
  385. //SetCursor( (wxStockCursor) m_currentCursor );
  386. if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
  387. {
  388. SetAutoPanRequest( true );
  389. SetCursor( wxCURSOR_HAND );
  390. }
  391. }
  392. }
  393. }
  394. // End of block command on a double click
  395. // To avoid an unwanted block move command if the mouse is moved while double clicking
  396. if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
  397. {
  398. if( !screen->IsBlockActive() && IsMouseCaptured() )
  399. m_endMouseCaptureCallback( this, nullptr );
  400. }
  401. lastPanel = this;
  402. }
  403. bool SCH_DRAW_PANEL::OnRightClick( wxMouseEvent& event )
  404. {
  405. auto controls = GetViewControls();
  406. auto vmp = controls->GetMousePosition();
  407. wxPoint mouseWorldPos ( (int) vmp.x, (int) vmp.y );
  408. wxMenu MasterMenu;
  409. if( !GetParent()->OnRightClick( mouseWorldPos, &MasterMenu ) )
  410. return false;
  411. GetParent()->AddMenuZoomAndGrid( &MasterMenu );
  412. m_ignoreMouseEvents = true;
  413. PopupMenu( &MasterMenu, event.GetPosition() );
  414. m_ignoreMouseEvents = false;
  415. return true;
  416. }
  417. void SCH_DRAW_PANEL::CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase )
  418. {
  419. wxCHECK_RET( m_mouseCaptureCallback != NULL, wxT( "Mouse capture callback not set." ) );
  420. m_mouseCaptureCallback( this, aDC, aPosition, aErase );
  421. }
  422. void SCH_DRAW_PANEL::CallEndMouseCapture( wxDC* aDC )
  423. {
  424. // CallEndMouseCapture is sometimes called with m_endMouseCaptureCallback == NULL
  425. // for instance after an ABORT in block paste.
  426. if( m_endMouseCaptureCallback )
  427. m_endMouseCaptureCallback( this, aDC );
  428. }
  429. void SCH_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
  430. bool aCallEndFunc )
  431. {
  432. if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc )
  433. m_endMouseCaptureCallback( this, nullptr );
  434. m_mouseCaptureCallback = NULL;
  435. m_endMouseCaptureCallback = NULL;
  436. SetAutoPanRequest( false );
  437. if( id != -1 && cursor != -1 )
  438. {
  439. //wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX );
  440. GetParent()->SetToolID( id, cursor, title );
  441. }
  442. }
  443. void SCH_DRAW_PANEL::CrossHairOff( wxDC* DC )
  444. {
  445. m_viewControls->ShowCursor( false );
  446. }
  447. void SCH_DRAW_PANEL::CrossHairOn( wxDC* DC )
  448. {
  449. m_viewControls->ShowCursor( true );
  450. }
  451. void SCH_DRAW_PANEL::MoveCursorToCrossHair()
  452. {
  453. GetViewControls()->WarpCursor( GetParent()->GetCrossHairPosition(), true );
  454. }
  455. void SCH_DRAW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
  456. {
  457. EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
  458. }
  459. void SCH_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
  460. {
  461. event.Skip();
  462. }
  463. void SCH_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
  464. {
  465. int localkey = event.GetKeyCode();
  466. bool keyWasHandled = false;
  467. switch( localkey )
  468. {
  469. default:
  470. break;
  471. case WXK_ESCAPE:
  472. m_abortRequest = true;
  473. if( IsMouseCaptured() )
  474. EndMouseCapture();
  475. else
  476. EndMouseCapture( ID_NO_TOOL_SELECTED, 0 /*m_defaultCursor*/, wxEmptyString );
  477. keyWasHandled = true; // The key is captured: the key event will be not skipped
  478. break;
  479. }
  480. /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
  481. * They have an ascii code from 1 to 27 remapped
  482. * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
  483. */
  484. if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z )
  485. localkey += 'A' - 1;
  486. /* Disallow shift for keys that have two keycodes on them (e.g. number and
  487. * punctuation keys) leaving only the "letter keys" of A-Z.
  488. * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
  489. * and Ctrl-( and Ctrl-5 (FR layout).
  490. * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
  491. */
  492. bool keyIsLetter = ( localkey >= 'A' && localkey <= 'Z' ) ||
  493. ( localkey >= 'a' && localkey <= 'z' );
  494. if( event.ShiftDown() && ( keyIsLetter || localkey > 256 ) )
  495. localkey |= GR_KB_SHIFT;
  496. if( event.ControlDown() )
  497. localkey |= GR_KB_CTRL;
  498. if( event.AltDown() )
  499. localkey |= GR_KB_ALT;
  500. // Some key commands use the current mouse position: refresh it.
  501. //pos = wxGetMousePosition() - GetScreenPosition();
  502. // Compute the cursor position in drawing units. Also known as logical units to wxDC.
  503. //pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
  504. auto p = GetViewControls()->GetCursorPosition( false );
  505. wxPoint pos ((int)p.x, (int)p.y);
  506. GetParent()->SetMousePosition( pos );
  507. // a Key event has to be skipped only if it is not handled:
  508. if( !GetParent()->GeneralControl( nullptr, pos, localkey ) && !keyWasHandled )
  509. event.Skip();
  510. }
  511. void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
  512. {
  513. if( !m_gal->IsInitialized() || !m_gal->IsVisible() )
  514. // The first wxPaintEvent can be fired at startup before the GAL engine is fully initialized
  515. // (depending on platforms). Do nothing in this case
  516. return;
  517. if( m_painter )
  518. static_cast<KIGFX::SCH_PAINTER*>(m_painter.get())->GetSettings()->ImportLegacyColors( nullptr );
  519. EDA_DRAW_PANEL_GAL::onPaint( aEvent );
  520. }