Update ratsnest on footprint change (GAL).

This commit is contained in:
Maciej Suminski 2015-07-28 17:33:18 +02:00
parent 5402bf0960
commit c632f3db18
2 changed files with 66 additions and 99 deletions

View File

@ -392,21 +392,19 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
item->ClearFlags(); item->ClearFlags();
// It is necessary to determine if anything has changed // It is necessary to determine if anything has changed
PICKED_ITEMS_LIST* lastChange = undoList.empty() ? NULL : undoList.back(); unsigned int oldSize = undoList.size();
// Display properties dialog provided by the legacy canvas frame // Display properties dialog provided by the legacy canvas frame
editFrame->OnEditItemRequest( NULL, item ); editFrame->OnEditItemRequest( NULL, item );
PICKED_ITEMS_LIST* currentChange = undoList.empty() ? NULL : undoList.back(); for( unsigned int i = oldSize; i < undoList.size(); ++i )
processChanges( undoList[i] );
if( lastChange != currentChange ) // Something has changed if( oldSize != undoList.size() ) // Something has changed
{ {
processChanges( currentChange );
item->ViewUpdate(); item->ViewUpdate();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest(); RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
ratsnest->Update( item );
ratsnest->Recalculate(); ratsnest->Recalculate();
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
@ -1044,14 +1042,20 @@ bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize )
void EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList ) void EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList )
{ {
KIGFX::VIEW* view = getView();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
for( unsigned int i = 0; i < aList->GetCount(); ++i ) for( unsigned int i = 0; i < aList->GetCount(); ++i )
{ {
UNDO_REDO_T operation = aList->GetPickedItemStatus( i ); UNDO_REDO_T operation = aList->GetPickedItemStatus( i );
EDA_ITEM* updItem = aList->GetPickedItem( i ); BOARD_ITEM* updItem = static_cast<BOARD_ITEM*>( aList->GetPickedItem( i ) );
switch( operation ) switch( operation )
{ {
case UR_CHANGED: case UR_CHANGED:
ratsnest->Update( updItem );
// fall through
case UR_MODEDIT: case UR_MODEDIT:
updItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); updItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
break; break;
@ -1059,18 +1063,19 @@ void EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList )
case UR_DELETED: case UR_DELETED:
if( updItem->Type() == PCB_MODULE_T ) if( updItem->Type() == PCB_MODULE_T )
static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove,
getView(), _1 ) ); view, _1 ) );
getView()->Remove( updItem ); view->Remove( updItem );
//ratsnest->Remove( updItem ); // this is done in BOARD::Remove
break; break;
case UR_NEW: case UR_NEW:
if( updItem->Type() == PCB_MODULE_T ) if( updItem->Type() == PCB_MODULE_T )
static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add,
getView(), _1 ) ); view, _1 ) );
getView()->Add( updItem ); view->Add( updItem );
updItem->ViewUpdate(); //ratsnest->Add( updItem ); // this is done in BOARD::Add
break; break;
default: default:

View File

