KiCad PCB EDA Suite
GERBER_FILE_IMAGE_LIST Class Reference

GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded and can be displayed there are 32 images max which can be loaded. More...

#include <gerber_file_image_list.h>

Public Member Functions

 GERBER_FILE_IMAGE_LIST ()
 
 ~GERBER_FILE_IMAGE_LIST ()
 
GERBER_FILE_IMAGEGetGbrImage (int aIdx)
 
unsigned ImagesMaxCount ()
 
int AddGbrImage (GERBER_FILE_IMAGE *aGbrImage, int aIdx)
 Add a GERBER_FILE_IMAGE* at index aIdx or at the first free location if aIdx < 0. More...
 
void DeleteAllImages ()
 Remove all loaded data in list, and delete all images, freeing the memory. More...
 
void DeleteImage (unsigned int aIdx)
 Delete the loaded data of image aIdx, freeing the memory. More...
 
const wxString GetDisplayName (int aIdx, bool aNameOnly=false, bool aFullName=false)
 Get the display name for the layer at aIdx. More...
 
std::unordered_map< int, int > SortImagesByFunction (LayerSortFunction sortFunction)
 Sort loaded images by file extension matching. More...
 
std::unordered_map< int, int > SortImagesByFileExtension ()
 Sort loaded images by file extension matching. More...
 
std::unordered_map< int, int > SortImagesByZOrder ()
 Sort loaded images by Z order priority, if they have the X2 FileFormat info (SortImagesByZOrder updates the graphic layer of these items) More...
 
std::unordered_map< int, int > SwapImages (unsigned int layer1, unsigned int layer2)
 Swap two images and their orders. More...
 
std::unordered_map< int, int > RemoveImage (unsigned int layer)
 Removes (and deletes) an image, rotating the removed image to the end. More...
 
unsigned GetLoadedImageCount ()
 Get number of loaded images. More...
 

Static Public Member Functions

static void GetGerberLayerFromFilename (const wxString &filename, enum GERBER_ORDER_ENUM &order, wxString &matchedExtension)
 Utility function to guess which PCB layer of a gerber/drill file corresponds to based on its file extension. More...
 
static GERBER_FILE_IMAGE_LISTGetImagesList ()
 

Private Member Functions

std::unordered_map< int, int > GetLayerRemap ()
 When the image order has changed, call this to get a mapping to pass to the frame's Remap() function to remap the widgets layer order. More...
 

Private Attributes

std::vector< GERBER_FILE_IMAGE * > m_GERBER_List
 

Detailed Description

GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded and can be displayed there are 32 images max which can be loaded.

Definition at line 86 of file gerber_file_image_list.h.

Constructor & Destructor Documentation

◆ GERBER_FILE_IMAGE_LIST()

GERBER_FILE_IMAGE_LIST::GERBER_FILE_IMAGE_LIST ( )

Definition at line 43 of file gerber_file_image_list.cpp.

44{
46
47 for( unsigned layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
48 m_GERBER_List.push_back( nullptr );
49}
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List
#define GERBER_DRAWLAYERS_COUNT
Definition: layer_ids.h:402

References GERBER_DRAWLAYERS_COUNT, and m_GERBER_List.

◆ ~GERBER_FILE_IMAGE_LIST()

GERBER_FILE_IMAGE_LIST::~GERBER_FILE_IMAGE_LIST ( )

Definition at line 52 of file gerber_file_image_list.cpp.

53{
55}
void DeleteAllImages()
Remove all loaded data in list, and delete all images, freeing the memory.

References DeleteAllImages().

Member Function Documentation

◆ AddGbrImage()

int GERBER_FILE_IMAGE_LIST::AddGbrImage ( GERBER_FILE_IMAGE aGbrImage,
int  aIdx 
)

Add a GERBER_FILE_IMAGE* at index aIdx or at the first free location if aIdx < 0.

Parameters
aGbrImageis the image to add.
aIdxis the location to use ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).
Returns
true if the index used, or -1 if no room to add image

Definition at line 83 of file gerber_file_image_list.cpp.

84{
85 int idx = aIdx;
86
87 if( idx < 0 )
88 {
89 for( idx = 0; idx < (int)m_GERBER_List.size(); idx++ )
90 {
91 if( m_GERBER_List[idx] == nullptr )
92 break;
93 }
94 }
95
96 if( idx >= (int)m_GERBER_List.size() )
97 return -1; // No room
98
99 m_GERBER_List[idx] = aGbrImage;
100
101 return idx;
102}

