Fix more bugs from collapsing LIB_* to SCH_*.

The transform can always be used: it will be the identiy
transform when in the schematic.

Also fixes a bug where textbox borders didn't get
plotted, and a couple others where things were still
expecting an upside-down coordinate system.
This commit is contained in:
Jeff Young 2024-04-29 12:18:29 +01:00
parent 3d56494652
commit e5a17b96a3
3 changed files with 35 additions and 125 deletions

View File

@ -142,24 +142,14 @@ void SCH_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
ptList.clear();
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
}
else if( GetShape() == SHAPE_T::BEZIER )
{
ptList.clear();
for( const VECTOR2I& pt : m_bezierPoints )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
}
COLOR4D color = GetStroke().GetColor();
@ -221,33 +211,19 @@ void SCH_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
aPlotter->SetCurrentLineWidth( pen_size );
aPlotter->SetDash( pen_size, lineStyle );
VECTOR2I start = m_start;
VECTOR2I end = m_end;
VECTOR2I start = renderSettings->TransformCoordinate( m_start ) + aOffset;
VECTOR2I end = renderSettings->TransformCoordinate( m_end ) + aOffset;
VECTOR2I mid, center;
if( m_layer == LAYER_DEVICE )
{
start = renderSettings->TransformCoordinate( start ) + aOffset;
end = renderSettings->TransformCoordinate( end ) + aOffset;
}
switch( GetShape() )
{
case SHAPE_T::ARC:
mid = GetArcMid();
if( m_layer == LAYER_DEVICE )
mid = renderSettings->TransformCoordinate( mid ) + aOffset;
mid = renderSettings->TransformCoordinate( GetArcMid() ) + aOffset;
aPlotter->Arc( start, mid, end, fill, pen_size );
break;
case SHAPE_T::CIRCLE:
center = getCenter();
if( m_layer == LAYER_DEVICE )
center = renderSettings->TransformCoordinate( center ) + aOffset;
center = renderSettings->TransformCoordinate( getCenter() ) + aOffset;
aPlotter->Circle( center, GetRadius() * 2, fill, pen_size );
break;
@ -308,24 +284,14 @@ void SCH_SHAPE::PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit
ptList.clear();
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
}
else if( GetShape() == SHAPE_T::BEZIER )
{
ptList.clear();
for( const VECTOR2I& pt : m_bezierPoints )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
}
if( GetFillMode() == FILL_T::FILLED_WITH_COLOR )
@ -394,31 +360,21 @@ void SCH_SHAPE::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBod
ptList.clear();
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
}
else if( GetShape() == SHAPE_T::BEZIER )
{
ptList.clear();
for( const VECTOR2I& pt : m_bezierPoints )
{
if( m_layer == LAYER_DEVICE )
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
else
ptList.push_back( pt );
}
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
}
VECTOR2I start = GetStart();
VECTOR2I end = GetEnd();
VECTOR2I center = ( GetShape() == SHAPE_T::ARC ) ? getCenter() : VECTOR2I( 0, 0 );
if( m_layer == LAYER_DEVICE )
if( aSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() )
{
start = aSettings->TransformCoordinate( start ) + aOffset;
end = aSettings->TransformCoordinate( end ) + aOffset;
@ -527,16 +483,9 @@ void SCH_SHAPE::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBod
STROKE_PARAMS::Stroke( shape, GetEffectiveLineStyle(), penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b )
{
if( m_layer == LAYER_DEVICE )
{
VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
}
else
{
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
}
VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
} );
}

View File

