KiCad PCB EDA Suite
sch_draw_panel.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 (C) 2014-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #include <view/wx_view_controls.h>
27 #include <worksheet_viewitem.h>
28 
30 #include <sch_draw_panel.h>
31 #include <sch_view.h>
32 #include <sch_painter.h>
33 #include <sch_edit_frame.h>
35 
36 #include <functional>
37 
38 #include <sch_sheet.h>
39 #include <pgm_base.h>
40 
41 using namespace std::placeholders;
42 
43 
44 // Events used by EDA_DRAW_PANEL
45 // GAL TODO: some (most?) of these need to be implemented...
46 BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledCanvas )
47 // EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
48 // EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering )
49 // EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel )
50 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
51 // EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify )
52 #endif
53 // EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent )
54  EVT_CHAR( SCH_DRAW_PANEL::OnKeyEvent )
55  EVT_CHAR_HOOK( SCH_DRAW_PANEL::OnCharHook )
56  EVT_PAINT( SCH_DRAW_PANEL::onPaint )
57 // EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground )
58 // EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll )
59 // EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate )
60 // EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan )
61 END_EVENT_TABLE()
62 
63 SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
64  const wxPoint& aPosition, const wxSize& aSize,
65  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
66  EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ),
67  m_parent( aParentWindow )
68 {
69  m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
70  m_showCrossHair = true;
71  m_view = new KIGFX::SCH_VIEW( true, dynamic_cast<SCH_BASE_FRAME*>( aParentWindow ) );
72  m_view->SetGAL( m_gal );
73 
74  m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
75 
76  m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
77 
78  m_view->SetPainter( m_painter.get() );
79  m_view->SetScaleLimits( 50.0, 0.05 ); // This fixes the zoom in and zoom out limits
80  m_view->SetMirror( false, false );
81 
82  setDefaultLayerOrder();
83  setDefaultLayerDeps();
84 
85  view()->UpdateAllLayersOrder();
86 
87  // View controls is the first in the event handler chain, so the Tool Framework operates
88  // on updated viewport data.
89  m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
90 
91  const wxEventType events[] =
92  {
93  wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
94  wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
95  wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
96  wxEVT_MOTION, wxEVT_MOUSEWHEEL,
97  };
98 
99  for( auto e : events )
100  {
101  Connect( e, wxMouseEventHandler( SCH_DRAW_PANEL::OnMouseEvent ), NULL, this );
102  }
103 
104  Connect( wxEVT_CHAR, wxKeyEventHandler( SCH_DRAW_PANEL::OnKeyEvent ), NULL, this );
105  Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( SCH_DRAW_PANEL::OnCharHook ), NULL, this );
106 
107  Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
108  Pgm().CommonSettings()->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
109  Pgm().CommonSettings()->Read( ENBL_AUTO_PAN_KEY, &m_enableAutoPan, true );
110 
111  m_canStartBlock = -1; // Command block can start if >= 0
112  m_abortRequest = false;
113  m_ignoreMouseEvents = false;
114  // Be sure a mouse release button event will be ignored when creating the canvas
115  // if the mouse click was not made inside the canvas (can happen sometimes, when
116  // launching a editor from a double click made in another frame)
117  m_ignoreNextLeftButtonRelease = true;
118 
119  m_mouseCaptureCallback = NULL;
120  m_endMouseCaptureCallback = NULL;
121 
122  m_enableBlockCommands = false;
123  m_minDragEventCount = 0;
124 
125  m_cursorLevel = 0;
126  m_PrintIsMirrored = false;
127 
128  m_doubleClickInterval = 250;
129 
130  m_viewControls->SetSnapping( true );
131 
132  SetEvtHandlerEnabled( true );
133  SetFocus();
134  Show( true );
135  Raise();
136  StartDrawing();
137 }
138 
139 
141 {
142 }
143 
144 
146 {
147  view()->Clear();
148  view()->DisplayComponent( const_cast<LIB_PART*>(aComponent) );
149 
150 }
151 
152 
154 {
155  view()->Clear();
156  view()->DisplaySheet( const_cast<SCH_SHEET*>(aSheet) );
157 }
158 
159 
161 {
162  view()->Clear();
163 
164  if( aScreen )
165  view()->DisplaySheet( const_cast<SCH_SCREEN*>( aScreen ) );
166 }
167 
168 
170 {
171  //m_view->RecacheAllItems();
172 }
173 
174 
176 {
177  for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
178  {
179  LAYER_NUM layer = SCH_LAYER_ORDER[i];
180  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
181 
182  m_view->SetLayerOrder( layer, i );
183  }
184 }
185 
186 
188 {
189  VECTOR2D grid_size = m_gal->GetGridSize();
190  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
191  setDefaultLayerDeps();
192  m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
193 
194  // Keep grid size and grid visibility:
195  m_gal->SetGridSize( grid_size );
196  SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParent() );
197 
198  if( frame )
199  m_gal->SetGridVisibility( frame->IsGridVisible() );
200 
201  Refresh();
202 
203  return rv;
204 }
205 
206 
208 {
209  m_enableMousewheelPan = aEnable;
210 
211  if( GetParent()->IsGalCanvasActive() )
212  GetParent()->GetGalCanvas()->GetViewControls()->EnableMousewheelPan( aEnable );
213 }
214 
215 
217 {
219 
220  if( GetParent()->IsGalCanvasActive() )
221  GetParent()->GetGalCanvas()->GetViewControls()->EnableAutoPan( aEnable );
222 }
223 
224 
226 {
227  wxCHECK( GetParent()->IsGalCanvasActive(), /*void*/ );
228  GetParent()->GetGalCanvas()->GetViewControls()->SetAutoPan( aEnable );
229 }
230 
231 
233 {
234  m_enableZoomNoCenter = aEnable;
235 
236  if( GetParent()->IsGalCanvasActive() )
237  GetParent()->GetGalCanvas()->GetViewControls()->EnableCursorWarping( !aEnable );
238 }
239 
240 
242 {
243  // caching makes no sense for Cairo and other software renderers
244  auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
245 
246  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
247  m_view->SetLayerTarget( i, target );
248 
249  // Bitmaps are draw on a non cached GAL layer:
250  m_view->SetLayerTarget( LAYER_DRAW_BITMAPS , KIGFX::TARGET_NONCACHED );
251 
252  // Some draw layers need specific settings
253  m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
254  m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
255 
256  m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
257  m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
258 
259  m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED );
260  m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
261 }
262 
263 
265 {
266  return static_cast<KIGFX::SCH_VIEW*>( m_view );
267 }
268 
270 {
271  return GetParent()->GetScreen();
272 }
273 
275 {
276  return static_cast<EDA_DRAW_FRAME*>(m_parent); // static_cast<SCH_EDIT_FRAME*> (m_parent);
277 }
278 
279 
280 void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
281 {
282  int localbutt = 0;
283  BASE_SCREEN* screen = GetScreen();
284  auto controls = GetViewControls();
285  auto vmp = VECTOR2I( controls->GetMousePosition() );
286  wxPoint mousePos ( vmp.x, vmp.y );
287 
288  event.Skip();
289 
290  if( !screen )
291  return;
292 
293  /* Adjust value to filter mouse displacement before consider the drag
294  * mouse is really a drag command, not just a movement while click
295  */
296 #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5
297 
298  if( event.Leaving() )
299  m_canStartBlock = -1;
300 
301  if( !IsMouseCaptured() ) // No mouse capture in progress.
302  SetAutoPanRequest( false );
303 
304  if( GetParent()->IsActive() )
305  SetFocus();
306  else
307  return;
308 
309  if( !event.IsButton() && !event.Moving() && !event.Dragging() )
310  return;
311 
312  if( event.RightUp() )
313  {
314  OnRightClick( event );
315  return;
316  }
317 
318  if( m_ignoreMouseEvents )
319  return;
320 
321  if( event.LeftDown() )
322  localbutt = GR_M_LEFT_DOWN;
323 
324  if( event.ButtonDClick( 1 ) )
325  localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
326 
327  if( event.MiddleDown() )
328  localbutt = GR_M_MIDDLE_DOWN;
329 
330  // Compute the cursor position in drawing (logical) units.
331  //GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) );
332 
333  int kbstat = 0;
334 
335  if( event.ShiftDown() )
336  kbstat |= GR_KB_SHIFT;
337 
338  if( event.ControlDown() )
339  kbstat |= GR_KB_CTRL;
340 
341  if( event.AltDown() )
342  kbstat |= GR_KB_ALT;
343 
344  // Calling Double Click and Click functions :
345  if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
346  {
347  GetParent()->OnLeftDClick( nullptr, mousePos );
348 
349  // inhibit a response to the mouse left button release,
350  // because we have a double click, and we do not want a new
351  // OnLeftClick command at end of this Double Click
352  m_ignoreNextLeftButtonRelease = true;
353  }
354  else if( event.LeftUp() )
355  {
356  // A block command is in progress: a left up is the end of block
357  // or this is the end of a double click, already seen
358  // Note also m_ignoreNextLeftButtonRelease can be set by
359  // the call to OnLeftClick(), so do not change it after calling OnLeftClick
360  bool ignoreEvt = m_ignoreNextLeftButtonRelease;
361  m_ignoreNextLeftButtonRelease = false;
362 
363  if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt )
364  GetParent()->OnLeftClick( nullptr, mousePos );
365 
366  }
367  else if( !event.LeftIsDown() )
368  {
369  /* be sure there is a response to a left button release command
370  * even when a LeftUp event is not seen. This happens when a
371  * double click opens a dialog box, and the release mouse button
372  * is made when the dialog box is opened.
373  */
374  m_ignoreNextLeftButtonRelease = false;
375  }
376 
377  if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) )
378  {
379  m_PanStartCenter = GetParent()->GetScrollCenterPosition();
380  m_PanStartEventPosition = event.GetPosition();
381 
382  CrossHairOff( );
383  SetCurrentCursor( wxCURSOR_SIZING );
384  }
385 
386  if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) )
387  {
388  CrossHairOn();
389  SetDefaultCursor();
390  }
391 
392  if( event.MiddleIsDown() )
393  {
394  // already managed by EDA_DRAW_PANEL_GAL mouse event handler.
395  return;
396  }
397 
398  // Calling the general function on mouse changes (and pseudo key commands)
399  GetParent()->GeneralControl( nullptr, mousePos );
400 
401  /*******************************/
402  /* Control of block commands : */
403  /*******************************/
404 
405  // Command block can't start if mouse is dragging a new panel
406  static SCH_DRAW_PANEL* lastPanel;
407  if( lastPanel != this )
408  {
409  m_minDragEventCount = 0;
410  m_canStartBlock = -1;
411  }
412 
413  /* A new command block can start after a release buttons
414  * and if the drag is enough
415  * This is to avoid a false start block when a dialog box is dismissed,
416  * or when changing panels in hierarchy navigation
417  * or when clicking while and moving mouse
418  */
419  if( !event.LeftIsDown() && !event.MiddleIsDown() )
420  {
421  m_minDragEventCount = 0;
422  m_canStartBlock = 0;
423 
424  /* Remember the last cursor position when a drag mouse starts
425  * this is the last position ** before ** clicking a button
426  * this is useful to start a block command from the point where the
427  * mouse was clicked first
428  * (a filter creates a delay for the real block command start, and
429  * we must remember this point)
430  */
431  m_CursorStartPos = GetParent()->GetCrossHairPosition();
432  }
433 
434  if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) )
435  {
436  if( !screen->IsBlockActive() )
437  {
438  screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
439  }
440 
441  if( event.LeftDown() )
442  {
443  if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
444  {
445  SetAutoPanRequest( false );
446  GetParent()->HandleBlockPlace( nullptr );
447  m_ignoreNextLeftButtonRelease = true;
448  }
449  }
450  else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() )
451  {
452  // Mouse is dragging: if no block in progress, start a block command.
453  if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
454  {
455  // Start a block command
456  int cmd_type = kbstat;
457 
458  // A block command is started if the drag is enough. A small
459  // drag is ignored (it is certainly a little mouse move when
460  // clicking) not really a drag mouse
461  if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
462  m_minDragEventCount++;
463  else
464  {
465  auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0;
466 
467  DBG(printf("start block\n");)
468 
469  if( !GetParent()->HandleBlockBegin( nullptr, cmd_type, m_CursorStartPos, cmd ) )
470  {
471  // should not occur: error
472  GetParent()->DisplayToolMsg(
473  wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
474  }
475  else
476  {
477  SetAutoPanRequest( true );
478  SetCursor( wxCURSOR_SIZING );
479  }
480  }
481  }
482  }
483 
484  if( event.ButtonUp( wxMOUSE_BTN_LEFT ) )
485  {
486  /* Release the mouse button: end of block.
487  * The command can finish (DELETE) or have a next command (MOVE,
488  * COPY). However the block command is canceled if the block
489  * size is small because a block command filtering is already
490  * made, this case happens, but only when the on grid cursor has
491  * not moved.
492  */
493  #define BLOCK_MINSIZE_LIMIT 1
494  bool BlockIsSmall =
496  && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT );
497 
498  if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall )
499  {
500  if( m_endMouseCaptureCallback )
501  {
502  m_endMouseCaptureCallback( this, nullptr );
503  SetAutoPanRequest( false );
504  }
505 
506  //SetCursor( (wxStockCursor) m_currentCursor );
507  }
508  else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END )
509  {
510  SetAutoPanRequest( false );
511  GetParent()->HandleBlockEnd( nullptr );
512  //SetCursor( (wxStockCursor) m_currentCursor );
513  if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
514  {
515  SetAutoPanRequest( true );
516  SetCursor( wxCURSOR_HAND );
517  }
518  }
519  }
520  }
521 
522  // End of block command on a double click
523  // To avoid an unwanted block move command if the mouse is moved while double clicking
524  if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
525  {
526  if( !screen->IsBlockActive() && IsMouseCaptured() )
527  {
528  m_endMouseCaptureCallback( this, nullptr );
529  }
530  }
531 
532  lastPanel = this;
533 
534 }
535 
536 
537 bool SCH_DRAW_PANEL::OnRightClick( wxMouseEvent& event )
538 {
539  auto controls = GetViewControls();
540  auto vmp = controls->GetMousePosition();
541  wxPoint mouseWorldPos ( (int) vmp.x, (int) vmp.y );
542 
543  wxMenu MasterMenu;
544 
545  if( !GetParent()->OnRightClick( mouseWorldPos, &MasterMenu ) )
546  return false;
547 
548  GetParent()->AddMenuZoomAndGrid( &MasterMenu );
549 
550  m_ignoreMouseEvents = true;
551  PopupMenu( &MasterMenu, event.GetPosition() );
552  m_ignoreMouseEvents = false;
553 
554  return true;
555 }
556 
557 void SCH_DRAW_PANEL::CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase )
558 {
559  wxCHECK_RET( m_mouseCaptureCallback != NULL, wxT( "Mouse capture callback not set." ) );
560 
561  m_mouseCaptureCallback( this, aDC, aPosition, aErase );
562 }
563 
564 
566 {
567  // CallEndMouseCapture is sometimes called with m_endMouseCaptureCallback == NULL
568  // for instance after an ABORT in block paste.
569  if( m_endMouseCaptureCallback )
570  m_endMouseCaptureCallback( this, aDC );
571 }
572 
573 
574 void SCH_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
575  bool aCallEndFunc )
576 {
577  if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc )
578  {
579  m_endMouseCaptureCallback( this, nullptr );
580  }
581 
582  m_mouseCaptureCallback = NULL;
583  m_endMouseCaptureCallback = NULL;
584  SetAutoPanRequest( false );
585 
586  if( id != -1 && cursor != -1 )
587  {
588  //wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX );
589  GetParent()->SetToolID( id, cursor, title );
590  }
591 }
592 
594 {
595  m_viewControls->ShowCursor( false );
596 }
597 
598 
600 {
601  m_viewControls->ShowCursor( true );
602 }
603 
604 
606 {
607  GetViewControls()->WarpCursor( GetParent()->GetCrossHairPosition(), true );
608 }
609 
610 
611 void SCH_DRAW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
612 {
613  EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
614 }
615 
616 
617 void SCH_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
618 {
619  event.Skip();
620 }
621 
622 
623 void SCH_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
624 {
625  int localkey;
626 
627  localkey = event.GetKeyCode();
628 
629  switch( localkey )
630  {
631  default:
632  break;
633 
634  case WXK_ESCAPE:
635  m_abortRequest = true;
636 
637  if( IsMouseCaptured() )
638  EndMouseCapture();
639  else
640  EndMouseCapture( ID_NO_TOOL_SELECTED, 0 /*m_defaultCursor*/, wxEmptyString );
641  break;
642  }
643 
644  /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
645  * They have an ascii code from 1 to 27 remapped
646  * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
647  */
648  if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z )
649  localkey += 'A' - 1;
650 
651  /* Disallow shift for keys that have two keycodes on them (e.g. number and
652  * punctuation keys) leaving only the "letter keys" of A-Z.
653  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
654  * and Ctrl-( and Ctrl-5 (FR layout).
655  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
656  */
657  bool keyIsLetter = ( localkey >= 'A' && localkey <= 'Z' ) ||
658  ( localkey >= 'a' && localkey <= 'z' );
659 
660  if( event.ShiftDown() && ( keyIsLetter || localkey > 256 ) )
661  localkey |= GR_KB_SHIFT;
662 
663  if( event.ControlDown() )
664  localkey |= GR_KB_CTRL;
665 
666  if( event.AltDown() )
667  localkey |= GR_KB_ALT;
668 
669 
670  // Some key commands use the current mouse position: refresh it.
671  //pos = wxGetMousePosition() - GetScreenPosition();
672 
673  // Compute the cursor position in drawing units. Also known as logical units to wxDC.
674  //pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
675 
676  auto p = GetViewControls()->GetCursorPosition( false );
677 
678  wxPoint pos ((int)p.x, (int)p.y);
679 
680  GetParent()->SetMousePosition( pos );
681 
682  if( !GetParent()->GeneralControl( nullptr, pos, localkey ) )
683  event.Skip();
684 }
685 
686 
687 void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
688 {
689  if( !m_gal->IsInitialized() )
690  // The first wxPaintEvent can be fired at startup before the GAL engine is fully initialized
691  // (depending on platforms). Do nothing in this case
692  return;
693 
694  if( m_painter )
695  static_cast<KIGFX::SCH_PAINTER*>(m_painter.get())->GetSettings()->ImportLegacyColors( nullptr );
696 
697  EDA_DRAW_PANEL_GAL::onPaint( aEvent );
698 }
Definition of the SCH_SHEET class for Eeschema.
bool OnRightClick(wxMouseEvent &event)
#define GR_KB_ALT
#define GR_M_DCLICK
Definition: gr_basic.h:77
KIGFX::SCH_VIEW * view() const
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
#define GR_M_MIDDLE_DOWN
Definition: gr_basic.h:76
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
virtual EDA_DRAW_FRAME * GetParent() const override
#define BLOCK_MINSIZE_LIMIT
void OnShow() override
>
to handle and draw images bitmaps
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library...
constexpr double SCH_WORLD_UNIT
Definition: sch_view.h:42
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
virtual void MoveCursorToCrossHair() override
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
int GetHeight() const
Definition: eda_rect.h:118
#define GR_KB_CTRL
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
virtual void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true) override
Function EndMouseCapture ends mouse a capture.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
#define abs(a)
Definition: auxiliary.h:84
WX_VIEW_CONTROLS class definition.
virtual bool IsGridVisible() const
Definition: draw_frame.h:525
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:712
virtual void CallEndMouseCapture(wxDC *aDC) override
Function CallEndMouseCapture calls the end mouse capture callback.
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:48
Auxiliary rendering target (noncached)
Definition: definitions.h:42
static const LAYER_NUM SCH_LAYER_ORDER[]
Definition: sch_view.h:44
void OnMouseEvent(wxMouseEvent &event)
Class that handles properties and drawing of worksheet layout.
bool IsBlockActive() const
Definition: base_screen.h:499
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:51
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase) override
Function CallMouseCapture calls the mouse capture callback.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
virtual void CrossHairOff(wxDC *DC=nullptr) override
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void OnKeyEvent(wxKeyEvent &event)
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
Class SCH_PAINTER Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:112
void SetEnableAutoPan(bool aEnable) override
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent)) override
Define a library symbol object.
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:49
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
virtual void CrossHairOn(wxDC *DC=nullptr) override
general purpose overlay
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
#define GR_KB_SHIFT
bool SwitchBackend(GAL_TYPE aGalType) override
Function SwitchBackend Switches method of rendering graphics.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetAutoPanRequest(bool aEnable) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
#define GR_M_LEFT_DOWN
Definition: gr_basic.h:74
void SetEnableZoomNoCenter(bool aEnable) override
see class PGM_BASE
Main rendering target (cached)
Definition: definitions.h:41
BLOCK_STATE_T GetState() const
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
size_t i
Definition: json11.cpp:597
void DisplaySheet(const SCH_SHEET *aSheet)
currently selected items overlay
int GetWidth() const
Definition: eda_rect.h:117
void OnCharHook(wxKeyEvent &event)
BASE_SCREEN * GetScreen() override
virtual void SetGridVisibility(bool aVisible)
It may be overloaded by derived classes.
Definition: draw_frame.h:534
#define DBG(x)
Definition: fctsys.h:33
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME, and SCH_EDIT_FRAME, and it brings in a common way of handling the provided virtual functions for the derived classes.
virtual void SetEnableAutoPan(bool aEnable)
void DisplayComponent(const LIB_PART *aComponent)
Function DisplayBoard FIXME adds all items from the current board to the VIEW, so they can be display...
void setDefaultLayerOrder()
Reassigns layer order to the initial settings.
void SetEnableMousewheelPan(bool aEnable) override