2020-07-12 16:58:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Roberto Fernandez Bautista <@Qbort>
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file cadstar_pcb.h
|
2020-07-30 22:42:56 +00:00
|
|
|
* @brief Converts a CADSTAR_PCB_ARCHIVE_PARSER object into a KiCad BOARD object
|
2020-07-12 16:58:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CADSTAR_PCB_H_
|
|
|
|
#define CADSTAR_PCB_H_
|
|
|
|
|
|
|
|
#include <cadstar_pcb_archive_parser.h>
|
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
|
2020-07-30 22:42:56 +00:00
|
|
|
class CADSTAR_PCB : public CADSTAR_PCB_ARCHIVE_PARSER
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-07-30 22:42:56 +00:00
|
|
|
explicit CADSTAR_PCB( wxString aFilename ) : CADSTAR_PCB_ARCHIVE_PARSER( aFilename )
|
2020-07-12 16:58:35 +00:00
|
|
|
{
|
2020-08-28 20:32:53 +00:00
|
|
|
mBoard = nullptr;
|
2020-08-16 17:12:08 +00:00
|
|
|
mDesignCenter.x = 0;
|
|
|
|
mDesignCenter.y = 0;
|
2020-07-12 16:58:35 +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
|
|
|
|
* @param aBoard
|
2020-07-12 16:58:35 +00:00
|
|
|
*/
|
2020-08-09 22:01:28 +00:00
|
|
|
void Load( ::BOARD* aBoard );
|
2020-07-12 16:58:35 +00:00
|
|
|
|
|
|
|
private:
|
2020-08-28 20:32:53 +00:00
|
|
|
::BOARD* mBoard;
|
|
|
|
std::map<LAYER_ID, PCB_LAYER_ID> mLayermap; ///< Map between Cadstar and KiCad Layers.
|
|
|
|
///< Populated by loadBoardStackup().
|
|
|
|
std::map<SYMDEF_ID, MODULE*> mLibraryMap; ///< Map between Cadstar and KiCad
|
|
|
|
///< components in the library. Populated
|
|
|
|
///< by loadComponentLibrary().
|
|
|
|
std::map<PHYSICAL_LAYER_ID, LAYER_ID> mCopperLayers; ///< Map of CADSTAR Physical layers to
|
|
|
|
///< CADSTAR Layer IDs
|
|
|
|
wxPoint mDesignCenter; ///< Used for calculating the required
|
|
|
|
///< offset to apply to the Cadstar design
|
|
|
|
///< so that it fits in KiCad canvas
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
// Functions for loading individual elements:
|
|
|
|
void loadBoardStackup();
|
2020-08-28 20:32:53 +00:00
|
|
|
void loadComponentLibrary();
|
|
|
|
// clang-format off
|
|
|
|
// Helper functions for Component Library loading:
|
|
|
|
void loadLibraryFigures(const SYMDEF& aComponent, MODULE* aModule);
|
|
|
|
void loadLibraryPads(const SYMDEF& aComponent, MODULE* aModule);
|
|
|
|
// clang-format on
|
2020-08-16 17:12:08 +00:00
|
|
|
void loadBoards();
|
2020-08-23 10:34:27 +00:00
|
|
|
void loadFigures();
|
|
|
|
void loadAreas();
|
2020-08-28 20:32:53 +00:00
|
|
|
void loadComponents();
|
|
|
|
// clang-format off
|
|
|
|
// Helper functions for Component loading:
|
|
|
|
void loadComponentAttributes( const COMPONENT& aComponent, MODULE* aModule );
|
|
|
|
// clang-format on
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarShape
|
|
|
|
* @param aCadstarLayerID KiCad layer to draw on
|
|
|
|
* @param aCadstarLinecodeID Thickness of line to draw with
|
2020-08-23 10:34:27 +00:00
|
|
|
* @param aShapeName for reporting warnings/errors to the user
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aContainer to draw on (e.g. mBoard)
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarShape( const SHAPE& aCadstarShape, const PCB_LAYER_ID& aKiCadLayer,
|
2020-08-28 20:32:53 +00:00
|
|
|
const LINECODE_ID& aCadstarLinecodeID, const wxString& aShapeName,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Uses DRAWSEGMENT to draw the cutouts on mBoard object
|
|
|
|
* @param aVertices
|
|
|
|
* @param aKiCadLayer KiCad layer to draw on
|
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aContainer to draw on (e.g. mBoard)
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarCutoutsAsSegments( const std::vector<CUTOUT>& aCutouts,
|
2020-08-28 20:32:53 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Uses DRAWSEGMENT to draw the vertices on mBoard object
|
|
|
|
* @param aCadstarVertices
|
|
|
|
* @param aKiCadLayer KiCad layer to draw on
|
|
|
|
* @param aLineThickness Thickness of line to draw with
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aContainer to draw on (e.g. mBoard)
|
2020-08-16 17:12:08 +00:00
|
|
|
*/
|
|
|
|
void drawCadstarVerticesAsSegments( const std::vector<VERTEX>& aCadstarVertices,
|
2020-08-28 20:32:53 +00:00
|
|
|
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
|
|
|
|
BOARD_ITEM_CONTAINER* aContainer );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-23 10:34:27 +00:00
|
|
|
* @brief Returns a vector of pointers to DRAWSEGMENT objects. Caller owns the objects.
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aCadstarVertices *
|
|
|
|
* @param aContainer to draw on (e.g. mBoard). Can be nullptr.
|
2020-08-16 17:12:08 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2020-08-28 20:32:53 +00:00
|
|
|
std::vector<DRAWSEGMENT*> getDrawSegmentsFromVertices(
|
|
|
|
const std::vector<VERTEX>& aCadstarVertices, BOARD_ITEM_CONTAINER* aContainer = nullptr );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarShape
|
|
|
|
* @param aLineThickness Thickness of line to draw with
|
|
|
|
* @return Pointer to ZONE_CONTAINER. Caller owns the object.
|
|
|
|
*/
|
|
|
|
ZONE_CONTAINER* getZoneFromCadstarShape(
|
|
|
|
const SHAPE& aCadstarShape, const int& aLineThickness );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
2020-08-28 20:32:53 +00:00
|
|
|
* @param aContainer to draw on (e.g. mBoard). Can be nullptr.
|
2020-08-23 10:34:27 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2020-08-28 20:32:53 +00:00
|
|
|
SHAPE_POLY_SET getPolySetFromCadstarShape( const SHAPE& aCadstarShape,
|
|
|
|
const int& aLineThickness = -1, BOARD_ITEM_CONTAINER* aContainer = nullptr );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns a SHAPE_LINE_CHAIN object from a series of DRAWSEGMENT objects
|
|
|
|
* @param aDrawSegments
|
|
|
|
* @return
|
|
|
|
*/
|
2020-08-28 20:32:53 +00:00
|
|
|
SHAPE_LINE_CHAIN getLineChainFromDrawsegments( const std::vector<DRAWSEGMENT*> aDrawSegments );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Adds a CADSTAR Attribute to a KiCad module
|
|
|
|
* @param aCadstarAttrLoc
|
|
|
|
* @param aCadstarAttributeID
|
|
|
|
* @param aModule
|
|
|
|
* @param aAttributeValue
|
|
|
|
*/
|
|
|
|
void addAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
|
|
|
const ATTRIBUTE_ID& aCadstarAttributeID, MODULE* aModule,
|
|
|
|
const wxString& aAttributeValue );
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief If the LineCode ID is found, returns the thickness as defined in the Linecode,
|
|
|
|
* otherwise returns the default line thickness in Edge_Cuts KiCad layer
|
|
|
|
* @param aCadstarLineCodeID
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
|
|
|
|
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
|
|
|
|
|
|
|
|
|
|
|
PADCODE getPadCode( const PADCODE_ID& aCadstarPadCodeID );
|
|
|
|
|
|
|
|
|
|
|
|
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
|
|
|
|
|
|
|
|
|
|
|
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
|
|
|
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
|
|
|
|
|
|
|
PART getPart( const PART_ID& aCadstarPartID );
|
|
|
|
|
2020-08-16 17:12:08 +00:00
|
|
|
/**
|
|
|
|
* @brief Scales, offsets and inverts y axis to make the point usable directly in KiCad
|
|
|
|
* @param aCadstarPoint
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
wxPoint getKiCadPoint( wxPoint aCadstarPoint );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarLength
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
int getKiCadLength( long long aCadstarLength )
|
|
|
|
{
|
|
|
|
return aCadstarLength * KiCadUnitMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarAngle
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
double getKiCadAngle( const long long& aCadstarAngle )
|
|
|
|
{
|
|
|
|
return (double) aCadstarAngle / 100.0;
|
|
|
|
}
|
2020-08-16 17:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aPoint
|
|
|
|
* @return Angle in decidegrees of the polar representation of the point, scaled 0..360
|
|
|
|
*/
|
|
|
|
double getPolarAngle( wxPoint aPoint );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aLayerNum Physical / logical layer number (starts at 1)
|
|
|
|
* @return PCB_LAYER_ID
|
|
|
|
*/
|
|
|
|
PCB_LAYER_ID getKiCadCopperLayerID( unsigned int aLayerNum );
|
|
|
|
|
|
|
|
|
2020-08-23 10:34:27 +00:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
|
|
|
* @return PCB_LAYER_ID
|
|
|
|
*/
|
|
|
|
PCB_LAYER_ID getKiCadLayer( const LAYER_ID& aCadstarLayerID );
|
2020-08-23 10:34:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarLayerID
|
|
|
|
* @return LSET
|
|
|
|
*/
|
|
|
|
LSET getKiCadLayerSet( const LAYER_ID& aCadstarLayerID );
|
|
|
|
|
2020-08-28 20:32:53 +00:00
|
|
|
|
|
|
|
bool isModule( BOARD_ITEM_CONTAINER* aContainer )
|
|
|
|
{
|
|
|
|
return aContainer && aContainer->GetClass() == wxT( "MODULE" );
|
|
|
|
}
|
2020-07-12 16:58:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CADSTAR_PCB_H_
|