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-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
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.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VIEW_GROUP_H_
|
|
|
|
#define VIEW_GROUP_H_
|
|
|
|
|
2023-09-26 11:40:17 +00:00
|
|
|
#include <gal/gal.h>
|
2013-08-20 13:07:38 +00:00
|
|
|
#include <view/view_item.h>
|
|
|
|
#include <deque>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
2020-12-27 00:41:04 +00:00
|
|
|
/**
|
|
|
|
* Extend #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).
|
|
|
|
*/
|
2023-09-26 11:40:17 +00:00
|
|
|
class GAL_API VIEW_GROUP : public VIEW_ITEM
|
2013-08-20 13:07:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-15 19:26:35 +00:00
|
|
|
VIEW_GROUP( VIEW* aView = nullptr );
|
2013-08-20 13:07:38 +00:00
|
|
|
virtual ~VIEW_GROUP();
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the number of stored items.
|
2016-11-04 21:29:47 +00:00
|
|
|
*/
|
|
|
|
virtual unsigned int GetSize() const;
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Add an item to the group.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
|
|
|
virtual void Add( VIEW_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Remove an item from the group.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
|
|
|
virtual void Remove( VIEW_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Remove all the stored items from the group.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
|
|
|
virtual void Clear();
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
virtual VIEW_ITEM* GetItem( unsigned int aIdx ) const;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the bounding box for all stored items covering all its layers.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual const BOX2I ViewBBox() const override;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Draw all the stored items in the group on the given layer.
|
2013-08-20 13:07:38 +00:00
|
|
|
*
|
|
|
|
* @param aLayer is the layer which should be drawn.
|
2017-06-21 07:32:19 +00:00
|
|
|
* @param aView is the VIEW that should be used for drawing.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
2016-12-02 17:58:12 +00:00
|
|
|
virtual void ViewDraw( int aLayer, VIEW* aView ) const override;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return all the layers used by the stored items.
|
2013-08-20 13:07:38 +00:00
|
|
|
*
|
|
|
|
* @param aLayers[] is the output layer index array.
|
|
|
|
* @param aCount is the number of layer indices in aLayers[].
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set layer used to draw the group.
|
2013-08-20 13:07:38 +00:00
|
|
|
*/
|
|
|
|
inline virtual void SetLayer( int aLayer )
|
|
|
|
{
|
|
|
|
m_layer = aLayer;
|
|
|
|
}
|
|
|
|
|
2013-09-12 15:42:28 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Free all the items that were added to the group.
|
2013-09-12 15:42:28 +00:00
|
|
|
*/
|
2013-09-10 17:25:02 +00:00
|
|
|
void FreeItems();
|
|
|
|
|
2013-08-20 13:07:38 +00:00
|
|
|
protected:
|
2021-10-03 12:58:56 +00:00
|
|
|
virtual const std::vector<VIEW_ITEM*> updateDrawList() const;
|
2016-11-04 21:29:47 +00:00
|
|
|
|
2021-10-03 12:58:56 +00:00
|
|
|
protected:
|
|
|
|
int m_layer;
|
|
|
|
std::vector<VIEW_ITEM*> m_groupItems;
|
2013-08-20 13:07:38 +00:00
|
|
|
};
|
2016-11-04 21:29:47 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
} // namespace KIGFX
|
2013-08-20 13:07:38 +00:00
|
|
|
|
|
|
|
#endif // VIEW_GROUP_H_
|