CADSTAR Schematic: Fix import of text alignment
Ensure that the text alignment applied to text objects corresponds to valid text alignments that can be set within eeschema Fixes https://gitlab.com/kicad/code/kicad/-/issues/8090
This commit is contained in:
parent
213d2fe977
commit
d041578150
|
@ -2537,7 +2537,6 @@ void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextIte
|
||||||
{
|
{
|
||||||
if( !aKiCadTextItem->GetText().IsEmpty() )
|
if( !aKiCadTextItem->GetText().IsEmpty() )
|
||||||
{
|
{
|
||||||
//No exact KiCad equivalent, so lets move the position of the text
|
|
||||||
int txtAngleDecideg = aKiCadTextItem->GetTextAngleDegrees() * 10.0;
|
int txtAngleDecideg = aKiCadTextItem->GetTextAngleDegrees() * 10.0;
|
||||||
wxPoint positionOffset( 0, aKiCadTextItem->GetInterline() );
|
wxPoint positionOffset( 0, aKiCadTextItem->GetInterline() );
|
||||||
RotatePoint( &positionOffset, txtAngleDecideg );
|
RotatePoint( &positionOffset, txtAngleDecideg );
|
||||||
|
|
|
@ -86,6 +86,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh
|
||||||
m_plugin = aSchPlugin;
|
m_plugin = aSchPlugin;
|
||||||
m_libraryFileName = aLibraryFileName;
|
m_libraryFileName = aLibraryFileName;
|
||||||
|
|
||||||
|
loadTextVariables(); // Load text variables right at the start to ensure bounding box
|
||||||
|
// calculations work correctly for text items
|
||||||
loadSheets();
|
loadSheets();
|
||||||
loadHierarchicalSheetPins();
|
loadHierarchicalSheetPins();
|
||||||
loadPartsLibrary();
|
loadPartsLibrary();
|
||||||
|
@ -95,7 +97,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh
|
||||||
loadFigures();
|
loadFigures();
|
||||||
loadTexts();
|
loadTexts();
|
||||||
loadDocumentationSymbols();
|
loadDocumentationSymbols();
|
||||||
loadTextVariables();
|
|
||||||
|
|
||||||
if( Schematic.VariantHierarchy.Variants.size() > 0 )
|
if( Schematic.VariantHierarchy.Variants.size() > 0 )
|
||||||
{
|
{
|
||||||
|
@ -712,8 +713,14 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
|
||||||
wxPoint nearestPt = (wxPoint) busLineChain.NearestPoint( busLabelLoc );
|
wxPoint nearestPt = (wxPoint) busLineChain.NearestPoint( busLabelLoc );
|
||||||
|
|
||||||
label->SetPosition( nearestPt );
|
label->SetPosition( nearestPt );
|
||||||
applyTextSettings( bus.BusLabel.TextCodeID, bus.BusLabel.Alignment,
|
|
||||||
bus.BusLabel.Justification, label );
|
applyTextSettings( label,
|
||||||
|
bus.BusLabel.TextCodeID,
|
||||||
|
bus.BusLabel.Alignment,
|
||||||
|
bus.BusLabel.Justification );
|
||||||
|
|
||||||
|
// Note orientation of the bus label will be determined in loadNets
|
||||||
|
// (the position of the wire will determine how best to place the bus label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,10 +755,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
|
||||||
{
|
{
|
||||||
val->SetVisible( true );
|
val->SetVisible( true );
|
||||||
val->SetPosition( getKiCadPoint( netTerm.NetLabel.Position ) );
|
val->SetPosition( getKiCadPoint( netTerm.NetLabel.Position ) );
|
||||||
val->SetTextAngle( getAngleTenthDegree( netTerm.NetLabel.OrientAngle ) );
|
|
||||||
|
|
||||||
applyTextSettings( netTerm.NetLabel.TextCodeID, netTerm.NetLabel.Alignment,
|
applyTextSettings( val,
|
||||||
netTerm.NetLabel.Justification, val );
|
netTerm.NetLabel.TextCodeID,
|
||||||
|
netTerm.NetLabel.Alignment,
|
||||||
|
netTerm.NetLabel.Justification,
|
||||||
|
netTerm.NetLabel.OrientAngle,
|
||||||
|
netTerm.NetLabel.Mirror );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( m_globalLabelsMap.find( netTerm.SymbolID ) != m_globalLabelsMap.end() )
|
else if( m_globalLabelsMap.find( netTerm.SymbolID ) != m_globalLabelsMap.end() )
|
||||||
|
@ -816,9 +826,10 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
|
||||||
|
|
||||||
if( busTerm.HasNetLabel )
|
if( busTerm.HasNetLabel )
|
||||||
{
|
{
|
||||||
|
applyTextSettings( label,
|
||||||
applyTextSettings( busTerm.NetLabel.TextCodeID, busTerm.NetLabel.Alignment,
|
busTerm.NetLabel.TextCodeID,
|
||||||
busTerm.NetLabel.Justification, label );
|
busTerm.NetLabel.Alignment,
|
||||||
|
busTerm.NetLabel.Justification );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1095,19 +1106,19 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols()
|
||||||
{
|
{
|
||||||
TEXT txt = textPair.second;
|
TEXT txt = textPair.second;
|
||||||
|
|
||||||
|
txt.Mirror = ( txt.Mirror ) ? !mirrorInvert : mirrorInvert;
|
||||||
|
txt.OrientAngle = docSym.OrientAngle - txt.OrientAngle;
|
||||||
|
|
||||||
SCH_TEXT* kiTxt = getKiCadSchText( txt );
|
SCH_TEXT* kiTxt = getKiCadSchText( txt );
|
||||||
|
|
||||||
wxPoint newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
|
wxPoint newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
|
||||||
scalingFactor, centreOfTransform, mirrorInvert );
|
scalingFactor, centreOfTransform, mirrorInvert );
|
||||||
double newTxtAngle = NormalizeAnglePos( kiTxt->GetTextAngle() + rotationAngle );
|
|
||||||
bool newMirrorStatus = kiTxt->IsMirrored() ? !mirrorInvert : mirrorInvert;
|
|
||||||
int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
|
int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
|
||||||
int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
|
int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
|
||||||
int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
|
int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
|
||||||
|
|
||||||
kiTxt->SetPosition( newPosition );
|
kiTxt->SetPosition( newPosition );
|
||||||
kiTxt->SetTextAngle( newTxtAngle );
|
|
||||||
kiTxt->SetMirrored( newMirrorStatus );
|
|
||||||
kiTxt->SetTextWidth( newTxtWidth );
|
kiTxt->SetTextWidth( newTxtWidth );
|
||||||
kiTxt->SetTextHeight( newTxtHeight );
|
kiTxt->SetTextHeight( newTxtHeight );
|
||||||
kiTxt->SetTextThickness( newTxtThickness );
|
kiTxt->SetTextThickness( newTxtThickness );
|
||||||
|
@ -1272,9 +1283,15 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
||||||
LIB_TEXT* libtext = new LIB_TEXT( aPart );
|
LIB_TEXT* libtext = new LIB_TEXT( aPart );
|
||||||
libtext->SetText( csText.Text );
|
libtext->SetText( csText.Text );
|
||||||
libtext->SetUnit( gateNumber );
|
libtext->SetUnit( gateNumber );
|
||||||
libtext->SetTextAngle( getAngleTenthDegree( csText.OrientAngle ) );
|
|
||||||
libtext->SetPosition( getKiCadLibraryPoint( csText.Position, symbol.Origin ) );
|
libtext->SetPosition( getKiCadLibraryPoint( csText.Position, symbol.Origin ) );
|
||||||
applyTextSettings( csText.TextCodeID, csText.Alignment, csText.Justification, libtext );
|
|
||||||
|
applyTextSettings( libtext,
|
||||||
|
csText.TextCodeID,
|
||||||
|
csText.Alignment,
|
||||||
|
csText.Justification,
|
||||||
|
csText.OrientAngle,
|
||||||
|
csText.Mirror );
|
||||||
|
|
||||||
aPart->AddDrawItem( libtext );
|
aPart->AddDrawItem( libtext );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1374,47 +1391,35 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
||||||
attrField->SetText( aAttributeVal.Value );
|
attrField->SetText( aAttributeVal.Value );
|
||||||
attrField->SetUnit( gateNumber );
|
attrField->SetUnit( gateNumber );
|
||||||
|
|
||||||
|
ATTRIBUTE_ID& attrid = aAttributeVal.AttributeID;
|
||||||
|
attrField->SetVisible( isAttributeVisible( attrid ) );
|
||||||
|
|
||||||
if( aAttributeVal.HasLocation )
|
if( aAttributeVal.HasLocation )
|
||||||
{
|
{
|
||||||
// #1 Check if the part itself defined a location for the field
|
// #1 Check if the part itself defined a location for the field
|
||||||
applyToLibraryFieldAttribute( aAttributeVal.AttributeLocation, symbol.Origin,
|
applyToLibraryFieldAttribute( aAttributeVal.AttributeLocation, symbol.Origin,
|
||||||
attrField );
|
attrField );
|
||||||
attrField->SetVisible( isAttributeVisible( aAttributeVal.AttributeID ) );
|
|
||||||
}
|
}
|
||||||
else if( symbol.TextLocations.find( aAttributeVal.AttributeID )
|
else if( symbol.TextLocations.find( aAttributeVal.AttributeID )
|
||||||
!= symbol.TextLocations.end() )
|
!= symbol.TextLocations.end() )
|
||||||
{
|
{
|
||||||
// #2 Look in the symbol definition: Text locations
|
// #2 Look in the symbol definition: Text locations
|
||||||
TEXT_LOCATION symTxtLoc = symbol.TextLocations.at( aAttributeVal.AttributeID );
|
TEXT_LOCATION symTxtLoc = symbol.TextLocations.at( aAttributeVal.AttributeID );
|
||||||
|
|
||||||
applyToLibraryFieldAttribute( symTxtLoc, symbol.Origin, attrField );
|
applyToLibraryFieldAttribute( symTxtLoc, symbol.Origin, attrField );
|
||||||
attrField->SetVisible( isAttributeVisible( symTxtLoc.AttributeID ) );
|
|
||||||
}
|
}
|
||||||
else if( symbol.AttributeValues.find( aAttributeVal.AttributeID )
|
else if( symbol.AttributeValues.find( attrid ) != symbol.AttributeValues.end()
|
||||||
!= symbol.AttributeValues.end() )
|
&& symbol.AttributeValues.at( attrid ).HasLocation )
|
||||||
{
|
{
|
||||||
// #3 Look in the symbol definition: Attribute values
|
// #3 Look in the symbol definition: Attribute values
|
||||||
ATTRIBUTE_VALUE symAttrVal =
|
ATTRIBUTE_VALUE symAttrVal = symbol.AttributeValues.at( attrid );
|
||||||
symbol.AttributeValues.at( aAttributeVal.AttributeID );
|
|
||||||
|
|
||||||
if( symAttrVal.HasLocation )
|
|
||||||
{
|
|
||||||
applyToLibraryFieldAttribute( symAttrVal.AttributeLocation, symbol.Origin,
|
applyToLibraryFieldAttribute( symAttrVal.AttributeLocation, symbol.Origin,
|
||||||
attrField );
|
attrField );
|
||||||
attrField->SetVisible( isAttributeVisible( symAttrVal.AttributeID ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
attrField->SetVisible( false );
|
attrField->SetVisible( false );
|
||||||
applyTextSettings( wxT( "TC1" ), ALIGNMENT::NO_ALIGNMENT,
|
applyTextSettings( attrField, wxT( "TC1" ), ALIGNMENT::NO_ALIGNMENT,
|
||||||
JUSTIFICATION::LEFT, attrField );
|
JUSTIFICATION::LEFT );
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
attrField->SetVisible( false );
|
|
||||||
applyTextSettings( wxT( "TC1" ), ALIGNMENT::NO_ALIGNMENT,
|
|
||||||
JUSTIFICATION::LEFT, attrField );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1530,12 +1535,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute(
|
||||||
const ATTRIBUTE_LOCATION& aCadstarAttrLoc, wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField )
|
const ATTRIBUTE_LOCATION& aCadstarAttrLoc, wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField )
|
||||||
{
|
{
|
||||||
aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
|
aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
|
||||||
aKiCadField->SetTextAngle( getAngleTenthDegree( aCadstarAttrLoc.OrientAngle ) );
|
|
||||||
aKiCadField->SetBold( false );
|
|
||||||
aKiCadField->SetVisible( true );
|
|
||||||
|
|
||||||
applyTextSettings( aCadstarAttrLoc.TextCodeID, aCadstarAttrLoc.Alignment,
|
applyTextSettings( aKiCadField,
|
||||||
aCadstarAttrLoc.Justification, aKiCadField );
|
aCadstarAttrLoc.TextCodeID,
|
||||||
|
aCadstarAttrLoc.Alignment,
|
||||||
|
aCadstarAttrLoc.Justification,
|
||||||
|
aCadstarAttrLoc.OrientAngle,
|
||||||
|
aCadstarAttrLoc.Mirror );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1651,46 +1657,37 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute(
|
||||||
bool aIsMirrored, SCH_FIELD* aKiCadField )
|
bool aIsMirrored, SCH_FIELD* aKiCadField )
|
||||||
{
|
{
|
||||||
aKiCadField->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
|
aKiCadField->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
|
||||||
aKiCadField->SetTextAngle( getAngleTenthDegree( aCadstarAttrLoc.OrientAngle )
|
|
||||||
- aComponentOrientationDeciDeg );
|
|
||||||
aKiCadField->SetBold( false );
|
|
||||||
aKiCadField->SetVisible( true );
|
aKiCadField->SetVisible( true );
|
||||||
|
|
||||||
ALIGNMENT fieldAlignment = aCadstarAttrLoc.Alignment;
|
ALIGNMENT alignment = aCadstarAttrLoc.Alignment;
|
||||||
JUSTIFICATION fieldJustification = aCadstarAttrLoc.Justification;
|
|
||||||
|
double textAngle = getAngleTenthDegree( aCadstarAttrLoc.OrientAngle ) - aComponentOrientationDeciDeg;
|
||||||
|
long long cadstarAngle = getCadstarAngle( textAngle );
|
||||||
|
|
||||||
// KiCad mirrors the justification and alignment when the component is mirrored but CADSTAR
|
|
||||||
// specifies it post-mirroring
|
|
||||||
if( aIsMirrored )
|
if( aIsMirrored )
|
||||||
{
|
{
|
||||||
switch( fieldAlignment )
|
// In KiCad, the angle of the symbol instance affects the position of the symbol fields because
|
||||||
|
// there is a distinction on x-axis and y-axis mirroring
|
||||||
|
double angleDeciDeg = NormalizeAnglePos( aComponentOrientationDeciDeg );
|
||||||
|
int quadrant = KiROUND( angleDeciDeg / 900.0 );
|
||||||
|
quadrant %= 4;
|
||||||
|
|
||||||
|
switch( quadrant )
|
||||||
{
|
{
|
||||||
// Change left to right:
|
case 1:
|
||||||
case ALIGNMENT::NO_ALIGNMENT:
|
case 3: alignment = rotate180( alignment ); KI_FALLTHROUGH;
|
||||||
case ALIGNMENT::BOTTOMLEFT: fieldAlignment = ALIGNMENT::BOTTOMRIGHT; break;
|
case 0:
|
||||||
case ALIGNMENT::CENTERLEFT: fieldAlignment = ALIGNMENT::CENTERRIGHT; break;
|
case 2: alignment = mirrorX( alignment ); break;
|
||||||
case ALIGNMENT::TOPLEFT: fieldAlignment = ALIGNMENT::TOPRIGHT; break;
|
default: wxFAIL_MSG( "unknown quadrant" ); break;
|
||||||
//Change right to left:
|
|
||||||
case ALIGNMENT::BOTTOMRIGHT: fieldAlignment = ALIGNMENT::BOTTOMLEFT; break;
|
|
||||||
case ALIGNMENT::CENTERRIGHT: fieldAlignment = ALIGNMENT::CENTERLEFT; break;
|
|
||||||
case ALIGNMENT::TOPRIGHT: fieldAlignment = ALIGNMENT::TOPLEFT; break;
|
|
||||||
// Center alignment does not mirror:
|
|
||||||
case ALIGNMENT::BOTTOMCENTER:
|
|
||||||
case ALIGNMENT::CENTERCENTER:
|
|
||||||
case ALIGNMENT::TOPCENTER: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch( fieldJustification )
|
|
||||||
{
|
|
||||||
case JUSTIFICATION::LEFT: fieldJustification = JUSTIFICATION::RIGHT; break;
|
|
||||||
case JUSTIFICATION::RIGHT: fieldJustification = JUSTIFICATION::LEFT; break;
|
|
||||||
case JUSTIFICATION::CENTER: break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyTextSettings( aKiCadField,
|
||||||
applyTextSettings( aCadstarAttrLoc.TextCodeID, fieldAlignment, fieldJustification,
|
aCadstarAttrLoc.TextCodeID,
|
||||||
aKiCadField );
|
alignment,
|
||||||
|
aCadstarAttrLoc.Justification,
|
||||||
|
cadstarAngle,
|
||||||
|
aCadstarAttrLoc.Mirror );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2065,11 +2062,16 @@ 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" ) );
|
||||||
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 );
|
applyTextSettings( &blockNameField,
|
||||||
|
block.BlockLabel.TextCodeID,
|
||||||
|
block.BlockLabel.Alignment,
|
||||||
|
block.BlockLabel.Justification,
|
||||||
|
block.BlockLabel.OrientAngle,
|
||||||
|
block.BlockLabel.Mirror );
|
||||||
|
|
||||||
fields.push_back( blockNameField );
|
fields.push_back( blockNameField );
|
||||||
loadedSheet->SetFields( fields );
|
loadedSheet->SetFields( fields );
|
||||||
}
|
}
|
||||||
|
@ -2342,10 +2344,62 @@ LABEL_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyleDeciDeg(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
|
CADSTAR_SCH_ARCHIVE_LOADER::ALIGNMENT
|
||||||
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
|
CADSTAR_SCH_ARCHIVE_LOADER::mirrorX( const ALIGNMENT& aCadstarAlignment )
|
||||||
EDA_TEXT* aKiCadTextItem )
|
|
||||||
{
|
{
|
||||||
|
switch( aCadstarAlignment )
|
||||||
|
{
|
||||||
|
// Change left to right:
|
||||||
|
case ALIGNMENT::NO_ALIGNMENT:
|
||||||
|
case ALIGNMENT::BOTTOMLEFT: return ALIGNMENT::BOTTOMRIGHT;
|
||||||
|
case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT;
|
||||||
|
case ALIGNMENT::TOPLEFT: return ALIGNMENT::TOPRIGHT;
|
||||||
|
//Change right to left:
|
||||||
|
case ALIGNMENT::BOTTOMRIGHT: return ALIGNMENT::BOTTOMLEFT;
|
||||||
|
case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT;
|
||||||
|
case ALIGNMENT::TOPRIGHT: return ALIGNMENT::TOPLEFT;
|
||||||
|
// Center alignment does not mirror:
|
||||||
|
case ALIGNMENT::BOTTOMCENTER:
|
||||||
|
case ALIGNMENT::CENTERCENTER:
|
||||||
|
case ALIGNMENT::TOPCENTER: return aCadstarAlignment;
|
||||||
|
// Shouldn't be here
|
||||||
|
default: wxFAIL_MSG( "Unknown Cadstar Alignment" ); return aCadstarAlignment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CADSTAR_SCH_ARCHIVE_LOADER::ALIGNMENT
|
||||||
|
CADSTAR_SCH_ARCHIVE_LOADER::rotate180( const ALIGNMENT& aCadstarAlignment )
|
||||||
|
{
|
||||||
|
switch( aCadstarAlignment )
|
||||||
|
{
|
||||||
|
case ALIGNMENT::NO_ALIGNMENT:
|
||||||
|
case ALIGNMENT::BOTTOMLEFT: return ALIGNMENT::TOPRIGHT;
|
||||||
|
case ALIGNMENT::BOTTOMCENTER: return ALIGNMENT::TOPCENTER;
|
||||||
|
case ALIGNMENT::BOTTOMRIGHT: return ALIGNMENT::TOPLEFT;
|
||||||
|
case ALIGNMENT::TOPLEFT: return ALIGNMENT::BOTTOMRIGHT;
|
||||||
|
case ALIGNMENT::TOPCENTER: return ALIGNMENT::BOTTOMCENTER;
|
||||||
|
case ALIGNMENT::TOPRIGHT: return ALIGNMENT::BOTTOMLEFT;
|
||||||
|
case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT;
|
||||||
|
case ALIGNMENT::CENTERCENTER: return ALIGNMENT::CENTERCENTER;
|
||||||
|
case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT;
|
||||||
|
// Shouldn't be here
|
||||||
|
default: wxFAIL_MSG( "Unknown Cadstar Alignment" ); return aCadstarAlignment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadTextItem,
|
||||||
|
const TEXTCODE_ID& aCadstarTextCodeID,
|
||||||
|
const ALIGNMENT& aCadstarAlignment,
|
||||||
|
const JUSTIFICATION& aCadstarJustification,
|
||||||
|
const long long aCadstarOrientAngle,
|
||||||
|
bool aMirrored )
|
||||||
|
{
|
||||||
|
// Justification ignored for now as not supported in eeschema, but leaving this code in
|
||||||
|
// place for future upgrades.
|
||||||
|
// TODO update this when eeschema supports justification independent of anchor position.
|
||||||
|
|
||||||
TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
|
TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
|
||||||
int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
|
int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
|
||||||
int textWidth = getKiCadLength( textCode.Width );
|
int textWidth = getKiCadLength( textCode.Width );
|
||||||
|
@ -2364,69 +2418,165 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarT
|
||||||
aKiCadTextItem->SetTextWidth( textWidth );
|
aKiCadTextItem->SetTextWidth( textWidth );
|
||||||
aKiCadTextItem->SetTextHeight( textHeight );
|
aKiCadTextItem->SetTextHeight( textHeight );
|
||||||
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
|
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
|
||||||
|
aKiCadTextItem->SetTextAngle( getAngleTenthDegree( aCadstarOrientAngle ) );
|
||||||
|
aKiCadTextItem->SetBold( textCode.Font.Modifier1 == FONT_BOLD );
|
||||||
|
aKiCadTextItem->SetItalic( textCode.Font.Italic );
|
||||||
|
|
||||||
switch( aCadstarAlignment )
|
ALIGNMENT textAlignment = aCadstarAlignment;
|
||||||
|
|
||||||
|
// KiCad mirrors the justification and alignment when the symbol is mirrored but CADSTAR
|
||||||
|
// specifies it post-mirroring. In contrast, if the text item itself is mirrored (not
|
||||||
|
// supported in KiCad), CADSTAR specifies the alignment and justification pre-mirroring
|
||||||
|
if( aMirrored )
|
||||||
|
textAlignment = mirrorX( aCadstarAlignment );
|
||||||
|
|
||||||
|
auto setAlignment = [&]( EDA_TEXT* aText, ALIGNMENT aAlignment )
|
||||||
|
{
|
||||||
|
switch( aAlignment )
|
||||||
{
|
{
|
||||||
case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
|
case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
|
||||||
FixTextPositionNoAlignment( aKiCadTextItem );
|
//No exact KiCad equivalent, so lets move the position of the text
|
||||||
|
FixTextPositionNoAlignment( aText );
|
||||||
KI_FALLTHROUGH;
|
KI_FALLTHROUGH;
|
||||||
case ALIGNMENT::BOTTOMLEFT:
|
case ALIGNMENT::BOTTOMLEFT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::BOTTOMCENTER:
|
case ALIGNMENT::BOTTOMCENTER:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::BOTTOMRIGHT:
|
case ALIGNMENT::BOTTOMRIGHT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::CENTERLEFT:
|
case ALIGNMENT::CENTERLEFT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::CENTERCENTER:
|
case ALIGNMENT::CENTERCENTER:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::CENTERRIGHT:
|
case ALIGNMENT::CENTERRIGHT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::TOPLEFT:
|
case ALIGNMENT::TOPLEFT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::TOPCENTER:
|
case ALIGNMENT::TOPCENTER:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALIGNMENT::TOPRIGHT:
|
case ALIGNMENT::TOPRIGHT:
|
||||||
aKiCadTextItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||||
aKiCadTextItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
LABEL_SPIN_STYLE spin = getSpinStyle( aCadstarOrientAngle, aMirrored );
|
||||||
|
EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
|
||||||
|
wxCHECK( textEdaItem, /* void */ ); // ensure this is a EDA_ITEM
|
||||||
|
|
||||||
|
switch( textEdaItem->Type() )
|
||||||
|
{
|
||||||
|
// Some KiCad schematic text items only permit a limited amount of angles
|
||||||
|
// and text justifications
|
||||||
|
case SCH_FIELD_T:
|
||||||
|
case LIB_FIELD_T:
|
||||||
|
{
|
||||||
|
// Spin style not used. All text justifications are permitted. However, only orientations
|
||||||
|
// of 0 deg or 90 deg are supported
|
||||||
|
double angleDeciDeg = NormalizeAnglePos( aKiCadTextItem->GetTextAngle() );
|
||||||
|
int quadrant = KiROUND( angleDeciDeg / 900.0 );
|
||||||
|
quadrant %= 4;
|
||||||
|
|
||||||
|
switch( quadrant )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
angleDeciDeg = 0;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
angleDeciDeg = 900;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
angleDeciDeg = 0;
|
||||||
|
textAlignment = rotate180( textAlignment );
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
angleDeciDeg = 900;
|
||||||
|
textAlignment = rotate180( textAlignment );
|
||||||
|
break;
|
||||||
|
default: wxFAIL_MSG( "Unknown Quadrant" );
|
||||||
|
}
|
||||||
|
|
||||||
|
aKiCadTextItem->SetTextAngle( angleDeciDeg );
|
||||||
|
setAlignment( aKiCadTextItem, textAlignment );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case SCH_TEXT_T:
|
||||||
|
{
|
||||||
|
// Note spin style in a SCH_TEXT results in a vertical alignment GR_TEXT_VJUSTIFY_BOTTOM
|
||||||
|
// so need to adjust the location of the text element based on Cadstar's original text
|
||||||
|
// alignment (anchor position).
|
||||||
|
setAlignment( aKiCadTextItem, textAlignment );
|
||||||
|
EDA_RECT bb = textEdaItem->GetBoundingBox();
|
||||||
|
int off = static_cast<SCH_TEXT*>( aKiCadTextItem )->GetTextOffset();
|
||||||
|
wxPoint pos;
|
||||||
|
|
||||||
|
// Change the anchor point of the text item to make it match the same bounding box
|
||||||
|
// And correct the error introduced by the text offseting in KiCad
|
||||||
|
switch( spin )
|
||||||
|
{
|
||||||
|
case LABEL_SPIN_STYLE::BOTTOM: pos = { bb.GetRight() - off, bb.GetTop() }; break;
|
||||||
|
case LABEL_SPIN_STYLE::UP: pos = { bb.GetRight() - off, bb.GetBottom() }; break;
|
||||||
|
case LABEL_SPIN_STYLE::LEFT: pos = { bb.GetRight() , bb.GetBottom() + off }; break;
|
||||||
|
case LABEL_SPIN_STYLE::RIGHT: pos = { bb.GetLeft() , bb.GetBottom() + off }; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
aKiCadTextItem->SetTextPos( pos );
|
||||||
|
}
|
||||||
|
KI_FALLTHROUGH;
|
||||||
|
|
||||||
|
// We don't want to change position of net labels as that would break connectivity
|
||||||
|
case SCH_LABEL_T:
|
||||||
|
case SCH_GLOBAL_LABEL_T:
|
||||||
|
case SCH_HIER_LABEL_T:
|
||||||
|
case SCH_SHEET_PIN_T:
|
||||||
|
static_cast<SCH_TEXT*>( aKiCadTextItem )->SetLabelSpinStyle( spin );
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement )
|
SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement )
|
||||||
{
|
{
|
||||||
SCH_TEXT* kiTxt = new SCH_TEXT();
|
SCH_TEXT* kiTxt = new SCH_TEXT();
|
||||||
|
|
||||||
|
kiTxt->SetParent( m_schematic ); // set to the schematic for now to avoid asserts
|
||||||
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
|
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
|
||||||
kiTxt->SetText( aCadstarTextElement.Text );
|
kiTxt->SetText( aCadstarTextElement.Text );
|
||||||
kiTxt->SetTextAngle( getAngleTenthDegree( aCadstarTextElement.OrientAngle ) );
|
|
||||||
kiTxt->SetMirrored( aCadstarTextElement.Mirror );
|
applyTextSettings( kiTxt,
|
||||||
applyTextSettings( aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment,
|
aCadstarTextElement.TextCodeID,
|
||||||
aCadstarTextElement.Justification, kiTxt );
|
aCadstarTextElement.Alignment,
|
||||||
|
aCadstarTextElement.Justification,
|
||||||
|
aCadstarTextElement.OrientAngle,
|
||||||
|
aCadstarTextElement.Mirror );
|
||||||
|
|
||||||
return kiTxt;
|
return kiTxt;
|
||||||
}
|
}
|
||||||
|
@ -2521,7 +2671,6 @@ wxPoint CADSTAR_SCH_ARCHIVE_LOADER::applyTransform( const wxPoint& aPoint,
|
||||||
if( aMirrorInvert )
|
if( aMirrorInvert )
|
||||||
{
|
{
|
||||||
MIRROR( retVal.x, aTransformCentre.x );
|
MIRROR( retVal.x, aTransformCentre.x );
|
||||||
MIRROR( retVal.x, aTransformCentre.x );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aRotationAngleDeciDeg != 0.0 )
|
if( aRotationAngleDeciDeg != 0.0 )
|
||||||
|
|
|
@ -176,9 +176,13 @@ private:
|
||||||
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false );
|
||||||
|
|
||||||
//Helper functions for loading text elements
|
//Helper functions for loading text elements
|
||||||
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
|
void applyTextSettings( EDA_TEXT* aKiCadTextItem,
|
||||||
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
|
const TEXTCODE_ID& aCadstarTextCodeID,
|
||||||
EDA_TEXT* aKiCadTextItem );
|
const ALIGNMENT& aCadstarAlignment,
|
||||||
|
const JUSTIFICATION& aCadstarJustification,
|
||||||
|
const long long aCadstarOrientAngle = 0,
|
||||||
|
bool aMirrored = false );
|
||||||
|
|
||||||
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
|
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,6 +206,8 @@ private:
|
||||||
int getKiCadUnitNumberFromGate( const GATE_ID& aCadstarGateID );
|
int getKiCadUnitNumberFromGate( const GATE_ID& aCadstarGateID );
|
||||||
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 );
|
||||||
|
ALIGNMENT mirrorX( const ALIGNMENT& aCadstarAlignment );
|
||||||
|
ALIGNMENT rotate180( const ALIGNMENT& aCadstarAlignment );
|
||||||
|
|
||||||
//General Graphical manipulation functions
|
//General Graphical manipulation functions
|
||||||
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
|
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
|
||||||
|
@ -257,6 +263,13 @@ private:
|
||||||
return getAngleTenthDegree( aCadstarAngle ) / 10.0;
|
return getAngleTenthDegree( aCadstarAngle ) / 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long long getCadstarAngle( const double& aAngleTenthDegree )
|
||||||
|
{
|
||||||
|
return KiROUND( ( aAngleTenthDegree / getAngleTenthDegree( aAngleTenthDegree ) )
|
||||||
|
* aAngleTenthDegree );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param aPoint
|
* @param aPoint
|
||||||
|
|
Loading…
Reference in New Issue