1 /* 2 * This program source code file is part of KiCad, a free EDA CAD application. 3 * 4 * Copyright (C) 2020 Jan Mrázek <email@honzamrazek.cz> 5 * Copyright (C) 2020 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com> 6 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. 7 * 8 * This program is free software: you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the 10 * Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along 19 * with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef PLUGIN_COMMON_LAYER_MAPPING_H 23 #define PLUGIN_COMMON_LAYER_MAPPING_H 24 25 #include <functional> 26 #include <map> 27 28 #include <io_mgr.h> 29 #include <layer_ids.h> // PCB_LAYER_ID 30 31 /** 32 * @brief Describes an imported layer and how it could be mapped to KiCad Layers 33 */ 34 struct INPUT_LAYER_DESC 35 { 36 wxString Name; ///< Imported layer name as displayed in original application. 37 LSET PermittedLayers; ///< KiCad layers that the imported layer can be mapped onto. 38 PCB_LAYER_ID AutoMapLayer; ///< Best guess as to what the equivalent KiCad layer might be. 39 bool Required; ///< Should we require the layer to be assigned? 40 INPUT_LAYER_DESCINPUT_LAYER_DESC41 INPUT_LAYER_DESC() 42 : Name( wxEmptyString ), 43 PermittedLayers(), 44 AutoMapLayer( PCB_LAYER_ID::UNDEFINED_LAYER ), 45 Required( true ) 46 { 47 } 48 }; 49 50 /** 51 * @brief Pointer to a function that takes a map of source and KiCad layers 52 * and returns a re-mapped version. If the re-mapped layer is UNDEFINED_LAYER, 53 * then the source layer will not be imported 54 */ 55 using LAYER_MAPPING_HANDLER = std::function<std::map<wxString, PCB_LAYER_ID>( const std::vector<INPUT_LAYER_DESC>& )>; 56 57 58 /** 59 * @brief Plugin class for import plugins that support remappable layers 60 */ 61 class LAYER_REMAPPABLE_PLUGIN 62 { 63 public: 64 /** 65 * @brief Register a different handler to be called when mapping of input 66 * layers to KiCad layers occurs 67 * 68 * The function is marked as virtual, so the plugins can implement extra 69 * logic (e.g., enable warnings or checks) 70 * 71 * @param aLayerMappingHandler 72 */ RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)73 virtual void RegisterLayerMappingCallback( LAYER_MAPPING_HANDLER aLayerMappingHandler ) 74 { 75 m_layer_mapping_handler = aLayerMappingHandler; 76 } 77 78 virtual ~LAYER_REMAPPABLE_PLUGIN() = default; 79 protected: 80 LAYER_MAPPING_HANDLER m_layer_mapping_handler; ///< Callback to get layer mapping 81 }; 82 83 #endif // PLUGIN_COMMON_LAYER_MAPPING_H 84