2017-10-31 15:08:18 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2017-10-30 19:17:23 +00:00
|
|
|
#include <pcb_view.h>
|
|
|
|
#include <pcb_display_options.h>
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pcb_group.h>
|
|
|
|
#include <footprint.h>
|
2017-10-30 19:17:23 +00:00
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
namespace KIGFX {
|
2017-10-30 19:17:23 +00:00
|
|
|
PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
|
2017-10-31 15:08:18 +00:00
|
|
|
VIEW( aIsDynamic )
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
// Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
|
|
|
|
// and Gerbview.
|
|
|
|
// However, ensure this area has the right size (max size allowed by integer coordinates) in
|
|
|
|
// case of the default value is changed. Could be a size depending on the drawing-sheet size.
|
2018-11-18 19:04:17 +00:00
|
|
|
typedef std::numeric_limits<int> coord_limits;
|
|
|
|
double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
|
|
|
|
double size = coord_limits::max() - coord_limits::epsilon();
|
|
|
|
m_boundary.SetOrigin( pos, pos );
|
|
|
|
m_boundary.SetSize( size, size );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2017-10-30 19:17:23 +00:00
|
|
|
PCB_VIEW::~PCB_VIEW()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
|
|
|
void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
|
2017-10-31 15:08:18 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
|
2020-11-13 12:21:02 +00:00
|
|
|
footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
|
|
|
|
{
|
|
|
|
VIEW::Add( aChild );
|
|
|
|
} );
|
2017-10-31 15:08:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
VIEW::Add( aItem, aDrawPriority );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
|
|
|
void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
|
2017-10-31 15:08:18 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
|
2020-11-13 12:21:02 +00:00
|
|
|
footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
|
|
|
|
{
|
|
|
|
VIEW::Remove( aChild );
|
|
|
|
} );
|
2017-10-31 15:08:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
VIEW::Remove( aItem );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
const BOARD_ITEM* boardItem = dynamic_cast<const BOARD_ITEM*>( aItem );
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
|
2017-10-31 15:08:18 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( boardItem );
|
2020-12-29 12:33:37 +00:00
|
|
|
footprint->RunOnChildren(
|
2021-01-09 13:42:35 +00:00
|
|
|
[this, aUpdateFlags]( BOARD_ITEM* child )
|
2020-12-29 12:33:37 +00:00
|
|
|
{
|
2021-01-09 13:42:35 +00:00
|
|
|
VIEW::Update( child, aUpdateFlags );
|
2020-12-29 12:33:37 +00:00
|
|
|
} );
|
|
|
|
}
|
2020-12-29 17:08:23 +00:00
|
|
|
else if( boardItem && boardItem->Type() == PCB_GROUP_T )
|
2020-12-29 12:33:37 +00:00
|
|
|
{
|
2020-12-29 17:08:23 +00:00
|
|
|
const PCB_GROUP* group = static_cast<const PCB_GROUP*>( boardItem );
|
2020-12-29 12:33:37 +00:00
|
|
|
group->RunOnChildren(
|
2021-01-09 13:42:35 +00:00
|
|
|
[this, aUpdateFlags]( BOARD_ITEM* child )
|
2020-12-29 12:33:37 +00:00
|
|
|
{
|
2021-01-09 13:42:35 +00:00
|
|
|
Update( child, aUpdateFlags );
|
2020-12-29 12:33:37 +00:00
|
|
|
} );
|
2017-10-31 15:08:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 17:08:23 +00:00
|
|
|
VIEW::Update( aItem, aUpdateFlags );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2017-10-31 15:08:18 +00:00
|
|
|
PCB_VIEW::Update( aItem, KIGFX::ALL );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2019-11-07 14:23:09 +00:00
|
|
|
void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
|
2017-10-30 19:17:23 +00:00
|
|
|
{
|
2023-08-20 16:08:51 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
|
2017-10-31 15:08:18 +00:00
|
|
|
|
2021-09-07 20:34:10 +00:00
|
|
|
settings->LoadDisplayOptions( aOptions );
|
2017-10-30 19:17:23 +00:00
|
|
|
}
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|