KiCad PCB EDA Suite
altium_pcb.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) 2019-2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef ALTIUM_PCB_H
25 #define ALTIUM_PCB_H
26 
27 #include <functional>
29 #include <vector>
30 
31 #include <altium_parser_pcb.h>
32 
33 
34 enum class ALTIUM_PCB_DIR
35 {
37 
39  ARCS6,
40  BOARD6,
42  CLASSES6,
52  EMBEDDEDS6,
55  FILLS6,
56  FROMTOS6,
57  MODELS,
59  NETS6,
60  PADS6,
66  POLYGONS6,
67  REGIONS6,
68  RULES6,
73  TEXTS,
74  TEXTS6,
75  TEXTURES,
76  TRACKS6,
77  UNIONNAMES,
79  VIAS6,
81 };
82 
83 
84 class BOARD;
85 class DRAWSEGMENT;
86 class MODULE;
87 class ZONE_CONTAINER;
88 
89 
97 void ParseAltiumPcb( BOARD* aBoard, const wxString& aFileName,
98  const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping );
99 
100 
101 namespace CFB
102 {
103 class CompoundFileReader;
104 struct COMPOUND_FILE_ENTRY;
105 } // namespace CFB
106 
107 
108 // type declaration required for a helper method
110 typedef std::function<void( const CFB::CompoundFileReader&, const CFB::COMPOUND_FILE_ENTRY* )>
112 
113 
115 {
116 public:
117  explicit ALTIUM_PCB( BOARD* aBoard );
118  ~ALTIUM_PCB();
119 
120  void Parse( const CFB::CompoundFileReader& aReader,
121  const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping );
122 
123 private:
124  PCB_LAYER_ID GetKicadLayer( ALTIUM_LAYER aAltiumLayer ) const;
125  int GetNetCode( uint16_t aId ) const;
126  const ARULE6* GetRule( ALTIUM_RULE_KIND aKind, const wxString& aName ) const;
127  const ARULE6* GetRuleDefault( ALTIUM_RULE_KIND aKind ) const;
128 
129  void ParseFileHeader(
130  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
131 
132  // Text Format
133  void ParseBoard6Data(
134  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
135  void ParseClasses6Data(
136  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
138  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
140  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
141  void ParseModelsData( const CFB::CompoundFileReader& aReader,
142  const CFB::COMPOUND_FILE_ENTRY* aEntry, const wxString aRootDir );
143  void ParseNets6Data(
144  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
145  void ParsePolygons6Data(
146  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
147  void ParseRules6Data(
148  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
149 
150  // Binary Format
151  void ParseArcs6Data(
152  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
154  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
155  void ParsePads6Data(
156  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
157  void ParseVias6Data(
158  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
159  void ParseTracks6Data(
160  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
161  void ParseTexts6Data(
162  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
163  void ParseFills6Data(
164  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
166  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
168  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
169  void ParseRegions6Data(
170  const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
171 
172  // Helper Functions
173  void HelperParseDimensions6Linear( const ADIMENSION6& aElem );
174  void HelperParseDimensions6Leader( const ADIMENSION6& aElem );
175  void HelperParseDimensions6Datum( const ADIMENSION6& aElem );
176  void HelperParseDimensions6Center( const ADIMENSION6& aElem );
177 
178  void HelperParsePad6NonCopper( const APAD6& aElem );
179 
180  void HelperCreateBoardOutline( const std::vector<ALTIUM_VERTICE>& aVertices );
181 
182  DRAWSEGMENT* HelperCreateAndAddDrawsegment( uint16_t aComponent );
183  void HelperDrawsegmentSetLocalCoord( DRAWSEGMENT* aDs, uint16_t aComponent );
184 
186  std::vector<MODULE*> m_components;
187  std::vector<ZONE_CONTAINER*> m_polygons;
188  std::map<wxString, wxString> m_models;
189  size_t m_num_nets;
190  std::map<ALTIUM_LAYER, PCB_LAYER_ID> m_layermap; // used to correctly map copper layers
191  std::map<ALTIUM_RULE_KIND, std::vector<ARULE6>> m_rules;
192 
193  std::map<ALTIUM_LAYER, ZONE_CONTAINER*> m_outer_plane;
194 
197 };
198 
199 
200 #endif //ALTIUM_PCB_H
void HelperParseDimensions6Datum(const ADIMENSION6 &aElem)
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
void Parse(const CFB::CompoundFileReader &aReader, const std::map< ALTIUM_PCB_DIR, std::string > &aFileMapping)
Definition: altium_pcb.cpp:342
void ParseVias6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void ParseShapeBasedRegions6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
const ARULE6 * GetRule(ALTIUM_RULE_KIND aKind, const wxString &aName) const
Definition: altium_pcb.cpp:511
void ParseComponents6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
Definition: altium_pcb.cpp:774
void ParseRules6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void ParsePolygons6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
DRAWSEGMENT * HelperCreateAndAddDrawsegment(uint16_t aComponent)
Definition: altium_pcb.cpp:106
std::vector< ZONE_CONTAINER * > m_polygons
Definition: altium_pcb.h:187
void ParseComponentsBodies6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
Definition: altium_pcb.cpp:824
PCB_LAYER_ID GetKicadLayer(ALTIUM_LAYER aAltiumLayer) const
Definition: altium_pcb.cpp:142
void ParseArcs6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
const ARULE6 * GetRuleDefault(ALTIUM_RULE_KIND aKind) const
Definition: altium_pcb.cpp:528
int GetNetCode(uint16_t aId) const
Definition: altium_pcb.cpp:494
std::map< wxString, wxString > m_models
Definition: altium_pcb.h:188
void ParsePads6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void HelperParseDimensions6Leader(const ADIMENSION6 &aElem)
Definition: altium_pcb.cpp:979
void ParseRegions6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
PCB_LAYER_ID
A quick note on layer IDs:
BOARD * m_board
Definition: altium_pcb.h:185
std::map< ALTIUM_LAYER, PCB_LAYER_ID > m_layermap
Definition: altium_pcb.h:190
void ParseDimensions6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
ALTIUM_RULE_KIND
void ParseTexts6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void ParseClasses6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
Definition: altium_pcb.cpp:744
ALTIUM_PCB_DIR
Definition: altium_pcb.h:34
std::map< ALTIUM_LAYER, ZONE_CONTAINER * > m_outer_plane
Definition: altium_pcb.h:193
void ParseFileHeader(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
Definition: altium_pcb.cpp:545
void ParseBoardRegionsData(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
std::vector< MODULE * > m_components
Definition: altium_pcb.h:186
void HelperParseDimensions6Center(const ADIMENSION6 &aElem)
size_t m_num_nets
Definition: altium_pcb.h:189
int m_highest_pour_index
Altium stores pour order across all layers.
Definition: altium_pcb.h:196
void ParseModelsData(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry, const wxString aRootDir)
void ParseTracks6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void HelperParseDimensions6Linear(const ADIMENSION6 &aElem)
Definition: altium_pcb.cpp:896
Board layer functions and definitions.
void HelperParsePad6NonCopper(const APAD6 &aElem)
void ParseNets6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
void HelperCreateBoardOutline(const std::vector< ALTIUM_VERTICE > &aVertices)
Definition: altium_pcb.cpp:679
ALTIUM_LAYER
std::map< ALTIUM_RULE_KIND, std::vector< ARULE6 > > m_rules
Definition: altium_pcb.h:191
void ParseFills6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
void ParseAltiumPcb(BOARD *aBoard, const wxString &aFileName, const std::map< ALTIUM_PCB_DIR, std::string > &aFileMapping)
Helper method which opens a Altium Board File and parses it.
Definition: altium_pcb.cpp:50
void ParseBoard6Data(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
Definition: altium_pcb.cpp:564
void HelperDrawsegmentSetLocalCoord(DRAWSEGMENT *aDs, uint16_t aComponent)
Definition: altium_pcb.cpp:130
std::function< void(const CFB::CompoundFileReader &, const CFB::COMPOUND_FILE_ENTRY *)> PARSE_FUNCTION_POINTER_fp
Definition: altium_pcb.h:109
ALTIUM_PCB(BOARD *aBoard)
Definition: altium_pcb.cpp:331