2019-04-14 00:44:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2022-08-24 10:30:27 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.TXT for contributors.
|
2019-04-14 00:44:05 +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
|
|
|
|
*/
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
#include <tools/ee_selection.h>
|
2020-06-19 11:48:00 +00:00
|
|
|
#include <sch_item.h>
|
2021-04-11 15:24:11 +00:00
|
|
|
#include <sch_reference_list.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2020-10-30 20:30:23 +00:00
|
|
|
#include <sch_sheet.h>
|
2020-06-19 11:48:00 +00:00
|
|
|
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2020-05-15 19:53:59 +00:00
|
|
|
EE_SELECTION::EE_SELECTION( SCH_SCREEN* aScreen ) :
|
|
|
|
SELECTION()
|
|
|
|
{
|
|
|
|
m_screen = aScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EDA_ITEM* EE_SELECTION::GetTopLeftItem( bool onlyModules ) const
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2022-04-12 17:13:15 +00:00
|
|
|
EDA_ITEM* topLeftConnectedItem = nullptr;
|
|
|
|
VECTOR2I topLeftConnectedPos;
|
|
|
|
|
2019-05-23 17:04:22 +00:00
|
|
|
EDA_ITEM* topLeftItem = nullptr;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeftPos;
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2022-04-12 17:13:15 +00:00
|
|
|
auto processItem =
|
|
|
|
[]( EDA_ITEM* aItem, EDA_ITEM** aCurrent, VECTOR2I* aCurrentPos )
|
|
|
|
{
|
|
|
|
VECTOR2I pos = aItem->GetPosition();
|
|
|
|
|
2022-04-12 18:18:15 +00:00
|
|
|
if( ( *aCurrent == nullptr )
|
2022-04-12 17:13:15 +00:00
|
|
|
|| ( pos.x < aCurrentPos->x )
|
|
|
|
|| ( pos.x == aCurrentPos->x && pos.y < aCurrentPos->y ) )
|
|
|
|
{
|
|
|
|
*aCurrent = aItem;
|
|
|
|
*aCurrentPos = pos;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item
|
2020-04-24 13:36:10 +00:00
|
|
|
// in the selection
|
2022-04-12 17:13:15 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
for( EDA_ITEM* item : m_items )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2022-04-12 17:13:15 +00:00
|
|
|
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
|
|
|
|
LIB_PIN* lib_pin = dynamic_cast<LIB_PIN*>( item );
|
2019-05-23 17:04:22 +00:00
|
|
|
|
2022-04-12 17:13:15 +00:00
|
|
|
// Prefer connection points (which should remain on grid)
|
|
|
|
|
|
|
|
if( ( sch_item && sch_item->IsConnectable() ) || lib_pin )
|
|
|
|
processItem( item, &topLeftConnectedItem, &topLeftConnectedPos );
|
|
|
|
|
|
|
|
processItem( item, &topLeftItem, &topLeftPos );
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 17:13:15 +00:00
|
|
|
if( topLeftConnectedItem )
|
|
|
|
return topLeftConnectedItem;
|
|
|
|
else
|
|
|
|
return topLeftItem;
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
2020-06-19 11:48:00 +00:00
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I EE_SELECTION::GetBoundingBox() const
|
2020-10-30 20:30:23 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox;
|
2020-10-30 20:30:23 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_items )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2021-06-30 21:28:46 +00:00
|
|
|
{
|
|
|
|
// Quiet Coverity warning. The LIB_SYMBOL field container is a Boost ptr_vector
|
|
|
|
// so the exception is legit.
|
|
|
|
try
|
|
|
|
{
|
2021-09-23 21:07:19 +00:00
|
|
|
bbox.Merge( static_cast<SCH_SYMBOL*>( item )->GetBoundingBox() );
|
2021-06-30 21:28:46 +00:00
|
|
|
}
|
2022-01-01 19:40:27 +00:00
|
|
|
catch( const boost::bad_pointer& )
|
2021-06-30 21:28:46 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG( "Invalid pointer." );
|
|
|
|
}
|
|
|
|
}
|
2020-10-30 20:30:23 +00:00
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
2021-06-30 21:28:46 +00:00
|
|
|
{
|
2020-10-30 20:30:23 +00:00
|
|
|
bbox.Merge( static_cast<SCH_SHEET*>( item )->GetBodyBoundingBox() );
|
2021-06-30 21:28:46 +00:00
|
|
|
}
|
2020-10-30 20:30:23 +00:00
|
|
|
else
|
2021-06-30 21:28:46 +00:00
|
|
|
{
|
2020-10-30 20:30:23 +00:00
|
|
|
bbox.Merge( item->GetBoundingBox() );
|
2021-06-30 21:28:46 +00:00
|
|
|
}
|
2020-10-30 20:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|