KiCad PCB EDA Suite
legacy_wx/eda_draw_frame.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) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2018 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 
30 #include <fctsys.h>
31 #include <pgm_base.h>
32 #include <kiface_i.h>
33 #include <gr_basic.h>
34 #include <common.h>
35 #include <bitmaps.h>
36 #include <macros.h>
37 #include <id.h>
38 #include <class_drawpanel.h>
39 #include <base_screen.h>
40 #include <msgpanel.h>
41 #include <draw_frame.h>
42 #include <confirm.h>
43 #include <kicad_device_context.h>
44 #include <dialog_helpers.h>
45 #include <base_units.h>
46 #include <math/box2.h>
47 #include <lockfile.h>
48 #include <trace_helpers.h>
49 
50 #include <wx/clipbrd.h>
51 #include <fctsys.h>
52 #include <gr_basic.h>
53 #include <common.h>
54 #include <id.h>
55 #include <base_screen.h>
56 #include <confirm.h>
57 #include <draw_frame.h>
58 
59 
60 #include <wx/fontdlg.h>
61 #include <wx/snglinst.h>
62 #include <view/view.h>
63 #include <view/view_controls.h>
65 #include <tool/tool_manager.h>
66 #include <tool/tool_dispatcher.h>
67 #include <tool/actions.h>
68 
69 #include <advanced_config.h>
70 #include <menus_helpers.h>
71 #include <page_info.h>
72 #include <title_block.h>
74 
79 static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
80 
81 
84 static const wxString FirstRunShownKeyword( wxT( "FirstRunShown" ) );
85 
87 
101 static const wxString MaxUndoItemsEntry(wxT( "DevelMaxUndoItems" ) );
102 
103 BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
104  EVT_CHAR_HOOK( EDA_DRAW_FRAME::OnCharHook )
105 
106  EVT_MOUSEWHEEL( EDA_DRAW_FRAME::OnMouseEvent )
107  EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen )
108  EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate )
110 
113 
115  EDA_DRAW_FRAME::OnSelectGrid )
116 
117  EVT_TOOL( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnToggleGridState )
119  EDA_DRAW_FRAME::OnSelectUnits )
120 
121  EVT_TOOL( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnToggleCrossHairStyle )
122 
123  EVT_UPDATE_UI( wxID_UNDO, EDA_DRAW_FRAME::OnUpdateUndo )
124  EVT_UPDATE_UI( wxID_REDO, EDA_DRAW_FRAME::OnUpdateRedo )
126  EVT_UPDATE_UI( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnUpdateCrossHairStyle )
128  EDA_DRAW_FRAME::OnUpdateUnits )
129 END_EVENT_TABLE()
130 
131 
132 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
133  FRAME_T aFrameType,
134  const wxString& aTitle,
135  const wxPoint& aPos, const wxSize& aSize,
136  long aStyle, const wxString & aFrameName ) :
137  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
138 {
139  m_socketServer = nullptr;
140  m_drawToolBar = NULL;
141  m_optionsToolBar = NULL;
142  m_auxiliaryToolBar = NULL;
143  m_gridSelectBox = NULL;
144  m_zoomSelectBox = NULL;
145  m_hotkeysDescrList = NULL;
146 
147  m_canvas = NULL;
148  m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
149  m_galCanvas = NULL;
150  m_galCanvasActive = false;
151  m_actions = NULL;
152  m_toolManager = NULL;
153  m_toolDispatcher = NULL;
154  m_messagePanel = NULL;
155  m_currentScreen = NULL;
156  m_toolId = ID_NO_TOOL_SELECTED;
157  m_lastDrawToolId = ID_NO_TOOL_SELECTED;
158  m_showAxis = false; // true to draw axis.
159  m_showBorderAndTitleBlock = false; // true to display reference sheet.
160  m_showGridAxis = false; // true to draw the grid axis
161  m_showOriginAxis = false; // true to draw the grid origin
162  m_LastGridSizeId = 0;
163  m_drawGrid = true; // hide/Show grid. default = show
164  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
165  m_showPageLimits = false;
166  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
167  // BLACK for Pcbnew, BLACK or WHITE for eeschema
168  m_snapToGrid = true;
169  m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
170  m_movingCursorWithKeyboard = false;
171  m_zoomLevelCoeff = 1.0;
172 
173  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
174 
175  CreateStatusBar( 6 );
176 
177  // set the size of the status bar subwindows:
178 
179  wxWindow* stsbar = GetStatusBar();
180 
181  int dims[] = {
182 
183  // remainder of status bar on far left is set to a default or whatever is left over.
184  -1,
185 
186  // When using GetTextSize() remember the width of character '1' is not the same
187  // as the width of '0' unless the font is fixed width, and it usually won't be.
188 
189  // zoom:
190  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
191 
192  // cursor coords
193  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
194 
195  // delta distances
196  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
197 
198  // units display, Inches is bigger than mm
199  GetTextSize( _( "Inches" ), stsbar ).x + 10,
200 
201  // Size for the panel used as "Current tool in play": will take longest string from
202  // void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) in pcbnew/edit.cpp
203  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
204  };
205 
206  SetStatusWidths( arrayDim( dims ), dims );
207 
208  // Create child subwindows.
209  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
210  m_FramePos.x = m_FramePos.y = 0;
211  m_FrameSize.y -= m_MsgFrameHeight;
212 
213  m_canvas = new EDA_DRAW_PANEL( this, -1, wxPoint( 0, 0 ), m_FrameSize );
214  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
215  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
216 
217  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
218 }
219 
220 
222 {
223  delete m_socketServer;
224  for( auto socket : m_sockets )
225  {
226  socket->Shutdown();
227  socket->Destroy();
228  }
229 
231 
232  delete m_actions;
233  delete m_toolManager;
234  delete m_toolDispatcher;
235  delete m_galCanvas;
236 
237  delete m_currentScreen;
238  m_currentScreen = NULL;
239 
240  m_auimgr.UnInit();
241 
242  ReleaseFile();
243 }
244 
245 
246 void EDA_DRAW_FRAME::OnCharHook( wxKeyEvent& event )
247 {
248  wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dump( event ) );
249  // Key events can be filtered here.
250  // Currently no filtering is made.
251  event.Skip();
252 }
253 
254 
256 {
257  m_file_checker = nullptr;
258 }
259 
260 
261 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
262 {
263  m_file_checker = ::LockFile( aFileName );
264 
265  return bool( m_file_checker );
266 }
267 
268 
270 {
271  UpdateStatusBar();
272  UpdateMsgPanel();
273 }
274 
276 {
278 
279  wxConfigBase* settings = Pgm().CommonSettings();
280 
281  int autosaveInterval;
282  settings->Read( AUTOSAVE_INTERVAL_KEY, &autosaveInterval );
283  SetAutoSaveInterval( autosaveInterval );
284 
285  int historySize;
286  settings->Read( FILE_HISTORY_SIZE_KEY, &historySize, DEFAULT_FILE_HISTORY_SIZE );
287  Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
288 
289  bool option;
290  settings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
291  m_canvas->SetEnableMousewheelPan( option );
292 
293  settings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
294  m_canvas->SetEnableZoomNoCenter( option );
295 
296  settings->Read( ENBL_AUTO_PAN_KEY, &option );
297  m_canvas->SetEnableAutoPan( option );
298 
299  int tmp;
302 
305 
307 }
308 
309 
311 {
312  if( m_messagePanel )
314 }
315 
316 
317 void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
318 {
319  if( m_canvas )
320  m_canvas->SetCanStartBlock( -1 );
321 
322  event.Skip(); // required under wxMAC
323 }
324 
325 
326 void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
327 {
328  if( m_canvas )
329  m_canvas->SetCanStartBlock( -1 );
330 
331  event.Skip();
332 }
333 
334 
336 {
338 }
339 
340 
341 void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
342 {
344 
345  if( IsGalCanvasActive() )
346  {
349  }
350 
351  m_canvas->Refresh();
352 }
353 
354 
355 bool EDA_DRAW_FRAME::GetToolToggled( int aToolId )
356 {
357  // Checks all the toolbars and returns true if the given tool id is toggled.
358  return ( ( m_mainToolBar && m_mainToolBar->GetToolToggled( aToolId ) ) ||
359  ( m_optionsToolBar && m_optionsToolBar->GetToolToggled( aToolId ) ) ||
360  ( m_drawToolBar && m_drawToolBar->GetToolToggled( aToolId ) ) ||
361  ( m_auxiliaryToolBar && m_auxiliaryToolBar->GetToolToggled( aToolId ) )
362  );
363 }
364 
365 
366 wxAuiToolBarItem* EDA_DRAW_FRAME::GetToolbarTool( int aToolId )
367 {
368  // Checks all the toolbars and returns a reference to the given tool id
369  // (or the first tool found, but only one or 0 tool is expected, because on
370  // Windows, when different tools have the same ID, it creates issues)
371  if( m_mainToolBar && m_mainToolBar->FindTool( aToolId ) )
372  return m_mainToolBar->FindTool( aToolId );
373 
374  if( m_optionsToolBar && m_optionsToolBar->FindTool( aToolId ) )
375  return m_optionsToolBar->FindTool( aToolId );
376 
377  if( m_drawToolBar && m_drawToolBar->FindTool( aToolId ) )
378  return m_drawToolBar->FindTool( aToolId );
379 
380  if( m_auxiliaryToolBar && m_auxiliaryToolBar->FindTool( aToolId ) )
381  return m_auxiliaryToolBar->FindTool( aToolId );
382 
383  return nullptr;
384 }
385 
386 
387 void EDA_DRAW_FRAME::OnSelectUnits( wxCommandEvent& aEvent )
388 {
389  if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM && m_UserUnits != MILLIMETRES )
390  {
393  }
394  else if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH && m_UserUnits != INCHES )
395  {
398  }
399 }
400 
401 
402 void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent )
403 {
405  m_canvas->CrossHairOff( &dc );
406 
407  auto& galOpts = GetGalDisplayOptions();
408  galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
409  galOpts.NotifyChanged();
410 
411  m_canvas->CrossHairOn( &dc );
412 }
413 
414 
415 void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent )
416 {
417  if( GetScreen() )
418  aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 );
419 }
420 
421 
422 void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent )
423 {
424  if( GetScreen() )
425  aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 );
426 }
427 
428 
429 void EDA_DRAW_FRAME::OnUpdateUnits( wxUpdateUIEvent& aEvent )
430 {
431  bool enable;
432 
433  enable = ( ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM) && (m_UserUnits == MILLIMETRES))
434  || ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH) && (m_UserUnits == INCHES)) );
435 
436  aEvent.Check( enable );
437  DisplayUnitsMsg();
438 }
439 
440 
441 void EDA_DRAW_FRAME::OnUpdateGrid( wxUpdateUIEvent& aEvent )
442 {
443  wxString tool_tip = IsGridVisible() ? _( "Hide grid" ) : _( "Show grid" );
444 
445  aEvent.Check( IsGridVisible() );
446  m_optionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_GRID, tool_tip );
447 }
448 
449 
450 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
451 {
452  // No need to update the grid select box if it doesn't exist or the grid setting change
453  // was made using the select box.
454  if( m_gridSelectBox == NULL || m_auxiliaryToolBar == NULL )
455  return;
456 
457  int select = wxNOT_FOUND;
458 
459  for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
460  {
461  if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId )
462  {
463  select = (int) i;
464  break;
465  }
466  }
467 
468  if( select != m_gridSelectBox->GetSelection() )
469  m_gridSelectBox->SetSelection( select );
470 }
471 
472 
473 void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent )
474 {
475  aEvent.Check( GetGalDisplayOptions().m_fullscreenCursor );
476 }
477 
478 
480 {
481 }
482 
483 
485 {
486 }
487 
488 
489 bool EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
490 {
491  return false;
492 }
493 
495  wxString* aFullFileName )
496 {
497  int result = EDA_BASE_FRAME::WriteHotkeyConfig( aDescList, aFullFileName );
498 
499  if( IsGalCanvasActive() )
501 
502  return result;
503 }
504 
505 void EDA_DRAW_FRAME::ToolOnRightClick( wxCommandEvent& event )
506 {
507 }
508 
509 
510 void EDA_DRAW_FRAME::PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMode, void* aData )
511 {
512  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
513 }
514 
515 
516 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
517 {
518  int* clientData;
519  int eventId = ID_POPUP_GRID_LEVEL_100;
520 
521  if( event.GetEventType() == wxEVT_CHOICE )
522  {
523  if( m_gridSelectBox == NULL ) // Should not happen
524  return;
525 
526  /*
527  * Don't use wxCommandEvent::GetClientData() here. It always
528  * returns NULL in GTK. This solution is not as elegant but
529  * it works.
530  */
531  int index = m_gridSelectBox->GetSelection();
532  wxASSERT( index != wxNOT_FOUND );
533 
534  if( index == int( m_gridSelectBox->GetCount() - 2 ) )
535  {
536  // this is the separator
537  wxUpdateUIEvent dummy;
539  return;
540  }
541  else if( index == int( m_gridSelectBox->GetCount() - 1 ) )
542  {
543  wxUpdateUIEvent dummy;
545  wxCommandEvent dummy2;
546  OnGridSettings( dummy2 );
547  return;
548  }
549 
550  clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
551 
552  if( clientData != NULL )
553  eventId = *clientData;
554  }
555  else
556  {
557  eventId = event.GetId();
558  }
559 
560  int idx = eventId - ID_POPUP_GRID_LEVEL_1000;
561 
562  // Notify GAL
563  TOOL_MANAGER* mgr = GetToolManager();
564 
565  if( mgr && IsGalCanvasActive() )
566  mgr->RunAction( "common.Control.gridPreset", true, idx );
567  else
568  SetPresetGrid( idx );
569 
570  m_canvas->Refresh();
571 }
572 
573 
574 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
575 {
576  if( m_zoomSelectBox == NULL )
577  return; // Should not happen!
578 
579  int id = m_zoomSelectBox->GetCurrentSelection();
580 
581  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
582  return;
583 
584  if( IsGalCanvasActive() )
585  {
586  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
587  UpdateStatusBar();
588  m_galCanvas->Refresh();
589  }
590  else if( id == 0 ) // Auto zoom (Fit in Page)
591  {
592  Zoom_Automatique( true );
593  m_canvas->Refresh();
594  }
595  else
596  {
597  double selectedZoom = GetScreen()->m_ZoomList[id-1];
598 
599  if( GetScreen()->SetZoom( selectedZoom ) )
601  }
602 }
603 
604 
606 {
607  return GetScreen()->GetZoom();
608 }
609 
610 
611 void EDA_DRAW_FRAME::OnMouseEvent( wxMouseEvent& event )
612 {
613  event.Skip();
614 }
615 
616 
617 void EDA_DRAW_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
618 {
619 }
620 
621 
622 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
623 {
624  SetStatusText( msg, 5 );
625 }
626 
627 
629 {
630  wxString msg;
631 
632  switch( m_UserUnits )
633  {
634  case INCHES:
635  msg = _( "Inches" );
636  break;
637 
638  case MILLIMETRES:
639  msg = _( "mm" );
640  break;
641 
642  default:
643  msg = _( "Units" );
644  break;
645  }
646 
647  SetStatusText( msg, 4 );
648 }
649 
650 
651 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
652 {
653  m_FrameSize = GetClientSize( );
654 
655  SizeEv.Skip();
656 }
657 
658 
659 void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
660 {
661  // Keep default cursor in toolbars
662  SetCursor( wxNullCursor );
663 
664  // Change m_canvas cursor if requested.
665  if( m_canvas && aCursor >= 0 )
666  m_canvas->SetCurrentCursor( aCursor );
667 
668  // Change GAL canvas cursor if requested.
669  if( IsGalCanvasActive() && aCursor >= 0 )
670  GetGalCanvas()->SetCurrentCursor( aCursor );
671 
672  DisplayToolMsg( aToolMsg );
673 
674  if( aId < 0 )
675  return;
676 
677  wxCHECK2_MSG( aId >= ID_NO_TOOL_SELECTED, aId = ID_NO_TOOL_SELECTED,
678  wxString::Format( wxT( "Current tool ID cannot be set to %d." ), aId ) );
679 
680  m_toolId = aId;
681 }
682 
683 
685 {
686  // Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
687 
688  int defaultCursor = wxCURSOR_DEFAULT;
689 
690  // Change GAL canvas cursor if requested.
691  if( IsGalCanvasActive() )
692  defaultCursor = GetGalCanvas()->GetDefaultCursor();
693  else if( m_canvas )
694  defaultCursor = m_canvas->GetDefaultCursor();
695 
696  SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString );
697 }
698 
699 
700 wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
701 {
702  wxPoint pos = aPosition;
703 
704  if( m_currentScreen != NULL && m_snapToGrid )
705  pos = GetNearestGridPosition( aPosition );
706 
707  return pos;
708 }
709 
710 
712 {
713  BASE_SCREEN * screen = GetScreen();
714 
715  int new_grid_cmd = screen->GetGridCmdId();
716 
717  // if the grid id is the not the last, increment it
718  if( screen->GridExists( new_grid_cmd + 1 ) )
719  new_grid_cmd += 1;
720 
721  SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
722 }
723 
724 
726 {
727  BASE_SCREEN * screen = GetScreen();
728 
729  int new_grid_cmd = screen->GetGridCmdId();
730 
731  // if the grid id is the not the first, increment it
732  if( screen->GridExists( new_grid_cmd - 1 ) )
733  new_grid_cmd -= 1;
734 
735  SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
736 }
737 
738 
739 void EDA_DRAW_FRAME::SetPresetGrid( int aIndex )
740 {
741  BASE_SCREEN * screen = GetScreen();
742 
743  if( ! screen->GridExists( aIndex + ID_POPUP_GRID_LEVEL_1000 ) )
744  aIndex = screen->GetGrids()[0].m_CmdId;
745 
746  // aIndex is a Command Id relative to ID_POPUP_GRID_LEVEL_1000 comand id code.
747  // we need an index in grid list (the cmd id in list is is screen->GetGrids()[0].m_CmdId):
748  int glistIdx = aIndex + ID_POPUP_GRID_LEVEL_1000 - screen->GetGrids()[0].m_CmdId;
749 
750  if( m_gridSelectBox )
751  {
752  if( glistIdx < 0 || glistIdx >= (int) m_gridSelectBox->GetCount() - 2 )
753  {
754  wxASSERT_MSG( false, "Invalid grid index" );
755  return;
756  }
757 
758  m_gridSelectBox->SetSelection( glistIdx );
759  }
760 
761  // Be sure m_LastGridSizeId is up to date.
762  m_LastGridSizeId = aIndex;
764 
765  // Put cursor on new grid
766  SetCrossHairPosition( RefPos( true ) );
767 }
768 
769 
771 {
772  return 0;
773 }
774 
775 
777 {
780 }
781 
782 
783 void EDA_DRAW_FRAME::HandleBlockPlace( wxDC* DC )
784 {
785 }
786 
787 
788 bool EDA_DRAW_FRAME::HandleBlockEnd( wxDC* DC )
789 {
790  return false;
791 }
792 
793 
795 {
796  SetStatusText( GetZoomLevelIndicator(), 1 );
797 
798  // Absolute and relative cursor positions are handled by overloading this function and
799  // handling the internal to user units conversion at the appropriate level.
800 
801  // refresh units display
802  DisplayUnitsMsg();
803 }
804 
805 
806 const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const
807 {
808  wxString Line;
809  double level = 0.0;
810 
811  if( IsGalCanvasActive() )
812  {
813  level = m_galCanvas->GetGAL()->GetZoomFactor();
814  }
815  else if( BASE_SCREEN* screen = GetScreen() )
816  {
817  level = m_zoomLevelCoeff / (double) screen->GetZoom();
818  }
819 
820  // returns a human readable value which can be displayed as zoom
821  // level indicator in dialogs.
822  Line.Printf( wxT( "Z %.2f" ), level );
823 
824  return Line;
825 }
826 
827 
828 void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
829 {
831 
832  wxString baseCfgName = ConfigBaseName();
833  wxConfigBase* cmnCfg = Pgm().CommonSettings();
834 
835  // Read units used in dialogs and toolbars
836  EDA_UNITS_T unitsTmp;
837 
838  if( aCfg->Read( baseCfgName + UserUnitsEntryKeyword, (int*) &unitsTmp ) )
839  SetUserUnits( unitsTmp );
840  else
842 
843  // Read show/hide grid entry
844  bool btmp;
845  if( aCfg->Read( baseCfgName + ShowGridEntryKeyword, &btmp ) )
846  SetGridVisibility( btmp );
847 
848  // Read grid color:
849  COLOR4D wtmp = COLOR4D::UNSPECIFIED;
850 
851  if( wtmp.SetFromWxString( aCfg->Read( baseCfgName + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
852  SetGridColor( wtmp );
853 
854  aCfg->Read( baseCfgName + LastGridSizeIdKeyword, &m_LastGridSizeId, 0L );
855 
856  // m_LastGridSizeId is an offset, expected to be >= 0
857  if( m_LastGridSizeId < 0 )
858  m_LastGridSizeId = 0;
859 
860  m_UndoRedoCountMax = aCfg->Read( baseCfgName + MaxUndoItemsEntry,
861  long( DEFAULT_MAX_UNDO_ITEMS ) );
862 
863  aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
864 
866 
867  int temp;
870 
873 
875 }
876 
877 
878 void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
879 {
881 
882  wxString baseCfgName = ConfigBaseName();
883 
884  aCfg->Write( baseCfgName + UserUnitsEntryKeyword, (int) m_UserUnits );
885  aCfg->Write( baseCfgName + ShowGridEntryKeyword, IsGridVisible() );
886  aCfg->Write( baseCfgName + GridColorEntryKeyword,
887  GetGridColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) );
888  aCfg->Write( baseCfgName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
889  aCfg->Write( baseCfgName + FirstRunShownKeyword, m_firstRunDialogSetting );
890 
891  if( GetScreen() )
892  aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
893 
895 }
896 
897 
898 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper,
899  const wxString& textLower,
900  COLOR4D color, int pad )
901 {
902  if( m_messagePanel == NULL )
903  return;
904 
905  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
906 }
907 
908 
910 {
911  if( m_messagePanel == NULL )
912  return;
913 
915 }
916 
917 
918 void EDA_DRAW_FRAME::SetMsgPanel( const MSG_PANEL_ITEMS& aList )
919 {
920  if( m_messagePanel == NULL )
921  return;
922 
923  ClearMsgPanel();
924 
925  for( unsigned i = 0; i < aList.size(); i++ )
926  m_messagePanel->AppendMessage( aList[i] );
927 }
928 
929 
931 {
932  wxCHECK_RET( aItem != NULL, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
933 
934  MSG_PANEL_ITEMS items;
935  aItem->GetMsgPanelInfo( m_UserUnits, items );
936  SetMsgPanel( items );
937 }
938 
939 
941 {
942  EDA_ITEM* item = GetScreen()->GetCurItem();
943 
944  if( item )
945  SetMsgPanel( item );
946 }
947 
948 
949 // FIXME: There needs to be a better way for child windows to load preferences.
950 // This function pushes four preferences from a parent window to a child window
951 // i.e. from eeschema to the schematic symbol editor
952 void EDA_DRAW_FRAME::PushPreferences( const EDA_DRAW_PANEL* aParentCanvas )
953 {
955  m_canvas->SetEnableAutoPan( aParentCanvas->GetEnableAutoPan() );
956 }
957 
958 
959 bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition,
960  int aExplicitCommand )
961 {
963 
964  if( ( block->GetCommand() != BLOCK_IDLE ) || ( block->GetState() != STATE_NO_BLOCK ) )
965  return false;
966 
967  if( aExplicitCommand == 0 )
968  block->SetCommand( (BLOCK_COMMAND_T) BlockCommand( aKey ) );
969  else
970  block->SetCommand( (BLOCK_COMMAND_T) aExplicitCommand );
971 
972  if( block->GetCommand() == 0 )
973  return false;
974 
975  switch( block->GetCommand() )
976  {
977  case BLOCK_IDLE:
978  break;
979 
980  case BLOCK_MOVE: // Move
981  case BLOCK_DRAG: // Drag (block defined)
982  case BLOCK_DRAG_ITEM: // Drag from a drag item command
983  case BLOCK_DUPLICATE: // Duplicate
984  case BLOCK_DUPLICATE_AND_INCREMENT: // Duplicate and increment relevant references
985  case BLOCK_DELETE: // Delete
986  case BLOCK_COPY: // Copy
987  case BLOCK_FLIP: // Flip
988  case BLOCK_ZOOM: // Window Zoom
989  case BLOCK_PRESELECT_MOVE: // Move with preselection list
990  block->InitData( m_canvas, aPosition );
991  break;
992 
993  case BLOCK_PASTE:
994  block->InitData( m_canvas, aPosition );
995  block->SetLastCursorPosition( wxPoint( 0, 0 ) );
997 
998  if( block->GetCount() == 0 ) // No data to paste
999  {
1000  DisplayError( this, wxT( "No block to paste" ), 20 );
1003  block->SetState( STATE_NO_BLOCK );
1004  block->SetMessageBlock( this );
1005  return true;
1006  }
1007 
1008  if( !m_canvas->IsMouseCaptured() )
1009  {
1010  block->ClearItemsList();
1011  DisplayError( this,
1012  wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: m_mouseCaptureCallback NULL" ) );
1013  block->SetState( STATE_NO_BLOCK );
1014  block->SetMessageBlock( this );
1015  return true;
1016  }
1017 
1018  block->SetState( STATE_BLOCK_MOVE );
1019  m_canvas->CallMouseCapture( aDC, aPosition, false );
1020  break;
1021 
1022  default:
1023  {
1024  wxString msg;
1025  msg << wxT( "EDA_DRAW_FRAME::HandleBlockBegin() error: Unknown command " ) <<
1026  block->GetCommand();
1027  DisplayError( this, msg );
1028  }
1029  break;
1030  }
1031 
1032  block->SetMessageBlock( this );
1033  return true;
1034 }
1035 
1036 
1037 // I am not seeing a problem with this size yet:
1038 static const double MAX_AXIS = INT_MAX - 100;
1039 
1040 #define VIRT_MIN (-MAX_AXIS/2.0)
1041 #define VIRT_MAX (MAX_AXIS/2.0)
1042 
1043 
1044 void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
1045 {
1046  BASE_SCREEN* screen = GetScreen();
1047 
1048  if( !screen || !m_canvas )
1049  return;
1050 
1051  double scale = screen->GetScalingFactor();
1052 
1053  wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scale = %.10g" ),
1054  aCenterPositionIU.x, aCenterPositionIU.y, scale );
1055 
1056  // Calculate the portion of the drawing that can be displayed in the
1057  // client area at the current zoom level.
1058 
1059  // visible viewport in device units ~ pixels
1060  wxSize clientSizeDU = m_canvas->GetClientSize();
1061 
1062  // Size of the client window in IU
1063  DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale );
1064 
1065  // Full drawing or "page" rectangle in internal units
1066  DBOX pageRectIU( wxPoint( 0, 0 ), wxSize( GetPageSizeIU().x, GetPageSizeIU().y ) );
1067 
1068  // Remark: if something is modified here, perhaps EDA_DRAW_FRAME::RedrawScreen2()
1069  // will need changes accordint to the way the center is computed
1070  // Account for scrollbars
1071  wxSize scrollbarSizeDU = m_canvas->GetSize() - m_canvas->GetClientSize();
1072  wxSize scrollbarSizeIU = scrollbarSizeDU * (1 / scale);
1073  wxPoint centerAdjustedIU = aCenterPositionIU + scrollbarSizeIU / 2;
1074 
1075  // The upper left corner of the client rectangle in internal units.
1076  double xIU = centerAdjustedIU.x - clientSizeIU.x / 2.0;
1077  double yIU = centerAdjustedIU.y - clientSizeIU.y / 2.0;
1078 
1079  // If drawn around the center, adjust the client rectangle accordingly.
1080  if( screen->m_Center )
1081  {
1082  // half page offset.
1083  xIU += pageRectIU.GetWidth() / 2.0;
1084  yIU += pageRectIU.GetHeight() / 2.0;
1085  }
1086 
1087  DBOX clientRectIU( wxPoint( xIU, yIU ), wxSize( clientSizeIU.x, clientSizeIU.y ) );
1088  wxPoint centerPositionIU;
1089 
1090  // put "int" limits on the clientRect
1091  if( clientRectIU.GetLeft() < VIRT_MIN )
1092  clientRectIU.MoveLeftTo( VIRT_MIN );
1093  if( clientRectIU.GetTop() < VIRT_MIN )
1094  clientRectIU.MoveTopTo( VIRT_MIN );
1095  if( clientRectIU.GetRight() > VIRT_MAX )
1096  clientRectIU.MoveRightTo( VIRT_MAX );
1097  if( clientRectIU.GetBottom() > VIRT_MAX )
1098  clientRectIU.MoveBottomTo( VIRT_MAX );
1099 
1100  centerPositionIU.x = KiROUND( clientRectIU.GetX() + clientRectIU.GetWidth() / 2 );
1101  centerPositionIU.y = KiROUND( clientRectIU.GetY() + clientRectIU.GetHeight() / 2 );
1102 
1103  if( screen->m_Center )
1104  {
1105  centerPositionIU.x -= KiROUND( pageRectIU.GetWidth() / 2.0 );
1106  centerPositionIU.y -= KiROUND( pageRectIU.GetHeight() / 2.0 );
1107  }
1108 
1109  DSIZE virtualSizeIU;
1110 
1111  if( pageRectIU.GetLeft() < clientRectIU.GetLeft() && pageRectIU.GetRight() > clientRectIU.GetRight() )
1112  {
1113  virtualSizeIU.x = pageRectIU.GetSize().x;
1114  }
1115  else
1116  {
1117  double pageCenterX = pageRectIU.GetX() + ( pageRectIU.GetWidth() / 2 );
1118  double clientCenterX = clientRectIU.GetX() + ( clientRectIU.GetWidth() / 2 );
1119 
1120  if( clientRectIU.GetWidth() > pageRectIU.GetWidth() )
1121  {
1122  if( pageCenterX > clientCenterX )
1123  virtualSizeIU.x = ( pageCenterX - clientRectIU.GetLeft() ) * 2;
1124  else if( pageCenterX < clientCenterX )
1125  virtualSizeIU.x = ( clientRectIU.GetRight() - pageCenterX ) * 2;
1126  else
1127  virtualSizeIU.x = clientRectIU.GetWidth();
1128  }
1129  else
1130  {
1131  if( pageCenterX > clientCenterX )
1132  virtualSizeIU.x = pageRectIU.GetWidth() + ( (pageRectIU.GetLeft() - clientRectIU.GetLeft() ) * 2 );
1133  else if( pageCenterX < clientCenterX )
1134  virtualSizeIU.x = pageRectIU.GetWidth() + ( (clientRectIU.GetRight() - pageRectIU.GetRight() ) * 2 );
1135  else
1136  virtualSizeIU.x = pageRectIU.GetWidth();
1137  }
1138  }
1139 
1140  if( pageRectIU.GetTop() < clientRectIU.GetTop() && pageRectIU.GetBottom() > clientRectIU.GetBottom() )
1141  {
1142  virtualSizeIU.y = pageRectIU.GetSize().y;
1143  }
1144  else
1145  {
1146  double pageCenterY = pageRectIU.GetY() + ( pageRectIU.GetHeight() / 2 );
1147  double clientCenterY = clientRectIU.GetY() + ( clientRectIU.GetHeight() / 2 );
1148 
1149  if( clientRectIU.GetHeight() > pageRectIU.GetHeight() )
1150  {
1151  if( pageCenterY > clientCenterY )
1152  virtualSizeIU.y = ( pageCenterY - clientRectIU.GetTop() ) * 2;
1153  else if( pageCenterY < clientCenterY )
1154  virtualSizeIU.y = ( clientRectIU.GetBottom() - pageCenterY ) * 2;
1155  else
1156  virtualSizeIU.y = clientRectIU.GetHeight();
1157  }
1158  else
1159  {
1160  if( pageCenterY > clientCenterY )
1161  virtualSizeIU.y = pageRectIU.GetHeight() +
1162  ( ( pageRectIU.GetTop() - clientRectIU.GetTop() ) * 2 );
1163  else if( pageCenterY < clientCenterY )
1164  virtualSizeIU.y = pageRectIU.GetHeight() +
1165  ( ( clientRectIU.GetBottom() - pageRectIU.GetBottom() ) * 2 );
1166  else
1167  virtualSizeIU.y = pageRectIU.GetHeight();
1168  }
1169  }
1170 
1171  // put "int" limits on the virtualSizeIU
1172  virtualSizeIU.x = std::min( virtualSizeIU.x, MAX_AXIS );
1173  virtualSizeIU.y = std::min( virtualSizeIU.y, MAX_AXIS );
1174 
1175  if( screen->m_Center )
1176  {
1177  screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 );
1178  screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 );
1179  }
1180  else
1181  {
1182  screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.GetWidth() ) / 2.0 );
1183  screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.GetHeight() ) / 2.0 );
1184  }
1185 
1186  /* Always set scrollbar pixels per unit to 1 unless you want the zoom
1187  * around cursor to jump around. This reported problem occurs when the
1188  * zoom point is not on a pixel per unit increment. If you set the
1189  * pixels per unit to 10, you have potential for the zoom point to
1190  * jump around +/-5 pixels from the nearest grid point.
1191  */
1192  screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1;
1193 
1194  // Number of scroll bar units for the given zoom level in device units.
1195  double unitsX = virtualSizeIU.x * scale;
1196  double unitsY = virtualSizeIU.y * scale;
1197 
1198  // Store the requested center position for later use
1199  SetScrollCenterPosition( aCenterPositionIU );
1200 
1201  // Calculate the scroll bar position in internal units to place the
1202  // center position at the center of client rectangle.
1203  double posX = centerPositionIU.x - clientRectIU.GetWidth() / 2.0 - screen->m_DrawOrg.x;
1204  double posY = centerPositionIU.y - clientRectIU.GetHeight() / 2.0 - screen->m_DrawOrg.y;
1205 
1206  // Convert scroll bar position to device units.
1207  posX = KiROUND( posX * scale );
1208  posY = KiROUND( posY * scale );
1209 
1210  if( posX < 0 )
1211  {
1212  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
1213  posX = 0;
1214  }
1215 
1216  if( posX > unitsX )
1217  {
1218  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
1219  posX = unitsX;
1220  }
1221 
1222  if( posY < 0 )
1223  {
1224  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
1225  posY = 0;
1226  }
1227 
1228  if( posY > unitsY )
1229  {
1230  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
1231  posY = unitsY;
1232  }
1233 
1234  screen->m_ScrollbarPos = wxPoint( KiROUND( posX ), KiROUND( posY ) );
1235  screen->m_ScrollbarNumber = wxSize( KiROUND( unitsX ), KiROUND( unitsY ) );
1236 
1237  wxLogTrace( traceScrollSettings,
1238  wxT( "Drawing = (%.10g, %.10g), Client = (%.10g, %.10g), Offset = (%d, %d), SetScrollbars(%d, %d, %d, %d, %d, %d)" ),
1239  virtualSizeIU.x, virtualSizeIU.y, clientSizeIU.x, clientSizeIU.y,
1240  screen->m_DrawOrg.x, screen->m_DrawOrg.y,
1242  screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y,
1243  screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y );
1244 
1245  bool noRefresh = true;
1246 
1247  m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX,
1248  screen->m_ScrollPixelsPerUnitY,
1249  screen->m_ScrollbarNumber.x,
1250  screen->m_ScrollbarNumber.y,
1251  screen->m_ScrollbarPos.x,
1252  screen->m_ScrollbarPos.y, noRefresh );
1253 }
1254 
1255 
1256 void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
1257 {
1258  KIGFX::VIEW* view = GetGalCanvas()->GetView();
1259  KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
1260 
1261  // Display the same view after canvas switching
1262  if( aEnable )
1263  {
1264  // Switch to GAL renderer from legacy
1265  if( !m_galCanvasActive )
1266  {
1267  // Set up viewport
1268  view->SetScale( GetZoomLevelCoeff() / m_canvas->GetZoom() );
1270  }
1271 
1272  // Set up grid settings
1273  gal->SetGridVisibility( IsGridVisible() );
1274  gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
1275  gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
1276 
1277  // Transfer EDA_DRAW_PANEL settings
1278  KIGFX::VIEW_CONTROLS* viewControls = GetGalCanvas()->GetViewControls();
1279  viewControls->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() );
1281  viewControls->EnableAutoPan( m_canvas->GetEnableAutoPan() );
1282  }
1283  else if( m_galCanvasActive )
1284  {
1285  // Switch to legacy renderer from GAL
1286  m_canvas->SetZoom( GetGalCanvas()->GetLegacyZoom() );
1287  VECTOR2D center = view->GetCenter();
1288  AdjustScrollBars( wxPoint( center.x, center.y ) );
1289  }
1290 
1291  m_canvas->SetEvtHandlerEnabled( !aEnable );
1292  GetGalCanvas()->SetEvtHandlerEnabled( aEnable );
1293 
1294  // Switch panes
1295  m_auimgr.GetPane( "DrawFrame" ).Show( !aEnable );
1296  m_auimgr.GetPane( "DrawFrameGal" ).Show( aEnable );
1297  m_auimgr.Update();
1298 
1299  // Reset current tool on switch();
1301 
1302  m_galCanvasActive = aEnable;
1303 }
1304 
1305 
1307 {
1308  auto galCanvas = GetGalCanvas();
1309  wxCHECK( galCanvas, false );
1310  bool use_gal = galCanvas->SwitchBackend( aCanvasType );
1311  use_gal &= aCanvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1312  UseGalCanvas( use_gal );
1313  m_canvasType = use_gal ? aCanvasType : EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1314 
1315  return use_gal;
1316 }
1317 
1318 
1320 {
1322  wxConfigBase* cfg = Kiface().KifaceSettings();
1323 
1324  if( cfg )
1325  {
1326  canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE)
1328  }
1329 
1330  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1331  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1332  {
1333  assert( false );
1334  canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1335  }
1336 
1337  // Coerce the value into a GAL type when Legacy is not available
1338  // Default to Cairo, and on the first, user will be prompted for OpenGL
1339  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1340  && !ADVANCED_CFG::GetCfg().AllowLegacyCanvas() )
1341  {
1342 #ifdef __WXMAC__
1343  // Cairo renderer doesn't handle Retina displays
1345 #else
1347 #endif
1348  }
1349 
1350  return canvasType;
1351 }
1352 
1353 
1355 {
1356  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
1357  // have a fixed type, or do not have a option to set the canvas type (they inherit from
1358  // a parent frame)
1359  FRAME_T allowed_frames[] =
1360  {
1362  };
1363 
1364  bool allow_save = false;
1365 
1366  for( int ii = 0; ii < 3; ii++ )
1367  {
1368  if( m_Ident == allowed_frames[ii] )
1369  {
1370  allow_save = true;
1371  break;
1372  }
1373  }
1374 
1375  if( !allow_save )
1376  return false;
1377 
1378  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1379  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1380  {
1381  wxASSERT( false );
1382  return false;
1383  }
1384 
1385  wxConfigBase* cfg = Kiface().KifaceSettings();
1386 
1387  if( cfg )
1388  return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
1389 
1390  return false;
1391 }
1392 
1393 //-----< BASE_SCREEN API moved here >--------------------------------------------
1394 
1395 wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const
1396 {
1397  // subject to change, borrow from old BASE_SCREEN for now.
1398  if( IsGalCanvasActive() )
1399  {
1401 
1402  return wxPoint( cursor.x, cursor.y );
1403  }
1404  else
1405  {
1406  BASE_SCREEN* screen = GetScreen(); // virtual call
1407  return screen->getCrossHairPosition( aInvertY );
1408  }
1409 }
1410 
1411 
1412 void EDA_DRAW_FRAME::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
1413 {
1414  BASE_SCREEN* screen = GetScreen(); // virtual call
1415  screen->setCrossHairPosition( aPosition, GetGridOrigin(), aSnapToGrid );
1416 }
1417 
1418 
1419 wxPoint EDA_DRAW_FRAME::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) const
1420 {
1421  BASE_SCREEN* screen = GetScreen(); // virtual call
1422  return screen->getCursorPosition( aOnGrid, GetGridOrigin(), aGridSize );
1423 }
1424 
1425 
1426 wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize ) const
1427 {
1428  BASE_SCREEN* screen = GetScreen(); // virtual call
1429  return screen->getNearestGridPosition( aPosition, GetGridOrigin(), aGridSize );
1430 }
1431 
1432 
1434 {
1435  BASE_SCREEN* screen = GetScreen(); // virtual call
1436  return screen->getCrossHairScreenPosition();
1437 }
1438 
1439 
1440 void EDA_DRAW_FRAME::SetMousePosition( const wxPoint& aPosition )
1441 {
1442  BASE_SCREEN* screen = GetScreen(); // virtual call
1443  screen->setMousePosition( aPosition );
1444 }
1445 
1446 
1447 wxPoint EDA_DRAW_FRAME::RefPos( bool useMouse ) const
1448 {
1449  BASE_SCREEN* screen = GetScreen(); // virtual call
1450  return screen->refPos( useMouse );
1451 }
1452 
1453 
1454 const wxPoint& EDA_DRAW_FRAME::GetScrollCenterPosition() const
1455 {
1456  BASE_SCREEN* screen = GetScreen(); // virtual call
1457  return screen->getScrollCenterPosition();
1458 }
1459 
1460 
1461 void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint )
1462 {
1463  BASE_SCREEN* screen = GetScreen(); // virtual call
1464  screen->setScrollCenterPosition( aPoint );
1465 }
1466 
1467 //-----</BASE_SCREEN API moved here >--------------------------------------------
1468 
1469 void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC* aDC )
1470 {
1471  wxPoint newpos = GetCrossHairPosition();
1472 
1473  // Redraw the crosshair if it moved
1474  if( aOldPos != newpos )
1475  {
1476  SetCrossHairPosition( aOldPos, false );
1477  m_canvas->CrossHairOff( aDC );
1478  SetCrossHairPosition( newpos, false );
1479  m_canvas->CrossHairOn( aDC );
1480 
1481  if( m_canvas->IsMouseCaptured() )
1482  {
1483 #ifdef USE_WX_OVERLAY
1484  wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
1485  oDC.Clear();
1486  m_canvas->CallMouseCapture( aDC, aEvtPos, false );
1487 #else
1488  m_canvas->CallMouseCapture( aDC, aEvtPos, true );
1489 #endif
1490  }
1491 #ifdef USE_WX_OVERLAY
1492  else
1493  {
1494  m_overlay.Reset();
1495  }
1496 #endif
1497  }
1498 }
1499 
1500 
1501 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
1502  const wxString& wildcard, const wxString& ext,
1503  bool isDirectory )
1504 {
1505  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
1506  aFilename.SetExt( ext );
1507 
1508 #ifndef __WXMAC__
1509  if( isDirectory && doOpen )
1510  {
1511  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
1512  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1513 
1514  if( dlg.ShowModal() == wxID_CANCEL )
1515  return false;
1516 
1517  aFilename = dlg.GetPath();
1518  aFilename.SetExt( ext );
1519  }
1520  else
1521 #endif
1522  {
1523  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
1524  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1525  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1526 
1527  if( dlg.ShowModal() == wxID_CANCEL )
1528  return false;
1529 
1530  aFilename = dlg.GetPath();
1531  aFilename.SetExt( ext );
1532  }
1533 
1534  return true;
1535 }
1536 
1537 
1538 bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid )
1539 {
1540  bool key_handled = false;
1541 
1542  // If requested snap the current position to the grid
1543  if( aSnapToGrid )
1544  *aPos = GetNearestGridPosition( *aPos );
1545 
1546  switch( aHotKey )
1547  {
1548  // All these keys have almost the same treatment
1549  case GR_KB_CTRL | WXK_NUMPAD8:
1550  case GR_KB_CTRL | WXK_UP:
1551  case GR_KB_CTRL | WXK_NUMPAD2:
1552  case GR_KB_CTRL | WXK_DOWN:
1553  case GR_KB_CTRL | WXK_NUMPAD4:
1554  case GR_KB_CTRL | WXK_LEFT:
1555  case GR_KB_CTRL | WXK_NUMPAD6:
1556  case GR_KB_CTRL | WXK_RIGHT:
1557  case WXK_NUMPAD8:
1558  case WXK_UP:
1559  case WXK_NUMPAD2:
1560  case WXK_DOWN:
1561  case WXK_NUMPAD4:
1562  case WXK_LEFT:
1563  case WXK_NUMPAD6:
1564  case WXK_RIGHT:
1565  key_handled = true;
1566  {
1567  /* Here's a tricky part: when doing cursor key movement, the
1568  * 'previous' point should be taken from memory, *not* from the
1569  * freshly computed position in the event. Otherwise you can't do
1570  * sub-pixel movement. The m_movingCursorWithKeyboard oneshot 'eats'
1571  * the automatic motion event generated by cursor warping */
1572  wxRealPoint gridSize = GetScreen()->GetGridSize();
1573  *aPos = GetCrossHairPosition();
1574 
1575  // Bonus: ^key moves faster (x10)
1576  switch( aHotKey )
1577  {
1578  case GR_KB_CTRL|WXK_NUMPAD8:
1579  case GR_KB_CTRL|WXK_UP:
1580  aPos->y -= KiROUND( 10 * gridSize.y );
1581  break;
1582 
1583  case GR_KB_CTRL|WXK_NUMPAD2:
1584  case GR_KB_CTRL|WXK_DOWN:
1585  aPos->y += KiROUND( 10 * gridSize.y );
1586  break;
1587 
1588  case GR_KB_CTRL|WXK_NUMPAD4:
1589  case GR_KB_CTRL|WXK_LEFT:
1590  aPos->x -= KiROUND( 10 * gridSize.x );
1591  break;
1592 
1593  case GR_KB_CTRL|WXK_NUMPAD6:
1594  case GR_KB_CTRL|WXK_RIGHT:
1595  aPos->x += KiROUND( 10 * gridSize.x );
1596  break;
1597 
1598  case WXK_NUMPAD8:
1599  case WXK_UP:
1600  aPos->y -= KiROUND( gridSize.y );
1601  break;
1602 
1603  case WXK_NUMPAD2:
1604  case WXK_DOWN:
1605  aPos->y += KiROUND( gridSize.y );
1606  break;
1607 
1608  case WXK_NUMPAD4:
1609  case WXK_LEFT:
1610  aPos->x -= KiROUND( gridSize.x );
1611  break;
1612 
1613  case WXK_NUMPAD6:
1614  case WXK_RIGHT:
1615  aPos->x += KiROUND( gridSize.x );
1616  break;
1617 
1618  default: /* Can't happen since we entered the statement */
1619  break;
1620  }
1621 
1622  m_canvas->MoveCursor( *aPos );
1624  }
1625  break;
1626 
1627  default:
1628  break;
1629  }
1630 
1631  return key_handled;
1632 }
1633 
1634 
1635 bool EDA_DRAW_FRAME::isBusy() const
1636 {
1637  const BASE_SCREEN* screen = const_cast< BASE_SCREEN* >( GetScreen() );
1638 
1639  if( !screen )
1640  return false;
1641 
1642  return ( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
1643  || ( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK );
1644 }
1645 
1646 
1647 void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
1648 {
1649  if( IsGalCanvasActive() )
1650  return;
1651 
1652  AdjustScrollBars( aCenterPoint );
1653 
1654  // Move the mouse cursor to the on grid graphic cursor position
1655  if( aWarpPointer )
1657 
1658  m_canvas->Refresh();
1659  m_canvas->Update();
1660 }
1661 
1662 
1663 void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore )
1664 {
1665  if( IsGalCanvasActive() )
1666  return;
1667 
1668  // Account for scrollbars (see EDA_DRAW_FRAME::AdjustScrollBars that takes
1669  // in account scroolbars area to adjust scroll bars)
1670  wxSize scrollbarSize = m_canvas->GetSize() - m_canvas->GetClientSize();
1671  wxSize sizeAdjusted = m_canvas->GetClientSize() - scrollbarSize;
1672 
1673  wxPoint dPos = posBefore - sizeAdjusted / 2;
1674 
1675  // screen position of crosshair after zoom
1676  wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1677  wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
1678 
1679  AdjustScrollBars( newCenter );
1680 
1681  m_canvas->Refresh();
1682  m_canvas->Update();
1683 }
1684 
1685 
1687 {
1688  m_canvas->Refresh();
1689  m_canvas->Update();
1690 }
1691 
1692 
1693 // Factor out the calculation portion of the various BestZoom() implementations.
1694 //
1695 // Note that like it's forerunners this routine has an intentional side-effect: it
1696 // sets the scroll centre position. While I'm not happy about that, it's probably
1697 // not worth fixing as its days are numbered (GAL canvases use a different method).
1698 double EDA_DRAW_FRAME::bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre )
1699 {
1700  double bestzoom = std::max( sizeX * scaleFactor / (double) m_canvas->GetClientSize().x,
1701  sizeY * scaleFactor / (double) m_canvas->GetClientSize().y );
1702 
1703  // Take scrollbars into account
1704  DSIZE scrollbarSize = m_canvas->GetSize() - m_canvas->GetClientSize();
1705  centre.x -= int( bestzoom * scrollbarSize.x / 2.0 );
1706  centre.y -= int( bestzoom * scrollbarSize.y / 2.0 );
1707 
1708  SetScrollCenterPosition( centre );
1709 
1710  return bestzoom;
1711 }
1712 
1713 
1714 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1715 {
1716  BASE_SCREEN* screen = GetScreen();
1717 
1718  // Set the best zoom and get center point.
1719 
1720  // BestZoom() can compute an illegal zoom if the client window size
1721  // is small, say because frame is not maximized. So use the clamping form
1722  // of SetZoom():
1723  double bestzoom = BestZoom();
1724  screen->SetScalingFactor( bestzoom );
1725 
1726  if( !screen->m_Initialized )
1728 
1729  if( !IsGalCanvasActive() )
1730  RedrawScreen( GetScrollCenterPosition(), aWarpPointer );
1731  else
1732  m_toolManager->RunAction( "common.Control.zoomFitScreen", true );
1733 }
1734 
1735 
1737 {
1738  // Compute the best zoom
1739  Rect.Normalize();
1740 
1741  wxSize size = m_canvas->GetClientSize();
1742 
1743  // Use ceil to at least show the full rect
1744  double scalex = (double) Rect.GetSize().x / size.x;
1745  double bestscale = (double) Rect.GetSize().y / size.y;
1746 
1747  bestscale = std::max( bestscale, scalex );
1748 
1749  GetScreen()->SetScalingFactor( bestscale );
1750  RedrawScreen( Rect.Centre(), true );
1751 }
1752 
1753 
1754 void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
1755 {
1756  if( m_canvas == NULL )
1757  return;
1758 
1759  int id = event.GetId();
1760  bool zoom_at_cursor = false;
1761  BASE_SCREEN* screen = GetScreen();
1762  wxPoint center = GetScrollCenterPosition();
1763 
1764  if ( id == ID_KEY_ZOOM_IN )
1765  {
1766  id = GetCanvas()->GetEnableZoomNoCenter() ?
1768  }
1769  else if ( id == ID_KEY_ZOOM_OUT )
1770  {
1771  id = GetCanvas()->GetEnableZoomNoCenter() ?
1773  }
1774 
1775  switch( id )
1776  {
1777  case ID_OFFCENTER_ZOOM_IN:
1778  center = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1779 
1780  if( screen->SetPreviousZoom() )
1781  RedrawScreen2( center );
1782  break;
1783 
1784  case ID_POPUP_ZOOM_IN:
1785  zoom_at_cursor = true;
1786  center = GetCrossHairPosition();
1787 
1788  // fall thru
1789  case ID_VIEWER_ZOOM_IN:
1790  case ID_ZOOM_IN:
1791  if( screen->SetPreviousZoom() )
1792  RedrawScreen( center, zoom_at_cursor );
1793  break;
1794 
1795  case ID_OFFCENTER_ZOOM_OUT:
1796  center = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1797 
1798  if( screen->SetNextZoom() )
1799  RedrawScreen2( center );
1800  break;
1801 
1802  case ID_POPUP_ZOOM_OUT:
1803  zoom_at_cursor = true;
1804  center = GetCrossHairPosition();
1805 
1806  // fall thru
1807  case ID_VIEWER_ZOOM_OUT:
1808  case ID_ZOOM_OUT:
1809  if( screen->SetNextZoom() )
1810  RedrawScreen( center, zoom_at_cursor );
1811  break;
1812 
1813  case ID_VIEWER_ZOOM_REDRAW:
1814  case ID_POPUP_ZOOM_REDRAW:
1815  case ID_ZOOM_REDRAW:
1816  // This usually means something went wrong. Do a hard refresh.
1817  SetScreen( GetScreen() );
1818  break;
1819 
1820  case ID_POPUP_ZOOM_CENTER:
1821  center = GetCrossHairPosition();
1822  RedrawScreen( center, true );
1823  break;
1824 
1825  case ID_POPUP_ZOOM_PAGE:
1826  case ID_VIEWER_ZOOM_PAGE:
1827  case ID_ZOOM_PAGE:
1828  Zoom_Automatique( false );
1829  break;
1830 
1831  case ID_POPUP_ZOOM_SELECT:
1832  break;
1833 
1834  case ID_POPUP_CANCEL:
1836  break;
1837 
1838  default:
1840  }
1841 
1842  UpdateStatusBar();
1843 }
1844 
1845 
1847 {
1848  GetScreen()->SetNextZoom();
1849 }
1850 
1851 
1853 {
1855 }
1856 
1857 
1858 void EDA_DRAW_FRAME::SetPresetZoom( int aIndex )
1859 {
1860  BASE_SCREEN* screen = GetScreen();
1861 
1862  if( aIndex >= (int) screen->m_ZoomList.size() )
1863  {
1864  wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
1865  __TFILE__, __LINE__, aIndex );
1866  return;
1867  }
1868 
1869  if( m_zoomSelectBox )
1870  m_zoomSelectBox->SetSelection( aIndex );
1871 
1872  if( screen->SetZoom( screen->m_ZoomList[aIndex] ) )
1874 
1875  UpdateStatusBar();
1876 }
1877 
1878 
1879 void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
1880 {
1881  int maxZoomIds;
1882  double zoom;
1883  wxString msg;
1884  BASE_SCREEN* screen = m_canvas->GetScreen();
1885 
1886  msg = AddHotkeyName( _( "Center" ), m_hotkeysDescrList, HK_ZOOM_CENTER );
1887  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_CENTER, msg, KiBitmap( zoom_center_on_screen_xpm ) );
1888  msg = AddHotkeyName( _( "Zoom In" ), m_hotkeysDescrList, HK_ZOOM_IN );
1889  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_IN, msg, KiBitmap( zoom_in_xpm ) );
1890  msg = AddHotkeyName( _( "Zoom Out" ), m_hotkeysDescrList, HK_ZOOM_OUT );
1891  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_OUT, msg, KiBitmap( zoom_out_xpm ) );
1892  msg = AddHotkeyName( _( "Redraw View" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
1893  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_REDRAW, msg, KiBitmap( zoom_redraw_xpm ) );
1894  msg = AddHotkeyName( _( "Zoom to Fit" ), m_hotkeysDescrList, HK_ZOOM_AUTO );
1895  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_PAGE, msg, KiBitmap( zoom_fit_in_page_xpm ) );
1896 
1897 
1898  wxMenu* zoom_choice = new wxMenu;
1899  AddMenuItem( MasterMenu, zoom_choice,
1900  ID_POPUP_ZOOM_SELECT, _( "Zoom" ),
1901  KiBitmap( zoom_selection_xpm ) );
1902 
1903  zoom = screen->GetZoom();
1905  maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.size() ) ?
1906  maxZoomIds : screen->m_ZoomList.size();
1907 
1908  // Populate zoom submenu.
1909  for( int i = 0; i < maxZoomIds; i++ )
1910  {
1911  msg.Printf( wxT( "%.2f" ), m_zoomLevelCoeff / screen->m_ZoomList[i] );
1912 
1913  zoom_choice->Append( ID_POPUP_ZOOM_LEVEL_START + i, _( "Zoom: " ) + msg,
1914  wxEmptyString, wxITEM_CHECK );
1915  if( zoom == screen->m_ZoomList[i] )
1916  zoom_choice->Check( ID_POPUP_ZOOM_LEVEL_START + i, true );
1917  }
1918 
1919  // Create grid submenu as required.
1920  if( screen->GetGridCount() )
1921  {
1922  wxMenu* gridMenu = new wxMenu;
1923  AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT,
1924  _( "Grid" ), KiBitmap( grid_select_xpm ) );
1925 
1926  wxArrayString gridsList;
1927  int icurr = screen->BuildGridsChoiceList( gridsList, GetUserUnits() != INCHES );
1928 
1929  for( unsigned i = 0; i < gridsList.GetCount(); i++ )
1930  {
1931  GRID_TYPE& grid = screen->GetGrid( i );
1932  gridMenu->Append( grid.m_CmdId, gridsList[i], wxEmptyString, wxITEM_CHECK );
1933 
1934  if( (int)i == icurr )
1935  gridMenu->Check( grid.m_CmdId, true );
1936  }
1937  }
1938 
1939  MasterMenu->AppendSeparator();
1940  AddMenuItem( MasterMenu, ID_POPUP_CANCEL, _( "Close" ), KiBitmap( cancel_xpm ) );
1941 }
1942 
1943 
1944 // Find the first child dialog.
1945 wxWindow* findDialog( wxWindowList& aList )
1946 {
1947  for( wxWindow* window : aList )
1948  {
1949  if( dynamic_cast<DIALOG_SHIM*>( window ) )
1950  return window;
1951  }
1952  return NULL;
1953 }
1954 
1955 
1956 void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aWarpCursor, bool aCenterView )
1957 {
1958  if( IsGalCanvasActive() )
1959  {
1960  if( aCenterView )
1961  {
1962  wxWindow* dialog = findDialog( GetChildren() );
1963 
1964  // If a dialog partly obscures the window, then center on the uncovered area.
1965  if( dialog )
1966  {
1967  wxRect dialogRect( GetGalCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
1968  dialog->GetSize() );
1969  GetGalCanvas()->GetView()->SetCenter( aPos, dialogRect );
1970  }
1971  else
1972  GetGalCanvas()->GetView()->SetCenter( aPos );
1973  }
1974 
1975  if( aWarpCursor )
1977  else
1979  }
1980  else
1981  {
1983 
1984  // There may be need to reframe the drawing.
1985  if( aCenterView || !m_canvas->IsPointOnDisplay( aPos ) )
1986  {
1987  SetCrossHairPosition( aPos );
1988  RedrawScreen( aPos, aWarpCursor );
1989  }
1990  else
1991  {
1992  // Put cursor on item position
1993  m_canvas->CrossHairOff( &dc );
1994  SetCrossHairPosition( aPos );
1995 
1996  if( aWarpCursor )
1998  }
1999 
2000  // Be sure cross hair cursor is ON:
2001  m_canvas->CrossHairOn( &dc );
2002  m_canvas->CrossHairOn( &dc );
2003  }
2004 }
2005 
2006 
2007 static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );
2008 
2009 
2010 void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
2011 {
2012  DrawPageOnClipboard( this );
2013 
2014  if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
2015  {
2016  if( GetScreen()->IsBlockActive() )
2017  m_canvas->SetCursor( wxCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ) );
2018 
2020  }
2021 }
2022 
2023 
2024 /* copy the current page or block to the clipboard ,
2025  * to export drawings to other applications (word processing ...)
2026  * This is not suitable for copy command within Eeschema or Pcbnew
2027  */
2029 {
2030  bool DrawBlock = false;
2031  wxRect DrawArea;
2032  BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
2033 
2034  if( screen->IsBlockActive() )
2035  {
2036  DrawBlock = true;
2037  DrawArea.SetX( screen->m_BlockLocate.GetX() );
2038  DrawArea.SetY( screen->m_BlockLocate.GetY() );
2039  DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
2040  DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
2041  }
2042  else
2043  DrawArea.SetSize( aFrame->GetPageSizeIU() );
2044 
2045  // Calculate a reasonable dc size, in pixels, and the dc scale to fit
2046  // the drawings into the dc size
2047  // scale is the ratio resolution (in PPI) / internal units
2048  double ppi = 300; // Use 300 pixels per inch to create bitmap images on start
2049  double inch2Iu = 1000.0 * (double) screen->MilsToIuScalar();
2050  double scale = ppi / inch2Iu;
2051 
2052  wxSize dcsize = DrawArea.GetSize();
2053 
2054  int maxdim = std::max( dcsize.x, dcsize.y );
2055 
2056  // the max size in pixels of the bitmap used to byuild the sheet copy
2057  const int maxbitmapsize = 3000;
2058 
2059  while( int( maxdim * scale ) > maxbitmapsize )
2060  {
2061  ppi = ppi / 1.5;
2062  scale = ppi / inch2Iu;
2063  }
2064 
2065  dcsize.x *= scale;
2066  dcsize.y *= scale;
2067 
2068  // Set draw offset, zoom... to values needed to draw in the memory DC
2069  // after saving initial values:
2070  wxPoint tmp_startvisu = screen->m_StartVisu;
2071  double tmpzoom = screen->GetZoom();
2072  wxPoint old_org = screen->m_DrawOrg;
2073  screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
2074  screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
2075 
2076  screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
2077 
2078  wxMemoryDC dc;
2079  wxBitmap image( dcsize );
2080  dc.SelectObject( image );
2081 
2082  EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
2083  GRResetPenAndBrush( &dc );
2084  GRForceBlackPen( false );
2085  screen->m_IsPrinting = true;
2086  dc.SetUserScale( scale, scale );
2087 
2088  aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
2089  wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
2090 
2091  if( DrawBlock )
2092  {
2093  dc.SetClippingRegion( DrawArea );
2094  }
2095 
2096  dc.Clear();
2097  aFrame->GetCanvas()->EraseScreen( &dc );
2098  const LSET allLayersMask = LSET().set();
2099  aFrame->PrintPage( &dc, allLayersMask, false );
2100  screen->m_IsPrinting = false;
2101  aFrame->GetCanvas()->SetClipBox( tmp );
2102 
2103  bool success = true;
2104 
2105  if( wxTheClipboard->Open() )
2106  {
2107  // This data objects are held by the clipboard,
2108  // so do not delete them in the app.
2109  wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
2110  wxTheClipboard->SetData( clipbrd_data );
2111  wxTheClipboard->Close();
2112  }
2113  else
2114  success = false;
2115 
2116  // Deselect Bitmap from DC in order to delete the MemoryDC safely
2117  // without deleting the bitmap
2118  dc.SelectObject( wxNullBitmap );
2119 
2120  GRForceBlackPen( false );
2121 
2122  screen->m_StartVisu = tmp_startvisu;
2123  screen->m_DrawOrg = old_org;
2124  screen->SetZoom( tmpzoom );
2125 
2126  return success;
2127 }
2128 
2129 
2130 void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
2131  const PAGE_INFO& aPageInfo,
2132  const wxString &aFullSheetName,
2133  const wxString& aFileName,
2134  TITLE_BLOCK& aTitleBlock,
2135  int aSheetCount, int aSheetNumber,
2136  int aPenWidth, double aScalar,
2137  COLOR4D aColor, COLOR4D aAltColor,
2138  const wxString& aSheetLayer )
2139 {
2140  WS_DRAW_ITEM_LIST drawList;
2141 
2142  drawList.SetPenSize( aPenWidth );
2143  drawList.SetMilsToIUfactor( aScalar );
2144  drawList.SetSheetNumber( aSheetNumber );
2145  drawList.SetSheetCount( aSheetCount );
2146  drawList.SetFileName( aFileName );
2147  drawList.SetSheetName( aFullSheetName );
2148  drawList.SetSheetLayer( aSheetLayer );
2149 
2150  drawList.BuildWorkSheetGraphicList( aPageInfo,
2151  aTitleBlock, aColor, aAltColor );
2152 
2153  // Draw item list
2154  drawList.Draw( aClipBox, aDC );
2155 }
2156 
2157 
2158 void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
2159  double aScalar, const wxString &aFilename,
2160  const wxString &aSheetLayer )
2161 {
2163  return;
2164 
2165  const PAGE_INFO& pageInfo = GetPageSettings();
2166  wxSize pageSize = pageInfo.GetSizeMils();
2167 
2168  // if not printing, draw the page limits:
2169  if( !aScreen->m_IsPrinting && m_showPageLimits )
2170  {
2171  GRSetDrawMode( aDC, GR_COPY );
2172  GRRect( m_canvas->GetClipBox(), aDC, 0, 0,
2173  pageSize.x * aScalar, pageSize.y * aScalar, aLineWidth,
2175  }
2176 
2177  TITLE_BLOCK t_block = GetTitleBlock();
2178  COLOR4D color = COLOR4D( RED );
2179 
2180  wxPoint origin = aDC->GetDeviceOrigin();
2181 
2182  if( aScreen->m_IsPrinting && origin.y > 0 )
2183  {
2184  aDC->SetDeviceOrigin( 0, 0 );
2185  aDC->SetAxisOrientation( true, false );
2186  }
2187 
2188  DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
2189  GetScreenDesc(), aFilename, t_block,
2190  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
2191  aLineWidth, aScalar, color, color, aSheetLayer );
2192 
2193  if( aScreen->m_IsPrinting && origin.y > 0 )
2194  {
2195  aDC->SetDeviceOrigin( origin.x, origin.y );
2196  aDC->SetAxisOrientation( true, true );
2197  }
2198 }
2199 
2200 
2201 wxString EDA_DRAW_FRAME::GetScreenDesc() const
2202 {
2203  // Virtual function. In basic class, returns
2204  // an empty string.
2205  return wxEmptyString;
2206 }
2207 
2208 
2210 {
2211  BOX2I rv;
2212  rv.SetMaximum();
2213  return rv;
2214 }
2215 
2216 
2217 bool EDA_DRAW_FRAME::saveCanvasImageToFile( const wxString& aFileName, wxBitmapType aBitmapType )
2218 {
2219  return SaveCanvasImageToFile( this, aFileName, aBitmapType );
2220 }
virtual BASE_SCREEN * GetScreen()=0
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:128
virtual void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:123
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
Definition: base_screen.h:410
void CommonSettingsChanged() override
Function CommonSettingsChanged Notification event that some of the common (suite-wide) settings have ...
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:120
BLOCK_STATE_T GetState() const
virtual wxPoint GetScreenCenterLogicalPosition()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void AdjustScrollBars(const wxPoint &aCenterPosition)
int m_ScreenNumber
Definition: base_screen.h:216
void OnToggleCrossHairStyle(wxCommandEvent &aEvent)
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_MODEDIT_INSERT_MODULE_IN_BOARD
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
bool m_galCanvasActive
whether to use new GAL engine
Definition: draw_frame.h:100
void SetCurrentCursor(int aCursor)
Function SetCurrentCursor Set the current cursor shape for drawpanel.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
wxSize m_ScrollbarNumber
Current virtual draw area size in scroll units.
Definition: base_screen.h:192
bool IsBlockActive() const
Definition: base_screen.h:499
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
virtual const TITLE_BLOCK & GetTitleBlock() const =0
int m_ScrollPixelsPerUnitY
Pixels per scroll unit in the vertical direction.
Definition: base_screen.h:190
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:953
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
void setScrollCenterPosition(const wxPoint &aPoint)
Definition: base_screen.h:174
virtual void HandleBlockPlace(wxDC *DC)
Called after HandleBlockEnd, when a block command needs to be executed after the block is moved to it...
bool SaveCanvasImageToFile(EDA_DRAW_FRAME *aFrame, const wxString &aFileName, wxBitmapType aBitmapType)
Save the current view as an image file.
Definition: bitmap.cpp:195
virtual wxPoint ToDeviceXY(const wxPoint &pos)
Function ToDeviceXY transforms logical to device coordinates.
#define LastGridSizeIdKeyword
Most recently used grid size (suffix)
Definition: draw_frame.h:69
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
int GetDefaultCursor() const
Function GetDefaultCursor.
coord_type GetX() const
Definition: box2.h:188
virtual int BlockCommand(EDA_KEY aKey)
Return the block command code (BLOCK_MOVE, BLOCK_COPY...) corresponding to the keys pressed (ALT,...
TOOL_DISPATCHER * m_toolDispatcher
Definition: draw_frame.h:129
virtual void SetEnableZoomNoCenter(bool aEnable)
coord_type GetTop() const
Definition: box2.h:202
#define DEFAULT_MAX_UNDO_ITEMS
Definition: draw_frame.h:47
int GetX() const
Definition: eda_rect.h:109
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:339
virtual void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:181
double bestZoom(double sizeX, double sizeY, double scaleFactor, wxPoint centre)
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:223
VIEW_CONTROLS class definition.
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:340
wxPoint getCursorPosition(bool aOnGrid, const wxPoint &aGridOrigin, wxRealPoint *aGridSize) const
Function getCursorPosition returns the current cursor position in logical (drawing) units.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
Definition: draw_frame.h:179
virtual double BestZoom()=0
Return the zoom level which displays the full page on screen.
virtual void OnGridSettings(wxCommandEvent &event)
Definition: draw_frame.h:604
wxPoint getNearestGridPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin, wxRealPoint *aGridSize) const
Function getNearestGridPosition returns the nearest aGridSize location to aPosition.
void SetScrollCenterPosition(const wxPoint &aPoint)
virtual bool IsGridVisible() const
Definition: draw_frame.h:535
wxPoint GetCrossHairScreenPosition() const
Return the cross hair position in device (display) units.b.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
void OnMouseEvent(wxMouseEvent &event)
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file.
int color
Definition: DXF_plotter.cpp:62
void MoveBottomTo(coord_type aBottom)
Definition: box2.h:204
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
Definition: id.h:241
virtual bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL)
int GetWidth() const
Definition: eda_rect.h:117
std::vector< wxSocketBase * > m_sockets
interprocess communication
Definition: draw_frame.h:104
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
virtual void EnableMousewheelPan(bool aEnable)
Function EnableMousewheelPan() Enables or disables mousewheel panning.
wxString ConfigBaseName()
Function ConfigBaseName.
virtual void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
EVT_MENU_RANGE(ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE, EDA_DRAW_FRAME::OnZoom) EVT_MENU_RANGE(ID_POPUP_GRID_LEVEL_1000
BLOCK_COMMAND_T
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
#define GR_KB_CTRL
coord_type GetRight() const
Definition: box2.h:197
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
void SetCanStartBlock(int aStartBlock)
void ReleaseFile()
Release the current file marked in use.
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:417
virtual void ToolOnRightClick(wxCommandEvent &event)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
virtual wxString GetCanvasTypeKey()
Definition: draw_frame.h:241
wxAuiManager m_auimgr
virtual EDA_RECT * GetClipBox()
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock, COLOR4D aColor, COLOR4D aAltColor)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
virtual void OnZoom(wxCommandEvent &event)
void OnMenuOpen(wxMenuEvent &event)
void SkipNextLeftButtonReleaseEvent()
After calling this function, if the left mouse button is down, the next left mouse button release eve...
virtual void SetGridColor(COLOR4D aColor)
Definition: draw_frame.h:560
void CopyToClipboard(wxCommandEvent &event)
Copy the current page or the current block to the clipboard.
coord_type GetBottom() const
Definition: box2.h:198
virtual void MoveCursor(const wxPoint &aPosition)
Function MoveCursor moves the mouse pointer to aPosition in logical (drawing) units.
class EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
Sentinel, do not use as a parameter.
virtual void SetPrevGrid()
Change the grid size settings to the previous one available.
The base class for create windows for drawing purpose.
Definition: draw_frame.h:81
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
void PushPreferences(const EDA_DRAW_PANEL *aParentCanvas)
Push preferences from a parent window to a child window.
void FocusOnLocation(const wxPoint &aPos, bool aWarpCursor=true, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
COLOR4D m_drawBgColor
the background color of the draw canvas BLACK for Pcbnew, BLACK or WHITE for eeschema
Definition: draw_frame.h:116
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
bool SetPreviousZoom()
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
wxChoice * m_gridSelectBox
Definition: draw_frame.h:151
virtual void UseGalCanvas(bool aEnable)
Use to switch between standard and GAL-based canvas.
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
prevents opening same file multiple times.
Definition: draw_frame.h:106
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file.
virtual void InitBlockPasteInfos()
static const double MAX_AXIS
virtual const wxSize GetPageSizeIU() const =0
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
#define UserUnitsEntryKeyword
User units.
Definition: draw_frame.h:63
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:48
#define VIRT_MIN
min X or Y coordinate in virtual space
bool SetNextZoom()
Auxiliary rendering target (noncached)
Definition: definitions.h:49
void SetClipBox(const EDA_RECT &aRect)
static const wxString MaxUndoItemsEntry(wxT("DevelMaxUndoItems"))
Integer to set the maximum number of undo items on the stack.
This file contains miscellaneous commonly used macros and functions.
void ClearItemsList()
Function ClearItemsList clear only the list of EDA_ITEM pointers, it does NOT delete the EDA_ITEM obj...
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:114
void DisplayUnitsMsg()
Display current unit pane on the status bar.
bool saveCanvasImageToFile(const wxString &aFileName, wxBitmapType aBitmapType=wxBITMAP_TYPE_PNG)
void OnUpdateUndo(wxUpdateUIEvent &aEvent)
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:941
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Handle the common part of GeneralControl dedicated to global cursor keys (i.e.
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:928
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode
virtual wxPoint ToLogicalXY(const wxPoint &pos)
Function ToLogicalXY transforms device to logical coordinates.
Class TOOL_MANAGER.
Definition: tool_manager.h:49
virtual bool HandleBlockBegin(wxDC *aDC, EDA_KEY aKey, const wxPoint &aPosition, int aExplicitCommand=0)
Initialize a block command.
void EnableCursorWarping(bool aEnable)
Function EnableCursorWarping() Enables or disables warping the cursor.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
virtual const PAGE_INFO & GetPageSettings() const =0
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:53
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
Definition: base_screen.h:198
void MoveLeftTo(coord_type aLeft)
Definition: box2.h:205
void ReadConfig(wxConfigBase *aCfg, const wxString &aBaseName)
static const wxString traceScrollSettings(wxT("KicadScrollSettings"))
Definition for enabling and disabling scroll bar setting trace output.
virtual bool IsPointOnDisplay(const wxPoint &aPosition)
Function IsPointOnDisplay.
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:51
wxAuiToolBar * m_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window.
Definition: draw_frame.h:156
#define DEFAULT_FILE_HISTORY_SIZE
The default file history size is 9.
Definition: pgm_base.h:60
Class LSET is a set of PCB_LAYER_IDs.
a helper to handle the real device context used in KiCad
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:163
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
void OnUpdateRedo(wxUpdateUIEvent &aEvent)
BASE_SCREEN * m_currentScreen
current used SCREEN
Definition: draw_frame.h:90
static bool DrawPageOnClipboard(EDA_DRAW_FRAME *aFrame)
const wxPoint & GetScrollCenterPosition() const
double GetZoomLevelCoeff() const
Return the coefficient to convert internal display scale factor to zoom level.
Definition: draw_frame.h:471
virtual void PrintPage(wxDC *aDC, LSET aPrintMask, bool aPrintMirrorMode, void *aData=NULL)
Print the page pointed by current screen, set by the calling print function.
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:108
void RefreshCrossHair(const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC *aDC)
Move and refresh the crosshair after movement and call the mouse capture function.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
EDA_DRAW_FRAME::OnSelectGrid EVT_TOOL_RANGE(ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH, EDA_DRAW_FRAME::OnSelectUnits) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SELECT_UNIT_MM
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:204
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:596
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
bool m_Center
Center on screen.
Definition: base_screen.h:202
bool m_Initialized
Definition: base_screen.h:207
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:166
virtual void CrossHairOn(wxDC *DC=nullptr)
GAL not used (the legacy wxDC engine is used)
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
wxPoint getCrossHairPosition(bool aInvertY) const
Function getCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Definition: base_screen.h:107
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
bool m_showBorderAndTitleBlock
True shows the drawing border and title block.
Definition: draw_frame.h:146
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard EVT_UPDATE_UI_RANGE(ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar) EVT_UPDATE_UI(ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:291
void SetScalingFactor(double iu_per_du)
Function SetScalingFactor sets the scaling factor of "internal unit per device unit".
const wxPoint & getScrollCenterPosition() const
Definition: base_screen.h:173
coord_type GetWidth() const
Definition: box2.h:195
Definition: common.h:161
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:152
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
void SetMaximum()
Definition: box2.h:71
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:472
wxPoint GetGridPosition(const wxPoint &aPosition) const
Return the nearest grid position to aPosition if a screen is defined and snap to grid is enabled.
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units.
static const wxString FirstRunShownKeyword(wxT("FirstRunShown"))
virtual void SetZoom(double mode)
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:49
int m_ScrollPixelsPerUnitX
Pixels per scroll unit in the horizontal direction.
Definition: base_screen.h:189
virtual void ReCreateAuxiliaryToolbar()
Helper dialog and control classes.
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:52
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
virtual void CrossHairOff(wxDC *DC=nullptr)
uint32_t EDA_KEY
Definition: common.h:74
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
wxAuiToolBarItem * GetToolbarTool(int aToolId)
Checks all the toolbars and returns a reference to the given tool id or nullptr if not found.
void OnUpdateUnits(wxUpdateUIEvent &aEvent)
double GetZoomFactor() const
Get the zoom factor.
wxLogTrace helper definitions.
void setMousePosition(const wxPoint &aPosition)
Definition: base_screen.h:156
Definition: colors.h:60
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
void OnToggleGridState(wxCommandEvent &aEvent)
virtual bool SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
bool GetEnableZoomNoCenter() const
virtual int MilsToIuScalar()
Function MilsToIuScalar returns the scalar required to convert mils to internal units.
Definition: base_screen.h:245
void SetPresetZoom(int aIndex)
Change zoom to one of the preset values.
const wxSize & GetSizeMils() const
Definition: page_info.h:142
virtual void EnableAutoPan(bool aEnabled)
Function EnableAutoPan Turns on/off auto panning (user setting to disable it entirely).
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
void SetPresetGrid(int aIndex)
Change the grid size to one of the preset values.
int m_UndoRedoCountMax
default Undo/Redo command Max depth, to be handed
Definition: draw_frame.h:121
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:395
void EraseMsgBox()
Definition: msgpanel.cpp:216
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Set the tool command ID to aId and sets the cursor to aCursor.
bool GetEnableMousewheelPan() const
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: base_struct.h:297
virtual void SetCurrentCursor(int aCursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
wxPoint refPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
Definition: base_screen.h:168
virtual const wxPoint & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
int m_LastGridSizeId
Definition: draw_frame.h:110
virtual COLOR4D GetGridColor()
Definition: draw_frame.h:552
virtual void RedrawScreen2(const wxPoint &posBefore)
Put the crosshair back to the screen position it had before zooming.
wxPoint getCrossHairScreenPosition() const
Function getCursorScreenPosition returns the cross hair position in device (display) units....
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:160
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
bool m_IsPrinting
Definition: base_screen.h:220
Definition: solve.cpp:178
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
int GetHeight() const
Definition: eda_rect.h:118
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
#define AUTOSAVE_INTERVAL_KEY
Definition: pgm_base.h:47
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...
wxPoint m_ScrollbarPos
Current scroll bar position in scroll units.
Definition: base_screen.h:196
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor, int aPad=6)
Function AppendMessage appends a message to the message panel.
Definition: msgpanel.cpp:110
void DrawPageLayout(wxDC *aDC, EDA_RECT *aClipBox, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, COLOR4D aAltColor, const wxString &aSheetLayer)
Function DrawPageLayout is a core function to draw the page layout with the frame and the basic inscr...
virtual void SetNextGrid()
Change the grid size settings to the next one available.
EDA_DRAW_PANEL_GAL * m_galCanvas
GAL display options - this is the frame's interface to setting GAL display options.
Definition: draw_frame.h:94
virtual const wxString GetZoomLevelIndicator() const
Return a human readable value which can be displayed as zoom level indicator in dialogs.
virtual bool HandleBlockEnd(wxDC *DC)
Handle the "end" of a block command, i.e.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99
wxSocketServer * m_socketServer
Definition: draw_frame.h:103
void Normalize()
Function Normalize ensures that the height ant width are positive.
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
coord_type GetY() const
Definition: box2.h:189
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
wxWindow * findDialog(wxWindowList &aList)
void OnUpdateCrossHairStyle(wxUpdateUIEvent &aEvent)
void WriteConfig(wxConfigBase *aCfg, const wxString &aBaseName)
virtual void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
Redraw the entire screen area by updating the scroll bars and mouse pointer in order to have aCenterP...
void SetMaxFiles(size_t aMaxFiles)
Definition: pgm_base.cpp:79
void setCrossHairPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin, bool aSnapToGrid)
Function setCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:54
void SetAutoSaveInterval(int aInterval)
double m_zoomLevelCoeff
a suitable value to convert the internal zoom scaling factor
Definition: draw_frame.h:118
const int scale
void DisplayToolMsg(const wxString &msg)
bool GridExists(int aCommandId)
Function GridExists tests for grid command ID (not an index in grid list, but a wxID) exists in grid ...
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value)
see class PGM_BASE
virtual void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void OnUpdateGrid(wxUpdateUIEvent &aEvent)
void SetMousePosition(const wxPoint &aPosition)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class GRID_TYPE is for grid arrays.
Definition: base_screen.h:45
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
#define max(a, b)
Definition: auxiliary.h:86
#define INSTALL_UNBUFFERED_DC(name, parent)
double GetScalingFactor() const
Function GetScalingFactor returns the inverse of the current scale used to draw items on screen.
Definition: base_screen.cpp:95
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
virtual int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL)
Function WriteHotkeyConfig Store the current hotkey list It is stored using the standard wxConfig mec...
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
Definition: draw_frame.h:65
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
Definition: draw_frame.h:97
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
size_t i
Definition: json11.cpp:597
size_t GetGridCount() const
Function GetGridCount().
Definition: base_screen.h:457
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
Definition: base_screen.h:183
virtual void SetEnableMousewheelPan(bool aEnable)
void SetNextZoom()
Change the zoom to the next one available.
int GetY() const
Definition: eda_rect.h:110
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:55
The common library.
coord_type GetHeight() const
Definition: box2.h:196
wxPoint RefPos(bool useMouse) const
Return the reference position, coming from either the mouse position or the cursor position.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool m_showPageLimits
true to display the page limits
Definition: draw_frame.h:114
wxPoint Centre() const
Definition: eda_rect.h:60
void SetGridVisibility(bool aVisibility)
Sets the visibility setting of the grid.
Definition: colors.h:49
int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL) override
virtual int GetDefaultCursor() const
Function GetDefaultCursor.
virtual void Window_Zoom(EDA_RECT &Rect)
int m_NumberOfScreens
Definition: base_screen.h:217
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
virtual void CommonSettingsChanged()
Function CommonSettingsChanged Notification event that some of the common (suite-wide) settings have ...
virtual void AddMenuZoomAndGrid(wxMenu *aMasterMenu)
Add standard zoom commands and submenu zoom and grid selection to a popup menu uses zoom hotkeys info...
classes and function to generate graphics to plt or draw titles blocks and frame references
virtual void SetGridVisibility(bool aVisible)
It may be overloaded by derived classes.
Definition: draw_frame.h:544
const Vec & GetSize() const
Definition: box2.h:187
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Draws on screen the page layout with the frame and the basic inscriptions.
void Draw(EDA_RECT *aClipBox, wxDC *aDC)
Draws the item list created by BuildWorkSheetGraphicList.
coord_type GetLeft() const
Definition: box2.h:201
Definition: colors.h:45
virtual void OnCharHook(wxKeyEvent &event)
Capture the key event before it is sent to the GUI.
void OnSelectUnits(wxCommandEvent &aEvent)
virtual void unitsChangeRefresh()
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
Class VIEW.
Definition: view.h:61
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
bool GetToolToggled(int aToolId)
Checks all the toolbars and returns true if the given tool id is toggled.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
void MoveTopTo(coord_type aTop)
Definition: box2.h:203
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
int m_CmdId
Definition: base_screen.h:48
BASE_SCREEN class implementation.
Message panel definition file.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
virtual void EraseScreen(wxDC *DC)
Function OnMouseWheel handles mouse wheel events.
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:123
ACTIONS * m_actions
Definition: draw_frame.h:130
virtual void OnLeftDClick(wxDC *DC, const wxPoint &MousePos)
#define GridColorEntryKeyword
Grid color ID (suffix)
Definition: draw_frame.h:67
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:403
static int GetRequiredHeight()
Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:71
void SetPrevZoom()
Change the zoom to the previous one available.
virtual void SetEnableAutoPan(bool aEnable)
#define VIRT_MAX
max X or Y coordinate in virtual space
virtual void UpdateStatusBar()
Update the status bar information.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:243
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:404
virtual void OnActivate(wxActivateEvent &event)
Called when activating the frame.
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:176
void ClearMsgPanel(void)
Clear all messages from the message panel.
void UpdateHotKeys()
wxPoint GetCursorPosition(bool aOnGrid, wxRealPoint *aGridSize=NULL) const
Return the current cursor position in logical (drawing) units.
EDA_UNITS_T
Definition: common.h:160
virtual void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
long m_firstRunDialogSetting
Key to control whether first run dialog is shown on startup.
Definition: draw_frame.h:149
void SetUserUnits(EDA_UNITS_T aUnits)
Definition: draw_frame.h:292
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false)=0
Moves cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
Definition: base_screen.h:219
bool m_snapToGrid
Indicates if cursor should be snapped to grid.
Definition: draw_frame.h:92
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
const wxSize GetSize() const
Definition: eda_rect.h:101
void SetCommand(BLOCK_COMMAND_T aCommand)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
#define min(a, b)
Definition: auxiliary.h:85
Class GAL is the abstract interface for drawing on a 2D-surface.
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual wxString GetScreenDesc() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void MoveRightTo(coord_type aRight)
Definition: box2.h:206
virtual const BOX2I GetDocumentExtents() const
void SetIgnoreLeftButtonReleaseEvent(bool aIgnore)
File locking utilities.