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 <class_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. More...
 
void DeleteImage (int aIdx)
 delete the loaded data of image aIdx. More...
 
const wxString GetDisplayName (int aIdx, bool aNameOnly=false)
 
void 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 62 of file class_gerber_file_image_list.h.

Constructor & Destructor Documentation

GERBER_FILE_IMAGE_LIST::GERBER_FILE_IMAGE_LIST ( )

Definition at line 46 of file class_gerber_file_image_list.cpp.

References GERBER_DRAWLAYERS_COUNT, and m_GERBER_List.

47 {
49 
50  for( unsigned layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
51  m_GERBER_List.push_back( NULL );
52 }
#define GERBER_DRAWLAYERS_COUNT
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List
GERBER_FILE_IMAGE_LIST::~GERBER_FILE_IMAGE_LIST ( )

Definition at line 55 of file class_gerber_file_image_list.cpp.

References DeleteAllImages().

56 {
58 }
void DeleteAllImages()
remove all loaded data in list, and delete all images.

Member Function Documentation

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 80 of file class_gerber_file_image_list.cpp.

References m_GERBER_List.

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

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

remove all loaded data in list, and delete all images.

Memory is freed

Definition at line 102 of file class_gerber_file_image_list.cpp.

References DeleteImage(), and m_GERBER_List.

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

103 {
104  for( unsigned idx = 0; idx < m_GERBER_List.size(); ++idx )
105  DeleteImage( idx );
106 }
void DeleteImage(int aIdx)
delete the loaded data of image aIdx.
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List
void GERBER_FILE_IMAGE_LIST::DeleteImage ( int  aIdx)

delete the loaded data of image aIdx.

Memory is freed

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

Definition at line 109 of file class_gerber_file_image_list.cpp.

References GetGbrImage(), and m_GERBER_List.

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

110 {
111  // Ensure the index is valid:
112  if( aIdx < 0 || aIdx >= int( m_GERBER_List.size() ) )
113  return;
114 
115  // delete image aIdx
116  GERBER_FILE_IMAGE* gbr_image = GetGbrImage( aIdx );
117 
118  delete gbr_image;
119  m_GERBER_List[ aIdx ] = NULL;
120 }
Class GERBER_FILE_IMAGE holds 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
const wxString GERBER_FILE_IMAGE_LIST::GetDisplayName ( int  aIdx,
bool  aNameOnly = false 
)
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
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)

Definition at line 123 of file class_gerber_file_image_list.cpp.

References X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerId(), X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerSide(), GetChars(), 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 GBR_LAYER_BOX_SELECTOR::GetLayerName(), GERBER_DRAW_ITEM::GetMsgPanelInfo(), and GERBER_LAYER_WIDGET::ReFill().

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

Definition at line 226 of file class_gerber_file_image_list.cpp.

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

Referenced by GERBER_LAYER_WIDGET::onPopupSelection().

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

Member Data Documentation

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

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