Fix crash bug when deleting sheet pin and disappearing bug when moving them.

Fixes: lp:1827890
* https://bugs.launchpad.net/kicad/+bug/1827890
This commit is contained in:
Jeff Young 2019-05-06 16:30:29 +01:00
parent 13beb344ca
commit b97d65e791
7 changed files with 39 additions and 44 deletions

View File

@ -123,8 +123,8 @@ bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool
if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aStart ) )
line = return_line;
SaveCopyInUndoList( (SCH_ITEM*)line, UR_DELETED, aAppend );
RemoveFromScreen( (SCH_ITEM*)line );
SaveCopyInUndoList( line, UR_DELETED, aAppend );
RemoveFromScreen( line );
aAppend = true;
retval = true;

View File

@ -609,7 +609,7 @@ void SCH_BASE_FRAME::createCanvas()
}
void SCH_BASE_FRAME::RefreshItem( SCH_ITEM* aItem, bool isAddOrDelete )
void SCH_BASE_FRAME::RefreshItem( EDA_ITEM* aItem, bool isAddOrDelete )
{
EDA_ITEM* parent = aItem->GetParent();
@ -633,14 +633,14 @@ void SCH_BASE_FRAME::RefreshItem( SCH_ITEM* aItem, bool isAddOrDelete )
}
void SCH_BASE_FRAME::AddToScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen )
void SCH_BASE_FRAME::AddToScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen )
{
auto screen = aScreen;
if( aScreen == nullptr )
screen = GetScreen();
screen->Append( aItem );
screen->Append( (SCH_ITEM*) aItem );
if( screen == GetScreen() )
{
@ -650,7 +650,7 @@ void SCH_BASE_FRAME::AddToScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen )
}
void SCH_BASE_FRAME::RemoveFromScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen )
void SCH_BASE_FRAME::RemoveFromScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen )
{
auto screen = aScreen;
@ -660,7 +660,7 @@ void SCH_BASE_FRAME::RemoveFromScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen )
if( screen == GetScreen() )
GetCanvas()->GetView()->Remove( aItem );
screen->Remove( aItem );
screen->Remove( (SCH_ITEM*) aItem );
if( screen == GetScreen() )
RefreshItem( aItem, true ); // handle any additional parent semantics

View File

