2020-07-12 16:58:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-31 20:47:36 +00:00
|
|
|
* Copyright (C) 2020-2021 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-07-12 16:58:35 +00:00
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-08-29 18:09:48 +00:00
|
|
|
* @file cadstar_pcb_archive_loader.h
|
|
|
|
* @brief Loads a cpa file into a KiCad BOARD object
|
2020-07-12 16:58:35 +00:00
|
|
|
*/
|
|
|
|
|
2020-08-29 18:09:48 +00:00
|
|
|
#ifndef CADSTAR_PCB_ARCHIVE_LOADER_H_
|
|
|
|
#define CADSTAR_PCB_ARCHIVE_LOADER_H_
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
#include <cadstar_pcb_archive_parser.h>
|
2020-10-09 16:58:21 +00:00
|
|
|
#include <cadstar_pcb_archive_plugin.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2020-08-31 22:09:29 +00:00
|
|
|
#include <set>
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
class BOARD;
|
2021-06-06 19:03:10 +00:00
|
|
|
class BOARD_STACKUP_ITEM;
|
2021-06-11 16:59:28 +00:00
|
|
|
class PCB_DIMENSION_BASE;
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2020-08-30 14:10:26 +00:00
|
|
|
class CADSTAR_PCB_ARCHIVE_LOADER : public CADSTAR_PCB_ARCHIVE_PARSER
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-10-01 22:47:38 +00:00
|
|
|
explicit CADSTAR_PCB_ARCHIVE_LOADER(
|
|
|
|
wxString aFilename, LAYER_MAPPING_HANDLER aLayerMappingHandler, bool aLogLayerWarnings )
|
2020-08-31 22:09:29 +00:00
|
|
|
: CADSTAR_PCB_ARCHIVE_PARSER( aFilename )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_layerMappingHandler = aLayerMappingHandler;
|
|
|
|
m_logLayerWarnings = aLogLayerWarnings;
|
|
|
|
m_board = nullptr;
|
|
|
|
m_project = nullptr;
|
|
|
|
m_designCenter.x = 0;
|
|
|
|
m_designCenter.y = 0;
|
|
|
|
m_doneCopperWarning = false;
|
|
|
|
m_doneSpacingClassWarning = false;
|
|
|
|
m_doneNetClassWarning = false;
|
|
|
|
m_numNets = 0;
|
2020-07-12 16:58:35 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
~CADSTAR_PCB_ARCHIVE_LOADER()
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<SYMDEF_ID, FOOTPRINT*> libItem : m_libraryMap )
|
2020-08-31 22:09:29 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = libItem.second;
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint )
|
|
|
|
delete footprint;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
/**
|
2020-07-30 22:42:56 +00:00
|
|
|
* @brief Loads a CADSTAR PCB Archive file into the KiCad BOARD object given
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aBoard
|
2020-07-12 16:58:35 +00:00
|
|
|
*/
|
2021-02-13 20:00:17 +00:00
|
|
|
void Load( BOARD* aBoard, PROJECT* aProject );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
2021-01-31 21:55:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Return a copy of the loaded library footprints (caller owns the objects)
|
|
|
|
* @return Container with all the footprint definitions that were loaded
|
|
|
|
*/
|
|
|
|
std::vector<FOOTPRINT*> GetLoadedLibraryFootpints() const;
|
2020-09-06 17:00:02 +00:00
|
|
|
|
2020-07-12 16:58:35 +00:00
|
|
|
private:
|
2021-02-13 20:00:17 +00:00
|
|
|
LAYER_MAPPING_HANDLER m_layerMappingHandler; ///< Callback to get layer mapping
|
|
|
|
bool m_logLayerWarnings; ///< Used in loadBoardStackup()
|
|
|
|
BOARD* m_board;
|
|
|
|
PROJECT* m_project;
|
|
|
|
std::map<LAYER_ID, PCB_LAYER_ID> m_layermap; ///< Map between Cadstar and KiCad Layers.
|
2020-08-28 20:32:53 +00:00
|
|
|
///< Populated by loadBoardStackup().
|
2021-02-13 20:00:17 +00:00
|
|
|
std::map<SYMDEF_ID, FOOTPRINT*> m_libraryMap; ///< Map between Cadstar and KiCad
|
2020-08-28 20:32:53 +00:00
|
|
|
///< components in the library. Populated
|
2020-08-31 22:09:29 +00:00
|
|
|
///< by loadComponentLibrary(). Owns the
|
2020-11-13 15:15:52 +00:00
|
|
|
///< FOOTPRINT objects.
|
2021-02-13 20:00:17 +00:00
|
|
|
std::map<GROUP_ID, PCB_GROUP*> m_groupMap; ///< Map between Cadstar and KiCad
|
2020-09-06 21:20:32 +00:00
|
|
|
///< groups. Does NOT ownthe PCB_GROUP
|
|
|
|
///< objects (these should have been
|
2021-02-13 20:00:17 +00:00
|
|
|
///< loaded to m_board).
|
|
|
|
std::map<COMPONENT_ID, FOOTPRINT*> m_componentMap; ///< Map between Cadstar and KiCad
|
2020-08-31 22:09:29 +00:00
|
|
|
///< components on the board. Does NOT own
|
2020-11-13 15:15:52 +00:00
|
|
|
///< the FOOTPRINT objects (these should
|
2021-02-13 20:00:17 +00:00
|
|
|
///< have been loaded to m_board).
|
2021-04-10 18:14:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map of pad anchor points (first) to copper pads (second). In the vast majority
|
|
|
|
* of designs there is only one copper pad, but just in case, making it a vector
|
|
|
|
*/
|
|
|
|
using ASSOCIATED_COPPER_PADS = std::map<PAD_ID, std::vector<PAD_ID>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associated copper pads (if any) for each component library definition
|
|
|
|
*/
|
|
|
|
std::map<SYMDEF_ID, ASSOCIATED_COPPER_PADS> m_librarycopperpads;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
std::map<NET_ID, NETINFO_ITEM*> m_netMap; ///< Map between Cadstar and KiCad Nets
|
|
|
|
std::map<ROUTECODE_ID, NETCLASSPTR> m_netClassMap; ///< Map between Cadstar and KiCad classes
|
|
|
|
std::map<TEMPLATE_ID, ZONE*> m_zonesMap; ///< Map between Cadstar and KiCad zones
|
|
|
|
std::vector<LAYER_ID> m_powerPlaneLayers; ///< List of layers that are marked as
|
2020-09-10 20:58:20 +00:00
|
|
|
///< power plane in CADSTAR. This is used
|
2020-08-31 22:09:29 +00:00
|
|
|
///< by "loadtemplates"
|
2021-02-13 20:00:17 +00:00
|
|
|
wxPoint m_designCenter; ///< Used for calculating the required
|
2020-08-28 20:32:53 +00:00
|
|
|
///< offset to apply to the Cadstar design
|
|
|
|
///< so that it fits in KiCad canvas
|
2021-02-13 20:00:17 +00:00
|
|
|
std::set<HATCHCODE_ID> m_hatchcodesTested; ///< Used by checkAndLogHatchCode() to
|
2020-08-31 22:09:29 +00:00
|
|
|
///< avoid multiple duplicate warnings
|
2021-02-13 20:00:17 +00:00
|
|
|
std::set<PADCODE_ID> m_padcodesTested; ///< Used by getKiCadPad() to avoid
|
2020-10-25 23:28:04 +00:00
|
|
|
///< multiple duplicate warnings
|
2021-02-13 20:00:17 +00:00
|
|
|
bool m_doneCopperWarning; ///< Used by loadCoppers() to avoid
|
2020-08-31 22:09:29 +00:00
|
|
|
///< multiple duplicate warnings
|
2021-02-13 20:00:17 +00:00
|
|
|
bool m_doneSpacingClassWarning; ///< Used by getKiCadNet() to avoid
|
2020-09-06 15:24:40 +00:00
|
|
|
///< multiple duplicate warnings
|
2021-02-13 20:00:17 +00:00
|
|
|
bool m_doneNetClassWarning; ///< Used by getKiCadNet() to avoid
|
2020-09-06 15:24:40 +00:00
|
|
|
///< multiple duplicate warnings
|
2021-02-13 20:00:17 +00:00
|
|
|
int m_numNets; ///< Number of nets loaded so far
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
// Functions for loading individual elements:
|
|
|
|
void loadBoardStackup();
|
2021-02-13 20:00:17 +00:00
|
|
|
void remapUnsureLayers(); ///< Callback m_layerMappingHandler for layers we aren't sure of
|
2020-09-02 18:35:12 +00:00
|
|
|
void loadDesignRules();
|
2020-08-28 20:32:53 +00:00
|
|
|
void loadComponentLibrary();
|
2020-09-06 21:20:32 +00:00
|
|
|
void loadGroups();
|
2020-08-16 17:12:08 +00:00
|
|
|
void loadBoards();
|
2020-08-23 10:34:27 +00:00
|
|
|
void loadFigures();
|
2020-09-02 21:48:18 +00:00
|
|
|
void loadTexts();
|
2020-09-06 22:16:02 +00:00
|
|
|
void loadDimensions();
|
2020-08-23 10:34:27 +00:00
|
|
|
void loadAreas();
|
2020-08-28 20:32:53 +00:00
|
|
|
void loadComponents();
|
2020-09-05 15:31:57 +00:00
|
|
|
void loadDocumentationSymbols();
|
2020-08-31 22:09:29 +00:00
|
|
|
void loadTemplates();
|
|
|
|
void loadCoppers();
|
|
|
|
void loadNets();
|
2020-12-13 15:40:03 +00:00
|
|
|
void loadTextVariables();
|
2020-08-30 12:23:25 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
// Helper functions for element loading:
|
2020-10-01 22:47:38 +00:00
|
|
|
void logBoardStackupWarning( const wxString& aCadstarLayerName,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer );
|
|
|
|
void logBoardStackupMessage( const wxString& aCadstarLayerName,
|
|
|
|
const PCB_LAYER_ID& aKiCadLayer );
|
2021-02-13 20:00:17 +00:00
|
|
|
void initStackupItem( const LAYER& aCadstarLayer, BOARD_STACKUP_ITEM* aKiCadItem,
|
2020-12-28 02:21:37 +00:00
|
|
|
int aDielectricSublayer );
|
2020-11-13 15:15:52 +00:00
|
|
|
void loadLibraryFigures( const SYMDEF_PCB& aComponent, FOOTPRINT* aFootprint );
|
|
|
|
void loadLibraryCoppers( const SYMDEF_PCB& aComponent, FOOTPRINT* aFootprint );
|
|
|
|
void loadLibraryAreas( const SYMDEF_PCB& aComponent, FOOTPRINT* aFootprint );
|
|
|
|
void loadLibraryPads( const SYMDEF_PCB& aComponent, FOOTPRINT* aFootprint );
|
|
|
|
void loadComponentAttributes( const COMPONENT& aComponent, FOOTPRINT* aFootprint );
|
2021-03-25 11:28:22 +00:00
|
|
|
void loadNetTracks( const NET_ID& aCadstarNetID, const NET_PCB::ROUTE& aCadstarRoute,
|
|
|
|
long aStartWidth = std::numeric_limits<long>::max(),
|
|
|
|
long aEndWidth = std::numeric_limits<long>::max() );
|
|
|
|
|
|
|
|
/// Load via and return via size
|
|
|
|
int loadNetVia( const NET_ID& aCadstarNetID, const NET_PCB::VIA& aCadstarVia );
|
2020-09-06 17:00:02 +00:00
|
|
|
void checkAndLogHatchCode( const HATCHCODE_ID& aCadstarHatchcodeID );
|
2021-06-11 16:59:28 +00:00
|
|
|
void applyDimensionSettings( const DIMENSION& aCadstarDim, PCB_DIMENSION_BASE* aKiCadDim );
|
2021-02-13 20:00:17 +00:00
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-02-06 19:36:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Tries to make a best guess as to the zone priorities based on the pour status.
|
|
|
|
*/
|
|
|
|
void calculateZonePriorities();
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
//Helper functions for drawing /loading objects onto screen:
|
2020-09-06 21:20:32 +00:00
|
|
|
|
2020-09-05 15:31:57 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarText
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the text to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aCadstarLayerOverride if not empty, overrides the LayerID in aCadstarText
|
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
|
|
|
* @param aMirrorInvert if true, it inverts the Mirror status of aCadstarText
|
|
|
|
*/
|
|
|
|
void drawCadstarText( const TEXT& aCadstarText, BOARD_ITEM_CONTAINER* aContainer,
|
2020-11-13 11:17:15 +00:00
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const LAYER_ID& aCadstarLayerOverride = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-09-05 15:31:57 +00:00
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarShape
|
2020-08-16 17:12:08 +00:00
|
|
|
* @param aCadstarLayerID KiCad layer to draw on
|
2020-09-08 17:35:06 +00:00
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2020-08-23 10:34:27 +00:00
|
|
|
* @param aShapeName for reporting warnings/errors to the user
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the shape
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarShape( const SHAPE& aCadstarShape, const PCB_LAYER_ID& aKiCadLayer,
|
2020-11-13 11:17:15 +00:00
|
|
|
const int& aLineThickness, const wxString& aShapeName,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0, const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-13 20:00:17 +00:00
|
|
|
* @brief Uses PCB_SHAPE to draw the cutouts on m_board object
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aVertices
|
2020-08-16 17:12:08 +00:00
|
|
|
* @param aKiCadLayer KiCad layer to draw on
|
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the drawsegments
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarCutoutsAsSegments( const std::vector<CUTOUT>& aCutouts,
|
2020-11-13 11:17:15 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-13 20:00:17 +00:00
|
|
|
* @brief Uses PCB_SHAPE to draw the vertices on m_board object
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aCadstarVertices
|
2020-08-16 17:12:08 +00:00
|
|
|
* @param aKiCadLayer KiCad layer to draw on
|
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the drawsegment
|
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarVerticesAsSegments( const std::vector<VERTEX>& aCadstarVertices,
|
2020-11-13 11:17:15 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer,
|
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-04 23:34:59 +00:00
|
|
|
* @brief Returns a vector of pointers to PCB_SHAPE objects. Caller owns the objects.
|
2020-08-31 22:09:29 +00:00
|
|
|
* @param aCadstarVertices
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board). Can be nullptr.
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the drawsegment
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
2020-11-13 11:17:15 +00:00
|
|
|
std::vector<PCB_SHAPE*> getDrawSegmentsFromVertices( const std::vector<VERTEX>& aCadstarVertices,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer = nullptr,
|
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
/**
|
2020-10-04 23:34:59 +00:00
|
|
|
* @brief Returns a pointer to a PCB_SHAPE object. Caller owns the object.
|
2020-08-31 22:09:29 +00:00
|
|
|
* @param aCadstarStartPoint
|
|
|
|
* @param aCadstarVertex
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board). Can be nullptr.
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aCadstarGroupID to add the shape to
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the drawsegment
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-08-31 22:09:29 +00:00
|
|
|
*/
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* getDrawSegmentFromVertex( const POINT& aCadstarStartPoint,
|
2020-11-13 11:17:15 +00:00
|
|
|
const VERTEX& aCadstarVertex,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer = nullptr,
|
|
|
|
const GROUP_ID& aCadstarGroupID = wxEmptyString,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarShape
|
2020-08-23 10:34:27 +00:00
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2020-11-13 15:15:52 +00:00
|
|
|
* @param aParentContainer Parent object (e.g. BOARD or FOOTPRINT pointer)
|
2020-11-11 23:05:59 +00:00
|
|
|
* @return Pointer to ZONE. Caller owns the object.
|
2020-08-23 10:34:27 +00:00
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* getZoneFromCadstarShape( const SHAPE& aCadstarShape, const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aParentContainer );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns a SHAPE_POLY_SET object from a Cadstar SHAPE
|
|
|
|
* @param aCadstarShape
|
|
|
|
* @param aLineThickness Thickness of line is used for expanding the polygon by half.
|
2021-02-13 20:00:17 +00:00
|
|
|
* @param aContainer to draw on (e.g. m_board). Can be nullptr.
|
2020-09-05 15:31:57 +00:00
|
|
|
* @param aMoveVector move draw segment by this amount (in KiCad coordinates)
|
|
|
|
* @param aRotationAngle rotate draw segment by this amount (in tenth degrees)
|
|
|
|
* @param aScalingFactor scale draw segment by this amount
|
|
|
|
* @param aTransformCentre around which all transforms are applied (KiCad coordinates)
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aMirrorInvert if true, mirrors the shape
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-08-23 10:34:27 +00:00
|
|
|
*/
|
2020-08-28 20:32:53 +00:00
|
|
|
SHAPE_POLY_SET getPolySetFromCadstarShape( const SHAPE& aCadstarShape,
|
2020-11-13 11:17:15 +00:00
|
|
|
const int& aLineThickness = -1,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer = nullptr,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngle = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-04 23:34:59 +00:00
|
|
|
* @brief Returns a SHAPE_LINE_CHAIN object from a series of PCB_SHAPE objects
|
2020-08-23 10:34:27 +00:00
|
|
|
* @param aDrawSegments
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-08-23 10:34:27 +00:00
|
|
|
*/
|
2020-10-04 23:34:59 +00:00
|
|
|
SHAPE_LINE_CHAIN getLineChainFromDrawsegments( const std::vector<PCB_SHAPE*> aDrawSegments );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns a vector of pointers to TRACK/ARC objects. Caller owns the objects
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aDrawsegments
|
2020-08-31 22:09:29 +00:00
|
|
|
* @param aParentContainer sets this as the parent of each TRACK object and Add()s it to the parent
|
|
|
|
* @param aNet sets all the tracks to this net, unless nullptr
|
|
|
|
* @param aLayerOverride Sets all tracks to this layer, or, if it is UNDEFINED_LAYER, uses the layers
|
|
|
|
* in the DrawSegments
|
|
|
|
* @param aWidthOverride Sets all tracks to this width, or, if it is UNDEFINED_LAYER, uses the width
|
|
|
|
* in the DrawSegments
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-08-31 22:09:29 +00:00
|
|
|
*/
|
2021-06-11 21:07:02 +00:00
|
|
|
std::vector<PCB_TRACK*> makeTracksFromDrawsegments( const std::vector<PCB_SHAPE*> aDrawsegments,
|
|
|
|
BOARD_ITEM_CONTAINER* aParentContainer,
|
|
|
|
NETINFO_ITEM* aNet = nullptr,
|
|
|
|
PCB_LAYER_ID aLayerOverride = UNDEFINED_LAYER,
|
|
|
|
int aWidthOverride = -1 );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
/**
|
2020-11-13 11:17:15 +00:00
|
|
|
* @brief Adds a CADSTAR Attribute to a KiCad footprint
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aCadstarAttrLoc
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aCadstarAttributeID
|
2020-11-13 01:12:36 +00:00
|
|
|
* @param aFootprint
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aAttributeValue
|
2020-08-28 20:32:53 +00:00
|
|
|
*/
|
|
|
|
void addAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
2020-11-13 15:15:52 +00:00
|
|
|
const ATTRIBUTE_ID& aCadstarAttributeID, FOOTPRINT* aFootprint,
|
2020-11-13 11:17:15 +00:00
|
|
|
const wxString& aAttributeValue );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2021-03-25 11:28:22 +00:00
|
|
|
/**
|
|
|
|
* @brief CADSTAR's Post Processor does an action called "Route Offset" which
|
|
|
|
* is applied when a route is wider than the pad on which it is terminating or
|
|
|
|
* when there are different widths of route, in order to reduce overlap.
|
|
|
|
* @param aPointToOffset Point that we want to offset by aOffsetAmount
|
|
|
|
* @param aRefPoint Reference point to use for determine the angle of the offset
|
|
|
|
* @param aOffsetAmount
|
|
|
|
*/
|
|
|
|
void applyRouteOffset( wxPoint* aPointToOffset, const wxPoint& aRefPoint,
|
|
|
|
const long& aOffsetAmount );
|
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
//Helper Functions for obtaining CADSTAR elements in the parsed structures
|
|
|
|
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
|
2020-08-31 22:09:29 +00:00
|
|
|
COPPERCODE getCopperCode( const COPPERCODE_ID& aCadstaCopperCodeID );
|
2020-09-05 15:31:57 +00:00
|
|
|
HATCHCODE getHatchCode( const HATCHCODE_ID& aCadstarHatchcodeID );
|
|
|
|
LAYERPAIR getLayerPair( const LAYERPAIR_ID& aCadstarLayerPairID );
|
2020-08-31 22:09:29 +00:00
|
|
|
PADCODE getPadCode( const PADCODE_ID& aCadstarPadCodeID );
|
2020-09-05 15:31:57 +00:00
|
|
|
PART getPart( const PART_ID& aCadstarPartID );
|
2020-09-06 15:24:40 +00:00
|
|
|
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
|
2020-09-05 15:31:57 +00:00
|
|
|
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
2020-09-06 15:24:40 +00:00
|
|
|
VIACODE getViaCode( const VIACODE_ID& aCadstarViaCodeID );
|
2020-09-06 17:00:02 +00:00
|
|
|
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
2020-09-10 20:58:20 +00:00
|
|
|
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
|
|
|
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-09-06 17:00:02 +00:00
|
|
|
// Helper Functions for obtaining individual elements as KiCad elements:
|
2020-09-06 21:20:32 +00:00
|
|
|
double getHatchCodeAngleDegrees( const HATCHCODE_ID& aCadstarHatchcodeID );
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* getKiCadPad( const COMPONENT_PAD& aCadstarPad, FOOTPRINT* aParent );
|
2021-04-10 18:14:43 +00:00
|
|
|
PAD*& getPadReference( FOOTPRINT* aFootprint, const PAD_ID aCadstarPadID );
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* getFootprintFromCadstarID( const COMPONENT_ID& aCadstarComponentID );
|
2020-09-06 21:20:32 +00:00
|
|
|
int getKiCadHatchCodeThickness( const HATCHCODE_ID& aCadstarHatchcodeID );
|
|
|
|
int getKiCadHatchCodeGap( const HATCHCODE_ID& aCadstarHatchcodeID );
|
|
|
|
PCB_GROUP* getKiCadGroup( const GROUP_ID& aCadstarGroupID );
|
2020-08-31 22:09:29 +00:00
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
|
|
|
* @brief Scales, offsets and inverts y axis to make the point usable directly in KiCad
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aCadstarPoint
|
|
|
|
* @return
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
wxPoint getKiCadPoint( wxPoint aCadstarPoint );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarLength
|
|
|
|
* @return
|
2020-08-28 20:32:53 +00:00
|
|
|
*/
|
|
|
|
int getKiCadLength( long long aCadstarLength )
|
|
|
|
{
|
|
|
|
return aCadstarLength * KiCadUnitMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarAngle
|
|
|
|
* @return
|
2020-08-28 20:32:53 +00:00
|
|
|
*/
|
2020-08-31 22:09:29 +00:00
|
|
|
double getAngleTenthDegree( const long long& aCadstarAngle )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-11-19 15:25:20 +00:00
|
|
|
// CADSTAR v6 (which outputted Format Version 8) and earlier versions used 1/10 degree
|
|
|
|
// as the unit for angles/orientations. It is assumed that CADSTAR version 7 (i.e. Format
|
|
|
|
// Version 9 and later) is the version that introduced 1/1000 degree for angles.
|
2021-01-31 20:47:36 +00:00
|
|
|
if( Header.Format.Version > 8 )
|
2020-11-19 15:25:20 +00:00
|
|
|
{
|
|
|
|
return (double) aCadstarAngle / 100.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (double) aCadstarAngle;
|
|
|
|
}
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarAngle
|
|
|
|
* @return
|
2020-08-31 22:09:29 +00:00
|
|
|
*/
|
|
|
|
double getAngleDegrees( const long long& aCadstarAngle )
|
|
|
|
{
|
2020-11-19 15:25:20 +00:00
|
|
|
return getAngleTenthDegree( aCadstarAngle ) / 10.0;
|
2020-08-31 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aPoint
|
2020-08-16 17:12:08 +00:00
|
|
|
* @return Angle in decidegrees of the polar representation of the point, scaled 0..360
|
|
|
|
*/
|
|
|
|
double getPolarAngle( wxPoint aPoint );
|
|
|
|
|
2020-08-31 22:09:29 +00:00
|
|
|
/**
|
2021-02-13 20:00:17 +00:00
|
|
|
* @brief Searches m_netMap and returns the NETINFO_ITEM pointer if exists. Otherwise
|
|
|
|
* creates a new one and adds it to m_board.
|
2020-10-09 16:58:21 +00:00
|
|
|
* @param aCadstarNetID
|
|
|
|
* @return
|
2020-08-31 22:09:29 +00:00
|
|
|
*/
|
|
|
|
NETINFO_ITEM* getKiCadNet( const NET_ID& aCadstarNetID );
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
2020-08-16 17:12:08 +00:00
|
|
|
* @param aLayerNum Physical / logical layer number (starts at 1)
|
2020-12-28 02:21:37 +00:00
|
|
|
* @param aDetectMaxLayer If true, returns B.Cu if the requested layer is the maximum layer
|
2020-08-16 17:12:08 +00:00
|
|
|
* @return PCB_LAYER_ID
|
|
|
|
*/
|
2020-12-28 02:21:37 +00:00
|
|
|
PCB_LAYER_ID getKiCadCopperLayerID( unsigned int aLayerNum, bool aDetectMaxLayer = true );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
2020-08-23 10:34:27 +00:00
|
|
|
* @return true if the layer corresponds to a KiCad LSET or false if the layer maps directly
|
2020-08-28 20:32:53 +00:00
|
|
|
*/
|
2020-08-23 10:34:27 +00:00
|
|
|
bool isLayerSet( const LAYER_ID& aCadstarLayerID );
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
2020-08-16 17:12:08 +00:00
|
|
|
* @return PCB_LAYER_ID
|
|
|
|
*/
|
|
|
|
PCB_LAYER_ID getKiCadLayer( const LAYER_ID& aCadstarLayerID );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-09 16:58:21 +00:00
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
2020-08-23 10:34:27 +00:00
|
|
|
* @return LSET
|
|
|
|
*/
|
|
|
|
LSET getKiCadLayerSet( const LAYER_ID& aCadstarLayerID );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool isFootprint( BOARD_ITEM_CONTAINER* aContainer )
|
2020-08-28 20:32:53 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
return aContainer && aContainer->Type() == PCB_FOOTPRINT_T;
|
2020-08-28 20:32:53 +00:00
|
|
|
}
|
2020-09-06 21:20:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
void addToGroup( const GROUP_ID& aCadstarGroupID, BOARD_ITEM* aKiCadItem );
|
|
|
|
|
|
|
|
/**
|
2021-02-13 20:00:17 +00:00
|
|
|
* @brief Adds a new PCB_GROUP* to m_groupMap
|
2020-09-06 21:20:32 +00:00
|
|
|
* @param aName Name to give the group. If name already exists, append "_1", "_2", etc.
|
|
|
|
* to the end to ensure it is unique
|
2020-10-09 16:58:21 +00:00
|
|
|
* @return
|
2020-09-06 21:20:32 +00:00
|
|
|
*/
|
|
|
|
GROUP_ID createUniqueGroupID( const wxString& aName );
|
2020-07-12 16:58:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-29 18:09:48 +00:00
|
|
|
#endif // CADSTAR_PCB_ARCHIVE_LOADER_H_
|