References m_GERBER_List.

Referenced by GERBVIEW_FRAME::Read_EXCELLON_File(), and GERBVIEW_FRAME::Read_GERBER_File().

◆ DeleteAllImages()

void GERBER_FILE_IMAGE_LIST::DeleteAllImages ( )

Remove all loaded data in list, and delete all images, freeing the memory.

Definition at line 105 of file gerber_file_image_list.cpp.

106{
107 for( unsigned idx = 0; idx < m_GERBER_List.size(); ++idx )
108 DeleteImage( idx );
109}
void DeleteImage(unsigned int aIdx)
Delete the loaded data of image aIdx, freeing the memory.

References DeleteImage(), and m_GERBER_List.

Referenced by GERBVIEW_FRAME::Clear_DrawLayers(), ~GERBER_FILE_IMAGE_LIST(), and GERBVIEW_FRAME::~GERBVIEW_FRAME().

◆ DeleteImage()

void GERBER_FILE_IMAGE_LIST::DeleteImage ( unsigned int  aIdx)

Delete the loaded data of image aIdx, freeing the memory.

Parameters
aIdxis the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).

Definition at line 112 of file gerber_file_image_list.cpp.

113{
114 // Ensure the index is valid:
115 if( aIdx >= m_GERBER_List.size() )
116 return;
117
118 // delete image aIdx
119 GERBER_FILE_IMAGE* gbr_image = GetGbrImage( static_cast<int>( aIdx ) );
120
121 delete gbr_image;
122 m_GERBER_List[ aIdx ] = nullptr;
123}
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.

References GetGbrImage(), and m_GERBER_List.

Referenced by DeleteAllImages(), and RemoveImage().

◆ GetDisplayName()

const wxString GERBER_FILE_IMAGE_LIST::GetDisplayName ( int  aIdx,
bool  aNameOnly = false,
bool  aFullName = false 
)

Get the display name for the layer at aIdx.

if a file is loaded, the name is: "<aIdx+1> <short filename> <X2 FileFunction info> if a X2 FileFunction info is found" or (if no FileFunction info) "<aIdx+1> <short filename> *" if no file loaded, the name is: "Layer n" with n = aIdx+1

Parameters
aIdxis the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).
aNameOnlyset to false (default) to add the layer number (for layers manager) or true to return only the name without layer name (status bar)/
aFullNameset to false (default) to ellipsize the name, true to return the full name.
Returns
a name for image aIdx which can be used in layers manager and layer selector or in the status bar

Definition at line 126 of file gerber_file_image_list.cpp.

127{
128 wxString name;
129
130 GERBER_FILE_IMAGE* gerber = nullptr;
131
132 if( aIdx >= 0 && aIdx < (int)m_GERBER_List.size() )
133 gerber = m_GERBER_List[aIdx];
134
135 // if a file is loaded, build the name:
136 // <id> <short filename> <X2 FileFunction info> if a X2 FileFunction info is found
137 // or (if no FileFunction info)
138 // <id> <short filename> *
139 if( gerber )
140 {
141 wxFileName fn( gerber->m_FileName );
142 wxString filename = fn.GetFullName();
143
144 // If the filename is too long, display a shortened name if requested
145 const int maxlen = 30;
146
147 if( !aFullName && filename.Length() > maxlen )
148 {
149 wxString shortenedfn = filename.Left(2) + wxT( "..." ) + filename.Right(maxlen-5);
150 filename = shortenedfn;
151 }
152
153 if( gerber->m_FileFunction )
154 {
155 if( gerber->m_FileFunction->IsCopper() )
156 {
157 name.Printf( wxT( "%s (%s, %s, %s)" ),
158 filename.GetData(),
159 gerber->m_FileFunction->GetFileType(),
160 gerber->m_FileFunction->GetBrdLayerId(),
161 gerber->m_FileFunction->GetBrdLayerSide() );
162 }
163 if( gerber->m_FileFunction->IsDrillFile() )
164 {
165 name.Printf( wxT( "%s (%s,%s,%s,%s)" ),
166 filename.GetData(),
167 gerber->m_FileFunction->GetFileType(),
169 gerber->m_FileFunction->GetLPType(),
170 gerber->m_FileFunction->GetRouteType() );
171 }
172 else
173 {
174 name.Printf( wxT( "%s (%s, %s)" ),
175 filename.GetData(),
176 gerber->m_FileFunction->GetFileType(),
177 gerber->m_FileFunction->GetBrdLayerId() );
178 }
179 }
180 else
181 {
182 name = filename;
183 }
184
185 if( aNameOnly )
186 return name;
187
188 wxString fullname;
189
190 fullname.Printf( wxT( "%d " ), aIdx + 1 );
191 fullname << name;
192 return fullname;
193 }
194 else
195 {
196 name.Printf( _( "Graphic layer %d" ), aIdx + 1 );
197 }
198
199 return name;
200}
const char * name
Definition: DXF_plotter.cpp:56
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
file function parameters, found in a TF command or a G04
wxString m_FileName
Full File Name for this layer.
bool IsCopper()
return true if the filefunction type is "Copper"
const wxString & GetBrdLayerSide()
the brd layer Pos: Top, Bot, Inr same as GetBrdLayerId() for non copper type
const wxString & GetFileType()
the type of layer (Copper, Soldermask ... )
const wxString & GetBrdLayerId()
the brd layer identifier: Ln, only for Copper type or Top, Bot for other types
#define _(s)