@ -306,18 +306,18 @@ public:
* Add an item to the screen (and view)
* aScreen is the screen the item is located on, if not the current screen
*/
void AddToScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen = nullptr );
void AddToScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen = nullptr );
/**
* Remove an item from the screen (and view)
* aScreen is the screen the item is located on, if not the current screen
*/
void RemoveFromScreen( SCH_ITEM* aItem, SCH_SCREEN* aScreen = nullptr );
void RemoveFromScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen = nullptr );
/**
* Mark an item for refresh.
*/
void RefreshItem( SCH_ITEM* aItem, bool isAddOrDelete = false );
void RefreshItem( EDA_ITEM* aItem, bool isAddOrDelete = false );
/**
* Mark all items for refresh.

View File

@ -1320,28 +1320,25 @@ void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
{
for( auto& sheetPin : aSheet->GetPins() )
{
if( !sheetPin.IsMoving() )
// For aesthetic reasons, the SHEET_PIN is drawn with a small offset
// of width / 2
int width = aSheet->GetPenSize();
wxPoint initial_pos = sheetPin.GetTextPos();
wxPoint offset_pos = initial_pos;
switch( sheetPin.GetEdge() )
{
// For aesthetic reasons, the SHEET_PIN is drawn with a small offset
// of width / 2
int width = aSheet->GetPenSize();
wxPoint initial_pos = sheetPin.GetTextPos();
wxPoint offset_pos = initial_pos;
switch( sheetPin.GetEdge() )
{
case SCH_SHEET_PIN::SHEET_TOP_SIDE: offset_pos.y -= width / 2; break;
case SCH_SHEET_PIN::SHEET_BOTTOM_SIDE: offset_pos.y += width / 2; break;
case SCH_SHEET_PIN::SHEET_RIGHT_SIDE: offset_pos.x -= width / 2; break;
case SCH_SHEET_PIN::SHEET_LEFT_SIDE: offset_pos.x += width / 2; break;
default: break;
}
sheetPin.SetTextPos( offset_pos );
draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
m_gal->DrawLine( offset_pos, initial_pos );
sheetPin.SetTextPos( initial_pos );
case SCH_SHEET_PIN::SHEET_TOP_SIDE: offset_pos.y -= width / 2; break;
case SCH_SHEET_PIN::SHEET_BOTTOM_SIDE: offset_pos.y += width / 2; break;
case SCH_SHEET_PIN::SHEET_RIGHT_SIDE: offset_pos.x -= width / 2; break;
case SCH_SHEET_PIN::SHEET_LEFT_SIDE: offset_pos.x += width / 2; break;
default: break;
}
sheetPin.SetTextPos( offset_pos );
draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
m_gal->DrawLine( offset_pos, initial_pos );
sheetPin.SetTextPos( initial_pos );
}
}
}

View File

@ -926,10 +926,7 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
saveCopyInUndoList( item, UR_DELETED, appendToUndo );
appendToUndo = true;
if( item->Type() == SCH_SHEET_PIN_T )
static_cast<SCH_SHEET*>( item->GetParent() )->RemovePin( (SCH_SHEET_PIN*) item );
else
m_frame->RemoveFromScreen( (SCH_ITEM*) item );
updateView( item );
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
@ -946,7 +943,10 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
}
}
updateView( (SCH_ITEM*) item );
if( item->Type() == SCH_SHEET_PIN_T )
static_cast<SCH_SHEET*>( item->GetParent() )->RemovePin( (SCH_SHEET_PIN*) item );
else
m_frame->RemoveFromScreen( item );
}
}

View File

@ -262,7 +262,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
// Apply any initial offset in case we're coming from a previous command.
//
moveItem( (SCH_ITEM*) item, m_moveOffset, m_frame->GetToolId() == ID_SCH_DRAG );
moveItem( item, m_moveOffset, m_frame->GetToolId() == ID_SCH_DRAG );
}
// Set up the starting position and move/drag offset
@ -274,10 +274,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
VECTOR2I delta = m_cursor - selection.GetReferencePoint();
// Drag items to the current cursor position
for( int i = 0; i < selection.GetSize(); ++i )
for( EDA_ITEM* item : selection )
{
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetItem( i ) );
// Don't double move pins, fields, etc.
if( item->GetParent() && item->GetParent()->IsSelected() )
continue;
@ -323,7 +321,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
if( item->GetParent() && item->GetParent()->IsSelected() )
continue;
moveItem( (SCH_ITEM*) item, delta, m_frame->GetToolId() == ID_SCH_DRAG );
moveItem( item, delta, m_frame->GetToolId() == ID_SCH_DRAG );
updateView( item );
}
@ -566,7 +564,7 @@ void SCH_MOVE_TOOL::addJunctionsIfNeeded( SELECTION& aSelection, bool* aAppendUn
}
void SCH_MOVE_TOOL::moveItem( SCH_ITEM* aItem, VECTOR2I aDelta, bool isDrag )
void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta, bool isDrag )
{
switch( aItem->Type() )
{
@ -581,11 +579,11 @@ void SCH_MOVE_TOOL::moveItem( SCH_ITEM* aItem, VECTOR2I aDelta, bool isDrag )
case SCH_PIN_T:
case SCH_FIELD_T:
aItem->Move( wxPoint( aDelta.x, -aDelta.y ) );
static_cast<SCH_ITEM*>( aItem )->Move( wxPoint( aDelta.x, -aDelta.y ) );
break;
default:
aItem->Move( (wxPoint) aDelta );
static_cast<SCH_ITEM*>( aItem )->Move( (wxPoint) aDelta );
break;
}

View File

@ -56,7 +56,7 @@ public:
int Main( const TOOL_EVENT& aEvent );
private:
void moveItem( SCH_ITEM* aItem, VECTOR2I aDelta, bool isDrag );
void moveItem( EDA_ITEM* aItem, VECTOR2I aDelta, bool isDrag );
///> Finds additional items for a drag operation.
///> Connected items with no wire are included (as there is no wire to adjust for the drag).