CADSTAR Archive Importer: Fix position of multiline text with NO_ALIGNMENT in CADSTAR
This commit is contained in:
parent
a33ccf48b9
commit
b168b74919
|
@ -24,6 +24,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <plugins/cadstar/cadstar_archive_parser.h>
|
#include <plugins/cadstar/cadstar_archive_parser.h>
|
||||||
|
#include <eda_text.h>
|
||||||
|
#include <trigo.h>
|
||||||
|
|
||||||
// Ratio derived from CADSTAR default font. See doxygen comment in cadstar_archive_parser.h
|
// Ratio derived from CADSTAR default font. See doxygen comment in cadstar_archive_parser.h
|
||||||
const double CADSTAR_ARCHIVE_PARSER::TXT_HEIGHT_RATIO = ( 24.0 - 5.0 ) / 24.0;
|
const double CADSTAR_ARCHIVE_PARSER::TXT_HEIGHT_RATIO = ( 24.0 - 5.0 ) / 24.0;
|
||||||
|
@ -2416,3 +2418,24 @@ std::vector<CADSTAR_ARCHIVE_PARSER::CUTOUT> CADSTAR_ARCHIVE_PARSER::ParseAllChil
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem )
|
||||||
|
{
|
||||||
|
if( !aKiCadTextItem->GetText().IsEmpty() )
|
||||||
|
{
|
||||||
|
//No exact KiCad equivalent, so lets move the position of the text
|
||||||
|
int txtAngleDecideg = aKiCadTextItem->GetTextAngleDegrees() * 10.0;
|
||||||
|
wxPoint positionOffset( 0, aKiCadTextItem->GetInterline() );
|
||||||
|
RotatePoint( &positionOffset, txtAngleDecideg );
|
||||||
|
|
||||||
|
//Count num of additional lines
|
||||||
|
wxString text = aKiCadTextItem->GetText();
|
||||||
|
int numExtraLines = text.Replace( "\n", "\n" );
|
||||||
|
numExtraLines -= text.at( text.size() - 1 ) == '\n'; // Ignore new line character at end
|
||||||
|
positionOffset.x *= numExtraLines;
|
||||||
|
positionOffset.y *= numExtraLines;
|
||||||
|
|
||||||
|
aKiCadTextItem->Offset( positionOffset );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
|
#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
|
||||||
#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
|
#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
|
||||||
|
|
||||||
|
class EDA_TEXT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper functions and common structures for CADSTAR PCB and Schematic archive files.
|
* @brief Helper functions and common structures for CADSTAR PCB and Schematic archive files.
|
||||||
|
@ -1324,6 +1325,14 @@ public:
|
||||||
*/
|
*/
|
||||||
static std::vector<CUTOUT> ParseAllChildCutouts(
|
static std::vector<CUTOUT> ParseAllChildCutouts(
|
||||||
XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
|
XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR. Assumes that the
|
||||||
|
* provided text element has been initialised with a position and orientation.
|
||||||
|
* @param aKiCadTextItem a Kicad item to correct
|
||||||
|
*/
|
||||||
|
static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
|
||||||
|
|
||||||
}; // class CADSTAR_ARCHIVE_PARSER
|
}; // class CADSTAR_ARCHIVE_PARSER
|
||||||
|
|
||||||
#endif // CADSTAR_ARCHIVE_PARSER_H_
|
#endif // CADSTAR_ARCHIVE_PARSER_H_
|
||||||
|
|
|
@ -627,12 +627,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
|
||||||
if( busTerm.HasNetLabel )
|
if( busTerm.HasNetLabel )
|
||||||
{
|
{
|
||||||
SCH_LABEL* label = new SCH_LABEL();
|
SCH_LABEL* label = new SCH_LABEL();
|
||||||
applyTextSettings( busTerm.NetLabel.TextCodeID, busTerm.NetLabel.Alignment,
|
|
||||||
busTerm.NetLabel.Justification, label );
|
|
||||||
|
|
||||||
label->SetText( netName );
|
label->SetText( netName );
|
||||||
label->SetPosition( getKiCadPoint( busTerm.SecondPoint ) );
|
label->SetPosition( getKiCadPoint( busTerm.SecondPoint ) );
|
||||||
label->SetVisible( true );
|
label->SetVisible( true );
|
||||||
|
|
||||||
|
applyTextSettings( busTerm.NetLabel.TextCodeID, busTerm.NetLabel.Alignment,
|
||||||
|
busTerm.NetLabel.Justification, label );
|
||||||
|
|
||||||
netlabels.insert( { busTerm.ID, label } );
|
netlabels.insert( { busTerm.ID, label } );
|
||||||
|
|
||||||
mSheetMap.at( bus.LayerID )->GetScreen()->Append( label );
|
mSheetMap.at( bus.LayerID )->GetScreen()->Append( label );
|
||||||
|
@ -1642,11 +1643,11 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets(
|
||||||
|
|
||||||
SCH_FIELD blockNameField( getKiCadPoint( block.BlockLabel.Position ), 2,
|
SCH_FIELD blockNameField( getKiCadPoint( block.BlockLabel.Position ), 2,
|
||||||
loadedSheet, wxString( "Block name" ) );
|
loadedSheet, wxString( "Block name" ) );
|
||||||
applyTextSettings( block.BlockLabel.TextCodeID, block.BlockLabel.Alignment,
|
|
||||||
block.BlockLabel.Justification, &blockNameField );
|
|
||||||
blockNameField.SetTextAngle( getAngleTenthDegree( block.BlockLabel.OrientAngle ) );
|
blockNameField.SetTextAngle( getAngleTenthDegree( block.BlockLabel.OrientAngle ) );
|
||||||
blockNameField.SetText( block.Name );
|
blockNameField.SetText( block.Name );
|
||||||
blockNameField.SetVisible( true );
|
blockNameField.SetVisible( true );
|
||||||
|
applyTextSettings( block.BlockLabel.TextCodeID, block.BlockLabel.Alignment,
|
||||||
|
block.BlockLabel.Justification, &blockNameField );
|
||||||
fields.push_back( blockNameField );
|
fields.push_back( blockNameField );
|
||||||
loadedSheet->SetFields( fields );
|
loadedSheet->SetFields( fields );
|
||||||
}
|
}
|
||||||
|
@ -1916,14 +1917,16 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarT
|
||||||
EDA_TEXT* aKiCadTextItem )
|
EDA_TEXT* aKiCadTextItem )
|
||||||
{
|
{
|
||||||
TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
|
TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
|
||||||
|
int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
|
||||||
aKiCadTextItem->SetTextWidth( getKiCadLength( textCode.Width ) );
|
aKiCadTextItem->SetTextWidth( getKiCadLength( textCode.Width ) );
|
||||||
aKiCadTextItem->SetTextHeight( getKiCadLength( textCode.Height ) );
|
aKiCadTextItem->SetTextHeight( textHeight );
|
||||||
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
|
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
|
||||||
|
|
||||||
switch( aCadstarAlignment )
|
switch( aCadstarAlignment )
|
||||||
{
|
{
|
||||||
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
|
||||||
|
FixTextPositionNoAlignment( aKiCadTextItem );
|
||||||
|
KI_FALLTHROUGH;
|
||||||
case ALIGNMENT::BOTTOMLEFT:
|
case ALIGNMENT::BOTTOMLEFT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||||
|
@ -1977,10 +1980,10 @@ SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextE
|
||||||
|
|
||||||
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
|
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
|
||||||
kiTxt->SetText( aCadstarTextElement.Text );
|
kiTxt->SetText( aCadstarTextElement.Text );
|
||||||
applyTextSettings( aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment,
|
|
||||||
aCadstarTextElement.Justification, kiTxt );
|
|
||||||
kiTxt->SetTextAngle( getAngleTenthDegree( aCadstarTextElement.OrientAngle ) );
|
kiTxt->SetTextAngle( getAngleTenthDegree( aCadstarTextElement.OrientAngle ) );
|
||||||
kiTxt->SetMirrored( aCadstarTextElement.Mirror );
|
kiTxt->SetMirrored( aCadstarTextElement.Mirror );
|
||||||
|
applyTextSettings( aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment,
|
||||||
|
aCadstarTextElement.Justification, kiTxt );
|
||||||
|
|
||||||
return kiTxt;
|
return kiTxt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2106,6 +2106,9 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText,
|
||||||
|
|
||||||
txt->Move( aMoveVector );
|
txt->Move( aMoveVector );
|
||||||
|
|
||||||
|
if( aCadstarText.Alignment == ALIGNMENT::NO_ALIGNMENT )
|
||||||
|
FixTextPositionNoAlignment( txt );
|
||||||
|
|
||||||
LAYER_ID layersToDrawOn = aCadstarLayerOverride;
|
LAYER_ID layersToDrawOn = aCadstarLayerOverride;
|
||||||
|
|
||||||
if( layersToDrawOn.IsEmpty() )
|
if( layersToDrawOn.IsEmpty() )
|
||||||
|
@ -2661,6 +2664,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta
|
||||||
switch( aCadstarAttrLoc.Alignment )
|
switch( aCadstarAttrLoc.Alignment )
|
||||||
{
|
{
|
||||||
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
|
||||||
|
FixTextPositionNoAlignment( txt );
|
||||||
|
KI_FALLTHROUGH;
|
||||||
case ALIGNMENT::BOTTOMLEFT:
|
case ALIGNMENT::BOTTOMLEFT:
|
||||||
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||||
|
|
Loading…
Reference in New Issue