2020-09-08 19:51:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
|
|
|
* 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_sch_archive_loader.h
|
|
|
|
* @brief Loads a csa file into a KiCad SCHEMATIC object
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CADSTAR_SCH_ARCHIVE_LOADER_H_
|
|
|
|
#define CADSTAR_SCH_ARCHIVE_LOADER_H_
|
|
|
|
|
|
|
|
#include <sch_plugins/cadstar/cadstar_sch_archive_parser.h>
|
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h> // SCH_LAYER_ID
|
|
|
|
#include <plotter.h> // PLOT_DASH_TYPE
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <sch_io_mgr.h>
|
|
|
|
|
|
|
|
class EDA_TEXT;
|
|
|
|
class LABEL_SPIN_STYLE;
|
|
|
|
class LIB_FIELD;
|
|
|
|
class LIB_PART;
|
|
|
|
class SCH_COMPONENT;
|
2020-09-27 02:35:24 +00:00
|
|
|
class SCH_ITEM;
|
2020-09-20 21:08:46 +00:00
|
|
|
class SCH_FIELD;
|
2020-09-23 20:39:11 +00:00
|
|
|
class SCH_GLOBALLABEL;
|
|
|
|
class SCH_HIERLABEL;
|
|
|
|
class SCH_SHEET;
|
2020-09-27 02:35:24 +00:00
|
|
|
class SCH_TEXT;
|
2020-09-20 21:08:46 +00:00
|
|
|
class SCHEMATIC;
|
2020-09-08 19:51:22 +00:00
|
|
|
|
|
|
|
class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename )
|
|
|
|
: CADSTAR_SCH_ARCHIVE_PARSER( aFilename )
|
|
|
|
{
|
2020-09-19 22:05:02 +00:00
|
|
|
mSchematic = nullptr;
|
|
|
|
mRootSheet = nullptr;
|
2020-09-20 21:08:46 +00:00
|
|
|
mPlugin = nullptr;
|
2020-09-19 22:05:02 +00:00
|
|
|
mDesignCenter.x = 0;
|
|
|
|
mDesignCenter.y = 0;
|
2020-09-08 19:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~CADSTAR_SCH_ARCHIVE_LOADER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Loads a CADSTAR PCB Archive file into the KiCad BOARD object given
|
2020-09-19 22:05:02 +00:00
|
|
|
* @param aSchematic Schematic to add the design onto
|
|
|
|
* @param aRootSheet Root sheet to add the design onto
|
2020-09-08 19:51:22 +00:00
|
|
|
*/
|
2020-09-20 21:08:46 +00:00
|
|
|
void Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRootSheet,
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER* aSchPlugin, wxFileName aLibraryFileName );
|
2020-09-08 19:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
2020-09-23 20:39:11 +00:00
|
|
|
typedef std::pair<BLOCK_ID, TERMINAL_ID> BLOCK_PIN_ID;
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
::SCHEMATIC* mSchematic;
|
|
|
|
::SCH_SHEET* mRootSheet;
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER* mPlugin;
|
|
|
|
wxFileName mLibraryFileName;
|
|
|
|
wxPoint mDesignCenter; ///< Used for calculating the required
|
|
|
|
///< offset to apply to the Cadstar design
|
|
|
|
///< so that it fits in KiCad canvas
|
|
|
|
std::set<HATCHCODE_ID> mHatchcodesTested; ///< Used by checkAndLogHatchCode() to
|
|
|
|
///< avoid multiple duplicate warnings
|
|
|
|
std::map<LAYER_ID, SCH_SHEET*> mSheetMap; ///< Map between Cadstar and KiCad Sheets
|
2020-09-23 20:39:11 +00:00
|
|
|
std::map<BLOCK_PIN_ID, SCH_HIERLABEL*>
|
|
|
|
mSheetPinMap; ///< Map between Cadstar and KiCad Sheets Pins
|
|
|
|
std::map<PART_ID, LIB_PART*> mPartMap; ///< Map between Cadstar and KiCad Parts
|
|
|
|
std::map<SYMDEF_ID, LIB_PART*>
|
|
|
|
mPowerSymLibMap; ///< Map between Cadstar and KiCad Power Symbol Library items
|
|
|
|
std::map<SYMBOL_ID, SCH_COMPONENT*>
|
|
|
|
mPowerSymMap; ///< Map between Cadstar and KiCad Power Symbols
|
|
|
|
std::map<SYMBOL_ID, SCH_GLOBALLABEL*>
|
|
|
|
mGlobLabelMap; ///< Map between Cadstar and KiCad Global Labels
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
void loadSheets();
|
2020-09-23 20:39:11 +00:00
|
|
|
void loadHierarchicalSheetPins();
|
2020-09-20 21:08:46 +00:00
|
|
|
void loadPartsLibrary();
|
|
|
|
void loadSchematicSymbolInstances();
|
2020-09-26 13:27:03 +00:00
|
|
|
void loadBusses();
|
2020-09-23 20:39:11 +00:00
|
|
|
void loadNets();
|
2020-09-26 18:23:13 +00:00
|
|
|
void loadFigures();
|
2020-09-27 02:35:24 +00:00
|
|
|
void loadTexts();
|
2020-09-27 12:19:51 +00:00
|
|
|
void loadDocumentationSymbols();
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
//Helper Functions for loading sheets
|
2020-09-19 22:05:02 +00:00
|
|
|
void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize,
|
|
|
|
SCH_SHEET* aParentSheet );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
void loadChildSheets( LAYER_ID aCadstarSheetID );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
std::vector<LAYER_ID> findOrphanSheets();
|
2020-09-27 12:19:51 +00:00
|
|
|
|
|
|
|
int getSheetNumber( LAYER_ID aCadstarSheetID );
|
|
|
|
|
|
|
|
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
//Helper Functions for loading library items
|
|
|
|
void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart,
|
|
|
|
const GATE_ID& aGateID, LIB_PART* aPart );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
void loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
|
|
|
wxPoint aSymbolOrigin, LIB_PART* aPart, int aGateNumber );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
void loadLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
|
|
|
wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField );
|
|
|
|
|
|
|
|
//Helper Functions for loading symbols in schematic
|
2020-09-20 21:08:46 +00:00
|
|
|
SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart,
|
|
|
|
double& aComponentOrientationDeciDeg );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
|
|
|
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
|
|
|
const double& aComponentOrientationDeciDeg, SCH_FIELD* aKiCadField );
|
|
|
|
|
|
|
|
int getComponentOrientation(
|
|
|
|
long long aCadstarOrientAngle, double& aReturnedOrientationDeciDeg );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
//Helper functions for loading nets
|
2020-09-27 12:19:51 +00:00
|
|
|
POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID );
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
wxString getNetName( const NET_SCH& aNet );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
//Helper functions for loading figures / graphical items
|
|
|
|
void loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
2020-09-27 12:19:51 +00:00
|
|
|
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
|
|
|
|
const wxPoint& aMoveVector = { 0, 0 }, const double& aRotationAngleDeciDeg = 0.0,
|
|
|
|
const double& aScalingFactor = 1.0, const wxPoint& aTransformCentre = { 0, 0 },
|
|
|
|
const bool& aMirrorInvert = false );
|
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride,
|
2020-09-27 12:19:51 +00:00
|
|
|
SCH_LAYER_ID aKiCadSchLayerID, const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngleDeciDeg = 0.0, const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
|
|
|
|
|
|
|
//Helper functions for loading text elements
|
|
|
|
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
|
|
|
|
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
|
|
|
|
EDA_TEXT* aKiCadTextItem );
|
|
|
|
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
|
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
//Helper Functions for obtaining CADSTAR elements from the parsed structures
|
2020-09-20 21:08:46 +00:00
|
|
|
SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
|
|
|
wxString generateSymDefName( const SYMDEF_ID& aSymdefID );
|
|
|
|
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
|
|
|
|
PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID );
|
|
|
|
PART getPart( const PART_ID& aCadstarPartID );
|
|
|
|
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
|
|
|
|
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
|
|
|
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
|
|
|
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
|
|
|
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
PART::DEFINITION::PIN getPartDefinitionPin(
|
|
|
|
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
//Helper Functions for obtaining individual elements as KiCad elements:
|
2020-09-20 21:08:46 +00:00
|
|
|
int getKiCadUnitNumberFromGate( const GATE_ID& aCadstarGateID );
|
|
|
|
LABEL_SPIN_STYLE getSpinStyle( const long long& aCadstarOrientation, bool aMirror );
|
2020-09-26 13:27:03 +00:00
|
|
|
LABEL_SPIN_STYLE getSpinStyleDeciDeg( const double& aOrientationDeciDeg );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
//General Graphical manipulation functions
|
2020-09-19 22:05:02 +00:00
|
|
|
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
|
|
|
|
|
|
|
|
wxPoint getKiCadPoint( wxPoint aCadstarPoint );
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
wxPoint getKiCadLibraryPoint( wxPoint aCadstarPoint, wxPoint aCadstarCentre );
|
|
|
|
|
2020-09-27 12:19:51 +00:00
|
|
|
wxPoint applyTransform( const wxPoint& aPoint, const wxPoint& aMoveVector = { 0, 0 },
|
|
|
|
const double& aRotationAngleDeciDeg = 0.0, const double& aScalingFactor = 1.0,
|
|
|
|
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
int getKiCadLength( long long aCadstarLength )
|
|
|
|
{
|
|
|
|
return aCadstarLength * KiCadUnitMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarAngle
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
double getAngleTenthDegree( const long long& aCadstarAngle )
|
|
|
|
{
|
|
|
|
return (double) aCadstarAngle / 100.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aCadstarAngle
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
double getAngleDegrees( const long long& aCadstarAngle )
|
|
|
|
{
|
|
|
|
return (double) aCadstarAngle / 1000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aPoint
|
|
|
|
* @return Angle in decidegrees of the polar representation of the point, scaled 0..360
|
|
|
|
*/
|
|
|
|
double getPolarAngle( wxPoint aPoint );
|
2020-09-08 19:51:22 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param aPoint
|
|
|
|
* @return Radius of polar representation of the point
|
|
|
|
*/
|
|
|
|
double getPolarRadius( wxPoint aPoint );
|
|
|
|
|
2020-09-08 19:51:22 +00:00
|
|
|
}; // CADSTAR_SCH_ARCHIVE_LOADER
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CADSTAR_SCH_ARCHIVE_LOADER_H_
|