CADSTAR Schematic Archive Importer: Load Documentation Symbols

This commit is contained in:
Roberto Fernandez Bautista 2020-09-27 13:19:51 +01:00
parent c6bc72d579
commit 5e2e692ad8
2 changed files with 164 additions and 31 deletions

View File

@ -86,6 +86,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo
loadNets(); loadNets();
loadFigures(); loadFigures();
loadTexts(); loadTexts();
loadDocumentationSymbols();
// TODO Load other elements! // TODO Load other elements!
// For all sheets, centre all elements and re calculate the page size: // For all sheets, centre all elements and re calculate the page size:
@ -657,6 +658,66 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadTexts()
} }
void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols()
{
for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docSymPair :
Schematic.DocumentationSymbols )
{
DOCUMENTATION_SYMBOL docSym = docSymPair.second;
if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() )
{
wxLogError(
wxString::Format( _( "Documentation Symbol '%s' refers to symbol definition "
"ID '%s' which does not exist in the library. The symbol "
"was not loaded." ),
docSym.ID, docSym.SymdefID ) );
continue;
}
SYMDEF_SCM docSymDef = Library.SymbolDefinitions.at( docSym.SymdefID );
wxPoint moveVector = getKiCadPoint( docSym.Origin ) - getKiCadPoint( docSymDef.Origin );
double rotationAngle = getAngleTenthDegree( docSym.OrientAngle );
double scalingFactor =
(double) docSym.ScaleRatioNumerator / (double) docSym.ScaleRatioDenominator;
wxPoint centreOfTransform = getKiCadPoint( docSymDef.Origin );
bool mirrorInvert = docSym.Mirror;
for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDef.Figures )
{
FIGURE fig = figPair.second;
loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor,
centreOfTransform, mirrorInvert );
}
for( std::pair<TEXT_ID, TEXT> textPair : docSymDef.Texts )
{
TEXT txt = textPair.second;
SCH_TEXT* kiTxt = getKiCadSchText( txt );
wxPoint newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
scalingFactor, centreOfTransform, mirrorInvert );
double newTxtAngle = NormalizeAnglePos( kiTxt->GetTextAngle() + rotationAngle );
bool newMirrorStatus = kiTxt->IsMirrored() ? !mirrorInvert : mirrorInvert;
int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
kiTxt->SetPosition( newPosition );
kiTxt->SetTextAngle( newTxtAngle );
kiTxt->SetMirrored( newMirrorStatus );
kiTxt->SetTextWidth( newTxtWidth );
kiTxt->SetTextHeight( newTxtHeight );
kiTxt->SetTextThickness( newTxtThickness );
loadItemOntoKiCadSheet( docSym.LayerID, kiTxt );
}
}
}
void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID,
const PART* aCadstarPart, const GATE_ID& aGateID, LIB_PART* aPart ) const PART* aCadstarPart, const GATE_ID& aGateID, LIB_PART* aPart )
{ {
@ -1073,7 +1134,9 @@ wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName( const NET_SCH& aNet )
void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices, void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID ) LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
{ {
const VERTEX* prev = &aCadstarVertices.at( 0 ); const VERTEX* prev = &aCadstarVertices.at( 0 );
const VERTEX* cur; const VERTEX* cur;
@ -1089,11 +1152,18 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
wxPoint startPoint = getKiCadPoint( prev->End ); wxPoint startPoint = getKiCadPoint( prev->End );
wxPoint endPoint = getKiCadPoint( cur->End ); wxPoint endPoint = getKiCadPoint( cur->End );
segment->SetLayer( aKiCadSchLayerID );
segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) );
segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
//Apply transforms
startPoint = applyTransform( startPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
aTransformCentre, aMirrorInvert );
endPoint = applyTransform( endPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
aTransformCentre, aMirrorInvert );
segment->SetStartPoint( startPoint ); segment->SetStartPoint( startPoint );
segment->SetEndPoint( endPoint ); segment->SetEndPoint( endPoint );
segment->SetLayer( aKiCadSchLayerID );
segment->SetLineWidth( getLineThickness( aCadstarLineCodeID ) );
segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
prev = cur; prev = cur;
@ -1103,15 +1173,19 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure, void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure,
const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID ) const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID,
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
{ {
loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID, loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
aCadstarFigure.LayerID, aKiCadSchLayerID ); aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg,
aScalingFactor, aTransformCentre, aMirrorInvert );
for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts ) for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
{ {
loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarFigure.LayerID, loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride,
aKiCadSchLayerID ); aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
aTransformCentre, aMirrorInvert );
} }
} }
@ -1612,6 +1686,41 @@ wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint(
} }
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::applyTransform( const wxPoint& aPoint,
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
{
wxPoint retVal = aPoint;
if( aScalingFactor != 1.0 )
{
//scale point
retVal -= aTransformCentre;
retVal.x = KiROUND( retVal.x * aScalingFactor );
retVal.y = KiROUND( retVal.y * aScalingFactor );
retVal += aTransformCentre;
}
if( aMirrorInvert )
{
MIRROR( retVal.x, aTransformCentre.x );
MIRROR( retVal.x, aTransformCentre.x );
}
if( aRotationAngleDeciDeg != 0.0 )
{
RotatePoint( &retVal, aTransformCentre, aRotationAngleDeciDeg );
}
if( aMoveVector != wxPoint{ 0, 0 } )
{
retVal += aMoveVector;
}
return retVal;
}
double CADSTAR_SCH_ARCHIVE_LOADER::getPolarAngle( wxPoint aPoint ) double CADSTAR_SCH_ARCHIVE_LOADER::getPolarAngle( wxPoint aPoint )
{ {
return NormalizeAnglePos( ArcTangente( aPoint.y, aPoint.x ) ); return NormalizeAnglePos( ArcTangente( aPoint.y, aPoint.x ) );

View File

@ -103,53 +103,77 @@ private:
void loadNets(); void loadNets();
void loadFigures(); void loadFigures();
void loadTexts(); void loadTexts();
void loadDocumentationSymbols();
//Helper Functions for loading sheets //Helper Functions for loading sheets
void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize, void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize,
SCH_SHEET* aParentSheet ); SCH_SHEET* aParentSheet );
void loadChildSheets( LAYER_ID aCadstarSheetID ); void loadChildSheets( LAYER_ID aCadstarSheetID );
std::vector<LAYER_ID> findOrphanSheets(); std::vector<LAYER_ID> findOrphanSheets();
int getSheetNumber( LAYER_ID aCadstarSheetID );
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem ); int getSheetNumber( LAYER_ID aCadstarSheetID );
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem );
//Helper Functions for loading library items //Helper Functions for loading library items
void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart, void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart,
const GATE_ID& aGateID, LIB_PART* aPart ); const GATE_ID& aGateID, LIB_PART* aPart );
void loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices, void loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
wxPoint aSymbolOrigin, LIB_PART* aPart, int aGateNumber ); wxPoint aSymbolOrigin, LIB_PART* aPart, int aGateNumber );
void loadLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc, void loadLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField ); wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField );
//Helper Functions for loading symbols in schematic //Helper Functions for loading symbols in schematic
SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart, SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart,
double& aComponentOrientationDeciDeg ); double& aComponentOrientationDeciDeg );
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
const double& aComponentOrientationDeciDeg, SCH_FIELD* aKiCadField ); void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
int getComponentOrientation( const double& aComponentOrientationDeciDeg, SCH_FIELD* aKiCadField );
long long aCadstarOrientAngle, double& aReturnedOrientationDeciDeg );
int getComponentOrientation(
long long aCadstarOrientAngle, double& aReturnedOrientationDeciDeg );
//Helper functions for loading nets //Helper functions for loading nets
POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID ); POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID );
wxString getNetName( const NET_SCH& aNet ); wxString getNetName( const NET_SCH& aNet );
//Helper functions for loading figures / graphical items //Helper functions for loading figures / graphical items
void loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices, void loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
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 );
void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride, void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride,
SCH_LAYER_ID aKiCadSchLayerID ); 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 );
//Helper Functions for obtaining CADSTAR elements from the parsed structures //Helper Functions for obtaining CADSTAR elements from the parsed structures
SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate ); SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate );
wxString generateSymDefName( const SYMDEF_ID& aSymdefID );
int getLineThickness( const LINECODE_ID& aCadstarLineCodeID ); wxString generateSymDefName( const SYMDEF_ID& aSymdefID );
PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID ); int getLineThickness( const LINECODE_ID& aCadstarLineCodeID );
PART getPart( const PART_ID& aCadstarPartID ); PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID );
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID ); PART getPart( const PART_ID& aCadstarPartID );
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID ); ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID ); TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID, wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap ); wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
PART::DEFINITION::PIN getPartDefinitionPin( PART::DEFINITION::PIN getPartDefinitionPin(
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID ); const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID );
@ -158,11 +182,8 @@ private:
LABEL_SPIN_STYLE getSpinStyle( const long long& aCadstarOrientation, bool aMirror ); LABEL_SPIN_STYLE getSpinStyle( const long long& aCadstarOrientation, bool aMirror );
LABEL_SPIN_STYLE getSpinStyleDeciDeg( const double& aOrientationDeciDeg ); LABEL_SPIN_STYLE getSpinStyleDeciDeg( const double& aOrientationDeciDeg );
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
EDA_TEXT* aKiCadTextItem );
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
// General Graphical manipulation functions
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure ); std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
@ -170,6 +191,9 @@ private:
wxPoint getKiCadLibraryPoint( wxPoint aCadstarPoint, wxPoint aCadstarCentre ); wxPoint getKiCadLibraryPoint( wxPoint aCadstarPoint, wxPoint aCadstarCentre );
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 );
int getKiCadLength( long long aCadstarLength ) int getKiCadLength( long long aCadstarLength )
{ {