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 (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 > SortImagesByZOrder ()
 Sort loaded images by Z order priority, if they have the X2 FileFormat info (SortImagesByZOrder updates the graphic layer of these items) More...
 

Static Public Member Functions

static GERBER_FILE_IMAGE_LISTGetImagesList ()
 

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 63 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 44 of file gerber_file_image_list.cpp.

45 {
47 
48  for( unsigned layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
49  m_GERBER_List.push_back( nullptr );
50 }
#define GERBER_DRAWLAYERS_COUNT
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List

References GERBER_DRAWLAYERS_COUNT, and m_GERBER_List.

◆ ~GERBER_FILE_IMAGE_LIST()

GERBER_FILE_IMAGE_LIST::~GERBER_FILE_IMAGE_LIST ( )

Definition at line 53 of file gerber_file_image_list.cpp.

54 {
56 }
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
aGbrImage= the image to add
aIdx= 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 78 of file gerber_file_image_list.cpp.

79 {
80  int idx = aIdx;
81 
82  if( idx < 0 )
83  {
84  for( idx = 0; idx < (int)m_GERBER_List.size(); idx++ )
85  {
86  if( m_GERBER_List[idx] == NULL )
87  break;
88  }
89  }
90 
91  if( idx >= (int)m_GERBER_List.size() )
92  return -1; // No room
93 
94  m_GERBER_List[idx] = aGbrImage;
95 
96  return idx;
97 }
#define NULL
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List

References m_GERBER_List, and NULL.

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 100 of file gerber_file_image_list.cpp.

101 {
102  for( unsigned idx = 0; idx < m_GERBER_List.size(); ++idx )
103  DeleteImage( idx );
104 }
void DeleteImage(int aIdx)
Delete the loaded data of image aIdx, freeing the memory.
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List

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 ( int  aIdx)

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

Parameters
aIdx= the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )

Definition at line 107 of file gerber_file_image_list.cpp.

108 {
109  // Ensure the index is valid:
110  if( aIdx < 0 || aIdx >= int( m_GERBER_List.size() ) )
111  return;
112 
113  // delete image aIdx
114  GERBER_FILE_IMAGE* gbr_image = GetGbrImage( aIdx );
115 
116  delete gbr_image;
117  m_GERBER_List[ aIdx ] = nullptr;
118 }
Hold the image data and parameters for one gerber file and layer parameters.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List

References GetGbrImage(), and m_GERBER_List.

Referenced by DeleteAllImages(), and GERBVIEW_FRAME::Erase_Current_DrawLayer().

◆ 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.

Parameters
aIdx= the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 )
aNameOnly= false (default) to add the layer number (for layers manager) or true to return only the name without layer name (status bar)
aFullName= 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 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

Definition at line 121 of file gerber_file_image_list.cpp.

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

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, name, and NULL.

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

◆ GetGbrImage()

◆ GetImagesList()

◆ ImagesMaxCount()

◆ 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 225 of file gerber_file_image_list.cpp.

226 {
227  std::sort( m_GERBER_List.begin(), m_GERBER_List.end(), sortZorder );
228 
229  // The image order has changed.
230  // Graphic layer numbering must be updated to match the widgets layer order
231 
232  // Store the old/new graphic layer info:
233  std::unordered_map<int, int> tab_lyr;
234 
235  for( unsigned layer = 0; layer < m_GERBER_List.size(); ++layer )
236  {
237  GERBER_FILE_IMAGE* gerber = m_GERBER_List[layer];
238 
239  if( !gerber )
240  continue;
241 
242  tab_lyr[gerber->m_GraphicLayer] = layer;
243  gerber->m_GraphicLayer = layer ;
244  }
245 
246  return tab_lyr;
247 }
static bool sortZorder(const GERBER_FILE_IMAGE *const &ref, const GERBER_FILE_IMAGE *const &test)
Hold the image data and parameters for one gerber file and layer parameters.
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List

References m_GERBER_List, GERBER_FILE_IMAGE::m_GraphicLayer, and sortZorder().

Referenced by GERBVIEW_FRAME::SortLayersByX2Attributes().

Member Data Documentation

◆ m_GERBER_List

std::vector<GERBER_FILE_IMAGE*> GERBER_FILE_IMAGE_LIST::m_GERBER_List
private

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