2019-04-15 14:34:58 +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
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-15 14:34:58 +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
|
|
|
|
*/
|
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <core/typeinfo.h>
|
2021-03-22 12:51:32 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2021-11-01 21:05:30 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <ee_actions.h>
|
|
|
|
#include <ee_collectors.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_selection_tool.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <eeschema_id.h> // For MAX_SELECT_ITEM_IDS
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <lib_item.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <math/util.h>
|
2021-09-19 10:05:58 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <menus_helpers.h>
|
|
|
|
#include <painter.h>
|
|
|
|
#include <preview_items/selection_area.h>
|
|
|
|
#include <sch_base_frame.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-02-01 16:39:26 +00:00
|
|
|
#include <sch_field.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_item.h>
|
2019-06-11 20:17:05 +00:00
|
|
|
#include <sch_line.h>
|
2021-09-23 21:13:32 +00:00
|
|
|
#include <sch_junction.h>
|
2021-12-30 16:51:04 +00:00
|
|
|
#include <sch_marker.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2021-11-27 14:18:01 +00:00
|
|
|
#include <lib_shape.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2020-10-01 23:53:47 +00:00
|
|
|
#include <tools/ee_grid_helper.h>
|
2021-09-29 17:50:22 +00:00
|
|
|
#include <tools/ee_point_editor.h>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
2021-11-13 16:38:19 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = []( const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2021-06-15 12:31:28 +00:00
|
|
|
return !symbol->GetLibSymbolRef() || !symbol->GetLibSymbolRef()->IsPower();
|
2019-05-02 10:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleSymbolOrPower = []( const SELECTION& aSel )
|
2021-02-17 00:14:23 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_SYMBOL_T;
|
2021-02-17 00:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleDeMorganSymbol = []( const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2021-06-15 12:31:28 +00:00
|
|
|
return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->HasConversion();
|
2019-05-02 10:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleMultiUnitSymbol = []( const SELECTION& aSel )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2021-06-15 12:31:28 +00:00
|
|
|
return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->GetUnitCount() >= 2;
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-12-30 16:51:04 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleNonExcludedMarker = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
if( aSel.CountType( SCH_MARKER_T ) != 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !static_cast<SCH_MARKER*>( aSel.Front() )->IsExcluded();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:28:16 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::EE_SELECTION_TOOL() :
|
2019-04-21 23:45:34 +00:00
|
|
|
TOOL_INTERACTIVE( "eeschema.InteractiveSelection" ),
|
2019-04-28 23:34:43 +00:00
|
|
|
m_frame( nullptr ),
|
2020-11-21 20:57:13 +00:00
|
|
|
m_nonModifiedCursor( KICURSOR::ARROW ),
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor( false ),
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer( false ),
|
2019-05-06 02:32:01 +00:00
|
|
|
m_unit( 0 ),
|
2019-06-05 19:15:57 +00:00
|
|
|
m_convert( 0 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-08-20 23:05:21 +00:00
|
|
|
m_selection.Clear();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::~EE_SELECTION_TOOL()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
using E_C = EE_CONDITIONS;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::Init()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-06 02:32:01 +00:00
|
|
|
m_frame = getEditFrame<SCH_BASE_FRAME>();
|
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
|
|
|
|
SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditorFrame )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor = true;
|
|
|
|
m_unit = symbolEditorFrame->GetUnit();
|
|
|
|
m_convert = symbolEditorFrame->GetConvert();
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
static KICAD_T wireOrBusTypes[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT };
|
2021-10-12 20:05:37 +00:00
|
|
|
static KICAD_T connectedTypes[] = { SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_NETCLASS_FLAG_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_PIN_T,
|
|
|
|
EOT };
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
auto wireSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_ITEM_LOCATE_WIRE_T );
|
|
|
|
auto busSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_ITEM_LOCATE_BUS_T );
|
2019-05-17 16:45:27 +00:00
|
|
|
auto wireOrBusSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( wireOrBusTypes );
|
2020-07-07 10:17:30 +00:00
|
|
|
auto connectedSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( connectedTypes );
|
2019-05-17 16:45:27 +00:00
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2020-12-11 20:02:20 +00:00
|
|
|
auto schEditSheetPageNumberCondition =
|
2021-02-19 14:51:18 +00:00
|
|
|
[&] ( const SELECTION& aSel )
|
2020-12-11 20:02:20 +00:00
|
|
|
{
|
2021-02-19 14:51:18 +00:00
|
|
|
if( m_isSymbolEditor || m_isSymbolViewer )
|
|
|
|
return false;
|
|
|
|
|
2021-02-19 19:04:44 +00:00
|
|
|
return E_C::LessThan( 2 )( aSel ) && E_C::OnlyType( SCH_SHEET_T )( aSel );
|
2020-12-11 20:02:20 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
auto schEditCondition =
|
|
|
|
[this] ( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
return !m_isSymbolEditor && !m_isSymbolViewer;
|
2020-07-07 10:17:30 +00:00
|
|
|
};
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
auto belowRootSheetCondition =
|
|
|
|
[&]( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
return editFrame
|
|
|
|
&& editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
auto haveSymbolCondition =
|
2020-05-13 02:00:37 +00:00
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
return m_isSymbolEditor &&
|
|
|
|
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
auto& menu = m_menu.GetMenu();
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddItem( EE_ACTIONS::explicitCrossProbe, sheetSelection && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 1 );
|
2019-05-03 22:48:24 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::drawWire, schEditCondition && EE_CONDITIONS::Empty, 100 );
|
|
|
|
menu.AddItem( EE_ACTIONS::drawBus, schEditCondition && EE_CONDITIONS::Empty, 100 );
|
2019-05-03 22:48:24 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::finishWire, SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire, 100 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::finishBus, SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus, 100 );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 200 );
|
2019-05-17 15:16:13 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2021-10-12 20:05:37 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeClassLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-05-17 15:16:13 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 250 );
|
2021-02-21 15:44:38 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::importSingleSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
|
2020-12-11 20:02:20 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2021-06-15 12:31:28 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::symbolProperties,
|
|
|
|
haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
|
|
|
|
menu.AddItem( EE_ACTIONS::pinTable,
|
|
|
|
haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
|
2019-05-01 13:24:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 1000 );
|
2019-06-11 14:38:21 +00:00
|
|
|
m_frame->AddStandardSubMenus( m_menu );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.SetOwner( this );
|
|
|
|
Connect( wxEVT_TIMER, wxTimerEventHandler( EE_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::Reset( RESET_REASON aReason )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-06 02:32:01 +00:00
|
|
|
m_frame = getEditFrame<SCH_BASE_FRAME>();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( aReason == TOOL_BASE::MODEL_RELOAD )
|
|
|
|
{
|
|
|
|
// Remove pointers to the selected items from containers without changing their
|
|
|
|
// properties (as they are already deleted while a new sheet is loaded)
|
|
|
|
m_selection.Clear();
|
|
|
|
getView()->GetPainter()->GetSettings()->SetHighlight( false );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbolEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
|
|
|
SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
if( symbolEditFrame )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor = true;
|
2020-12-25 23:37:01 +00:00
|
|
|
m_unit = symbolEditFrame->GetUnit();
|
|
|
|
m_convert = symbolEditFrame->GetConvert();
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// Restore previous properties of selected items and remove them from containers
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
getView()->Add( &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int EE_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-14 11:14:00 +00:00
|
|
|
ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
|
2019-05-13 20:42:40 +00:00
|
|
|
CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
|
|
|
|
|
|
|
|
if( conditionalMenu )
|
|
|
|
conditionalMenu->Evaluate( m_selection );
|
|
|
|
|
|
|
|
if( actionMenu )
|
|
|
|
actionMenu->UpdateAll();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-23 22:57:34 +00:00
|
|
|
const KICAD_T movableSymbolItems[] =
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
LIB_SHAPE_T,
|
2020-04-23 22:57:34 +00:00
|
|
|
LIB_TEXT_T,
|
|
|
|
LIB_PIN_T,
|
|
|
|
LIB_FIELD_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-01 20:03:14 +00:00
|
|
|
const KICAD_T movableSymbolAliasItems[] =
|
|
|
|
{
|
|
|
|
LIB_FIELD_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-20 18:51:24 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
KIID lastRolloverItem = niluuid;
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
bool displayWireCursor = false;
|
2021-02-15 14:57:06 +00:00
|
|
|
bool displayBusCursor = false;
|
2021-02-17 19:43:07 +00:00
|
|
|
bool displayLineCursor = false;
|
2020-11-29 16:31:43 +00:00
|
|
|
KIID rolloverItem = lastRolloverItem;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
// on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
|
|
|
|
evt->Modifier( MD_ALT ) );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
|
|
|
|
|
|
|
|
MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
if( evt->IsMouseDown( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
// Avoid triggering when running under other tools
|
2021-10-01 00:25:33 +00:00
|
|
|
EE_POINT_EDITOR *pt_tool = m_toolMgr->GetTool<EE_POINT_EDITOR>();
|
|
|
|
|
|
|
|
if( m_frame->ToolStackIsEmpty() && pt_tool && !pt_tool->HasPoint() )
|
2021-09-09 23:23:00 +00:00
|
|
|
{
|
|
|
|
m_originalCursor = m_toolMgr->GetMousePosition();
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.StartOnce( 500 );
|
2021-09-09 23:23:00 +00:00
|
|
|
}
|
2021-09-05 20:37:52 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
// Single click? Select single object
|
2021-09-05 20:37:52 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
// If the timer has stopped, then we have already run the disambiguate routine
|
|
|
|
// and we don't want to register an extra click here
|
|
|
|
if( !m_disambiguateTimer.IsRunning() )
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
EE_COLLECTOR collector;
|
2020-10-02 20:18:07 +00:00
|
|
|
bool continueSelect = true;
|
2020-10-01 23:53:47 +00:00
|
|
|
|
|
|
|
// Collect items at the clicked location (doesn't select them yet)
|
2021-12-02 16:54:13 +00:00
|
|
|
if( CollectHits( collector, evt->Position() ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2021-09-23 21:39:29 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false, false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( collector.GetCount() == 1 && !m_isSymbolEditor && !modifier_enabled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
// Check if we want to auto start wires
|
2020-12-03 15:10:23 +00:00
|
|
|
VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
|
|
|
|
LAYER_CONNECTABLE, nullptr );
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2021-10-01 00:25:33 +00:00
|
|
|
EE_POINT_EDITOR *pt_tool = m_toolMgr->GetTool<EE_POINT_EDITOR>();
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
2021-10-01 00:25:33 +00:00
|
|
|
&& pt_tool && !pt_tool->HasPoint()
|
2020-10-03 19:05:28 +00:00
|
|
|
&& collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2021-02-15 14:57:06 +00:00
|
|
|
OPT_TOOL_EVENT newEvt;
|
|
|
|
SCH_CONNECTION* connection = collector[0]->Connection();
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
|
2021-06-10 14:10:55 +00:00
|
|
|
|| collector[0]->Type() == SCH_SYMBOL_T )
|
2021-02-17 19:43:07 +00:00
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawWire.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( connection && connection->IsBus() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( collector[0]->Type() == SCH_LINE_T
|
|
|
|
&& static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
2021-02-17 19:43:07 +00:00
|
|
|
newEvt = EE_ACTIONS::drawLines.MakeEvent();
|
2021-02-15 14:57:06 +00:00
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2021-02-15 14:57:06 +00:00
|
|
|
auto* params = newEvt->Parameter<DRAW_SEGMENT_EVENT_PARAMS*>();
|
|
|
|
auto* newParams = new DRAW_SEGMENT_EVENT_PARAMS();
|
2020-10-02 20:18:07 +00:00
|
|
|
|
|
|
|
*newParams= *params;
|
|
|
|
newParams->quitOnDraw = true;
|
|
|
|
newEvt->SetParameter( newParams );
|
|
|
|
|
2021-01-29 22:07:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( true, snappedCursorPos );
|
2020-10-08 03:57:26 +00:00
|
|
|
newEvt->SetMousePosition( snappedCursorPos );
|
2021-01-29 22:07:49 +00:00
|
|
|
newEvt->SetHasPosition( true );
|
2021-02-21 12:45:50 +00:00
|
|
|
newEvt->SetForceImmediate( true );
|
2020-10-02 20:18:07 +00:00
|
|
|
m_toolMgr->ProcessEvent( *newEvt );
|
2021-01-29 22:07:49 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
continueSelect = false;
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( collector[0]->IsHypertext() )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
collector[0]->DoHypertextMenu( m_frame );
|
2020-10-05 10:54:37 +00:00
|
|
|
continueSelect = false;
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( continueSelect )
|
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
// If we didn't click on an anchor, we perform a normal select, pass in the
|
|
|
|
// items we previously collected
|
2020-10-05 10:54:37 +00:00
|
|
|
selectPoint( collector, nullptr, nullptr, m_additive, m_subtractive,
|
2020-10-02 20:18:07 +00:00
|
|
|
m_exclusive_or );
|
2021-12-02 16:54:13 +00:00
|
|
|
|
|
|
|
m_selection.SetIsHover( false );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// right click? if there is any object - show the context menu
|
2019-04-21 23:45:34 +00:00
|
|
|
bool selectionCancelled = false;
|
|
|
|
|
2021-01-31 14:59:18 +00:00
|
|
|
if( m_selection.Empty() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-10-29 15:11:06 +00:00
|
|
|
ClearSelection();
|
2020-05-24 23:35:04 +00:00
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
|
|
|
|
&selectionCancelled );
|
2019-04-21 23:45:34 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
2021-01-31 14:59:18 +00:00
|
|
|
// If the cursor has moved off the bounding box of the selection by more than
|
|
|
|
// a grid square, check to see if there is another item available for selection
|
|
|
|
// under the cursor. If there is, the user likely meant to get the context menu
|
|
|
|
// for that item. If there is no new item, then keep the original selection and
|
|
|
|
// show the context menu for it.
|
|
|
|
else if( !m_selection.GetBoundingBox().Inflate(
|
|
|
|
grid.GetGrid().x, grid.GetGrid().y ).Contains(
|
|
|
|
(wxPoint) evt->Position() ) )
|
|
|
|
{
|
|
|
|
EE_SELECTION saved_selection = m_selection;
|
|
|
|
|
2021-04-05 17:51:48 +00:00
|
|
|
for( const auto& item : saved_selection )
|
2021-01-31 14:59:18 +00:00
|
|
|
RemoveItemFromSel( item, true );
|
|
|
|
|
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
|
|
|
|
&selectionCancelled );
|
|
|
|
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
2021-03-22 02:01:45 +00:00
|
|
|
for( const auto& item : saved_selection )
|
2021-01-31 14:59:18 +00:00
|
|
|
AddItemToSel( item, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( !selectionCancelled )
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-06 19:26:20 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// double click? Display the properties window
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( m_selection.Empty() )
|
2020-11-23 19:46:17 +00:00
|
|
|
SelectPoint( evt->Position() );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 20:14:03 +00:00
|
|
|
EDA_ITEM* item = m_selection.Front();
|
|
|
|
|
|
|
|
if( item && item->Type() == SCH_SHEET_T )
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::enterSheet );
|
2019-05-03 20:14:03 +00:00
|
|
|
else
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::properties );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-09-17 00:19:31 +00:00
|
|
|
else if( evt->IsDblClick( BUT_MIDDLE ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// Middle double click? Do zoom to fit or zoom to objects
|
2021-03-05 06:43:03 +00:00
|
|
|
if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
|
2020-09-17 00:19:31 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitObjects, true );
|
|
|
|
else
|
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitScreen, true );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
else if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2021-03-05 00:01:17 +00:00
|
|
|
// Is another tool already moving a new object? Don't allow a drag start
|
2021-05-30 21:04:07 +00:00
|
|
|
if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
|
2021-03-05 00:01:17 +00:00
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// drag with LMB? Select multiple objects (or at least draw a selection box) or
|
|
|
|
// drag them
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
if( modifier_enabled || drag_action == MOUSE_DRAG_ACTION::SELECT )
|
2021-01-11 11:48:51 +00:00
|
|
|
{
|
|
|
|
selectMultiple();
|
|
|
|
}
|
2021-01-11 15:46:41 +00:00
|
|
|
else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-23 17:40:29 +00:00
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-01 20:03:14 +00:00
|
|
|
if( m_isSymbolEditor )
|
|
|
|
{
|
|
|
|
if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
|
|
|
|
m_selection = RequestSelection( movableSymbolAliasItems );
|
|
|
|
else
|
|
|
|
m_selection = RequestSelection( movableSymbolItems );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
m_selection = RequestSelection( EE_COLLECTOR::MovableItems );
|
2021-07-01 20:03:14 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Check if dragging has started within any of selected items bounding box
|
|
|
|
if( selectionContains( evt->Position() ) )
|
|
|
|
{
|
|
|
|
// Yes -> run the move tool and wait till it finishes
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2021-07-01 20:03:14 +00:00
|
|
|
m_toolMgr->InvokeTool( "eeschema.SymbolMoveTool" );
|
2020-04-23 22:57:34 +00:00
|
|
|
else
|
|
|
|
m_toolMgr->InvokeTool( "eeschema.InteractiveMove" );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
// No -> drag a selection box
|
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// context sub-menu selection? Handle unit selection or bus unfolding
|
2019-05-02 20:03:03 +00:00
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
2021-06-10 14:10:55 +00:00
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
|
2019-05-02 20:44:23 +00:00
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( symbol )
|
|
|
|
static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( symbol, unit );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
2019-05-05 14:16:29 +00:00
|
|
|
else if( evt->GetCommandId().get() >= ID_POPUP_SCH_UNFOLD_BUS
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
|
|
|
{
|
|
|
|
wxString* net = new wxString( *evt->Parameter<wxString*>() );
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::unfoldBus, true, net );
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-05-06 20:55:35 +00:00
|
|
|
}
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
else if( evt->IsMotion() && !m_isSymbolEditor && m_frame->ToolStackIsEmpty() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-11-29 16:31:43 +00:00
|
|
|
rolloverItem = niluuid;
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
|
|
|
// We are checking if we should display a pencil when hovering over anchors
|
|
|
|
// for "auto starting" wires when clicked
|
2021-10-06 03:26:59 +00:00
|
|
|
getViewControls()->ForceCursorPosition( false );
|
|
|
|
|
2021-09-18 17:18:41 +00:00
|
|
|
if( CollectHits( collector, evt->Position() ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2021-09-23 21:39:29 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false, false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
if( collector.GetCount() == 1 && !modifier_enabled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-12-03 15:10:23 +00:00
|
|
|
VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
|
|
|
|
LAYER_CONNECTABLE, nullptr );
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2021-10-01 00:25:33 +00:00
|
|
|
EE_POINT_EDITOR *pt_tool = m_toolMgr->GetTool<EE_POINT_EDITOR>();
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
2021-10-01 00:25:33 +00:00
|
|
|
&& pt_tool && !pt_tool->HasPoint()
|
2021-11-25 00:55:03 +00:00
|
|
|
&& !collector[0]->IsConnectivityDirty()
|
2020-10-03 19:05:28 +00:00
|
|
|
&& collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2021-02-15 14:57:06 +00:00
|
|
|
SCH_CONNECTION* connection = collector[0]->Connection();
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
|
2021-06-10 14:10:55 +00:00
|
|
|
|| collector[0]->Type() == SCH_SYMBOL_T )
|
2021-02-17 19:43:07 +00:00
|
|
|
{
|
|
|
|
displayWireCursor = true;
|
|
|
|
}
|
|
|
|
else if( connection && connection->IsBus() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
|
|
|
displayBusCursor = true;
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( collector[0]->Type() == SCH_LINE_T
|
|
|
|
&& static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
2021-02-17 19:43:07 +00:00
|
|
|
displayLineCursor = true;
|
2021-02-15 14:57:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:07:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( true, snappedCursorPos );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( collector[0]->IsHypertext()
|
2020-11-18 12:02:52 +00:00
|
|
|
&& !collector[0]->IsSelected()
|
|
|
|
&& !m_additive && !m_subtractive && !m_exclusive_or )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
rolloverItem = collector[0]->m_Uuid;
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 14:39:14 +00:00
|
|
|
else
|
2020-11-23 19:46:17 +00:00
|
|
|
{
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-23 19:46:17 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( rolloverItem != lastRolloverItem )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_frame->GetItem( lastRolloverItem );
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
item->ClearFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = niluuid;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item = m_frame->GetItem( rolloverItem );
|
|
|
|
|
2020-10-12 09:32:51 +00:00
|
|
|
if( item )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
item->SetFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = rolloverItem;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
if( displayWireCursor )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_WIRE_ADD;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-02-15 14:57:06 +00:00
|
|
|
else if( displayBusCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_BUS;
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( displayLineCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_GRAPHIC;
|
|
|
|
}
|
2020-10-02 20:18:07 +00:00
|
|
|
else if( rolloverItem != niluuid )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::HAND;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-01-11 11:48:51 +00:00
|
|
|
else if( !m_selection.Empty()
|
2021-01-11 15:46:41 +00:00
|
|
|
&& drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
|
2021-01-11 11:48:51 +00:00
|
|
|
&& evt->HasPosition()
|
|
|
|
&& selectionContains( evt->Position() ) ) //move/drag option prediction
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::MOVING;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
else
|
2020-10-08 00:50:28 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::ARROW;
|
2020-10-08 00:50:28 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-10-30 13:57:59 +00:00
|
|
|
// Shutting down; clear the selection
|
|
|
|
m_selection.Clear();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
int EE_SELECTION_TOOL::disambiguateCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_skip_heuristics = true;
|
2021-09-24 19:44:26 +00:00
|
|
|
SelectPoint( m_originalCursor, EE_COLLECTOR::AllItems, nullptr, &m_canceledMenu, false,
|
|
|
|
m_additive, m_subtractive, m_exclusive_or );
|
2021-09-05 20:37:52 +00:00
|
|
|
m_skip_heuristics = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_SELECTION_TOOL::onDisambiguationExpire( wxTimerEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::DisambiguatePoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 15:23:05 +00:00
|
|
|
void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
2020-12-30 00:51:34 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() && !m_multiple )
|
2020-11-18 15:23:05 +00:00
|
|
|
{
|
|
|
|
wxMouseState keyboardState = wxGetMouseState();
|
|
|
|
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
|
|
|
|
keyboardState.AltDown() );
|
2020-11-18 15:23:05 +00:00
|
|
|
|
|
|
|
if( m_additive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD );
|
|
|
|
else if( m_subtractive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT );
|
|
|
|
else if( m_exclusive_or )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( m_nonModifiedCursor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::GetSelection()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
return m_selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
2020-10-02 20:18:07 +00:00
|
|
|
const KICAD_T* aFilterList )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-19 10:05:58 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2021-11-28 18:59:55 +00:00
|
|
|
int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 );
|
2021-09-19 10:05:58 +00:00
|
|
|
aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-05-09 03:11:36 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
aCollector.Collect( symbol->GetDrawItems(), aFilterList, (wxPoint) aWhere, m_unit,
|
2020-10-02 20:18:07 +00:00
|
|
|
m_convert );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
aCollector.Collect( m_frame->GetScreen(), aFilterList, (wxPoint) aWhere, m_unit,
|
|
|
|
m_convert );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
return aCollector.GetCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere,
|
2021-09-23 21:39:29 +00:00
|
|
|
bool aCheckLocked, bool aSelectPoints )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-19 10:05:58 +00:00
|
|
|
if( !Selectable( collector[i], &aWhere ) )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( aCheckLocked && collector[i]->IsLocked() )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-11 20:17:05 +00:00
|
|
|
|
|
|
|
// SelectPoint, unlike other selection routines, can select line ends
|
2021-09-23 21:39:29 +00:00
|
|
|
if( aSelectPoints && collector[i]->Type() == SCH_LINE_T )
|
2019-06-11 20:17:05 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) collector[i];
|
2019-06-11 20:17:05 +00:00
|
|
|
line->ClearFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
2019-06-11 20:17:05 +00:00
|
|
|
line->SetFlags( STARTPOINT );
|
2020-10-02 20:18:07 +00:00
|
|
|
else if( HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
2019-06-11 20:17:05 +00:00
|
|
|
line->SetFlags( ENDPOINT );
|
|
|
|
else
|
|
|
|
line->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
|
2020-10-02 20:18:07 +00:00
|
|
|
if( collector.GetCount() > 1 && !m_skip_heuristics )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
GuessSelectionCandidates( collector, aWhere );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem,
|
2020-10-02 20:18:07 +00:00
|
|
|
bool* aSelectionCancelledFlag, bool aAdd, bool aSubtract,
|
|
|
|
bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// If still more than one item we're going to have to ask the user.
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 1 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-13 17:14:59 +00:00
|
|
|
// Try to call selectionMenu via RunAction() to avoid event-loop contention
|
|
|
|
// But it we cannot handle the event, then we don't have an active tool loop, so
|
|
|
|
// handle it directly.
|
|
|
|
if( !m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &aCollector ) )
|
2021-09-23 18:46:07 +00:00
|
|
|
{
|
|
|
|
if( !doSelectionMenu( &aCollector ) )
|
|
|
|
aCollector.m_MenuCancelled = true;
|
|
|
|
}
|
2021-09-13 17:14:59 +00:00
|
|
|
|
|
|
|
if( aCollector.m_MenuCancelled )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aSelectionCancelledFlag )
|
|
|
|
*aSelectionCancelledFlag = true;
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( !aAdd && !aSubtract && !aExclusiveOr )
|
|
|
|
ClearSelection();
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 0 )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
for( int i = 0; i < aCollector.GetCount(); ++i )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aSubtract || ( aExclusiveOr && aCollector[i]->IsSelected() ) )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
unselect( aCollector[i] );
|
2020-05-27 15:18:12 +00:00
|
|
|
anySubtracted = true;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
select( aCollector[i] );
|
2020-05-27 15:18:12 +00:00
|
|
|
anyAdded = true;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
if( anyAdded )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aItem && aCollector.GetCount() == 1 )
|
|
|
|
*aItem = aCollector[0];
|
2020-05-24 23:35:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( anySubtracted )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
|
2020-10-05 10:54:37 +00:00
|
|
|
EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
|
|
|
|
bool aCheckLocked, bool aAdd, bool aSubtract,
|
|
|
|
bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
if( !CollectHits( collector, aWhere, aFilterList ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
return false;
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2021-09-23 21:39:29 +00:00
|
|
|
narrowSelection( collector, aWhere, aCheckLocked, true );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
return selectPoint( collector, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
// hold all visible items
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
|
|
|
|
|
|
|
|
// Filter the view items based on the selection box
|
|
|
|
BOX2I selectionBox;
|
|
|
|
|
|
|
|
selectionBox.SetMaximum();
|
|
|
|
view->Query( selectionBox, selectedItems ); // Get the list of selected items
|
|
|
|
|
|
|
|
// Sheet pins aren't in the view; add them by hand
|
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
int layer = pair.second;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
|
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
|
2020-08-20 23:05:21 +00:00
|
|
|
{
|
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
|
|
|
|
{
|
|
|
|
if( Selectable( item ) )
|
|
|
|
select( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_multiple = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 19:11:26 +00:00
|
|
|
void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-06-28 19:11:26 +00:00
|
|
|
// Prefer exact hits to sloppy ones
|
2021-09-19 10:05:58 +00:00
|
|
|
std::set<EDA_ITEM*> exactHits;
|
2019-06-26 18:43:37 +00:00
|
|
|
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-05-16 23:48:39 +00:00
|
|
|
{
|
2021-11-27 14:18:01 +00:00
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
|
|
|
LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( item );
|
2019-05-16 23:48:39 +00:00
|
|
|
|
2021-09-21 17:15:41 +00:00
|
|
|
// Lines are hard to hit. Give them a bit more slop to still be considered "exact".
|
|
|
|
|
2021-11-27 14:18:01 +00:00
|
|
|
if( line || ( shape && shape->GetShape() == SHAPE_T::POLY ) )
|
2021-09-21 17:15:41 +00:00
|
|
|
{
|
2021-11-27 14:18:01 +00:00
|
|
|
if( item->HitTest( (wxPoint) aPos, Mils2iu( DANGLING_SYMBOL_SIZE ) ) )
|
|
|
|
exactHits.insert( item );
|
2021-09-21 17:15:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( item->HitTest( (wxPoint) aPos, 0 ) )
|
|
|
|
exactHits.insert( item );
|
|
|
|
}
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
|
2019-06-26 18:43:37 +00:00
|
|
|
{
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
|
2021-09-21 17:15:41 +00:00
|
|
|
if( !exactHits.count( item ) )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( item );
|
2019-06-26 18:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
// Find the closest item. (Note that at this point all hits are either exact or non-exact.)
|
2021-11-01 21:05:30 +00:00
|
|
|
wxPoint pos( aPos );
|
2021-11-27 14:18:01 +00:00
|
|
|
SEG poss( m_isSymbolEditor ? mapCoords( pos ) : pos,
|
|
|
|
m_isSymbolEditor ? mapCoords( pos ) : pos );
|
2020-09-19 14:55:05 +00:00
|
|
|
EDA_ITEM* closest = nullptr;
|
2021-11-01 21:05:30 +00:00
|
|
|
int closestDist = INT_MAX / 2;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : collector )
|
|
|
|
{
|
2021-09-19 10:05:58 +00:00
|
|
|
EDA_RECT bbox = item->GetBoundingBox();
|
2021-11-01 21:05:30 +00:00
|
|
|
int dist = INT_MAX / 2;
|
2021-09-19 10:05:58 +00:00
|
|
|
|
|
|
|
if( exactHits.count( item ) )
|
|
|
|
{
|
2021-09-23 22:58:46 +00:00
|
|
|
if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
closest = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
2021-09-21 17:15:41 +00:00
|
|
|
|
2021-09-23 22:58:46 +00:00
|
|
|
if( line )
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2021-09-21 17:15:41 +00:00
|
|
|
dist = DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos );
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
else if( text )
|
|
|
|
{
|
|
|
|
text->GetEffectiveTextShape()->Collide( poss, closestDist, &dist );
|
|
|
|
}
|
|
|
|
else if( symbol )
|
|
|
|
{
|
2021-11-13 16:38:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
bbox = symbol->GetBodyBoundingBox();
|
|
|
|
}
|
|
|
|
catch( const boost::bad_pointer& exc )
|
|
|
|
{
|
|
|
|
// This may be overkill and could be an assertion but we are more likely to
|
|
|
|
// find any boost pointer container errors this way.
|
|
|
|
wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
|
|
|
|
|
|
|
if( bbox.Contains( pos ) )
|
|
|
|
dist = EuclideanNorm( bbox.GetCenter() - pos );
|
|
|
|
else
|
|
|
|
rect.Collide( poss, closestDist, &dist );
|
|
|
|
}
|
2021-09-21 17:15:41 +00:00
|
|
|
else
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
|
|
|
dist = EuclideanNorm( bbox.GetCenter() - pos );
|
|
|
|
}
|
2021-09-19 10:05:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
2021-11-01 21:05:30 +00:00
|
|
|
rect.Collide( poss, collector.m_Threshold, &dist );
|
2021-09-19 10:05:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 14:55:05 +00:00
|
|
|
if( dist < closestDist )
|
|
|
|
{
|
|
|
|
closestDist = dist;
|
|
|
|
closest = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
// Construct a tight box (1/2 height and width) around the center of the closest item.
|
|
|
|
// All items which exist at least partly outside this box have sufficient other areas
|
|
|
|
// for selection and can be dropped.
|
2020-09-30 02:28:23 +00:00
|
|
|
if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
|
2020-09-19 14:55:05 +00:00
|
|
|
{
|
2020-09-30 02:28:23 +00:00
|
|
|
EDA_RECT tightBox = closest->GetBoundingBox();
|
|
|
|
tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[i];
|
|
|
|
|
|
|
|
if( item == closest )
|
|
|
|
continue;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
if( !item->HitTest( tightBox, true ) )
|
|
|
|
collector.Transfer( item );
|
|
|
|
}
|
2020-09-19 14:55:05 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] )
|
2019-04-23 12:51:48 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
|
|
|
|
|
|
|
|
ClearSelection();
|
|
|
|
SelectPoint( cursorPos, aFilterList );
|
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
}
|
|
|
|
else // Trim an existing selection by aFilterList
|
2019-04-23 17:12:10 +00:00
|
|
|
{
|
2021-10-18 12:24:06 +00:00
|
|
|
bool isMoving = false;
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
|
2021-11-06 16:03:41 +00:00
|
|
|
isMoving |= static_cast<SCH_ITEM*>( item )->IsMoving();
|
2019-04-23 17:12:10 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
if( !item->IsType( aFilterList ) )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
|
|
|
unselect( item );
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
}
|
2019-04-23 17:12:10 +00:00
|
|
|
}
|
2019-05-20 15:42:49 +00:00
|
|
|
|
2021-10-18 12:24:06 +00:00
|
|
|
if( !isMoving )
|
|
|
|
updateReferencePoint();
|
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
|
|
|
|
return m_selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_SELECTION_TOOL::updateReferencePoint()
|
|
|
|
{
|
2019-05-22 21:09:20 +00:00
|
|
|
VECTOR2I refP( 0, 0 );
|
2019-05-22 02:42:33 +00:00
|
|
|
|
2019-05-22 21:09:20 +00:00
|
|
|
if( m_selection.Size() > 0 )
|
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-05-22 21:09:20 +00:00
|
|
|
refP = static_cast<LIB_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
|
2019-05-22 02:42:33 +00:00
|
|
|
else
|
2019-05-22 21:09:20 +00:00
|
|
|
refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
|
2019-05-07 09:38:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 21:09:20 +00:00
|
|
|
m_selection.SetReferencePoint( refP );
|
2019-04-23 12:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-07 23:00:39 +00:00
|
|
|
// Some navigation actions are allowed in selectMultiple
|
|
|
|
const TOOL_ACTION* allowedActions[] = { &ACTIONS::panUp, &ACTIONS::panDown,
|
|
|
|
&ACTIONS::panLeft, &ACTIONS::panRight,
|
|
|
|
&ACTIONS::cursorUp, &ACTIONS::cursorDown,
|
|
|
|
&ACTIONS::cursorLeft, &ACTIONS::cursorRight,
|
|
|
|
&ACTIONS::cursorUpFast, &ACTIONS::cursorDownFast,
|
|
|
|
&ACTIONS::cursorLeftFast, &ACTIONS::cursorRightFast,
|
|
|
|
&ACTIONS::zoomIn, &ACTIONS::zoomOut,
|
|
|
|
&ACTIONS::zoomInCenter, &ACTIONS::zoomOutCenter,
|
|
|
|
&ACTIONS::zoomCenter, &ACTIONS::zoomFitScreen,
|
|
|
|
&ACTIONS::zoomFitObjects, nullptr };
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectMultiple()
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
bool cancelled = false; // Was the tool canceled while it was running?
|
2019-04-23 17:40:29 +00:00
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
KIGFX::PREVIEW::SELECTION_AREA area;
|
|
|
|
view->Add( &area );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-09 01:24:26 +00:00
|
|
|
int width = area.GetEnd().x - area.GetOrigin().x;
|
2021-12-10 18:43:35 +00:00
|
|
|
int height = area.GetEnd().y - area.GetOrigin().y;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
|
|
|
/* Selection mode depends on direction of drag-selection:
|
|
|
|
* Left > Right : Select objects that are fully enclosed by selection
|
|
|
|
* Right > Left : Select objects that are crossed by selection
|
|
|
|
*/
|
2021-12-10 18:43:35 +00:00
|
|
|
bool isWindowSelection = width >= 0;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
|
|
|
if( view->IsMirroredX() )
|
2021-12-10 18:43:35 +00:00
|
|
|
isWindowSelection = !isWindowSelection;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( isWindowSelection ? KICURSOR::SELECT_WINDOW
|
|
|
|
: KICURSOR::SELECT_LASSO );
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
if( !m_drag_additive && !m_drag_subtractive )
|
2019-07-09 19:50:40 +00:00
|
|
|
ClearSelection();
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Start drawing a selection box
|
|
|
|
area.SetOrigin( evt->DragOrigin() );
|
|
|
|
area.SetEnd( evt->Position() );
|
2021-09-05 20:37:52 +00:00
|
|
|
area.SetAdditive( m_drag_additive );
|
|
|
|
area.SetSubtractive( m_drag_subtractive );
|
|
|
|
area.SetExclusiveOr( false );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
view->SetVisible( &area, true );
|
|
|
|
view->Update( &area );
|
|
|
|
getViewControls()->SetAutoPan( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsMouseUp( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
// End drawing the selection box
|
|
|
|
view->SetVisible( &area, false );
|
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
// Fetch items from the RTree that are in our area of interest
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> nearbyViewItems;
|
|
|
|
view->Query( area.ViewBBox(), nearbyViewItems );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
// Build lists of nearby items and their children
|
2021-12-12 17:38:16 +00:00
|
|
|
std::vector<EDA_ITEM*> nearbyItems;
|
|
|
|
std::vector<EDA_ITEM*> nearbyChildren;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2021-12-12 17:38:16 +00:00
|
|
|
EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first );
|
2019-08-29 14:59:36 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
if( item )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2021-12-10 18:43:35 +00:00
|
|
|
item->ClearFlags( TEMP_SELECTED | STARTPOINT | ENDPOINT );
|
|
|
|
nearbyItems.push_back( item );
|
2021-12-12 17:38:16 +00:00
|
|
|
}
|
2021-12-10 18:43:35 +00:00
|
|
|
|
2021-12-12 17:38:16 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2021-12-10 18:43:35 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
nearbyChildren.push_back( aChild );
|
|
|
|
} );
|
2021-03-07 14:32:49 +00:00
|
|
|
}
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
|
|
|
|
selectionRect.Normalize();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2021-12-10 18:43:35 +00:00
|
|
|
auto selectItem =
|
2021-12-12 17:38:16 +00:00
|
|
|
[&]( EDA_ITEM* aItem )
|
2021-12-10 18:43:35 +00:00
|
|
|
{
|
|
|
|
if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
|
|
|
|
{
|
|
|
|
unselect( aItem );
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
select( aItem );
|
|
|
|
aItem->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
anyAdded = true;
|
|
|
|
}
|
|
|
|
};
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-12 17:38:16 +00:00
|
|
|
for( EDA_ITEM* item : nearbyItems )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2021-12-10 18:43:35 +00:00
|
|
|
if( Selectable( item ) && item->HitTest( selectionRect, isWindowSelection ) )
|
|
|
|
{
|
|
|
|
item->SetFlags( TEMP_SELECTED );
|
|
|
|
selectItem( item );
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-12 17:38:16 +00:00
|
|
|
for( EDA_ITEM* item : nearbyChildren )
|
2021-12-10 18:43:35 +00:00
|
|
|
{
|
|
|
|
if( Selectable( item )
|
|
|
|
&& !item->GetParent()->HasFlag( TEMP_SELECTED )
|
|
|
|
&& item->HitTest( selectionRect, isWindowSelection ) )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2021-12-10 18:43:35 +00:00
|
|
|
selectItem( item );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Inform other potentially interested tools
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anyAdded )
|
2019-04-23 17:40:29 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anySubtracted )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
break; // Stop waiting for events
|
|
|
|
}
|
2021-12-07 23:00:39 +00:00
|
|
|
|
|
|
|
// Allow some actions for navigation
|
|
|
|
for( int i = 0; allowedActions[i]; ++i )
|
|
|
|
{
|
|
|
|
if( evt->IsAction( allowedActions[i] ) )
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
// Stop drawing the selection box
|
|
|
|
view->Remove( &area );
|
|
|
|
m_multiple = false; // Multiple selection mode is inactive
|
|
|
|
|
|
|
|
if( !cancelled )
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
static KICAD_T nodeTypes[] =
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
SCH_SYMBOL_LOCATE_POWER_T,
|
|
|
|
SCH_PIN_T,
|
|
|
|
SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_NETCLASS_FLAG_T,
|
2021-07-17 19:56:18 +00:00
|
|
|
SCH_JUNCTION_T,
|
|
|
|
EOT
|
2019-04-30 13:54:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2019-05-10 19:22:26 +00:00
|
|
|
EE_COLLECTOR collector;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
//TODO(snh): Reimplement after exposing KNN interface
|
2021-09-19 10:05:58 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
|
|
|
|
int thresholdMax = std::max( pixelThreshold, gridThreshold );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
|
2019-05-15 17:00:49 +00:00
|
|
|
{
|
|
|
|
collector.m_Threshold = threshold;
|
2019-06-25 23:39:58 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), nodeTypes, (wxPoint) aPosition );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
|
|
|
if( collector.GetCount() > 0 )
|
|
|
|
break;
|
|
|
|
}
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
return collector.GetCount() ? collector[ 0 ] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2021-05-09 17:14:41 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
SelectPoint( cursorPos, nodeTypes );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
static KICAD_T wiresAndBuses[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT };
|
2019-04-30 17:02:38 +00:00
|
|
|
|
2020-04-02 17:03:53 +00:00
|
|
|
RequestSelection( wiresAndBuses );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2019-05-01 21:50:11 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) m_selection.Front();
|
2019-04-30 13:54:32 +00:00
|
|
|
EDA_ITEMS items;
|
|
|
|
|
|
|
|
m_frame->GetScreen()->ClearDrawingState();
|
2020-12-14 21:11:33 +00:00
|
|
|
std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( SCH_ITEM* item : conns )
|
2019-06-25 23:39:58 +00:00
|
|
|
select( item );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
if( m_selection.GetSize() > 1 )
|
2019-04-30 13:54:32 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::AddItemToSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-01 20:15:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
|
2019-05-01 20:15:51 +00:00
|
|
|
{
|
|
|
|
if( aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
select( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
2019-05-01 20:15:51 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::AddItemsToSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-03 22:46:44 +00:00
|
|
|
AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-03 22:46:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 22:46:44 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
if( aList )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-03 22:46:44 +00:00
|
|
|
for( EDA_ITEM* item : *aList )
|
|
|
|
select( item );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 22:46:44 +00:00
|
|
|
// Inform other potentially interested tools
|
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::RemoveItemFromSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-01 20:15:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
|
2019-05-01 20:15:51 +00:00
|
|
|
{
|
|
|
|
if( aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
unselect( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
2019-05-01 20:15:51 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::RemoveItemsFromSel( const TOOL_EVENT& aEvent )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-03 22:46:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
if( aList )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : *aList )
|
|
|
|
unselect( item );
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 12:51:32 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode )
|
|
|
|
{
|
|
|
|
EDA_ITEMS removeItems;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
|
|
|
if( alg::contains( *aList, item->m_Uuid ) )
|
|
|
|
removeItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveItemsFromSel( &removeItems, aQuietMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-18 13:11:34 +00:00
|
|
|
void EE_SELECTION_TOOL::BrightenItem( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
highlight( aItem, BRIGHTENED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void EE_SELECTION_TOOL::UnbrightenItem( EDA_ITEM* aItem )
|
2019-05-18 13:11:34 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
unhighlight( aItem, BRIGHTENED );
|
2019-05-18 13:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
void EE_SELECTION_TOOL::RebuildSelection()
|
|
|
|
{
|
|
|
|
m_selection.Clear();
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2019-05-11 10:06:28 +00:00
|
|
|
|
2020-03-06 12:05:21 +00:00
|
|
|
for( LIB_ITEM& item : start->GetDrawItems() )
|
2020-01-04 23:05:57 +00:00
|
|
|
{
|
|
|
|
if( item.IsSelected() )
|
|
|
|
select( static_cast<EDA_ITEM*>( &item ) );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-11 10:06:28 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
|
2019-10-27 17:47:26 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// If the field and symbol are selected, only use the symbol
|
2020-02-05 04:48:33 +00:00
|
|
|
if( item->IsSelected() )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
select( item );
|
|
|
|
}
|
2020-02-05 04:48:33 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->IsSelected() )
|
|
|
|
select( aChild );
|
|
|
|
} );
|
2020-02-05 04:48:33 +00:00
|
|
|
}
|
2019-10-27 17:47:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
|
|
|
|
updateReferencePoint();
|
2019-06-29 18:57:23 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-05-11 10:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-10 19:22:26 +00:00
|
|
|
EE_COLLECTOR* collector = aEvent.Parameter<EE_COLLECTOR*>();
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2019-04-25 20:25:44 +00:00
|
|
|
if( !doSelectionMenu( collector ) )
|
|
|
|
collector->m_MenuCancelled = true;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
bool EE_SELECTION_TOOL::doSelectionMenu( EE_COLLECTOR* aCollector )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-14 11:14:00 +00:00
|
|
|
EDA_ITEM* current = nullptr;
|
2020-05-24 23:35:04 +00:00
|
|
|
bool selectAll = false;
|
2020-07-07 04:51:12 +00:00
|
|
|
bool expandSelection = false;
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
do
|
2019-04-23 12:51:48 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
/// The user has requested the full, non-limited list of selection items
|
|
|
|
if( expandSelection )
|
|
|
|
aCollector->Combine();
|
2020-05-24 23:35:04 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
expandSelection = false;
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
int limit = std::min( 9, aCollector->GetCount() );
|
|
|
|
ACTION_MENU menu( true );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
for( int i = 0; i < limit; ++i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
wxString text;
|
|
|
|
EDA_ITEM* item = ( *aCollector )[i];
|
|
|
|
text = item->GetSelectMenuText( m_frame->GetUserUnits() );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
|
|
|
|
menu.Add( menuText, i + 1, item->GetMenuImage() );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.AppendSeparator();
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
|
2020-05-24 23:35:04 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
if( !expandSelection && aCollector->HasAdditionalItems() )
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
|
2020-07-07 04:51:12 +00:00
|
|
|
|
|
|
|
if( aCollector->m_MenuTitle.Length() )
|
|
|
|
{
|
|
|
|
menu.SetTitle( aCollector->m_MenuTitle );
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.SetIcon( BITMAPS::info );
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.DisplayTitle( true );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.DisplayTitle( false );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
SetContextMenu( &menu, CMENU_NOW );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->Action() == TA_CHOICE_MENU_UPDATE )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
if( selectAll )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
unhighlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
}
|
|
|
|
else if( current )
|
|
|
|
{
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = *evt->GetCommandId();
|
|
|
|
|
|
|
|
// User has pointed an item, so show it in a different way
|
|
|
|
if( id > 0 && id <= limit )
|
|
|
|
{
|
|
|
|
current = ( *aCollector )[id - 1];
|
|
|
|
highlight( current, BRIGHTENED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User has pointed on the "Select All" option
|
|
|
|
if( id == limit + 1 )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
highlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
selectAll = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
if( selectAll )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
unhighlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
}
|
|
|
|
else if( current )
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
|
|
|
|
OPT<int> id = evt->GetCommandId();
|
|
|
|
|
|
|
|
// User has selected the "Select All" option
|
|
|
|
if( id == limit + 1 )
|
|
|
|
{
|
|
|
|
selectAll = true;
|
|
|
|
current = nullptr;
|
|
|
|
}
|
2021-02-24 10:55:35 +00:00
|
|
|
else if( id == limit + 2 )
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
current = nullptr;
|
|
|
|
expandSelection = true;
|
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
// User has selected an item, so this one will be returned
|
|
|
|
else if( id && ( *id > 0 ) && ( *id <= limit ) )
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
current = ( *aCollector )[*id - 1];
|
|
|
|
}
|
2021-02-24 10:55:35 +00:00
|
|
|
// User has cancelled the menu (either by <esc> or clicking out of it)
|
2020-07-07 04:51:12 +00:00
|
|
|
else
|
|
|
|
{
|
2021-02-24 10:55:35 +00:00
|
|
|
selectAll = false;
|
|
|
|
current = nullptr;
|
2020-07-07 04:51:12 +00:00
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
break;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
} while( expandSelection );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
if( selectAll )
|
|
|
|
return true;
|
|
|
|
else if( current )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
aCollector->Empty();
|
|
|
|
aCollector->Append( current );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
|
|
|
|
bool checkVisibilityOnly ) const
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
// NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
|
2021-03-07 11:58:11 +00:00
|
|
|
|
|
|
|
SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2020-11-23 19:46:17 +00:00
|
|
|
|
|
|
|
// Do not allow selection of anything except fields when the current symbol in the symbol
|
|
|
|
// editor is a derived symbol.
|
2021-03-07 11:58:11 +00:00
|
|
|
if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != LIB_FIELD_T )
|
2020-11-23 19:46:17 +00:00
|
|
|
return false;
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_PIN_T:
|
2021-09-19 10:05:58 +00:00
|
|
|
{
|
|
|
|
const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
|
|
|
|
|
|
|
|
if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
|
2019-04-21 23:45:34 +00:00
|
|
|
return false;
|
2021-09-19 10:05:58 +00:00
|
|
|
|
|
|
|
if( m_frame->eeconfig()->m_Selection.select_pin_selects_symbol )
|
|
|
|
{
|
|
|
|
// Pin anchors have to be allowed for auto-starting wires.
|
|
|
|
if( aPos )
|
|
|
|
{
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor( *aPos, LAYER_CONNECTABLE, nullptr );
|
|
|
|
|
|
|
|
if( pin->IsPointClickableAnchor( (wxPoint) cursorPos ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
|
2019-04-21 23:45:34 +00:00
|
|
|
return false;
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
case LIB_FIELD_T: // LIB_FIELD object can always be edited.
|
2019-12-12 15:44:53 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case LIB_SHAPE_T:
|
2019-08-15 07:09:52 +00:00
|
|
|
case LIB_TEXT_T:
|
2019-05-08 18:56:03 +00:00
|
|
|
case LIB_PIN_T:
|
2020-11-23 19:46:17 +00:00
|
|
|
if( symEditFrame )
|
2019-12-12 16:42:11 +00:00
|
|
|
{
|
|
|
|
LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
if( lib_item->GetUnit() && lib_item->GetUnit() != symEditFrame->GetUnit() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
if( lib_item->GetConvert() && lib_item->GetConvert() != symEditFrame->GetConvert() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
case SCH_MARKER_T: // Always selectable
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default: // Suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void EE_SELECTION_TOOL::ClearSelection()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( m_selection.GetSize() )
|
2019-05-05 10:33:34 +00:00
|
|
|
unhighlight( (EDA_ITEM*) m_selection.Front(), SELECTED, &m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
getView()->Update( &m_selection );
|
|
|
|
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::select( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
highlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::unselect( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
unhighlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
KICAD_T itemType = aItem->Type();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( aMode == SELECTED )
|
|
|
|
aItem->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aItem->SetBrightened();
|
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Add( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Highlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2021-10-12 20:05:37 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
aChild->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aChild->SetBrightened();
|
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->Update( aItem->GetParent() );
|
|
|
|
else
|
|
|
|
getView()->Update( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
KICAD_T itemType = aItem->Type();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( aMode == SELECTED )
|
|
|
|
aItem->ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aItem->ClearBrightened();
|
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Remove( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Unhighlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2020-11-17 16:02:47 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
aChild->ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aChild->ClearBrightened();
|
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->Update( aItem->GetParent() );
|
|
|
|
else
|
|
|
|
getView()->Update( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
const unsigned GRIP_MARGIN = 20;
|
|
|
|
VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
|
|
|
|
|
|
|
|
// Check if the point is located within any of the currently selected items bounding boxes
|
2020-12-14 21:11:33 +00:00
|
|
|
for( EDA_ITEM* item : m_selection )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
BOX2I itemBox = item->ViewBBox();
|
|
|
|
itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
|
|
|
|
|
|
|
|
if( itemBox.Contains( aPoint ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::setTransitions()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::Main, EE_ACTIONS::selectionActivate.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectNode, EE_ACTIONS::selectNode.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectConnection, EE_ACTIONS::selectConnection.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::ClearSelection, EE_ACTIONS::clearSelection.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::AddItemToSel, EE_ACTIONS::addItemToSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::AddItemsToSel, EE_ACTIONS::addItemsToSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::RemoveItemFromSel, EE_ACTIONS::removeItemFromSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::RemoveItemsFromSel, EE_ACTIONS::removeItemsFromSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectionMenu, EE_ACTIONS::selectionMenu.MakeEvent() );
|
2020-08-20 23:05:21 +00:00
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectAll, EE_ACTIONS::selectAll.MakeEvent() );
|
2021-09-05 20:37:52 +00:00
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::disambiguateCursor, EVENTS::DisambiguatePoint );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:34:58 +00:00
|
|
|
|