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>
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2004-2021 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>
|
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>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_line.h>
|
2020-04-26 20:53:29 +00:00
|
|
|
#include <sch_screen.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <transform.h>
|
2020-03-30 13:14:44 +00:00
|
|
|
#include "sch_reference_list.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,
|
2020-06-19 11:48:00 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2020-06-24 17:35:33 +00:00
|
|
|
SCH_JUNCTION_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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-13 01:15:45 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::MovableItems[] =
|
|
|
|
{
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T EE_COLLECTOR::WiresOnly[] = {
|
|
|
|
SCH_LINE_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
const KICAD_T EE_COLLECTOR::FieldOwners[] = {
|
2020-10-28 22:32:08 +00:00
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_T,
|
2020-11-17 16:02:47 +00:00
|
|
|
SCH_GLOBAL_LABEL_T,
|
2020-10-28 22:32:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-10-02 20:25:14 +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,
|
2020-04-10 13:08:14 +00:00
|
|
|
int aUnit, int aConvert )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2020-04-10 13:08:14 +00:00
|
|
|
// Components and sheets own their own children so have to be visited even if
|
|
|
|
// they're not in the filter list
|
|
|
|
bool componentsVisited = false;
|
|
|
|
bool sheetsVisited = false;
|
2020-11-17 16:02:47 +00:00
|
|
|
bool globalLabelsVisited = false;
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( const KICAD_T* filter = aFilterList; *filter != EOT; ++filter )
|
|
|
|
{
|
2020-04-10 13:08:14 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( *filter ) )
|
|
|
|
{
|
2020-04-11 14:08:10 +00:00
|
|
|
if( *filter == SCH_COMPONENT_T || *filter == SCH_LOCATE_ANY_T )
|
2020-04-10 13:08:14 +00:00
|
|
|
componentsVisited = true;
|
2020-04-11 14:08:10 +00:00
|
|
|
|
|
|
|
if( *filter == SCH_SHEET_T || *filter == SCH_LOCATE_ANY_T )
|
2020-04-10 13:08:14 +00:00
|
|
|
sheetsVisited = true;
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
if( *filter == SCH_GLOBAL_LABEL_T || *filter == SCH_LOCATE_ANY_T )
|
|
|
|
globalLabelsVisited = true;
|
|
|
|
|
2020-10-02 20:25:14 +00:00
|
|
|
item->Visit( m_inspector, nullptr, m_scanTypes );
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !componentsVisited )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_COMPONENT_T ) )
|
2020-10-02 20:25:14 +00:00
|
|
|
item->Visit( m_inspector, nullptr, m_scanTypes );
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !sheetsVisited )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_SHEET_T ) )
|
2020-10-02 20:25:14 +00:00
|
|
|
item->Visit( m_inspector, nullptr, m_scanTypes );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( !globalLabelsVisited )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
|
|
|
|
item->Visit( m_inspector, nullptr, m_scanTypes );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[],
|
2020-04-10 13:08:14 +00:00
|
|
|
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
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
for( LIB_ITEM& item : aItems )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-10-02 20:25:14 +00:00
|
|
|
if( item.Visit( m_inspector, nullptr, m_scanTypes ) == SEARCH_RESULT::QUIT )
|
2019-06-25 23:39:58 +00:00
|
|
|
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;
|
|
|
|
|
2020-10-02 20:25:14 +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
|
|
|
|
2020-10-02 20:25:14 +00:00
|
|
|
if(( m_list[0]->Type() == SCH_LINE_T) && ( m_list[1]->Type() == SCH_LINE_T) )
|
|
|
|
return ( ( SCH_LINE* ) m_list[0])->GetLayer() == ( ( SCH_LINE* ) m_list[1])->GetLayer();
|
2011-07-12 06:57:11 +00:00
|
|
|
|
2020-10-02 20:25:14 +00:00
|
|
|
if(( m_list[0]->Type() == SCH_LINE_T) && is_busentry1 )
|
2011-07-12 06:57:11 +00:00
|
|
|
return true;
|
|
|
|
|
2020-10-02 20:25:14 +00:00
|
|
|
if( is_busentry0 && ( m_list[1]->Type() == SCH_LINE_T) )
|
2011-07-12 06:57:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-24 20:55:32 +00:00
|
|
|
void CollectOtherUnits( const wxString& aRef, int aUnit, SCH_SHEET_PATH& aSheet,
|
2020-03-30 13:14:44 +00:00
|
|
|
std::vector<SCH_COMPONENT*>* otherUnits )
|
|
|
|
{
|
2020-10-24 20:55:32 +00:00
|
|
|
SCH_REFERENCE_LIST components;
|
2020-11-15 16:08:31 +00:00
|
|
|
aSheet.GetSymbols( components );
|
2020-03-30 13:14:44 +00:00
|
|
|
|
2020-10-24 20:55:32 +00:00
|
|
|
for( unsigned i = 0; i < components.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE component = components[i];
|
2020-03-30 13:14:44 +00:00
|
|
|
|
2020-10-24 20:55:32 +00:00
|
|
|
if( component.GetRef() == aRef && component.GetUnit() != aUnit )
|
2020-11-15 16:08:31 +00:00
|
|
|
otherUnits->push_back( component.GetSymbol() );
|
2020-03-30 13:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|