References _, X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerId(), X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerSide(), X2_ATTRIBUTE_FILEFUNCTION::GetDrillLayerPair(), X2_ATTRIBUTE_FILEFUNCTION::GetFileType(), X2_ATTRIBUTE_FILEFUNCTION::GetLPType(), X2_ATTRIBUTE_FILEFUNCTION::GetRouteType(), X2_ATTRIBUTE_FILEFUNCTION::IsCopper(), X2_ATTRIBUTE_FILEFUNCTION::IsDrillFile(), GERBER_FILE_IMAGE::m_FileFunction, GERBER_FILE_IMAGE::m_FileName, m_GERBER_List, and name.

Referenced by GERBVIEW_FRAME::GERBVIEW_FRAME(), GERBER_DRAW_ITEM::GetItemDescription(), GBR_LAYER_BOX_SELECTOR::getLayerName(), GERBER_DRAW_ITEM::GetMsgPanelInfo(), and GERBER_LAYER_WIDGET::ReFill().

◆ GetGbrImage()

◆ GetGerberLayerFromFilename()

void GERBER_FILE_IMAGE_LIST::GetGerberLayerFromFilename ( const wxString &  filename,
enum GERBER_ORDER_ENUM order,
wxString &  matchedExtension 
)
static

Utility function to guess which PCB layer of a gerber/drill file corresponds to based on its file extension.

Supports many CAD program file extension patterns. Detects gerbers, drills, edge layers, etc.

Parameters
filenameFilename to check against the extension matching table.
orderReturns the order that this layer should be placed in a set of layers.
matchedExtensionThe actual extension pattern that this filename matched.

Definition at line 307 of file gerber_file_image_list.cpp.

310{
312 matchedExtension = "";
313
314 for( struct GERBER_ORDER o : gerberFileExtensionOrder )
315 {
316 wxString ext = filename.Right( o.m_FilenameMask.length() ).Upper();
317
318 if( ext.Matches( o.m_FilenameMask ) )
319 {
320 order = o.m_Order;
321 matchedExtension = ext;
322 return;
323 }
324 }
325}
static struct GERBER_ORDER gerberFileExtensionOrder[]

References GERBER_LAYER_UNKNOWN, and gerberFileExtensionOrder.

Referenced by GERBVIEW_FRAME::OpenProjectFiles(), sortFileExtension(), and GERBVIEW_FRAME::unarchiveFiles().

◆ GetImagesList()

◆ GetLayerRemap()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::GetLayerRemap ( )
private

When the image order has changed, call this to get a mapping to pass to the frame's Remap() function to remap the widgets layer order.

Returns
Map describing the remap.

Definition at line 414 of file gerber_file_image_list.cpp.

415{
416 // The image order has changed.
417 // Graphic layer numbering must be updated to match the widgets layer order
418
419 // Store the old/new graphic layer info:
420 std::unordered_map<int, int> tab_lyr;
421
422 for( unsigned layer = 0; layer < m_GERBER_List.size(); ++layer )
423 {
424 GERBER_FILE_IMAGE* gerber = m_GERBER_List[layer];
425
426 if( !gerber )
427 continue;
428
429 tab_lyr[gerber->m_GraphicLayer] = layer;
430 gerber->m_GraphicLayer = layer ;
431 }
432
433 return tab_lyr;
434}
int m_GraphicLayer
Graphic layer Number.

