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 
54 
57 static const wxChar FirstRunShownKeyword[] = wxT( "FirstRunShown" );
58 
59 static const wxChar FindReplaceFlagsEntry[] = wxT( "LastFindReplaceFlags" );
60 static const wxChar FindStringEntry[] = wxT( "LastFindString" );
61 static const wxChar ReplaceStringEntry[] = wxT( "LastReplaceString" );
62 static const wxChar FindStringHistoryEntry[] = wxT( "FindStringHistoryList%d" );
63 static const wxChar ReplaceStringHistoryEntry[] = wxT( "ReplaceStringHistoryList%d" );
65 
66 #define FR_HISTORY_LIST_CNT 10
67 
68 
81 static const wxString MaxUndoItemsEntry(wxT( "DevelMaxUndoItems" ) );
82 
83 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
84  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
85  long aStyle, const wxString & aFrameName ) :
86  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
87 {
88  m_socketServer = nullptr;
89  m_mainToolBar = NULL;
90  m_drawToolBar = NULL;
91  m_optionsToolBar = NULL;
92  m_auxiliaryToolBar = NULL;
93  m_gridSelectBox = NULL;
94  m_zoomSelectBox = NULL;
97 
99  m_canvas = NULL;
100  m_toolDispatcher = NULL;
101  m_messagePanel = NULL;
102  m_currentScreen = NULL;
103  m_showBorderAndTitleBlock = false; // true to display reference sheet.
104  m_LastGridSizeId = 0;
105  m_drawGrid = true; // hide/Show grid. default = show
106  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
107  m_showPageLimits = false;
108  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
109  // BLACK for Pcbnew, BLACK or WHITE for eeschema
111  m_zoomLevelCoeff = 1.0;
113  m_PolarCoords = false;
114  m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
115 
116  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
117 
118  CreateStatusBar( 7 );
119 
120  // set the size of the status bar subwindows:
121 
122  wxWindow* stsbar = GetStatusBar();
123 
124  int dims[] = {
125 
126  // remainder of status bar on far left is set to a default or whatever is left over.
127  -1,
128 
129  // When using GetTextSize() remember the width of character '1' is not the same
130  // as the width of '0' unless the font is fixed width, and it usually won't be.
131 
132  // zoom:
133  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
134 
135  // cursor coords
136  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
137 
138  // delta distances
139  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
140 
141  // grid size
142  GetTextSize( wxT( "grid X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
143 
144  // units display, Inches is bigger than mm
145  GetTextSize( _( "Inches" ), stsbar ).x + 10,
146 
147  // Size for the "Current Tool" panel; longest string from SetTool()
148  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
149  };
150 
151  SetStatusWidths( arrayDim( dims ), dims );
152 
153  // Create child subwindows.
154  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
155  m_FramePos.x = m_FramePos.y = 0;
157 
158  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
159  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
160 
161  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
162 }
163 
164 
166 {
167  delete m_socketServer;
168 
169  for( auto socket : m_sockets )
170  {
171  socket->Shutdown();
172  socket->Destroy();
173  }
174 
176 
177  delete m_actions;
178  delete m_toolManager;
179  delete m_toolDispatcher;
180  delete m_canvas;
181 
182  delete m_currentScreen;
183  m_currentScreen = NULL;
184 
185  delete m_findReplaceData;
186 
187  m_auimgr.UnInit();
188 
189  ReleaseFile();
190 }
191 
192 
194 {
195  m_file_checker = nullptr;
196 }
197 
198 
199 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
200 {
201  m_file_checker = ::LockFile( aFileName );
202 
203  return bool( m_file_checker );
204 }
205 
206 
208 {
209  UpdateStatusBar();
210  UpdateMsgPanel();
211 }
212 
213 
214 void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
215 {
216  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
217 
218  wxConfigBase* settings = Pgm().CommonSettings();
219  KIGFX::VIEW_CONTROLS* viewControls = GetCanvas()->GetViewControls();
220 
221  int autosaveInterval;
222  settings->Read( AUTOSAVE_INTERVAL_KEY, &autosaveInterval );
223  SetAutoSaveInterval( autosaveInterval );
224 
225  int historySize;
226  settings->Read( FILE_HISTORY_SIZE_KEY, &historySize, DEFAULT_FILE_HISTORY_SIZE );
227  Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
228 
229  bool option;
230  settings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
231  viewControls->EnableMousewheelPan( option );
232 
233  settings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
234  viewControls->EnableCursorWarping( !option );
235 
236  settings->Read( ENBL_AUTO_PAN_KEY, &option );
237  viewControls->EnableAutoPan( option );
238 
239  m_galDisplayOptions.ReadCommonConfig( *settings, this );
240 }
241 
242 
244 {
245  if( m_messagePanel )
247 }
248 
249 
250 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
251 {
252  // No need to update the grid select box if it doesn't exist or the grid setting change
253  // was made using the select box.
254  if( m_gridSelectBox == NULL )
255  return;
256 
257  int select = wxNOT_FOUND;
258 
259  for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
260  {
261  if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId )
262  {
263  select = (int) i;
264  break;
265  }
266  }
267 
268  if( select != m_gridSelectBox->GetSelection() )
269  m_gridSelectBox->SetSelection( select );
270 }
271 
272 
273 void EDA_DRAW_FRAME::PrintPage( wxDC* aDC )
274 {
275  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
276 }
277 
278 
279 /*
280  * Respond to selections in the toolbar grid popup
281  */
282 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
283 {
284  wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" );
285 
286  int id = m_gridSelectBox->GetCurrentSelection() + ID_POPUP_GRID_FIRST;
287 
288  if( id == ID_POPUP_GRID_SEPARATOR )
289  {
290  // wxWidgets will check the separator, which we don't want.
291  // Re-check the current grid.
292  wxUpdateUIEvent dummy;
294  }
295  else if( id == ID_POPUP_GRID_SETTINGS )
296  {
297  // wxWidgets will check the Grid Settings... entry, which we don't want.
298  // R-check the current grid.
299  wxUpdateUIEvent dummy;
301  // Now run the Grid Settings... dialog
302  wxCommandEvent dummy2;
303  OnGridSettings( dummy2 );
304  }
305  else if( id >= ID_POPUP_GRID_FIRST && id < ID_POPUP_GRID_SEPARATOR )
306  {
308  }
309 
310  UpdateStatusBar();
311  m_canvas->Refresh();
312 }
313 
314 
316 {
317  wxAcceleratorEntry entries[1];
318  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
319  wxAcceleratorTable accel( 1, entries );
320  SetAcceleratorTable( accel );
321 }
322 
323 
324 /*
325  * Respond to selections in the toolbar zoom popup
326  */
327 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
328 {
329  wxCHECK_RET( m_zoomSelectBox, "m_zoomSelectBox uninitialized" );
330 
331  int id = m_zoomSelectBox->GetCurrentSelection();
332 
333  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
334  return;
335 
336  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
337  UpdateStatusBar();
338  m_canvas->Refresh();
339 }
340 
341 
343 {
344  return GetScreen()->GetZoom();
345 }
346 
347 
349 {
350  COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
351  CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
352 
353  aMenu.AddSeparator( 1000 );
355  aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
356  aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
358 
359  aMenu.AddSeparator( 1000 );
360 
361  auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
362  zoomMenu->SetTool( commonTools );
363  aToolMenu.AddSubMenu( zoomMenu );
364 
365  auto gridMenu = std::make_shared<GRID_MENU>( this );
366  gridMenu->SetTool( commonTools );
367  aToolMenu.AddSubMenu( gridMenu );
368 
369  aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
370  aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
371 }
372 
373 
374 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
375 {
376  SetStatusText( msg, 6 );
377 }
378 
379 
380 /*
381  * Display the grid status.
382  */
384 {
385  wxString line;
386  wxString gridformatter;
387 
388  switch( m_userUnits )
389  {
390  case INCHES:
391  gridformatter = "grid %.3f";
392  break;
393 
394  case MILLIMETRES:
395  gridformatter = "grid %.4f";
396  break;
397 
398  default:
399  gridformatter = "grid %f";
400  break;
401  }
402 
403  wxRealPoint curr_grid_size = GetScreen()->GetGridSize();
404  double grid = To_User_Unit( m_userUnits, curr_grid_size.x );
405  line.Printf( gridformatter, grid );
406 
407  SetStatusText( line, 4 );
408 }
409 
410 
412 {
413  wxString msg;
414 
415  switch( m_userUnits )
416  {
417  case INCHES: msg = _( "Inches" ); break;
418  case MILLIMETRES: msg = _( "mm" ); break;
419  default: msg = _( "Units" ); break;
420  }
421 
422  SetStatusText( msg, 5 );
423 }
424 
425 
426 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
427 {
428  m_FrameSize = GetClientSize( );
429 
430  SizeEv.Skip();
431 }
432 
433 
435 {
436  SetStatusText( GetZoomLevelIndicator(), 1 );
437 
438  // Absolute and relative cursor positions are handled by overloading this function and
439  // handling the internal to user units conversion at the appropriate level.
440 
441  // refresh units display
442  DisplayUnitsMsg();
443 }
444 
445 
447 {
448  // returns a human readable value which can be displayed as zoom
449  // level indicator in dialogs.
450  return wxString::Format( wxT( "Z %.2f" ), m_canvas->GetGAL()->GetZoomFactor() );
451 }
452 
453 
454 void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
455 {
457 
458  wxString baseCfgName = ConfigBaseName();
459  wxConfigBase* cmnCfg = Pgm().CommonSettings();
460 
461  // Read units used in dialogs and toolbars
462  EDA_UNITS_T unitsTmp;
463 
464  if( aCfg->Read( baseCfgName + UserUnitsEntryKeyword, (int*) &unitsTmp ) )
465  SetUserUnits( unitsTmp );
466  else
468 
469  // Read show/hide grid entry
470  bool btmp;
471  if( aCfg->Read( baseCfgName + ShowGridEntryKeyword, &btmp ) )
472  SetGridVisibility( btmp );
473 
474  aCfg->Read( baseCfgName + LastGridSizeIdKeyword, &m_LastGridSizeId, m_LastGridSizeId );
475 
476  // m_LastGridSizeId is an offset, expected to be >= 0
477  if( m_LastGridSizeId < 0 )
478  m_LastGridSizeId = 0;
479 
480  m_UndoRedoCountMax = aCfg->Read( baseCfgName + MaxUndoItemsEntry,
481  long( DEFAULT_MAX_UNDO_ITEMS ) );
482 
483  aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
484 
485  m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this );
486 
487  long tmp;
488  aCfg->Read( FindReplaceFlagsEntry, &tmp, (long) wxFR_DOWN );
489  m_findReplaceData->SetFlags( (wxUint32) tmp & ~FR_REPLACE_ITEM_FOUND );
490  m_findReplaceData->SetFindString( aCfg->Read( FindStringEntry, wxEmptyString ) );
491  m_findReplaceData->SetReplaceString( aCfg->Read( ReplaceStringEntry, wxEmptyString ) );
492 
493  // Load the find and replace string history list.
494  for( int i = 0; i < FR_HISTORY_LIST_CNT; ++i )
495  {
496  wxString tmpHistory;
497  wxString entry;
498  entry.Printf( FindStringHistoryEntry, i );
499  tmpHistory = aCfg->Read( entry, wxEmptyString );
500 
501  if( !tmpHistory.IsEmpty() )
502  m_findStringHistoryList.Add( tmpHistory );
503 
504  entry.Printf( ReplaceStringHistoryEntry, i );
505  tmpHistory = aCfg->Read( entry, wxEmptyString );
506 
507  if( !tmpHistory.IsEmpty() )
508  m_replaceStringHistoryList.Add( tmpHistory );
509  }
510 }
511 
512 
513 void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
514 {
516 
517  wxString baseCfgName = ConfigBaseName();
518 
519  aCfg->Write( baseCfgName + UserUnitsEntryKeyword, (int) m_userUnits );
520  aCfg->Write( baseCfgName + ShowGridEntryKeyword, IsGridVisible() );
521  aCfg->Write( baseCfgName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
522  aCfg->Write( baseCfgName + FirstRunShownKeyword, m_firstRunDialogSetting );
523 
524  if( GetScreen() )
525  aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
526 
527  m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName );
528 
529  // Save find dialog session setting.
530  aCfg->Write( FindReplaceFlagsEntry, (long) m_findReplaceData->GetFlags() );
531  aCfg->Write( FindStringEntry, m_findReplaceData->GetFindString() );
532  aCfg->Write( ReplaceStringEntry, m_findReplaceData->GetReplaceString() );
533 
534  // Save the find and replace string history list.
535  unsigned i;
536  wxString tmpHistory;
537  wxString entry; // invoke constructor outside of any loops
538 
539  for( i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
540  {
541  entry.Printf( FindStringHistoryEntry, i );
542  aCfg->Write( entry, m_findStringHistoryList[ i ] );
543  }
544 
545  for( i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
546  {
547  entry.Printf( ReplaceStringHistoryEntry, i );
548  aCfg->Write( entry, m_replaceStringHistoryList[ i ] );
549  }
550 }
551 
552 
553 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
554  COLOR4D color, int pad )
555 {
556  if( m_messagePanel )
557  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
558 }
559 
560 
562 {
563  if( m_messagePanel )
565 }
566 
567 
569 {
570  if( m_messagePanel )
571  {
573 
574  for( const MSG_PANEL_ITEM& item : aList )
575  m_messagePanel->AppendMessage( item );
576  }
577 }
578 
579 
581 {
582  wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
583 
584  MSG_PANEL_ITEMS items;
585  aItem->GetMsgPanelInfo( m_userUnits, items );
586  SetMsgPanel( items );
587 }
588 
589 
591 {
593 }
594 
595 
597 {
598  GetCanvas()->SetEvtHandlerEnabled( true );
599  GetCanvas()->StartDrawing();
600 }
601 
602 
604 {
605  GetCanvas()->SwitchBackend( aCanvasType );
607 
609 }
610 
611 
613 {
615  wxConfigBase* cfg = Kiface().KifaceSettings();
616 
617  if( cfg )
618  {
619  canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE)
621  }
622 
623  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
624  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
625  {
626  wxASSERT( false );
628  }
629 
630  // Legacy canvas no longer supported. Switch to Cairo, and on the first instantiation
631  // the user will be prompted to switch to OpenGL
632  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
633  {
634 #ifdef __WXMAC__
635  // Cairo renderer doesn't handle Retina displays
637 #else
639 #endif
640  }
641 
642  return canvasType;
643 }
644 
645 
647 {
648  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
649  // have a fixed type, or do not have a option to set the canvas type (they inherit from
650  // a parent frame)
651  FRAME_T allowed_frames[] =
652  {
654  };
655 
656  bool allow_save = false;
657 
658  for( int ii = 0; ii < 3; ii++ )
659  {
660  if( m_Ident == allowed_frames[ii] )
661  {
662  allow_save = true;
663  break;
664  }
665  }
666 
667  if( !allow_save )
668  return false;
669 
670  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
671  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
672  {
673  wxASSERT( false );
674  return false;
675  }
676 
677  wxConfigBase* cfg = Kiface().KifaceSettings();
678 
679  if( cfg )
680  return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
681 
682  return false;
683 }
684 
685 //-----< BASE_SCREEN API moved here >--------------------------------------------
686 
687 wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition ) const
688 {
689  return GetScreen()->getNearestGridPosition( aPosition, GetGridOrigin() );
690 }
691 
692 //-----</BASE_SCREEN API moved here >--------------------------------------------
693 
695 {
696  return BOX2I();
697 }
698 
699 
701 {
702  // To be implemented by subclasses.
703 }
704 
705 
706 // Factor out the calculation portion of the various BestZoom() implementations.
707 //
708 // Note that like it's forerunners this routine has an intentional side-effect: it
709 // sets the scroll centre position. While I'm not happy about that, it's probably
710 // not worth fixing as its days are numbered (GAL canvases use a different method).
711 double EDA_DRAW_FRAME::bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre )
712 {
713  return 1.0;
714 }
715 
716 
717 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
718 {
720 }
721 
722 
723 // Find the first child dialog.
724 wxWindow* findDialog( wxWindowList& aList )
725 {
726  for( wxWindow* window : aList )
727  {
728  if( dynamic_cast<DIALOG_SHIM*>( window ) )
729  return window;
730  }
731  return NULL;
732 }
733 
734 
735 void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aCenterView )
736 {
737  if( aCenterView )
738  {
739  wxWindow* dialog = findDialog( GetChildren() );
740 
741  // If a dialog partly obscures the window, then center on the uncovered area.
742  if( dialog )
743  {
744  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
745  dialog->GetSize() );
746  GetCanvas()->GetView()->SetCenter( aPos, dialogRect );
747  }
748  else
749  GetCanvas()->GetView()->SetCenter( aPos );
750  }
751 
753 }
754 
755 
756 static const wxString productName = wxT( "KiCad E.D.A. " );
757 
758 void PrintPageLayout( wxDC* aDC, const PAGE_INFO& aPageInfo, const wxString& aFullSheetName,
759  const wxString& aFileName, const TITLE_BLOCK& aTitleBlock, int aSheetCount,
760  int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor,
761  const wxString& aSheetLayer )
762 {
763  WS_DRAW_ITEM_LIST drawList;
764 
765  drawList.SetDefaultPenSize( aPenWidth );
766  drawList.SetMilsToIUfactor( aScalar );
767  drawList.SetSheetNumber( aSheetNumber );
768  drawList.SetSheetCount( aSheetCount );
769  drawList.SetFileName( aFileName );
770  drawList.SetSheetName( aFullSheetName );
771  drawList.SetSheetLayer( aSheetLayer );
772 
773  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
774 
775  // Draw item list
776  drawList.Print( aDC, aColor );
777 }
778 
779 
780 void EDA_DRAW_FRAME::PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
781  double aScalar, const wxString &aFilename,
782  const wxString &aSheetLayer, COLOR4D aColor )
783 {
785  return;
786 
787  COLOR4D color = ( aColor != COLOR4D::UNSPECIFIED ) ? aColor : COLOR4D( RED );
788 
789  wxPoint origin = aDC->GetDeviceOrigin();
790 
791  if( origin.y > 0 )
792  {
793  aDC->SetDeviceOrigin( 0, 0 );
794  aDC->SetAxisOrientation( true, false );
795  }
796 
798  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber, aLineWidth, aScalar,
799  color, aSheetLayer );
800 
801  if( origin.y > 0 )
802  {
803  aDC->SetDeviceOrigin( origin.x, origin.y );
804  aDC->SetAxisOrientation( true, true );
805  }
806 }
807 
808 
810 {
811  // Virtual function. Base class implementation returns an empty string.
812  return wxEmptyString;
813 }
814 
815 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
816  const wxString& wildcard, const wxString& ext,
817  bool isDirectory )
818 {
819  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
820  aFilename.SetExt( ext );
821 
822  if( isDirectory && doOpen )
823  {
824  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
825  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
826 
827  if( dlg.ShowModal() == wxID_CANCEL )
828  return false;
829 
830  aFilename = dlg.GetPath();
831  aFilename.SetExt( ext );
832  }
833  else
834  {
835  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
836  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
837  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
838 
839  if( dlg.ShowModal() == wxID_CANCEL )
840  return false;
841 
842  aFilename = dlg.GetPath();
843  aFilename.SetExt( ext );
844  }
845 
846  return true;
847 }
848 
849 
851 {
852  // Rebuild all toolbars, and update the checked state of check tools
853  if( m_mainToolBar )
855 
856  if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
858 
859  if( m_optionsToolBar ) // Options (typically on left edge of window)
861 
862  if( m_auxiliaryToolBar ) // Additional tools under main toolbar
864 
865  // Update the checked state of tools
866  SyncToolbars();
867 }
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.
double bestZoom(double sizeX, double sizeY, double scaleFactor, wxPoint centre)
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:92
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:200
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:130
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:155
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:327
#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:91
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:87
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:88
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:154
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...