KiCad PCB EDA Suite
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-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <fctsys.h>
27 #include <pgm_base.h>
28 #include <kiface_i.h>
29 #include <bitmaps.h>
30 #include <macros.h>
31 #include <id.h>
32 #include <base_screen.h>
33 #include <msgpanel.h>
34 #include <eda_draw_frame.h>
35 #include <confirm.h>
36 #include <dialog_helpers.h>
37 #include <lockfile.h>
38 #include <trace_helpers.h>
39 #include <wx/snglinst.h>
40 #include <view/view.h>
41 #include <tool/tool_manager.h>
42 #include <tool/action_manager.h>
43 #include <tool/tool_dispatcher.h>
44 #include <tool/actions.h>
45 #include <ws_draw_item.h>
46 #include <page_info.h>
47 #include <title_block.h>
48 #include <tool/tool_menu.h>
50 #include <tool/zoom_menu.h>
51 #include <tool/grid_menu.h>
52 #include <tool/common_tools.h>
53 #include <dialog_shim.h>
54 
55 
58 static const wxChar FirstRunShownKeyword[] = wxT( "FirstRunShown" );
59 
60 static const wxChar FindReplaceFlagsEntry[] = wxT( "LastFindReplaceFlags" );
61 static const wxChar FindStringEntry[] = wxT( "LastFindString" );
62 static const wxChar ReplaceStringEntry[] = wxT( "LastReplaceString" );
63 static const wxChar FindStringHistoryEntry[] = wxT( "FindStringHistoryList%d" );
64 static const wxChar ReplaceStringHistoryEntry[] = wxT( "ReplaceStringHistoryList%d" );
66 
67 #define FR_HISTORY_LIST_CNT 10
68 
69 
82 static const wxString MaxUndoItemsEntry(wxT( "DevelMaxUndoItems" ) );
83 
84 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
85  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
86  long aStyle, const wxString & aFrameName ) :
87  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
88 {
89  m_socketServer = nullptr;
90  m_mainToolBar = NULL;
91  m_drawToolBar = NULL;
92  m_optionsToolBar = NULL;
93  m_auxiliaryToolBar = NULL;
94  m_gridSelectBox = NULL;
95  m_zoomSelectBox = NULL;
98 
100  m_canvas = NULL;
101  m_toolDispatcher = NULL;
102  m_messagePanel = NULL;
103  m_currentScreen = NULL;
104  m_showBorderAndTitleBlock = false; // true to display reference sheet.
105  m_LastGridSizeId = 0;
106  m_drawGrid = true; // hide/Show grid. default = show
107  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
108  m_showPageLimits = false;
109  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
110  // BLACK for Pcbnew, BLACK or WHITE for eeschema
112  m_zoomLevelCoeff = 1.0;
114  m_PolarCoords = false;
115  m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
116 
117  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
118 
119  CreateStatusBar( 7 );
120 
121  // set the size of the status bar subwindows:
122 
123  wxWindow* stsbar = GetStatusBar();
124 
125  int dims[] = {
126 
127  // remainder of status bar on far left is set to a default or whatever is left over.
128  -1,
129 
130  // When using GetTextSize() remember the width of character '1' is not the same
131  // as the width of '0' unless the font is fixed width, and it usually won't be.
132 
133  // zoom:
134  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
135 
136  // cursor coords
137  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
138 
139  // delta distances
140  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
141 
142  // grid size
143  GetTextSize( wxT( "grid X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
144 
145  // units display, Inches is bigger than mm
146  GetTextSize( _( "Inches" ), stsbar ).x + 10,
147 
148  // Size for the "Current Tool" panel; longest string from SetTool()
149  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
150  };
151 
152  SetStatusWidths( arrayDim( dims ), dims );
153 
154  // Create child subwindows.
155  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
156  m_FramePos.x = m_FramePos.y = 0;
158 
159  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
160  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
161 
162  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
163 }
164 
165 
167 {
168  delete m_socketServer;
169 
170  for( auto socket : m_sockets )
171  {
172  socket->Shutdown();
173  socket->Destroy();
174  }
175 
177 
178  delete m_actions;
179  delete m_toolManager;
180  delete m_toolDispatcher;
181  delete m_canvas;
182 
183  delete m_currentScreen;
184  m_currentScreen = NULL;
185 
186  delete m_findReplaceData;
187 
188  m_auimgr.UnInit();
189 
190  ReleaseFile();
191 }
192 
193 
195 {
196  m_file_checker = nullptr;
197 }
198 
199 
200 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
201 {
202  m_file_checker = ::LockFile( aFileName );
203 
204  return bool( m_file_checker );
205 }
206 
207 
209 {
210  UpdateStatusBar();
211  UpdateMsgPanel();
212 }
213 
214 
215 void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
216 {
217  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
218 
219  wxConfigBase* settings = Pgm().CommonSettings();
220  KIGFX::VIEW_CONTROLS* viewControls = GetCanvas()->GetViewControls();
221 
222  int autosaveInterval;
223  settings->Read( AUTOSAVE_INTERVAL_KEY, &autosaveInterval );
224  SetAutoSaveInterval( autosaveInterval );
225 
226  int historySize;
227  settings->Read( FILE_HISTORY_SIZE_KEY, &historySize, DEFAULT_FILE_HISTORY_SIZE );
228  Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
229 
230  bool option;
231  settings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
232  viewControls->EnableMousewheelPan( option );
233 
234  settings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
235  viewControls->EnableCursorWarping( !option );
236 
237  settings->Read( ENBL_AUTO_PAN_KEY, &option );
238  viewControls->EnableAutoPan( option );
239 
240  m_galDisplayOptions.ReadCommonConfig( *settings, this );
241 }
242 
243 
245 {
246  if( m_messagePanel )
248 }
249 
250 
251 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
252 {
253  // No need to update the grid select box if it doesn't exist or the grid setting change
254  // was made using the select box.
255  if( m_gridSelectBox == NULL )
256  return;
257 
258  int select = wxNOT_FOUND;
259 
260  for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
261  {
262  if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId )
263  {
264  select = (int) i;
265  break;
266  }
267  }
268 
269  if( select != m_gridSelectBox->GetSelection() )
270  m_gridSelectBox->SetSelection( select );
271 }
272 
273 
274 void EDA_DRAW_FRAME::PrintPage( wxDC* aDC )
275 {
276  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
277 }
278 
279 
280 /*
281  * Respond to selections in the toolbar grid popup
282  */
283 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
284 {
285  wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" );
286 
287  int id = m_gridSelectBox->GetCurrentSelection() + ID_POPUP_GRID_FIRST;
288 
289  if( id == ID_POPUP_GRID_SEPARATOR )
290  {
291  // wxWidgets will check the separator, which we don't want.
292  // Re-check the current grid.
293  wxUpdateUIEvent dummy;
295  }
296  else if( id == ID_POPUP_GRID_SETTINGS )
297  {
298  // wxWidgets will check the Grid Settings... entry, which we don't want.
299  // R-check the current grid.
300  wxUpdateUIEvent dummy;
302  // Now run the Grid Settings... dialog
303  wxCommandEvent dummy2;
304  OnGridSettings( dummy2 );
305  }
306  else if( id >= ID_POPUP_GRID_FIRST && id < ID_POPUP_GRID_SEPARATOR )
307  {
309  }
310 
311  UpdateStatusBar();
312  m_canvas->Refresh();
313 }
314 
315 
317 {
318  wxAcceleratorEntry entries[1];
319  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
320  wxAcceleratorTable accel( 1, entries );
321  SetAcceleratorTable( accel );
322 }
323 
324 
325 /*
326  * Respond to selections in the toolbar zoom popup
327  */
328 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
329 {
330  wxCHECK_RET( m_zoomSelectBox, "m_zoomSelectBox uninitialized" );
331 
332  int id = m_zoomSelectBox->GetCurrentSelection();
333 
334  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
335  return;
336 
337  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
338  UpdateStatusBar();
339  m_canvas->Refresh();
340 }
341 
342 
344 {
345  return GetScreen()->GetZoom();
346 }
347 
348 
350 {
351  COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
352  CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
353 
354  aMenu.AddSeparator( 1000 );
356  aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
357  aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
359 
360  aMenu.AddSeparator( 1000 );
361 
362  auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
363  zoomMenu->SetTool( commonTools );
364  aToolMenu.AddSubMenu( zoomMenu );
365 
366  auto gridMenu = std::make_shared<GRID_MENU>( this );
367  gridMenu->SetTool( commonTools );
368  aToolMenu.AddSubMenu( gridMenu );
369 
370  aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
371  aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
372 }
373 
374 
375 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
376 {
377  SetStatusText( msg, 6 );
378 }
379 
380 
381 /*
382  * Display the grid status.
383  */
385 {
386  wxString line;
387  wxString gridformatter;
388 
389  switch( m_userUnits )
390  {
391  case INCHES:
392  gridformatter = "grid %.3f";
393  break;
394 
395  case MILLIMETRES:
396  gridformatter = "grid %.4f";
397  break;
398 
399  default:
400  gridformatter = "grid %f";
401  break;
402  }
403 
404  wxRealPoint curr_grid_size = GetScreen()->GetGridSize();
405  double grid = To_User_Unit( m_userUnits, curr_grid_size.x );
406  line.Printf( gridformatter, grid );
407 
408  SetStatusText( line, 4 );
409 }
410 
411 
413 {
414  wxString msg;
415 
416  switch( m_userUnits )
417  {
418  case INCHES: msg = _( "Inches" ); break;
419  case MILLIMETRES: msg = _( "mm" ); break;
420  default: msg = _( "Units" ); break;
421  }
422 
423  SetStatusText( msg, 5 );
424 }
425 
426 
427 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
428 {
429  m_FrameSize = GetClientSize( );
430 
431  SizeEv.Skip();
432 }
433 
434 
436 {
437  SetStatusText( GetZoomLevelIndicator(), 1 );
438 
439  // Absolute and relative cursor positions are handled by overloading this function and
440  // handling the internal to user units conversion at the appropriate level.
441 
442  // refresh units display
443  DisplayUnitsMsg();
444 }
445 
446 
448 {
449  // returns a human readable value which can be displayed as zoom
450  // level indicator in dialogs.
451  return wxString::Format( wxT( "Z %.2f" ), m_canvas->GetGAL()->GetZoomFactor() );
452 }
453 
454 
455 void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
456 {
458 
459  wxString baseCfgName = ConfigBaseName();
460  wxConfigBase* cmnCfg = Pgm().CommonSettings();
461 
462  // Read units used in dialogs and toolbars
463  EDA_UNITS_T unitsTmp;
464 
465  if( aCfg->Read( baseCfgName + UserUnitsEntryKeyword, (int*) &unitsTmp ) )
466  SetUserUnits( unitsTmp );
467  else
469 
470  // Read show/hide grid entry
471  bool btmp;
472  if( aCfg->Read( baseCfgName + ShowGridEntryKeyword, &btmp ) )
473  SetGridVisibility( btmp );
474 
475  aCfg->Read( baseCfgName + LastGridSizeIdKeyword, &m_LastGridSizeId, m_LastGridSizeId );
476 
477  // m_LastGridSizeId is an offset, expected to be >= 0
478  if( m_LastGridSizeId < 0 )
479  m_LastGridSizeId = 0;
480 
481  m_UndoRedoCountMax = aCfg->Read( baseCfgName + MaxUndoItemsEntry,
482  long( DEFAULT_MAX_UNDO_ITEMS ) );
483 
484  aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
485 
486  m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this );
487 
488  long tmp;
489  aCfg->Read( FindReplaceFlagsEntry, &tmp, (long) wxFR_DOWN );
490  m_findReplaceData->SetFlags( (wxUint32) tmp & ~FR_REPLACE_ITEM_FOUND );
491  m_findReplaceData->SetFindString( aCfg->Read( FindStringEntry, wxEmptyString ) );
492  m_findReplaceData->SetReplaceString( aCfg->Read( ReplaceStringEntry, wxEmptyString ) );
493 
494  // Load the find and replace string history list.
495  for( int i = 0; i < FR_HISTORY_LIST_CNT; ++i )
496  {
497  wxString tmpHistory;
498  wxString entry;
499  entry.Printf( FindStringHistoryEntry, i );
500  tmpHistory = aCfg->Read( entry, wxEmptyString );
501 
502  if( !tmpHistory.IsEmpty() )
503  m_findStringHistoryList.Add( tmpHistory );
504 
505  entry.Printf( ReplaceStringHistoryEntry, i );
506  tmpHistory = aCfg->Read( entry, wxEmptyString );
507 
508  if( !tmpHistory.IsEmpty() )
509  m_replaceStringHistoryList.Add( tmpHistory );
510  }
511 }
512 
513 
514 void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
515 {
517 
518  wxString baseCfgName = ConfigBaseName();
519 
520  aCfg->Write( baseCfgName + UserUnitsEntryKeyword, (int) m_userUnits );
521  aCfg->Write( baseCfgName + ShowGridEntryKeyword, IsGridVisible() );
522  aCfg->Write( baseCfgName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
523  aCfg->Write( baseCfgName + FirstRunShownKeyword, m_firstRunDialogSetting );
524 
525  if( GetScreen() )
526  aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
527 
528  m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName );
529 
530  // Save find dialog session setting.
531  aCfg->Write( FindReplaceFlagsEntry, (long) m_findReplaceData->GetFlags() );
532  aCfg->Write( FindStringEntry, m_findReplaceData->GetFindString() );
533  aCfg->Write( ReplaceStringEntry, m_findReplaceData->GetReplaceString() );
534 
535  // Save the find and replace string history list.
536  unsigned i;
537  wxString tmpHistory;
538  wxString entry; // invoke constructor outside of any loops
539 
540  for( i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
541  {
542  entry.Printf( FindStringHistoryEntry, i );
543  aCfg->Write( entry, m_findStringHistoryList[ i ] );
544  }
545 
546  for( i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
547  {
548  entry.Printf( ReplaceStringHistoryEntry, i );
549  aCfg->Write( entry, m_replaceStringHistoryList[ i ] );
550  }
551 }
552 
553 
554 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
555  COLOR4D color, int pad )
556 {
557  if( m_messagePanel )
558  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
559 }
560 
561 
563 {
564  if( m_messagePanel )
566 }
567 
568 
570 {
571  if( m_messagePanel )
572  {
574 
575  for( const MSG_PANEL_ITEM& item : aList )
576  m_messagePanel->AppendMessage( item );
577  }
578 }
579 
580 
582 {
583  wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
584 
585  MSG_PANEL_ITEMS items;
586  aItem->GetMsgPanelInfo( m_userUnits, items );
587  SetMsgPanel( items );
588 }
589 
590 
592 {
594 }
595 
596 
598 {
599  GetCanvas()->SetEvtHandlerEnabled( true );
600  GetCanvas()->StartDrawing();
601 }
602 
603 
605 {
606  GetCanvas()->SwitchBackend( aCanvasType );
608 
610 }
611 
612 
614 {
616  wxConfigBase* cfg = Kiface().KifaceSettings();
617 
618  if( cfg )
619  {
620  canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE)
622  }
623 
624  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
625  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
626  {
627  wxASSERT( false );
629  }
630 
631  // Legacy canvas no longer supported. Switch to Cairo, and on the first instantiation
632  // the user will be prompted to switch to OpenGL
633  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
634  {
635 #ifdef __WXMAC__
636  // Cairo renderer doesn't handle Retina displays
638 #else
640 #endif
641  }
642 
643  return canvasType;
644 }
645 
646 
648 {
649  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
650  // have a fixed type, or do not have a option to set the canvas type (they inherit from
651  // a parent frame)
652  FRAME_T allowed_frames[] =
653  {
654  FRAME_SCH,
657  };
658 
659  bool allow_save = false;
660 
661  for( unsigned ii = 0; ii < arrayDim( allowed_frames ); ii++ )
662  {
663  if( m_Ident == allowed_frames[ii] )
664  {
665  allow_save = true;
666  break;
667  }
668  }
669 
670  if( !allow_save )
671  return false;
672 
673  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
674  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
675  {
676  wxASSERT( false );
677  return false;
678  }
679 
680  wxConfigBase* cfg = Kiface().KifaceSettings();
681 
682  if( cfg )
683  return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
684 
685  return false;
686 }
687 
688 //-----< BASE_SCREEN API moved here >--------------------------------------------
689 
690 wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition ) const
691 {
692  return GetScreen()->getNearestGridPosition( aPosition, GetGridOrigin() );
693 }
694 
695 //-----</BASE_SCREEN API moved here >--------------------------------------------
696 
698 {
699  return BOX2I();
700 }
701 
702 
704 {
705  // To be implemented by subclasses.
706 }
707 
708 
709 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
710 {
712 }
713 
714 
715 // Find the first child dialog.
716 wxWindow* findDialog( wxWindowList& aList )
717 {
718  for( wxWindow* window : aList )
719  {
720  if( dynamic_cast<DIALOG_SHIM*>( window ) )
721  return window;
722  }
723  return NULL;
724 }
725 
726 
727 void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aCenterView )
728 {
729  if( aCenterView )
730  {
731  wxWindow* dialog = findDialog( GetChildren() );
732 
733  // If a dialog partly obscures the window, then center on the uncovered area.
734  if( dialog )
735  {
736  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
737  dialog->GetSize() );
738  GetCanvas()->GetView()->SetCenter( aPos, dialogRect );
739  }
740  else
741  GetCanvas()->GetView()->SetCenter( aPos );
742  }
743 
745 }
746 
747 
748 static const wxString productName = wxT( "KiCad E.D.A. " );
749 
750 void PrintPageLayout( wxDC* aDC, const PAGE_INFO& aPageInfo, const wxString& aFullSheetName,
751  const wxString& aFileName, const TITLE_BLOCK& aTitleBlock, int aSheetCount,
752  int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor,
753  const wxString& aSheetLayer )
754 {
755  WS_DRAW_ITEM_LIST drawList;
756 
757  drawList.SetDefaultPenSize( aPenWidth );
758  drawList.SetMilsToIUfactor( aScalar );
759  drawList.SetSheetNumber( aSheetNumber );
760  drawList.SetSheetCount( aSheetCount );
761  drawList.SetFileName( aFileName );
762  drawList.SetSheetName( aFullSheetName );
763  drawList.SetSheetLayer( aSheetLayer );
764 
765  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
766 
767  // Draw item list
768  drawList.Print( aDC, aColor );
769 }
770 
771 
772 void EDA_DRAW_FRAME::PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
773  double aScalar, const wxString &aFilename,
774  const wxString &aSheetLayer, COLOR4D aColor )
775 {
777  return;
778 
779  COLOR4D color = ( aColor != COLOR4D::UNSPECIFIED ) ? aColor : COLOR4D( RED );
780 
781  wxPoint origin = aDC->GetDeviceOrigin();
782 
783  if( origin.y > 0 )
784  {
785  aDC->SetDeviceOrigin( 0, 0 );
786  aDC->SetAxisOrientation( true, false );
787  }
788 
790  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber, aLineWidth, aScalar,
791  color, aSheetLayer );
792 
793  if( origin.y > 0 )
794  {
795  aDC->SetDeviceOrigin( origin.x, origin.y );
796  aDC->SetAxisOrientation( true, true );
797  }
798 }
799 
800 
802 {
803  // Virtual function. Base class implementation returns an empty string.
804  return wxEmptyString;
805 }
806 
807 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
808  const wxString& wildcard, const wxString& ext,
809  bool isDirectory )
810 {
811  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
812  aFilename.SetExt( ext );
813 
814  if( isDirectory && doOpen )
815  {
816  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
817  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
818 
819  if( dlg.ShowModal() == wxID_CANCEL )
820  return false;
821 
822  aFilename = dlg.GetPath();
823  aFilename.SetExt( ext );
824  }
825  else
826  {
827  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
828  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
829  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
830 
831  if( dlg.ShowModal() == wxID_CANCEL )
832  return false;
833 
834  aFilename = dlg.GetPath();
835  aFilename.SetExt( ext );
836  }
837 
838  return true;
839 }
840 
841 
843 {
844  // Rebuild all toolbars, and update the checked state of check tools
845  if( m_mainToolBar )
847 
848  if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
850 
851  if( m_optionsToolBar ) // Options (typically on left edge of window)
853 
854  if( m_auxiliaryToolBar ) // Additional tools under main toolbar
856 
857  // Update the checked state of tools
858  SyncToolbars();
859 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
virtual void ReCreateVToolbar()=0
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
Definition: base_screen.h:279
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
static const wxChar ReplaceStringHistoryEntry[]
void PrintWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Prints the page layout with the frame and the basic inscriptions.
int m_ScreenNumber
Definition: base_screen.h:135
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:425
virtual void PrintPage(wxDC *aDC)
Print the page pointed by current screen, set by the calling print function.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:404
void SetUserUnits(EDA_UNITS_T aUnits)
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
static const wxString MaxUndoItemsEntry(wxT("DevelMaxUndoItems"))
Integer to set the maximum number of undo items on the stack.
static const wxChar ReplaceStringEntry[]
virtual const TITLE_BLOCK & GetTitleBlock() const =0
#define LastGridSizeIdKeyword
Most recently used grid size (suffix)
ACTION_TOOLBAR * m_auxiliaryToolBar
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
ACTION_TOOLBAR * m_optionsToolBar
void ReadCommonConfig(wxConfigBase &aCommonConfig, wxWindow *aWindow)
Read GAL config options from the common config store.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
double GetZoom() const
Function GetZoom returns the current "zoom factor", which is a measure of "internal units per device ...
Definition: base_screen.h:240
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
virtual void OnGridSettings(wxCommandEvent &event)
virtual bool IsGridVisible() const
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
virtual void SaveSettings(wxConfigBase *aCfg)
Saves common frame parameters to a configuration data file.
int color
Definition: DXF_plotter.cpp:62
Class TOOL_MENU.
Definition: tool_menu.h:47
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ws_draw_item.h:420
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
ACTIONS * m_actions
std::vector< wxSocketBase * > m_sockets
interprocess communication
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:412
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
virtual void EnableMousewheelPan(bool aEnable)
Function EnableMousewheelPan() Enables or disables mousewheel panning.
wxString ConfigBaseName()
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of ckeck tools.
wxArrayString m_findStringHistoryList
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
void ReleaseFile()
Release the current file marked in use.
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:286
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
#define DEFAULT_MAX_UNDO_ITEMS
virtual wxString GetCanvasTypeKey()
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
class EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
Sentinel, do not use as a parameter.
static const wxChar FirstRunShownKeyword[]
COLOR4D m_drawBgColor
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
wxChoice * m_gridSelectBox
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
prevents opening same file multiple times.
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
void ReadConfig(wxConfigBase &aCommonConfig, wxConfigBase &aAppCondfig, const wxString &aBaseCfgName, wxWindow *aWindow)
Read application and common configs.
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:201
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
#define UserUnitsEntryKeyword
User units.
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:50
This file contains miscellaneous commonly used macros and functions.
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:115
void DisplayUnitsMsg()
Display current unit pane on the status bar.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
EDA_DRAW_PANEL_GAL * m_canvas
GAL display options - this is the frame's interface to setting GAL display options.
static const wxChar FindReplaceFlagsEntry[]
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void EnableCursorWarping(bool aEnable)
Function EnableCursorWarping() Enables or disables warping the cursor.
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 ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:53
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:604
BASE_SCREEN * m_currentScreen
current used SCREEN
static TOOL_ACTION gridPreset
Definition: actions.h:131
static const wxChar FindStringHistoryEntry[]
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
wxArrayString m_replaceStringHistoryList
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:450
EDA_MSG_PANEL * m_messagePanel
GAL not used (the legacy wxDC engine is used)
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
bool m_showBorderAndTitleBlock
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
Definition: common.h:134
wxChoice * m_zoomSelectBox
void WriteConfig(wxConfigBase &aCfg, const wxString &aBaseName)
virtual void LoadSettings(wxConfigBase *aCfg)
Load common frame parameters from a configuration file.
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:432
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:51
Helper dialog and control classes.
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:54
wxWindow * findDialog(wxWindowList &aList)
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
double GetZoomFactor() const
Get the zoom factor.
wxLogTrace helper definitions.
Definition: colors.h:60
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
virtual void EnableAutoPan(bool aEnabled)
Function EnableAutoPan Turns on/off auto panning (user setting to disable it entirely).
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
void EraseMsgBox()
Definition: msgpanel.cpp:216
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: base_struct.h:328
#define FR_HISTORY_LIST_CNT
Maximum size of the find/replace history stacks.
void InitExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
virtual const wxPoint & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
#define _(s)
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:204
void StartDrawing()
Function StartDrawing() Begins drawing if it was stopped previously.
virtual void ReCreateOptToolbar()=0
void LoadSettings(wxConfigBase *aCfg) override
Load 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:49
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void 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
Class COMMON_TOOLS.
Definition: common_tools.h:38
virtual const wxString GetZoomLevelIndicator() const
Return a human readable value which can be displayed as zoom level indicator in dialogs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
wxSocketServer * m_socketServer
virtual void CommonSettingsChanged(bool aEnvVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void SetMaxFiles(size_t aMaxFiles)
Definition: pgm_base.cpp:120
void SetAutoSaveInterval(int aInterval)
double m_zoomLevelCoeff
virtual void ReCreateHToolbar()=0
void FocusOnLocation(const wxPoint &aPos, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
see class PGM_BASE
EDA_UNITS_T m_userUnits
virtual void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
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
static TOOL_ACTION zoomCenter
Definition: actions.h:92
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
Definition: ws_draw_item.h:441
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define max(a, b)
Definition: auxiliary.h:86
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
#define DEFAULT_FILE_HISTORY_SIZE
IDs range for menuitems file history: The default range file history size is 9 (compatible with defau...
Definition: id.h:69
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
size_t i
Definition: json11.cpp:597
size_t GetGridCount() const
Function GetGridCount().
Definition: base_screen.h:324
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
wxFindReplaceData * m_findReplaceData
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
int m_NumberOfScreens
Definition: base_screen.h:136
static TOOL_ACTION zoomIn
Definition: actions.h:88
wxPoint getNearestGridPosition(const wxPoint &aPosition, const wxPoint &aGridOrigin) const
Function getNearestGridPosition returns the nearest aGridSize location to aPosition.
static TOOL_ACTION zoomOut
Definition: actions.h:89
virtual void SetGridVisibility(bool aVisible)
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
TOOL_MANAGER * m_toolManager
void UpdateStatusBar() override
Update the status bar information.
Definition: colors.h:45
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
void Print(wxDC *aDC, COLOR4D aColor)
Draws the item list created by BuildWorkSheetGraphicList.
void DisplayGridMsg()
Display current grid pane on the status bar.
int m_CmdId
Definition: base_screen.h:46
BASE_SCREEN class implementation.
Message panel definition file.
void PostEvent(const TOOL_EVENT &aEvent)
Puts an event to the event queue to be processed at the end of event processing cycle.
Definition: tool_manager.h:228
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:272
static int GetRequiredHeight()
Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:71
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
EDA_UNITS_T
Definition: common.h:133
long m_firstRunDialogSetting
static const wxChar FindStringEntry[]
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
void DisplayToolMsg(const wxString &msg) override
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual wxString GetScreenDesc() const
static const wxString productName
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
ACTION_TOOLBAR * m_drawToolBar
virtual const BOX2I GetDocumentExtents() const
File locking utilities.
void PrintPageLayout(wxDC *aDC, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, const wxString &aSheetLayer)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...