2013-08-20 13:07:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
2021-10-03 12:58:56 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-08-20 13:07:38 +00:00
|
|
|
* @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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file view_group.cpp
|
|
|
|
* @brief VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
|
|
|
|
* VIEW_GROUP does not take over ownership of the held items. The main purpose of this class is
|
|
|
|
* to group items and draw them on a single layer (in particular the overlay).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <set>
|
2021-10-03 12:58:56 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2013-08-20 13:07:38 +00:00
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <view/view.h>
|
2023-08-18 11:34:59 +00:00
|
|
|
#include <view/view_item.h>
|
2013-08-20 13:07:38 +00:00
|
|
|
#include <painter.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2013-08-20 13:07:38 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
using namespace KIGFX;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
VIEW_GROUP::VIEW_GROUP( VIEW* aView ) :
|
2020-12-29 17:08:23 +00:00
|
|
|
VIEW_ITEM(),
|
2018-08-28 21:57:31 +00:00
|
|
|
m_layer( LAYER_SELECT_OVERLAY )
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VIEW_GROUP::~VIEW_GROUP()
|
|
|
|
{
|
2017-01-16 13:23:22 +00:00
|
|
|
// VIEW_ITEM destructor removes the object from its parent view
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VIEW_GROUP::Add( VIEW_ITEM* aItem )
|
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
m_groupItems.push_back( aItem );
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VIEW_GROUP::Remove( VIEW_ITEM* aItem )
|
|
|
|
{
|
2021-10-03 12:58:56 +00:00
|
|
|
alg::delete_matching( m_groupItems, aItem );
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VIEW_GROUP::Clear()
|
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
m_groupItems.clear();
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int VIEW_GROUP::GetSize() const
|
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
return m_groupItems.size();
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 09:44:58 +00:00
|
|
|
|
|
|
|
VIEW_ITEM *VIEW_GROUP::GetItem( unsigned int idx ) const
|
2016-11-04 21:29:47 +00:00
|
|
|
{
|
|
|
|
return m_groupItems[idx];
|
|
|
|
}
|
2013-08-20 13:07:38 +00:00
|
|
|
|
2017-04-20 09:44:58 +00:00
|
|
|
|
2013-08-20 13:07:38 +00:00
|
|
|
const BOX2I VIEW_GROUP::ViewBBox() const
|
|
|
|
{
|
2018-08-03 11:59:15 +00:00
|
|
|
BOX2I bb;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2018-08-03 11:59:15 +00:00
|
|
|
if( !m_groupItems.size() )
|
|
|
|
{
|
|
|
|
bb.SetMaximum();
|
2018-10-11 03:14:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bb = m_groupItems[0]->ViewBBox();
|
|
|
|
|
2021-10-03 12:58:56 +00:00
|
|
|
for( VIEW_ITEM* item : m_groupItems )
|
2018-10-11 03:14:47 +00:00
|
|
|
bb.Merge( item->ViewBBox() );
|
2018-08-03 11:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bb;
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
2018-09-23 13:13:57 +00:00
|
|
|
KIGFX::GAL* gal = aView->GetGAL();
|
|
|
|
PAINTER* painter = aView->GetPainter();
|
|
|
|
bool isSelection = m_layer == LAYER_SELECT_OVERLAY;
|
2020-11-17 20:47:50 +00:00
|
|
|
|
|
|
|
const std::vector<VIEW_ITEM*> drawList = updateDrawList();
|
2023-08-18 11:34:59 +00:00
|
|
|
constexpr double HIDE = std::numeric_limits<double>::max();
|
2016-11-04 21:29:47 +00:00
|
|
|
|
2022-08-26 02:51:11 +00:00
|
|
|
std::map<int, std::vector<VIEW_ITEM*>> layer_item_map;
|
2018-03-25 15:10:51 +00:00
|
|
|
|
|
|
|
// Build a list of layers used by the items in the group
|
2020-11-17 20:47:50 +00:00
|
|
|
for( VIEW_ITEM* item : drawList )
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
2018-03-25 15:10:51 +00:00
|
|
|
int item_layers[VIEW::VIEW_MAX_LAYERS], item_layers_count;
|
|
|
|
item->ViewGetLayers( item_layers, item_layers_count );
|
2013-08-20 13:07:38 +00:00
|
|
|
|
2018-03-25 15:10:51 +00:00
|
|
|
for( int i = 0; i < item_layers_count; i++ )
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
2022-07-26 18:06:29 +00:00
|
|
|
wxCHECK2_MSG( item_layers[i] <= LAYER_ID_COUNT, continue, wxT( "Invalid item layer" ) );
|
2018-03-25 15:10:51 +00:00
|
|
|
layer_item_map[ item_layers[i] ].push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 03:14:47 +00:00
|
|
|
int layers[VIEW::VIEW_MAX_LAYERS] = { 0 };
|
|
|
|
int layers_count = 0;
|
2018-03-25 15:10:51 +00:00
|
|
|
|
2020-12-29 10:42:42 +00:00
|
|
|
for( const std::pair<const int, std::vector<VIEW_ITEM*>>& entry : layer_item_map )
|
2018-03-25 15:10:51 +00:00
|
|
|
layers[ layers_count++ ] = entry.first;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
2018-03-25 15:10:51 +00:00
|
|
|
aView->SortLayers( layers, layers_count );
|
|
|
|
|
|
|
|
// Now draw the layers in sorted order
|
|
|
|
|
|
|
|
gal->PushDepth();
|
|
|
|
|
|
|
|
for( int i = 0; i < layers_count; i++ )
|
|
|
|
{
|
2018-09-23 13:13:57 +00:00
|
|
|
int layer = layers[i];
|
2022-01-21 23:23:57 +00:00
|
|
|
|
2022-11-05 12:00:56 +00:00
|
|
|
if( IsZoneFillLayer( layer ) )
|
2022-01-21 23:23:57 +00:00
|
|
|
layer = layer - LAYER_ZONE_START;
|
|
|
|
|
2018-09-23 13:13:57 +00:00
|
|
|
bool draw = aView->IsLayerVisible( layer );
|
|
|
|
|
|
|
|
if( isSelection )
|
|
|
|
{
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
case LAYER_PADS_TH:
|
2021-01-30 14:41:31 +00:00
|
|
|
case LAYER_PAD_PLATEDHOLES:
|
|
|
|
case LAYER_PAD_HOLEWALLS:
|
2023-08-04 10:13:20 +00:00
|
|
|
case LAYER_PADS_SMD_FR:
|
|
|
|
case LAYER_PADS_SMD_BK:
|
2018-09-23 13:13:57 +00:00
|
|
|
draw = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( draw )
|
2018-03-25 15:10:51 +00:00
|
|
|
{
|
|
|
|
gal->AdvanceDepth();
|
|
|
|
|
2020-12-29 10:42:42 +00:00
|
|
|
for( VIEW_ITEM* item : layer_item_map[ layers[i] ] )
|
2018-03-25 15:10:51 +00:00
|
|
|
{
|
2023-08-18 11:34:59 +00:00
|
|
|
// Ignore LOD scale for selected items, but don't ignore things explicitly
|
|
|
|
// hidden.
|
|
|
|
if( item->ViewGetLOD( layer, aView ) == HIDE )
|
|
|
|
continue;
|
|
|
|
|
2013-09-06 09:31:16 +00:00
|
|
|
if( !painter->Draw( item, layers[i] ) )
|
2016-12-02 17:58:12 +00:00
|
|
|
item->ViewDraw( layers[i], aView ); // Alternative drawing method
|
2013-09-06 09:31:16 +00:00
|
|
|
}
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
2013-10-02 08:19:48 +00:00
|
|
|
}
|
2018-03-25 15:10:51 +00:00
|
|
|
|
|
|
|
gal->PopDepth();
|
2013-08-20 13:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VIEW_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2013-09-06 09:31:16 +00:00
|
|
|
// Everything is displayed on a single layer
|
2013-08-20 13:07:38 +00:00
|
|
|
aLayers[0] = m_layer;
|
|
|
|
aCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-01 14:55:33 +00:00
|
|
|
void VIEW_GROUP::FreeItems()
|
|
|
|
{
|
2017-01-17 14:07:57 +00:00
|
|
|
for( unsigned int i = 0 ; i < GetSize(); i++ )
|
|
|
|
delete GetItem( i );
|
2016-06-21 11:47:12 +00:00
|
|
|
|
|
|
|
Clear();
|
2013-10-01 14:55:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2021-10-03 12:58:56 +00:00
|
|
|
const std::vector<VIEW_ITEM*> VIEW_GROUP::updateDrawList() const
|
2013-10-01 14:55:33 +00:00
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
return m_groupItems;
|
|
|
|
}
|
2013-10-01 14:55:33 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
/*void VIEW_GROUP::ItemsSetVisibility( bool aVisible )
|
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
for(unsigned int i = 0 ; i < GetSize(); i++)
|
2016-11-04 21:29:47 +00:00
|
|
|
GetItem(i)->ViewSetVisible( aVisible );
|
2013-10-01 14:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
void VIEW_GROUP::ItemsViewUpdate( VIEW_ITEM::VIEW_UPDATE_FLAGS aFlags )
|
2013-10-01 14:55:33 +00:00
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
for(unsigned int i = 0 ; i < GetSize(); i++)
|
2016-11-04 21:29:47 +00:00
|
|
|
GetItem(i)->ViewUpdate( aFlags );
|
|
|
|
}*/
|