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_UPDATE_UI( wxID_UNDO, EDA_DRAW_FRAME::OnUpdateUndo )
118  EVT_UPDATE_UI( wxID_REDO, EDA_DRAW_FRAME::OnUpdateRedo )
119 END_EVENT_TABLE()
120 
121 
122 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
123  FRAME_T aFrameType,
124  const wxString& aTitle,
125  const wxPoint& aPos, const wxSize& aSize,
126  long aStyle, const wxString & aFrameName ) :
127  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
128 {
129  m_socketServer = nullptr;
130  m_mainToolBar = NULL;
131  m_drawToolBar = NULL;
132  m_optionsToolBar = NULL;
133  m_auxiliaryToolBar = NULL;
134  m_gridSelectBox = NULL;
135  m_zoomSelectBox = NULL;
136  m_hotkeysDescrList = NULL;
137 
138  m_canvas = NULL;
139  m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
140  m_galCanvas = NULL;
141  m_galCanvasActive = false;
142  m_actions = NULL;
143  m_toolManager = NULL;
144  m_toolDispatcher = NULL;
145  m_messagePanel = NULL;
146  m_currentScreen = NULL;
147  m_toolId = ID_NO_TOOL_SELECTED;
148  m_lastDrawToolId = ID_NO_TOOL_SELECTED;
149  m_showAxis = false; // true to draw axis.
150  m_showBorderAndTitleBlock = false; // true to display reference sheet.
151  m_showGridAxis = false; // true to draw the grid axis
152  m_showOriginAxis = false; // true to draw the grid origin
153  m_LastGridSizeId = 0;
154  m_drawGrid = true; // hide/Show grid. default = show
155  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
156  m_showPageLimits = false;
157  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
158  // BLACK for Pcbnew, BLACK or WHITE for eeschema
159  m_snapToGrid = true;
160  m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
161  m_movingCursorWithKeyboard = false;
162  m_zoomLevelCoeff = 1.0;
163 
164  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
165 
166  CreateStatusBar( 6 );
167 
168  // set the size of the status bar subwindows:
169 
170  wxWindow* stsbar = GetStatusBar();
171 
172  int dims[] = {
173 
174  // remainder of status bar on far left is set to a default or whatever is left over.
175  -1,
176 
177  // When using GetTextSize() remember the width of character '1' is not the same
178  // as the width of '0' unless the font is fixed width, and it usually won't be.
179 
180  // zoom:
181  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
182 
183  // cursor coords
184  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
185 
186  // delta distances
187  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
188 
189  // units display, Inches is bigger than mm
190  GetTextSize( _( "Inches" ), stsbar ).x + 10,
191 
192  // Size for the panel used as "Current tool in play": will take longest string from
193  // void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) in pcbnew/edit.cpp
194  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
195  };
196 
197  SetStatusWidths( arrayDim( dims ), dims );
198 
199  // Create child subwindows.
200  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
201  m_FramePos.x = m_FramePos.y = 0;
202  m_FrameSize.y -= m_MsgFrameHeight;
203 
204  m_canvas = new EDA_DRAW_PANEL( this, -1, wxPoint( 0, 0 ), m_FrameSize );
205  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
206  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
207 
208  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
209 }
210 
211 
213 {
214  delete m_socketServer;
215  for( auto socket : m_sockets )
216  {
217  socket->Shutdown();
218  socket->Destroy();
219  }
220 
222 
223  delete m_actions;
224  delete m_toolManager;
225  delete m_toolDispatcher;
226  delete m_galCanvas;
227 
228  delete m_currentScreen;
229  m_currentScreen = NULL;
230 
231  m_auimgr.UnInit();
232 
233  ReleaseFile();
234 }
235 
236 
237 void EDA_DRAW_FRAME::OnCharHook( wxKeyEvent& event )
238 {
239  wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dump( event ) );
240  // Key events can be filtered here.
241  // Currently no filtering is made.
242  event.Skip();
243 }
244 
245 
247 {
248  m_file_checker = nullptr;
249 }
250 
251 
252 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
253 {
254  m_file_checker = ::LockFile( aFileName );
255 
256  return bool( m_file_checker );
257 }
258 
259 
261 {
262  UpdateStatusBar();
263  UpdateMsgPanel();
264 }
265 
267 {
269 
270  wxConfigBase* settings = Pgm().CommonSettings();
271 
272  int autosaveInterval;
273  settings->Read( AUTOSAVE_INTERVAL_KEY, &autosaveInterval );
274  SetAutoSaveInterval( autosaveInterval );
275 
276  int historySize;
277  settings->Read( FILE_HISTORY_SIZE_KEY, &historySize, DEFAULT_FILE_HISTORY_SIZE );
278  Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
279 
280  bool option;
281  settings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
282  m_canvas->SetEnableMousewheelPan( option );
283 
284  settings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
285  m_canvas->SetEnableZoomNoCenter( option );
286 
287  settings->Read( ENBL_AUTO_PAN_KEY, &option );
288  m_canvas->SetEnableAutoPan( option );
289 
290  m_galDisplayOptions.ReadCommonConfig( *settings, this );
291 }
292 
293 
295 {
296  if( m_messagePanel )
298 }
299 
300 
301 void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
302 {
303  if( m_canvas )
304  m_canvas->SetCanStartBlock( -1 );
305 
306  event.Skip(); // required under wxMAC
307 }
308 
309 
310 void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
311 {
312  if( m_canvas )
313  m_canvas->SetCanStartBlock( -1 );
314 
315  event.Skip();
316 }
317 
318 
320 {
322 }
323 
324 
325 void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
326 {
328 
329  if( IsGalCanvasActive() )
330  {
333  }
334 
335  m_canvas->Refresh();
336 }
337 
338 
339 bool EDA_DRAW_FRAME::GetToolToggled( int aToolId )
340 {
341  // Checks all the toolbars and returns true if the given tool id is toggled.
342  return ( ( m_mainToolBar && m_mainToolBar->GetToolToggled( aToolId ) ) ||
343  ( m_optionsToolBar && m_optionsToolBar->GetToolToggled( aToolId ) ) ||
344  ( m_drawToolBar && m_drawToolBar->GetToolToggled( aToolId ) ) ||
345  ( m_auxiliaryToolBar && m_auxiliaryToolBar->GetToolToggled( aToolId ) )
346  );
347 }
348 
349 
350 void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent )
351 {
353  m_canvas->CrossHairOff( &dc );
354 
355  auto& galOpts = GetGalDisplayOptions();
356  galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
357  galOpts.NotifyChanged();
358 
359  m_canvas->CrossHairOn( &dc );
360 }
361 
362 
363 void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent )
364 {
365  if( GetScreen() )
366  aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 );
367 }
368 
369 
370 void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent )
371 {
372  if( GetScreen() )
373  aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 );
374 }
375 
376 
377 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
378 {
379  // No need to update the grid select box if it doesn't exist or the grid setting change
380  // was made using the select box.
381  if( m_gridSelectBox == NULL || m_auxiliaryToolBar == NULL )
382  return;
383 
384  int select = wxNOT_FOUND;
385 
386  for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
387  {
388  if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId )
389  {
390  select = (int) i;
391  break;
392  }
393  }
394 
395  if( select != m_gridSelectBox->GetSelection() )
396  m_gridSelectBox->SetSelection( select );
397 }
398 
399 
400 void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent )
401 {
402  aEvent.Check( GetGalDisplayOptions().m_fullscreenCursor );
403 }
404 
405 
407 {
408 }
409 
410 
412 {
413 }
414 
415 
416 bool EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
417 {
418  return false;
419 }
420 
422  wxString* aFullFileName )
423 {
424  int result = EDA_BASE_FRAME::WriteHotkeyConfig( aDescList, aFullFileName );
425 
426  if( IsGalCanvasActive() )
428 
429  return result;
430 }
431 
432 void EDA_DRAW_FRAME::ToolOnRightClick( wxCommandEvent& event )
433 {
434 }
435 
436 
437 void EDA_DRAW_FRAME::PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMode, void* aData )
438 {
439  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
440 }
441 
442 
443 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
444 {
445  int* clientData;
446  int eventId = ID_POPUP_GRID_LEVEL_100;
447 
448  if( event.GetEventType() == wxEVT_CHOICE )
449  {
450  if( m_gridSelectBox == NULL ) // Should not happen
451  return;
452 
453  /*
454  * Don't use wxCommandEvent::GetClientData() here. It always
455  * returns NULL in GTK. This solution is not as elegant but
456  * it works.
457  */
458  int index = m_gridSelectBox->GetSelection();
459  wxASSERT( index != wxNOT_FOUND );
460 
461  if( index == int( m_gridSelectBox->GetCount() - 2 ) )
462  {
463  // this is the separator
464  wxUpdateUIEvent dummy;
466  return;
467  }
468  else if( index == int( m_gridSelectBox->GetCount() - 1 ) )
469  {
470  wxUpdateUIEvent dummy;
472  wxCommandEvent dummy2;
473  OnGridSettings( dummy2 );
474  return;
475  }
476 
477  clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
478 
479  if( clientData != NULL )
480  eventId = *clientData;
481  }
482  else
483  {
484  eventId = event.GetId();
485  }
486 
487  int idx = eventId - ID_POPUP_GRID_LEVEL_1000;
488 
489  // Notify GAL
490  TOOL_MANAGER* mgr = GetToolManager();
491 
492  if( mgr && IsGalCanvasActive() )
493  mgr->RunAction( "common.Control.gridPreset", true, idx );
494  else
495  SetPresetGrid( idx );
496 
497  m_canvas->Refresh();
498 }
499 
500 
501 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
502 {
503  if( m_zoomSelectBox == NULL )
504  return; // Should not happen!
505 
506  int id = m_zoomSelectBox->GetCurrentSelection();
507 
508  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
509  return;
510 
511  if( IsGalCanvasActive() )
512  {
513  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
514  UpdateStatusBar();
515  m_galCanvas->Refresh();
516  }
517  else if( id == 0 ) // Auto zoom (Fit in Page)
518  {
519  Zoom_Automatique( true );
520  m_canvas->Refresh();
521  }
522  else
523  {
524  double selectedZoom = GetScreen()->m_ZoomList[id-1];
525 
526  if( GetScreen()->SetZoom( selectedZoom ) )
528  }
529 }
530 
531 
533 {
534  return GetScreen()->GetZoom();
535 }
536 
537 
538 void EDA_DRAW_FRAME::OnMouseEvent( wxMouseEvent& event )
539 {
540  event.Skip();
541 }
542 
543 
544 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
545 {
546  m_toolMsg = msg;
547  SetStatusText( msg, 5 );
548 }
549 
550 
552 {
553  wxString msg;
554 
555  switch( m_UserUnits )
556  {
557  case INCHES:
558  msg = _( "Inches" );
559  break;
560 
561  case MILLIMETRES:
562  msg = _( "mm" );
563  break;
564 
565  default:
566  msg = _( "Units" );
567  break;
568  }
569 
570  SetStatusText( msg, 4 );
571 }
572 
573 
574 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
575 {
576  m_FrameSize = GetClientSize( );
577 
578  SizeEv.Skip();
579 }
580 
581 
582 void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
583 {
584  // Keep default cursor in toolbars
585  SetCursor( wxNullCursor );
586 
587  // Change m_canvas cursor if requested.
588  if( m_canvas && aCursor >= 0 )
589  m_canvas->SetCurrentCursor( aCursor );
590 
591  // Change GAL canvas cursor if requested.
592  if( IsGalCanvasActive() && aCursor >= 0 )
593  GetGalCanvas()->SetCurrentCursor( aCursor );
594 
595  DisplayToolMsg( aToolMsg );
596 
597  if( aId < 0 )
598  return;
599 
600  wxCHECK2_MSG( aId >= ID_NO_TOOL_SELECTED, aId = ID_NO_TOOL_SELECTED,
601  wxString::Format( wxT( "Current tool ID cannot be set to %d." ), aId ) );
602 
603  m_toolId = aId;
604 }
605 
606 
608 {
609  // Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
610 
611  int defaultCursor = wxCURSOR_DEFAULT;
612 
613  // Change GAL canvas cursor if requested.
614  if( IsGalCanvasActive() )
615  defaultCursor = GetGalCanvas()->GetDefaultCursor();
616  else if( m_canvas )
617  defaultCursor = m_canvas->GetDefaultCursor();
618 
619  SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString );
620 }
621 
622 
623 wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
624 {
625  wxPoint pos = aPosition;
626 
627  if( m_currentScreen != NULL && m_snapToGrid )
628  pos = GetNearestGridPosition( aPosition );
629 
630  return pos;
631 }
632 
633 
635 {
636  BASE_SCREEN * screen = GetScreen();
637 
638  int new_grid_cmd = screen->GetGridCmdId();
639 
640  // if the grid id is the not the last, increment it
641  if( screen->GridExists( new_grid_cmd + 1 ) )
642  new_grid_cmd += 1;
643 
644  SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
645 }
646 
647 
649 {
650  BASE_SCREEN * screen = GetScreen();
651 
652  int new_grid_cmd = screen->GetGridCmdId();
653 
654  // if the grid id is the not the first, increment it
655  if( screen->GridExists( new_grid_cmd - 1 ) )
656  new_grid_cmd -= 1;
657 
658  SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
659 }
660 
661 
662 void EDA_DRAW_FRAME::SetPresetGrid( int aIndex )
663 {
664  BASE_SCREEN * screen = GetScreen();
665 
666  if( ! screen->GridExists( aIndex + ID_POPUP_GRID_LEVEL_1000 ) )
667  aIndex = screen->GetGrids()[0].m_CmdId;
668 
669  // aIndex is a Command Id relative to ID_POPUP_GRID_LEVEL_1000 comand id code.
670  // we need an index in grid list (the cmd id in list is is screen->GetGrids()[0].m_CmdId):
671  int glistIdx = aIndex + ID_POPUP_GRID_LEVEL_1000 - screen->GetGrids()[0].m_CmdId;
672 
673  if( m_gridSelectBox )
674  {
675  if( glistIdx < 0 || glistIdx >= (int) m_gridSelectBox->GetCount() - 2 )
676  {
677  wxASSERT_MSG( false, "Invalid grid index" );
678  return;
679  }
680 
681  m_gridSelectBox->SetSelection( glistIdx );
682  }
683 
684  // Be sure m_LastGridSizeId is up to date.
685  m_LastGridSizeId = aIndex;
687 
688  // Put cursor on new grid
689  SetCrossHairPosition( RefPos( true ) );
690 }
691 
692 
694 {
695  return 0;
696 }
697 
698 
700 {
703 }
704 
705 
706 void EDA_DRAW_FRAME::HandleBlockPlace( wxDC* DC )
707 {
708 }
709 
710 
711 bool EDA_DRAW_FRAME::HandleBlockEnd( wxDC* DC )
712 {
713  return false;
714 }
715 
716 
718 {
719  SetStatusText( GetZoomLevelIndicator(), 1 );
720 
721  // Absolute and relative cursor positions are handled by overloading this function and
722  // handling the internal to user units conversion at the appropriate level.
723 
724  // refresh units display
725  DisplayUnitsMsg();
726 }
727 
728 
729 const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const
730 {
731  wxString Line;
732  double level = 0.0;
733 
734  if( IsGalCanvasActive() )
735  {
736  level = m_galCanvas->GetGAL()->GetZoomFactor();
737  }
738  else if( BASE_SCREEN* screen = GetScreen() )
739  {
740  level = m_zoomLevelCoeff / (double) screen->GetZoom();
741  }
742 
743  // returns a human readable value which can be displayed as zoom
744  // level indicator in dialogs.
745  Line.Printf( wxT( "Z %.2f" ), level );
746 
747  return Line;
748 }
749 
750 
751 void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
752 {
754 
755  wxString baseCfgName = ConfigBaseName();
756  wxConfigBase* cmnCfg = Pgm().CommonSettings();
757 
758  // Read units used in dialogs and toolbars
759  EDA_UNITS_T unitsTmp;
760 
761  if( aCfg->Read( baseCfgName + UserUnitsEntryKeyword, (int*) &unitsTmp ) )
762  SetUserUnits( unitsTmp );
763  else
765 
766  // Read show/hide grid entry
767  bool btmp;
768  if( aCfg->Read( baseCfgName + ShowGridEntryKeyword, &btmp ) )
769  SetGridVisibility( btmp );
770 
771  // Read grid color:
772  COLOR4D wtmp = COLOR4D::UNSPECIFIED;
773 
774  if( wtmp.SetFromWxString( aCfg->Read( baseCfgName + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
775  SetGridColor( wtmp );
776 
777  aCfg->Read( baseCfgName + LastGridSizeIdKeyword, &m_LastGridSizeId, 0L );
778 
779  // m_LastGridSizeId is an offset, expected to be >= 0
780  if( m_LastGridSizeId < 0 )
781  m_LastGridSizeId = 0;
782 
783  m_UndoRedoCountMax = aCfg->Read( baseCfgName + MaxUndoItemsEntry,
784  long( DEFAULT_MAX_UNDO_ITEMS ) );
785 
786  aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
787 
788  m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this );
789 }
790 
791 
792 void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
793 {
795 
796  wxString baseCfgName = ConfigBaseName();
797 
798  aCfg->Write( baseCfgName + UserUnitsEntryKeyword, (int) m_UserUnits );
799  aCfg->Write( baseCfgName + ShowGridEntryKeyword, IsGridVisible() );
800  aCfg->Write( baseCfgName + GridColorEntryKeyword,
801  GetGridColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) );
802  aCfg->Write( baseCfgName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
803  aCfg->Write( baseCfgName + FirstRunShownKeyword, m_firstRunDialogSetting );
804 
805  if( GetScreen() )
806  aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
807 
808  m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName );
809 }
810 
811 
812 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper,
813  const wxString& textLower,
814  COLOR4D color, int pad )
815 {
816  if( m_messagePanel == NULL )
817  return;
818 
819  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
820 }
821 
822 
824 {
825  if( m_messagePanel == NULL )
826  return;
827 
829 }
830 
831 
832 void EDA_DRAW_FRAME::SetMsgPanel( const MSG_PANEL_ITEMS& aList )
833 {
834  if( m_messagePanel == NULL )
835  return;
836 
837  ClearMsgPanel();
838 
839  for( unsigned i = 0; i < aList.size(); i++ )
840  m_messagePanel->AppendMessage( aList[i] );
841 }
842 
843 
845 {
846  wxCHECK_RET( aItem != NULL, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
847 
848  MSG_PANEL_ITEMS items;
849  aItem->GetMsgPanelInfo( m_UserUnits, items );
850  SetMsgPanel( items );
851 }
852 
853 
855 {
856  EDA_ITEM* item = GetScreen()->GetCurItem();
857 
858  if( item )
859  SetMsgPanel( item );
860 }
861 
862 
863 // FIXME: There needs to be a better way for child windows to load preferences.
864 // This function pushes four preferences from a parent window to a child window
865 // i.e. from eeschema to the schematic symbol editor
866 void EDA_DRAW_FRAME::PushPreferences( const EDA_DRAW_PANEL* aParentCanvas )
867 {
869  m_canvas->SetEnableAutoPan( aParentCanvas->GetEnableAutoPan() );
870 }
871 
872 
873 bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition,
874  int aExplicitCommand )
875 {
877 
878  if( ( block->GetCommand() != BLOCK_IDLE ) || ( block->GetState() != STATE_NO_BLOCK ) )
879  return false;
880 
881  if( aExplicitCommand == 0 )
882  block->SetCommand( (BLOCK_COMMAND_T) BlockCommand( aKey ) );
883  else
884  block->SetCommand( (BLOCK_COMMAND_T) aExplicitCommand );
885 
886  if( block->GetCommand() == 0 )
887  return false;
888 
889  switch( block->GetCommand() )
890  {
891  case BLOCK_IDLE:
892  break;
893 
894  case BLOCK_MOVE: // Move
895  case BLOCK_DRAG: // Drag (block defined)
896  case BLOCK_DRAG_ITEM: // Drag from a drag item command
897  case BLOCK_DUPLICATE: // Duplicate
898  case BLOCK_DUPLICATE_AND_INCREMENT: // Duplicate and increment relevant references
899  case BLOCK_DELETE: // Delete
900  case BLOCK_COPY: // Copy
901  case BLOCK_FLIP: // Flip
902  case BLOCK_ZOOM: // Window Zoom
903  case BLOCK_PRESELECT_MOVE: // Move with preselection list
904  block->InitData( m_canvas, aPosition );
905  break;
906 
907  case BLOCK_PASTE:
908  block->InitData( m_canvas, aPosition );
909  block->SetLastCursorPosition( wxPoint( 0, 0 ) );
911 
912  if( block->GetCount() == 0 ) // No data to paste
913  {
914  DisplayError( this, wxT( "No block to paste" ), 20 );
917  block->SetState( STATE_NO_BLOCK );
918  block->SetMessageBlock( this );
919  return true;
920  }
921 
922  if( !m_canvas->IsMouseCaptured() )
923  {
924  block->ClearItemsList();
925  DisplayError( this,
926  wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: m_mouseCaptureCallback NULL" ) );
927  block->SetState( STATE_NO_BLOCK );
928  block->SetMessageBlock( this );
929  return true;
930  }
931 
932  block->SetState( STATE_BLOCK_MOVE );
933  m_canvas->CallMouseCapture( aDC, aPosition, false );
934  break;
935 
936  default:
937  {
938  wxString msg;
939  msg << wxT( "EDA_DRAW_FRAME::HandleBlockBegin() error: Unknown command " ) <<
940  block->GetCommand();
941  DisplayError( this, msg );
942  }
943  break;
944  }
945 
946  block->SetMessageBlock( this );
947  return true;
948 }
949 
950 
951 // I am not seeing a problem with this size yet:
952 static const double MAX_AXIS = INT_MAX - 100;
953 
954 #define VIRT_MIN (-MAX_AXIS/2.0)
955 #define VIRT_MAX (MAX_AXIS/2.0)
956 
957 
958 void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
959 {
960  BASE_SCREEN* screen = GetScreen();
961 
962  if( !screen || !m_canvas )
963  return;
964 
965  double scale = screen->GetScalingFactor();
966 
967  wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scale = %.10g" ),
968  aCenterPositionIU.x, aCenterPositionIU.y, scale );
969 
970  // Calculate the portion of the drawing that can be displayed in the
971  // client area at the current zoom level.
972 
973  // visible viewport in device units ~ pixels
974  wxSize clientSizeDU = m_canvas->GetClientSize();
975 
976  // Size of the client window in IU
977  DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale );
978 
979  // Full drawing or "page" rectangle in internal units
980  DBOX pageRectIU( wxPoint( 0, 0 ), wxSize( GetPageSizeIU().x, GetPageSizeIU().y ) );
981 
982  // Remark: if something is modified here, perhaps EDA_DRAW_FRAME::RedrawScreen2()
983  // will need changes accordint to the way the center is computed
984  // Account for scrollbars
985  wxSize scrollbarSizeDU = m_canvas->GetSize() - m_canvas->GetClientSize();
986  wxSize scrollbarSizeIU = scrollbarSizeDU * (1 / scale);
987  wxPoint centerAdjustedIU = aCenterPositionIU + scrollbarSizeIU / 2;
988 
989  // The upper left corner of the client rectangle in internal units.
990  double xIU = centerAdjustedIU.x - clientSizeIU.x / 2.0;
991  double yIU = centerAdjustedIU.y - clientSizeIU.y / 2.0;
992 
993  // If drawn around the center, adjust the client rectangle accordingly.
994  if( screen->m_Center )
995  {
996  // half page offset.
997  xIU += pageRectIU.GetWidth() / 2.0;
998  yIU += pageRectIU.GetHeight() / 2.0;
999  }
1000 
1001  DBOX clientRectIU( wxPoint( xIU, yIU ), wxSize( clientSizeIU.x, clientSizeIU.y ) );
1002  wxPoint centerPositionIU;
1003 
1004  // put "int" limits on the clientRect
1005  if( clientRectIU.GetLeft() < VIRT_MIN )
1006  clientRectIU.MoveLeftTo( VIRT_MIN );
1007  if( clientRectIU.GetTop() < VIRT_MIN )
1008  clientRectIU.MoveTopTo( VIRT_MIN );
1009  if( clientRectIU.GetRight() > VIRT_MAX )
1010  clientRectIU.MoveRightTo( VIRT_MAX );
1011  if( clientRectIU.GetBottom() > VIRT_MAX )
1012  clientRectIU.MoveBottomTo( VIRT_MAX );
1013 
1014  centerPositionIU.x = KiROUND( clientRectIU.GetX() + clientRectIU.GetWidth() / 2 );
1015  centerPositionIU.y = KiROUND( clientRectIU.GetY() + clientRectIU.GetHeight() / 2 );
1016 
1017  if( screen->m_Center )
1018  {
1019  centerPositionIU.x -= KiROUND( pageRectIU.GetWidth() / 2.0 );
1020  centerPositionIU.y -= KiROUND( pageRectIU.GetHeight() / 2.0 );
1021  }
1022 
1023  DSIZE virtualSizeIU;
1024 
1025  if( pageRectIU.GetLeft() < clientRectIU.GetLeft() && pageRectIU.GetRight() > clientRectIU.GetRight() )
1026  {
1027  virtualSizeIU.x = pageRectIU.GetSize().x;
1028  }
1029  else
1030  {
1031  double pageCenterX = pageRectIU.GetX() + ( pageRectIU.GetWidth() / 2 );
1032  double clientCenterX = clientRectIU.GetX() + ( clientRectIU.GetWidth() / 2 );
1033 
1034  if( clientRectIU.GetWidth() > pageRectIU.GetWidth() )
1035  {
1036  if( pageCenterX > clientCenterX )
1037  virtualSizeIU.x = ( pageCenterX - clientRectIU.GetLeft() ) * 2;
1038  else if( pageCenterX < clientCenterX )
1039  virtualSizeIU.x = ( clientRectIU.GetRight() - pageCenterX ) * 2;
1040  else
1041  virtualSizeIU.x = clientRectIU.GetWidth();
1042  }
1043  else
1044  {
1045  if( pageCenterX > clientCenterX )
1046  virtualSizeIU.x = pageRectIU.GetWidth() + ( (pageRectIU.GetLeft() - clientRectIU.GetLeft() ) * 2 );
1047  else if( pageCenterX < clientCenterX )
1048  virtualSizeIU.x = pageRectIU.GetWidth() + ( (clientRectIU.GetRight() - pageRectIU.GetRight() ) * 2 );
1049  else
1050  virtualSizeIU.x = pageRectIU.GetWidth();
1051  }
1052  }
1053 
1054  if( pageRectIU.GetTop() < clientRectIU.GetTop() && pageRectIU.GetBottom() > clientRectIU.GetBottom() )
1055  {
1056  virtualSizeIU.y = pageRectIU.GetSize().y;
1057  }
1058  else
1059  {
1060  double pageCenterY = pageRectIU.GetY() + ( pageRectIU.GetHeight() / 2 );
1061  double clientCenterY = clientRectIU.GetY() + ( clientRectIU.GetHeight() / 2 );
1062 
1063  if( clientRectIU.GetHeight() > pageRectIU.GetHeight() )
1064  {
1065  if( pageCenterY > clientCenterY )
1066  virtualSizeIU.y = ( pageCenterY - clientRectIU.GetTop() ) * 2;
1067  else if( pageCenterY < clientCenterY )
1068  virtualSizeIU.y = ( clientRectIU.GetBottom() - pageCenterY ) * 2;
1069  else
1070  virtualSizeIU.y = clientRectIU.GetHeight();
1071  }
1072  else
1073  {
1074  if( pageCenterY > clientCenterY )
1075  virtualSizeIU.y = pageRectIU.GetHeight() +
1076  ( ( pageRectIU.GetTop() - clientRectIU.GetTop() ) * 2 );
1077  else if( pageCenterY < clientCenterY )
1078  virtualSizeIU.y = pageRectIU.GetHeight() +
1079  ( ( clientRectIU.GetBottom() - pageRectIU.GetBottom() ) * 2 );
1080  else
1081  virtualSizeIU.y = pageRectIU.GetHeight();
1082  }
1083  }
1084 
1085  // put "int" limits on the virtualSizeIU
1086  virtualSizeIU.x = std::min( virtualSizeIU.x, MAX_AXIS );
1087  virtualSizeIU.y = std::min( virtualSizeIU.y, MAX_AXIS );
1088 
1089  if( screen->m_Center )
1090  {
1091  screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 );
1092  screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 );
1093  }
1094  else
1095  {
1096  screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.GetWidth() ) / 2.0 );
1097  screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.GetHeight() ) / 2.0 );
1098  }
1099 
1100  /* Always set scrollbar pixels per unit to 1 unless you want the zoom
1101  * around cursor to jump around. This reported problem occurs when the
1102  * zoom point is not on a pixel per unit increment. If you set the
1103  * pixels per unit to 10, you have potential for the zoom point to
1104  * jump around +/-5 pixels from the nearest grid point.
1105  */
1106  screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1;
1107 
1108  // Number of scroll bar units for the given zoom level in device units.
1109  double unitsX = virtualSizeIU.x * scale;
1110  double unitsY = virtualSizeIU.y * scale;
1111 
1112  // Store the requested center position for later use
1113  SetScrollCenterPosition( aCenterPositionIU );
1114 
1115  // Calculate the scroll bar position in internal units to place the
1116  // center position at the center of client rectangle.
1117  double posX = centerPositionIU.x - clientRectIU.GetWidth() / 2.0 - screen->m_DrawOrg.x;
1118  double posY = centerPositionIU.y - clientRectIU.GetHeight() / 2.0 - screen->m_DrawOrg.y;
1119 
1120  // Convert scroll bar position to device units.
1121  posX = KiROUND( posX * scale );
1122  posY = KiROUND( posY * scale );
1123 
1124  if( posX < 0 )
1125  {
1126  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
1127  posX = 0;
1128  }
1129 
1130  if( posX > unitsX )
1131  {
1132  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
1133  posX = unitsX;
1134  }
1135 
1136  if( posY < 0 )
1137  {
1138  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
1139  posY = 0;
1140  }
1141 
1142  if( posY > unitsY )
1143  {
1144  wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
1145  posY = unitsY;
1146  }
1147 
1148  screen->m_ScrollbarPos = wxPoint( KiROUND( posX ), KiROUND( posY ) );
1149  screen->m_ScrollbarNumber = wxSize( KiROUND( unitsX ), KiROUND( unitsY ) );
1150 
1151  wxLogTrace( traceScrollSettings,
1152  wxT( "Drawing = (%.10g, %.10g), Client = (%.10g, %.10g), Offset = (%d, %d), SetScrollbars(%d, %d, %d, %d, %d, %d)" ),
1153  virtualSizeIU.x, virtualSizeIU.y, clientSizeIU.x, clientSizeIU.y,
1154  screen->m_DrawOrg.x, screen->m_DrawOrg.y,
1156  screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y,
1157  screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y );
1158 
1159  bool noRefresh = true;
1160 
1161  m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX,
1162  screen->m_ScrollPixelsPerUnitY,
1163  screen->m_ScrollbarNumber.x,
1164  screen->m_ScrollbarNumber.y,
1165  screen->m_ScrollbarPos.x,
1166  screen->m_ScrollbarPos.y, noRefresh );
1167 }
1168 
1169 
1170 void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
1171 {
1172  KIGFX::VIEW* view = GetGalCanvas()->GetView();
1173  KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
1174 
1175  // Display the same view after canvas switching
1176  if( aEnable )
1177  {
1178  // Switch to GAL renderer from legacy
1179  if( !m_galCanvasActive )
1180  {
1181  // Set up viewport
1182  view->SetScale( GetZoomLevelCoeff() / m_canvas->GetZoom() );
1184  }
1185 
1186  // Set up grid settings
1187  gal->SetGridVisibility( IsGridVisible() );
1188  gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
1189  gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
1190 
1191  // Transfer EDA_DRAW_PANEL settings
1192  KIGFX::VIEW_CONTROLS* viewControls = GetGalCanvas()->GetViewControls();
1193  viewControls->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() );
1195  viewControls->EnableAutoPan( m_canvas->GetEnableAutoPan() );
1196  }
1197  else if( m_galCanvasActive )
1198  {
1199  // Switch to legacy renderer from GAL
1200  m_canvas->SetZoom( GetGalCanvas()->GetLegacyZoom() );
1201  VECTOR2D center = view->GetCenter();
1202  AdjustScrollBars( wxPoint( center.x, center.y ) );
1203  }
1204 
1205  m_canvas->SetEvtHandlerEnabled( !aEnable );
1206  GetGalCanvas()->SetEvtHandlerEnabled( aEnable );
1207 
1208  // Switch panes
1209  m_auimgr.GetPane( "DrawFrame" ).Show( !aEnable );
1210  m_auimgr.GetPane( "DrawFrameGal" ).Show( aEnable );
1211  m_auimgr.Update();
1212 
1213  // Reset current tool on switch();
1215 
1216  m_galCanvasActive = aEnable;
1217 }
1218 
1219 
1221 {
1222  auto galCanvas = GetGalCanvas();
1223  wxCHECK( galCanvas, false );
1224  bool use_gal = galCanvas->SwitchBackend( aCanvasType );
1225  use_gal &= aCanvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1226  UseGalCanvas( use_gal );
1227  m_canvasType = use_gal ? aCanvasType : EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1228 
1229  return use_gal;
1230 }
1231 
1232 
1234 {
1236  wxConfigBase* cfg = Kiface().KifaceSettings();
1237 
1238  if( cfg )
1239  {
1240  canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE)
1242  }
1243 
1244  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1245  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1246  {
1247  assert( false );
1248  canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
1249  }
1250 
1251  // Coerce the value into a GAL type when Legacy is not available
1252  // Default to Cairo, and on the first, user will be prompted for OpenGL
1253  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1254  && !ADVANCED_CFG::GetCfg().AllowLegacyCanvas() )
1255  {
1256 #ifdef __WXMAC__
1257  // Cairo renderer doesn't handle Retina displays
1259 #else
1261 #endif
1262  }
1263 
1264  return canvasType;
1265 }
1266 
1267 
1269 {
1270  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
1271  // have a fixed type, or do not have a option to set the canvas type (they inherit from
1272  // a parent frame)
1273  FRAME_T allowed_frames[] =
1274  {
1276  };
1277 
1278  bool allow_save = false;
1279 
1280  for( int ii = 0; ii < 3; ii++ )
1281  {
1282  if( m_Ident == allowed_frames[ii] )
1283  {
1284  allow_save = true;
1285  break;
1286  }
1287  }
1288 
1289  if( !allow_save )
1290  return false;
1291 
1292  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
1293  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1294  {
1295  wxASSERT( false );
1296  return false;
1297  }
1298 
1299  wxConfigBase* cfg = Kiface().KifaceSettings();
1300 
1301  if( cfg )
1302  return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
1303 
1304  return false;
1305 }
1306 
1307 //-----< BASE_SCREEN API moved here >--------------------------------------------
1308 
1309 wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const
1310 {
1311  // subject to change, borrow from old BASE_SCREEN for now.
1312  if( IsGalCanvasActive() )
1313  {
1315 
1316  return wxPoint( cursor.x, cursor.y );
1317  }
1318  else
1319  {
1320  BASE_SCREEN* screen = GetScreen(); // virtual call
1321  return screen->getCrossHairPosition( aInvertY );
1322  }
1323 }
1324 
1325 
1326 void EDA_DRAW_FRAME::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
1327 {
1328  BASE_SCREEN* screen = GetScreen(); // virtual call
1329  screen->setCrossHairPosition( aPosition, GetGridOrigin(), aSnapToGrid );
1330 }
1331 
1332 
1333 wxPoint EDA_DRAW_FRAME::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) const
1334 {
1335  BASE_SCREEN* screen = GetScreen(); // virtual call
1336  return screen->getCursorPosition( aOnGrid, GetGridOrigin(), aGridSize );
1337 }
1338 
1339 
1340 wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize ) const
1341 {
1342  BASE_SCREEN* screen = GetScreen(); // virtual call
1343  return screen->getNearestGridPosition( aPosition, GetGridOrigin(), aGridSize );
1344 }
1345 
1346 
1348 {
1349  BASE_SCREEN* screen = GetScreen(); // virtual call
1350  return screen->getCrossHairScreenPosition();
1351 }
1352 
1353 
1354 void EDA_DRAW_FRAME::SetMousePosition( const wxPoint& aPosition )
1355 {
1356  BASE_SCREEN* screen = GetScreen(); // virtual call
1357  screen->setMousePosition( aPosition );
1358 }
1359 
1360 
1361 wxPoint EDA_DRAW_FRAME::RefPos( bool useMouse ) const
1362 {
1363  BASE_SCREEN* screen = GetScreen(); // virtual call
1364  return screen->refPos( useMouse );
1365 }
1366 
1367 
1368 const wxPoint& EDA_DRAW_FRAME::GetScrollCenterPosition() const
1369 {
1370  BASE_SCREEN* screen = GetScreen(); // virtual call
1371  return screen->getScrollCenterPosition();
1372 }
1373 
1374 
1375 void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint )
1376 {
1377  BASE_SCREEN* screen = GetScreen(); // virtual call
1378  screen->setScrollCenterPosition( aPoint );
1379 }
1380 
1381 //-----</BASE_SCREEN API moved here >--------------------------------------------
1382 
1383 void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC* aDC )
1384 {
1385  wxPoint newpos = GetCrossHairPosition();
1386 
1387  // Redraw the crosshair if it moved
1388  if( aOldPos != newpos )
1389  {
1390  SetCrossHairPosition( aOldPos, false );
1391  m_canvas->CrossHairOff( aDC );
1392  SetCrossHairPosition( newpos, false );
1393  m_canvas->CrossHairOn( aDC );
1394 
1395  if( m_canvas->IsMouseCaptured() )
1396  {
1397 #ifdef USE_WX_OVERLAY
1398  wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
1399  oDC.Clear();
1400  m_canvas->CallMouseCapture( aDC, aEvtPos, false );
1401 #else
1402  m_canvas->CallMouseCapture( aDC, aEvtPos, true );
1403 #endif
1404  }
1405 #ifdef USE_WX_OVERLAY
1406  else
1407  {
1408  m_overlay.Reset();
1409  }
1410 #endif
1411  }
1412 }
1413 
1414 
1415 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
1416  const wxString& wildcard, const wxString& ext,
1417  bool isDirectory )
1418 {
1419  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
1420  aFilename.SetExt( ext );
1421 
1422 #ifndef __WXMAC__
1423  if( isDirectory && doOpen )
1424  {
1425  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
1426  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1427 
1428  if( dlg.ShowModal() == wxID_CANCEL )
1429  return false;
1430 
1431  aFilename = dlg.GetPath();
1432  aFilename.SetExt( ext );
1433  }
1434  else
1435 #endif
1436  {
1437  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
1438  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1439  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1440 
1441  if( dlg.ShowModal() == wxID_CANCEL )
1442  return false;
1443 
1444  aFilename = dlg.GetPath();
1445  aFilename.SetExt( ext );
1446  }
1447 
1448  return true;
1449 }
1450 
1451 
1452 bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid )
1453 {
1454  bool key_handled = false;
1455 
1456  // If requested snap the current position to the grid
1457  if( aSnapToGrid )
1458  *aPos = GetNearestGridPosition( *aPos );
1459 
1460  switch( aHotKey )
1461  {
1462  // All these keys have almost the same treatment
1463  case GR_KB_CTRL | WXK_NUMPAD8:
1464  case GR_KB_CTRL | WXK_UP:
1465  case GR_KB_CTRL | WXK_NUMPAD2:
1466  case GR_KB_CTRL | WXK_DOWN:
1467  case GR_KB_CTRL | WXK_NUMPAD4:
1468  case GR_KB_CTRL | WXK_LEFT:
1469  case GR_KB_CTRL | WXK_NUMPAD6:
1470  case GR_KB_CTRL | WXK_RIGHT:
1471  case WXK_NUMPAD8:
1472  case WXK_UP:
1473  case WXK_NUMPAD2:
1474  case WXK_DOWN:
1475  case WXK_NUMPAD4:
1476  case WXK_LEFT:
1477  case WXK_NUMPAD6:
1478  case WXK_RIGHT:
1479  key_handled = true;
1480  {
1481  /* Here's a tricky part: when doing cursor key movement, the
1482  * 'previous' point should be taken from memory, *not* from the
1483  * freshly computed position in the event. Otherwise you can't do
1484  * sub-pixel movement. The m_movingCursorWithKeyboard oneshot 'eats'
1485  * the automatic motion event generated by cursor warping */
1486  wxRealPoint gridSize = GetScreen()->GetGridSize();
1487  *aPos = GetCrossHairPosition();
1488 
1489  // Bonus: ^key moves faster (x10)
1490  switch( aHotKey )
1491  {
1492  case GR_KB_CTRL|WXK_NUMPAD8:
1493  case GR_KB_CTRL|WXK_UP:
1494  aPos->y -= KiROUND( 10 * gridSize.y );
1495  break;
1496 
1497  case GR_KB_CTRL|WXK_NUMPAD2:
1498  case GR_KB_CTRL|WXK_DOWN:
1499  aPos->y += KiROUND( 10 * gridSize.y );
1500  break;
1501 
1502  case GR_KB_CTRL|WXK_NUMPAD4:
1503  case GR_KB_CTRL|WXK_LEFT:
1504  aPos->x -= KiROUND( 10 * gridSize.x );
1505  break;
1506 
1507  case GR_KB_CTRL|WXK_NUMPAD6:
1508  case GR_KB_CTRL|WXK_RIGHT:
1509  aPos->x += KiROUND( 10 * gridSize.x );
1510  break;
1511 
1512  case WXK_NUMPAD8:
1513  case WXK_UP:
1514  aPos->y -= KiROUND( gridSize.y );
1515  break;
1516 
1517  case WXK_NUMPAD2:
1518  case WXK_DOWN:
1519  aPos->y += KiROUND( gridSize.y );
1520  break;
1521 
1522  case WXK_NUMPAD4:
1523  case WXK_LEFT:
1524  aPos->x -= KiROUND( gridSize.x );
1525  break;
1526 
1527  case WXK_NUMPAD6:
1528  case WXK_RIGHT:
1529  aPos->x += KiROUND( gridSize.x );
1530  break;
1531 
1532  default: /* Can't happen since we entered the statement */
1533  break;
1534  }
1535 
1536  m_canvas->MoveCursor( *aPos );
1538  }
1539  break;
1540 
1541  default:
1542  break;
1543  }
1544 
1545  return key_handled;
1546 }
1547 
1548 
1549 void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
1550 {
1551  if( IsGalCanvasActive() )
1552  return;
1553 
1554  AdjustScrollBars( aCenterPoint );
1555 
1556  // Move the mouse cursor to the on grid graphic cursor position
1557  if( aWarpPointer )
1559 
1560  m_canvas->Refresh();
1561  m_canvas->Update();
1562 }
1563 
1564 
1565 void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore )
1566 {
1567  if( IsGalCanvasActive() )
1568  return;
1569 
1570  // Account for scrollbars (see EDA_DRAW_FRAME::AdjustScrollBars that takes
1571  // in account scroolbars area to adjust scroll bars)
1572  wxSize scrollbarSize = m_canvas->GetSize() - m_canvas->GetClientSize();
1573  wxSize sizeAdjusted = m_canvas->GetClientSize() - scrollbarSize;
1574 
1575  wxPoint dPos = posBefore - sizeAdjusted / 2;
1576 
1577  // screen position of crosshair after zoom
1578  wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1579  wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
1580 
1581  AdjustScrollBars( newCenter );
1582 
1583  m_canvas->Refresh();
1584  m_canvas->Update();
1585 }
1586 
1587 
1589 {
1590  m_canvas->Refresh();
1591  m_canvas->Update();
1592 }
1593 
1594 
1595 // Factor out the calculation portion of the various BestZoom() implementations.
1596 //
1597 // Note that like it's forerunners this routine has an intentional side-effect: it
1598 // sets the scroll centre position. While I'm not happy about that, it's probably
1599 // not worth fixing as its days are numbered (GAL canvases use a different method).
1600 double EDA_DRAW_FRAME::bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre )
1601 {
1602  double bestzoom = std::max( sizeX * scaleFactor / (double) m_canvas->GetClientSize().x,
1603  sizeY * scaleFactor / (double) m_canvas->GetClientSize().y );
1604 
1605  // Take scrollbars into account
1606  DSIZE scrollbarSize = m_canvas->GetSize() - m_canvas->GetClientSize();
1607  centre.x -= int( bestzoom * scrollbarSize.x / 2.0 );
1608  centre.y -= int( bestzoom * scrollbarSize.y / 2.0 );
1609 
1610  SetScrollCenterPosition( centre );
1611 
1612  return bestzoom;
1613 }
1614 
1615 
1616 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1617 {
1618  BASE_SCREEN* screen = GetScreen();
1619 
1620  // Set the best zoom and get center point.
1621 
1622  // BestZoom() can compute an illegal zoom if the client window size
1623  // is small, say because frame is not maximized. So use the clamping form
1624  // of SetZoom():
1625  double bestzoom = BestZoom();
1626  screen->SetScalingFactor( bestzoom );
1627 
1628  if( !screen->m_Initialized )
1630 
1631  if( !IsGalCanvasActive() )
1632  RedrawScreen( GetScrollCenterPosition(), aWarpPointer );
1633  else
1634  m_toolManager->RunAction( "common.Control.zoomFitScreen", true );
1635 }
1636 
1637 
1639 {
1640  // Compute the best zoom
1641  Rect.Normalize();
1642 
1643  wxSize size = m_canvas->GetClientSize();
1644 
1645  // Use ceil to at least show the full rect
1646  double scalex = (double) Rect.GetSize().x / size.x;
1647  double bestscale = (double) Rect.GetSize().y / size.y;
1648 
1649  bestscale = std::max( bestscale, scalex );
1650 
1651  GetScreen()->SetScalingFactor( bestscale );
1652  RedrawScreen( Rect.Centre(), true );
1653 }
1654 
1655 
1656 void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
1657 {
1658  if( m_canvas == NULL )
1659  return;
1660 
1661  int id = event.GetId();
1662  bool zoom_at_cursor = false;
1663  BASE_SCREEN* screen = GetScreen();
1664  wxPoint center = GetScrollCenterPosition();
1665 
1666  if ( id == ID_KEY_ZOOM_IN )
1667  {
1668  id = GetCanvas()->GetEnableZoomNoCenter() ?
1670  }
1671  else if ( id == ID_KEY_ZOOM_OUT )
1672  {
1673  id = GetCanvas()->GetEnableZoomNoCenter() ?
1675  }
1676 
1677  switch( id )
1678  {
1679  case ID_OFFCENTER_ZOOM_IN:
1680  center = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1681 
1682  if( screen->SetPreviousZoom() )
1683  RedrawScreen2( center );
1684  break;
1685 
1686  case ID_POPUP_ZOOM_IN:
1687  zoom_at_cursor = true;
1688  center = GetCrossHairPosition();
1689 
1690  // fall thru
1691  case ID_VIEWER_ZOOM_IN:
1692  case ID_ZOOM_IN:
1693  if( screen->SetPreviousZoom() )
1694  RedrawScreen( center, zoom_at_cursor );
1695  break;
1696 
1697  case ID_OFFCENTER_ZOOM_OUT:
1698  center = m_canvas->ToDeviceXY( GetCrossHairPosition() );
1699 
1700  if( screen->SetNextZoom() )
1701  RedrawScreen2( center );
1702  break;
1703 
1704  case ID_POPUP_ZOOM_OUT:
1705  zoom_at_cursor = true;
1706  center = GetCrossHairPosition();
1707 
1708  // fall thru
1709  case ID_VIEWER_ZOOM_OUT:
1710  case ID_ZOOM_OUT:
1711  if( screen->SetNextZoom() )
1712  RedrawScreen( center, zoom_at_cursor );
1713  break;
1714 
1715  case ID_VIEWER_ZOOM_REDRAW:
1716  case ID_POPUP_ZOOM_REDRAW:
1717  case ID_ZOOM_REDRAW:
1718  // This usually means something went wrong. Do a hard refresh.
1719  SetScreen( GetScreen() );
1720  break;
1721 
1722  case ID_POPUP_ZOOM_CENTER:
1723  center = GetCrossHairPosition();
1724  RedrawScreen( center, true );
1725  break;
1726 
1727  case ID_POPUP_ZOOM_PAGE:
1728  case ID_VIEWER_ZOOM_PAGE:
1729  case ID_ZOOM_PAGE:
1730  Zoom_Automatique( false );
1731  break;
1732 
1733  case ID_POPUP_ZOOM_SELECT:
1734  break;
1735 
1736  case ID_POPUP_CANCEL:
1738  break;
1739 
1740  default:
1742  }
1743 
1744  UpdateStatusBar();
1745 }
1746 
1747 
1749 {
1750  GetScreen()->SetNextZoom();
1751 }
1752 
1753 
1755 {
1757 }
1758 
1759 
1761 {
1762  BASE_SCREEN* screen = GetScreen();
1763 
1764  if( aIndex >= (int) screen->m_ZoomList.size() )
1765  {
1766  wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
1767  __TFILE__, __LINE__, aIndex );
1768  return;
1769  }
1770 
1771  if( m_zoomSelectBox )
1772  m_zoomSelectBox->SetSelection( aIndex );
1773 
1774  if( screen->SetZoom( screen->m_ZoomList[aIndex] ) )
1776 
1777  UpdateStatusBar();
1778 }
1779 
1780 
1781 void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
1782 {
1783  int maxZoomIds;
1784  double zoom;
1785  wxString msg;
1786  BASE_SCREEN* screen = m_canvas->GetScreen();
1787 
1788  msg = AddHotkeyName( _( "Center" ), m_hotkeysDescrList, HK_ZOOM_CENTER );
1789  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_CENTER, msg, KiBitmap( zoom_center_on_screen_xpm ) );
1790  msg = AddHotkeyName( _( "Zoom In" ), m_hotkeysDescrList, HK_ZOOM_IN );
1791  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_IN, msg, KiBitmap( zoom_in_xpm ) );
1792  msg = AddHotkeyName( _( "Zoom Out" ), m_hotkeysDescrList, HK_ZOOM_OUT );
1793  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_OUT, msg, KiBitmap( zoom_out_xpm ) );
1794  msg = AddHotkeyName( _( "Redraw View" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
1795  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_REDRAW, msg, KiBitmap( zoom_redraw_xpm ) );
1796  msg = AddHotkeyName( _( "Zoom to Fit" ), m_hotkeysDescrList, HK_ZOOM_AUTO );
1797  AddMenuItem( MasterMenu, ID_POPUP_ZOOM_PAGE, msg, KiBitmap( zoom_fit_in_page_xpm ) );
1798 
1799 
1800  wxMenu* zoom_choice = new wxMenu;
1801  AddMenuItem( MasterMenu, zoom_choice,
1802  ID_POPUP_ZOOM_SELECT, _( "Zoom" ),
1803  KiBitmap( zoom_selection_xpm ) );
1804 
1805  zoom = screen->GetZoom();
1807  maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.size() ) ?
1808  maxZoomIds : screen->m_ZoomList.size();
1809 
1810  // Populate zoom submenu.
1811  for( int i = 0; i < maxZoomIds; i++ )
1812  {
1813  msg.Printf( wxT( "%.2f" ), m_zoomLevelCoeff / screen->m_ZoomList[i] );
1814 
1815  zoom_choice->Append( ID_POPUP_ZOOM_LEVEL_START + i, _( "Zoom: " ) + msg,
1816  wxEmptyString, wxITEM_CHECK );
1817  if( zoom == screen->m_ZoomList[i] )
1818  zoom_choice->Check( ID_POPUP_ZOOM_LEVEL_START + i, true );
1819  }
1820 
1821  // Create grid submenu as required.
1822  if( screen->GetGridCount() )
1823  {
1824  wxMenu* gridMenu = new wxMenu;
1825  AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT,
1826  _( "Grid" ), KiBitmap( grid_select_xpm ) );
1827 
1828  wxArrayString gridsList;
1829  int icurr = screen->BuildGridsChoiceList( gridsList, GetUserUnits() != INCHES );
1830 
1831  for( unsigned i = 0; i < gridsList.GetCount(); i++ )
1832  {
1833  GRID_TYPE& grid = screen->GetGrid( i );
1834  gridMenu->Append( grid.m_CmdId, gridsList[i], wxEmptyString, wxITEM_CHECK );
1835 
1836  if( (int)i == icurr )
1837  gridMenu->Check( grid.m_CmdId, true );
1838  }
1839  }
1840 
1841  MasterMenu->AppendSeparator();
1842  AddMenuItem( MasterMenu, ID_POPUP_CANCEL, _( "Close" ), KiBitmap( cancel_xpm ) );
1843 }
1844 
1845 
1846 // Find the first child dialog.
1847 wxWindow* findDialog( wxWindowList& aList )
1848 {
1849  for( wxWindow* window : aList )
1850  {
1851  if( dynamic_cast<DIALOG_SHIM*>( window ) )
1852  return window;
1853  }
1854  return NULL;
1855 }
1856 
1857 
1858 void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aWarpCursor, bool aCenterView )
1859 {
1860  if( IsGalCanvasActive() )
1861  {
1862  if( aCenterView )
1863  {
1864  wxWindow* dialog = findDialog( GetChildren() );
1865 
1866  // If a dialog partly obscures the window, then center on the uncovered area.
1867  if( dialog )
1868  {
1869  wxRect dialogRect( GetGalCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
1870  dialog->GetSize() );
1871  GetGalCanvas()->GetView()->SetCenter( aPos, dialogRect );
1872  }
1873  else
1874  GetGalCanvas()->GetView()->SetCenter( aPos );
1875  }
1876 
1877  if( aWarpCursor )
1879  else
1881  }
1882  else
1883  {
1885 
1886  // There may be need to reframe the drawing.
1887  if( aCenterView || !m_canvas->IsPointOnDisplay( aPos ) )
1888  {
1889  SetCrossHairPosition( aPos );
1890  RedrawScreen( aPos, aWarpCursor );
1891  }
1892  else
1893  {
1894  // Put cursor on item position
1895  m_canvas->CrossHairOff( &dc );
1896  SetCrossHairPosition( aPos );
1897 
1898  if( aWarpCursor )
1900  }
1901 
1902  // Be sure cross hair cursor is ON:
1903  m_canvas->CrossHairOn( &dc );
1904  m_canvas->CrossHairOn( &dc );
1905  }
1906 }
1907 
1908 
1909 static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );
1910 
1911 
1912 void EDA_DRAW_FRAME::CopyToClipboard( wxCommandEvent& event )
1913 {
1914  DrawPageOnClipboard( this );
1915 
1916  if( event.GetId() == ID_GEN_COPY_BLOCK_TO_CLIPBOARD )
1917  {
1918  if( GetScreen()->IsBlockActive() )
1919  m_canvas->SetCursor( wxCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ) );
1920 
1922  }
1923 }
1924 
1925 
1926 /* copy the current page or block to the clipboard ,
1927  * to export drawings to other applications (word processing ...)
1928  * This is not suitable for copy command within Eeschema or Pcbnew
1929  */
1931 {
1932  bool DrawBlock = false;
1933  wxRect DrawArea;
1934  BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();
1935 
1936  if( screen->IsBlockActive() )
1937  {
1938  DrawBlock = true;
1939  DrawArea.SetX( screen->m_BlockLocate.GetX() );
1940  DrawArea.SetY( screen->m_BlockLocate.GetY() );
1941  DrawArea.SetWidth( screen->m_BlockLocate.GetWidth() );
1942  DrawArea.SetHeight( screen->m_BlockLocate.GetHeight() );
1943  }
1944  else
1945  DrawArea.SetSize( aFrame->GetPageSizeIU() );
1946 
1947  // Calculate a reasonable dc size, in pixels, and the dc scale to fit
1948  // the drawings into the dc size
1949  // scale is the ratio resolution (in PPI) / internal units
1950  double ppi = 300; // Use 300 pixels per inch to create bitmap images on start
1951  double inch2Iu = 1000.0 * (double) screen->MilsToIuScalar();
1952  double scale = ppi / inch2Iu;
1953 
1954  wxSize dcsize = DrawArea.GetSize();
1955 
1956  int maxdim = std::max( dcsize.x, dcsize.y );
1957 
1958  // the max size in pixels of the bitmap used to byuild the sheet copy
1959  const int maxbitmapsize = 3000;
1960 
1961  while( int( maxdim * scale ) > maxbitmapsize )
1962  {
1963  ppi = ppi / 1.5;
1964  scale = ppi / inch2Iu;
1965  }
1966 
1967  dcsize.x *= scale;
1968  dcsize.y *= scale;
1969 
1970  // Set draw offset, zoom... to values needed to draw in the memory DC
1971  // after saving initial values:
1972  wxPoint tmp_startvisu = screen->m_StartVisu;
1973  double tmpzoom = screen->GetZoom();
1974  wxPoint old_org = screen->m_DrawOrg;
1975  screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
1976  screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
1977 
1978  screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
1979 
1980  wxMemoryDC dc;
1981  wxBitmap image( dcsize );
1982  dc.SelectObject( image );
1983 
1984  EDA_RECT tmp = *aFrame->GetCanvas()->GetClipBox();
1985  GRResetPenAndBrush( &dc );
1986  GRForceBlackPen( false );
1987  screen->m_IsPrinting = true;
1988  dc.SetUserScale( scale, scale );
1989 
1990  aFrame->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
1991  wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) );
1992 
1993  if( DrawBlock )
1994  {
1995  dc.SetClippingRegion( DrawArea );
1996  }
1997 
1998  dc.Clear();
1999  aFrame->GetCanvas()->EraseScreen( &dc );
2000  const LSET allLayersMask = LSET().set();
2001  aFrame->PrintPage( &dc, allLayersMask, false );
2002  screen->m_IsPrinting = false;
2003  aFrame->GetCanvas()->SetClipBox( tmp );
2004 
2005  bool success = true;
2006 
2007  if( wxTheClipboard->Open() )
2008  {
2009  // This data objects are held by the clipboard,
2010  // so do not delete them in the app.
2011  wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
2012  wxTheClipboard->SetData( clipbrd_data );
2013  wxTheClipboard->Close();
2014  }
2015  else
2016  success = false;
2017 
2018  // Deselect Bitmap from DC in order to delete the MemoryDC safely
2019  // without deleting the bitmap
2020  dc.SelectObject( wxNullBitmap );
2021 
2022  GRForceBlackPen( false );
2023 
2024  screen->m_StartVisu = tmp_startvisu;
2025  screen->m_DrawOrg = old_org;
2026  screen->SetZoom( tmpzoom );
2027 
2028  return success;
2029 }
2030 
2031 
2032 void DrawPageLayout( wxDC* aDC, EDA_RECT* aClipBox,
2033  const PAGE_INFO& aPageInfo,
2034  const wxString &aFullSheetName,
2035  const wxString& aFileName,
2036  TITLE_BLOCK& aTitleBlock,
2037  int aSheetCount, int aSheetNumber,
2038  int aPenWidth, double aScalar,
2039  COLOR4D aColor, COLOR4D aAltColor,
2040  const wxString& aSheetLayer )
2041 {
2042  WS_DRAW_ITEM_LIST drawList;
2043 
2044  drawList.SetPenSize( aPenWidth );
2045  drawList.SetMilsToIUfactor( aScalar );
2046  drawList.SetSheetNumber( aSheetNumber );
2047  drawList.SetSheetCount( aSheetCount );
2048  drawList.SetFileName( aFileName );
2049  drawList.SetSheetName( aFullSheetName );
2050  drawList.SetSheetLayer( aSheetLayer );
2051 
2052  drawList.BuildWorkSheetGraphicList( aPageInfo,
2053  aTitleBlock, aColor, aAltColor );
2054 
2055  // Draw item list
2056  drawList.Draw( aClipBox, aDC );
2057 }
2058 
2059 
2060 void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
2061  double aScalar, const wxString &aFilename,
2062  const wxString &aSheetLayer )
2063 {
2065  return;
2066 
2067  const PAGE_INFO& pageInfo = GetPageSettings();
2068  wxSize pageSize = pageInfo.GetSizeMils();
2069 
2070  // if not printing, draw the page limits:
2071  if( !aScreen->m_IsPrinting && m_showPageLimits )
2072  {
2073  GRSetDrawMode( aDC, GR_COPY );
2074  GRRect( m_canvas->GetClipBox(), aDC, 0, 0,
2075  pageSize.x * aScalar, pageSize.y * aScalar, aLineWidth,
2077  }
2078 
2079  TITLE_BLOCK t_block = GetTitleBlock();
2080  COLOR4D color = COLOR4D( RED );
2081 
2082  wxPoint origin = aDC->GetDeviceOrigin();
2083 
2084  if( aScreen->m_IsPrinting && origin.y > 0 )
2085  {
2086  aDC->SetDeviceOrigin( 0, 0 );
2087  aDC->SetAxisOrientation( true, false );
2088  }
2089 
2090  DrawPageLayout( aDC, m_canvas->GetClipBox(), pageInfo,
2091  GetScreenDesc(), aFilename, t_block,
2092  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber,
2093  aLineWidth, aScalar, color, color, aSheetLayer );
2094 
2095  if( aScreen->m_IsPrinting && origin.y > 0 )
2096  {
2097  aDC->SetDeviceOrigin( origin.x, origin.y );
2098  aDC->SetAxisOrientation( true, true );
2099  }
2100 }
2101 
2102 
2103 wxString EDA_DRAW_FRAME::GetScreenDesc() const
2104 {
2105  // Virtual function. In basic class, returns
2106  // an empty string.
2107  return wxEmptyString;
2108 }
2109 
2110 
2112 {
2113  BOX2I rv;
2114  rv.SetMaximum();
2115  return rv;
2116 }
2117 
2118 
2119 bool EDA_DRAW_FRAME::saveCanvasImageToFile( const wxString& aFileName, wxBitmapType aBitmapType )
2120 {
2121  return SaveCanvasImageToFile( this, aFileName, aBitmapType );
2122 }
virtual BASE_SCREEN * GetScreen()=0
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:130
virtual void ReCreateMenuBar() override
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
Notification event that some of the common (suite-wide) settings have changed.
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:127
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
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:102
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:949
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
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:70
ACTION_TOOLBAR * m_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window.
Definition: draw_frame.h:159
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:131
virtual void SetEnableZoomNoCenter(bool aEnable)
coord_type GetTop() const
Definition: box2.h:202
ACTION_TOOLBAR * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:166
#define DEFAULT_MAX_UNDO_ITEMS
Definition: draw_frame.h:48
void ReadCommonConfig(wxConfigBase &aCommonConfig, wxWindow *aWindow)
Read GAL config options from the common config store.
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:184
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:251
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:182
virtual double BestZoom()=0
Return the zoom level which displays the full page on screen.
virtual void OnGridSettings(wxCommandEvent &event)
Definition: draw_frame.h:602
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:533
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:931
void OnMouseEvent(wxMouseEvent &event)
virtual void SaveSettings(wxConfigBase *aCfg)
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:235
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:106
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()
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:239
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...
ACTION_TOOLBAR * m_mainToolBar
Definition: draw_frame.h:156
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:558
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:82
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:118
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:153
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:108
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
virtual void InitBlockPasteInfos()
void ReadConfig(wxConfigBase &aCommonConfig, wxConfigBase &aAppCondfig, const wxString &aBaseCfgName, wxWindow *aWindow)
Read application and common configs.
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:64
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:49
#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:115
void DisplayUnitsMsg()
Display current unit pane on the status bar.
bool saveCanvasImageToFile(const wxString &aFileName, wxBitmapType aBitmapType=wxBITMAP_TYPE_PNG)
void OnUpdateUndo(wxUpdateUIEvent &aEvent)
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:924
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.
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
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:52
#define DEFAULT_FILE_HISTORY_SIZE
The default file history size is 9.
Definition: pgm_base.h:61
Class LSET is a set of PCB_LAYER_IDs.
a helper to handle the real device context used in KiCad
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:92
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:475
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:110
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.
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:169
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:148
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:289
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:158
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:154
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
TOOL_MANAGER * GetToolManager() const override
Return the tool manager instance, if any.
Definition: draw_frame.h:937
void WriteConfig(wxConfigBase &aCfg, const wxString &aBaseName)
virtual void LoadSettings(wxConfigBase *aCfg)
Load 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:50
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:53
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:71
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
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:123
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:399
void EraseMsgBox()
Definition: msgpanel.cpp:216
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:321
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:112
virtual COLOR4D GetGridColor()
Definition: draw_frame.h:550
virtual void ClearMsgPanel()
Clear all messages from the message panel.
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:190
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
bool m_IsPrinting
Definition: base_screen.h:220
Definition: solve.cpp:178
void LoadSettings(wxConfigBase *aCfg) override
Load 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:48
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:96
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:107
wxSocketServer * m_socketServer
Definition: draw_frame.h:105
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:128
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)
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...
void SetAutoSaveInterval(int aInterval)
double m_zoomLevelCoeff
a suitable value to convert the internal zoom scaling factor
Definition: draw_frame.h:120
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 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)
Store the current hotkey list.
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
Definition: draw_frame.h:66
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
Definition: draw_frame.h:99
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:157
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:116
wxPoint Centre() const
Definition: eda_rect.h:60
wxString m_toolMsg
Definition: draw_frame.h:90
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()
Notification event that some of the common (suite-wide) settings have changed.
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:542
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.
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.
virtual void EraseScreen(wxDC *DC)
Function OnMouseWheel handles mouse wheel events.
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:125
ACTIONS * m_actions
Definition: draw_frame.h:132
#define GridColorEntryKeyword
Grid color ID (suffix)
Definition: draw_frame.h:68
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:244
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:408
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:179
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:157
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:151
void SetUserUnits(EDA_UNITS_T aUnits)
Definition: draw_frame.h:290
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:94
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
ACTION_TOOLBAR * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:163
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_ADD_FOOTPRINT_TO_BOARD
void MoveRightTo(coord_type aRight)
Definition: box2.h:206
virtual const BOX2I GetDocumentExtents() const
void SetIgnoreLeftButtonReleaseEvent(bool aIgnore)
File locking utilities.