From c9817df9db9527eeedaab4ade4bedeb77465f98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Tue, 31 Oct 2017 16:08:18 +0100 Subject: [PATCH] refactoring: implemented BOARD-specific view Add()/Remove()/Update() methods in PCB_VIEW, moved to libpcbcommon --- common/CMakeLists.txt | 3 + common/view/view.cpp | 2 +- pcbnew/CMakeLists.txt | 4 +- pcbnew/board_commit.cpp | 27 --------- pcbnew/footprint_preview_panel.cpp | 2 - pcbnew/netlist.cpp | 2 - pcbnew/pcb_draw_panel_gal.cpp | 3 - pcbnew/pcb_view.cpp | 97 ++++++++++++++++++++++++------ pcbnew/pcb_view.h | 1 + pcbnew/undo_redo.cpp | 23 +------ 10 files changed, 88 insertions(+), 76 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8ee2036a4b..11229a1045 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -411,6 +411,9 @@ set( PCB_COMMON_SRCS ../pcbnew/gpcb_plugin.cpp ../pcbnew/pcb_netlist.cpp ../pcbnew/pcb_display_options.cpp + ../pcbnew/pcb_draw_panel_gal.cpp + ../pcbnew/pcb_view.cpp + ../pcbnew/pcb_painter.cpp widgets/widget_net_selector.cpp pcb_plot_params_keywords.cpp pcb_keywords.cpp diff --git a/common/view/view.cpp b/common/view/view.cpp index a971129e5e..65e4f19659 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -252,7 +252,7 @@ void VIEW::OnDestroy( VIEW_ITEM* aItem ) return; if( data->m_view ) - data->m_view->Remove( aItem ); + data->m_view->VIEW::Remove( aItem ); delete data; } diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 38f3ecff34..fb187bac3f 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -260,8 +260,8 @@ set( PCBNEW_CLASS_SRCS pad_edition_functions.cpp pcbnew_config.cpp pcbplot.cpp - pcb_draw_panel_gal.cpp - pcb_view.cpp +# pcb_draw_panel_gal.cpp +# pcb_view.cpp plot_board_layers.cpp plot_brditems_plotter.cpp print_board_functions.cpp diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 95c5de5c33..4a1c878f5b 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -121,13 +121,6 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry ) if( !( changeFlags & CHT_DONE ) ) board->Add( boardItem ); - //ratsnest->Add( boardItem ); // TODO currently done by BOARD::Add() - - if( boardItem->Type() == PCB_MODULE_T ) - { - MODULE* mod = static_cast( boardItem ); - mod->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); - } } else { @@ -229,7 +222,6 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry ) MODULE* module = static_cast( boardItem ); module->ClearFlags(); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); view->Remove( module ); @@ -258,12 +250,6 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry ) undoList.PushItem( itemWrapper ); } - if( boardItem->Type() == PCB_MODULE_T ) - { - MODULE* module = static_cast( boardItem ); - module->RunOnChildren( [&view] ( BOARD_ITEM* aItem ) { view->Update( aItem ); } ); - } - if( ent.m_copy ) connectivity->MarkItemNetAsDirty( static_cast( ent.m_copy ) ); @@ -335,11 +321,6 @@ void BOARD_COMMIT::Revert() switch( ent.m_type ) { case CHT_ADD: - if( item->Type() == PCB_MODULE_T ) - { - MODULE* oldModule = static_cast( item ); - oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - } view->Remove( item ); connectivity->Remove( item ); @@ -350,7 +331,6 @@ void BOARD_COMMIT::Revert() { MODULE* newModule = static_cast( item ); newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) ); - newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); } view->Add( item ); @@ -359,12 +339,6 @@ void BOARD_COMMIT::Revert() case CHT_MODIFY: { - if( item->Type() == PCB_MODULE_T ) - { - MODULE* oldModule = static_cast( item ); - oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - } - view->Remove( item ); connectivity->Remove( item ); @@ -378,7 +352,6 @@ void BOARD_COMMIT::Revert() { MODULE* newModule = static_cast( item ); newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) ); - newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); } view->Add( item ); diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 753e7be4c8..d711952fac 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -300,10 +300,8 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( MODULE *module ) { GetView()->Clear(); module->SetParent ( &*m_dummyBoard ); - module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, GetView(), _1, -1 ) ); GetView()->Add ( module ); - GetView()->SetVisible( module, true ); GetView()->Update( module, KIGFX::ALL ); diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index e4fce7f352..a48f0447e2 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -111,7 +111,6 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, // Remove old modules for( MODULE* module = board->m_Modules; module; module = module->Next() ) { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); view->Remove( module ); } } @@ -158,7 +157,6 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, // Reload modules for( MODULE* module = board->m_Modules; module; module = module->Next() ) { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); view->Add( module ); } diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index d79b6c8154..629e414ee6 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -153,10 +153,7 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( const BOARD* aBoard ) // Load modules and its additional elements for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) - { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, m_view, _1, -1 ) ); m_view->Add( module ); - } // Segzones (equivalent of ZONE_CONTAINER for legacy boards) for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() ) diff --git a/pcbnew/pcb_view.cpp b/pcbnew/pcb_view.cpp index 357ecca6cd..48e7609bb7 100644 --- a/pcbnew/pcb_view.cpp +++ b/pcbnew/pcb_view.cpp @@ -1,47 +1,110 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013-2017 CERN + * @author Tomasz Wlostowski + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include +using namespace std::placeholders; + #include #include #include -namespace KIGFX -{ +#include +namespace KIGFX { PCB_VIEW::PCB_VIEW( bool aIsDynamic ) : - VIEW ( aIsDynamic ) + VIEW( aIsDynamic ) { - } + PCB_VIEW::~PCB_VIEW() { - } -void PCB_VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority ) + +void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority ) { - VIEW::Add( aItem, aDrawPriority ); + auto item = static_cast( aItem ); + + if( item->Type() == PCB_MODULE_T ) + { + auto mod = static_cast( item ); + mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) { + VIEW::Add( aModItem ); + } ); + } + + VIEW::Add( item, aDrawPriority ); } -void PCB_VIEW::Remove( VIEW_ITEM* aItem ) + +void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem ) { - VIEW::Remove( aItem ); + auto item = static_cast( aItem ); + + + if( item->Type() == PCB_MODULE_T ) + { + auto mod = static_cast( item ); + mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) { + VIEW::Remove( aModItem ); + } ); + } + + VIEW::Remove( item ); } -void PCB_VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags ) + +void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) { - VIEW::Update( aItem, aUpdateFlags ); + auto item = static_cast( aItem ); + + if( item->Type() == PCB_MODULE_T ) + { + auto mod = static_cast( item ); + mod->RunOnChildren([this, aUpdateFlags] ( BOARD_ITEM* aModItem ) { + VIEW::Update( aModItem, aUpdateFlags ); + } ); + } + + VIEW::Update( item, aUpdateFlags ); } -/// @copydoc VIEW::Update() -void PCB_VIEW::Update( VIEW_ITEM* aItem ) + +void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem ) { - VIEW::Update( aItem ); + PCB_VIEW::Update( aItem, KIGFX::ALL ); } + void PCB_VIEW::UpdateDisplayOptions( PCB_DISPLAY_OPTIONS* aOptions ) { - auto painter = static_cast( GetPainter() ); - auto settings = static_cast( painter->GetSettings() ); + auto painter = static_cast( GetPainter() ); + auto settings = static_cast( painter->GetSettings() ); + settings->LoadDisplayOptions( aOptions ); } - }; diff --git a/pcbnew/pcb_view.h b/pcbnew/pcb_view.h index ce7148ddd8..2782c5d526 100644 --- a/pcbnew/pcb_view.h +++ b/pcbnew/pcb_view.h @@ -27,6 +27,7 @@ #include #include +#include class PCB_DISPLAY_OPTIONS; diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 2bca3af8ba..ed877f1792 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -409,7 +409,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool bool reBuild_ratsnest = false; bool deep_reBuild_ratsnest = false; // true later if pointers must be rebuilt - KIGFX::VIEW* view = GetGalCanvas()->GetView(); + auto view = GetGalCanvas()->GetView(); auto connectivity = GetBoard()->GetConnectivity(); // Undo in the reverse order of list creation: (this can allow stacked changes @@ -488,12 +488,6 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool // Remove all pads/drawings/texts, as they become invalid // for the VIEW after SwapData() called for modules - if( item->Type() == PCB_MODULE_T ) - { - MODULE* oldModule = static_cast( item ); - oldModule->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - } - view->Remove( item ); connectivity->Remove( item ); @@ -504,7 +498,6 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool if( item->Type() == PCB_MODULE_T ) { MODULE* newModule = static_cast( item ); - newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); newModule->RunOnChildren( std::bind( &BOARD_ITEM::ClearFlags, _1, EDA_ITEM_ALL_FLAGS )); } @@ -518,26 +511,12 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool case UR_NEW: /* new items are deleted */ aList->SetPickedItemStatus( UR_DELETED, ii ); GetModel()->Remove( item ); - - if( item->Type() == PCB_MODULE_T ) - { - MODULE* module = static_cast( item ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - } - view->Remove( item ); break; case UR_DELETED: /* deleted items are put in List, as new items */ aList->SetPickedItemStatus( UR_NEW, ii ); GetModel()->Add( item ); - - if( item->Type() == PCB_MODULE_T ) - { - MODULE* module = static_cast( item ); - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) ); - } - view->Add( item ); build_item_list = true; break;