Libedit: Fix a few places where item could be NULL
Fixes: lp:1761058 * https://bugs.launchpad.net/kicad/+bug/1761058
This commit is contained in:
parent
bbb513e2e5
commit
d1af5210e0
|
@ -804,7 +804,7 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
|
|||
break;
|
||||
|
||||
case HK_LIBEDIT_MOVE_GRAPHIC_ITEM:
|
||||
if( !itemInEdit )
|
||||
if( !itemInEdit && !blocInProgress )
|
||||
{
|
||||
SetDrawItem( LocateItemUsingCursor( aPosition ) );
|
||||
|
||||
|
@ -817,7 +817,7 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
|
|||
break;
|
||||
|
||||
case HK_DRAG:
|
||||
if( !itemInEdit )
|
||||
if( !itemInEdit && !blocInProgress )
|
||||
{
|
||||
SetDrawItem( LocateItemUsingCursor( aPosition ) );
|
||||
|
||||
|
@ -833,16 +833,22 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
|
|||
if( !itemInEdit )
|
||||
SetDrawItem( LocateItemUsingCursor( aPosition ) );
|
||||
|
||||
cmd.SetId( ID_LIBEDIT_MIRROR_Y );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
if( GetDrawItem() )
|
||||
{
|
||||
cmd.SetId( ID_LIBEDIT_MIRROR_Y );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
}
|
||||
break;
|
||||
|
||||
case HK_MIRROR_X: // Mirror X
|
||||
if( !itemInEdit )
|
||||
SetDrawItem( LocateItemUsingCursor( aPosition ) );
|
||||
|
||||
cmd.SetId( ID_LIBEDIT_MIRROR_X );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
if( GetDrawItem() )
|
||||
{
|
||||
cmd.SetId( ID_LIBEDIT_MIRROR_X );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -835,7 +835,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
case ID_POPUP_LIBEDIT_DELETE_ITEM:
|
||||
if( item )
|
||||
deleteItem( &dc );
|
||||
deleteItem( &dc, item );
|
||||
|
||||
break;
|
||||
|
||||
|
@ -844,9 +844,9 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
break;
|
||||
|
||||
if( item->Type() == LIB_PIN_T )
|
||||
StartMovePin( &dc );
|
||||
StartMovePin( item );
|
||||
else
|
||||
StartMoveDrawSymbol( &dc );
|
||||
StartMoveDrawSymbol( &dc, item );
|
||||
break;
|
||||
|
||||
case ID_POPUP_LIBEDIT_MODIFY_ITEM:
|
||||
|
@ -861,7 +861,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|| item->Type() == LIB_ARC_T
|
||||
)
|
||||
{
|
||||
StartModifyDrawSymbol( &dc );
|
||||
StartModifyDrawSymbol( &dc, item );
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -1377,11 +1377,10 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF
|
|||
}
|
||||
|
||||
|
||||
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
|
||||
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC, LIB_ITEM* aItem )
|
||||
{
|
||||
LIB_ITEM* item = GetDrawItem();
|
||||
|
||||
wxCHECK_RET( item != NULL, "No drawing item selected to delete." );
|
||||
if( !aItem )
|
||||
return;
|
||||
|
||||
m_canvas->CrossHairOff( aDC );
|
||||
|
||||
|
@ -1389,9 +1388,9 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
|
|||
|
||||
SaveCopyInUndoList( part );
|
||||
|
||||
if( item->Type() == LIB_PIN_T )
|
||||
if( aItem->Type() == LIB_PIN_T )
|
||||
{
|
||||
LIB_PIN* pin = static_cast<LIB_PIN*>( item );
|
||||
LIB_PIN* pin = static_cast<LIB_PIN*>( aItem );
|
||||
wxPoint pos = pin->GetPosition();
|
||||
|
||||
part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
|
||||
|
@ -1428,7 +1427,7 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
|
|||
}
|
||||
else
|
||||
{
|
||||
part->RemoveDrawItem( item, m_canvas, aDC );
|
||||
part->RemoveDrawItem( aItem, m_canvas, aDC );
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -551,8 +551,9 @@ private:
|
|||
* Deletes the currently selected draw item.
|
||||
*
|
||||
* @param aDC The device context to draw upon when removing item.
|
||||
* @param aItem The item to delete
|
||||
*/
|
||||
void deleteItem( wxDC* aDC );
|
||||
void deleteItem( wxDC* aDC, LIB_ITEM* aItem );
|
||||
|
||||
// General editing
|
||||
public:
|
||||
|
@ -570,7 +571,13 @@ private:
|
|||
|
||||
// Editing pins
|
||||
void CreatePin( wxDC* DC );
|
||||
void StartMovePin( wxDC* DC );
|
||||
|
||||
/**
|
||||
* Prepare the displacement of a pin
|
||||
*
|
||||
* @param aPin the pin to prepare for movement.
|
||||
*/
|
||||
void StartMovePin( LIB_ITEM* aPin );
|
||||
|
||||
/**
|
||||
* Adds copies of \a aPin in components with multiple units in all units
|
||||
|
@ -590,8 +597,8 @@ private:
|
|||
// Editing graphic items
|
||||
LIB_ITEM* CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC );
|
||||
void GraphicItemBeginDraw( wxDC* DC );
|
||||
void StartMoveDrawSymbol( wxDC* DC );
|
||||
void StartModifyDrawSymbol( wxDC* DC ); //<! Modify the item, adjust size etc.
|
||||
void StartMoveDrawSymbol( wxDC* DC, LIB_ITEM* aItem );
|
||||
void StartModifyDrawSymbol( wxDC* DC, LIB_ITEM* aItem ); //<! Modify the item, adjust size etc.
|
||||
void EndDrawGraphicItem( wxDC* DC );
|
||||
|
||||
/**
|
||||
|
|
|
@ -119,8 +119,7 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
|
|||
|
||||
if( item )
|
||||
{
|
||||
SetDrawItem( item );
|
||||
deleteItem( DC );
|
||||
deleteItem( DC, item );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -324,16 +324,10 @@ void LIB_EDIT_FRAME::PlacePin()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the displacement of a pin
|
||||
*
|
||||
* Locate the pin pointed to by the cursor, and set the cursor management
|
||||
* function move the pin.
|
||||
*/
|
||||
void LIB_EDIT_FRAME::StartMovePin( wxDC* DC )
|
||||
void LIB_EDIT_FRAME::StartMovePin( LIB_ITEM* aItem )
|
||||
{
|
||||
LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem();
|
||||
wxPoint startPos;
|
||||
LIB_PIN* cur_pin = (LIB_PIN*) aItem;
|
||||
wxPoint startPos;
|
||||
|
||||
TempCopyComponent();
|
||||
|
||||
|
@ -472,7 +466,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
|
|||
|
||||
if( pin->GetFlags() & IS_CANCELLED )
|
||||
{
|
||||
deleteItem( DC );
|
||||
deleteItem( DC, pin );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -292,11 +292,9 @@ static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
|
|||
}
|
||||
|
||||
|
||||
void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC )
|
||||
void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC, LIB_ITEM* aItem )
|
||||
{
|
||||
LIB_ITEM* item = GetDrawItem();
|
||||
|
||||
if( item == NULL )
|
||||
if( aItem == NULL )
|
||||
return;
|
||||
|
||||
SetCursor( wxCURSOR_HAND );
|
||||
|
@ -305,25 +303,23 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC )
|
|||
|
||||
// For fields only, move the anchor point of the field
|
||||
// to the cursor position to allow user to see the text justification
|
||||
if( item->Type() == LIB_FIELD_T )
|
||||
item->BeginEdit( IS_MOVED, item->GetPosition() );
|
||||
if( aItem->Type() == LIB_FIELD_T )
|
||||
aItem->BeginEdit( IS_MOVED, aItem->GetPosition() );
|
||||
else
|
||||
item->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) );
|
||||
aItem->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) );
|
||||
|
||||
m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn );
|
||||
m_canvas->CallMouseCapture( DC, wxDefaultPosition, true );
|
||||
}
|
||||
|
||||
|
||||
void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC )
|
||||
void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC, LIB_ITEM* aItem )
|
||||
{
|
||||
LIB_ITEM* item = GetDrawItem();
|
||||
|
||||
if( item == NULL )
|
||||
if( aItem == NULL )
|
||||
return;
|
||||
|
||||
TempCopyComponent();
|
||||
item->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) );
|
||||
aItem->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) );
|
||||
m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn );
|
||||
m_canvas->CallMouseCapture( DC, wxDefaultPosition, true );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue