Update SCH_SCREEN's RTree when moving items.

Or when modifying geometric shape/properties.

Fixes https://gitlab.com/kicad/code/kicad/issues/5922
This commit is contained in:
Jeff Young 2020-10-30 15:15:20 +00:00
parent 45618327cf
commit 9065908859
7 changed files with 49 additions and 48 deletions

View File

@ -321,7 +321,7 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
m_editedPoint->SetPosition( controls->GetCursorPosition( snap ) ); m_editedPoint->SetPosition( controls->GetCursorPosition( snap ) );
updateItem(); updateParentItem();
updatePoints(); updatePoints();
} }
@ -464,7 +464,7 @@ static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
} }
void EE_POINT_EDITOR::updateItem() const void EE_POINT_EDITOR::updateParentItem() const
{ {
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
@ -637,7 +637,7 @@ void EE_POINT_EDITOR::updateItem() const
break; break;
} }
updateView( item ); updateItem( item, true );
m_frame->SetMsgPanel( item ); m_frame->SetMsgPanel( item );
} }
@ -831,7 +831,7 @@ int EE_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) ); VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
polyLine->AddCorner( mapCoords( cursorPos ) ); polyLine->AddCorner( mapCoords( cursorPos ) );
updateView( polyLine ); updateItem( polyLine, true );
updatePoints(); updatePoints();
return 0; return 0;
@ -850,7 +850,7 @@ int EE_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
polyLine->RemoveCorner( getEditedPointIndex() ); polyLine->RemoveCorner( getEditedPointIndex() );
updateView( polyLine ); updateItem( polyLine, true );
updatePoints(); updatePoints();
return 0; return 0;

View File

@ -61,7 +61,7 @@ public:
private: private:
///> Updates item's points with edit points. ///> Updates item's points with edit points.
void updateItem() const; void updateParentItem() const;
///> Updates edit points with item's points. ///> Updates edit points with item's points.
void updatePoints(); void updatePoints();

View File

@ -100,17 +100,38 @@ public:
} }
protected: protected:
///> Similar to getView()->Update(), but handles items that are redrawn by their parents. /**
void updateView( EDA_ITEM* aItem ) const * Similar to getView()->Update(), but handles items that are redrawn by their parents
* and updating the SCH_SCREEN's RTree.
*/
void updateItem( EDA_ITEM* aItem, bool aUpdateRTree ) const
{ {
KICAD_T itemType = aItem->Type(); switch( aItem->Type() )
{
if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T ) case SCH_SHEET_PIN_T:
getView()->Update( aItem );
getView()->Update( aItem->GetParent() ); getView()->Update( aItem->GetParent() );
getView()->Update( aItem ); // Moving sheet pins does not change the BBox.
} break;
case SCH_PIN_T:
case SCH_FIELD_T:
getView()->Update( aItem );
getView()->Update( aItem->GetParent() );
if( aUpdateRTree )
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( aItem->GetParent() ) );
break;
default:
getView()->Update( aItem );
if( aUpdateRTree )
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( aItem ) );
}
}
///> Similar to m_frame->SaveCopyInUndoList(), but handles items that are owned by their ///> Similar to m_frame->SaveCopyInUndoList(), but handles items that are owned by their
///> parents. ///> parents.

View File

@ -453,7 +453,7 @@ void LIB_EDIT_TOOL::editGraphicProperties( LIB_ITEM* aItem )
else else
aItem->SetUnit( m_frame->GetUnit() ); aItem->SetUnit( m_frame->GetUnit() );
updateView( aItem ); updateItem( aItem, true );
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
m_frame->OnModify( ); m_frame->OnModify( );
@ -477,7 +477,7 @@ void LIB_EDIT_TOOL::editTextProperties( LIB_ITEM* aItem )
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return; return;
updateView( aItem ); updateItem( aItem, true );
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
m_frame->OnModify( ); m_frame->OnModify( );
} }
@ -524,7 +524,7 @@ void LIB_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
} }
else else
{ {
updateView( aField ); updateItem( aField, true );
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
m_frame->OnModify(); m_frame->OnModify();
m_frame->DisplayCmpDoc(); m_frame->DisplayCmpDoc();

View File

@ -151,7 +151,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection ) for( EDA_ITEM* item : selection )
{ {
moveItem( item, delta ); moveItem( item, delta );
updateView( item ); updateItem( item, false );
} }
m_anchorPos = m_cursor; m_anchorPos = m_cursor;
@ -191,7 +191,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection ) for( EDA_ITEM* item : selection )
{ {
moveItem( item, delta ); moveItem( item, delta );
updateView( item ); updateItem( item, false );
} }
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved ); m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );

View File

@ -1055,7 +1055,7 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
saveCopyInUndoList( item, UNDO_REDO::DELETED, appendToUndo ); saveCopyInUndoList( item, UNDO_REDO::DELETED, appendToUndo );
appendToUndo = true; appendToUndo = true;
updateView( sch_item ); updateItem( sch_item, false );
if( sch_item->Type() == SCH_SHEET_PIN_T ) if( sch_item->Type() == SCH_SHEET_PIN_T )
{ {
@ -1282,8 +1282,7 @@ int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
sheet->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); sheet->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true );
} }
m_frame->GetScreen()->Update( item ); updateItem( item, true );
updateView( item );
m_frame->OnModify(); m_frame->OnModify();
if( selection.IsHover() ) if( selection.IsHover() )
@ -1593,8 +1592,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
wxFAIL_MSG( wxString( "Cannot edit schematic item type " ) + item->GetClass() ); wxFAIL_MSG( wxString( "Cannot edit schematic item type " ) + item->GetClass() );
} }
m_frame->GetScreen()->Update( item ); updateItem( item, true );
updateView( item );
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
@ -1741,8 +1739,7 @@ int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent )
sheet->CleanupSheet(); sheet->CleanupSheet();
m_frame->GetScreen()->Update( sheet ); updateItem( sheet, true );
updateView( sheet );
m_frame->OnModify(); m_frame->OnModify();
if( selection.IsHover() ) if( selection.IsHover() )

View File

@ -298,7 +298,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
continue; continue;
moveItem( item, delta ); moveItem( item, delta );
updateView( item ); updateItem( item, false );
} }
m_anchorPos = m_cursor; m_anchorPos = m_cursor;
@ -355,7 +355,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
continue; continue;
moveItem( item, delta ); moveItem( item, delta );
updateView( item ); updateItem( item, false );
} }
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved ); m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
@ -456,26 +456,9 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
} }
else else
{ {
// Moving items changes the RTree box bounds. // One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree).
for( auto item : selection ) for( auto item : selection )
{ updateItem( item, true );
switch( item->Type() )
{
// Moving sheet pins does not change the BBox.
case SCH_SHEET_PIN_T:
break;
// Moving fields should update the associated component
case SCH_FIELD_T:
if( item->GetParent() )
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item->GetParent() ) );
break;
default:
m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item ) );
}
}
// If we move items away from a junction, we _may_ want to add a junction there // If we move items away from a junction, we _may_ want to add a junction there
// to denote the state. // to denote the state.
@ -802,7 +785,7 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
append_undo = true; append_undo = true;
moveItem( dritem, gridpt ); moveItem( dritem, gridpt );
updateView( dritem ); updateItem( dritem, true );
} }
} }
@ -845,7 +828,7 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
append_undo = true; append_undo = true;
moveItem( dritem, most_common ); moveItem( dritem, most_common );
updateView( dritem ); updateItem( dritem, true );
} }
} }
} }