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 (C) 1992-2021 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef GERBER_FILE_IMAGE_LIST_H
26#define GERBER_FILE_IMAGE_LIST_H
27
28#include <vector>
29#include <set>
30#include <unordered_map>
31
32#include <gerber_draw_item.h>
33#include <am_primitive.h>
34
35
36enum class GERBER_ORDER_ENUM : int
37{
38 GERBER_DRILL = 0,
52};
53
54
55/* gerber files have different parameters to define units and how items must be plotted.
56 * some are for the entire file, and other can change along a file.
57 * In Gerber world:
58 * an image is the entire gerber file and its "global" parameters
59 * a layer (that is very different from a board layer) is just a sub set of a file that
60 * have specific parameters
61 * if a Image parameter is set more than once, only the last value is used
62 * Some parameters can change along a file and are not layer specific: they are stored
63 * in GERBER_ITEM items, when instanced.
64 *
65 * In GerbView, to handle these parameters, there are 2 classes:
66 * GERBER_FILE_IMAGE : the main class containing most of parameters and data to plot a graphic layer
67 * Some of them can change along the file
68 * There is one GERBER_FILE_IMAGE per file and one graphic layer per file or GERBER_FILE_IMAGE
69 * GerbView does not read and merge 2 gerber file in one graphic layer:
70 * I believe this is not possible due to the constraints in Image parameters.
71 * GERBER_LAYER : containing the subset of parameters that is layer specific
72 * A GERBER_FILE_IMAGE must include one GERBER_LAYER to define all parameters to plot a file.
73 * But a GERBER_FILE_IMAGE can use more than one GERBER_LAYER.
74 */
75
76typedef bool( LayerSortFunction )( const GERBER_FILE_IMAGE* const& ref,
77 const GERBER_FILE_IMAGE* const& test );
78
80
87{
88public:
91
102 static void GetGerberLayerFromFilename( const wxString& filename, enum GERBER_ORDER_ENUM& order,
103 wxString& matchedExtension );
104
106 GERBER_FILE_IMAGE* GetGbrImage( int aIdx );
107
108 unsigned ImagesMaxCount() { return m_GERBER_List.size(); }
109
117 int AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx );
118
119
123 void DeleteAllImages();
124
130 void DeleteImage( unsigned int aIdx );
131
150 const wxString GetDisplayName( int aIdx, bool aNameOnly = false, bool aFullName = false );
151
157 std::unordered_map<int, int> SortImagesByFunction( LayerSortFunction sortFunction );
158
164 std::unordered_map<int, int> SortImagesByFileExtension();
165
172 std::unordered_map<int, int> SortImagesByZOrder();
173
179 std::unordered_map<int, int> SwapImages( unsigned int layer1, unsigned int layer2 );
180
186 std::unordered_map<int, int> RemoveImage( unsigned int layer );
187
193 unsigned GetLoadedImageCount();
194
195private:
203 std::unordered_map<int, int> GetLayerRemap();
204
205 // the list of loaded images (1 image = 1 gerber file)
206 std::vector<GERBER_FILE_IMAGE*> m_GERBER_List;
207};
208
209#endif // ifndef GERBER_FILE_IMAGE_LIST_H
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
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)