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