refactoring: implemented BOARD-specific view Add()/Remove()/Update() methods in PCB_VIEW, moved to libpcbcommon

This commit is contained in:
Tomasz Włostowski 2017-10-31 16:08:18 +01:00
parent 0245912c34
commit c9817df9db
10 changed files with 88 additions and 76 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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<MODULE*>( 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<MODULE*>( 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<MODULE*>( boardItem );
module->RunOnChildren( [&view] ( BOARD_ITEM* aItem ) { view->Update( aItem ); } );
}
if( ent.m_copy )
connectivity->MarkItemNetAsDirty( static_cast<BOARD_ITEM*>( 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<MODULE*>( 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<MODULE*>( 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<MODULE*>( 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<MODULE*>( item );
newModule->RunOnChildren( std::bind( &EDA_ITEM::ClearFlags, _1, SELECTED ) );
newModule->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
}
view->Add( item );

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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() )

View File

@ -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 <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* 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 <functional>
using namespace std::placeholders;
#include <pcb_view.h>
#include <pcb_display_options.h>
#include <pcb_painter.h>
namespace KIGFX
{
#include <class_module.h>
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<BOARD_ITEM*>( aItem );
if( item->Type() == PCB_MODULE_T )
{
auto mod = static_cast<MODULE*>( 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<BOARD_ITEM*>( aItem );
if( item->Type() == PCB_MODULE_T )
{
auto mod = static_cast<MODULE*>( 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<BOARD_ITEM*>( aItem );
if( item->Type() == PCB_MODULE_T )
{
auto mod = static_cast<MODULE*>( 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<KIGFX::PCB_PAINTER*>( GetPainter() );
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
settings->LoadDisplayOptions( aOptions );
}
};

View File

@ -27,6 +27,7 @@
#include <layers_id_colors_and_visibility.h>
#include <view/view.h>
#include <class_board_item.h>
class PCB_DISPLAY_OPTIONS;

View File

@ -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<MODULE*>( 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<MODULE*>( 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<MODULE*>( 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<MODULE*>( item );
module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1, -1 ) );
}
view->Add( item );
build_item_list = true;
break;