More data validity checks in POINT_EDITOR

Fixes: lp:1690658
* https://bugs.launchpad.net/kicad/+bug/1690658
This commit is contained in:
Maciej Suminski 2017-05-16 11:38:00 +02:00
parent 4336db3a7c
commit 499eabceb4
1 changed files with 28 additions and 7 deletions

View File

@ -87,6 +87,9 @@ public:
{ {
std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem ); std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
if( !aItem )
return points;
// Generate list of edit points basing on the item type // Generate list of edit points basing on the item type
switch( aItem->Type() ) switch( aItem->Type() )
{ {
@ -274,12 +277,16 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
view->Add( m_editPoints.get() ); view->Add( m_editPoints.get() );
m_editedPoint = NULL; m_editedPoint = NULL;
bool modified = false; bool modified = false;
bool revert = false;
BOARD_COMMIT commit( editFrame ); BOARD_COMMIT commit( editFrame );
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
if( revert )
break;
if( !m_editPoints || if( !m_editPoints ||
evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->ClearedEvent ) ||
evt->Matches( m_selectionTool->UnselectedEvent ) || evt->Matches( m_selectionTool->UnselectedEvent ) ||
@ -336,16 +343,13 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
else if( evt->IsCancel() ) else if( evt->IsCancel() )
{ {
if( modified ) // Restore the last change if( modified ) // Restore the last change
{ revert = true;
commit.Revert();
updatePoints();
modified = false;
}
// Let the selection tool receive the event too // Let the selection tool receive the event too
m_toolMgr->PassEvent(); m_toolMgr->PassEvent();
break; // Do not exit right now, let the selection clear the selection
//break;
} }
else else
@ -356,8 +360,13 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
if( m_editPoints ) if( m_editPoints )
{ {
finishItem();
view->Remove( m_editPoints.get() ); view->Remove( m_editPoints.get() );
if( modified && revert )
commit.Revert();
else
finishItem();
m_editPoints.reset(); m_editPoints.reset();
} }
@ -369,6 +378,9 @@ void POINT_EDITOR::updateItem() const
{ {
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
if( !item )
return;
switch( item->Type() ) switch( item->Type() )
{ {
case PCB_LINE_T: case PCB_LINE_T:
@ -529,6 +541,9 @@ void POINT_EDITOR::finishItem() const
{ {
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
if( !item )
return;
if( item->Type() == PCB_ZONE_AREA_T ) if( item->Type() == PCB_ZONE_AREA_T )
{ {
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item ); ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
@ -549,6 +564,9 @@ void POINT_EDITOR::updatePoints()
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
if( !item )
return;
switch( item->Type() ) switch( item->Type() )
{ {
case PCB_LINE_T: case PCB_LINE_T:
@ -887,6 +905,9 @@ int POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
if( !item )
return 0;
if( item->Type() == PCB_ZONE_AREA_T ) if( item->Type() == PCB_ZONE_AREA_T )
{ {
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();