References m_GERBER_List, and GERBER_FILE_IMAGE::m_GraphicLayer.

Referenced by RemoveImage(), SortImagesByFunction(), and SwapImages().

◆ GetLoadedImageCount()

unsigned GERBER_FILE_IMAGE_LIST::GetLoadedImageCount ( )

Get number of loaded images.

Returns
number of images loaded

Definition at line 73 of file gerber_file_image_list.cpp.

74{
75 auto notNull = []( GERBER_FILE_IMAGE* image )
76 {
77 return image != nullptr;
78 };
79 return std::count_if( m_GERBER_List.begin(), m_GERBER_List.end(), notNull );
80}

References image, and m_GERBER_List.

Referenced by GERBVIEW_FRAME::LoadFileOrShowDialog(), and GERBVIEW_CONTROL::MoveLayerDown().

◆ ImagesMaxCount()

◆ RemoveImage()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::RemoveImage ( unsigned int  layer)

Removes (and deletes) an image, rotating the removed image to the end.

Returns
a mapping of old to new layer index

Definition at line 467 of file gerber_file_image_list.cpp.

468{
469 if( layer >= m_GERBER_List.size() )
470 return std::unordered_map<int, int>();
471
472 DeleteImage( layer );
473 // Move deleted image to end of list, move all other images up
474 std::rotate( m_GERBER_List.begin() + layer, m_GERBER_List.begin() + layer + 1,
475 m_GERBER_List.end() );
476 return GetLayerRemap();
477}
std::unordered_map< int, int > GetLayerRemap()
When the image order has changed, call this to get a mapping to pass to the frame's Remap() function ...

References DeleteImage(), GetLayerRemap(), and m_GERBER_List.

◆ SortImagesByFileExtension()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::SortImagesByFileExtension ( )

Sort loaded images by file extension matching.

Returns
a mapping of old to new layer index

Definition at line 445 of file gerber_file_image_list.cpp.

446{
448}
std::unordered_map< int, int > SortImagesByFunction(LayerSortFunction sortFunction)
Sort loaded images by file extension matching.
static bool sortFileExtension(const GERBER_FILE_IMAGE *const &ref, const GERBER_FILE_IMAGE *const &test)

References sortFileExtension(), and SortImagesByFunction().

◆ SortImagesByFunction()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::SortImagesByFunction ( LayerSortFunction  sortFunction)

Sort loaded images by file extension matching.

Returns
a mapping of old to new layer index

Definition at line 438 of file gerber_file_image_list.cpp.

439{
440 std::sort( m_GERBER_List.begin(), m_GERBER_List.end(), sortFunction );
441 return GetLayerRemap();
442}

References GetLayerRemap(), and m_GERBER_List.

Referenced by SortImagesByFileExtension(), and SortImagesByZOrder().

◆ SortImagesByZOrder()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::SortImagesByZOrder ( )

Sort loaded images by Z order priority, if they have the X2 FileFormat info (SortImagesByZOrder updates the graphic layer of these items)

Returns
a mapping of old to new layer index

Definition at line 451 of file gerber_file_image_list.cpp.

452{
454}
static bool sortZorder(const GERBER_FILE_IMAGE *const &ref, const GERBER_FILE_IMAGE *const &test)

References SortImagesByFunction(), and sortZorder().

◆ SwapImages()

std::unordered_map< int, int > GERBER_FILE_IMAGE_LIST::SwapImages ( unsigned int  layer1,
unsigned int  layer2 
)

Swap two images and their orders.

Returns
a mapping of old to new layer index

Definition at line 457 of file gerber_file_image_list.cpp.

459{
460 if( ( layer1 >= m_GERBER_List.size() ) || ( layer2 >= m_GERBER_List.size() ) )
461 return std::unordered_map<int, int>();
462
463 std::swap( m_GERBER_List[layer1], m_GERBER_List[layer2] );
464 return GetLayerRemap();
465}

References GetLayerRemap(), and m_GERBER_List.

Referenced by GERBVIEW_CONTROL::MoveLayerDown().

Member Data Documentation

◆ m_GERBER_List


The documentation for this class was generated from the following files: