From 497fb31ae0a99a55b44a7ced366e8395a62635a5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 16 Jun 2016 12:19:07 +0200 Subject: [PATCH] BOARD_COMMIT can be constructed using a PCB_BASE_FRAME*. --- pcbnew/board_commit.cpp | 44 ++++++++++++++++++++++++----------------- pcbnew/board_commit.h | 6 +++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 0fa58381a5..0a53e1f200 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -30,14 +30,21 @@ #include #include -#include #include #include BOARD_COMMIT::BOARD_COMMIT( PCB_TOOL* aTool ) { - m_tool = aTool; + m_toolMgr = aTool->GetManager(); + m_editModules = aTool->EditingModules(); +} + + +BOARD_COMMIT::BOARD_COMMIT( PCB_BASE_FRAME* aFrame ) +{ + m_toolMgr = aFrame->GetToolManager(); + m_editModules = aFrame->IsType( FRAME_PCB_MODULE_EDITOR ); } @@ -50,29 +57,29 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) { // Objects potentially interested in changes: PICKED_ITEMS_LIST undoList; - TOOL_MANAGER* toolMgr = m_tool->GetManager(); - KIGFX::VIEW* view = toolMgr->GetView(); - BOARD* board = (BOARD*) toolMgr->GetModel(); - PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) toolMgr->GetEditFrame(); + KIGFX::VIEW* view = m_toolMgr->GetView(); + BOARD* board = (BOARD*) m_toolMgr->GetModel(); + PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame(); RN_DATA* ratsnest = board->GetRatsnest(); - bool editModules = m_tool->EditingModules(); + if( Empty() ) + return; - // Module items need to be saved in the undo buffer before modification - if( editModules ) + for( COMMIT_LINE& ent : m_changes ) { - frame->SaveCopyInUndoList( board->m_Modules, UR_CHANGED ); - } + // Module items need to be saved in the undo buffer before modification + if( m_editModules ) + { + frame->SaveCopyInUndoList( static_cast( ent.m_copy ), UR_CHANGED ); + } - BOOST_FOREACH( COMMIT_LINE& ent, m_changes ) - { BOARD_ITEM* boardItem = static_cast( ent.m_item ); switch( ent.m_type ) { case CHT_ADD: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_NEW ); undoList.PushItem( itemWrapper ); @@ -90,12 +97,13 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } view->Add( boardItem ); + //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() break; } case CHT_REMOVE: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_DELETED ); undoList.PushItem( itemWrapper ); @@ -116,7 +124,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) case CHT_MODIFY: { - if( !editModules ) + if( !m_editModules ) { ITEM_PICKER itemWrapper( boardItem, UR_CHANGED ); itemWrapper.SetLink( ent.m_copy ); @@ -140,13 +148,13 @@ void BOARD_COMMIT::Push( const wxString& aMessage ) } } - if( !editModules ) + if( !m_editModules ) frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED ); frame->OnModify(); ratsnest->Recalculate(); - m_committed = true; + clear(); } diff --git a/pcbnew/board_commit.h b/pcbnew/board_commit.h index 84d87f79ef..7f4d09db15 100644 --- a/pcbnew/board_commit.h +++ b/pcbnew/board_commit.h @@ -30,18 +30,22 @@ class BOARD_ITEM; class PICKED_ITEMS_LIST; class PCB_TOOL; +class PCB_BASE_FRAME; +class TOOL_MANAGER; class BOARD_COMMIT : public COMMIT { public: BOARD_COMMIT( PCB_TOOL* aTool ); + BOARD_COMMIT( PCB_BASE_FRAME* aFrame ); virtual ~BOARD_COMMIT(); virtual void Push( const wxString& aMessage ); virtual void Revert(); private: - PCB_TOOL* m_tool; + TOOL_MANAGER* m_toolMgr; + bool m_editModules; virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const; };