From a907e50424617e5220632a0edbf9edac801e005f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 17 Jun 2016 20:00:29 +0200 Subject: [PATCH] Gerbview: code cleanup (mainly remove g_GERBER_List global variable) --- gerbview/block.cpp | 21 ++++++------- gerbview/class_gbr_layer_box_selector.cpp | 11 ++++--- gerbview/class_gbr_layout.cpp | 18 ++++++++--- gerbview/class_gbr_layout.h | 6 ++++ gerbview/class_gerber_file_image_list.cpp | 13 ++++++-- gerbview/class_gerber_file_image_list.h | 6 ++-- gerbview/class_gerbview_layer_widget.cpp | 17 +++++----- gerbview/class_gerbview_layer_widget.h | 3 ++ gerbview/clear_gbr_drawlayers.cpp | 4 +-- .../dialogs/dialog_print_using_printer.cpp | 5 +-- gerbview/events_called_functions.cpp | 4 +-- gerbview/excellon_read_drill_file.cpp | 19 ++++++------ gerbview/export_to_pcbnew.cpp | 14 +++++---- gerbview/gerbview_frame.cpp | 31 +++++++++++++------ gerbview/gerbview_frame.h | 21 ++++++++++--- gerbview/locate.cpp | 7 +++-- gerbview/onleftclick.cpp | 3 +- gerbview/readgerb.cpp | 5 +-- gerbview/select_layers_to_pcb.cpp | 8 +++-- gerbview/toolbars_gerber.cpp | 3 +- 20 files changed, 139 insertions(+), 80 deletions(-) diff --git a/gerbview/block.cpp b/gerbview/block.cpp index 0464792f60..c2345ab67c 100644 --- a/gerbview/block.cpp +++ b/gerbview/block.cpp @@ -36,9 +36,9 @@ #include #include - -static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool erase ); +// Call back function used in block command +static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, + const wxPoint& aPosition, bool erase ); int GERBVIEW_FRAME::BlockCommand( EDA_KEY key ) @@ -82,7 +82,7 @@ void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC ) if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - Block_Move( DC ); + Block_Move(); GetScreen()->m_BlockLocate.ClearItemsList(); break; @@ -177,16 +177,14 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y ) { - screen->m_BlockLocate.Draw( aPanel, - aDC, + screen->m_BlockLocate.Draw( aPanel, aDC, screen->m_BlockLocate.GetMoveVector(), - g_XorMode, - Color ); + g_XorMode, Color ); } } -void GERBVIEW_FRAME::Block_Move( wxDC* DC ) +void GERBVIEW_FRAME::Block_Move() { wxPoint delta; wxPoint oldpos; @@ -201,10 +199,11 @@ void GERBVIEW_FRAME::Block_Move( wxDC* DC ) /* Calculate displacement vectors. */ delta = GetScreen()->m_BlockLocate.GetMoveVector(); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; diff --git a/gerbview/class_gbr_layer_box_selector.cpp b/gerbview/class_gbr_layer_box_selector.cpp index 99bbe630b0..c28569af5b 100644 --- a/gerbview/class_gbr_layer_box_selector.cpp +++ b/gerbview/class_gbr_layer_box_selector.cpp @@ -7,9 +7,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2012 Jean-Pierre Charras + * Copyright (C) 1992-2016 Jean-Pierre Charras * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,7 +42,9 @@ void GBR_LAYER_BOX_SELECTOR::Resync() Freeze(); Clear(); - for( int layerid = 0; layerid < GERBER_DRAWLAYERS_COUNT; ++layerid ) + GERBER_FILE_IMAGE_LIST& images = GERBER_FILE_IMAGE_LIST::GetImagesList(); + + for( unsigned layerid = 0; layerid < images.ImagesMaxCount(); ++layerid ) { wxBitmap layerbmp( BM_SIZE, BM_SIZE ); wxString layername; @@ -79,7 +81,8 @@ EDA_COLOR_T GBR_LAYER_BOX_SELECTOR::GetLayerColor( int aLayer ) const // Returns the name of the layer id wxString GBR_LAYER_BOX_SELECTOR::GetLayerName( int aLayer ) const { - wxString name = g_GERBER_List.GetDisplayName( aLayer ); + GERBER_FILE_IMAGE_LIST& images = GERBER_FILE_IMAGE_LIST::GetImagesList(); + wxString name = images.GetDisplayName( aLayer ); return name; } diff --git a/gerbview/class_gbr_layout.cpp b/gerbview/class_gbr_layout.cpp index 7715e3bba5..14b4370c37 100644 --- a/gerbview/class_gbr_layout.cpp +++ b/gerbview/class_gbr_layout.cpp @@ -45,6 +45,13 @@ GBR_LAYOUT::~GBR_LAYOUT() { } +// Accessor to the list of gerber files (and drill files) images +GERBER_FILE_IMAGE_LIST* GBR_LAYOUT::GetImagesList() +{ + return &GERBER_FILE_IMAGE_LIST::GetImagesList(); +} + + bool GBR_LAYOUT::IsLayerPrintable( int aLayer ) const { for( unsigned ii = 0; ii < m_printLayersList.size(); ++ii ) @@ -56,14 +63,15 @@ bool GBR_LAYOUT::IsLayerPrintable( int aLayer ) const return false; } + EDA_RECT GBR_LAYOUT::ComputeBoundingBox() { EDA_RECT bbox; bool first_item = true; - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; @@ -171,7 +179,7 @@ void GBR_LAYOUT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode, layer = active_layer; } - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; @@ -335,9 +343,9 @@ void GBR_LAYOUT::DrawItemsDCodeID( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GRSetDrawMode( aDC, aDrawMode ); - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; diff --git a/gerbview/class_gbr_layout.h b/gerbview/class_gbr_layout.h index f14a3dd1a9..563b2b83a9 100644 --- a/gerbview/class_gbr_layout.h +++ b/gerbview/class_gbr_layout.h @@ -43,6 +43,8 @@ #include +class GERBER_FILE_IMAGE_LIST; + /** * Class GBR_LAYOUT * holds list of GERBER_DRAW_ITEM currently loaded. @@ -60,6 +62,10 @@ public: GBR_LAYOUT(); ~GBR_LAYOUT(); + // Accessor to the GERBER_FILE_IMAGE_LIST, + // which handles the list of gerber files (and drill files) images loaded + GERBER_FILE_IMAGE_LIST* GetImagesList(); + const wxPoint& GetAuxOrigin() const { return m_originAxisPosition; diff --git a/gerbview/class_gerber_file_image_list.cpp b/gerbview/class_gerber_file_image_list.cpp index d9f64d7959..6573fad408 100644 --- a/gerbview/class_gerber_file_image_list.cpp +++ b/gerbview/class_gerber_file_image_list.cpp @@ -38,6 +38,10 @@ #include +// The global image list: +GERBER_FILE_IMAGE_LIST s_GERBER_List; + + // GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files GERBER_FILE_IMAGE_LIST::GERBER_FILE_IMAGE_LIST() { @@ -54,6 +58,12 @@ GERBER_FILE_IMAGE_LIST::~GERBER_FILE_IMAGE_LIST() } +GERBER_FILE_IMAGE_LIST& GERBER_FILE_IMAGE_LIST::GetImagesList() +{ + return s_GERBER_List; +} + + GERBER_FILE_IMAGE* GERBER_FILE_IMAGE_LIST::GetGbrImage( int aIdx ) { if( (unsigned)aIdx < m_GERBER_List.size() ) @@ -217,6 +227,3 @@ void GERBER_FILE_IMAGE_LIST::SortImagesByZOrder() } } - -// The global image list: -GERBER_FILE_IMAGE_LIST g_GERBER_List; diff --git a/gerbview/class_gerber_file_image_list.h b/gerbview/class_gerber_file_image_list.h index 6a10cb112a..9f2fb9bf0a 100644 --- a/gerbview/class_gerber_file_image_list.h +++ b/gerbview/class_gerber_file_image_list.h @@ -69,8 +69,11 @@ public: ~GERBER_FILE_IMAGE_LIST(); //Accessor + static GERBER_FILE_IMAGE_LIST& GetImagesList(); GERBER_FILE_IMAGE* GetGbrImage( int aIdx ); + unsigned ImagesMaxCount() { return m_GERBER_List.size(); } + /** * Add a GERBER_FILE_IMAGE* at index aIdx * or at the first free location if aIdx < 0 @@ -112,7 +115,4 @@ public: void SortImagesByZOrder(); }; - -extern GERBER_FILE_IMAGE_LIST g_GERBER_List; - #endif // ifndef CLASS_GERBER_FILE_IMAGE_LIST_H diff --git a/gerbview/class_gerbview_layer_widget.cpp b/gerbview/class_gerbview_layer_widget.cpp index 2e77c6b5af..aeb53cd2b7 100644 --- a/gerbview/class_gerbview_layer_widget.cpp +++ b/gerbview/class_gerbview_layer_widget.cpp @@ -77,11 +77,12 @@ GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFo // using installRightLayerClickHandler } -/** - * Function SetLayersManagerTabsText - * Update the layer manager tabs labels - * Useful when changing Language or to set labels to a non default value - */ +GERBER_FILE_IMAGE_LIST* GERBER_LAYER_WIDGET::GetImagesList() +{ + return &GERBER_FILE_IMAGE_LIST::GetImagesList(); +} + + void GERBER_LAYER_WIDGET::SetLayersManagerTabsText( ) { m_notebook->SetPageText(0, _("Layer") ); @@ -208,7 +209,7 @@ void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) break; case ID_SORT_GBR_LAYERS: - g_GERBER_List.SortImagesByZOrder(); + GetImagesList()->SortImagesByZOrder(); myframe->ReFillLayerWidget(); myframe->syncLayerBox( true ); myframe->GetCanvas()->Refresh(); @@ -238,7 +239,7 @@ void GERBER_LAYER_WIDGET::ReFill() for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) { - wxString msg = g_GERBER_List.GetDisplayName( layer ); + wxString msg = GetImagesList()->GetDisplayName( layer ); AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, myframe->GetLayerColor( layer ), wxEmptyString, true ) ); @@ -311,7 +312,7 @@ void GERBER_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled ) */ bool GERBER_LAYER_WIDGET::useAlternateBitmap(int aRow) { - return g_GERBER_List.GetGbrImage( aRow ) != NULL; + return GetImagesList()->GetGbrImage( aRow ) != NULL; } /* diff --git a/gerbview/class_gerbview_layer_widget.h b/gerbview/class_gerbview_layer_widget.h index d7dfc78dc4..3c05367651 100644 --- a/gerbview/class_gerbview_layer_widget.h +++ b/gerbview/class_gerbview_layer_widget.h @@ -77,6 +77,8 @@ class GERBER_LAYER_WIDGET : public LAYER_WIDGET */ virtual bool useAlternateBitmap(int aRow); + GERBER_FILE_IMAGE_LIST* GetImagesList(); + public: /** @@ -103,6 +105,7 @@ public: void OnLayerVisible( int aLayer, bool isVisible, bool isFinal ); void OnRenderColorChange( int aId, EDA_COLOR_T aColor ); void OnRenderEnable( int aId, bool isEnabled ); + /** * Function SetLayersManagerTabsText * Update the layer manager tabs labels diff --git a/gerbview/clear_gbr_drawlayers.cpp b/gerbview/clear_gbr_drawlayers.cpp index 3ed9504d71..44154b6a66 100644 --- a/gerbview/clear_gbr_drawlayers.cpp +++ b/gerbview/clear_gbr_drawlayers.cpp @@ -47,7 +47,7 @@ bool GERBVIEW_FRAME::Clear_DrawLayers( bool query ) return false; } - g_GERBER_List.DeleteAllImages(); + GetGerberLayout()->GetImagesList()->DeleteAllImages(); GetGerberLayout()->SetBoundingBox( EDA_RECT() ); @@ -70,7 +70,7 @@ void GERBVIEW_FRAME::Erase_Current_DrawLayer( bool query ) SetCurItem( NULL ); - g_GERBER_List.DeleteImage( layer ); + GetGerberLayout()->GetImagesList()->DeleteImage( layer ); m_LayersManager->UpdateLayerIcons(); syncLayerBox(); diff --git a/gerbview/dialogs/dialog_print_using_printer.cpp b/gerbview/dialogs/dialog_print_using_printer.cpp index a7e20c2e47..75b16c0abe 100644 --- a/gerbview/dialogs/dialog_print_using_printer.cpp +++ b/gerbview/dialogs/dialog_print_using_printer.cpp @@ -155,15 +155,16 @@ void DIALOG_PRINT_USING_PRINTER::InitValues( ) } s_Parameters.m_PageSetupData = s_pageSetupData; + GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList(); // Create layer list - for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) + for( unsigned ii = 0; ii < images->ImagesMaxCount(); ++ii ) { msg = _( "Layer" ); msg << wxT( " " ) << ii + 1; m_BoxSelectLayer[ii] = new wxCheckBox( this, -1, msg ); - if( g_GERBER_List.GetGbrImage( ii ) == NULL ) // Nothing loaded on this draw layer + if( images->GetGbrImage( ii ) == NULL ) // Nothing loaded on this draw layer m_BoxSelectLayer[ii]->Enable( false ); if( ii < 16 ) diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index b852ae8a73..10dfc34cd3 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -229,7 +229,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event ) void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event ) { - GERBER_FILE_IMAGE* gerber_image = g_GERBER_List.GetGbrImage( getActiveLayer() ); + GERBER_FILE_IMAGE* gerber_image = GetGbrImage( getActiveLayer() ); if( gerber_image ) { @@ -261,7 +261,7 @@ void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event ) void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event ) { int layer = getActiveLayer(); - GERBER_FILE_IMAGE* gerber_layer = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber_layer = GetGbrImage( layer ); if( gerber_layer ) { diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 9b14c0967e..eb010085e2 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -1,10 +1,3 @@ -/** - * @file excellon_read_drill_file.cpp - * Functions to read drill files (EXCELLON format) created by Pcbnew - * These files use only a subset of EXCELLON commands. - */ - - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -62,6 +55,13 @@ * Feed Rate and Spindle Speed are just skipped because they are not used in a viewer */ +/** + * @file excellon_read_drill_file.cpp + * Functions to read drill files (EXCELLON format) created by Pcbnew + * These files use only a subset of EXCELLON commands. + */ + + #include #include #include @@ -161,12 +161,13 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName ) { wxString msg; int layerId = getActiveLayer(); // current layer used in GerbView - EXCELLON_IMAGE* drill_Layer = (EXCELLON_IMAGE*) g_GERBER_List.GetGbrImage( layerId ); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); + EXCELLON_IMAGE* drill_Layer = (EXCELLON_IMAGE*) images->GetGbrImage( layerId ); if( drill_Layer == NULL ) { drill_Layer = new EXCELLON_IMAGE( layerId ); - layerId = g_GERBER_List.AddGbrImage( drill_Layer, layerId ); + layerId = images->AddGbrImage( drill_Layer, layerId ); } if( layerId < 0 ) diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index d9611fb541..ab235947b8 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -156,10 +156,11 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) { int layercount = 0; + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); // Count the Gerber layers which are actually currently used - for( LAYER_NUM ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) + for( LAYER_NUM ii = 0; ii < (LAYER_NUM)images->ImagesMaxCount(); ++ii ) { - if( g_GERBER_List.GetGbrImage( ii ) ) + if( images->GetGbrImage( ii ) ) layercount++; } @@ -221,10 +222,11 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa // create an image of gerber data // First: non copper layers: const int pcbCopperLayerMax = 31; + GERBER_FILE_IMAGE_LIST* images = m_gerbview_frame->GetGerberLayout()->GetImagesList(); - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; @@ -244,9 +246,9 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa } // Copper layers - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 9ab1f05b84..495a3cd2e3 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -369,16 +369,16 @@ int GERBVIEW_FRAME::getNextAvailableLayer( int aLayer ) const { int layer = aLayer; - for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i ) + for( unsigned i = 0; i < ImagesMaxCount(); ++i ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + const GERBER_FILE_IMAGE* gerber = GetGbrImage( layer ); if( gerber == NULL ) // this graphic layer is available: use it return layer; ++layer; // try next graphic layer - if( layer >= GERBER_DRAWLAYERS_COUNT ) + if( layer >= (int)ImagesMaxCount() ) layer = 0; } @@ -400,8 +400,8 @@ void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox ) m_SelLayerBox->SetSelection( getActiveLayer() ); - int dcodeSelected = -1; - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( getActiveLayer() ); + int dcodeSelected = -1; + GERBER_FILE_IMAGE* gerber = GetGbrImage( getActiveLayer() ); if( gerber ) dcodeSelected = gerber->m_Selected_Tool; @@ -422,13 +422,12 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - double scale = g_UserUnit == INCHES ? IU_PER_MILS * 1000 : - IU_PER_MM; + double scale = g_UserUnit == INCHES ? IU_PER_MILS * 1000 : IU_PER_MM; int curr_layer = getActiveLayer(); - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( int layer = 0; layer < (int)ImagesMaxCount(); ++layer ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE* gerber = GetGbrImage( layer ); if( gerber == NULL ) continue; @@ -444,6 +443,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() list.Add( Line ); const char* units = g_UserUnit == INCHES ? "\"" : "mm"; + for( ii = 0, jj = 1; ii < TOOLS_MAX_COUNT; ii++ ) { pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE, false ); @@ -483,7 +483,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() void GERBVIEW_FRAME::UpdateTitleAndInfo() { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( getActiveLayer() ); + GERBER_FILE_IMAGE* gerber = GetGbrImage( getActiveLayer() ); wxString text; // Display the gerber filename @@ -848,3 +848,14 @@ const wxString GERBVIEW_FRAME::GetZoomLevelIndicator() const { return EDA_DRAW_FRAME::GetZoomLevelIndicator(); } + +GERBER_FILE_IMAGE* GERBVIEW_FRAME::GetGbrImage( int aIdx ) const +{ + return m_gerberLayout->GetImagesList()->GetGbrImage( aIdx ); +} + +unsigned GERBVIEW_FRAME::ImagesMaxCount() const +{ + return m_gerberLayout->GetImagesList()->ImagesMaxCount(); +} + diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 1e44a284dd..1d21b538ef 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -46,6 +46,8 @@ class DCODE_SELECTION_BOX; class GERBER_LAYER_WIDGET; class GBR_LAYER_BOX_SELECTOR; class GERBER_DRAW_ITEM; +class GERBER_FILE_IMAGE; +class GERBER_FILE_IMAGE_LIST; /** @@ -82,6 +84,18 @@ public: return m_gerberLayout; } + /** + * Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data + */ + GERBER_FILE_IMAGE_LIST* GetImagesList() const + { + return m_gerberLayout->GetImagesList(); + } + + GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const; + + unsigned ImagesMaxCount() const; ///< The max number of file images + /** * Function GetGerberLayoutBoundingBox @@ -165,7 +179,7 @@ private: bool m_show_layer_manager_tools; - // An array sting to store warning messages when reaging a gerber file. + // An array sting to store warning messages when reading a gerber file. wxArrayString m_Messages; public: @@ -535,11 +549,8 @@ public: * moves all tracks and segments within the selected block. * New location is determined by the current offset from the selected * block's original location. - * Defined separately in Pcbnew and GerbView - * - * @param DC A device context to draw on. */ - void Block_Move( wxDC* DC ); + void Block_Move(); /** * Function ToPrinter diff --git a/gerbview/locate.cpp b/gerbview/locate.cpp index 2fe475c17a..b0267c9c7f 100644 --- a/gerbview/locate.cpp +++ b/gerbview/locate.cpp @@ -49,7 +49,8 @@ GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc ref = GetNearestGridPosition( ref ); int layer = getActiveLayer(); - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); // Search first on active layer GERBER_DRAW_ITEM* gerb_item = NULL; @@ -68,9 +69,9 @@ GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc if( !found ) // Search on all layers { - for( layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) + for( layer = 0; layer < (int)images->ImagesMaxCount(); ++layer ) { - gerber = g_GERBER_List.GetGbrImage( layer ); + gerber = images->GetGbrImage( layer ); if( gerber == NULL ) // Graphic layer not yet used continue; diff --git a/gerbview/onleftclick.cpp b/gerbview/onleftclick.cpp index 8b8b83bbf3..3dfe6f6004 100644 --- a/gerbview/onleftclick.cpp +++ b/gerbview/onleftclick.cpp @@ -42,7 +42,8 @@ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) if( DrawStruct == NULL ) { - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( getActiveLayer() ); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( getActiveLayer() ); if( gerber ) gerber->DisplayImageInfo( this ); diff --git a/gerbview/readgerb.cpp b/gerbview/readgerb.cpp index f618ecb0ca..38ecae5b68 100644 --- a/gerbview/readgerb.cpp +++ b/gerbview/readgerb.cpp @@ -41,12 +41,13 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName ) wxString msg; int layer = getActiveLayer(); - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); if( gerber == NULL ) { gerber = new GERBER_FILE_IMAGE( layer ); - g_GERBER_List.AddGbrImage( gerber, layer ); + images->AddGbrImage( gerber, layer ); } /* Read the gerber file */ diff --git a/gerbview/select_layers_to_pcb.cpp b/gerbview/select_layers_to_pcb.cpp index 423bd53d1f..80871e8bbf 100644 --- a/gerbview/select_layers_to_pcb.cpp +++ b/gerbview/select_layers_to_pcb.cpp @@ -120,9 +120,11 @@ void LAYERS_MAP_DIALOG::initDialog() LAYER_NUM pcb_layer_num = 0; m_gerberActiveLayersCount = 0; - for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) + GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList(); + + for( unsigned ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) { - if( g_GERBER_List.GetGbrImage( ii ) == NULL ) + if( images->GetGbrImage( ii ) == NULL ) break; if( (pcb_layer_num == m_exportBoardCopperLayersCount - 1) @@ -190,7 +192,7 @@ void LAYERS_MAP_DIALOG::initDialog() wxRIGHT | wxLEFT, 5 ); /* Add file name and extension without path. */ - wxFileName fn( g_GERBER_List.GetGbrImage( ii )->m_FileName ); + wxFileName fn( images->GetGbrImage( ii )->m_FileName ); label = new wxStaticText( this, wxID_STATIC, fn.GetFullName(), wxDefaultPosition, wxDefaultSize ); flexColumnBoxSizer->Add( label, 0, diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index 8284c03346..ab15448543 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -307,7 +307,8 @@ void GERBVIEW_FRAME::OnUpdateShowLayerManager( wxUpdateUIEvent& aEvent ) void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent ) { int layer = getActiveLayer(); - GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer ); + GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList(); + GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); int selected = ( gerber ) ? gerber->m_Selected_Tool : 0; if( m_DCodeSelector && m_DCodeSelector->GetSelectedDCodeId() != selected )