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
|
2022-01-16 20:29:03 +00:00
|
|
|
* Copyright (C) 2019-2022 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
|
|
|
|
*/
|
|
|
|
|
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>
|
2022-07-12 01:03:45 +00:00
|
|
|
#include <eeschema_id.h>
|
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>
|
2022-07-23 22:26:03 +00:00
|
|
|
#include <sch_painter.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#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-12-30 20:05:32 +00:00
|
|
|
#include <sch_bus_entry.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>
|
2022-07-09 17:55:40 +00:00
|
|
|
#include <tools/sch_editor_control.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>
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-12-22 19:00:10 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::MultipleSymbolsOrPower = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return aSel.GetSize() > 1 && aSel.OnlyContains( { SCH_SYMBOL_T } );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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() :
|
2022-07-12 01:03:45 +00:00
|
|
|
SELECTION_TOOL( "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
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
static std::vector<KICAD_T> connectedTypes =
|
2022-08-20 09:27:35 +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,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_JUNCTION_T
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-12-15 15:26:48 +00:00
|
|
|
auto linesSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_ITEM_LOCATE_GRAPHIC_LINE_T } );
|
2022-08-20 09:27:35 +00:00
|
|
|
auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } );
|
2022-02-27 20:14:22 +00:00
|
|
|
auto connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes );
|
2022-08-20 09:27:35 +00:00
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } );
|
|
|
|
auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( { SCH_SYMBOL_T, SCH_PIN_T, 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;
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
return E_C::LessThan( 2 )( aSel ) && E_C::OnlyTypes( { 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
|
|
|
};
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
auto haveHighlight =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
|
|
|
return editFrame && editFrame->GetHighlightedConnection() != nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto haveSymbol =
|
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
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
auto symbolDisplayNameIsEditable =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
if ( !m_isSymbolEditor )
|
|
|
|
return false;
|
|
|
|
|
2022-09-20 16:08:24 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2022-09-14 22:11:37 +00:00
|
|
|
|
2022-09-20 16:08:24 +00:00
|
|
|
return symbEditorFrame
|
|
|
|
&& symbEditorFrame->GetCurSymbol()
|
|
|
|
&& symbEditorFrame->GetCurSymbol()->IsMulti()
|
|
|
|
&& symbEditorFrame->IsSymbolEditable()
|
|
|
|
&& !symbEditorFrame->IsSymbolAlias();
|
2022-09-14 22:11:37 +00:00
|
|
|
};
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
auto& menu = m_menu.GetMenu();
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::clearHighlight, haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddSeparator( haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
|
|
|
|
menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 2 );
|
|
|
|
menu.AddItem( EE_ACTIONS::selectOnPCB, crossProbingSelection && EE_CONDITIONS::Idle, 2 );
|
|
|
|
menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
|
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 );
|
2022-02-27 20:14:22 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::selectConnection, connectedSelection && 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 );
|
2022-12-15 15:26:48 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::breakWire, linesSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::slice, linesSelection && EE_CONDITIONS::Idle, 250 );
|
2022-12-29 14:32:10 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::importSheetPin, 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 );
|
2022-07-10 23:14:29 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::symbolProperties, haveSymbol && EE_CONDITIONS::Empty, 400 );
|
|
|
|
menu.AddItem( EE_ACTIONS::pinTable, haveSymbol && EE_CONDITIONS::Empty, 400 );
|
2022-09-14 22:11:37 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::setUnitDisplayName,
|
|
|
|
haveSymbol && symbolDisplayNameIsEditable && 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
|
2022-07-12 01:03:45 +00:00
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2022-07-12 01:03:45 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
2022-02-25 15:32:13 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
// Restore previous properties of selected items and remove them from containers
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2022-02-25 15:32:13 +00:00
|
|
|
}
|
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-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;
|
2023-02-16 22:14:08 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
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
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
bool selCancelled = false;
|
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
|
|
|
MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
if( evt->IsMouseDown( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
// Avoid triggering when running under other tools
|
2022-12-08 17:37:15 +00:00
|
|
|
// Distinguish point editor from selection modification by checking modifiers
|
2022-04-17 07:54:19 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() && m_toolMgr->GetTool<EE_POINT_EDITOR>()
|
2022-12-08 19:09:30 +00:00
|
|
|
&& ( !m_toolMgr->GetTool<EE_POINT_EDITOR>()->HasPoint() || hasModifier() ) )
|
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
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
// Collect items at the clicked location (doesn't select them yet)
|
2020-10-01 23:53:47 +00:00
|
|
|
EE_COLLECTOR collector;
|
2022-02-14 00:53:47 +00:00
|
|
|
CollectHits( collector, evt->Position() );
|
2022-03-03 14:35:57 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-12-08 19:09:30 +00:00
|
|
|
if( collector.GetCount() == 1 && !m_isSymbolEditor && !hasModifier() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT autostart = autostartEvent( evt, grid, collector[0] );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostart )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
DRAW_SEGMENT_EVENT_PARAMS* params = new DRAW_SEGMENT_EVENT_PARAMS();
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
params->layer = autostart->Parameter<DRAW_SEGMENT_EVENT_PARAMS*>()->layer;
|
|
|
|
params->quitOnDraw = true;
|
|
|
|
params->sourceSegment = dynamic_cast<SCH_LINE*>( collector[0] );
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
autostart->SetParameter( params );
|
|
|
|
m_toolMgr->ProcessEvent( *autostart );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
selCancelled = true;
|
|
|
|
}
|
|
|
|
else if( collector[0]->IsHypertext() )
|
|
|
|
{
|
2022-08-27 18:14:57 +00:00
|
|
|
collector[ 0 ]->DoHypertextAction( m_frame );
|
2022-02-14 00:53:47 +00:00
|
|
|
selCancelled = true;
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( !selCancelled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
selectPoint( collector, evt->Position(), nullptr, nullptr, m_additive,
|
|
|
|
m_subtractive, 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
|
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();
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
|
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.
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( !m_selection.GetBoundingBox().Inflate( grid.GetGrid().x, grid.GetGrid().y )
|
|
|
|
.Contains( evt->Position() ) )
|
2021-01-31 14:59:18 +00:00
|
|
|
{
|
2022-12-22 19:16:38 +00:00
|
|
|
EE_COLLECTOR collector;
|
2021-01-31 14:59:18 +00:00
|
|
|
|
2022-12-22 19:16:38 +00:00
|
|
|
if( CollectHits( collector, evt->Position(), { SCH_LOCATE_ANY_T } ) )
|
2021-01-31 14:59:18 +00:00
|
|
|
{
|
2022-12-22 19:16:38 +00:00
|
|
|
ClearSelection();
|
2021-01-31 14:59:18 +00:00
|
|
|
|
2022-12-22 19:16:38 +00:00
|
|
|
SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
|
2021-01-31 14:59:18 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( !selCancelled )
|
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
|
|
|
|
2022-12-08 19:09:30 +00:00
|
|
|
if( hasModifier() || 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() )
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
|
|
|
m_selection = RequestSelection( { LIB_FIELD_T } );
|
|
|
|
}
|
2021-07-01 20:03:14 +00:00
|
|
|
else
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
|
|
|
m_selection = RequestSelection( { LIB_SHAPE_T,
|
|
|
|
LIB_TEXT_T,
|
|
|
|
LIB_TEXTBOX_T,
|
|
|
|
LIB_PIN_T,
|
|
|
|
LIB_FIELD_T } );
|
|
|
|
}
|
2021-07-01 20:03:14 +00:00
|
|
|
}
|
|
|
|
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
|
2022-11-19 21:01:45 +00:00
|
|
|
if( selectionContains( evt->DragOrigin() ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 21:56:17 +00:00
|
|
|
else if( evt->IsMouseDown( BUT_AUX1 ) )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::navigateBack, true );
|
|
|
|
}
|
|
|
|
else if( evt->IsMouseDown( BUT_AUX2 ) )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::navigateForward, true );
|
|
|
|
}
|
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
|
2022-08-30 20:58:43 +00:00
|
|
|
if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
|
|
|
&& *evt->GetCommandId() <= 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() );
|
2022-08-30 20:58:43 +00:00
|
|
|
int unit = *evt->GetCommandId() - 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
|
|
|
}
|
2022-08-30 20:58:43 +00:00
|
|
|
else if( *evt->GetCommandId() >= ID_POPUP_SCH_UNFOLD_BUS
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
2019-05-05 14:16:29 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-07-09 17:55:40 +00:00
|
|
|
if( !GetSelection().Empty() )
|
|
|
|
{
|
|
|
|
ClearSelection();
|
|
|
|
}
|
2022-07-18 21:03:14 +00:00
|
|
|
else if( evt->FirstResponder() == this && evt->GetCommandId() == (int) WXK_ESCAPE )
|
2022-07-09 17:55:40 +00:00
|
|
|
{
|
|
|
|
SCH_EDITOR_CONTROL* editor = m_toolMgr->GetTool<SCH_EDITOR_CONTROL>();
|
|
|
|
|
2022-07-23 09:32:21 +00:00
|
|
|
if( editor && m_frame->eeconfig()->m_Input.esc_clears_net_highlight )
|
2022-07-09 17:55:40 +00:00
|
|
|
editor->ClearHighlight( *evt );
|
|
|
|
}
|
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
|
|
|
}
|
2022-07-09 17:55:40 +00:00
|
|
|
else if( evt->IsMotion() && !m_isSymbolEditor && evt->FirstResponder() == this )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
// Update cursor and rollover item
|
2020-11-29 16:31:43 +00:00
|
|
|
rolloverItem = niluuid;
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
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
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-12-08 19:09:30 +00:00
|
|
|
if( collector.GetCount() == 1 && !hasModifier() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT autostartEvt = autostartEvent( evt, grid, collector[0] );
|
2021-10-01 00:25:33 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostartEvt )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostartEvt->Matches( EE_ACTIONS::drawBus.MakeEvent() ) )
|
2021-02-15 14:57:06 +00:00
|
|
|
displayBusCursor = true;
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( autostartEvt->Matches( EE_ACTIONS::drawWire.MakeEvent() ) )
|
|
|
|
displayWireCursor = true;
|
|
|
|
else if( autostartEvt->Matches( EE_ACTIONS::drawLines.MakeEvent() ) )
|
2021-02-17 19:43:07 +00:00
|
|
|
displayLineCursor = true;
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( collector[0]->IsHypertext() && !collector[0]->IsSelected() )
|
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 )
|
|
|
|
{
|
2022-08-27 18:14:57 +00:00
|
|
|
if( EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2022-08-27 18:14:57 +00:00
|
|
|
}
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
if( EDA_ITEM* item = m_frame->GetItem( rolloverItem ) )
|
|
|
|
{
|
|
|
|
if( !( item->GetFlags() & IS_ROLLOVER ) )
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT EE_SELECTION_TOOL::autostartEvent( TOOL_EVENT* aEvent, EE_GRID_HELPER& aGrid,
|
|
|
|
SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
VECTOR2I pos = aGrid.BestSnapAnchor( aEvent->Position(), LAYER_CONNECTABLE );
|
|
|
|
|
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
|
|
|
&& !m_toolMgr->GetTool<EE_POINT_EDITOR>()->HasPoint()
|
|
|
|
&& aItem->IsPointClickableAnchor( pos ) )
|
|
|
|
{
|
|
|
|
OPT_TOOL_EVENT newEvt = EE_ACTIONS::drawWire.MakeEvent();
|
|
|
|
|
|
|
|
if( aItem->Type() == SCH_BUS_BUS_ENTRY_T )
|
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = static_cast<SCH_BUS_WIRE_ENTRY*>( aItem );
|
|
|
|
|
|
|
|
if( !busEntry->m_connected_bus_item )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
|
|
|
|
|
|
|
|
if( line->IsBus() )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
else if( line->IsGraphicLine() )
|
|
|
|
newEvt = EE_ACTIONS::drawLines.MakeEvent();
|
|
|
|
}
|
2023-01-12 20:10:23 +00:00
|
|
|
else if( aItem->Type() == SCH_LABEL_T || aItem->Type() == SCH_HIER_LABEL_T
|
|
|
|
|| aItem->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
|
|
|
|
SCH_CONNECTION possibleConnection( label->Schematic()->ConnectionGraph() );
|
|
|
|
possibleConnection.ConfigureFromLabel( label->GetText() );
|
|
|
|
|
|
|
|
if( possibleConnection.IsBus() )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
|
|
|
|
newEvt->SetMousePosition( pos );
|
|
|
|
newEvt->SetHasPosition( true );
|
|
|
|
newEvt->SetForceImmediate( true );
|
|
|
|
|
|
|
|
getViewControls()->ForceCursorPosition( true, pos );
|
|
|
|
|
|
|
|
return newEvt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPT_TOOL_EVENT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
int EE_SELECTION_TOOL::disambiguateCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-02-26 00:14:41 +00:00
|
|
|
wxMouseState keyboardState = wxGetMouseState();
|
|
|
|
|
|
|
|
setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
|
|
|
|
keyboardState.AltDown() );
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_skip_heuristics = true;
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( m_originalCursor, { SCH_LOCATE_ANY_T }, nullptr, &m_canceledMenu, false,
|
2021-09-24 19:44:26 +00:00
|
|
|
m_additive, m_subtractive, m_exclusive_or );
|
2021-09-05 20:37:52 +00:00
|
|
|
m_skip_heuristics = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
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 );
|
2022-07-23 22:26:03 +00:00
|
|
|
aCollector.m_ShowPinElectricalTypes = m_frame->GetRenderSettings()->m_ShowPinsElectricalType;
|
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
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
aCollector.Collect( symbol->GetDrawItems(), aScanTypes, aWhere, m_unit, m_convert );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-08-21 19:54:07 +00:00
|
|
|
aCollector.Collect( m_frame->GetScreen(), aScanTypes, aWhere, m_unit, m_convert );
|
2022-07-19 08:47:34 +00:00
|
|
|
|
|
|
|
if( m_frame->eeconfig()->m_Selection.select_pin_selects_symbol )
|
|
|
|
{
|
|
|
|
int originalCount = aCollector.GetCount();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < originalCount; ++ii )
|
|
|
|
{
|
|
|
|
if( aCollector[ii]->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aCollector[ii] );
|
|
|
|
|
|
|
|
if( !aCollector.HasItem( pin->GetParentSymbol() ) )
|
|
|
|
aCollector.Append( pin->GetParentSymbol() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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,
|
2022-09-06 15:11:56 +00:00
|
|
|
bool aCheckLocked, bool aSelectedOnly )
|
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;
|
|
|
|
}
|
2022-09-06 15:11:56 +00:00
|
|
|
|
|
|
|
if( aSelectedOnly && !collector[i]->IsSelected() )
|
|
|
|
{
|
|
|
|
collector.Remove( i );
|
|
|
|
continue;
|
|
|
|
}
|
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 )
|
|
|
|
GuessSelectionCandidates( collector, aWhere );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
|
|
|
EDA_ITEM** aItem, 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();
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
int addedCount = 0;
|
2020-05-24 23:35:04 +00:00
|
|
|
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
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
EDA_ITEM_FLAGS flags = 0;
|
2022-12-01 19:59:22 +00:00
|
|
|
bool isLine = aCollector[i]->Type() == SCH_LINE_T;
|
2022-03-03 14:35:57 +00:00
|
|
|
|
|
|
|
// Handle line ends specially
|
2022-12-01 19:59:22 +00:00
|
|
|
if( isLine )
|
2022-03-03 14:35:57 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) aCollector[i];
|
|
|
|
|
|
|
|
if( HitTestPoints( line->GetStartPoint(), aWhere, aCollector.m_Threshold ) )
|
|
|
|
flags = STARTPOINT;
|
|
|
|
else if( HitTestPoints( line->GetEndPoint(), aWhere, aCollector.m_Threshold ) )
|
|
|
|
flags = ENDPOINT;
|
|
|
|
else
|
|
|
|
flags = STARTPOINT | ENDPOINT;
|
|
|
|
}
|
|
|
|
|
2022-12-01 19:59:22 +00:00
|
|
|
if( aSubtract
|
|
|
|
|| ( aExclusiveOr && aCollector[i]->IsSelected()
|
|
|
|
&& ( !isLine || ( isLine && aCollector[i]->HasFlag( flags ) ) ) ) )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
aCollector[i]->ClearFlags( flags );
|
2022-07-12 01:03:45 +00:00
|
|
|
|
2022-12-01 19:59:22 +00:00
|
|
|
// Need to update end shadows after ctrl-click unselecting one of two selected endpoints
|
|
|
|
if( isLine )
|
|
|
|
getView()->Update( aCollector[i] );
|
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
if( !aCollector[i]->HasFlag( STARTPOINT ) && !aCollector[i]->HasFlag( ENDPOINT ) )
|
|
|
|
{
|
|
|
|
unselect( aCollector[i] );
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
aCollector[i]->SetFlags( flags );
|
2020-10-01 23:53:47 +00:00
|
|
|
select( aCollector[i] );
|
2022-07-19 15:00:35 +00:00
|
|
|
addedCount++;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
if( addedCount == 1 )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2022-07-19 15:00:35 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::PointSelectedEvent );
|
2020-05-24 23:35:04 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2022-07-19 15:00:35 +00:00
|
|
|
else if( addedCount > 1 )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
else if( anySubtracted )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes,
|
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;
|
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
if( !CollectHits( collector, aWhere, aScanTypes ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
return false;
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-09-06 15:11:56 +00:00
|
|
|
narrowSelection( collector, aWhere, aCheckLocked, aSubtract );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
return selectPoint( collector, aWhere, 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 ) )
|
2022-04-11 18:32:16 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
item->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
select( item );
|
2022-04-11 18:32:16 +00:00
|
|
|
}
|
2020-08-20 23:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_multiple = false;
|
|
|
|
|
2022-11-13 22:53:41 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
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
|
|
|
{
|
2022-07-19 08:47:34 +00:00
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
|
|
|
LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( item );
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( 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".
|
|
|
|
|
2023-01-07 23:02:03 +00:00
|
|
|
if( line || ( shape && shape->GetShape() == SHAPE_T::POLY )
|
|
|
|
|| ( shape && shape->GetShape() == SHAPE_T::ARC ) )
|
2021-09-21 17:15:41 +00:00
|
|
|
{
|
2023-01-07 23:02:03 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( 6 ) );
|
2022-07-19 08:47:34 +00:00
|
|
|
|
|
|
|
if( item->HitTest( aPos, pixelThreshold ) )
|
|
|
|
exactHits.insert( item );
|
|
|
|
}
|
|
|
|
else if( symbol && m_frame->eeconfig()->m_Selection.select_pin_selects_symbol )
|
|
|
|
{
|
|
|
|
if( symbol->GetBodyAndPinsBoundingBox().Contains( aPos ) )
|
2021-11-27 14:18:01 +00:00
|
|
|
exactHits.insert( item );
|
2021-09-21 17:15:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
if( item->HitTest( aPos, 0 ) )
|
2021-09-21 17:15:41 +00:00
|
|
|
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.)
|
2022-02-14 00:53:47 +00:00
|
|
|
VECTOR2I 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 )
|
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = item->GetBoundingBox();
|
|
|
|
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 )
|
|
|
|
{
|
2022-11-23 13:19:23 +00:00
|
|
|
if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( text ) )
|
|
|
|
{
|
|
|
|
if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
symbol = static_cast<SCH_SYMBOL*>( field->GetParent() );
|
|
|
|
|
|
|
|
VECTOR2I relPos = pos - symbol->GetPosition();
|
|
|
|
relPos = symbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
|
|
|
|
pos = relPos + symbol->GetPosition();
|
|
|
|
|
|
|
|
poss = SEG( pos, pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-19 16:36:32 +00:00
|
|
|
if( dist == closestDist )
|
|
|
|
{
|
|
|
|
if( item->GetParent() == closest )
|
|
|
|
closest = item;
|
|
|
|
}
|
|
|
|
else if( dist < closestDist )
|
2020-09-19 14:55:05 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I tightBox = closest->GetBoundingBox();
|
2020-09-30 02:28:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const std::vector<KICAD_T>& aScanTypes )
|
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();
|
2022-08-21 19:54:07 +00:00
|
|
|
SelectPoint( cursorPos, aScanTypes );
|
2020-03-06 20:02:58 +00:00
|
|
|
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;
|
2022-07-03 17:23:08 +00:00
|
|
|
bool anyUnselected = false;
|
2021-10-18 12:24:06 +00:00
|
|
|
|
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
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
if( !item->IsType( aScanTypes ) )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
|
|
|
unselect( item );
|
2022-07-03 17:23:08 +00:00
|
|
|
anyUnselected = true;
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-23 17:12:10 +00:00
|
|
|
}
|
2019-05-20 15:42:49 +00:00
|
|
|
|
2022-07-03 17:23:08 +00:00
|
|
|
if( anyUnselected )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
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
|
2022-07-23 13:08:51 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2022-10-10 19:16:54 +00:00
|
|
|
bool isGreedy = width < 0;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
|
|
|
if( view->IsMirroredX() )
|
2022-10-10 19:16:54 +00:00
|
|
|
isGreedy = !isGreedy;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2022-10-10 19:16:54 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( isGreedy ? KICURSOR::SELECT_LASSO
|
|
|
|
: KICURSOR::SELECT_WINDOW );
|
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
|
2022-07-23 14:09:16 +00:00
|
|
|
std::unordered_set<EDA_ITEM*> nearbyItems;
|
|
|
|
std::vector<EDA_ITEM*> nearbyChildren;
|
|
|
|
std::vector<EDA_ITEM*> flaggedItems;
|
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
|
|
|
{
|
2022-07-23 13:08:51 +00:00
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first ) )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2022-07-23 14:09:16 +00:00
|
|
|
if( nearbyItems.insert( item ).second )
|
2022-07-23 13:08:51 +00:00
|
|
|
{
|
2022-07-23 14:09:16 +00:00
|
|
|
item->ClearFlags( CANDIDATE );
|
|
|
|
|
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
2022-09-09 12:39:55 +00:00
|
|
|
// Filter pins by unit
|
|
|
|
if( SCH_PIN* pin = dyn_cast<SCH_PIN*>( aChild ) )
|
|
|
|
{
|
|
|
|
int unit = pin->GetLibPin()->GetUnit();
|
|
|
|
|
|
|
|
if( unit && unit != pin->GetParentSymbol()->GetUnit() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-23 14:09:16 +00:00
|
|
|
nearbyChildren.push_back( aChild );
|
|
|
|
} );
|
|
|
|
}
|
2022-07-23 13:08:51 +00:00
|
|
|
}
|
2021-03-07 14:32:49 +00:00
|
|
|
}
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
BOX2I selectionRect( area.GetOrigin(), VECTOR2I( width, height ) );
|
2021-12-10 18:43:35 +00:00
|
|
|
selectionRect.Normalize();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2022-02-10 18:38:40 +00:00
|
|
|
|
2022-10-10 19:16:54 +00:00
|
|
|
auto selectItem =
|
2022-12-10 18:16:28 +00:00
|
|
|
[&]( EDA_ITEM* aItem, EDA_ITEM_FLAGS flags )
|
2022-10-10 19:16:54 +00:00
|
|
|
{
|
|
|
|
if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
|
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
if ( m_exclusive_or )
|
|
|
|
aItem->XorFlags( flags );
|
|
|
|
else
|
|
|
|
aItem->ClearFlags( flags );
|
2022-10-10 19:16:54 +00:00
|
|
|
|
|
|
|
if( !aItem->HasFlag( STARTPOINT ) && !aItem->HasFlag( ENDPOINT ) )
|
|
|
|
{
|
|
|
|
unselect( aItem );
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
2022-12-10 18:16:28 +00:00
|
|
|
|
|
|
|
// We changed one line endpoint on a selected line,
|
|
|
|
// update the view at least.
|
|
|
|
if( flags && !anySubtracted )
|
|
|
|
{
|
|
|
|
getView()->Update( aItem );
|
|
|
|
}
|
2022-10-10 19:16:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aItem->SetFlags( flags );
|
|
|
|
select( aItem );
|
|
|
|
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
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
bool selected = false;
|
|
|
|
EDA_ITEM_FLAGS flags = 0;
|
|
|
|
|
2022-07-23 22:26:03 +00:00
|
|
|
if( m_frame->GetRenderSettings()->m_ShowPinsElectricalType )
|
|
|
|
item->SetFlags( SHOW_ELEC_TYPE );
|
|
|
|
|
2022-12-10 18:16:28 +00:00
|
|
|
if( Selectable( item ) )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
2022-12-12 20:04:33 +00:00
|
|
|
if( ( isGreedy && line->HitTest( selectionRect, false ) )
|
|
|
|
|| ( selectionRect.Contains( line->GetEndPoint() )
|
|
|
|
&& selectionRect.Contains( line->GetStartPoint() ) ) )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= STARTPOINT | ENDPOINT;
|
|
|
|
}
|
|
|
|
else if( !isGreedy )
|
|
|
|
{
|
2022-12-12 20:04:33 +00:00
|
|
|
if( selectionRect.Contains( line->GetStartPoint() )
|
|
|
|
&& line->IsStartDangling() )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= STARTPOINT;
|
|
|
|
}
|
|
|
|
|
2022-12-12 20:04:33 +00:00
|
|
|
if( selectionRect.Contains( line->GetEndPoint() )
|
|
|
|
&& line->IsEndDangling() )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= ENDPOINT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selected = item->HitTest( selectionRect, !isGreedy );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( selected )
|
2021-12-10 18:43:35 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
item->SetFlags( CANDIDATE );
|
2022-04-16 22:44:34 +00:00
|
|
|
flaggedItems.push_back( item );
|
2022-12-10 18:16:28 +00:00
|
|
|
selectItem( item, flags );
|
2021-12-10 18:43:35 +00:00
|
|
|
}
|
2022-07-23 22:26:03 +00:00
|
|
|
|
|
|
|
item->ClearFlags( SHOW_ELEC_TYPE );
|
2021-12-10 18:43:35 +00:00
|
|
|
}
|
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
|
|
|
{
|
2022-07-23 22:26:03 +00:00
|
|
|
if( m_frame->GetRenderSettings()->m_ShowPinsElectricalType )
|
|
|
|
item->SetFlags( SHOW_ELEC_TYPE );
|
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
if( Selectable( item )
|
2022-03-03 14:35:57 +00:00
|
|
|
&& !item->GetParent()->HasFlag( CANDIDATE )
|
2022-10-10 19:16:54 +00:00
|
|
|
&& item->HitTest( selectionRect, !isGreedy ) )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
selectItem( item, 0 );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
2022-07-23 22:26:03 +00:00
|
|
|
|
|
|
|
item->ClearFlags( SHOW_ELEC_TYPE );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-16 22:44:34 +00:00
|
|
|
for( EDA_ITEM* item : flaggedItems )
|
|
|
|
item->ClearFlags( CANDIDATE );
|
|
|
|
|
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-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;
|
2022-08-20 09:27:35 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), connectedTypes, 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
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( cursorPos, connectedTypes );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
RequestSelection( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } );
|
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();
|
2022-05-29 21:51:07 +00:00
|
|
|
unsigned done = false;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
m_frame->GetScreen()->ClearDrawingState();
|
2022-05-29 21:51:07 +00:00
|
|
|
std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line, false );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( SCH_ITEM* item : conns )
|
2022-05-29 21:51:07 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } )
|
|
|
|
&& !item->IsSelected() )
|
|
|
|
{
|
2022-05-29 21:51:07 +00:00
|
|
|
done = true;
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2022-05-29 21:51:07 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
select( item );
|
2022-05-29 21:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !done )
|
|
|
|
{
|
|
|
|
conns = m_frame->GetScreen()->MarkConnections( line, true );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : conns )
|
|
|
|
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::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
void EE_SELECTION_TOOL::ZoomFitCrossProbeBBox( const BOX2I& aBBox )
|
2022-07-19 15:00:35 +00:00
|
|
|
{
|
2022-08-31 12:56:58 +00:00
|
|
|
if( aBBox.GetWidth() == 0 )
|
2022-07-19 15:00:35 +00:00
|
|
|
return;
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
BOX2I bbox = aBBox;
|
2022-07-19 15:00:35 +00:00
|
|
|
bbox.Normalize();
|
|
|
|
|
|
|
|
VECTOR2I bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
|
|
|
|
VECTOR2D screenSize = getView()->GetViewport().GetSize();
|
|
|
|
|
|
|
|
// This code tries to come up with a zoom factor that doesn't simply zoom in
|
|
|
|
// to the cross probed symbol, but instead shows a reasonable amount of the
|
|
|
|
// circuit around it to provide context. This reduces or eliminates the need
|
|
|
|
// to manually change the zoom because it's too close.
|
|
|
|
|
|
|
|
// Using the default text height as a constant to compare against, use the
|
|
|
|
// height of the bounding box of visible items for a footprint to figure out
|
|
|
|
// if this is a big symbol (like a processor) or a small symbol (like a resistor).
|
|
|
|
// This ratio is not useful by itself as a scaling factor. It must be "bent" to
|
|
|
|
// provide good scaling at varying symbol sizes. Bigger symbols need less
|
|
|
|
// scaling than small ones.
|
2022-09-16 23:42:20 +00:00
|
|
|
double currTextHeight = schIUScale.MilsToIU( DEFAULT_TEXT_SIZE );
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
double compRatio = bbSize.y / currTextHeight; // Ratio of symbol to text height
|
|
|
|
double compRatioBent = 1.0;
|
|
|
|
|
|
|
|
// LUT to scale zoom ratio to provide reasonable schematic context. Must work
|
|
|
|
// with symbols of varying sizes (e.g. 0402 package and 200 pin BGA).
|
|
|
|
// "first" is used as the input and "second" as the output
|
|
|
|
//
|
|
|
|
// "first" = compRatio (symbol height / default text height)
|
|
|
|
// "second" = Amount to scale ratio by
|
|
|
|
std::vector<std::pair<double, double>> lut{ { 1.25, 16 }, // 32
|
|
|
|
{ 2.5, 12 }, //24
|
|
|
|
{ 5, 8 }, // 16
|
|
|
|
{ 6, 6 }, //
|
|
|
|
{ 10, 4 }, //8
|
|
|
|
{ 20, 2 }, //4
|
|
|
|
{ 40, 1.5 }, // 2
|
|
|
|
{ 100, 1 } };
|
|
|
|
|
|
|
|
std::vector<std::pair<double, double>>::iterator it;
|
|
|
|
|
|
|
|
// Large symbol default is last LUT entry (1:1).
|
|
|
|
compRatioBent = lut.back().second;
|
|
|
|
|
|
|
|
// Use LUT to do linear interpolation of "compRatio" within "first", then
|
|
|
|
// use that result to linearly interpolate "second" which gives the scaling
|
|
|
|
// factor needed.
|
|
|
|
if( compRatio >= lut.front().first )
|
|
|
|
{
|
|
|
|
for( it = lut.begin(); it < lut.end() - 1; it++ )
|
|
|
|
{
|
|
|
|
if( it->first <= compRatio && next( it )->first >= compRatio )
|
|
|
|
{
|
|
|
|
double diffx = compRatio - it->first;
|
|
|
|
double diffn = next( it )->first - it->first;
|
|
|
|
|
|
|
|
compRatioBent = it->second + ( next( it )->second - it->second ) * diffx / diffn;
|
|
|
|
break; // We have our interpolated value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compRatioBent = lut.front().second; // Small symbol default is first entry
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is similar to the original KiCad code that scaled the zoom to make sure
|
|
|
|
// symbols were visible on screen. It's simply a ratio of screen size to
|
|
|
|
// symbol size, and its job is to zoom in to make the component fullscreen.
|
|
|
|
// Earlier in the code the symbol BBox is given a 20% margin to add some
|
|
|
|
// breathing room. We compare the height of this enlarged symbol bbox to the
|
|
|
|
// default text height. If a symbol will end up with the sides clipped, we
|
|
|
|
// adjust later to make sure it fits on screen.
|
|
|
|
screenSize.x = std::max( 10.0, screenSize.x );
|
|
|
|
screenSize.y = std::max( 10.0, screenSize.y );
|
|
|
|
double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
|
|
|
|
|
|
|
|
// Original KiCad code for how much to scale the zoom
|
|
|
|
double kicadRatio =
|
|
|
|
std::max( fabs( bbSize.x / screenSize.x ), fabs( bbSize.y / screenSize.y ) );
|
|
|
|
|
|
|
|
// If the width of the part we're probing is bigger than what the screen width
|
|
|
|
// will be after the zoom, then punt and use the KiCad zoom algorithm since it
|
|
|
|
// guarantees the part's width will be encompassed within the screen.
|
|
|
|
if( bbSize.x > screenSize.x * ratio * compRatioBent )
|
|
|
|
{
|
|
|
|
// Use standard KiCad zoom for parts too wide to fit on screen/
|
|
|
|
ratio = kicadRatio;
|
|
|
|
compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
|
|
|
|
wxLogTrace( "CROSS_PROBE_SCALE",
|
|
|
|
"Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f", ratio );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that "compRatioBent" holds our final scaling factor we apply it to the
|
|
|
|
// original fullscreen zoom ratio to arrive at the final ratio itself.
|
|
|
|
ratio *= compRatioBent;
|
|
|
|
|
|
|
|
bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
|
|
|
|
|
|
|
|
// Try not to zoom on every cross-probe; it gets very noisy
|
|
|
|
if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
|
|
|
|
getView()->SetScale( getView()->GetScale() / ratio );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EE_SELECTION_TOOL::SyncSelection( std::optional<SCH_SHEET_PATH> targetSheetPath,
|
|
|
|
SCH_ITEM* focusItem, std::vector<SCH_ITEM*> items )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
|
|
|
if( !editFrame || m_isSymbolEditor || m_isSymbolViewer )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( targetSheetPath && targetSheetPath != editFrame->Schematic().CurrentSheet() )
|
|
|
|
{
|
|
|
|
editFrame->Schematic().SetCurrentSheet( *targetSheetPath );
|
|
|
|
editFrame->DisplayCurrentSheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSelection( items.size() > 0 ? true /*quiet mode*/ : false );
|
|
|
|
|
|
|
|
// Perform individual selection of each item before processing the event.
|
|
|
|
for( SCH_ITEM* item : items )
|
|
|
|
select( item );
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = m_selection.GetBoundingBox();
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
|
|
|
|
{
|
|
|
|
if( m_frame->eeconfig()->m_CrossProbing.center_on_items )
|
|
|
|
{
|
|
|
|
if( m_frame->eeconfig()->m_CrossProbing.zoom_to_fit )
|
|
|
|
ZoomFitCrossProbeBBox( bbox );
|
|
|
|
|
|
|
|
editFrame->FocusOnItem( focusItem );
|
|
|
|
|
|
|
|
if( !focusItem )
|
|
|
|
editFrame->FocusOnLocation( bbox.Centre() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_selection.Size() > 0 )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
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() )
|
2022-07-12 01:03:45 +00:00
|
|
|
select( &item );
|
2020-01-04 23:05:57 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( pin->IsPointClickableAnchor( grid.BestSnapAnchor( *aPos, LAYER_CONNECTABLE ) ) )
|
2021-09-19 10:05:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
break;
|
2022-02-14 00:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
void EE_SELECTION_TOOL::ClearSelection( bool aQuietMode )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( m_selection.GetSize() )
|
2022-07-12 01:03:45 +00:00
|
|
|
unhighlight( 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
|
2022-07-19 15:00:35 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, 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 )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
aChild->SetSelected();
|
2023-02-16 22:14:08 +00:00
|
|
|
getView()->Hide( aChild, true );
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
aChild->SetBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2023-02-15 04:46:35 +00:00
|
|
|
if( aGroup && aMode != BRIGHTENED )
|
|
|
|
getView()->Hide( aItem, true );
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
|
2019-04-23 17:40:29 +00:00
|
|
|
else
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem, KIGFX::REPAINT );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, 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 )
|
2022-03-03 14:35:57 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
aItem->ClearSelected();
|
2022-03-03 14:35:57 +00:00
|
|
|
// Lines need endpoints cleared here
|
|
|
|
if( aItem->Type() == SCH_LINE_T )
|
|
|
|
aItem->ClearFlags( STARTPOINT | ENDPOINT );
|
2023-02-15 04:46:35 +00:00
|
|
|
|
|
|
|
if( aMode != BRIGHTENED )
|
|
|
|
getView()->Hide( aItem, false );
|
2022-03-03 14:35:57 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
aItem->ClearBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
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(
|
2022-07-12 01:03:45 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2022-07-12 01:03:45 +00:00
|
|
|
aChild->ClearSelected();
|
2023-02-16 22:14:08 +00:00
|
|
|
getView()->Hide( aChild, false );
|
|
|
|
}
|
2022-07-12 01:03:45 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2022-07-12 01:03:45 +00:00
|
|
|
aChild->ClearBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2022-07-12 01:03:45 +00:00
|
|
|
} );
|
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 )
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
|
2019-04-23 17:40:29 +00:00
|
|
|
else
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem, KIGFX::REPAINT );
|
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;
|
2022-11-20 19:24:16 +00:00
|
|
|
double margin = getView()->ToWorld( GRIP_MARGIN );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// 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();
|
2022-11-20 19:24:16 +00:00
|
|
|
itemBox.Inflate( margin ); // Give some margin for gripping an item
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
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
|
|
|
|