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