2011-07-12 06:57:11 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-07-12 06:57:11 +00:00
|
|
|
*
|
2018-04-13 13:58:25 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2019-04-04 22:49:49 +00:00
|
|
|
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2011-07-12 06:57:11 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2011-12-13 15:37:33 +00:00
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
#include <ee_collectors.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <lib_item.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_line.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <transform.h>
|
2011-07-12 06:57:11 +00:00
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::AllItems[] = {
|
2019-05-08 18:56:03 +00:00
|
|
|
SCH_LOCATE_ANY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::EditableItems[] = {
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
2019-04-15 23:56:41 +00:00
|
|
|
SCH_HIER_LABEL_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2017-10-31 16:33:37 +00:00
|
|
|
SCH_LINE_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::ComponentsOnly[] = {
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_COMPONENT_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::SheetsOnly[] = {
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
SEARCH_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData )
|
2011-07-12 06:57:11 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
if( aItem->Type() == LIB_PIN_T )
|
|
|
|
{
|
|
|
|
// Special selection rules apply to pins of different units when edited in
|
2020-03-06 20:02:58 +00:00
|
|
|
// synchronized pins mode. Leave it to EE_SELECTION_TOOL::Selectable() to
|
2019-05-08 18:56:03 +00:00
|
|
|
// decide what to do with them.
|
|
|
|
}
|
|
|
|
else if( m_Unit || m_Convert )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
|
|
|
LIB_ITEM* lib_item = dynamic_cast<LIB_ITEM*>( aItem );
|
|
|
|
|
|
|
|
if( m_Unit && lib_item && lib_item->GetUnit() && lib_item->GetUnit() != m_Unit )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2019-05-06 15:01:39 +00:00
|
|
|
if( m_Convert && lib_item && lib_item->GetConvert() && lib_item->GetConvert() != m_Convert )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 19:28:16 +00:00
|
|
|
if( aItem->HitTest( m_RefPos, m_Threshold ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
Append( aItem );
|
2011-07-12 06:57:11 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2011-07-12 06:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, const KICAD_T aFilterList[], const wxPoint& aPos,
|
|
|
|
int aUnit, int aConvert )
|
|
|
|
{
|
|
|
|
Empty(); // empty the collection just in case
|
|
|
|
|
|
|
|
SetScanTypes( aFilterList );
|
|
|
|
m_Unit = aUnit;
|
|
|
|
m_Convert = aConvert;
|
|
|
|
|
|
|
|
// remember where the snapshot was taken from and pass refPos to the Inspect() function.
|
|
|
|
SetRefPos( aPos );
|
|
|
|
|
|
|
|
if( aScreen )
|
|
|
|
{
|
|
|
|
for( const KICAD_T* filter = aFilterList; *filter != EOT; ++filter )
|
|
|
|
{
|
|
|
|
for( auto item : aScreen->Items().OfType( *filter ) )
|
|
|
|
item->Visit( m_inspector, nullptr, m_ScanTypes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[],
|
|
|
|
const wxPoint& aPos, int aUnit, int aConvert )
|
2011-07-12 06:57:11 +00:00
|
|
|
{
|
|
|
|
Empty(); // empty the collection just in case
|
|
|
|
|
|
|
|
SetScanTypes( aFilterList );
|
2019-05-06 02:32:01 +00:00
|
|
|
m_Unit = aUnit;
|
|
|
|
m_Convert = aConvert;
|
2011-07-12 06:57:11 +00:00
|
|
|
|
|
|
|
// remember where the snapshot was taken from and pass refPos to the Inspect() function.
|
2019-04-21 23:45:34 +00:00
|
|
|
SetRefPos( aPos );
|
2011-07-12 06:57:11 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto& item : aItems )
|
|
|
|
{
|
|
|
|
if( item.Visit( m_inspector, nullptr, m_ScanTypes ) == SEARCH_RESULT::QUIT )
|
|
|
|
break;
|
|
|
|
}
|
2011-07-12 06:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
bool EE_COLLECTOR::IsCorner() const
|
2011-07-12 06:57:11 +00:00
|
|
|
{
|
|
|
|
if( GetCount() != 2 )
|
|
|
|
return false;
|
|
|
|
|
2015-11-03 19:44:05 +00:00
|
|
|
bool is_busentry0 = (dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[0] ) != NULL);
|
|
|
|
bool is_busentry1 = (dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[1] ) != NULL);
|
2013-04-01 10:35:20 +00:00
|
|
|
|
2011-07-12 06:57:11 +00:00
|
|
|
if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_LINE_T) )
|
2017-11-27 22:44:41 +00:00
|
|
|
return ( ( SCH_LINE* ) m_List[0])->GetLayer() == ( ( SCH_LINE* ) m_List[1])->GetLayer();
|
2011-07-12 06:57:11 +00:00
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
if( (m_List[0]->Type() == SCH_LINE_T) && is_busentry1 )
|
2011-07-12 06:57:11 +00:00
|
|
|
return true;
|
|
|
|
|
2013-04-01 10:35:20 +00:00
|
|
|
if( is_busentry0 && (m_List[1]->Type() == SCH_LINE_T) )
|
2011-07-12 06:57:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
bool EE_COLLECTOR::IsDraggableJunction() const
|
2011-07-12 06:57:11 +00:00
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_List.size(); i++ )
|
2017-12-13 05:12:06 +00:00
|
|
|
if( ( (SCH_ITEM*) m_List[ i ] )->Type() == SCH_JUNCTION_T )
|
|
|
|
return true;
|
2011-07-12 06:57:11 +00:00
|
|
|
|
2017-12-13 05:12:06 +00:00
|
|
|
return false;
|
2011-07-12 06:57:11 +00:00
|
|
|
}
|