@ -45,11 +45,6 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <kiway.h> #include <kiway.h>
#include <boost/bind.hpp>
#include <tool/tool_manager.h>
#include <tools/common_actions.h>
static bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName ); static bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName );
@ -73,13 +68,14 @@ private:
void RebuildCmpList( wxCommandEvent& event ); void RebuildCmpList( wxCommandEvent& event );
void init(); void init();
void ChangeCurrentFootprint(); bool changeCurrentFootprint();
void ChangeSameFootprints( bool aUseValue); bool changeSameFootprints( bool aUseValue);
void ChangeAllFootprints(); bool changeAllFootprints();
bool Change_1_Module( MODULE* aModule, bool change_1_Module( MODULE* aModule,
const FPID& aNewFootprintFPID, const FPID& aNewFootprintFPID,
PICKED_ITEMS_LIST* aUndoPickList,
bool eShowError ); bool eShowError );
PICKED_ITEMS_LIST m_undoPickList;
}; };
int DIALOG_EXCHANGE_MODULE::m_selectionMode = 0; int DIALOG_EXCHANGE_MODULE::m_selectionMode = 0;
@ -128,26 +124,39 @@ void DIALOG_EXCHANGE_MODULE::init()
void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event ) void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event )
{ {
m_undoPickList.ClearItemsList();
m_selectionMode = m_Selection->GetSelection(); m_selectionMode = m_Selection->GetSelection();
bool result = false;
switch( m_Selection->GetSelection() ) switch( m_Selection->GetSelection() )
{ {
case 0: case 0:
ChangeCurrentFootprint(); result = changeCurrentFootprint();
break; break;
case 1: case 1:
ChangeSameFootprints( false ); result = changeSameFootprints( false );
break; break;
case 2: case 2:
ChangeSameFootprints( true ); result = changeSameFootprints( true );
break; break;
case 3: case 3:
ChangeAllFootprints(); result = changeAllFootprints();
break; break;
} }
if( result )
{
if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_parent->Compile_Ratsnest( NULL, true );
m_parent->GetCanvas()->Refresh();
}
if( m_undoPickList.GetCount() )
m_parent->SaveCopyInUndoList( m_undoPickList, UR_UNSPECIFIED );
} }
@ -207,25 +216,14 @@ void DIALOG_EXCHANGE_MODULE::RebuildCmpList( wxCommandEvent& event )
* - value and ref * - value and ref
* - pads net names * - pads net names
*/ */
void DIALOG_EXCHANGE_MODULE::ChangeCurrentFootprint() bool DIALOG_EXCHANGE_MODULE::changeCurrentFootprint()
{ {
wxString newmodulename = m_NewModule->GetValue(); wxString newmodulename = m_NewModule->GetValue();
if( newmodulename == wxEmptyString ) if( newmodulename == wxEmptyString )
return; return false;
PICKED_ITEMS_LIST pickList; return change_1_Module( m_currentModule, newmodulename, true );
if( Change_1_Module( m_currentModule, newmodulename, &pickList, true ) )
{
if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_parent->Compile_Ratsnest( NULL, true );
m_parent->GetCanvas()->Refresh();
}
if( pickList.GetCount() )
m_parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
@ -240,10 +238,11 @@ void DIALOG_EXCHANGE_MODULE::ChangeCurrentFootprint()
* if aUseValue is true, footprints having the same fpid should * if aUseValue is true, footprints having the same fpid should
* also have the same value * also have the same value
*/ */
void DIALOG_EXCHANGE_MODULE::ChangeSameFootprints( bool aUseValue ) bool DIALOG_EXCHANGE_MODULE::changeSameFootprints( bool aUseValue )
{ {
wxString msg; wxString msg;
MODULE* Module, * PtBack; MODULE* Module;
MODULE* PtBack;
bool change = false; bool change = false;
wxString newmodulename = m_NewModule->GetValue(); wxString newmodulename = m_NewModule->GetValue();
wxString value; wxString value;
@ -252,10 +251,10 @@ void DIALOG_EXCHANGE_MODULE::ChangeSameFootprints( bool aUseValue )
int ShowErr = 3; // Post 3 error messages max. int ShowErr = 3; // Post 3 error messages max.
if( m_parent->GetBoard()->m_Modules == NULL ) if( m_parent->GetBoard()->m_Modules == NULL )
return; return false;
if( newmodulename == wxEmptyString ) if( newmodulename == wxEmptyString )
return; return false;
lib_reference = m_currentModule->GetFPID(); lib_reference = m_currentModule->GetFPID();
@ -276,14 +275,12 @@ void DIALOG_EXCHANGE_MODULE::ChangeSameFootprints( bool aUseValue )
} }
if( !IsOK( this, msg ) ) if( !IsOK( this, msg ) )
return; return false;
/* The change is done from the last module because /* The change is done from the last module because
* Change_1_Module () modifies the last item in the list. * change_1_Module () modifies the last item in the list.
*/ *
PICKED_ITEMS_LIST pickList; * note: for the first module in chain (the last here), Module->Back()
/* note: for the first module in chain (the last here), Module->Back()
* points the board or is NULL * points the board or is NULL
*/ */
Module = m_parent->GetBoard()->m_Modules.GetLast(); Module = m_parent->GetBoard()->m_Modules.GetLast();
@ -301,22 +298,13 @@ void DIALOG_EXCHANGE_MODULE::ChangeSameFootprints( bool aUseValue )
continue; continue;
} }
if( Change_1_Module( Module, newmodulename, &pickList, ShowErr ) ) if( change_1_Module( Module, newmodulename, ShowErr ) )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
ShowErr--; ShowErr--;
} }
if( change ) return change;
{
if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_parent->Compile_Ratsnest( NULL, true );
m_parent->GetCanvas()->Refresh();
}
if( pickList.GetCount() )
m_parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
@ -327,24 +315,22 @@ void DIALOG_EXCHANGE_MODULE::ChangeSameFootprints( bool aUseValue )
* - value and ref * - value and ref
* - pads net names * - pads net names
*/ */
void DIALOG_EXCHANGE_MODULE::ChangeAllFootprints() bool DIALOG_EXCHANGE_MODULE::changeAllFootprints()
{ {
MODULE* Module, * PtBack; MODULE* Module, * PtBack;
bool change = false; bool change = false;
int ShowErr = 3; // Post 3 error max. int ShowErr = 3; // Post 3 error max.
if( m_parent->GetBoard()->m_Modules == NULL ) if( m_parent->GetBoard()->m_Modules == NULL )
return; return false;
if( !IsOK( this, _( "Change ALL modules ?" ) ) ) if( !IsOK( this, _( "Change ALL modules ?" ) ) )
return; return false;
/* The change is done from the last module because the function /* The change is done from the last module because the function
* Change_1_Module () modifies the last module in the list * change_1_Module () modifies the last module in the list
*/ *
PICKED_ITEMS_LIST pickList; * note: for the first module in chain (the last here), Module->Back()
/* note: for the first module in chain (the last here), Module->Back()
* points the board or is NULL * points the board or is NULL
*/ */
Module = m_parent->GetBoard()->m_Modules.GetLast(); Module = m_parent->GetBoard()->m_Modules.GetLast();
@ -353,22 +339,13 @@ void DIALOG_EXCHANGE_MODULE::ChangeAllFootprints()
{ {
PtBack = Module->Back(); PtBack = Module->Back();
if( Change_1_Module( Module, Module->GetFPID(), &pickList, ShowErr ) ) if( change_1_Module( Module, Module->GetFPID(), ShowErr ) )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
ShowErr--; ShowErr--;
} }
if( change ) return change;
{
if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_parent->Compile_Ratsnest( NULL, true );
m_parent->GetCanvas()->Refresh();
}
if( pickList.GetCount() )
m_parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
@ -381,9 +358,8 @@ void DIALOG_EXCHANGE_MODULE::ChangeAllFootprints()
* Returns: false if no change (if the new module is not found) * Returns: false if no change (if the new module is not found)
* true if OK * true if OK
*/ */
bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* aModule, bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule,
const FPID& aNewFootprintFPID, const FPID& aNewFootprintFPID,
PICKED_ITEMS_LIST* aUndoPickList,
bool aShowError ) bool aShowError )
{ {
MODULE* newModule; MODULE* newModule;
@ -395,7 +371,7 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* aModule,
wxBusyCursor dummy; wxBusyCursor dummy;
// Copy parameters from the old module. // Copy parameters from the old module.
FPID oldFootprintFPID = aModule->GetFPID(); FPID oldFootprintFPID = aModule->GetFPID();
// Load module. // Load module.
line.Printf( _( "Change footprint '%s' (from '%s') to '%s'" ), line.Printf( _( "Change footprint '%s' (from '%s') to '%s'" ),
@ -415,7 +391,7 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* aModule,
return false; return false;
} }
m_parent->Exchange_Module( aModule, newModule, aUndoPickList ); m_parent->Exchange_Module( aModule, newModule, &m_undoPickList );
m_parent->GetBoard()->Add( newModule, ADD_APPEND ); m_parent->GetBoard()->Add( newModule, ADD_APPEND );
if( aModule == m_currentModule ) if( aModule == m_currentModule )
@ -459,7 +435,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() ); aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() );
aNewModule->SetPath( aOldModule->GetPath() ); aNewModule->SetPath( aOldModule->GetPath() );
// Update pad netnames ( when possible) // Update pad netnames (when possible)
for( D_PAD* pad = aNewModule->Pads(); pad != NULL; pad = pad->Next() ) for( D_PAD* pad = aNewModule->Pads(); pad != NULL; pad = pad->Next() )
{ {
pad->SetNetCode( NETINFO_LIST::UNCONNECTED ); pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
@ -478,20 +454,6 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
ITEM_PICKER picker_new( aNewModule, UR_NEW ); ITEM_PICKER picker_new( aNewModule, UR_NEW );
aUndoPickList->PushItem( picker_old ); aUndoPickList->PushItem( picker_old );
aUndoPickList->PushItem( picker_new ); aUndoPickList->PushItem( picker_new );
if( IsGalCanvasActive() )
{
KIGFX::VIEW* view = GetGalCanvas()->GetView();
aOldModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) );
view->Remove( aOldModule );
aNewModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) );
view->Add( aNewModule );
m_toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
GetGalCanvas()->ForceRefresh();
}
} }
else else
{ {