2020-04-03 23:22:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019-2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ALTIUM_PCB_H
|
|
|
|
#define ALTIUM_PCB_H
|
|
|
|
|
|
|
|
#include <functional>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2020-04-03 23:22:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <altium_parser_pcb.h>
|
|
|
|
|
|
|
|
|
|
|
|
enum class ALTIUM_PCB_DIR
|
|
|
|
{
|
|
|
|
FILE_HEADER,
|
|
|
|
|
|
|
|
ADVANCEDPLACEROPTIONS6,
|
|
|
|
ARCS6,
|
|
|
|
BOARD6,
|
|
|
|
BOARDREGIONS,
|
|
|
|
CLASSES6,
|
|
|
|
COMPONENTBODIES6,
|
|
|
|
COMPONENTS6,
|
|
|
|
CONNECTIONS6,
|
|
|
|
COORDINATES6,
|
|
|
|
DESIGNRULECHECKEROPTIONS6,
|
|
|
|
DIFFERENTIALPAIRS6,
|
|
|
|
DIMENSIONS6,
|
|
|
|
EMBEDDEDBOARDS6,
|
|
|
|
EMBEDDEDFONTS6,
|
|
|
|
EMBEDDEDS6,
|
|
|
|
EXTENDPRIMITIVEINFORMATION,
|
|
|
|
FILEVERSIONINFO,
|
|
|
|
FILLS6,
|
|
|
|
FROMTOS6,
|
|
|
|
MODELS,
|
|
|
|
MODELSNOEMBED,
|
|
|
|
NETS6,
|
|
|
|
PADS6,
|
|
|
|
PADVIALIBRARY,
|
|
|
|
PADVIALIBRARYCACHE,
|
|
|
|
PADVIALIBRARYLINKS,
|
|
|
|
PINSWAPOPTIONS6,
|
|
|
|
PINPAIRSSECTION,
|
|
|
|
POLYGONS6,
|
|
|
|
REGIONS6,
|
|
|
|
RULES6,
|
|
|
|
SHAPEBASEDCOMPONENTBODIES6,
|
|
|
|
SHAPEBASEDREGIONS6,
|
|
|
|
SIGNALCLASSES,
|
|
|
|
SMARTUNIONS,
|
|
|
|
TEXTS,
|
|
|
|
TEXTS6,
|
|
|
|
TEXTURES,
|
|
|
|
TRACKS6,
|
|
|
|
UNIONNAMES,
|
|
|
|
UNIQUEIDPRIMITIVEINFORMATION,
|
|
|
|
VIAS6,
|
|
|
|
WIDESTRINGS6
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BOARD;
|
2020-10-04 23:34:59 +00:00
|
|
|
class PCB_SHAPE;
|
2020-11-13 15:15:52 +00:00
|
|
|
class FOOTPRINT;
|
2020-11-11 23:05:59 +00:00
|
|
|
class ZONE;
|
2021-07-24 13:23:55 +00:00
|
|
|
class PCB_DIMENSION_BASE;
|
2021-06-26 10:49:58 +00:00
|
|
|
class PROGRESS_REPORTER;
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method which opens a Altium Board File and parses it.
|
|
|
|
*
|
|
|
|
* @param aBoard board the pcb should be appended to
|
|
|
|
* @param aFileName file name of board file
|
2021-06-26 11:58:56 +00:00
|
|
|
* @param aProgressReporter report import progress, might be a nullptr.
|
2020-04-03 23:22:24 +00:00
|
|
|
* @param aFileMapping mapping how altium stream names are mapped
|
|
|
|
*/
|
2021-06-26 10:49:58 +00:00
|
|
|
void ParseAltiumPcb( BOARD* aBoard, const wxString& aFileName, PROGRESS_REPORTER* aProgressReporter,
|
|
|
|
const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace CFB
|
|
|
|
{
|
|
|
|
class CompoundFileReader;
|
|
|
|
struct COMPOUND_FILE_ENTRY;
|
|
|
|
} // namespace CFB
|
|
|
|
|
|
|
|
|
|
|
|
// type declaration required for a helper method
|
|
|
|
class ALTIUM_PCB;
|
|
|
|
typedef std::function<void( const CFB::CompoundFileReader&, const CFB::COMPOUND_FILE_ENTRY* )>
|
|
|
|
PARSE_FUNCTION_POINTER_fp;
|
|
|
|
|
|
|
|
|
|
|
|
class ALTIUM_PCB
|
|
|
|
{
|
|
|
|
public:
|
2021-06-26 10:49:58 +00:00
|
|
|
explicit ALTIUM_PCB( BOARD* aBoard, PROGRESS_REPORTER* aProgressReporter );
|
2020-04-03 23:22:24 +00:00
|
|
|
~ALTIUM_PCB();
|
|
|
|
|
2021-07-24 13:23:55 +00:00
|
|
|
void Parse( const CFB::CompoundFileReader& aReader,
|
|
|
|
const std::map<ALTIUM_PCB_DIR, std::string>& aFileMapping );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-26 10:49:58 +00:00
|
|
|
void checkpoint();
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
PCB_LAYER_ID GetKicadLayer( ALTIUM_LAYER aAltiumLayer ) const;
|
|
|
|
int GetNetCode( uint16_t aId ) const;
|
|
|
|
const ARULE6* GetRule( ALTIUM_RULE_KIND aKind, const wxString& aName ) const;
|
|
|
|
const ARULE6* GetRuleDefault( ALTIUM_RULE_KIND aKind ) const;
|
|
|
|
|
|
|
|
void ParseFileHeader(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
|
|
|
|
// Text Format
|
|
|
|
void ParseBoard6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseClasses6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseComponents6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseDimensions6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
2020-04-21 13:34:06 +00:00
|
|
|
void ParseModelsData( const CFB::CompoundFileReader& aReader,
|
2021-07-27 12:22:27 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* aEntry, const wxString& aRootDir );
|
2020-04-03 23:22:24 +00:00
|
|
|
void ParseNets6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParsePolygons6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseRules6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
|
|
|
|
// Binary Format
|
|
|
|
void ParseArcs6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
2020-04-21 13:34:06 +00:00
|
|
|
void ParseComponentsBodies6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
void ParsePads6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseVias6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseTracks6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseTexts6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseFills6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseBoardRegionsData(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseShapeBasedRegions6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
|
|
|
void ParseRegions6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
2021-11-10 16:46:01 +00:00
|
|
|
void ParseWideStrings6Data(
|
|
|
|
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry );
|
2020-04-03 23:22:24 +00:00
|
|
|
|
|
|
|
// Helper Functions
|
|
|
|
void HelperParseDimensions6Linear( const ADIMENSION6& aElem );
|
2021-07-24 13:23:55 +00:00
|
|
|
void HelperParseDimensions6Radial( const ADIMENSION6& aElem );
|
2020-04-03 23:22:24 +00:00
|
|
|
void HelperParseDimensions6Leader( const ADIMENSION6& aElem );
|
|
|
|
void HelperParseDimensions6Datum( const ADIMENSION6& aElem );
|
|
|
|
void HelperParseDimensions6Center( const ADIMENSION6& aElem );
|
|
|
|
|
2020-04-18 21:47:53 +00:00
|
|
|
void HelperParsePad6NonCopper( const APAD6& aElem );
|
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
void HelperCreateBoardOutline( const std::vector<ALTIUM_VERTICE>& aVertices );
|
|
|
|
|
2021-07-17 18:52:13 +00:00
|
|
|
PCB_SHAPE* HelperCreateAndAddShape( uint16_t aComponent );
|
|
|
|
void HelperShapeSetLocalCoord( PCB_SHAPE* aShape, uint16_t aComponent );
|
2020-04-18 21:47:53 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
BOARD* m_board;
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<FOOTPRINT*> m_components;
|
2020-11-11 23:05:59 +00:00
|
|
|
std::vector<ZONE*> m_polygons;
|
2021-07-24 13:23:55 +00:00
|
|
|
std::vector<PCB_DIMENSION_BASE*> m_radialDimensions;
|
2020-04-21 13:34:06 +00:00
|
|
|
std::map<wxString, wxString> m_models;
|
2021-11-10 16:46:01 +00:00
|
|
|
std::map<uint32_t, wxString> m_unicodeStrings;
|
2020-04-03 23:22:24 +00:00
|
|
|
size_t m_num_nets;
|
|
|
|
std::map<ALTIUM_LAYER, PCB_LAYER_ID> m_layermap; // used to correctly map copper layers
|
|
|
|
std::map<ALTIUM_RULE_KIND, std::vector<ARULE6>> m_rules;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
std::map<ALTIUM_LAYER, ZONE*> m_outer_plane;
|
2020-05-10 17:30:03 +00:00
|
|
|
|
2021-06-26 10:49:58 +00:00
|
|
|
PROGRESS_REPORTER* m_progressReporter; ///< optional; may be nullptr
|
|
|
|
unsigned m_doneCount;
|
|
|
|
unsigned m_lastProgressCount;
|
|
|
|
unsigned m_totalCount; ///< for progress reporting
|
|
|
|
|
2020-05-10 17:30:03 +00:00
|
|
|
/// Altium stores pour order across all layers
|
|
|
|
int m_highest_pour_index;
|
2020-04-03 23:22:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //ALTIUM_PCB_H
|