KiCad PCB EDA Suite
gerbview_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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <kiface_i.h>
31 #include <pgm_base.h>
32 #include <wxstruct.h>
33 #include <class_drawpanel.h>
34 #include <build_version.h>
35 #include <trigo.h>
36 #include <base_units.h>
38 #include <msgpanel.h>
39 #include <bitmaps.h>
41 
42 #include <gerbview.h>
43 #include <gerbview_frame.h>
44 #include <gerbview_id.h>
45 #include <hotkeys.h>
48 #include <dialog_helpers.h>
51 
52 
53 // Config keywords
54 static const wxString cfgShowPageSizeOption( wxT( "PageSizeOpt" ) );
55 static const wxString cfgShowDCodes( wxT( "ShowDCodesOpt" ) );
56 static const wxString cfgShowNegativeObjects( wxT( "ShowNegativeObjectsOpt" ) );
57 static const wxString cfgShowBorderAndTitleBlock( wxT( "ShowBorderAndTitleBlock" ) );
58 
59 
60 // Colors for layers and items
62 
63 GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
64  EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ),
65  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME )
66 {
67  m_auxiliaryToolBar = NULL;
69  m_gerberLayout = NULL;
70  m_zoomLevelCoeff = ZOOM_FACTOR( 110 ); // Adjusted to roughly displays zoom level = 1
71  // when the screen shows a 1:1 image
72  // obviously depends on the monitor,
73  // but this is an acceptable value
74 
75  PAGE_INFO pageInfo( wxT( "GERBER" ) );
76  SetPageSettings( pageInfo );
77 
79 
80  m_showAxis = true; // true to show X and Y axis on screen
81  m_showBorderAndTitleBlock = false; // true for reference drawings.
83  m_SelLayerBox = NULL;
84  m_DCodeSelector = NULL;
85  m_displayMode = 0;
89 
90  if( m_canvas )
92 
93  // Give an icon
94  wxIcon icon;
95  icon.CopyFromBitmap( KiBitmap( icon_gerbview_xpm ) );
96  SetIcon( icon );
97 
98  SetLayout( new GBR_LAYOUT() );
99 
100  SetVisibleLayers( -1 ); // All draw layers visible.
101 
102  SetScreen( new GBR_SCREEN( GetPageSettings().GetSizeIU() ) );
103 
104  // Create the PCB_LAYER_WIDGET *after* SetLayout():
105  wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
106  int pointSize = font.GetPointSize();
107  int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
108 
109  if( screenHeight <= 900 )
110  pointSize = (pointSize * 8) / 10;
111 
112  m_LayersManager = new GERBER_LAYER_WIDGET( this, m_canvas, pointSize );
113 
114  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
115  // initialize parameters in m_LayersManager
116  LoadSettings( config() );
117 
118  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
119 
120  if( m_LastGridSizeId < 0 )
121  m_LastGridSizeId = 0;
124  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
125 
126  ReCreateMenuBar();
130 
131  m_auimgr.SetManagedWindow( this );
132 
133  EDA_PANEINFO horiz;
134  horiz.HorizontalToolbarPane();
135 
136  EDA_PANEINFO vert;
137  vert.VerticalToolbarPane();
138 
139  EDA_PANEINFO mesg;
140  mesg.MessageToolbarPane();
141 
142  // Create a wxAuiPaneInfo for the Layers Manager, not derived from the template.
143  // the Layers Manager is floatable, but initially docked at far right
144  EDA_PANEINFO lyrs;
145  lyrs.LayersToolbarPane();
146  lyrs.MinSize( m_LayersManager->GetBestSize() );
147  lyrs.BestSize( m_LayersManager->GetBestSize() );
148  lyrs.Caption( _( "Visibles" ) );
149  lyrs.TopDockable( false ).BottomDockable( false );
150 
151 
152  if( m_mainToolBar )
153  m_auimgr.AddPane( m_mainToolBar,
154  wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) );
155 
156  if( m_auxiliaryToolBar ) // the auxiliary horizontal toolbar, that shows component and netname lists
157  {
158  m_auimgr.AddPane( m_auxiliaryToolBar,
159  wxAuiPaneInfo( horiz ).Name( wxT( "m_auxiliaryToolBar" ) ).Top().Row( 1 ) );
160  }
161 
162  if( m_drawToolBar )
163  m_auimgr.AddPane( m_drawToolBar,
164  wxAuiPaneInfo( vert ).Name( wxT( "m_drawToolBar" ) ).Right().Row( 1 ) );
165 
166  m_auimgr.AddPane( m_LayersManager,
167  lyrs.Name( wxT( "m_LayersManagerToolBar" ) ).Right().Layer( 0 ) );
168 
169  if( m_optionsToolBar )
170  m_auimgr.AddPane( m_optionsToolBar,
171  wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left() );
172 
173  if( m_canvas )
174  m_auimgr.AddPane( m_canvas,
175  wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
176 
177  if( m_messagePanel )
178  m_auimgr.AddPane( m_messagePanel,
179  wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer( 10 ) );
180 
181  ReFillLayerWidget(); // this is near end because contents establish size
182  m_LayersManager->ReFillRender(); // Update colors in Render after the config is read
183  m_auimgr.Update();
184 
185  setActiveLayer( 0, true );
186  Zoom_Automatique( false ); // Gives a default zoom value
188 }
189 
190 
192 {
193 }
194 
195 
196 void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
197 {
198  Destroy();
199 }
200 
201 
202 bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
203 {
204  // The current project path is also a valid command parameter. Check if a single path
205  // rather than a file name was passed to GerbView and use it as the initial MRU path.
206  if( aFileSet.size() > 0 )
207  {
208  wxString path = aFileSet[0];
209 
210  // For some reason wxApp appears to leave the trailing double quote on quoted
211  // parameters which are required for paths with spaces. Maybe this should be
212  // pushed back into PGM_SINGLE_TOP::OnPgmInit() but that may cause other issues.
213  // We can't buy a break!
214  if( path.Last() == wxChar( '\"' ) )
215  path.RemoveLast();
216 
217  if( !wxFileExists( path ) && wxDirExists( path ) )
218  {
219  wxLogDebug( wxT( "MRU path: %s." ), GetChars( path ) );
220  m_mruPath = path;
221  return true;
222  }
223 
224  const unsigned limit = std::min( unsigned( aFileSet.size() ),
225  unsigned( GERBER_DRAWLAYERS_COUNT ) );
226 
227  int layer = 0;
228 
229  for( unsigned i=0; i<limit; ++i, ++layer )
230  {
231  setActiveLayer( layer );
232 
233  // Try to guess the type of file by its ext
234  // if it is .drl (Kicad files), it is a drill file
235  wxFileName fn( aFileSet[i] );
236  wxString ext = fn.GetExt();
237 
238  if( ext == DrillFileExtension ) // In Excellon format
239  LoadExcellonFiles( aFileSet[i] );
240  else if( ext == GerberJobFileExtension )
241  LoadGerberJobFile( aFileSet[i] );
242  else
243  LoadGerberFiles( aFileSet[i] );
244  }
245  }
246 
247  Zoom_Automatique( true ); // Zoom fit in frame
248 
250 
251  return true;
252 }
253 
254 
256 {
258 
259  // gives a size to bbox (current page size), if no item in list
260  if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
261  {
262  wxSize pagesize = GetPageSettings().GetSizeMils();
263  bbox.SetSize( wxSize( Mils2iu( pagesize.x ), Mils2iu( pagesize.y ) ) );
264  }
265 
266  // Compute best zoom:
267  wxSize size = m_canvas->GetClientSize();
268  double x = (double) bbox.GetWidth() / (double) size.x;
269  double y = (double) bbox.GetHeight() / (double) size.y;
270  double best_zoom = std::max( x, y ) * 1.1;
271 
273 
274  return best_zoom;
275 }
276 
277 
278 void GERBVIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
279 {
281 
282  // was: wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );
284 
285  PAGE_INFO pageInfo( wxT( "GERBER" ) );
286 
288 
290  {
291  wxString pageType;
292  aCfg->Read( cfgShowPageSizeOption, &pageType, wxT( "GERBER" ) );
293  pageInfo.SetType( pageType );
294  }
295 
296  SetPageSettings( pageInfo );
297 
298  GetScreen()->InitDataPoints( pageInfo.GetSizeIU() );
299 
300  bool tmp;
301  aCfg->Read( cfgShowDCodes, &tmp, true );
303  aCfg->Read( cfgShowNegativeObjects, &tmp, false );
305 
306  // because we have more than one file history, we must read this one
307  // using a specific path
308  aCfg->SetPath( wxT( "drl_files" ) );
309  m_drillFileHistory.Load( *aCfg );
310  aCfg->SetPath( wxT( ".." ) );
311 
312  // because we have more than one file history, we must read this one
313  // using a specific path
314  aCfg->SetPath( wxT( "zip_files" ) );
315  m_zipFileHistory.Load( *aCfg );
316  aCfg->SetPath( wxT( ".." ) );
317 
318  // because we have more than one file history, we must read this one
319  // using a specific path
320  aCfg->SetPath( "job_files" );
321  m_jobFileHistory.Load( *aCfg );
322  aCfg->SetPath( wxT( ".." ) );
323 }
324 
325 
326 void GERBVIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
327 {
329 
330  // was: wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() );
332 
333  aCfg->Write( cfgShowPageSizeOption, GetPageSettings().GetType() );
335  aCfg->Write( cfgShowDCodes, IsElementVisible( LAYER_DCODES ) );
336  aCfg->Write( cfgShowNegativeObjects,
338 
339  // Save the drill file history list.
340  // Because we have more than one file history, we must save this one
341  // in a specific path
342  aCfg->SetPath( wxT( "drl_files" ) );
343  m_drillFileHistory.Save( *aCfg );
344  aCfg->SetPath( wxT( ".." ) );
345 
346  // Save the zip file history list.
347  aCfg->SetPath( wxT( "zip_files" ) );
348  m_zipFileHistory.Save( *aCfg );
349  aCfg->SetPath( wxT( ".." ) );
350 
351  // Save the job file history list.
352  aCfg->SetPath( "job_files" );
353  m_jobFileHistory.Save( *aCfg );
354  aCfg->SetPath( ".." );
355 }
356 
357 
359 {
363 
364  wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_LayersManager );
365 
366  wxSize bestz = m_LayersManager->GetBestSize();
367  bestz.x += 5; // gives a little margin
368 
369  lyrs.MinSize( bestz );
370  lyrs.BestSize( bestz );
371  lyrs.FloatingSize( bestz );
372 
373  if( lyrs.IsDocked() )
374  m_auimgr.Update();
375  else
376  m_LayersManager->SetSize( bestz );
377 
378  syncLayerWidget();
379 }
380 
381 
383  bool aNewState )
384 {
385  switch( aItemIdVisible )
386  {
387  case LAYER_DCODES:
388  m_DisplayOptions.m_DisplayDCodes = aNewState;
389  break;
390 
393  break;
394 
395  case LAYER_GERBVIEW_GRID:
396  SetGridVisibility( aNewState );
397  break;
398 
399  default:
400  wxLogDebug( wxT( "GERBVIEW_FRAME::SetElementVisibility(): bad arg %d" ), aItemIdVisible );
401  }
402 
403  m_LayersManager->SetRenderState( aItemIdVisible, aNewState );
404 }
405 
406 
408 {
409  int layer = aLayer;
410 
411  for( unsigned i = 0; i < ImagesMaxCount(); ++i )
412  {
413  const GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
414 
415  if( gerber == NULL ) // this graphic layer is available: use it
416  return layer;
417 
418  ++layer; // try next graphic layer
419 
420  if( layer >= (int)ImagesMaxCount() )
421  layer = 0;
422  }
423 
424  return NO_AVAILABLE_LAYERS;
425 }
426 
427 
429 {
432 }
433 
434 
435 void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox )
436 {
437  if( aRebuildLayerBox )
439 
440  m_SelLayerBox->SetSelection( getActiveLayer() );
441 
442  int dcodeSelected = -1;
444 
445  if( gerber )
446  dcodeSelected = gerber->m_Selected_Tool;
447 
448  if( m_DCodeSelector )
449  {
451  m_DCodeSelector->SetDCodeSelection( dcodeSelected );
452  m_DCodeSelector->Enable( gerber != NULL );
453  }
454 
456 }
457 
458 
460 {
461  int ii, jj;
462  wxString Line;
463  wxArrayString list;
464  double scale = g_UserUnit == INCHES ? IU_PER_MILS * 1000 : IU_PER_MM;
465  int curr_layer = getActiveLayer();
466 
467  for( int layer = 0; layer < (int)ImagesMaxCount(); ++layer )
468  {
469  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
470 
471  if( gerber == NULL )
472  continue;
473 
474  if( gerber->GetDcodesCount() == 0 )
475  continue;
476 
477  if( layer == curr_layer )
478  Line.Printf( wxT( "*** Active layer (%2.2d) ***" ), layer + 1 );
479  else
480  Line.Printf( wxT( "*** layer %2.2d ***" ), layer + 1 );
481 
482  list.Add( Line );
483 
484  const char* units = g_UserUnit == INCHES ? "\"" : "mm";
485 
486  for( ii = 0, jj = 1; ii < TOOLS_MAX_COUNT; ii++ )
487  {
488  D_CODE* pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE, false );
489 
490  if( pt_D_code == NULL )
491  continue;
492 
493  if( !pt_D_code->m_InUse && !pt_D_code->m_Defined )
494  continue;
495 
496  Line.Printf( wxT( "tool %2.2d: D%2.2d V %.4f %s H %.4f %s %s attribute '%s'" ),
497  jj,
498  pt_D_code->m_Num_Dcode,
499  pt_D_code->m_Size.y / scale, units,
500  pt_D_code->m_Size.x / scale, units,
501  D_CODE::ShowApertureType( pt_D_code->m_Shape ),
502  pt_D_code->m_AperFunction.IsEmpty()? wxT( "none" ) : GetChars( pt_D_code->m_AperFunction )
503  );
504 
505  if( !pt_D_code->m_Defined )
506  Line += wxT( " (not defined)" );
507 
508  if( pt_D_code->m_InUse )
509  Line += wxT( " (in use)" );
510 
511  list.Add( Line );
512  jj++;
513  }
514  }
515 
516  wxSingleChoiceDialog dlg( this, wxEmptyString, _( "D Codes" ), list, (void**) NULL,
517  wxCHOICEDLG_STYLE & ~wxCANCEL );
518 
519  dlg.ShowModal();
520 }
521 
522 
524 {
526 
527  // Display the gerber filename
528  if( gerber == NULL )
529  {
530  SetTitle( "GerbView" );
531 
532  SetStatusText( wxEmptyString, 0 );
533 
534  wxString info;
535  info.Printf( _( "Drawing layer %d not in use" ), getActiveLayer() + 1 );
536  m_TextInfo->SetValue( info );
537 
538  if( EnsureTextCtrlWidth( m_TextInfo, &info ) ) // Resized
539  m_auimgr.Update();
540 
541  ClearMsgPanel();
542  return;
543  }
544  else
545  {
546  wxString title;
547  title.Printf( L"GerbView \u2014 %s%s",
548  gerber->m_FileName,
549  gerber->m_IsX2_file
550  ? " " + _( "(with X2 attributes)" )
551  : wxString( wxEmptyString ) );
552  SetTitle( title );
553 
554  gerber->DisplayImageInfo( this );
555 
556  // Display Image Name and Layer Name (from the current gerber data):
557  wxString status;
558  status.Printf( _( "Image name: '%s' Layer name: '%s'" ),
559  GetChars( gerber->m_ImageName ),
560  GetChars( gerber->GetLayerParams().m_LayerName ) );
561  SetStatusText( status, 0 );
562 
563  // Display data format like fmt in X3.4Y3.4 no LZ or fmt mm X2.3 Y3.5 no TZ in main toolbar
564  wxString info;
565  info.Printf( wxT( "fmt: %s X%d.%d Y%d.%d no %cZ" ),
566  gerber->m_GerbMetric ? wxT( "mm" ) : wxT( "in" ),
567  gerber->m_FmtLen.x - gerber->m_FmtScale.x, gerber->m_FmtScale.x,
568  gerber->m_FmtLen.y - gerber->m_FmtScale.y, gerber->m_FmtScale.y,
569  gerber->m_NoTrailingZeros ? 'T' : 'L' );
570 
571  if( gerber->m_IsX2_file )
572  info << wxT(" ") << _( "X2 attr" );
573 
574  m_TextInfo->SetValue( info );
575 
576  if( EnsureTextCtrlWidth( m_TextInfo, &info ) ) // Resized
577  m_auimgr.Update();
578  }
579 }
580 
581 
583 {
584  switch( aItemIdVisible )
585  {
586  case LAYER_DCODES:
588  break;
589 
592  break;
593 
594  case LAYER_GERBVIEW_GRID:
595  return IsGridVisible();
596  break;
597 
598  default:
599  wxLogDebug( wxT( "GERBVIEW_FRAME::IsElementVisible(): bad arg %d" ), aItemIdVisible );
600  }
601 
602  return true;
603 }
604 
605 
607 {
608  return -1; // TODO
609 }
610 
611 
612 void GERBVIEW_FRAME::SetVisibleLayers( long aLayerMask )
613 {
614 // GetGerberLayout()->SetVisibleLayers( aLayerMask );
615 }
616 
617 
618 bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const
619 {
621  return m_LayersManager->IsLayerVisible( aLayer );
622  else
623  return GetGerberLayout()->IsLayerPrintable( aLayer );
624 }
625 
626 
628 {
629  COLOR4D color = COLOR4D::UNSPECIFIED;
630 
631  switch( aItemIdVisible )
632  {
634  case LAYER_DCODES:
635  color = m_colorsSettings->GetItemColor( aItemIdVisible );
636  break;
637 
638  case LAYER_GERBVIEW_GRID:
639  color = GetGridColor();
640  break;
641 
642  default:
643  wxLogDebug( wxT( "GERBVIEW_FRAME::GetVisibleElementColor(): bad arg %d" ),
644  (int)aItemIdVisible );
645  }
646 
647  return color;
648 }
649 
650 
652 {
655 }
656 
657 
659  COLOR4D aColor )
660 {
661  switch( aItemIdVisible )
662  {
664  case LAYER_DCODES:
665  m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
666  break;
667 
668  case LAYER_GERBVIEW_GRID:
669  SetGridColor( aColor );
670  m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
671  break;
672 
673  default:
674  wxLogDebug( wxT( "GERBVIEW_FRAME::SetVisibleElementColor(): bad arg %d" ),
675  (int) aItemIdVisible );
676  }
677 }
678 
680 {
683  else
684  return GetDrawBgColor();
685 }
686 
687 
689 {
690  return m_colorsSettings->GetLayerColor( aLayer );
691 }
692 
693 
694 void GERBVIEW_FRAME::SetLayerColor( int aLayer, COLOR4D aColor )
695 {
696  m_colorsSettings->SetLayerColor( aLayer, aColor );
697 }
698 
699 
701 {
702  return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer;
703 }
704 
705 
706 void GERBVIEW_FRAME::setActiveLayer( int aLayer, bool doLayerWidgetUpdate )
707 {
708  ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
709 
710  if( doLayerWidgetUpdate )
712 }
713 
714 
715 void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
716 {
717  m_paper = aPageSettings;
718 
719  if( GetScreen() )
720  GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() );
721 }
722 
723 
725 {
726  return m_paper;
727 }
728 
729 
730 const wxSize GERBVIEW_FRAME::GetPageSizeIU() const
731 {
732  // this function is only needed because EDA_DRAW_FRAME is not compiled
733  // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
734  // into an application specific source file.
735  return GetPageSettings().GetSizeIU();
736 }
737 
738 
740 {
741  wxASSERT( m_gerberLayout );
742  return m_gerberLayout->GetTitleBlock();
743 }
744 
745 
746 void GERBVIEW_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
747 {
748  wxASSERT( m_gerberLayout );
749  m_gerberLayout->SetTitleBlock( aTitleBlock );
750 }
751 
752 
754 {
755  wxASSERT( m_gerberLayout );
756  return m_gerberLayout->GetAuxOrigin();
757 }
758 
759 
760 void GERBVIEW_FRAME::SetAuxOrigin( const wxPoint& aPosition )
761 {
762  wxASSERT( m_gerberLayout );
763  m_gerberLayout->SetAuxOrigin( aPosition );
764 }
765 
766 
767 void GERBVIEW_FRAME::SetCurItem( GERBER_DRAW_ITEM* aItem, bool aDisplayInfo )
768 {
769  GetScreen()->SetCurItem( aItem );
770 
771  if( aItem )
772  {
773  if( aDisplayInfo )
774  {
775  MSG_PANEL_ITEMS items;
776  aItem->GetMsgPanelInfo( items );
777  SetMsgPanel( items );
778  }
779  }
780  else
781  {
782  EraseMsgBox();
783  }
784 }
785 
786 
788 {
790  return GetGerberLayout()->GetBoundingBox();
791 }
792 
794 {
796 
797  GBR_SCREEN* screen = (GBR_SCREEN*) GetScreen();
798 
799  if( !screen )
800  return;
801 
802  int dx;
803  int dy;
804  double dXpos;
805  double dYpos;
806  wxString line;
807  wxString locformatter;
808 
809  if( m_DisplayOptions.m_DisplayPolarCood ) // display relative polar coordinates
810  {
811  double theta, ro;
812 
813  dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
814  dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
815 
816  // atan2 in the 0,0 case returns 0
817  theta = RAD2DEG( atan2( (double) -dy, (double) dx ) );
818 
819  ro = hypot( dx, dy );
820  wxString formatter;
821  switch( g_UserUnit )
822  {
823  case INCHES:
824  formatter = wxT( "Ro %.6f Th %.1f" );
825  break;
826 
827  case MILLIMETRES:
828  formatter = wxT( "Ro %.5f Th %.1f" );
829  break;
830 
831  case UNSCALED_UNITS:
832  formatter = wxT( "Ro %f Th %f" );
833  break;
834 
835  case DEGREES:
836  wxASSERT( false );
837  break;
838  }
839 
840  line.Printf( formatter, To_User_Unit( g_UserUnit, ro ), theta );
841 
842  SetStatusText( line, 3 );
843  }
844 
845  // Display absolute coordinates:
848 
849  wxString absformatter;
850 
851  switch( g_UserUnit )
852  {
853  case INCHES:
854  absformatter = wxT( "X %.6f Y %.6f" );
855  locformatter = wxT( "dx %.6f dy %.6f dist %.4f" );
856  break;
857 
858  case MILLIMETRES:
859  absformatter = wxT( "X %.5f Y %.5f" );
860  locformatter = wxT( "dx %.5f dy %.5f dist %.3f" );
861  break;
862 
863  case UNSCALED_UNITS:
864  absformatter = wxT( "X %f Y %f" );
865  locformatter = wxT( "dx %f dy %f dist %f" );
866  break;
867 
868  case DEGREES:
869  wxASSERT( false );
870  break;
871  }
872 
873  line.Printf( absformatter, dXpos, dYpos );
874  SetStatusText( line, 2 );
875 
876  if( !m_DisplayOptions.m_DisplayPolarCood ) // display relative cartesian coordinates
877  {
878  // Display relative coordinates:
879  dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
880  dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
881  dXpos = To_User_Unit( g_UserUnit, dx );
882  dYpos = To_User_Unit( g_UserUnit, dy );
883 
884  // We already decided the formatter above
885  line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
886  SetStatusText( line, 3 );
887  }
888 }
889 
890 
892 {
894 }
895 
897 {
898  return m_gerberLayout->GetImagesList()->GetGbrImage( aIdx );
899 }
900 
902 {
904 }
905 
906 
908 { // Called on units change (see EDA_DRAW_FRAME)
911 }
EDA_PANEINFO & HorizontalToolbarPane()
Function HorizontalToolbarPane Change *this to a horizontal toolbar for KiCad.
Definition: wxstruct.h:479
Class GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
GERBER_FILE_IMAGE_LIST * GetImagesList()
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
static const wxString cfgShowBorderAndTitleBlock(wxT("ShowBorderAndTitleBlock"))
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:160
const wxString DrillFileExtension
void SetItemColor(int aItemIdx, COLOR4D aColor)
Function SetItemColor sets the color for an item which is one of the item indices given in enum PCB_L...
const wxSize GetPageSizeIU() const override
Function GetPageSizeIU works off of GetPageSettings() to return the size of the paper page in the int...
COLORS_DESIGN_SETTINGS g_ColorsSettings(FRAME_GERBER)
bool m_showAxis
True shows the X and Y axis indicators.
Definition: draw_frame.h:102
virtual const wxString GetZoomLevelIndicator() const
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
Definition: draw_frame.cpp:680
void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
bool IsLayerPrintable(int aLayer) const
Function IsLayerPrintable tests whether a given layer is visible.
EDA_RECT GetGerberLayoutBoundingBox()
Function GetGerberLayoutBoundingBox calculates the bounding box containing all gerber items...
Implementation of conversion functions that require both schematic and board internal units...
COLOR4D GetNegativeItemsColor()
Function GetNegativeItemsColor.
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:98
void SetVisibleElementColor(GERBVIEW_LAYER_ID aItemIdVisible, COLOR4D aColor)
void syncLayerBox(bool aRebuildLayerBox=false)
Function syncLayerBox updates the currently "selected" layer within m_SelLayerBox The currently activ...
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
void SetAuxOrigin(const wxPoint &aPoint) override
bool m_InUse
false if the aperure (previously defined) is not used to draw something
Definition: dcode.h:106
void SetCurItem(GERBER_DRAW_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:99
void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:140
const wxPoint & GetAuxOrigin() const override
Function GetAuxOrigin returns the origin of the axis used for plotting and various exports...
void SetScrollCenterPosition(const wxPoint &aPoint)
const wxPoint & GetAuxOrigin() const
void SetPageSettings(const PAGE_INFO &aPageSettings) override
const TITLE_BLOCK & GetTitleBlock() const override
GERBER_LAYER_WIDGET * m_LayersManager
#define ZOOM_FACTOR(x)
Definition: classpcb.cpp:48
double RAD2DEG(double rad)
Definition: trigo.h:192
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
int GetHeight() const
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SetAuxOrigin(const wxPoint &aPosition)
void SetDCodeSelection(int aDCodeId)
Function SetDCodeSelection.
D_CODE * GetDCODE(int aDCODE, bool aCreateIfNoExist=true)
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE...
static const wxString cfgShowNegativeObjects(wxT("ShowNegativeObjectsOpt"))
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
void SetLayerColor(LAYER_NUM aLayer, COLOR4D aColor)
Function SetLayerColor sets the color for aLayer which is one of the layer indices given in pcbstruct...
const wxString GerberJobFileExtension
bool m_DisplayNegativeObjects
Option to draw negative objects in a specific color.
wxAuiManager m_auimgr
Definition: wxstruct.h:144
wxFileHistory m_drillFileHistory
virtual void SetGridColor(COLOR4D aColor)
Function SetGridColor() , virtual.
Definition: draw_frame.h:476
EDA_RECT ComputeBoundingBox()
Function ComputeBoundingBox calculates the bounding box containing all Gerber items.
static const wxString cfgShowDCodes(wxT("ShowDCodesOpt"))
wxSize GetBestSize() const
Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic conten...
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
EDA_PANEINFO & LayersToolbarPane()
Function LayersToolbarPane Change *this to a layers toolbar for KiCad.
Definition: wxstruct.h:531
void SetVisibleLayers(long aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Definition: draw_frame.cpp:735
GERBVIEW_LAYER_ID
GerbView draw layers.
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:470
virtual bool IsGridVisible() const
Function IsGridVisible() , virtual.
Definition: draw_frame.h:448
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
int getNextAvailableLayer(int aLayer=0) const
Function getNextAvailableLayer finds the next empty layer starting at aLayer and returns it to the ca...
void SetGridVisibility(bool aVisible) override
Function SetGridVisibility(), virtual from EDA_DRAW_FRAME It may be overloaded by derived classes...
GERBVIEW_FRAME(KIWAY *aKiway, wxWindow *aParent)
long GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
const wxSize & GetSizeMils() const
void ReCreateHToolbar() override
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:69
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
EDA_PANEINFO & VerticalToolbarPane()
Function VerticalToolbarPane Change *this to a vertical toolbar for KiCad.
Definition: wxstruct.h:497
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:108
void DisplayImageInfo(GERBVIEW_FRAME *aMainFrame)
Function DisplayImageInfo has knowledge about the frame and how and where to put status information a...
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:314
COLOR4D GetVisibleElementColor(GERBVIEW_LAYER_ID aItemIdVisible)
Function GetVisibleElementColor returns the color of a gerber visible element.
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:125
bool EnsureTextCtrlWidth(wxTextCtrl *aCtrl, const wxString *aString)
Function EnsureTextCtrlWidth sets the minimum pixel width on a text control in order to make a text s...
Definition: common.cpp:108
unsigned ImagesMaxCount() const
The max number of file images.
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:291
PAGE_INFO m_paper
void ReCreateAuxiliaryToolbar() override
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:76
virtual void unitsChangeRefresh() override
Function unitsChangeRefresh is called when when the units setting has changed to allow for any derive...
#define GERBER_DRAWLAYERS_COUNT
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:773
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
void EraseMsgBox()
Definition: draw_frame.cpp:250
#define FIRST_DCODE
Definition: dcode.h:70
#define NO_AVAILABLE_LAYERS
bool LoadGerberFiles(const wxString &aFileName)
function LoadGerberFiles Load a photoplot (Gerber) file or many files.
Base window classes and related definitions.
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:128
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
bool m_showBorderAndTitleBlock
True shows the drawing border and title block.
Definition: draw_frame.h:112
Definition: common.h:145
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:100
COLORS_DESIGN_SETTINGS * m_colorsSettings
GBR_DISPLAY_OPTIONS m_DisplayOptions
TITLE_BLOCK & GetTitleBlock()
The common library.
static const wxChar * ShowApertureType(APERTURE_T aType)
Function ShowApertureType returns a character string telling what type of aperture type aType is...
Definition: dcode.cpp:94
double BestZoom() override
Return the zoom level which displays the full page on screen.
Helper dialog and control classes.
GBR_LAYOUT * m_gerberLayout
wxFileHistory m_jobFileHistory
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
GBR_LAYOUT * GetGerberLayout() const
bool m_DisplayPolarCood
Option to display coordinates in status bar in X,Y or Polar coords.
wxPoint m_FramePos
Definition: wxstruct.h:134
Class GERBER_LAYER_WIDGET is here to implement the abtract functions of LAYER_WIDGET so they may be t...
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
wxPoint Centre() const
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void OnCloseWindow(wxCloseEvent &Event)
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible tests whether a given layer is visible.
int m_LastGridSizeId
Definition: draw_frame.h:77
virtual COLOR4D GetGridColor()
Function GetGridColor() , virtual.
Definition: draw_frame.h:467
#define GERBVIEW_FRAME_NAME
Class GERBVIEW_FRAME is the main window used in GerbView.
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:122
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:140
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
Definition: draw_frame.cpp:705
void ReCreateOptToolbar()
Create or update the left vertical toolbar (option toolbar.
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE ...
Definition: dcode.h:109
void setActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function setActiveLayer will change the currently active layer to aLayer and also update the GERBER_L...
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
wxAuiToolBar * m_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window...
wxFileHistory m_zipFileHistory
const PAGE_INFO & GetPageSettings() const override
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
bool IsLayerVisible(LAYER_NUM aLayer)
Function IsLayerVisible returns the visible state of the layer ROW associated with aLayer id...
COLOR4D GetLayerColor(int aLayer) const
Function GetLayerColor gets a layer color for any valid layer.
void SetSize(const wxSize &size)
EDA_PANEINFO & MessageToolbarPane()
Function MessageToolbarPane Change *this to a message pane for KiCad.
Definition: wxstruct.h:516
double m_zoomLevelCoeff
a suitable value to convert the internal zoom scaling factor
Definition: draw_frame.h:85
void wxConfigSaveSetups(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList)
Function wxConfigSaveSetups writes aList of PARAM_CFG_ARRAY elements to save configuration values to ...
const int scale
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
PARAM_CFG_ARRAY & GetConfigurationSettings(void)
Function GetConfigurationSettings Populates the GerbView applications settings list.
#define max(a, b)
Definition: auxiliary.h:86
void SetElementVisibility(GERBVIEW_LAYER_ID aItemIdVisible, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool IsElementVisible(GERBVIEW_LAYER_ID aItemIdVisible) const
Function IsElementVisible tests whether a given element category is visible.
Class EDA_RECT handles the component boundary box.
int getActiveLayer()
Function getActiveLayer returns the active layer.
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
struct EDA_HOTKEY_CONFIG GerbviewHokeysDescr[]
void SetLayerColor(int aLayer, COLOR4D aColor)
Function SetLayerColor changes a layer color for any valid layer.
int GetWidth() const
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
void syncLayerWidget()
Function syncLayerWidget updates the currently "selected" layer within the GERBER_LAYER_WIDGET.
void SetEnableBlockCommands(bool aEnable)
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
double To_User_Unit(EDA_UNITS_T aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:90
bool LoadExcellonFiles(const wxString &aFileName)
function LoadExcellonFiles Load a drill (EXCELLON) file or many files.
virtual void SetGridVisibility(bool aVisible)
Function SetGridVisibility() , virtual It may be overloaded by derived classes.
Definition: draw_frame.h:458
wxSize m_FrameSize
Definition: wxstruct.h:135
EDA_RECT GetBoundingBox() const
Function GetBoundingBox may be called soon after ComputeBoundingBox() to return the same EDA_RECT...
void ReFillRender()
Function ReFillRender Rebuild Render for instance after the config is read.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
virtual void unitsChangeRefresh()
Function unitsChangeRefresh is called when when the units setting has changed to allow for any derive...
Definition: draw_frame.cpp:243
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
Message panel definition file.
void SetRenderState(int aId, bool isSet)
Function SetRenderState sets the state of the checkbox associated with aId within the Render tab grou...
void SetLayout(GBR_LAYOUT *aLayout)
Function SetLayout sets the m_gerberLayout member in such as way as to ensure deleting any previous G...
bool m_IsPrinting
true when printing a page, false when drawing on screen
bool m_DisplayDCodes
Option to show dcode values on items drawn with a dcode tool.
void wxConfigLoadSetups(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG_ARRAY elements to load configuration values from ...
void SelectLayer(LAYER_NUM aLayer)
Function SelectLayer changes the row selection in the layer list to aLayer provided.
virtual void UpdateStatusBar()
Function UpdateStatusBar updates the status bar information.
Definition: draw_frame.cpp:669
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void Liste_D_Codes()
Set Size Items (Lines, Flashes) from DCodes List.
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading new ...
void UpdateTitleAndInfo()
Function UpdateTitleAndInfo displays the short filename (if exists) of the selected layer on the capt...
static const wxString cfgShowPageSizeOption(wxT("PageSizeOpt"))
GERBER_LAYER & GetLayerParams()
Function GetLayerParams.
#define min(a, b)
Definition: auxiliary.h:85
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
const wxString GetZoomLevelIndicator() const override
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39