Swap non-temp and non-edit flags for SCH_ITEMs.

This is required to keep selected and brightened state across undo.

It's also probably required for things like IS_SHOWN_AS_BITMAP and
possibly ENTERED.  FWIW, most BOARD_ITEMs do a straight swap, including
the temp and edit flags.  But that seems like a risky change....

Also removes SyncView() call from Undo/Redo as that does a MODEL_RELOAD
which clears the selection.
This commit is contained in:
Jeff Young 2023-07-08 18:37:47 +01:00
parent c8e8b71198
commit 5bca002567
18 changed files with 65 additions and 11 deletions

View File

@ -107,6 +107,8 @@ EDA_ITEM* SCH_BITMAP::Clone() const
void SCH_BITMAP::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
aItem->GetClass() ) );

View File

@ -138,6 +138,8 @@ VECTOR2I SCH_BUS_ENTRY_BASE::GetEnd() const
void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
SCH_BUS_ENTRY_BASE* item = dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem );
wxCHECK_RET( item, wxT( "Cannot swap bus entry data with invalid item." ) );

View File

@ -407,6 +407,8 @@ void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
void SCH_FIELD::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ),
wxT( "Cannot swap field data with invalid item." ) );

View File

@ -259,6 +259,27 @@ void SCH_ITEM::SwapData( SCH_ITEM* aItem )
}
void SCH_ITEM::SwapFlags( SCH_ITEM* aItem )
{
EDA_ITEM_FLAGS editFlags = GetEditFlags();
EDA_ITEM_FLAGS tempFlags = GetTempFlags();
EDA_ITEM_FLAGS aItem_editFlags = aItem->GetEditFlags();
EDA_ITEM_FLAGS aItem_tempFlags = aItem->GetTempFlags();
std::swap( m_flags, aItem->m_flags );
ClearEditFlags();
SetFlags( editFlags );
ClearTempFlags();
SetFlags( tempFlags );
aItem->ClearEditFlags();
aItem->SetFlags( aItem_editFlags );
aItem->ClearTempFlags();
aItem->SetFlags( aItem_tempFlags );
}
void SCH_ITEM::ClearCaches()
{
auto clearTextCaches =

View File

@ -189,6 +189,11 @@ public:
*/
virtual void SwapData( SCH_ITEM* aItem );
/**
* Swap the non-temp and non-edit flags.
*/
void SwapFlags( SCH_ITEM* aItem );
/**
* Routine to create a new copy of given item.
* The new object is not put in draw list (not linked).

View File

@ -60,6 +60,8 @@ EDA_ITEM* SCH_JUNCTION::Clone() const
void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ),
wxT( "Cannot swap junction data with invalid item." ) );

View File

@ -1212,6 +1212,7 @@ SCH_DIRECTIVE_LABEL::SCH_DIRECTIVE_LABEL( const VECTOR2I& pos ) :
void SCH_DIRECTIVE_LABEL::SwapData( SCH_ITEM* aItem )
{
SCH_LABEL_BASE::SwapData( aItem );
SCH_DIRECTIVE_LABEL* label = static_cast<SCH_DIRECTIVE_LABEL*>( aItem );
std::swap( m_pinLength, label->m_pinLength );

View File

@ -837,6 +837,8 @@ bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) con
void SCH_LINE::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
SCH_LINE* item = (SCH_LINE*) aItem;
std::swap( m_layer, item->m_layer );

View File

@ -56,6 +56,8 @@ EDA_ITEM* SCH_NO_CONNECT::Clone() const
void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
wxT( "Cannot swap no connect data with invalid item." ) );

View File

@ -2783,7 +2783,7 @@ void SCH_PAINTER::draw( const SCH_HIERLABEL* aLabel, int aLayer )
m_gal->SetIsFill( true );
m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getTextThickness( aLabel ) );
m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
m_gal->SetStrokeColor( color );
m_gal->DrawPolyline( pts2 );

View File

@ -51,6 +51,8 @@ EDA_ITEM* SCH_SHAPE::Clone() const
void SCH_SHAPE::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
EDA_SHAPE::SwapShape( shape );

View File

@ -311,6 +311,8 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in
void SCH_SHEET::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( aItem->Type() == SCH_SHEET_T,
wxString::Format( wxT( "SCH_SHEET object cannot swap data with %s object." ),
aItem->GetClass() ) );

View File

@ -74,13 +74,14 @@ void SCH_SHEET_PIN::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOf
void SCH_SHEET_PIN::SwapData( SCH_ITEM* aItem )
{
SCH_HIERLABEL::SwapData( aItem );
wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
wxString::Format( "SCH_SHEET_PIN object cannot swap data with %s object.",
aItem->GetClass() ) );
SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( aItem );
SCH_HIERLABEL::SwapData( pin );
std::swap( m_number, pin->m_number );
std::swap( m_edge, pin->m_edge );
}

View File

@ -1119,6 +1119,8 @@ std::vector<SCH_PIN*> SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet ) const
void SCH_SYMBOL::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( aItem != nullptr && aItem->Type() == SCH_SYMBOL_T,
wxT( "Cannot swap data with invalid symbol." ) );

View File

@ -230,6 +230,8 @@ void SCH_TEXT::SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle )
void SCH_TEXT::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
SCH_TEXT* item = static_cast<SCH_TEXT*>( aItem );
std::swap( m_layer, item->m_layer );

View File

@ -186,14 +186,14 @@ VECTOR2I SCH_TEXTBOX::GetDrawPos() const
void SCH_TEXTBOX::SwapData( SCH_ITEM* aItem )
{
SCH_SHAPE::SwapData( aItem );
SCH_TEXTBOX* item = static_cast<SCH_TEXTBOX*>( aItem );
std::swap( m_layer, item->m_layer );
SwapText( *item );
SwapAttributes( *item );
SCH_SHAPE::SwapData( aItem );
}

View File

@ -1224,7 +1224,7 @@ int SCH_EDITOR_CONTROL::Undo( const TOOL_EVENT& aEvent )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
m_frame->SyncView();
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();
return 0;
@ -1255,7 +1255,6 @@ int SCH_EDITOR_CONTROL::Redo( const TOOL_EVENT& aEvent )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
m_frame->SyncView();
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();

View File

@ -134,16 +134,23 @@ public:
return m_flags & mask;
}
void ClearTempFlags()
{
ClearFlags( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
}
void ClearEditFlags()
{
ClearFlags( GetEditFlags() );
}
EDA_ITEM_FLAGS GetTempFlags() const
{
constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
return m_flags & mask;
}
void ClearTempFlags()
{
ClearFlags( GetTempFlags() );
}
virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
void SetIsShownAsBitmap( bool aBitmap )