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>
|
|
|
|
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
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
|
|
|
|
*/
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
/**
|
|
|
|
* @file sch_collectors.cpp
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <transform.h>
|
|
|
|
#include <sch_collectors.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_line.h>
|
2013-04-01 10:35:20 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2011-07-12 06:57:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::AllItems[] = {
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_LINE_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
LIB_PIN_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::AllItemsButPins[] = {
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_LINE_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::EditableItems[] = {
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2012-12-08 17:24:49 +00:00
|
|
|
const KICAD_T SCH_COLLECTOR::CmpFieldValueOnly[] = {
|
|
|
|
SCH_FIELD_LOCATE_VALUE_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::CmpFieldReferenceOnly[] = {
|
|
|
|
SCH_FIELD_LOCATE_REFERENCE_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::CmpFieldFootprintOnly[] = {
|
2018-09-24 14:31:35 +00:00
|
|
|
SCH_FIELD_LOCATE_FOOTPRINT_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::CmpFieldDatasheetOnly[] = {
|
|
|
|
SCH_FIELD_LOCATE_DATASHEET_T,
|
|
|
|
EOT
|
2012-12-08 17:24:49 +00:00
|
|
|
};
|
|
|
|
|
2011-07-12 06:57:11 +00:00
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::MovableItems[] = {
|
|
|
|
SCH_MARKER_T,
|
2011-10-19 20:32:21 +00:00
|
|
|
SCH_JUNCTION_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_NO_CONNECT_T,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
// SCH_LINE_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::DraggableItems[] = {
|
|
|
|
SCH_JUNCTION_T,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_LINE_T,
|
2012-12-21 12:56:17 +00:00
|
|
|
SCH_LABEL_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::RotatableItems[] = {
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::ParentItems[] = {
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
2013-04-01 10:35:20 +00:00
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2011-07-12 06:57:11 +00:00
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::ComponentsOnly[] = {
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::SheetsOnly[] = {
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T SCH_COLLECTOR::SheetsAndSheetLabels[] = {
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-28 20:30:50 +00:00
|
|
|
const KICAD_T SCH_COLLECTOR::OrientableItems[] = {
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_BITMAP_T,
|
2015-04-26 16:32:16 +00:00
|
|
|
SCH_SHEET_T,
|
2011-10-28 20:30:50 +00:00
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-11 18:29:22 +00:00
|
|
|
const KICAD_T SCH_COLLECTOR::CopyableItems[] = {
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-06 05:25:52 +00:00
|
|
|
const KICAD_T SCH_COLLECTOR::DoubleClickItems[] = {
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_MARKER_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData )
|
2011-07-12 06:57:11 +00:00
|
|
|
{
|
|
|
|
if( aItem->Type() != LIB_PIN_T && !aItem->HitTest( m_RefPos ) )
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
|
|
|
|
// Pins have special hit testing requirements that are relative to their parent
|
|
|
|
// SCH_COMPONENT item.
|
|
|
|
if( aItem->Type() == LIB_PIN_T )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aTestData && ( (EDA_ITEM*) aTestData )->Type() == SCH_COMPONENT_T,
|
|
|
|
SEARCH_CONTINUE, wxT( "Cannot inspect invalid data. Bad programmer!" ) );
|
|
|
|
|
|
|
|
// Pin hit testing is relative to the components position and orientation in the
|
|
|
|
// schematic. The hit test position must be converted to library coordinates.
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aTestData;
|
|
|
|
TRANSFORM transform = component->GetTransform().InverseTransform();
|
2011-10-19 20:32:21 +00:00
|
|
|
wxPoint position = transform.TransformCoordinate( m_RefPos - component->GetPosition() );
|
2011-07-12 06:57:11 +00:00
|
|
|
|
|
|
|
position.y *= -1; // Y axis polarity in schematic is inverted from library.
|
|
|
|
|
|
|
|
if( !aItem->HitTest( position ) )
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Append( aItem );
|
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[],
|
|
|
|
const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
Empty(); // empty the collection just in case
|
|
|
|
|
|
|
|
SetScanTypes( aFilterList );
|
|
|
|
|
|
|
|
// remember where the snapshot was taken from and pass refPos to the Inspect() function.
|
|
|
|
SetRefPos( aPosition );
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
EDA_ITEM::IterateForward( aItem, m_inspector, NULL, m_ScanTypes );
|
2011-07-12 06:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_COLLECTOR::IsCorner() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_COLLECTOR::IsNode( bool aIncludePins ) const
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_List.size(); i++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) m_List[ i ];
|
|
|
|
KICAD_T type = item->Type();
|
|
|
|
|
|
|
|
if( type == SCH_JUNCTION_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( type == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
if( item->GetLayer() != LAYER_WIRE )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( type == LIB_PIN_T )
|
|
|
|
{
|
|
|
|
if( !aIncludePins )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Any other item types indicate that this collection is not a node.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_COLLECTOR::IsDraggableJunction() const
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2011-12-01 16:49:28 +00:00
|
|
|
|
|
|
|
|
2018-02-12 01:31:11 +00:00
|
|
|
/**
|
|
|
|
* A singleton item of this class is returned for a weak reference that no longer exists.
|
|
|
|
* Its sole purpose is to flag the item as having been deleted.
|
|
|
|
*/
|
|
|
|
class DELETED_SCH_ITEM : public SCH_ITEM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DELETED_SCH_ITEM() :
|
|
|
|
SCH_ITEM( nullptr, NOT_USED )
|
|
|
|
{}
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override
|
|
|
|
{
|
|
|
|
return _( "(Deleted Item)" );
|
|
|
|
}
|
|
|
|
wxString GetClass() const override
|
|
|
|
{
|
|
|
|
return wxT( "DELETED_SCH_ITEM" );
|
|
|
|
}
|
2018-02-12 01:31:11 +00:00
|
|
|
|
|
|
|
// define pure virtuals:
|
|
|
|
wxPoint GetPosition() const override { return wxPoint(); }
|
|
|
|
void SetPosition( const wxPoint& ) override {}
|
|
|
|
void Draw( EDA_DRAW_PANEL* , wxDC* , const wxPoint& , GR_DRAWMODE , COLOR4D ) override {}
|
2018-02-12 18:36:03 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2018-02-12 01:31:11 +00:00
|
|
|
void Show( int , std::ostream& ) const override {}
|
2018-02-12 18:36:03 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-12 01:31:11 +00:00
|
|
|
void Move( const wxPoint& ) override {}
|
|
|
|
void MirrorY( int ) override {}
|
|
|
|
void MirrorX( int ) override {}
|
|
|
|
void Rotate( wxPoint ) override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DELETED_SCH_ITEM g_DeletedSchItem;
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ITEM* SCH_FIND_COLLECTOR::GetItem( int ndx ) const
|
|
|
|
{
|
|
|
|
if( (unsigned)ndx >= (unsigned)GetCount() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Do not simply return m_List[ ndx ] as it might have been deleted. Instead
|
|
|
|
// treat it as a weak reference and search the sheets for an item with the same
|
|
|
|
// pointer value.
|
|
|
|
|
2018-04-09 20:18:15 +00:00
|
|
|
void* weakRef = m_List[ ndx ];
|
|
|
|
SCH_ITEM* item = &g_DeletedSchItem;
|
2018-02-12 01:31:11 +00:00
|
|
|
|
2018-04-09 20:18:15 +00:00
|
|
|
INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* candidate, void* testData )
|
2018-02-12 01:31:11 +00:00
|
|
|
{
|
2018-04-09 20:18:15 +00:00
|
|
|
if( (void*) candidate == weakRef )
|
2018-02-12 01:31:11 +00:00
|
|
|
{
|
2018-04-09 20:18:15 +00:00
|
|
|
item = (SCH_ITEM*) candidate;
|
|
|
|
return SEARCH_QUIT;
|
2018-02-12 01:31:11 +00:00
|
|
|
}
|
2018-04-09 20:18:15 +00:00
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_sheetPaths.size(); i++ )
|
|
|
|
{
|
|
|
|
EDA_ITEM::IterateForward( m_sheetPaths[ i ].LastDrawList(),
|
|
|
|
inspector, nullptr, SCH_COLLECTOR::AllItems );
|
2018-02-12 01:31:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:18:15 +00:00
|
|
|
return item;
|
2018-02-12 01:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ITEM* SCH_FIND_COLLECTOR::operator[]( int ndx ) const
|
|
|
|
{
|
|
|
|
return GetItem( ndx );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-20 17:13:40 +00:00
|
|
|
bool SCH_FIND_COLLECTOR::PassedEnd() const
|
2011-12-13 15:37:33 +00:00
|
|
|
{
|
|
|
|
bool retv = false;
|
|
|
|
|
|
|
|
wxUint32 flags = m_findReplaceData.GetFlags();
|
|
|
|
|
|
|
|
if( GetCount() == 0 )
|
|
|
|
return true;
|
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
if( !(flags & FR_SEARCH_WRAP) || (flags & FR_SEARCH_REPLACE) )
|
2011-12-13 15:37:33 +00:00
|
|
|
{
|
|
|
|
if( flags & wxFR_DOWN )
|
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( m_foundIndex >= GetCount() )
|
2011-12-13 15:37:33 +00:00
|
|
|
retv = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( m_foundIndex < 0 )
|
2011-12-13 15:37:33 +00:00
|
|
|
retv = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
|
|
|
void SCH_FIND_COLLECTOR::dump()
|
|
|
|
{
|
|
|
|
int tmp = m_foundIndex;
|
|
|
|
|
|
|
|
wxLogTrace( traceFindReplace, wxT( "%d items found to replace %s with %s." ),
|
|
|
|
GetCount(), GetChars( m_findReplaceData.GetFindString() ),
|
|
|
|
GetChars( m_findReplaceData.GetReplaceString() ) );
|
|
|
|
|
|
|
|
for( m_foundIndex = 0; m_foundIndex < GetCount(); m_foundIndex++ )
|
2018-04-10 10:52:12 +00:00
|
|
|
wxLogTrace( traceFindReplace, wxT( " " ) + GetText( MILLIMETRES ) );
|
2011-12-13 15:37:33 +00:00
|
|
|
|
|
|
|
m_foundIndex = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIND_COLLECTOR::UpdateIndex()
|
|
|
|
{
|
|
|
|
wxUint32 flags = m_findReplaceData.GetFlags();
|
|
|
|
|
|
|
|
if( flags & wxFR_DOWN )
|
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( m_foundIndex < GetCount() )
|
|
|
|
m_foundIndex += 1;
|
2011-12-13 15:37:33 +00:00
|
|
|
if( (m_foundIndex >= GetCount()) && (flags & FR_SEARCH_WRAP) )
|
|
|
|
m_foundIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( m_foundIndex >= 0 )
|
|
|
|
m_foundIndex -= 1;
|
2011-12-13 15:37:33 +00:00
|
|
|
if( (m_foundIndex < 0) && (flags & FR_SEARCH_WRAP) )
|
|
|
|
m_foundIndex = GetCount() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
SCH_FIND_COLLECTOR_DATA SCH_FIND_COLLECTOR::GetFindData( int aIndex )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( (unsigned) aIndex < m_data.size(), SCH_FIND_COLLECTOR_DATA(),
|
|
|
|
wxT( "Attempt to get find data outside of list boundary." ) );
|
|
|
|
|
|
|
|
return m_data[ aIndex ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString SCH_FIND_COLLECTOR::GetText( EDA_UNITS_T aUnits )
|
2011-12-01 16:49:28 +00:00
|
|
|
{
|
2011-12-13 15:37:33 +00:00
|
|
|
wxCHECK_MSG( (GetCount() != 0) && IsValidIndex( m_foundIndex ), wxEmptyString,
|
2011-12-01 16:49:28 +00:00
|
|
|
wxT( "Cannot get found item at invalid index." ) );
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
SCH_FIND_COLLECTOR_DATA data = m_data[ m_foundIndex ];
|
2018-02-12 01:31:11 +00:00
|
|
|
EDA_ITEM* foundItem = GetItem( m_foundIndex );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
|
|
|
if( data.GetParent() )
|
|
|
|
{
|
2018-07-05 15:50:21 +00:00
|
|
|
return wxString::Format( _( "Match %i of %i: %s of %s in sheet %s" ),
|
|
|
|
m_foundIndex + 1,
|
|
|
|
GetCount(),
|
2018-04-10 10:52:12 +00:00
|
|
|
foundItem->GetSelectMenuText( aUnits ),
|
|
|
|
data.GetParent()->GetSelectMenuText( aUnits ),
|
|
|
|
data.GetSheetPath() );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-05 15:50:21 +00:00
|
|
|
return wxString::Format( _( "Match %i of %i: %s in sheet %s" ),
|
|
|
|
m_foundIndex + 1,
|
|
|
|
GetCount(),
|
2018-04-10 10:52:12 +00:00
|
|
|
foundItem->GetSelectMenuText( aUnits ),
|
|
|
|
data.GetSheetPath() );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
EDA_ITEM* SCH_FIND_COLLECTOR::GetItem( SCH_FIND_COLLECTOR_DATA& aData )
|
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( PassedEnd() )
|
2011-12-13 15:37:33 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
aData = m_data[ m_foundIndex ];
|
2018-02-12 01:31:11 +00:00
|
|
|
return GetItem( m_foundIndex );
|
2011-12-13 15:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
bool SCH_FIND_COLLECTOR::ReplaceItem( SCH_SHEET_PATH* aSheetPath )
|
2011-12-13 15:37:33 +00:00
|
|
|
{
|
2013-07-20 17:13:40 +00:00
|
|
|
if( PassedEnd() )
|
2011-12-13 15:37:33 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
wxCHECK_MSG( IsValidIndex( m_foundIndex ), false,
|
|
|
|
wxT( "Invalid replace list index in SCH_FIND_COLLECTOR." ) );
|
|
|
|
|
2018-02-12 01:31:11 +00:00
|
|
|
EDA_ITEM* item = GetItem( m_foundIndex );
|
2011-12-13 15:37:33 +00:00
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
bool replaced = item->Replace( m_findReplaceData, aSheetPath );
|
2011-12-13 15:37:33 +00:00
|
|
|
|
|
|
|
return replaced;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData )
|
2011-12-01 16:49:28 +00:00
|
|
|
{
|
|
|
|
wxPoint position;
|
|
|
|
|
2018-02-12 01:31:11 +00:00
|
|
|
if( aItem->Matches( m_findReplaceData, m_currentSheetPath, &position ) )
|
2011-12-01 16:49:28 +00:00
|
|
|
{
|
|
|
|
if( aItem->Type() == LIB_PIN_T )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aTestData && ( (EDA_ITEM*) aTestData )->Type() == SCH_COMPONENT_T,
|
|
|
|
SEARCH_CONTINUE, wxT( "Cannot inspect invalid data. Bad programmer!" ) );
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
// Pin positions are relative to their parent component's position and
|
|
|
|
// orientation in the schematic. The pin's position must be converted
|
|
|
|
// schematic coordinates.
|
2011-12-01 16:49:28 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aTestData;
|
|
|
|
TRANSFORM transform = component->GetTransform();
|
|
|
|
position.y = -position.y;
|
|
|
|
position = transform.TransformCoordinate( position ) + component->GetPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
Append( aItem );
|
2018-02-12 01:31:11 +00:00
|
|
|
m_data.push_back( SCH_FIND_COLLECTOR_DATA( position,
|
|
|
|
m_currentSheetPath->PathHumanReadable(),
|
2011-12-01 16:49:28 +00:00
|
|
|
(SCH_ITEM*) aTestData ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-18 15:38:46 +00:00
|
|
|
void SCH_FIND_COLLECTOR::SetReplaceString( const wxString &aReplaceString )
|
|
|
|
{
|
|
|
|
m_findReplaceData.SetReplaceString( aReplaceString );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
2013-07-14 18:08:20 +00:00
|
|
|
if( !IsSearchRequired( aFindReplaceData ) && !m_List.empty() && !m_forceSearch )
|
2011-12-01 16:49:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_findReplaceData = aFindReplaceData;
|
|
|
|
Empty(); // empty the collection just in case
|
|
|
|
m_data.clear();
|
2011-12-13 15:37:33 +00:00
|
|
|
m_foundIndex = 0;
|
2018-02-12 01:31:11 +00:00
|
|
|
m_sheetPaths.clear();
|
2015-04-09 19:37:48 +00:00
|
|
|
SetForceSearch( false );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
|
|
|
if( aSheetPath )
|
|
|
|
{
|
2018-02-12 01:31:11 +00:00
|
|
|
m_currentSheetPath = aSheetPath;
|
|
|
|
m_sheetPaths.push_back( *m_currentSheetPath );
|
2016-07-12 19:05:54 +00:00
|
|
|
EDA_ITEM::IterateForward( aSheetPath->LastDrawList(), m_inspector, NULL, m_ScanTypes );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-06 21:22:01 +00:00
|
|
|
SCH_SHEET_LIST schematic( g_RootSheet );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2016-03-06 21:22:01 +00:00
|
|
|
for( unsigned i = 0; i < schematic.size(); i++ )
|
2011-12-01 16:49:28 +00:00
|
|
|
{
|
2018-02-12 01:31:11 +00:00
|
|
|
m_currentSheetPath = &schematic[i];
|
|
|
|
m_sheetPaths.push_back( *m_currentSheetPath );
|
|
|
|
EDA_ITEM::IterateForward( m_currentSheetPath->LastDrawList(), m_inspector, NULL, m_ScanTypes );
|
2011-12-01 16:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
dump();
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
if( m_List.size() != m_data.size() )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "List size mismatch." ) );
|
|
|
|
m_List.clear();
|
|
|
|
m_data.clear();
|
|
|
|
}
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT SCH_TYPE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* testData )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
|
|
|
// The Vist() function only visits the testItem if its type was in the
|
|
|
|
// the scanList, so therefore we can collect anything given to us here.
|
|
|
|
Append( aItem );
|
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_TYPE_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[] )
|
|
|
|
{
|
|
|
|
Empty(); // empty the collection
|
|
|
|
|
|
|
|
SetScanTypes( aFilterList );
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
EDA_ITEM::IterateForward( aItem, m_inspector, NULL, m_ScanTypes );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|