Gerbview: cleanup code.

Remove GERBER_FILE_IMAGE_LIST dependency to EDA_ITEM, useless.
GERBER_FILE_IMAGE: replace DLIST by std::deque to store gerber draw items.
Remove dead code
This commit is contained in:
jean-pierre charras 2019-12-30 14:23:33 +01:00
parent b84fe2b703
commit 8d649b5351
16 changed files with 74 additions and 189 deletions

View File

@ -49,7 +49,6 @@ set( GERBVIEW_SRCS
gerbview_frame.cpp
json11.cpp
job_file_reader.cpp
locate.cpp
menubar.cpp
readgerb.cpp
rs274_read_XY_and_IJ_coordinates.cpp

View File

@ -284,7 +284,7 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
if( GetCanvas() )
{
for( GERBER_DRAW_ITEM* item = drill_layer->GetItemsList(); item; item = item->Next() )
for( GERBER_DRAW_ITEM* item : drill_layer->GetItems() )
GetCanvas()->GetView()->Add( (KIGFX::VIEW_ITEM*) item );
}
@ -665,7 +665,7 @@ bool EXCELLON_IMAGE::Execute_Drill_Command( char*& text )
}
gbritem = new GERBER_DRAW_ITEM( this );
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
if( m_SlotOn ) // Oblong hole
{
@ -925,7 +925,7 @@ void EXCELLON_IMAGE::FinishRouteCommand()
false );
}
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
StepAndRepeatItem( *gbritem );
}

View File

@ -261,9 +261,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa
if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
continue;
GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
for( ; gerb_item; gerb_item = gerb_item->Next() )
for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
export_non_copper_item( gerb_item, pcb_layer_number );
}
@ -280,9 +278,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa
if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
continue;
GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
for( ; gerb_item; gerb_item = gerb_item->Next() )
for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
export_copper_item( gerb_item, pcb_layer_number );
}

View File

