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-2020 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 <base_screen.h>
27 #include <bitmaps.h>
28 #include <confirm.h>
29 #include <dialog_shim.h>
30 #include <eda_draw_frame.h>
31 #include <fctsys.h>
32 #include <filehistory.h>
33 #include <id.h>
34 #include <kiface_i.h>
35 #include <lockfile.h>
36 #include <macros.h>
37 #include <msgpanel.h>
38 #include <page_info.h>
39 #include <pgm_base.h>
40 #include <settings/app_settings.h>
44 #include <title_block.h>
45 #include <tool/actions.h>
46 #include <tool/common_tools.h>
47 #include <tool/grid_menu.h>
49 #include <tool/tool_dispatcher.h>
50 #include <tool/tool_manager.h>
51 #include <tool/tool_menu.h>
52 #include <tool/zoom_menu.h>
53 #include <trace_helpers.h>
54 #include <view/view.h>
55 #include <ws_draw_item.h>
56 #include <wx/snglinst.h>
58 
59 #define FR_HISTORY_LIST_CNT 10
60 
61 
62 BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
65 END_EVENT_TABLE()
66 
67 
68 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
69  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
70  long aStyle, const wxString & aFrameName ) :
71  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
72 {
73  m_socketServer = nullptr;
74  m_mainToolBar = NULL;
75  m_drawToolBar = NULL;
76  m_optionsToolBar = NULL;
77  m_auxiliaryToolBar = NULL;
78  m_gridSelectBox = NULL;
79  m_zoomSelectBox = NULL;
80  m_firstRunDialogSetting = 0;
81  m_UndoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
82 
83  m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
84  m_canvas = NULL;
85  m_toolDispatcher = NULL;
86  m_messagePanel = NULL;
87  m_currentScreen = NULL;
88  m_showBorderAndTitleBlock = false; // true to display reference sheet.
89  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
90  m_showPageLimits = false;
91  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
92  // BLACK for Pcbnew, BLACK or WHITE for eeschema
93  m_colorSettings = nullptr;
94  m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
95  m_userUnits = EDA_UNITS::MILLIMETRES;
96  m_PolarCoords = false;
97  m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
98 
99  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
100 
101  CreateStatusBar( 7 );
102 
103  // set the size of the status bar subwindows:
104 
105  wxWindow* stsbar = GetStatusBar();
106 
107  int dims[] = {
108 
109  // remainder of status bar on far left is set to a default or whatever is left over.
110  -1,
111 
112  // When using GetTextSize() remember the width of character '1' is not the same
113  // as the width of '0' unless the font is fixed width, and it usually won't be.
114 
115  // zoom:
116  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
117 
118  // cursor coords
119  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
120 
121  // delta distances
122  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
123 
124  // grid size
125  GetTextSize( wxT( "grid X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
126 
127  // units display, Inches is bigger than mm
128  GetTextSize( _( "Inches" ), stsbar ).x + 10,
129 
130  // Size for the "Current Tool" panel; longest string from SetTool()
131  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
132  };
133 
134  SetStatusWidths( arrayDim( dims ), dims );
135 
136  // Create child subwindows.
137  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
138  m_FramePos.x = m_FramePos.y = 0;
139  m_FrameSize.y -= m_MsgFrameHeight;
140 
141  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
142  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
143 
144  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
145 }
146 
147 
149 {
150  delete m_socketServer;
151 
152  for( auto socket : m_sockets )
153  {
154  socket->Shutdown();
155  socket->Destroy();
156  }
157 
159 
160  delete m_actions;
161  delete m_toolManager;
162  delete m_toolDispatcher;
163  delete m_canvas;
164 
165  delete m_currentScreen;
167 
168  delete m_findReplaceData;
169 
170  m_auimgr.UnInit();
171 
172  ReleaseFile();
173 }
174 
175 
177 {
178  m_file_checker = nullptr;
179 }
180 
181 
182 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
183 {
184  m_file_checker = ::LockFile( aFileName );
185 
186  return bool( m_file_checker );
187 }
188 
189 
191 {
192  UpdateStatusBar();
193  UpdateMsgPanel();
194 }
195 
196 
198 {
201 
202  wxCommandEvent e( UNITS_CHANGED );
203  ProcessEventLocally( e );
204 }
205 
206 
207 void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
208 {
209  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
210 
211  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
212  KIGFX::VIEW_CONTROLS* viewControls = GetCanvas()->GetViewControls();
213 
215 
216  viewControls->LoadSettings();
217 
218  m_galDisplayOptions.ReadCommonConfig( *settings, this );
219 }
220 
221 
223 {
224  if( m_messagePanel )
226 }
227 
228 
230 {
231  UpdateStatusBar();
232  DisplayUnitsMsg();
233 
234  if( m_gridSelectBox == NULL )
235  return;
236 
237  // Update grid values with the current units setting.
238  m_gridSelectBox->Clear();
239  wxArrayString gridsList;
240 
242 
243  for( const wxString& grid : gridsList )
244  m_gridSelectBox->Append( grid );
245 
246  m_gridSelectBox->Append( wxT( "---" ) );
247  m_gridSelectBox->Append( _( "Edit User Grid..." ) );
248 
249  m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
250 }
251 
252 
253 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
254 {
255  // No need to update the grid select box if it doesn't exist or the grid setting change
256  // was made using the select box.
257  if( m_gridSelectBox == NULL )
258  return;
259 
260  int idx = config()->m_Window.grid.last_size_idx;
261  idx = std::max( 0, std::min( idx, (int) m_gridSelectBox->GetCount() - 1 ) );
262 
263  if( idx != m_gridSelectBox->GetSelection() )
264  m_gridSelectBox->SetSelection( idx );
265 }
266 
267 
269 {
270  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
271 }
272 
273 
274 /*
275  * Respond to selections in the toolbar grid popup
276  */
277 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
278 {
279  wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" );
280 
281  int idx = m_gridSelectBox->GetCurrentSelection();
282 
283  if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
284  {
285  // wxWidgets will check the separator, which we don't want.
286  // Re-check the current grid.
287  wxUpdateUIEvent dummy;
289  }
290  else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
291  {
292  // wxWidgets will check the Grid Settings... entry, which we don't want.
293  // Re-check the current grid.
294  wxUpdateUIEvent dummy;
296  // Now run the Grid Settings... dialog
297  wxCommandEvent dummy2;
298  OnGridSettings( dummy2 );
299  }
300  else
301  {
303  }
304 
305  UpdateStatusBar();
306  m_canvas->Refresh();
307 }
308 
309 
310 void EDA_DRAW_FRAME::OnGridSettings( wxCommandEvent& aEvent )
311 {
312  DIALOG_GRID_SETTINGS dlg( this );
313 
314  if( dlg.ShowModal() == wxID_OK )
315  {
316  UpdateStatusBar();
317  GetCanvas()->Refresh();
318  }
319 }
320 
321 
323 {
324  return config()->m_Window.grid.show;
325 }
326 
327 
329 {
330  config()->m_Window.grid.show = aVisible;
331 
332  // Update the display with the new grid
333  if( GetCanvas() )
334  {
335  // Check to ensure these exist, since this function could be called before
336  // the GAL and View have been created
337  if( GetCanvas()->GetGAL() )
338  GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
339 
340  if( GetCanvas()->GetView() )
342 
343  GetCanvas()->Refresh();
344  }
345 }
346 
347 
349 {
350  if( m_zoomSelectBox == NULL )
351  return;
352 
353  double zoom = m_canvas->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
354 
355  m_zoomSelectBox->Clear();
356  m_zoomSelectBox->Append( _( "Zoom Auto" ) );
357  m_zoomSelectBox->SetSelection( 0 );
358 
359  for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
360  {
361  double current = config()->m_Window.zoom_factors[i];
362 
363  m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
364 
365  if( zoom == current )
366  m_zoomSelectBox->SetSelection( i + 1 );
367  }
368 }
369 
370 
371 void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
372 {
373  if( m_zoomSelectBox == NULL || m_zoomSelectBox->GetParent() == NULL )
374  return;
375 
376  int current = 0; // display Auto if no match found
377 
378  // check for a match within 1%
379  double zoom = GetCanvas()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
380 
381  for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); i++ )
382  {
383  if( std::fabs( zoom - config()->m_Window.zoom_factors[i] ) < ( zoom / 100.0 ) )
384  {
385  current = i + 1;
386  break;
387  }
388  }
389 
390  if( current != m_zoomSelectBox->GetSelection() )
391  m_zoomSelectBox->SetSelection( current );
392 }
393 
394 
395 /*
396  * Respond to selections in the toolbar zoom popup
397  */
398 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
399 {
400  wxCHECK_RET( m_zoomSelectBox, "m_zoomSelectBox uninitialized" );
401 
402  int id = m_zoomSelectBox->GetCurrentSelection();
403 
404  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
405  return;
406 
407  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
408  UpdateStatusBar();
409  m_canvas->Refresh();
410 }
411 
412 
413 void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
414 {
415  // If the window is moved to a different display, the scaling factor may change
416  double oldFactor = m_galDisplayOptions.m_scaleFactor;
418 
419  if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
420  {
421  wxSize clientSize = GetClientSize();
422  GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
423  GetCanvas()->GetView()->MarkDirty();
424  }
425 
426  aEvent.Skip();
427 }
428 
429 
431 {
432  COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
433  CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
434 
435  aMenu.AddSeparator( 1000 );
437  aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
438  aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
440  if( IsType( FRAME_SCH ) || IsType( FRAME_PCB_EDITOR ) )
442 
443  aMenu.AddSeparator( 1000 );
444 
445  auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
446  zoomMenu->SetTool( commonTools );
447  aToolMenu.AddSubMenu( zoomMenu );
448 
449  auto gridMenu = std::make_shared<GRID_MENU>( this );
450  gridMenu->SetTool( commonTools );
451  aToolMenu.AddSubMenu( gridMenu );
452 
453  aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
454  aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
455 }
456 
457 
459 {
460  wxAcceleratorEntry entries[1];
461  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
462  wxAcceleratorTable accel( 1, entries );
463  SetAcceleratorTable( accel );
464 }
465 
466 
467 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
468 {
469  SetStatusText( msg, 6 );
470 }
471 
472 
473 /*
474  * Display the grid status.
475  */
477 {
478  wxString line;
479  wxString gridformatter;
480 
481  switch( m_userUnits )
482  {
483  case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break;
484  case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break;
485  default: gridformatter = "grid %f"; break;
486  }
487 
488  double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
489  line.Printf( gridformatter, grid );
490 
491  SetStatusText( line, 4 );
492 }
493 
494 
496 {
497  wxString msg;
498 
499  switch( m_userUnits )
500  {
501  case EDA_UNITS::INCHES: msg = _( "Inches" ); break;
502  case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
503  default: msg = _( "Units" ); break;
504  }
505 
506  SetStatusText( msg, 5 );
507 }
508 
509 
510 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
511 {
512  m_FrameSize = GetClientSize( );
513 
514  SizeEv.Skip();
515 }
516 
517 
519 {
520  SetStatusText( GetZoomLevelIndicator(), 1 );
521 
522  // Absolute and relative cursor positions are handled by overloading this function and
523  // handling the internal to user units conversion at the appropriate level.
524 
525  // refresh units display
526  DisplayUnitsMsg();
527 }
528 
529 
531 {
532  // returns a human readable value which can be displayed as zoom
533  // level indicator in dialogs.
534  double zoom = m_canvas->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
535  return wxString::Format( wxT( "Z %.2f" ), zoom );
536 }
537 
538 
540 {
542 
543  COMMON_SETTINGS* cmnCfg = Pgm().GetCommonSettings();
544  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
545 
546  // Read units used in dialogs and toolbars
547  SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
548 
551 
552  m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
553 
554  m_findReplaceData->SetFlags( aCfg->m_FindReplace.flags );
555  m_findReplaceData->SetFindString( aCfg->m_FindReplace.find_string );
556  m_findReplaceData->SetReplaceString( aCfg->m_FindReplace.replace_string );
557 
558  for( auto& s : aCfg->m_FindReplace.find_history )
559  m_findStringHistoryList.Add( s );
560 
561  for( auto& s : aCfg->m_FindReplace.replace_history )
563 }
564 
565 
567 {
569 
570  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
571 
572  aCfg->m_System.units = static_cast<int>( m_userUnits );
575 
576  m_galDisplayOptions.WriteConfig( *window );
577 
578  aCfg->m_FindReplace.flags = m_findReplaceData->GetFlags();
579  aCfg->m_FindReplace.find_string = m_findReplaceData->GetFindString();
580  aCfg->m_FindReplace.replace_string = m_findReplaceData->GetReplaceString();
581 
582  aCfg->m_FindReplace.find_history.clear();
583  aCfg->m_FindReplace.replace_history.clear();
584 
585  for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
586  aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
587 
588  for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
589  aCfg->m_FindReplace.replace_history.push_back(
590  m_replaceStringHistoryList[ i ].ToStdString() );
591 }
592 
593 
594 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
595  COLOR4D color, int pad )
596 {
597  if( m_messagePanel )
598  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
599 }
600 
601 
603 {
604  if( m_messagePanel )
606 }
607 
608 
610 {
611  if( m_messagePanel )
612  {
614 
615  for( const MSG_PANEL_ITEM& item : aList )
616  m_messagePanel->AppendMessage( item );
617  }
618 }
619 
620 
622 {
623  wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
624 
625  MSG_PANEL_ITEMS items;
626  aItem->GetMsgPanelInfo( this, items );
627  SetMsgPanel( items );
628 }
629 
630 
632 {
634 }
635 
636 
638 {
639  GetCanvas()->SetEvtHandlerEnabled( true );
640  GetCanvas()->StartDrawing();
641 }
642 
643 
645 {
646  GetCanvas()->SwitchBackend( aCanvasType );
648 
650 }
651 
652 
654 {
655 #ifdef __WXMAC__
656  // Cairo renderer doesn't handle Retina displays so there's really only one game
657  // in town for Mac
659 #endif
660 
663 
664  if( cfg )
665  canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
666 
667  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
668  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
669  {
670  wxASSERT( false );
672  }
673 
674  // Legacy canvas no longer supported. Switch to Cairo, and on the first instantiation
675  // the user will be prompted to switch to OpenGL
676  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
678 
679  return canvasType;
680 }
681 
682 
684 {
685  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
686  // have a fixed type, or do not have a option to set the canvas type (they inherit from
687  // a parent frame)
688  FRAME_T allowed_frames[] =
689  {
690  FRAME_SCH,
693  };
694 
695  bool allow_save = false;
696 
697  for( unsigned ii = 0; ii < arrayDim( allowed_frames ); ii++ )
698  {
699  if( m_Ident == allowed_frames[ii] )
700  {
701  allow_save = true;
702  break;
703  }
704  }
705 
706  if( !allow_save )
707  return false;
708 
709  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
710  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
711  {
712  wxASSERT( false );
713  return false;
714  }
715 
717 
718  if( cfg )
719  cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
720 
721  return false;
722 }
723 
724 
726 {
727  const wxPoint& gridOrigin = GetGridOrigin();
728  VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
729 
730  double xOffset = fmod( gridOrigin.x, gridSize.x );
731  int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
732  double yOffset = fmod( gridOrigin.y, gridSize.y );
733  int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
734 
735  return wxPoint( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
736 }
737 
738 
739 const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
740 {
741  return BOX2I();
742 }
743 
744 
746 {
747  // To be implemented by subclasses.
748 }
749 
750 
751 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
752 {
754 }
755 
756 
757 // Find the first child dialog.
758 wxWindow* findDialog( wxWindowList& aList )
759 {
760  for( wxWindow* window : aList )
761  {
762  if( dynamic_cast<DIALOG_SHIM*>( window ) )
763  return window;
764  }
765  return NULL;
766 }
767 
768 
770 {
771  bool centerView = false;
772  BOX2D r = GetCanvas()->GetView()->GetViewport();
773 
774  // Center if we're off the current view, or within 10% of its edge
775  r.Inflate( - (int) r.GetWidth() / 10 );
776 
777  if( !r.Contains( aPos ) )
778  centerView = true;
779 
780  // Center if we're behind an obscuring dialog, or within 10% of its edge
781  wxWindow* dialog = findDialog( GetChildren() );
782 
783  if( dialog )
784  {
785  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
786  dialog->GetSize() );
787  dialogRect.Inflate( dialogRect.GetWidth() / 10 );
788 
789  if( dialogRect.Contains( (wxPoint) GetCanvas()->GetView()->ToScreen( aPos ) ) )
790  centerView = true;
791  }
792 
793  if( centerView )
794  {
795  // If a dialog partly obscures the window, then center on the uncovered area.
796  if( dialog )
797  {
798  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
799  dialog->GetSize() );
800  GetCanvas()->GetView()->SetCenter( aPos, dialogRect );
801  }
802  else
803  GetCanvas()->GetView()->SetCenter( aPos );
804  }
805 
807 }
808 
809 
810 static const wxString productName = wxT( "KiCad E.D.A. " );
811 
812 void PrintPageLayout( RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
813  const wxString& aFullSheetName, const wxString& aFileName,
814  const TITLE_BLOCK& aTitleBlock, int aSheetCount, int aSheetNumber,
815  double aScalar, const PROJECT* aProject, const wxString& aSheetLayer )
816 {
817  WS_DRAW_ITEM_LIST drawList;
818 
819  drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
820  drawList.SetMilsToIUfactor( aScalar );
821  drawList.SetSheetNumber( aSheetNumber );
822  drawList.SetSheetCount( aSheetCount );
823  drawList.SetFileName( aFileName );
824  drawList.SetSheetName( aFullSheetName );
825  drawList.SetSheetLayer( aSheetLayer );
826  drawList.SetProject( aProject );
827 
828  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
829 
830  // Draw item list
831  drawList.Print( aSettings );
832 }
833 
834 
836  double aScalar, const wxString &aFilename,
837  const wxString &aSheetLayer )
838 {
840  return;
841 
842  wxDC* DC = aSettings->GetPrintDC();
843  wxPoint origin = DC->GetDeviceOrigin();
844 
845  if( origin.y > 0 )
846  {
847  DC->SetDeviceOrigin( 0, 0 );
848  DC->SetAxisOrientation( true, false );
849  }
850 
851  PrintPageLayout( aSettings, GetPageSettings(), GetScreenDesc(), aFilename, GetTitleBlock(),
852  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber, aScalar, &Prj(),
853  aSheetLayer );
854 
855  if( origin.y > 0 )
856  {
857  DC->SetDeviceOrigin( origin.x, origin.y );
858  DC->SetAxisOrientation( true, true );
859  }
860 }
861 
862 
864 {
865  // Virtual function. Base class implementation returns an empty string.
866  return wxEmptyString;
867 }
868 
869 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
870  const wxString& wildcard, const wxString& ext,
871  bool isDirectory )
872 {
873  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
874  aFilename.SetExt( ext );
875 
876  if( isDirectory && doOpen )
877  {
878  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
879  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
880 
881  if( dlg.ShowModal() == wxID_CANCEL )
882  return false;
883 
884  aFilename = dlg.GetPath();
885  aFilename.SetExt( ext );
886  }
887  else
888  {
889  // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
890  if( aFilename.GetName().empty() )
891  aFilename.SetName( "Library" );
892 
893  wxString dir = Prj().IsNullProject() ? aFilename.GetFullPath() : Prj().GetProjectPath();
894 
895  wxFileDialog dlg( this, prompt, dir, aFilename.GetFullName(),
896  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
897  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
898 
899  if( dlg.ShowModal() == wxID_CANCEL )
900  return false;
901 
902  aFilename = dlg.GetPath();
903  aFilename.SetExt( ext );
904  }
905 
906  return true;
907 }
908 
909 
911 {
912  // Rebuild all toolbars, and update the checked state of check tools
913  if( m_mainToolBar )
915 
916  if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
918 
919  if( m_optionsToolBar ) // Options (typically on left edge of window)
921 
922  if( m_auxiliaryToolBar ) // Additional tools under main toolbar
924 }
925 
926 
928 {
929  if( !m_colorSettings )
930  m_colorSettings = Pgm().GetSettingsManager().GetColorSettings();
931 
932  return m_colorSettings;
933 }
double To_User_Unit(EDA_UNITS 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:92
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
virtual void ReCreateVToolbar()=0
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:537
int m_ScreenNumber
Definition: base_screen.h:79
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:428
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:407
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
PROJECT holds project specific data.
Definition: project.h:61
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
std::vector< wxString > find_history
Definition: app_settings.h:108
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
ACTION_TOOLBAR * m_auxiliaryToolBar
This file is part of the common library.
ACTION_TOOLBAR * m_optionsToolBar
#define ZOOM_COEFF
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
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
int color
Definition: DXF_plotter.cpp:61
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.
virtual void PrintPage(RENDER_SETTINGS *aSettings)
Print the page pointed by current screen, set by the calling print function.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ws_draw_item.h:423
static constexpr GAL_TYPE GAL_FALLBACK
std::vector< wxSocketBase * > m_sockets
interprocess communication
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:415
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
void OnMove(wxMoveEvent &aEvent) override
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
wxArrayString m_findStringHistoryList
void PrintWorkSheet(RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the page layout with the frame and the basic inscriptions.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
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.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
wxAuiManager m_auimgr
static TOOL_ACTION zoomFitObjects
Definition: actions.h:95
ACTION_TOOLBAR * m_mainToolBar
Definition: color4d.h:44
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
Sentinel, do not use as a parameter.
The base class for create windows for drawing purpose.
#define DEFAULT_MAX_UNDO_ITEMS
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:124
wxChoice * m_gridSelectBox
virtual void LoadSettings()
Load new settings from program common settings
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
prevents opening same file multiple times.
std::vector< double > zoom_factors
Definition: app_settings.h:86
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:211
Auxiliary rendering target (noncached)
Definition: definitions.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:268
void DisplayUnitsMsg()
Display current unit pane in the status bar.
EDA_DRAW_PANEL_GAL * m_canvas
GAL display options - this is the frame's interface to setting GAL display options.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
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.
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:603
BASE_SCREEN * m_currentScreen
current used SCREEN
static TOOL_ACTION gridPreset
Definition: actions.h:137
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
FIND_REPLACE m_FindReplace
Definition: app_settings.h:159
#define NULL
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 MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:569
bool IsGridVisible() const
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:453
void WriteConfig(WINDOW_SETTINGS &aCfg)
GRID_SETTINGS grid
Definition: app_settings.h:89
EDA_MSG_PANEL * m_messagePanel
GAL not used (the legacy wxDC engine is used)
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid combobox.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
bool m_showBorderAndTitleBlock
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, 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:295
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:43
coord_type GetWidth() const
Definition: box2.h:197
wxChoice * m_zoomSelectBox
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:151
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, bool mmFirst)
Definition: grid_menu.cpp:80
std::vector< wxString > replace_history
Definition: app_settings.h:110
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:435
ACTIONS * m_actions
Definition: tools_holder.h:51
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Returns a pointer to the window settings for this frame.
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.
wxWindow * findDialog(wxWindowList &aList)
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
int GetMaxUndoItems() const
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.
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Returns bbox of document with option to not include some items.
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.
#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.
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:136
virtual void ResizeScreen(int aWidth, int aHeight)
Resizes the canvas.
void StartDrawing()
Function StartDrawing() Begins drawing if it was stopped previously.
virtual void ReCreateOptToolbar()=0
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
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
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:52
COMMON_TOOLS.
Definition: common_tools.h:38
COLOR_SETTINGS * m_colorSettings
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
void AddSeparator(int aOrder=ANY_ORDER)
Adds a separator to the menu.
wxSocketServer * m_socketServer
const VECTOR2D & GetGridSize() const
Returns the grid size.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
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.
WINDOW_SETTINGS m_Window
Definition: app_settings.h:171
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302
void SetAutoSaveInterval(int aInterval)
void Print(RENDER_SETTINGS *aSettings)
Draws the item list created by BuildWorkSheetGraphicList.
virtual void ReCreateHToolbar()=0
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:50
see class PGM_BASE
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
bool IsType(FRAME_T aType) const
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:201
static TOOL_ACTION zoomCenter
Definition: actions.h:93
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:444
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
void PrintPageLayout(RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, double aScalar, const PROJECT *aProject, const wxString &aSheetLayer)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...
double m_scaleFactor
The pixel scale factor (>1 for hi-DPI scaled displays)
#define _(s)
Definition: 3d_actions.cpp:33
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
EDA_UNITS m_userUnits
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
virtual void ReCreateAuxiliaryToolbar()
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
virtual COLOR_SETTINGS * GetColorSettings()
Returns a pointer to the active color theme settings.
void SetGridVisibility(bool aVisibility)
Sets the visibility setting of the grid.
wxFindReplaceData * m_findReplaceData
int GetDefaultPenWidth() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
int m_NumberOfScreens
Definition: base_screen.h:80
static TOOL_ACTION zoomIn
Definition: actions.h:89
static TOOL_ACTION zoomOut
Definition: actions.h:90
void SetUserUnits(EDA_UNITS aUnits)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
void OnGridSettings(wxCommandEvent &event)
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
void UpdateStatusBar() override
Update the status bar information.
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
Update the checked item in the zoom combobox.
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 SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:392
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
virtual void DisplayGridMsg()
Display current grid size in the status bar.
BASE_SCREEN class implementation.
Message panel definition file.
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
void ToggleUserUnits() override
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:273
static int GetRequiredHeight()
Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:71
virtual void SetGridVisibility(bool aVisible)
long m_firstRunDialogSetting
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:594
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
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 LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual wxString GetScreenDesc() const
static const wxString productName
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
ACTION_TOOLBAR * m_drawToolBar
File locking utilities.