@ -122,19 +122,9 @@ void SCH_TEXTBOX::Rotate90( bool aClockwise )
VECTOR2I SCH_TEXTBOX::GetDrawPos() const
{
BOX2I bbox;
BOX2I bbox = BOX2I( m_start, m_end - m_start );
if( m_layer == LAYER_DEVICE ) // TODO: nuke symbol editor's upside-down coordinate system
{
bbox = BOX2I( VECTOR2I( std::min( m_start.x, m_end.x ), std::min( -m_start.y, -m_end.y ) ),
VECTOR2I( abs( m_end.x - m_start.x ), abs( m_end.y - m_start.y ) ) );
}
else
{
bbox = BOX2I( m_start, m_end - m_start );
bbox.Normalize();
}
bbox.Normalize();
VECTOR2I pos( bbox.GetLeft() + m_marginLeft, bbox.GetBottom() - m_marginBottom );
@ -324,16 +314,9 @@ void SCH_TEXTBOX::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aB
STROKE_PARAMS::Stroke( shape, lineStyle, penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b )
{
if( m_layer == LAYER_DEVICE )
{
VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
}
else
{
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
}
VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
} );
}
@ -353,28 +336,7 @@ void SCH_TEXTBOX::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aB
color = color.Mix( bg, 0.5f );
}
if( m_layer == LAYER_DEVICE )
{
SCH_TEXTBOX temp( *this );
if( aSettings->m_Transform.y1 )
{
temp.SetTextAngle( temp.GetTextAngle() == ANGLE_HORIZONTAL ? ANGLE_VERTICAL
: ANGLE_HORIZONTAL );
}
// NB: GetDrawPos() will want Symbol Editor (upside-down) coordinates
temp.SetStart( VECTOR2I( pt1.x, -pt1.y ) );
temp.SetEnd( VECTOR2I( pt2.x, -pt2.y ) );
GRPrintText( DC, temp.GetDrawPos(), color, temp.GetShownText( true ), temp.GetTextAngle(),
temp.GetTextSize(), temp.GetHorizJustify(), temp.GetVertJustify(), penWidth,
temp.IsItalic(), temp.IsBold(), getDrawFont(), GetFontMetrics() );
}
else
{
EDA_TEXT::Print( aSettings, aOffset, color );
}
EDA_TEXT::Print( aSettings, aOffset, color );
}
@ -472,11 +434,10 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
if( IsPrivate() )
return;
SCH_SHAPE::Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
if( aBackground )
{
SCH_SHAPE::Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
return;
}
SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
@ -525,15 +486,15 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth );
TEXT_ATTRIBUTES attrs;
std::vector<VECTOR2I> positions;
wxArrayString strings_list;
wxArrayString strings_list;
wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' );
positions.reserve( strings_list.Count() );
if( m_layer == LAYER_DEVICE )
if( renderSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() )
{
VECTOR2I start = renderSettings->TransformCoordinate( m_start ) + aOffset;
VECTOR2I end = renderSettings->TransformCoordinate( m_end ) + aOffset;
SCH_TEXTBOX temp( *this );
if( renderSettings->m_Transform.y1 )
@ -542,17 +503,18 @@ void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS
: ANGLE_HORIZONTAL );
}
// NB: GetDrawPos() will want Symbol Editor (upside-down) coordinates
temp.SetStart( VECTOR2I( start.x, -start.y ) );
temp.SetEnd( VECTOR2I( end.x, -end.y ) );
temp.SetStart( renderSettings->TransformCoordinate( m_start ) + aOffset );
temp.SetEnd( renderSettings->TransformCoordinate( m_end ) + aOffset );
attrs = temp.GetAttributes();
temp.GetLinePositions( positions, (int) strings_list.Count() );
}
else
{
attrs = GetAttributes();
GetLinePositions( positions, (int) strings_list.Count() );
}
TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_StrokeWidth = penWidth;
attrs.m_Multiline = false;

View File

@ -177,8 +177,7 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM
//
// Careful when pasting. The pasted pin will be at the same location as it
// was copied from, leading us to believe it's a synchronized pin. It's not.
if( m_frame->SynchronizePins()
&& ( lib_item->GetEditFlags() & IS_PASTED ) == 0 )
if( m_frame->SynchronizePins() && !( lib_item->GetEditFlags() & IS_PASTED ) )
{
std::set<SCH_PIN*> sync_pins;
@ -188,8 +187,8 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM
if( lib_item->Type() == SCH_PIN_T )
{
SCH_PIN* cur_pin = static_cast<SCH_PIN*>( lib_item );
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
SCH_PIN* cur_pin = static_cast<SCH_PIN*>( lib_item );
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
got_unit[cur_pin->GetUnit()] = true;
@ -240,7 +239,7 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM
else if( m_frame->GetMoveWarpsCursor() )
{
VECTOR2I itemPos = selection.GetTopLeftItem()->GetPosition();
m_anchorPos = VECTOR2I( itemPos.x, -itemPos.y );
m_anchorPos = VECTOR2I( itemPos.x, itemPos.y );
getViewControls()->WarpMouseCursor( m_anchorPos, true, true );
m_cursor = m_anchorPos;