2020-08-11 19:37:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Joshua Redstone redstone at gmail.com
|
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-08-12 11:23:30 +00:00
|
|
|
* @file class_pcb_group.h
|
2020-08-11 19:37:07 +00:00
|
|
|
* @brief Class to handle a set of BOARD_ITEMs.
|
|
|
|
* Group parent is always board, not logical parent group.
|
|
|
|
* Group is transparent container - e.g., its position is derived from the position
|
|
|
|
* of its members.
|
|
|
|
* A selection containing a group implicitly contains its members. However other operations
|
|
|
|
* on sets of items, like committing, updating the view, etc the set is explicit.
|
|
|
|
*/
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
#ifndef CLASS_PCB_GROUP_H_
|
|
|
|
#define CLASS_PCB_GROUP_H_
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2020-08-20 00:22:48 +00:00
|
|
|
#include <board_commit.h>
|
2020-08-11 19:37:07 +00:00
|
|
|
#include <class_board_item.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class VIEW;
|
|
|
|
}
|
|
|
|
|
2020-09-16 00:59:12 +00:00
|
|
|
typedef std::unordered_set<BOARD_ITEM*> BOARD_ITEM_SET;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-12 11:23:30 +00:00
|
|
|
* PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
|
2020-08-11 19:37:07 +00:00
|
|
|
*/
|
2020-08-12 11:23:30 +00:00
|
|
|
class PCB_GROUP : public BOARD_ITEM
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-09-02 01:09:34 +00:00
|
|
|
PCB_GROUP( BOARD* aParent );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
static inline bool ClassOf( const EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem && PCB_GROUP_T == aItem->Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2020-09-16 00:59:12 +00:00
|
|
|
const BOARD_ITEM_SET& GetItems() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
return m_items;
|
|
|
|
}
|
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
void SetName( wxString aName )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-09-02 01:09:34 +00:00
|
|
|
m_name = aName;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds item to group. Does not take ownership of item.
|
2020-09-02 01:09:34 +00:00
|
|
|
*
|
|
|
|
* @return true if item was added (false if item belongs to a different group).
|
2020-08-11 19:37:07 +00:00
|
|
|
*/
|
2020-09-02 01:09:34 +00:00
|
|
|
bool AddItem( BOARD_ITEM* aItem );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes item from group.
|
2020-09-02 01:09:34 +00:00
|
|
|
*
|
2020-08-11 19:37:07 +00:00
|
|
|
* @return true if item was removed (false if item was not in the group).
|
|
|
|
*/
|
2020-09-02 01:09:34 +00:00
|
|
|
bool RemoveItem( BOARD_ITEM* aItem );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
wxString GetClass() const override
|
|
|
|
{
|
2020-08-12 11:23:30 +00:00
|
|
|
return wxT( "PCB_GROUP" );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined( DEBUG )
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const override
|
|
|
|
{
|
|
|
|
ShowDummy( os );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::GetPosition
|
|
|
|
wxPoint GetPosition() const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::SetPosition
|
2020-09-02 01:09:34 +00:00
|
|
|
void SetPosition( const wxPoint& aNewpos ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::GetLayerSet
|
|
|
|
LSET GetLayerSet() const override;
|
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::SetLayer
|
|
|
|
void SetLayer( PCB_LAYER_ID aLayer ) override
|
|
|
|
{
|
2020-08-16 19:10:18 +00:00
|
|
|
wxFAIL_MSG( "groups don't support layer SetLayer" );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::Clone
|
|
|
|
EDA_ITEM* Clone() const override;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clone() this and all descendents
|
|
|
|
*/
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* DeepClone() const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Duplicate() this and all descendents
|
|
|
|
*/
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* DeepDuplicate() const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::SwapData
|
|
|
|
void SwapData( BOARD_ITEM* aImage ) override;
|
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::IsOnLayer
|
2020-09-02 01:09:34 +00:00
|
|
|
bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::HitTest
|
|
|
|
bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::HitTest
|
|
|
|
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::GetBoundingBox
|
|
|
|
const EDA_RECT GetBoundingBox() const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::Visit
|
2020-09-02 01:09:34 +00:00
|
|
|
SEARCH_RESULT Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aScanTypes[] ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
///> @copydoc VIEW_ITEM::ViewGetLayers
|
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
|
|
|
///> @copydoc VIEW_ITEM::ViewGetLOD
|
2020-09-21 15:03:08 +00:00
|
|
|
double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::Move
|
|
|
|
void Move( const wxPoint& aMoveVector ) override;
|
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::Rotate
|
|
|
|
void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
|
|
|
|
|
|
|
|
///> @copydoc BOARD_ITEM::Flip
|
|
|
|
void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::GetSelectMenuText
|
|
|
|
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::GetMenuImage
|
|
|
|
BITMAP_DEF GetMenuImage() const override;
|
|
|
|
|
|
|
|
///> @copydoc EDA_ITEM::GetMsgPanelInfo
|
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
|
|
|
|
2020-08-20 00:22:48 +00:00
|
|
|
/**
|
|
|
|
* Add all the immediate children of this group to the board commit. This function does not
|
|
|
|
* enter any subgroups of this group, or add the group itself.
|
|
|
|
*
|
|
|
|
* @param aCommit is the commit to add the children to.
|
|
|
|
*/
|
|
|
|
void AddChildrenToCommit( BOARD_COMMIT& aCommit )
|
|
|
|
{
|
|
|
|
RunOnChildren( [&]( BOARD_ITEM* bItem )
|
|
|
|
{
|
|
|
|
aCommit.Add( bItem );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
/**
|
|
|
|
* Invokes a function on all members of the group.
|
|
|
|
* Note that this function should not add or remove items to the group
|
|
|
|
* @param aFunction is the function to be invoked.
|
|
|
|
*/
|
|
|
|
void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes a function on all descendents of the group.
|
2020-08-16 19:10:18 +00:00
|
|
|
* Note that this function should not add or remove items to the group or descendent
|
2020-08-11 19:37:07 +00:00
|
|
|
* groups.
|
|
|
|
* @param aFunction is the function to be invoked.
|
|
|
|
*/
|
|
|
|
void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction );
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Members of the group
|
2020-09-16 00:59:12 +00:00
|
|
|
BOARD_ITEM_SET m_items;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
// Optional group name
|
|
|
|
wxString m_name;
|
|
|
|
};
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
#endif // CLASS_PCB_GROUP_H_
|