@ -31,7 +31,7 @@
#include <gerber_file_image_list.h>
GBR_LAYOUT::GBR_LAYOUT() :
EDA_ITEM( (EDA_ITEM*)NULL, GERBER_LAYOUT_T )
EDA_ITEM( (EDA_ITEM*)nullptr, GERBER_LAYOUT_T )
{
}
@ -59,7 +59,7 @@ EDA_RECT GBR_LAYOUT::ComputeBoundingBox() const
if( gerber == NULL ) // Graphic layer not yet used
continue;
for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
{
if( first_item )
{
@ -95,7 +95,7 @@ SEARCH_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICA
switch( stype )
{
case GERBER_IMAGE_LIST_T:
case GERBER_LAYOUT_T:
for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
{
GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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
@ -32,16 +32,11 @@
#define GBR_LAYOUT_H
#include <dlist.h>
#include <colors_design_settings.h>
#include <common.h> // PAGE_INFO
#include <gerbview.h> // GERBER_DRAWLAYERS_COUNT
#include <title_block.h>
#include <gerber_draw_item.h>
#include <gbr_display_options.h>
#include <gr_basic.h>
#include <eda_rect.h>
class GERBER_FILE_IMAGE_LIST;

View File

@ -20,7 +20,7 @@
#include "gerber_collectors.h"
const KICAD_T GERBER_COLLECTOR::AllItems[] = {
GERBER_IMAGE_LIST_T,
GERBER_LAYOUT_T,
GERBER_IMAGE_T,
GERBER_DRAW_ITEM_T,
EOT

View File

@ -6,8 +6,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2016 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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
@ -105,7 +105,11 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer ) :
GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
{
m_Drawings.DeleteAll();
for( auto item : GetItems() )
delete item;
m_drawings.clear();
for( unsigned ii = 0; ii < arrayDim( m_Aperture_List ); ii++ )
{
@ -115,15 +119,6 @@ GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
delete m_FileFunction;
}
/*
* Function GetItemsList
* returns the first GERBER_DRAW_ITEM * item of the items list
*/
GERBER_DRAW_ITEM * GERBER_FILE_IMAGE::GetItemsList()
{
return m_Drawings;
}
D_CODE* GERBER_FILE_IMAGE::GetDCODEOrCreate( int aDCODE, bool aCreateIfNoExist )
{
@ -245,7 +240,7 @@ bool GERBER_FILE_IMAGE::HasNegativeItems()
else
{
m_hasNegativeItems = 0;
for( GERBER_DRAW_ITEM* item = GetItemsList(); item; item = item->Next() )
for( GERBER_DRAW_ITEM* item : GetItems() )
{
if( item->GetLayer() != m_GraphicLayer )
continue;
@ -313,6 +308,7 @@ void GERBER_FILE_IMAGE::StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem )
// create duplicate only if ii or jj > 0
if( jj == 0 && ii == 0 )
continue;
GERBER_DRAW_ITEM* dupItem = new GERBER_DRAW_ITEM( aItem );
wxPoint move_vector;
move_vector.x = scaletoIU( ii * GetLayerParams().m_StepForRepeat.x,
@ -320,7 +316,7 @@ void GERBER_FILE_IMAGE::StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem )
move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y,
GetLayerParams().m_StepForRepeatMetric );
dupItem->MoveXY( move_vector );
m_Drawings.Append( dupItem );
AddItemToList( dupItem );
}
}
}
@ -397,10 +393,6 @@ SEARCH_RESULT GERBER_FILE_IMAGE::Visit( INSPECTOR inspector, void* testData, con
const KICAD_T* p = scanTypes;
bool done = false;
#if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' ';
#endif
while( !done )
{
stype = *p;
@ -408,15 +400,16 @@ SEARCH_RESULT GERBER_FILE_IMAGE::Visit( INSPECTOR inspector, void* testData, con
switch( stype )
{
case GERBER_IMAGE_T:
case GERBER_IMAGE_LIST_T:
case GERBER_LAYOUT_T:
++p;
break;
case GERBER_DRAW_ITEM_T:
result = IterateForward( &m_Drawings[0], inspector, testData, p );
result = IterateForward( GetItems(), inspector, testData, p );
++p;
break;
case EOT:
default: // catch EOT or ANY OTHER type here and return.
done = true;
break;

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2010-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2010-2019 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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
@ -37,6 +37,8 @@
#define IsNumber( x ) ( ( ( (x) >= '0' ) && ( (x) <='9' ) ) \
|| ( (x) == '-' ) || ( (x) == '+' ) || ( (x) == '.' ) )
typedef std::vector<GERBER_DRAW_ITEM*> GERBER_DRAW_ITEMS;
class GERBVIEW_FRAME;
class D_CODE;
@ -110,11 +112,10 @@ class GERBER_FILE_IMAGE : public EDA_ITEM
///< (max TOOLS_MAX_COUNT: see dcode.h)
bool m_Exposure; ///< whether an aperture macro tool is flashed on or off
GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer
GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer
GERBER_DRAW_ITEMS m_drawings; // linked list of Gerber Items to draw
public:
DLIST<GERBER_DRAW_ITEM> m_Drawings; // linked list of Gerber Items to draw
bool m_InUse; // true if this image is currently in use
// (a file is loaded in it)
bool m_IsVisible; // true if the draw layer is visible and must be drawn
@ -250,8 +251,6 @@ public:
return wxT( "GERBER_FILE_IMAGE" );
}
void Clear_GERBER_FILE_IMAGE();
/**
* Read and load a gerber file.
* @param aFullFileName = the full filename of the Gerber file
@ -264,7 +263,7 @@ public:
const wxArrayString& GetMessages() const { return m_messagesList; }
/**
* @return the count of Dcode tools in used by the image
* @return the count of Dcode tools in use in the image
*/
int GetDcodesCount();
@ -273,10 +272,31 @@ public:
COLOR4D GetPositiveDrawColor() const { return m_PositiveDrawColor; }
/**
* Function GetItemsList
* @return the first GERBER_DRAW_ITEM * item of the items list
* @return a reference to the GERBER_DRAW_ITEMS deque list
*/
GERBER_DRAW_ITEM * GetItemsList();
GERBER_DRAW_ITEMS& GetItems() { return m_drawings; }
/**
* @return the count of GERBER_DRAW_ITEMS in the image
*/
int GetItemsCount() { return m_drawings.size(); }
/**
* Add a new GERBER_DRAW_ITEM item to the drawings list
* @param aItem is the GERBER_DRAW_ITEM to add to list
*/
void AddItemToList( GERBER_DRAW_ITEM* aItem )
{
m_drawings.push_back( aItem );
}
/**
* @return the last GERBER_DRAW_ITEM* item of the items list
*/
GERBER_DRAW_ITEM* GetLastItemInList() const
{
return m_drawings.back();
}
/**
* Function GetLayerParams

View File

@ -43,13 +43,12 @@ 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() :
EDA_ITEM( (EDA_ITEM*)NULL, GERBER_IMAGE_LIST_T )
GERBER_FILE_IMAGE_LIST::GERBER_FILE_IMAGE_LIST()
{
m_GERBER_List.reserve( GERBER_DRAWLAYERS_COUNT );
for( unsigned layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
m_GERBER_List.push_back( NULL );
m_GERBER_List.push_back( nullptr );
}

View File

@ -60,7 +60,7 @@ class GERBER_FILE_IMAGE;
* which are loaded and can be displayed
* there are 32 images max which can be loaded
*/
class GERBER_FILE_IMAGE_LIST : public EDA_ITEM
class GERBER_FILE_IMAGE_LIST
{
// the list of loaded images (1 image = 1 gerber file)
std::vector<GERBER_FILE_IMAGE*> m_GERBER_List;
@ -69,11 +69,6 @@ public:
GERBER_FILE_IMAGE_LIST();
~GERBER_FILE_IMAGE_LIST();
wxString GetClass() const override
{
return wxT( "GERBER_FILE_IMAGE_LIST" );
}
//Accessor
static GERBER_FILE_IMAGE_LIST& GetImagesList();
GERBER_FILE_IMAGE* GetGbrImage( int aIdx );
@ -123,12 +118,6 @@ public:
* @return a mapping of old to new layer index
*/
std::unordered_map<int, int> SortImagesByZOrder();
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif
};
#endif // ifndef GERBER_FILE_IMAGE_LIST_H

View File

@ -138,7 +138,7 @@ bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
if( gerber == NULL ) // Graphic layer not yet used
continue;
for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
{
m_view->Add (item );
}

View File

@ -470,8 +470,6 @@ public:
*/
void OnQuit( wxCommandEvent& event );
GERBER_DRAW_ITEM* Locate( const wxPoint& aPosition, int typeloc );
void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );

View File

@ -1,107 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* 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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file locate.cpp
*/
#include <fctsys.h>
#include <common.h>
#include <msgpanel.h>
#include <gerbview.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
/* locate a gerber item and return a pointer to it.
* Display info about this item
* Items on non visible layers are not taken in account
*/
GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc )
{
m_messagePanel->EraseMsgBox();
wxPoint ref = aPosition;
if( aTypeloc == CURSEUR_ON_GRILLE )
ref = GetNearestGridPosition( ref );
int layer = GetActiveLayer();
GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
GERBER_DRAW_ITEM* gerb_item = nullptr;
// Search first on active layer
// A not used graphic layer can be selected. So gerber can be NULL
if( gerber && gerber->m_IsVisible )
{
for( auto item = gerber->GetItemsList(); item; item = item->Next() )
{
if( item->HitTest( ref ) )
{
gerb_item = item;
break;
}
}
}
if( gerb_item == nullptr ) // Search on all layers
{
for( layer = 0; layer < (int)ImagesMaxCount(); ++layer )
{
gerber = GetGbrImage( layer );
if( gerber == nullptr ) // Graphic layer not yet used
continue;
if( !gerber->m_IsVisible )
continue;
if( layer == GetActiveLayer() )
continue;
for( auto item = gerber->GetItemsList(); item; item = item->Next() )
{
if( item->HitTest( ref ) )
{
gerb_item = item;
break;
}
}
if( gerb_item )
break;
}
}
if( gerb_item )
{
MSG_PANEL_ITEMS items;
gerb_item->GetMsgPanelInfo( m_userUnits, items );
SetMsgPanel( items );
}
return gerb_item;
}

View File

@ -79,7 +79,7 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
* or has missing definitions,
* warn the user:
*/
if( gerber->GetItemsList() && gerber->m_Has_MissingDCode )
if( gerber->GetItemsCount() && gerber->m_Has_MissingDCode )
{
if( !gerber->m_Has_DCode )
msg = _("Warning: this file has no D-Code definition\n"
@ -99,7 +99,11 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
// (maybe convert geometry into positives?)
}
for( auto item = gerber->GetItemsList(); item; item = item->Next() )
#ifdef GBR_USE_DLIST
for( auto item = gerber->GetFirstItemInList(); item; item = item->Next() )
#else
for( auto item : gerber->GetItems() )
#endif
GetCanvas()->GetView()->Add( (KIGFX::VIEW_ITEM*) item );
}

View File

@ -552,9 +552,9 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command )
break;
case GC_TURN_OFF_POLY_FILL:
if( m_Exposure && GetItemsList() ) // End of polygon
if( m_Exposure && GetLastItemInList() ) // End of polygon
{
GERBER_DRAW_ITEM * gbritem = m_Drawings.GetLast();
GERBER_DRAW_ITEM * gbritem = GetLastItemInList();
gbritem->m_Polygon.Append( gbritem->m_Polygon.CVertex( 0 ) );
StepAndRepeatItem( *gbritem );
}
@ -622,7 +622,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
{
m_Exposure = true;
gbritem = new GERBER_DRAW_ITEM( this );
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
gbritem->m_Shape = GBR_POLYGON;
gbritem->m_Flashed = false;
gbritem->m_DCode = 0; // No DCode for a Polygon (Region in Gerber dialect)
@ -639,7 +639,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
{
case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS:
gbritem = m_Drawings.GetLast();
gbritem = GetLastItemInList();
fillArcPOLY( gbritem, m_PreviousPos,
m_CurrentPos, m_IJPos,
@ -648,7 +648,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
break;
default:
gbritem = m_Drawings.GetLast();
gbritem = GetLastItemInList();
gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage
if( gbritem->m_Polygon.OutlineCount() == 0 )
@ -667,9 +667,9 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
break;
case 2: // code D2: exposure OFF (i.e. "move to")
if( m_Exposure && GetItemsList() ) // End of polygon
if( m_Exposure && GetLastItemInList() ) // End of polygon
{
gbritem = m_Drawings.GetLast();
gbritem = GetLastItemInList();
gbritem->m_Polygon.Append( gbritem->m_Polygon.CVertex( 0 ) );
StepAndRepeatItem( *gbritem );
}
@ -702,7 +702,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
{
case GERB_INTERPOL_LINEAR_1X:
gbritem = new GERBER_DRAW_ITEM( this );
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
m_CurrentPos, size, GetLayerParams().m_LayerNegative );
@ -712,7 +712,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS:
gbritem = new GERBER_DRAW_ITEM( this );
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
if( m_LastCoordIsIJPos )
{
@ -757,7 +757,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
}
gbritem = new GERBER_DRAW_ITEM( this );
m_Drawings.Append( gbritem );
AddItemToList( gbritem );
fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
size, GetLayerParams().m_LayerNegative );
StepAndRepeatItem( *gbritem );

View File

@ -174,7 +174,6 @@ enum KICAD_T
*/
GERBER_LAYOUT_T,
GERBER_DRAW_ITEM_T,
GERBER_IMAGE_LIST_T,
GERBER_IMAGE_T,
/*