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 <base_screen.h>
27 #include <bitmaps.h>
28 #include <confirm.h>
29 #include <dialog_helpers.h>
30 #include <dialog_shim.h>
31 #include <eda_draw_frame.h>
32 #include <fctsys.h>
33 #include <filehistory.h>
34 #include <id.h>
35 #include <kiface_i.h>
36 #include <lockfile.h>
37 #include <macros.h>
38 #include <msgpanel.h>
39 #include <page_info.h>
40 #include <pgm_base.h>
41 #include <settings/app_settings.h>
45 #include <title_block.h>
46 #include <tool/action_manager.h>
47 #include <tool/actions.h>
48 #include <tool/common_tools.h>
49 #include <tool/grid_menu.h>
51 #include <tool/tool_dispatcher.h>
52 #include <tool/tool_manager.h>
53 #include <tool/tool_menu.h>
54 #include <tool/zoom_menu.h>
55 #include <trace_helpers.h>
56 #include <view/view.h>
57 #include <ws_draw_item.h>
58 #include <wx/snglinst.h>
59 
60 
61 #define FR_HISTORY_LIST_CNT 10
62 
63 
64 EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
65  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
66  long aStyle, const wxString & aFrameName ) :
67  KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
68 {
69  m_socketServer = nullptr;
78 
80  m_canvas = NULL;
84  m_showBorderAndTitleBlock = false; // true to display reference sheet.
85  m_LastGridSizeId = 0;
86  m_drawGrid = true; // hide/Show grid. default = show
87  m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
88  m_showPageLimits = false;
89  m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
90  // BLACK for Pcbnew, BLACK or WHITE for eeschema
91  m_colorSettings = nullptr;
93  m_zoomLevelCoeff = 1.0;
95  m_PolarCoords = false;
96  m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
97 
98  m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
99 
100  CreateStatusBar( 7 );
101 
102  // set the size of the status bar subwindows:
103 
104  wxWindow* stsbar = GetStatusBar();
105 
106  int dims[] = {
107 
108  // remainder of status bar on far left is set to a default or whatever is left over.
109  -1,
110 
111  // When using GetTextSize() remember the width of character '1' is not the same
112  // as the width of '0' unless the font is fixed width, and it usually won't be.
113 
114  // zoom:
115  GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
116 
117  // cursor coords
118  GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
119 
120  // delta distances
121  GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
122 
123  // grid size
124  GetTextSize( wxT( "grid X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
125 
126  // units display, Inches is bigger than mm
127  GetTextSize( _( "Inches" ), stsbar ).x + 10,
128 
129  // Size for the "Current Tool" panel; longest string from SetTool()
130  GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
131  };
132 
133  SetStatusWidths( arrayDim( dims ), dims );
134 
135  // Create child subwindows.
136  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
137  m_FramePos.x = m_FramePos.y = 0;
139 
140  m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
141  wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
142 
143  m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
144 }
145 
146 
148 {
149  delete m_socketServer;
150 
151  for( auto socket : m_sockets )
152  {
153  socket->Shutdown();
154  socket->Destroy();
155  }
156 
158 
159  delete m_actions;
160  delete m_toolManager;
161  delete m_toolDispatcher;
162  delete m_canvas;
163 
164  delete m_currentScreen;
166 
167  delete m_findReplaceData;
168 
169  m_auimgr.UnInit();
170 
171  ReleaseFile();
172 }
173 
174 
176 {
177  m_file_checker = nullptr;
178 }
179 
180 
181 bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
182 {
183  m_file_checker = ::LockFile( aFileName );
184 
185  return bool( m_file_checker );
186 }
187 
188 
190 {
191  UpdateStatusBar();
192  UpdateMsgPanel();
193 }
194 
195 
196 void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
197 {
198  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
199 
200  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
201  KIGFX::VIEW_CONTROLS* viewControls = GetCanvas()->GetViewControls();
202 
204 
205  int historySize = settings->m_System.file_history_size;
206  Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
207 
208  viewControls->EnableMousewheelPan( settings->m_Input.mousewheel_pan );
209  viewControls->EnableCursorWarping( settings->m_Input.center_on_zoom );
210  viewControls->EnableAutoPan( settings->m_Input.auto_pan );
211 
212  m_galDisplayOptions.ReadCommonConfig( *settings, this );
213 }
214 
215 
217 {
218  if( m_messagePanel )
220 }
221 
222 
223 void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
224 {
225  // No need to update the grid select box if it doesn't exist or the grid setting change
226  // was made using the select box.
227  if( m_gridSelectBox == NULL )
228  return;
229 
230  int select = wxNOT_FOUND;
231 
232  for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
233  {
234  if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId )
235  {
236  select = (int) i;
237  break;
238  }
239  }
240 
241  if( select != m_gridSelectBox->GetSelection() )
242  m_gridSelectBox->SetSelection( select );
243 }
244 
245 
246 void EDA_DRAW_FRAME::PrintPage( wxDC* aDC )
247 {
248  wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
249 }
250 
251 
252 /*
253  * Respond to selections in the toolbar grid popup
254  */
255 void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
256 {
257  wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" );
258 
259  int id = m_gridSelectBox->GetCurrentSelection() + ID_POPUP_GRID_FIRST;
260 
261  if( id == ID_POPUP_GRID_SEPARATOR )
262  {
263  // wxWidgets will check the separator, which we don't want.
264  // Re-check the current grid.
265  wxUpdateUIEvent dummy;
267  }
268  else if( id == ID_POPUP_GRID_SETTINGS )
269  {
270  // wxWidgets will check the Grid Settings... entry, which we don't want.
271  // R-check the current grid.
272  wxUpdateUIEvent dummy;
274  // Now run the Grid Settings... dialog
275  wxCommandEvent dummy2;
276  OnGridSettings( dummy2 );
277  }
278  else if( id >= ID_POPUP_GRID_FIRST && id < ID_POPUP_GRID_SEPARATOR )
279  {
281  }
282 
283  UpdateStatusBar();
284  m_canvas->Refresh();
285 }
286 
287 
289 {
290  wxAcceleratorEntry entries[1];
291  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
292  wxAcceleratorTable accel( 1, entries );
293  SetAcceleratorTable( accel );
294 }
295 
296 
297 /*
298  * Respond to selections in the toolbar zoom popup
299  */
300 void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
301 {
302  wxCHECK_RET( m_zoomSelectBox, "m_zoomSelectBox uninitialized" );
303 
304  int id = m_zoomSelectBox->GetCurrentSelection();
305 
306  if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
307  return;
308 
309  m_toolManager->RunAction( "common.Control.zoomPreset", true, id );
310  UpdateStatusBar();
311  m_canvas->Refresh();
312 }
313 
314 
316 {
317  return GetScreen()->GetZoom();
318 }
319 
320 
321 void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
322 {
323  // If the window is moved to a different display, the scaling factor may change
324  double oldFactor = m_galDisplayOptions.m_scaleFactor;
326 
327  if( oldFactor != m_galDisplayOptions.m_scaleFactor )
328  {
329  wxSize clientSize = GetClientSize();
330  GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
331  GetCanvas()->GetView()->MarkDirty();
332  }
333 
334  aEvent.Skip();
335 }
336 
337 
339 {
340  COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
341  CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
342 
343  aMenu.AddSeparator( 1000 );
345  aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
346  aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
348 
349  aMenu.AddSeparator( 1000 );
350 
351  auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
352  zoomMenu->SetTool( commonTools );
353  aToolMenu.AddSubMenu( zoomMenu );
354 
355  auto gridMenu = std::make_shared<GRID_MENU>( this );
356  gridMenu->SetTool( commonTools );
357  aToolMenu.AddSubMenu( gridMenu );
358 
359  aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
360  aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
361 }
362 
363 
364 void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
365 {
366  SetStatusText( msg, 6 );
367 }
368 
369 
370 /*
371  * Display the grid status.
372  */
374 {
375  wxString line;
376  wxString gridformatter;
377 
378  switch( m_userUnits )
379  {
380  case EDA_UNITS::INCHES:
381  gridformatter = "grid %.3f";
382  break;
383 
385  gridformatter = "grid %.4f";
386  break;
387 
388  default:
389  gridformatter = "grid %f";
390  break;
391  }
392 
393  wxRealPoint curr_grid_size = GetScreen()->GetGridSize();
394  double grid = To_User_Unit( m_userUnits, curr_grid_size.x );
395  line.Printf( gridformatter, grid );
396 
397  SetStatusText( line, 4 );
398 }
399 
400 
402 {
403  wxString msg;
404 
405  switch( m_userUnits )
406  {
407  case EDA_UNITS::INCHES:
408  msg = _( "Inches" );
409  break;
411  msg = _( "mm" );
412  break;
413  default: msg = _( "Units" ); break;
414  }
415 
416  SetStatusText( msg, 5 );
417 }
418 
419 
420 void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
421 {
422  m_FrameSize = GetClientSize( );
423 
424  SizeEv.Skip();
425 }
426 
427 
429 {
430  SetStatusText( GetZoomLevelIndicator(), 1 );
431 
432  // Absolute and relative cursor positions are handled by overloading this function and
433  // handling the internal to user units conversion at the appropriate level.
434 
435  // refresh units display
436  DisplayUnitsMsg();
437 }
438 
439 
441 {
442  // returns a human readable value which can be displayed as zoom
443  // level indicator in dialogs.
444  return wxString::Format( wxT( "Z %.2f" ), m_canvas->GetGAL()->GetZoomFactor() );
445 }
446 
447 
449 {
451 
452  wxString baseCfgName = ConfigBaseName();
453  COMMON_SETTINGS* cmnCfg = Pgm().GetCommonSettings();
454  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
455 
456  // Read units used in dialogs and toolbars
457  SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
458 
459  // Read show/hide grid entry
460  SetGridVisibility( window->grid.show );
461 
462  m_LastGridSizeId = window->grid.last_size;
463 
464  // m_LastGridSizeId is an offset, expected to be >= 0
465  if( m_LastGridSizeId < 0 )
466  m_LastGridSizeId = 0;
467 
470 
471  m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
472 
473  m_findReplaceData->SetFlags( aCfg->m_FindReplace.flags );
474  m_findReplaceData->SetFindString( aCfg->m_FindReplace.find_string );
475  m_findReplaceData->SetReplaceString( aCfg->m_FindReplace.replace_string );
476 
477  for( auto& s : aCfg->m_FindReplace.find_history )
478  m_findStringHistoryList.Add( s );
479 
480  for( auto& s : aCfg->m_FindReplace.replace_history )
482 }
483 
484 
486 {
488 
489  WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
490 
491  aCfg->m_System.units = static_cast<int>( m_userUnits );
493 
494  window->grid.show = IsGridVisible();
495  window->grid.last_size = m_LastGridSizeId;
496 
497  if( GetScreen() )
499 
500  m_galDisplayOptions.WriteConfig( *window );
501 
502  aCfg->m_FindReplace.flags = m_findReplaceData->GetFlags();
503  aCfg->m_FindReplace.find_string = m_findReplaceData->GetFindString();
504  aCfg->m_FindReplace.replace_string = m_findReplaceData->GetReplaceString();
505 
506  aCfg->m_FindReplace.find_history.clear();
507  aCfg->m_FindReplace.replace_history.clear();
508 
509  for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
510  aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
511 
512  for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
513  aCfg->m_FindReplace.replace_history.push_back(
514  m_replaceStringHistoryList[ i ].ToStdString() );
515 }
516 
517 
518 void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
519  COLOR4D color, int pad )
520 {
521  if( m_messagePanel )
522  m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
523 }
524 
525 
527 {
528  if( m_messagePanel )
530 }
531 
532 
534 {
535  if( m_messagePanel )
536  {
538 
539  for( const MSG_PANEL_ITEM& item : aList )
540  m_messagePanel->AppendMessage( item );
541  }
542 }
543 
544 
546 {
547  wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
548 
549  MSG_PANEL_ITEMS items;
550  aItem->GetMsgPanelInfo( m_userUnits, items );
551  SetMsgPanel( items );
552 }
553 
554 
556 {
558 }
559 
560 
562 {
563  GetCanvas()->SetEvtHandlerEnabled( true );
564  GetCanvas()->StartDrawing();
565 }
566 
567 
569 {
570  GetCanvas()->SwitchBackend( aCanvasType );
572 
574 }
575 
576 
578 {
581 
582  if( cfg )
583  canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
584 
585  if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
586  || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
587  {
588  wxASSERT( false );
590  }
591 
592  // Legacy canvas no longer supported. Switch to Cairo, and on the first instantiation
593  // the user will be prompted to switch to OpenGL
594  if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
595  {
596 #ifdef __WXMAC__
597  // Cairo renderer doesn't handle Retina displays
599 #else
601 #endif
602  }
603 
604  return canvasType;
605 }
606 
607 
609 {
610  // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
611  // have a fixed type, or do not have a option to set the canvas type (they inherit from
612  // a parent frame)
613  FRAME_T allowed_frames[] =
614  {
615  FRAME_SCH,
618  };
619 
620  bool allow_save = false;
621 
622  for( unsigned ii = 0; ii < arrayDim( allowed_frames ); ii++ )
623  {
624  if( m_Ident == allowed_frames[ii] )
625  {
626  allow_save = true;
627  break;
628  }
629  }
630 
631  if( !allow_save )
632  return false;
633 
634  if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
635  || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
636  {
637  wxASSERT( false );
638  return false;
639  }
640 
642 
643  if( cfg )
644  cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
645 
646  return false;
647 }
648 
649 //-----< BASE_SCREEN API moved here >--------------------------------------------
650 
652 {
653  return GetScreen()->getNearestGridPosition( aPosition, GetGridOrigin() );
654 }
655 
656 //-----</BASE_SCREEN API moved here >--------------------------------------------
657 
659 {
660  return BOX2I();
661 }
662 
663 
665 {
666  // To be implemented by subclasses.
667 }
668 
669 
670 void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
671 {
673 }
674 
675 
676 // Find the first child dialog.
677 wxWindow* findDialog( wxWindowList& aList )
678 {
679  for( wxWindow* window : aList )
680  {
681  if( dynamic_cast<DIALOG_SHIM*>( window ) )
682  return window;
683  }
684  return NULL;
685 }
686 
687 
689 {
690  bool centerView = false;
691  BOX2D r = GetCanvas()->GetView()->GetViewport();
692 
693  // Center if we're off the current view, or within 10% of its edge
694  r.Inflate( - (int) r.GetWidth() / 10 );
695 
696  if( !r.Contains( aPos ) )
697  centerView = true;
698 
699  // Center if we're behind an obscuring dialog, or within 10% of its edge
700  wxWindow* dialog = findDialog( GetChildren() );
701 
702  if( dialog )
703  {
704  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
705  dialog->GetSize() );
706  dialogRect.Inflate( dialogRect.GetWidth() / 10 );
707 
708  if( dialogRect.Contains( (wxPoint) GetCanvas()->GetView()->ToScreen( aPos ) ) )
709  centerView = true;
710  }
711 
712  if( centerView )
713  {
714  // If a dialog partly obscures the window, then center on the uncovered area.
715  if( dialog )
716  {
717  wxRect dialogRect( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
718  dialog->GetSize() );
719  GetCanvas()->GetView()->SetCenter( aPos, dialogRect );
720  }
721  else
722  GetCanvas()->GetView()->SetCenter( aPos );
723  }
724 
726 }
727 
728 
729 static const wxString productName = wxT( "KiCad E.D.A. " );
730 
731 void PrintPageLayout( wxDC* aDC, const PAGE_INFO& aPageInfo, const wxString& aFullSheetName,
732  const wxString& aFileName, const TITLE_BLOCK& aTitleBlock, int aSheetCount,
733  int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor,
734  const wxString& aSheetLayer )
735 {
736  WS_DRAW_ITEM_LIST drawList;
737 
738  drawList.SetDefaultPenSize( aPenWidth );
739  drawList.SetMilsToIUfactor( aScalar );
740  drawList.SetSheetNumber( aSheetNumber );
741  drawList.SetSheetCount( aSheetCount );
742  drawList.SetFileName( aFileName );
743  drawList.SetSheetName( aFullSheetName );
744  drawList.SetSheetLayer( aSheetLayer );
745 
746  drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
747 
748  // Draw item list
749  drawList.Print( aDC, aColor );
750 }
751 
752 
753 void EDA_DRAW_FRAME::PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
754  double aScalar, const wxString &aFilename,
755  const wxString &aSheetLayer, COLOR4D aColor )
756 {
758  return;
759 
760  COLOR4D color = ( aColor != COLOR4D::UNSPECIFIED ) ? aColor : COLOR4D( RED );
761 
762  wxPoint origin = aDC->GetDeviceOrigin();
763 
764  if( origin.y > 0 )
765  {
766  aDC->SetDeviceOrigin( 0, 0 );
767  aDC->SetAxisOrientation( true, false );
768  }
769 
771  aScreen->m_NumberOfScreens, aScreen->m_ScreenNumber, aLineWidth, aScalar,
772  color, aSheetLayer );
773 
774  if( origin.y > 0 )
775  {
776  aDC->SetDeviceOrigin( origin.x, origin.y );
777  aDC->SetAxisOrientation( true, true );
778  }
779 }
780 
781 
783 {
784  // Virtual function. Base class implementation returns an empty string.
785  return wxEmptyString;
786 }
787 
788 bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
789  const wxString& wildcard, const wxString& ext,
790  bool isDirectory )
791 {
792  wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
793  aFilename.SetExt( ext );
794 
795  if( isDirectory && doOpen )
796  {
797  wxDirDialog dlg( this, prompt, Prj().GetProjectPath(),
798  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
799 
800  if( dlg.ShowModal() == wxID_CANCEL )
801  return false;
802 
803  aFilename = dlg.GetPath();
804  aFilename.SetExt( ext );
805  }
806  else
807  {
808  wxFileDialog dlg( this, prompt, Prj().GetProjectPath(), aFilename.GetFullName() ,
809  wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
810  : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
811 
812  if( dlg.ShowModal() == wxID_CANCEL )
813  return false;
814 
815  aFilename = dlg.GetPath();
816  aFilename.SetExt( ext );
817  }
818 
819  return true;
820 }
821 
822 
824 {
825  // Rebuild all toolbars, and update the checked state of check tools
826  if( m_mainToolBar )
828 
829  if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
831 
832  if( m_optionsToolBar ) // Options (typically on left edge of window)
834 
835  if( m_auxiliaryToolBar ) // Additional tools under main toolbar
837 
838  // Update the checked state of tools
839  SyncToolbars();
840 }
841 
842 
844 {
845  if( !m_colorSettings )
846  m_colorSettings = Pgm().GetSettingsManager().GetColorSettings();
847 
848  return m_colorSettings;
849 }
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:95
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
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
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:404
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
std::vector< wxString > find_history
Definition: app_settings.h:84
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.
TOOL_DISPATCHER * m_toolDispatcher
ACTION_TOOLBAR * m_optionsToolBar
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)
int GetMaxUndoItems() const
Definition: base_screen.h:211
virtual bool IsGridVisible() const
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.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ws_draw_item.h:420
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
void OnMove(wxMoveEvent &aEvent) override
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:139
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.
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:286
#define DEFAULT_MAX_UNDO_ITEMS
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
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.
COLOR4D m_drawBgColor
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
wxChoice * m_gridSelectBox
COLOR4D m_gridColor
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
prevents opening same file multiple times.
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:205
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:263
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.
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.
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:52
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:134
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
FIND_REPLACE m_FindReplace
Definition: app_settings.h:122
#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 SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:450
void WriteConfig(WINDOW_SETTINGS &aCfg)
GRID_SETTINGS grid
Definition: app_settings.h:63
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.
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
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
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
std::vector< wxString > replace_history
Definition: app_settings.h:86
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:432
Helper dialog and control classes.
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.
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.
#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
COMMON_TOOLS.
Definition: common_tools.h:38
COLOR_SETTINGS * m_colorSettings
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:83
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)
double m_zoomLevelCoeff
virtual void ReCreateHToolbar()=0
see class PGM_BASE
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.
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
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:125
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
size_t GetGridCount() const
Function GetGridCount().
Definition: base_screen.h:324
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
EDA_UNITS m_userUnits
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
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.
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
void SetUserUnits(EDA_UNITS aUnits)
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.
virtual void GetMsgPanelInfo(EDA_UNITS 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:320
Definition: colors.h:45
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 LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
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 FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
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:267
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.
long m_firstRunDialogSetting
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:610
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:40
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...