KiCad PCB EDA Suite
cadstar_pcb_archive_plugin.cpp
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) 2020 Roberto Fernandez Bautista <[email protected]>
5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
29#include <board.h>
30#include <footprint.h>
31#include <string_utf8_map.h>
32
33
35 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
36{
37 std::map<wxString, PCB_LAYER_ID> retval;
38
39 // Just return a the auto-mapped layers
40 for( INPUT_LAYER_DESC layerDesc : aInputLayerDescriptionVector )
41 {
42 retval.insert( { layerDesc.Name, layerDesc.AutoMapLayer } );
43 }
44
45 return retval;
46}
47
48
50 LAYER_MAPPING_HANDLER aLayerMappingHandler )
51{
53 m_show_layer_mapping_warnings = false; // only show warnings with default callback
54}
55
56
58{
59 m_board = nullptr;
60 m_props = nullptr;
64}
65
66
68{
69}
70
71
73{
75 {
76 delete fp;
77 }
78
79 m_loaded_footprints.clear();
80}
81
82
84{
85 return wxT( "CADSTAR PCB Archive" );
86}
87
88
90{
91 return wxT( "cpa" );
92}
93
94
96{
97 std::vector<FOOTPRINT*> retval;
98
100 {
101 retval.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
102 }
103
104 return retval;
105}
106
107
108BOARD* CADSTAR_PCB_ARCHIVE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
109 const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
110 PROGRESS_REPORTER* aProgressReporter )
111{
112 m_props = aProperties;
113 m_board = aAppendToMe ? aAppendToMe : new BOARD();
115
117 m_show_layer_mapping_warnings, aProgressReporter );
118 tempPCB.Load( m_board, aProject );
119
120 //center the board:
121 if( aProperties )
122 {
123 UTF8 page_width;
124 UTF8 page_height;
125
126 if( aProperties->Value( "page_width", &page_width )
127 && aProperties->Value( "page_height", &page_height ) )
128 {
130
131 int w = atoi( page_width.c_str() );
132 int h = atoi( page_height.c_str() );
133
134 int desired_x = ( w - bbbox.GetWidth() ) / 2;
135 int desired_y = ( h - bbbox.GetHeight() ) / 2;
136
137 m_board->Move( VECTOR2I( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
138 }
139 }
140
141 // Need to set legacy loading so that netclassess and design rules are loaded correctly
144
146
147 return m_board;
148}
Loads a cpa file into a KiCad BOARD object.
Pcbnew PLUGIN for CADSTAR PCB Archive (*.cpa) format: an ASCII format based on S-expressions.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition: board.h:342
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:823
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: board.cpp:383
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
Definition: board.h:346
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetY() const
Definition: box2.h:181
coord_type GetWidth() const
Definition: box2.h:187
coord_type GetX() const
Definition: box2.h:180
void Load(BOARD *aBoard, PROJECT *aProject)
Loads a CADSTAR PCB Archive file into the KiCad BOARD object given.
std::vector< FOOTPRINT * > GetLoadedLibraryFootpints() const
Return a copy of the loaded library footprints (caller owns the objects)
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
static std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler) override
Register a different handler to be called when mapping of Cadstar to KiCad layers occurs.
std::vector< FOOTPRINT * > m_loaded_footprints
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
virtual void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:64
A name/value tuple with unique names and optional values.
bool Value(const char *aName, UTF8 *aFetchedValue=nullptr) const
Fetch a property by aName and returns true if that property was found, else false.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
const char * c_str() const
Definition: utf8.h:102
std::function< std::map< wxString, PCB_LAYER_ID >(const std::vector< INPUT_LAYER_DESC > &)> LAYER_MAPPING_HANDLER
Pointer to a function that takes a map of source and KiCad layers and returns a re-mapped version.
Describes an imported layer and how it could be mapped to KiCad Layers.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618