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
|
2022-08-20 09:27:35 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-08-11 19:37:07 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-04-19 11:51:26 +00:00
|
|
|
* @file pcb_group.h
|
2020-08-11 19:37:07 +00:00
|
|
|
* @brief Class to handle a set of BOARD_ITEMs.
|
|
|
|
*/
|
|
|
|
|
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-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2020-08-11 19:37:07 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class VIEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* A set of BOARD_ITEMs (i.e., without duplicates).
|
2020-12-19 23:29:10 +00:00
|
|
|
*
|
|
|
|
* The group parent is always board, not logical parent group. The 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-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-10-03 11:16:29 +00:00
|
|
|
PCB_GROUP( BOARD_ITEM* aParent );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
static inline bool ClassOf( const EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem && PCB_GROUP_T == aItem->Type();
|
|
|
|
}
|
|
|
|
|
2020-09-24 01:05:46 +00:00
|
|
|
wxString GetClass() const override
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-09-24 01:05:46 +00:00
|
|
|
return wxT( "PCB_GROUP" );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 01:05:46 +00:00
|
|
|
wxString GetName() const { return m_name; }
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetName( const wxString& aName ) { m_name = aName; }
|
2020-09-24 01:05:46 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
std::unordered_set<BOARD_ITEM*>& GetItems()
|
|
|
|
{
|
|
|
|
return m_items;
|
|
|
|
}
|
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
const std::unordered_set<BOARD_ITEM*>& GetItems() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
return m_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Add 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
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Remove 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
|
|
|
|
2020-09-24 01:05:46 +00:00
|
|
|
void RemoveAll();
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2020-09-26 16:06:32 +00:00
|
|
|
/*
|
2022-10-06 18:02:29 +00:00
|
|
|
* Search for highest level group inside of aScope, containing item.
|
2020-12-19 23:29:10 +00:00
|
|
|
*
|
2021-01-11 22:56:56 +00:00
|
|
|
* @param aScope restricts the search to groups within the group scope.
|
2021-04-06 17:26:56 +00:00
|
|
|
* @param isFootprintEditor true if we should stop promoting at the footprint level
|
2022-10-06 18:02:29 +00:00
|
|
|
* @return group inside of aScope, containing item, if exists, otherwise, nullptr
|
2020-09-26 16:06:32 +00:00
|
|
|
*/
|
2021-04-06 17:26:56 +00:00
|
|
|
static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
|
2020-09-26 16:06:32 +00:00
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
|
2020-09-26 16:06:32 +00:00
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
#if defined( DEBUG )
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const override
|
|
|
|
{
|
|
|
|
ShowDummy( os );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::GetPosition
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetPosition() const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::SetPosition
|
2022-01-01 06:04:08 +00:00
|
|
|
void SetPosition( const VECTOR2I& aNewpos ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::GetLayerSet
|
2020-08-11 19:37:07 +00:00
|
|
|
LSET GetLayerSet() const override;
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::SetLayer
|
2020-08-11 19:37:07 +00:00
|
|
|
void SetLayer( PCB_LAYER_ID aLayer ) override
|
|
|
|
{
|
2022-02-09 11:14:08 +00:00
|
|
|
wxFAIL_MSG( wxT( "groups don't support layer SetLayer" ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 20:19:46 +00:00
|
|
|
/** Set layer for all items within the group.
|
2021-07-27 12:22:27 +00:00
|
|
|
*
|
2021-03-13 20:19:46 +00:00
|
|
|
* To avoid freezes with circular references, the maximum depth is 20 by default.
|
|
|
|
*/
|
|
|
|
void SetLayerRecursive( PCB_LAYER_ID aLayer, int aDepth );
|
|
|
|
|
2021-09-27 10:28:46 +00:00
|
|
|
void SetLocked( bool aLocked ) override;
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::Clone
|
2020-08-11 19:37:07 +00:00
|
|
|
EDA_ITEM* Clone() const override;
|
|
|
|
|
|
|
|
/*
|
2020-12-19 23:29:10 +00:00
|
|
|
* Clone() this and all descendants
|
2020-08-11 19:37:07 +00:00
|
|
|
*/
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* DeepClone() const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
/*
|
2020-12-19 23:29:10 +00:00
|
|
|
* Duplicate() this and all descendants
|
2020-08-11 19:37:07 +00:00
|
|
|
*/
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* DeepDuplicate() const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::IsOnLayer
|
2023-01-25 13:31:37 +00:00
|
|
|
bool IsOnLayer( PCB_LAYER_ID aLayer, bool aIncludeCourtyards = false ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::HitTest
|
2022-01-01 06:04:08 +00:00
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::HitTest
|
2022-08-31 09:33:46 +00:00
|
|
|
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::GetBoundingBox
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GetBoundingBox() const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2022-11-18 21:04:54 +00:00
|
|
|
// @copydoc BOARD_ITEM::GetEffectiveShape
|
|
|
|
std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
|
|
|
|
FLASHING aFlash = FLASHING::DEFAULT ) const override;
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::Visit
|
2022-07-30 00:00:39 +00:00
|
|
|
INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc VIEW_ITEM::ViewGetLayers
|
2020-08-11 19:37:07 +00:00
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @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
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::Move
|
2022-01-01 06:04:08 +00:00
|
|
|
void Move( const VECTOR2I& aMoveVector ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::Rotate
|
2022-01-13 19:32:00 +00:00
|
|
|
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::Flip
|
2022-01-01 06:04:08 +00:00
|
|
|
void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::GetItemDescription
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::GetMenuImage
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS GetMenuImage() const override;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2021-03-13 20:19:46 +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 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc EDA_ITEM::GetMsgPanelInfo
|
2020-08-11 19:37:07 +00:00
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Invoke a function on all members of the group.
|
2020-12-19 23:29:10 +00:00
|
|
|
*
|
|
|
|
* @note This function should not add or remove items to the group.
|
|
|
|
*
|
2020-08-11 19:37:07 +00:00
|
|
|
* @param aFunction is the function to be invoked.
|
|
|
|
*/
|
2020-10-27 11:03:35 +00:00
|
|
|
void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Invoke a function on all descendants of the group.
|
2020-12-19 23:29:10 +00:00
|
|
|
*
|
|
|
|
* @note This function should not add or remove items to the group or descendant groups.
|
2020-08-11 19:37:07 +00:00
|
|
|
* @param aFunction is the function to be invoked.
|
|
|
|
*/
|
2020-10-27 11:03:35 +00:00
|
|
|
void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction ) const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2022-11-28 17:10:02 +00:00
|
|
|
/**
|
|
|
|
* Check if the proposed type can be added to a group
|
|
|
|
* @param aType KICAD_T type to check
|
|
|
|
* @return true if the type can belong to a group, false otherwise
|
|
|
|
*/
|
|
|
|
static bool IsGroupableType( KICAD_T aType );
|
|
|
|
|
2022-11-11 17:09:25 +00:00
|
|
|
protected:
|
2023-03-24 13:02:13 +00:00
|
|
|
/// @copydoc BOARD_ITEM::swapData
|
2022-11-11 17:09:25 +00:00
|
|
|
void swapData( BOARD_ITEM* aImage ) override;
|
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
private:
|
2020-09-25 17:37:03 +00:00
|
|
|
std::unordered_set<BOARD_ITEM*> m_items; // Members of the group
|
|
|
|
wxString m_name; // Optional group name
|
2020-08-11 19:37:07 +00:00
|
|
|
};
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
#endif // CLASS_PCB_GROUP_H_
|