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
|
2023-10-06 17:04:00 +00:00
|
|
|
* Copyright (C) 1992-2023 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
|
|
|
|
*/
|
|
|
|
#include <bitmaps.h>
|
2021-10-31 16:32:24 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2022-11-18 21:04:54 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2022-09-29 23:16:25 +00:00
|
|
|
#include <footprint.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pcb_group.h>
|
2020-08-11 19:37:07 +00:00
|
|
|
#include <confirm.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2020-08-11 19:37:07 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
|
2022-11-28 17:10:02 +00:00
|
|
|
#include <wx/debug.h>
|
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
PCB_GROUP::PCB_GROUP( BOARD_ITEM* aParent ) :
|
2020-09-25 21:48:07 +00:00
|
|
|
BOARD_ITEM( aParent, PCB_GROUP_T )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
PCB_GROUP::PCB_GROUP( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer ) :
|
|
|
|
BOARD_ITEM( aParent, idtype, aLayer )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-28 17:10:02 +00:00
|
|
|
bool PCB_GROUP::IsGroupableType( KICAD_T aType )
|
|
|
|
{
|
|
|
|
switch ( aType )
|
|
|
|
{
|
|
|
|
case PCB_FOOTPRINT_T:
|
|
|
|
case PCB_PAD_T:
|
|
|
|
case PCB_SHAPE_T:
|
2023-10-23 17:23:24 +00:00
|
|
|
case PCB_REFERENCE_IMAGE_T:
|
2023-06-06 15:09:34 +00:00
|
|
|
case PCB_FIELD_T:
|
2022-11-28 17:10:02 +00:00
|
|
|
case PCB_TEXT_T:
|
|
|
|
case PCB_TEXTBOX_T:
|
2024-01-15 17:29:55 +00:00
|
|
|
case PCB_TABLE_T:
|
2022-11-28 19:28:04 +00:00
|
|
|
case PCB_GROUP_T:
|
2023-10-06 17:04:00 +00:00
|
|
|
case PCB_GENERATOR_T:
|
2022-11-28 17:10:02 +00:00
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
|
|
|
case PCB_ARC_T:
|
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
case PCB_DIM_ALIGNED_T:
|
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
case PCB_ZONE_T:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
bool PCB_GROUP::AddItem( BOARD_ITEM* aItem )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-11-28 17:10:02 +00:00
|
|
|
wxCHECK_MSG( IsGroupableType( aItem->Type() ), false,
|
|
|
|
wxT( "Invalid item type added to group: " ) + aItem->GetTypeDesc() );
|
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
// Items can only be in one group at a time
|
2020-09-25 17:37:03 +00:00
|
|
|
if( aItem->GetParentGroup() )
|
|
|
|
aItem->GetParentGroup()->RemoveItem( aItem );
|
2020-09-02 01:09:34 +00:00
|
|
|
|
|
|
|
m_items.insert( aItem );
|
2020-09-25 17:37:03 +00:00
|
|
|
aItem->SetParentGroup( this );
|
2020-09-02 01:09:34 +00:00
|
|
|
return true;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
bool PCB_GROUP::RemoveItem( BOARD_ITEM* aItem )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-09-02 01:09:34 +00:00
|
|
|
// Only clear the item's group field if it was inside this group
|
|
|
|
if( m_items.erase( aItem ) == 1 )
|
|
|
|
{
|
2020-09-25 17:37:03 +00:00
|
|
|
aItem->SetParentGroup( nullptr );
|
2020-09-02 01:09:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-09-24 01:05:46 +00:00
|
|
|
void PCB_GROUP::RemoveAll()
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
2020-09-25 17:37:03 +00:00
|
|
|
item->SetParentGroup( nullptr );
|
2020-09-24 01:05:46 +00:00
|
|
|
|
|
|
|
m_items.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-14 14:22:09 +00:00
|
|
|
/*
|
|
|
|
* @return if not in the footprint editor and aItem is in a footprint, returns the
|
|
|
|
* footprint's parent group. Otherwise, returns the aItem's parent group.
|
|
|
|
*/
|
|
|
|
PCB_GROUP* getClosestGroup( BOARD_ITEM* aItem, bool isFootprintEditor )
|
|
|
|
{
|
|
|
|
if( !isFootprintEditor && aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T )
|
|
|
|
return aItem->GetParent()->GetParentGroup();
|
|
|
|
else
|
|
|
|
return aItem->GetParentGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-06 18:02:29 +00:00
|
|
|
/// Returns the top level group inside the aScope group, or nullptr
|
|
|
|
PCB_GROUP* getNestedGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
|
2020-09-26 16:06:32 +00:00
|
|
|
{
|
2022-10-14 14:22:09 +00:00
|
|
|
PCB_GROUP* group = getClosestGroup( aItem, isFootprintEditor );
|
2021-01-11 22:56:56 +00:00
|
|
|
|
2022-10-06 18:02:29 +00:00
|
|
|
if( group == aScope )
|
|
|
|
return nullptr;
|
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
while( group && group->GetParentGroup() && group->GetParentGroup() != aScope )
|
2021-01-11 22:56:56 +00:00
|
|
|
{
|
2021-04-06 17:26:56 +00:00
|
|
|
if( group->GetParent()->Type() == PCB_FOOTPRINT_T && isFootprintEditor )
|
2021-01-11 22:56:56 +00:00
|
|
|
break;
|
2020-10-03 11:16:29 +00:00
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
group = group->GetParentGroup();
|
2021-01-11 22:56:56 +00:00
|
|
|
}
|
2020-09-26 16:06:32 +00:00
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
return group;
|
2020-09-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 18:02:29 +00:00
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
PCB_GROUP* PCB_GROUP::TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
|
2020-09-26 16:06:32 +00:00
|
|
|
{
|
2022-10-06 18:02:29 +00:00
|
|
|
return getNestedGroup( aItem, aScope, isFootprintEditor );
|
2021-04-06 17:26:56 +00:00
|
|
|
}
|
2020-09-26 16:06:32 +00:00
|
|
|
|
|
|
|
|
2021-04-06 17:26:56 +00:00
|
|
|
bool PCB_GROUP::WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
|
|
|
|
{
|
2022-10-14 14:22:09 +00:00
|
|
|
PCB_GROUP* group = getClosestGroup( aItem, isFootprintEditor );
|
|
|
|
|
|
|
|
if( group && group == aScope )
|
2022-10-06 18:02:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
PCB_GROUP* nested = getNestedGroup( aItem, aScope, isFootprintEditor );
|
2021-04-06 17:26:56 +00:00
|
|
|
|
2022-10-06 18:02:29 +00:00
|
|
|
return nested && nested->GetParentGroup() && nested->GetParentGroup() == aScope;
|
2020-09-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I PCB_GROUP::GetPosition() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
return GetBoundingBox().Centre();
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_GROUP::SetPosition( const VECTOR2I& aNewpos )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I delta = aNewpos - GetPosition();
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
Move( delta );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2021-09-27 10:28:46 +00:00
|
|
|
void PCB_GROUP::SetLocked( bool aLockState )
|
|
|
|
{
|
|
|
|
BOARD_ITEM::SetLocked( aLockState );
|
|
|
|
|
|
|
|
RunOnChildren(
|
|
|
|
[&]( BOARD_ITEM* child )
|
|
|
|
{
|
|
|
|
child->SetLocked( aLockState );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
EDA_ITEM* PCB_GROUP::Clone() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
// Use copy constructor to get the same uuid and other fields
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* newGroup = new PCB_GROUP( *this );
|
2020-08-11 19:37:07 +00:00
|
|
|
return newGroup;
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* PCB_GROUP::DeepClone() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
// Use copy constructor to get the same uuid and other fields
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* newGroup = new PCB_GROUP( *this );
|
2020-08-11 19:37:07 +00:00
|
|
|
newGroup->m_items.clear();
|
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
for( BOARD_ITEM* member : m_items )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
if( member->Type() == PCB_GROUP_T )
|
2020-08-12 11:23:30 +00:00
|
|
|
newGroup->AddItem( static_cast<PCB_GROUP*>( member )->DeepClone() );
|
2020-08-11 19:37:07 +00:00
|
|
|
else
|
|
|
|
newGroup->AddItem( static_cast<BOARD_ITEM*>( member->Clone() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return newGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
PCB_GROUP* PCB_GROUP::DeepDuplicate() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2021-02-09 16:35:43 +00:00
|
|
|
PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( Duplicate() );
|
2020-08-11 19:37:07 +00:00
|
|
|
newGroup->m_items.clear();
|
|
|
|
|
2020-09-02 01:09:34 +00:00
|
|
|
for( BOARD_ITEM* member : m_items )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
if( member->Type() == PCB_GROUP_T )
|
2020-08-12 11:23:30 +00:00
|
|
|
newGroup->AddItem( static_cast<PCB_GROUP*>( member )->DeepDuplicate() );
|
2020-08-11 19:37:07 +00:00
|
|
|
else
|
|
|
|
newGroup->AddItem( static_cast<BOARD_ITEM*>( member->Duplicate() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return newGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-11 17:09:25 +00:00
|
|
|
void PCB_GROUP::swapData( BOARD_ITEM* aImage )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_GROUP_T );
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
std::swap( *( (PCB_GROUP*) this ), *( (PCB_GROUP*) aImage ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool PCB_GROUP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-10-02 11:32:48 +00:00
|
|
|
// Groups are selected by promoting a selection of one of their children
|
|
|
|
return false;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool PCB_GROUP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-10-02 11:32:48 +00:00
|
|
|
// Groups are selected by promoting a selection of one of their children
|
2020-09-02 01:09:34 +00:00
|
|
|
return false;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I PCB_GROUP::GetBoundingBox() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2022-11-11 20:15:02 +00:00
|
|
|
for( BOARD_ITEM* item : m_items )
|
2022-09-29 23:16:25 +00:00
|
|
|
{
|
2022-11-11 20:15:02 +00:00
|
|
|
if( item->Type() == PCB_FOOTPRINT_T )
|
|
|
|
bbox.Merge( static_cast<FOOTPRINT*>( item )->GetBoundingBox( true, false ) );
|
|
|
|
else
|
|
|
|
bbox.Merge( item->GetBoundingBox() );
|
2022-09-29 23:16:25 +00:00
|
|
|
}
|
2020-09-02 01:09:34 +00:00
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
bbox.Inflate( pcbIUScale.mmToIU( 0.25 ) ); // Give a min size to the bbox
|
2022-11-11 20:15:02 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return bbox;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-11-18 21:04:54 +00:00
|
|
|
std::shared_ptr<SHAPE> PCB_GROUP::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
|
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
shape->AddShape( item->GetEffectiveShape( aLayer, aFlash )->Clone() );
|
|
|
|
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
INSPECT_RESULT PCB_GROUP::Visit( INSPECTOR aInspector, void* aTestData,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
for( KICAD_T scanType : aScanTypes )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == Type() )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
return INSPECT_RESULT::CONTINUE;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
LSET PCB_GROUP::GetLayerSet() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
LSET aSet;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
aSet |= item->GetLayerSet();
|
2020-09-02 01:09:34 +00:00
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
return aSet;
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2023-08-01 17:37:19 +00:00
|
|
|
bool PCB_GROUP::IsOnLayer( PCB_LAYER_ID aLayer ) const
|
2020-09-02 01:09:34 +00:00
|
|
|
{
|
|
|
|
// A group is on a layer if any item is on the layer
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
{
|
2023-08-01 17:37:19 +00:00
|
|
|
if( item->IsOnLayer( aLayer ) )
|
2020-09-02 01:09:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
void PCB_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-12-23 21:42:55 +00:00
|
|
|
aCount = 1;
|
|
|
|
aLayers[0] = LAYER_ANCHOR;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-09-21 15:03:08 +00:00
|
|
|
double PCB_GROUP::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
if( aView->IsLayerVisible( LAYER_ANCHOR ) )
|
2020-09-21 15:03:08 +00:00
|
|
|
return 0.0;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2020-09-21 15:03:08 +00:00
|
|
|
return std::numeric_limits<double>::max();
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_GROUP::Move( const VECTOR2I& aMoveVector )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-09-02 01:09:34 +00:00
|
|
|
for( BOARD_ITEM* member : m_items )
|
2020-08-15 02:45:56 +00:00
|
|
|
member->Move( aMoveVector );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-01-13 19:32:00 +00:00
|
|
|
void PCB_GROUP::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
item->Rotate( aRotCentre, aAngle );
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_GROUP::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
item->Flip( aCentre, aFlipLeftRight );
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2024-06-27 09:11:55 +00:00
|
|
|
wxString PCB_GROUP::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
if( m_name.empty() )
|
2022-11-11 20:15:02 +00:00
|
|
|
return wxString::Format( _( "Unnamed Group, %zu members" ), m_items.size() );
|
|
|
|
else
|
|
|
|
return wxString::Format( _( "Group '%s', %zu members" ), m_name, m_items.size() );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS PCB_GROUP::GetMenuImage() const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::module;
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-08-12 11:23:30 +00:00
|
|
|
void PCB_GROUP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Group" ), m_name.empty() ? _( "<unnamed>" ) : m_name );
|
2022-02-04 22:44:59 +00:00
|
|
|
aList.emplace_back( _( "Members" ), wxString::Format( wxT( "%zu" ), m_items.size() ) );
|
2021-07-22 11:45:33 +00:00
|
|
|
|
2021-10-31 16:32:24 +00:00
|
|
|
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
|
2021-07-22 11:45:33 +00:00
|
|
|
aList.emplace_back( _( "Status" ), _( "Locked" ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
void PCB_GROUP::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
aFunction( item );
|
|
|
|
}
|
|
|
|
catch( std::bad_function_call& )
|
|
|
|
{
|
2020-09-02 01:09:34 +00:00
|
|
|
wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnChildren" ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:45:56 +00:00
|
|
|
|
2024-01-22 23:32:13 +00:00
|
|
|
void PCB_GROUP::RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
|
|
|
|
int aDepth ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2024-01-22 23:32:13 +00:00
|
|
|
// Avoid freezes with infinite recursion
|
|
|
|
if( aDepth > 20 )
|
|
|
|
return;
|
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
{
|
|
|
|
aFunction( item );
|
2020-09-02 01:09:34 +00:00
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
if( item->Type() == PCB_GROUP_T )
|
2024-01-22 23:32:13 +00:00
|
|
|
item->RunOnDescendants( aFunction, aDepth + 1 );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( std::bad_function_call& )
|
|
|
|
{
|
2020-09-02 01:09:34 +00:00
|
|
|
wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnDescendants" ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-14 21:39:42 +00:00
|
|
|
|
2023-11-09 13:55:00 +00:00
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool PCB_GROUP::operator==( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const PCB_GROUP& other = static_cast<const PCB_GROUP&>( aOther );
|
|
|
|
|
|
|
|
if( m_items.size() != other.m_items.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The items in groups are in unordered sets hashed by the pointer value, so we need to
|
|
|
|
// order them by UUID (EDA_ITEM_SET) to compare
|
|
|
|
EDA_ITEM_SET itemSet( m_items.begin(), m_items.end() );
|
|
|
|
EDA_ITEM_SET otherItemSet( other.m_items.begin(), other.m_items.end() );
|
|
|
|
|
|
|
|
for( auto it1 = itemSet.begin(), it2 = otherItemSet.begin(); it1 != itemSet.end(); ++it1, ++it2 )
|
|
|
|
{
|
|
|
|
// Compare UUID instead of the items themselves because we only care if the contents
|
|
|
|
// of the group has changed, not which elements in the group have changed
|
|
|
|
if( ( *it1 )->m_Uuid != ( *it2 )->m_Uuid )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PCB_GROUP::Similarity( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const PCB_GROUP& other = static_cast<const PCB_GROUP&>( aOther );
|
|
|
|
|
|
|
|
double similarity = 0.0;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_items )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* otherItem : other.m_items )
|
|
|
|
{
|
|
|
|
similarity += item->Similarity( *otherItem );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return similarity / m_items.size();
|
|
|
|
}
|
2024-03-20 20:18:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct PCB_GROUP_DESC
|
|
|
|
{
|
|
|
|
PCB_GROUP_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( PCB_GROUP );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_GROUP, BOARD_ITEM> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_GROUP ), TYPE_HASH( BOARD_ITEM ) );
|
|
|
|
|
|
|
|
propMgr.Mask( TYPE_HASH( PCB_GROUP ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( PCB_GROUP ), TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( PCB_GROUP ), TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) );
|
|
|
|
|
|
|
|
const wxString groupTab = _HKI( "Group Properties" );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GROUP, wxString>( _HKI( "Name" ),
|
|
|
|
&PCB_GROUP::SetName, &PCB_GROUP::GetName ),
|
|
|
|
groupTab );
|
|
|
|
}
|
|
|
|
} _PCB_GROUP_DESC;
|