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/action_manager.h>
46 #include <tool/actions.h>
47 #include <tool/common_tools.h>
48 #include <tool/grid_menu.h>
50 #include <tool/tool_dispatcher.h>
51 #include <tool/tool_manager.h>
52 #include <tool/tool_menu.h>
53 #include <tool/zoom_menu.h>
54 #include <trace_helpers.h>
55 #include <view/view.h>
56 #include <ws_draw_item.h>
57 #include <wx/snglinst.h>
59 
60 #define FR_HISTORY_LIST_CNT 10
61 
62 
63 BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
66 END_EVENT_TABLE()
67 
68 
69 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
70  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
71  long aStyle, const wxString & aFrameName ) :
72  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
73 {
74  m_socketServer = nullptr;
75  m_mainToolBar = NULL;
76  m_drawToolBar = NULL;
77  m_optionsToolBar = NULL;
78  m_auxiliaryToolBar = NULL;
79  m_gridSelectBox = NULL;
80  m_zoomSelectBox = NULL;
81  m_firstRunDialogSetting = 0;
82  m_UndoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
83 
84  m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
85  m_canvas = NULL;
86  m_toolDispatcher = NULL;
87  m_messagePanel = NULL;
88  m_currentScreen = NULL;
89  m_showBorderAndTitleBlock = false; // true to display reference sheet.
90  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
91  m_showPageLimits = false;
92  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
93  // BLACK for Pcbnew, BLACK or WHITE for eeschema
94  m_colorSettings = nullptr;
95  m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
96  m_userUnits = EDA_UNITS::MILLIMETRES;
97  m_PolarCoords = false;
98  m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
99 
100  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
101 
102  CreateStatusBar( 7 );
103 
104  // set the size of the status bar subwindows:
105 
106  wxWindow* stsbar = GetStatusBar();
107 
108  int dims[] = {
109 
110  // remainder of status bar on far left is set to a default or whatever is left over.
111  -1,
112 
113  // When using GetTextSize() remember the width of character '1' is not the same
114  // as the width of '0' unless the font is fixed width, and it usually won't be.
115 
116  // zoom:
117  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
118 
119  // cursor coords
120  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
121 
122  // delta distances
123  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
124 
125  // grid size
126  GetTextSize( wxT( "grid X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
127 
128  // units display, Inches is bigger than mm
129  GetTextSize( _( "Inches" ), stsbar ).x + 10,
130 
131  // Size for the "Current Tool" panel; longest string from SetTool()
132  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
133  };
134 
135  SetStatusWidths( arrayDim( dims ), dims );
136 
137  // Create child subwindows.
138  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
139  m_FramePos.x = m_FramePos.y = 0;
140  m_FrameSize.y -= m_MsgFrameHeight;
141 
142  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
143  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
144 
145  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
146 }
147 
148 
150 {
151  delete m_socketServer;
152 
153  for( auto socket : m_sockets )
154  {
155  socket->Shutdown();
156  socket->Destroy();
157  }
158 
160 
161  delete m_actions;
162  delete m_toolManager;
163  delete m_toolDispatcher;
164  delete m_canvas;
165 
166  delete m_currentScreen;
168 
169  delete m_findReplaceData;
170 
171  m_auimgr.UnInit();
172 
173  ReleaseFile();
174 }
175 
176 
178 {
179  m_file_checker = nullptr;
180 }
181 
182 
183 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
184 {
185  m_file_checker = ::LockFile( aFileName );
186 
187  return bool( m_file_checker );
188 }
189 
190 
192 {
193  UpdateStatusBar();
194  UpdateMsgPanel();
195 }
196 
197 
199 {
202 
203  wxCommandEvent e( UNITS_CHANGED );
204  ProcessEventLocally( e );
205 }
206 
207 
208 void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
209 {
210  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
211 
212  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
213  KIGFX::VIEW_CONTROLS* viewControls = GetCanvas()->GetViewControls();
214 
216 
217  viewControls->LoadSettings();
218 
219  m_galDisplayOptions.ReadCommonConfig( *settings, this );
220 }
221 
222 
224 {
225  if( m_messagePanel )
227 }
228 
229 
231 {
232  UpdateStatusBar();
233  DisplayUnitsMsg();
234 
235  if( m_gridSelectBox == NULL )
236  return;
237 
238  // Update grid values with the current units setting.
239  m_gridSelectBox->Clear();
240  wxArrayString gridsList;
241 
243 
244  for( const wxString& grid : gridsList )
245  m_gridSelectBox->Append( grid );
246 
247  m_gridSelectBox->Append( wxT( "---" ) );
248  m_gridSelectBox->Append( _( "Edit User Grid..." ) );
249 
250  m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
251 }
252 
253 
254 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
255 {
256  // No need to update the grid select box if it doesn't exist or the grid setting change
257  // was made using the select box.
258  if( m_gridSelectBox == NULL )
259  return;
260 
261  int idx = config()->m_Window.grid.last_size_idx;
262  idx = std::max( 0, std::min( idx, (int) m_gridSelectBox->GetCount() - 1 ) );
263 
264  if( idx != m_gridSelectBox->GetSelection() )
265  m_gridSelectBox->SetSelection( idx );
266 }
267 
268 
270 {
271  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
272 }
273 
274 
275 /*
276  * Respond to selections in the toolbar grid popup
277  */
278 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
279 {
280  wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" );
281 
282  int idx = m_gridSelectBox->GetCurrentSelection();
283 
284  if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
285  {
286  // wxWidgets will check the separator, which we don't want.
287  // Re-check the current grid.
288  wxUpdateUIEvent dummy;
290  }
291  else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
292  {
293  // wxWidgets will check the Grid Settings... entry, which we don't want.
294  // Re-check the current grid.
295  wxUpdateUIEvent dummy;
297  // Now run the Grid Settings... dialog
298  wxCommandEvent dummy2;
299  OnGridSettings( dummy2 );
300  }
301  else
302  {
304  }
305 
306  UpdateStatusBar();
307  m_canvas->Refresh();
308 }
309 
310 
311 void EDA_DRAW_FRAME::OnGridSettings( wxCommandEvent& aEvent )
312 {
313  DIALOG_GRID_SETTINGS dlg( this );
314 
315  if( dlg.ShowModal() == wxID_OK )
316  {
317  UpdateStatusBar();
318  GetCanvas()->Refresh();
319  }
320 }
321 
322 
324 {
325  return config()->m_Window.grid.show;
326 }
327 
328 
330 {
331  config()->m_Window.grid.show = aVisible;
332 
333  // Update the display with the new grid
334  if( GetCanvas() )
335  {
336  // Check to ensure these exist, since this function could be called before
337  // the GAL and View have been created
338  if( GetCanvas()->GetGAL() )
339  GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
340 
341  if( GetCanvas()->GetView() )
343 
344  GetCanvas()->Refresh();
345  }
346 }
347 
348 
350 {
351  if( m_zoomSelectBox == NULL )
352  return;
353 
354  double zoom = m_canvas->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
355 
356  m_zoomSelectBox->Clear();
357  m_zoomSelectBox->Append( _( "Zoom Auto" ) );
358  m_zoomSelectBox->SetSelection( 0 );
359 
360  for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
361  {
362  double current = config()->m_Window.zoom_factors[i];
363 
364  m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
365 
366  if( zoom == current )
367  m_zoomSelectBox->SetSelection( i + 1 );
368  }
369 }
370 
371 
372 void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
373 {
374  if( m_zoomSelectBox == NULL || m_zoomSelectBox->GetParent() == NULL )
375  return;
376 
377  int current = 0; // display Auto if no match found
378 
379  // check for a match within 1%
380  double zoom = GetCanvas()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
381 
382  for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); i++ )
383  {
384  if( std::fabs( zoom - config()->m_Window.zoom_factors[i] ) < ( zoom / 100.0 ) )
385  {
386  current = i + 1;
387  break;
388  }
389  }
390 
391  if( current != m_zoomSelectBox->GetSelection() )
392  m_zoomSelectBox->SetSelection( current );
393 }
394 
395 
396 /*
397  * Respond to selections in the toolbar zoom popup
398  */
399 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
400 {
401  wxCHECK_RET( m_zoomSelectBox, "m_zoomSelectBox uninitialized" );
402 
403  int id = m_zoomSelectBox->GetCurrentSelection();
404 
405  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
406  return;
407 
408  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
409  UpdateStatusBar();
410  m_canvas->Refresh();
411 }
412 
413 
414 void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
415 {
416  // If the window is moved to a different display, the scaling factor may change
417  double oldFactor = m_galDisplayOptions.m_scaleFactor;
419 
420  if( oldFactor != m_galDisplayOptions.m_scaleFactor )
421  {
422  wxSize clientSize = GetClientSize();
423  GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
424  GetCanvas()->GetView()->MarkDirty();
425  }
426 
427  aEvent.Skip();
428 }
429 
430 
432 {
433  COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
434  CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
435 
436  aMenu.AddSeparator( 1000 );
438  aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
439  aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
441 
442  aMenu.AddSeparator( 1000 );
443 
444  auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
445  zoomMenu->SetTool( commonTools );
446  aToolMenu.AddSubMenu( zoomMenu );
447 
448  auto gridMenu = std::make_shared<GRID_MENU>( this );
449  gridMenu->SetTool( commonTools );
450  aToolMenu.AddSubMenu( gridMenu );
451 
452  aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
453  aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
454 }
455 
456 
458 {
459  wxAcceleratorEntry entries[1];
460  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
461  wxAcceleratorTable accel( 1, entries );
462  SetAcceleratorTable( accel );
463 }
464 
465 
466 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
467 {
468  SetStatusText( msg, 6 );
469 }
470 
471 
472 /*
473  * Display the grid status.
474  */
476 {
477  wxString line;
478  wxString gridformatter;
479 
480  switch( m_userUnits )
481  {
482  case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break;
483  case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break;
484  default: gridformatter = "grid %f"; break;
485  }
486 
487  double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
488  line.Printf( gridformatter, grid );
489 
490  SetStatusText( line, 4 );
491 }
492 
493 
495 {
496  wxString msg;
497 
498  switch( m_userUnits )
499  {
500  case EDA_UNITS::INCHES: msg = _( "Inches" ); break;
501  case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
502  default: msg = _( "Units" ); break;
503  }
504 
505  SetStatusText( msg, 5 );
506 }
507 
508 
509 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
510 {
511  m_FrameSize = GetClientSize( );
512 
513  SizeEv.Skip();
514 }
515 
516 
518 {
519  SetStatusText( GetZoomLevelIndicator(), 1 );
520 
521  // Absolute and relative cursor positions are handled by overloading this function and
522  // handling the internal to user units conversion at the appropriate level.
523 
524  // refresh units display
525  DisplayUnitsMsg();
526 }
527 
528 
530 {
531  // returns a human readable value which can be displayed as zoom
532  // level indicator in dialogs.
533  double zoom = m_canvas->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
534  return wxString::Format( wxT( "Z %.2f" ), zoom );
535 }
536 
537 
539 {
541 
542  COMMON_SETTINGS* cmnCfg = Pgm().GetCommonSettings();
543  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
544 
545  // Read units used in dialogs and toolbars
546  SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
547 
550 
551  m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
552 
553  m_findReplaceData->SetFlags( aCfg->m_FindReplace.flags );
554  m_findReplaceData->SetFindString( aCfg->m_FindReplace.find_string );
555  m_findReplaceData->SetReplaceString( aCfg->m_FindReplace.replace_string );
556 
557  for( auto& s : aCfg->m_FindReplace.find_history )
558  m_findStringHistoryList.Add( s );
559 
560  for( auto& s : aCfg->m_FindReplace.replace_history )
562 }
563 
564 
566 {
568 
569  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
570 
571  aCfg->m_System.units = static_cast<int>( m_userUnits );
574 
575  m_galDisplayOptions.WriteConfig( *window );
576 
577  aCfg->m_FindReplace.flags = m_findReplaceData->GetFlags();
578  aCfg->m_FindReplace.find_string = m_findReplaceData->GetFindString();
579  aCfg->m_FindReplace.replace_string = m_findReplaceData->GetReplaceString();
580 
581  aCfg->m_FindReplace.find_history.clear();
582  aCfg->m_FindReplace.replace_history.clear();
583 
584  for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
585  aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
586 
587  for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
588  aCfg->m_FindReplace.replace_history.push_back(
589  m_replaceStringHistoryList[ i ].ToStdString() );
590 }
591 
592 
593 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
594  COLOR4D color, int pad )
595 {
596  if( m_messagePanel )
597  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
598 }
599 
600 
602 {
603  if( m_messagePanel )
605 }
606 
607 
609 {
610  if( m_messagePanel )
611  {
613 
614  for( const MSG_PANEL_ITEM& item : aList )
615  m_messagePanel->AppendMessage( item );
616  }
617 }
618 
619 
621 {
622  wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
623 
624  MSG_PANEL_ITEMS items;
625  aItem->GetMsgPanelInfo( this, items );
626  SetMsgPanel( items );
627 }
628 
629 
631 {
633 }
634 
635 
637 {
638  GetCanvas()->SetEvtHandlerEnabled( true );
639  GetCanvas()->StartDrawing();
640 }
641 
642 
644 {
645  GetCanvas()->SwitchBackend( aCanvasType );
647 
649 }
650 
651 
653 {
656 
657  if( cfg )
658  canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
659 
660  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
661  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
662  {
663  wxASSERT( false );
665  }
666 
667  // Legacy canvas no longer supported. Switch to Cairo, and on the first instantiation
668  // the user will be prompted to switch to OpenGL
669  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
670  {
671 #ifdef __WXMAC__
672  // Cairo renderer doesn't handle Retina displays
674 #else
676 #endif
677  }
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 
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  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
890  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
891  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
892 
893  if( dlg.ShowModal() == wxID_CANCEL )
894  return false;
895 
896  aFilename = dlg.GetPath();
897  aFilename.SetExt( ext );
898  }
899 
900  return true;
901 }
902 
903 
905 {
906  // Rebuild all toolbars, and update the checked state of check tools
907  if( m_mainToolBar )
909 
910  if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
912 
913  if( m_optionsToolBar ) // Options (typically on left edge of window)
915 
916  if( m_auxiliaryToolBar ) // Additional tools under main toolbar
918 
919  // Update the checked state of tools
920  SyncToolbars();
921 }
922 
923 
925 {
926  if( !m_colorSettings )
927  m_colorSettings = Pgm().GetSettingsManager().GetColorSettings();
928 
929  return m_colorSettings;
930 }
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)
Function ShowAlways 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:521
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:538
int m_ScreenNumber
Definition: base_screen.h:79
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:429
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:408
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:100
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
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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:424
std::vector< wxSocketBase * > m_sockets
interprocess communication
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:416
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
void OnMove(wxMoveEvent &aEvent) override
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of ckeck 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
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 ZOOM_COEFF
#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
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:78
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:207
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:68
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:604
BASE_SCREEN * m_currentScreen
current used SCREEN
static TOOL_ACTION gridPreset
Definition: actions.h:135
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:91
FIND_REPLACE m_FindReplace
Definition: app_settings.h:143
#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:585
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:454
void WriteConfig(WINDOW_SETTINGS &aCfg)
GRID_SETTINGS grid
Definition: app_settings.h:81
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:196
wxChoice * m_zoomSelectBox
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
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:102
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:436
ACTIONS * m_actions
Definition: tools_holder.h:49
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 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.
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:50
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)
Function AddSeparator()
wxSocketServer * m_socketServer
const VECTOR2D & GetGridSize() const
Returns the grid size.
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:153
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:301
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:48
see class PGM_BASE
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:445
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
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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:88
static TOOL_ACTION zoomOut
Definition: actions.h:89
void SetUserUnits(EDA_UNITS aUnits)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
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:393
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:268
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:610
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
virtual const BOX2I GetDocumentExtents() const
File locking utilities.