KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gerber_file_image_list.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2010-2016 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef GERBER_FILE_IMAGE_LIST_H
22#define GERBER_FILE_IMAGE_LIST_H
23
24#include <vector>
25#include <set>
26#include <unordered_map>
27
28#include <gerber_draw_item.h>
29#include <am_primitive.h>
30
31
49
50
51/* gerber files have different parameters to define units and how items must be plotted.
52 * some are for the entire file, and other can change along a file.
53 * In Gerber world:
54 * an image is the entire gerber file and its "global" parameters
55 * a layer (that is very different from a board layer) is just a sub set of a file that
56 * have specific parameters
57 * if a Image parameter is set more than once, only the last value is used
58 * Some parameters can change along a file and are not layer specific: they are stored
59 * in GERBER_ITEM items, when instanced.
60 *
61 * In GerbView, to handle these parameters, there are 2 classes:
62 * GERBER_FILE_IMAGE : the main class containing most of parameters and data to plot a graphic layer
63 * Some of them can change along the file
64 * There is one GERBER_FILE_IMAGE per file and one graphic layer per file or GERBER_FILE_IMAGE
65 * GerbView does not read and merge 2 gerber file in one graphic layer:
66 * I believe this is not possible due to the constraints in Image parameters.
67 * GERBER_LAYER : containing the subset of parameters that is layer specific
68 * A GERBER_FILE_IMAGE must include one GERBER_LAYER to define all parameters to plot a file.
69 * But a GERBER_FILE_IMAGE can use more than one GERBER_LAYER.
70 */
71
72typedef bool( LayerSortFunction )( const GERBER_FILE_IMAGE* const& ref,
73 const GERBER_FILE_IMAGE* const& test );
74
76
83{
84public:
87
98 static void GetGerberLayerFromFilename( const wxString& filename, enum GERBER_ORDER_ENUM& order,
99 wxString& matchedExtension );
100
102 GERBER_FILE_IMAGE* GetGbrImage( int aIdx );
103
104 unsigned ImagesMaxCount() { return m_GERBER_List.size(); }
105
113 int AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx );
114
115
119 void DeleteAllImages();
120
126 void DeleteImage( unsigned int aIdx );
127
146 const wxString GetDisplayName( int aIdx, bool aNameOnly = false, bool aFullName = false );
147
153 std::unordered_map<int, int> SortImagesByFunction( LayerSortFunction sortFunction );
154
160 std::unordered_map<int, int> SortImagesByFileExtension();
161
168 std::unordered_map<int, int> SortImagesByZOrder();
169
175 std::unordered_map<int, int> SwapImages( unsigned int layer1, unsigned int layer2 );
176
182 std::unordered_map<int, int> RemoveImage( unsigned int layer );
183
189 unsigned GetLoadedImageCount();
190
191private:
199 std::unordered_map<int, int> GetLayerRemap();
200
201 // the list of loaded images (1 image = 1 gerber file)
202 std::vector<GERBER_FILE_IMAGE*> m_GERBER_List;
203};
204
205#endif // ifndef GERBER_FILE_IMAGE_LIST_H
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.
std::unordered_map< int, int > SwapImages(unsigned int layer1, unsigned int layer2)
Swap two images and their orders.
unsigned GetLoadedImageCount()
Get number of loaded images.
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 ext...
std::unordered_map< int, int > SortImagesByZOrder()
Sort loaded images by Z order priority, if they have the X2 FileFormat info (SortImagesByZOrder updat...
void DeleteImage(unsigned int aIdx)
Delete the loaded data of image aIdx, freeing the memory.
std::unordered_map< int, int > SortImagesByFileExtension()
Sort loaded images by file extension matching.
static GERBER_FILE_IMAGE_LIST & GetImagesList()
const wxString GetDisplayName(int aIdx, bool aNameOnly=false, bool aFullName=false)
Get the display name for the layer at aIdx.
void DeleteAllImages()
Remove all loaded data in list, and delete all images, freeing the memory.
std::vector< GERBER_FILE_IMAGE * > m_GERBER_List
std::unordered_map< int, int > RemoveImage(unsigned int layer)
Removes (and deletes) an image, rotating the removed image to the end.
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 ...
std::unordered_map< int, int > SortImagesByFunction(LayerSortFunction sortFunction)
Sort loaded images by file extension matching.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
bool LayerSortFunction(const GERBER_FILE_IMAGE *const &ref, const GERBER_FILE_IMAGE *const &test)