2016-05-26 07:50:49 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2016 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2021-06-03 18:32:24 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-05-26 07:50:49 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-01-29 12:26:58 +00:00
|
|
|
#ifndef GERBER_FILE_IMAGE_LIST_H
|
|
|
|
#define GERBER_FILE_IMAGE_LIST_H
|
2016-05-26 07:50:49 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
2018-02-27 02:15:32 +00:00
|
|
|
#include <unordered_map>
|
2016-05-26 07:50:49 +00:00
|
|
|
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerber_draw_item.h>
|
|
|
|
#include <am_primitive.h>
|
2016-05-26 07:50:49 +00:00
|
|
|
|
2021-08-02 20:00:34 +00:00
|
|
|
|
|
|
|
enum class GERBER_ORDER_ENUM : int
|
|
|
|
{
|
2022-07-25 19:23:23 +00:00
|
|
|
GERBER_DRILL = 0,
|
|
|
|
GERBER_BOARD_OUTLINE,
|
|
|
|
GERBER_KEEP_OUT,
|
|
|
|
GERBER_MECHANICAL,
|
|
|
|
GERBER_TOP_PASTE,
|
2021-08-02 20:00:34 +00:00
|
|
|
GERBER_TOP_SILK_SCREEN,
|
|
|
|
GERBER_TOP_SOLDER_MASK,
|
|
|
|
GERBER_TOP_COPPER,
|
|
|
|
GERBER_INNER,
|
|
|
|
GERBER_BOTTOM_COPPER,
|
|
|
|
GERBER_BOTTOM_SOLDER_MASK,
|
|
|
|
GERBER_BOTTOM_SILK_SCREEN,
|
|
|
|
GERBER_BOTTOM_PASTE,
|
|
|
|
GERBER_LAYER_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
/* gerber files have different parameters to define units and how items must be plotted.
|
|
|
|
* some are for the entire file, and other can change along a file.
|
|
|
|
* In Gerber world:
|
|
|
|
* an image is the entire gerber file and its "global" parameters
|
|
|
|
* a layer (that is very different from a board layer) is just a sub set of a file that
|
|
|
|
* have specific parameters
|
|
|
|
* if a Image parameter is set more than once, only the last value is used
|
|
|
|
* Some parameters can change along a file and are not layer specific: they are stored
|
2021-06-03 18:32:24 +00:00
|
|
|
* in GERBER_ITEM items, when instanced.
|
2016-05-26 07:50:49 +00:00
|
|
|
*
|
|
|
|
* In GerbView, to handle these parameters, there are 2 classes:
|
|
|
|
* GERBER_FILE_IMAGE : the main class containing most of parameters and data to plot a graphic layer
|
|
|
|
* Some of them can change along the file
|
|
|
|
* There is one GERBER_FILE_IMAGE per file and one graphic layer per file or GERBER_FILE_IMAGE
|
|
|
|
* GerbView does not read and merge 2 gerber file in one graphic layer:
|
|
|
|
* I believe this is not possible due to the constraints in Image parameters.
|
2021-06-03 18:32:24 +00:00
|
|
|
* GERBER_LAYER : containing the subset of parameters that is layer specific
|
2016-05-26 07:50:49 +00:00
|
|
|
* A GERBER_FILE_IMAGE must include one GERBER_LAYER to define all parameters to plot a file.
|
|
|
|
* But a GERBER_FILE_IMAGE can use more than one GERBER_LAYER.
|
|
|
|
*/
|
|
|
|
|
2021-08-02 20:00:34 +00:00
|
|
|
typedef bool( LayerSortFunction )( const GERBER_FILE_IMAGE* const& ref,
|
|
|
|
const GERBER_FILE_IMAGE* const& test );
|
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
class GERBER_FILE_IMAGE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 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
|
|
|
|
*/
|
2019-12-30 13:23:33 +00:00
|
|
|
class GERBER_FILE_IMAGE_LIST
|
2016-05-26 07:50:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GERBER_FILE_IMAGE_LIST();
|
|
|
|
~GERBER_FILE_IMAGE_LIST();
|
|
|
|
|
2021-08-02 20:00:34 +00:00
|
|
|
/**
|
|
|
|
* @brief 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.
|
|
|
|
*
|
|
|
|
* @param filename Filename to check against the extension matching table.
|
|
|
|
* @param order Returns the order that this layer should be placed in a set of layers.
|
|
|
|
* @param matchedExtension The actual extension pattern that this filename matched.
|
|
|
|
*/
|
|
|
|
static void GetGerberLayerFromFilename( const wxString& filename, enum GERBER_ORDER_ENUM& order,
|
|
|
|
wxString& matchedExtension );
|
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
static GERBER_FILE_IMAGE_LIST& GetImagesList();
|
2016-05-26 07:50:49 +00:00
|
|
|
GERBER_FILE_IMAGE* GetGbrImage( int aIdx );
|
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
unsigned ImagesMaxCount() { return m_GERBER_List.size(); }
|
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
/**
|
2021-03-26 15:47:02 +00:00
|
|
|
* Add a GERBER_FILE_IMAGE* at index aIdx or at the first free location if aIdx < 0
|
|
|
|
*
|
2021-06-03 18:32:24 +00:00
|
|
|
* @param aGbrImage is the image to add.
|
|
|
|
* @param aIdx is the location to use ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).
|
2016-05-26 07:50:49 +00:00
|
|
|
* @return true if the index used, or -1 if no room to add image
|
|
|
|
*/
|
|
|
|
int AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-26 15:47:02 +00:00
|
|
|
* Remove all loaded data in list, and delete all images, freeing the memory.
|
2016-05-26 07:50:49 +00:00
|
|
|
*/
|
2016-06-15 08:26:41 +00:00
|
|
|
void DeleteAllImages();
|
2016-05-26 07:50:49 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Delete the loaded data of image \a aIdx, freeing the memory.
|
2021-03-26 15:47:02 +00:00
|
|
|
*
|
2021-06-03 18:32:24 +00:00
|
|
|
* @param aIdx is the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).
|
2016-05-26 07:50:49 +00:00
|
|
|
*/
|
2016-06-15 08:26:41 +00:00
|
|
|
void DeleteImage( int aIdx );
|
2016-05-26 07:50:49 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Get the display name for the layer at \a aIdx.
|
2021-03-26 15:47:02 +00:00
|
|
|
*
|
2016-05-26 07:50:49 +00:00
|
|
|
* 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
|
2021-06-03 18:32:24 +00:00
|
|
|
*
|
|
|
|
* @param aIdx is the index ( 0 ... GERBER_DRAWLAYERS_COUNT-1 ).
|
|
|
|
* @param aNameOnly set to false (default) to add the layer number (for layers manager)
|
|
|
|
* or true to return only the name without layer name (status bar)/
|
|
|
|
* @param aFullName set to false (default) to ellipsize the name, true to return the full name.
|
|
|
|
*
|
|
|
|
* @return a name for image aIdx which can be used in layers manager and layer selector or
|
|
|
|
* in the status bar
|
2016-05-26 07:50:49 +00:00
|
|
|
*/
|
2021-03-26 15:47:02 +00:00
|
|
|
const wxString GetDisplayName( int aIdx, bool aNameOnly = false, bool aFullName = false );
|
2016-05-26 07:50:49 +00:00
|
|
|
|
2021-08-02 20:00:34 +00:00
|
|
|
/**
|
|
|
|
* Sort loaded images by file extension matching
|
|
|
|
*
|
|
|
|
* @return a mapping of old to new layer index
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, int> SortImagesByFunction( LayerSortFunction sortFunction );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort loaded images by file extension matching
|
|
|
|
*
|
|
|
|
* @return a mapping of old to new layer index
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, int> SortImagesByFileExtension();
|
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
/**
|
|
|
|
* Sort loaded images by Z order priority, if they have the X2 FileFormat info
|
|
|
|
* (SortImagesByZOrder updates the graphic layer of these items)
|
2018-02-27 02:15:32 +00:00
|
|
|
*
|
|
|
|
* @return a mapping of old to new layer index
|
2016-05-26 07:50:49 +00:00
|
|
|
*/
|
2018-02-27 02:15:32 +00:00
|
|
|
std::unordered_map<int, int> SortImagesByZOrder();
|
2021-06-03 18:32:24 +00:00
|
|
|
|
2021-08-04 18:47:26 +00:00
|
|
|
/**
|
|
|
|
* Swap two images and their orders.
|
|
|
|
*
|
|
|
|
* @return a mapping of old to new layer index
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, int> SwapImages( unsigned int layer1, unsigned int layer2 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes (and deletes) an image, rotating the removed image to the end.
|
|
|
|
*
|
|
|
|
* @return a mapping of old to new layer index
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, int> RemoveImage( unsigned int layer );
|
|
|
|
|
2021-07-25 03:41:05 +00:00
|
|
|
/**
|
|
|
|
* Get number of loaded images
|
|
|
|
*
|
|
|
|
* @return number of images loaded
|
|
|
|
*/
|
|
|
|
unsigned GetLoadedImageCount();
|
|
|
|
|
2021-06-03 18:32:24 +00:00
|
|
|
private:
|
2021-08-04 18:47:26 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return Map describing the remap.
|
|
|
|
*/
|
|
|
|
std::unordered_map<int, int> GetLayerRemap();
|
|
|
|
|
2021-06-03 18:32:24 +00:00
|
|
|
// the list of loaded images (1 image = 1 gerber file)
|
|
|
|
std::vector<GERBER_FILE_IMAGE*> m_GERBER_List;
|
2016-05-26 07:50:49 +00:00
|
|
|
};
|
|
|
|
|
2018-01-29 12:26:58 +00:00
|
|
|
#endif // ifndef GERBER_FILE_IMAGE_LIST_H
|