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 <roberto.fer.bau@gmail.com>
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 <properties.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 {
74  for( FOOTPRINT* fp : m_loaded_footprints )
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 
99  for( FOOTPRINT* fp : m_loaded_footprints )
100  {
101  retval.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
102  }
103 
104  return retval;
105 }
106 
107 
108 BOARD* CADSTAR_PCB_ARCHIVE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
109  const PROPERTIES* 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( wxPoint( 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 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
Pcbnew PLUGIN for CADSTAR PCB Archive (*.cpa) format: an ASCII format based on S-expressions.
Container for project specific data.
Definition: project.h:62
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition: board.h:268
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
Definition: board.h:272
int GetX() const
Definition: eda_rect.h:98
const EDA_RECT GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:737
A progress reporter interface for use in multi-threaded environments.
std::vector< FOOTPRINT * > m_loaded_footprints
int GetWidth() const
Definition: eda_rect.h:109
A name/value tuple with unique names and optional values.
Definition: properties.h:33
Describes an imported layer and how it could be mapped to KiCad Layers.
virtual void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
const char * c_str() const
Definition: utf8.h:102
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 * > GetLoadedLibraryFootpints() const
Return a copy of the loaded library footprints (caller owns the objects)
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.
Loads a cpa file into a KiCad BOARD object.
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *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 ...
static std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
void Load(BOARD *aBoard, PROJECT *aProject)
Loads a CADSTAR PCB Archive file into the KiCad BOARD object given.
bool Value(const char *aName, UTF8 *aFetchedValue=nullptr) const
Fetch a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
int GetHeight() const
Definition: eda_rect.h:110
void Move(const wxPoint &aMoveVector) override
Move this object.
Definition: board.cpp:268
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
Handle the component boundary box.
Definition: eda_rect.h:42
int GetY() const
Definition: eda_rect.h:99
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.