2019-04-15 14:34:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-15 14:34:58 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <core/typeinfo.h>
|
2021-03-22 12:51:32 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <ee_actions.h>
|
|
|
|
#include <ee_collectors.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_selection_tool.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <eeschema_id.h> // For MAX_SELECT_ITEM_IDS
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <lib_item.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <math/util.h>
|
|
|
|
#include <menus_helpers.h>
|
|
|
|
#include <painter.h>
|
|
|
|
#include <preview_items/selection_area.h>
|
|
|
|
#include <sch_base_frame.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-02-01 16:39:26 +00:00
|
|
|
#include <sch_field.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_item.h>
|
2019-06-11 20:17:05 +00:00
|
|
|
#include <sch_line.h>
|
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>
|
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>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
2019-04-15 14:34:58 +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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:28:16 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::EE_SELECTION_TOOL() :
|
2019-04-21 23:45:34 +00:00
|
|
|
TOOL_INTERACTIVE( "eeschema.InteractiveSelection" ),
|
2019-04-28 23:34:43 +00:00
|
|
|
m_frame( nullptr ),
|
2019-04-21 23:45:34 +00:00
|
|
|
m_additive( false ),
|
|
|
|
m_subtractive( false ),
|
2019-07-09 19:50:40 +00:00
|
|
|
m_exclusive_or( false ),
|
2019-04-21 23:45:34 +00:00
|
|
|
m_multiple( false ),
|
|
|
|
m_skip_heuristics( false ),
|
2020-11-21 20:57:13 +00:00
|
|
|
m_nonModifiedCursor( KICURSOR::ARROW ),
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor( false ),
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer( false ),
|
2019-05-06 02:32:01 +00:00
|
|
|
m_unit( 0 ),
|
2019-06-05 19:15:57 +00:00
|
|
|
m_convert( 0 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-08-20 23:05:21 +00:00
|
|
|
m_selection.Clear();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::~EE_SELECTION_TOOL()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
using E_C = EE_CONDITIONS;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::Init()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-06 02:32:01 +00:00
|
|
|
m_frame = getEditFrame<SCH_BASE_FRAME>();
|
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
|
|
|
|
SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditorFrame )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor = true;
|
|
|
|
m_unit = symbolEditorFrame->GetUnit();
|
|
|
|
m_convert = symbolEditorFrame->GetConvert();
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-02 10:59:36 +00:00
|
|
|
static KICAD_T wireOrBusTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
|
2020-07-07 10:17:30 +00:00
|
|
|
static KICAD_T connectedTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T,
|
|
|
|
SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T,
|
|
|
|
SCH_SHEET_PIN_T, SCH_PIN_T, EOT };
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
auto wireSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T );
|
|
|
|
auto busSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T );
|
|
|
|
auto wireOrBusSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( wireOrBusTypes );
|
2020-07-07 10:17:30 +00:00
|
|
|
auto connectedSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( connectedTypes );
|
2019-05-17 16:45:27 +00:00
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2020-12-11 20:02:20 +00:00
|
|
|
auto schEditSheetPageNumberCondition =
|
2021-02-19 14:51:18 +00:00
|
|
|
[&] ( const SELECTION& aSel )
|
2020-12-11 20:02:20 +00:00
|
|
|
{
|
2021-02-19 14:51:18 +00:00
|
|
|
if( m_isSymbolEditor || m_isSymbolViewer )
|
|
|
|
return false;
|
|
|
|
|
2021-02-19 19:04:44 +00:00
|
|
|
return E_C::LessThan( 2 )( aSel ) && E_C::OnlyType( SCH_SHEET_T )( aSel );
|
2020-12-11 20:02:20 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
auto schEditCondition =
|
|
|
|
[this] ( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
return !m_isSymbolEditor && !m_isSymbolViewer;
|
2020-07-07 10:17:30 +00:00
|
|
|
};
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
auto belowRootSheetCondition =
|
|
|
|
[&]( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
return editFrame
|
|
|
|
&& editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
auto haveSymbolCondition =
|
2020-05-13 02:00:37 +00:00
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
return m_isSymbolEditor &&
|
|
|
|
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
auto& menu = m_menu.GetMenu();
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddItem( EE_ACTIONS::explicitCrossProbe, sheetSelection && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 1 );
|
2019-05-03 22:48:24 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::drawWire, schEditCondition && EE_CONDITIONS::Empty, 100 );
|
|
|
|
menu.AddItem( EE_ACTIONS::drawBus, schEditCondition && EE_CONDITIONS::Empty, 100 );
|
2019-05-03 22:48:24 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::finishWire, SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire, 100 );
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 100 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::finishBus, SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus, 100 );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 200 );
|
2019-05-17 15:16:13 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-05-17 15:16:13 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 250 );
|
2021-02-21 15:44:38 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::importSingleSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
|
2020-12-11 20:02:20 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2021-06-15 12:31:28 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::symbolProperties,
|
|
|
|
haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
|
|
|
|
menu.AddItem( EE_ACTIONS::pinTable,
|
|
|
|
haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
|
2019-05-01 13:24:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 1000 );
|
2019-06-11 14:38:21 +00:00
|
|
|
m_frame->AddStandardSubMenus( m_menu );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::Reset( RESET_REASON aReason )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-06 02:32:01 +00:00
|
|
|
m_frame = getEditFrame<SCH_BASE_FRAME>();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( aReason == TOOL_BASE::MODEL_RELOAD )
|
|
|
|
{
|
|
|
|
// Remove pointers to the selected items from containers without changing their
|
|
|
|
// properties (as they are already deleted while a new sheet is loaded)
|
|
|
|
m_selection.Clear();
|
|
|
|
getView()->GetPainter()->GetSettings()->SetHighlight( false );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbolEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
|
|
|
SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
if( symbolEditFrame )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor = true;
|
2020-12-25 23:37:01 +00:00
|
|
|
m_unit = symbolEditFrame->GetUnit();
|
|
|
|
m_convert = symbolEditFrame->GetConvert();
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// Restore previous properties of selected items and remove them from containers
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
getView()->Add( &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int EE_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-14 11:14:00 +00:00
|
|
|
ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
|
2019-05-13 20:42:40 +00:00
|
|
|
CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
|
|
|
|
|
|
|
|
if( conditionalMenu )
|
|
|
|
conditionalMenu->Evaluate( m_selection );
|
|
|
|
|
|
|
|
if( actionMenu )
|
|
|
|
actionMenu->UpdateAll();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-23 22:57:34 +00:00
|
|
|
const KICAD_T movableSchematicItems[] =
|
|
|
|
{
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL_T,
|
2020-04-23 22:57:34 +00:00
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const KICAD_T movableSymbolItems[] =
|
|
|
|
{
|
|
|
|
LIB_ARC_T,
|
|
|
|
LIB_CIRCLE_T,
|
|
|
|
LIB_TEXT_T,
|
|
|
|
LIB_RECTANGLE_T,
|
|
|
|
LIB_POLYLINE_T,
|
|
|
|
LIB_BEZIER_T,
|
|
|
|
LIB_PIN_T,
|
|
|
|
LIB_FIELD_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-01 20:03:14 +00:00
|
|
|
const KICAD_T movableSymbolAliasItems[] =
|
|
|
|
{
|
|
|
|
LIB_FIELD_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-25 09:28:20 +00:00
|
|
|
void EE_SELECTION_TOOL::setModifiersState( bool aShiftState, bool aCtrlState, bool aAltState )
|
|
|
|
{
|
|
|
|
// Set the configuration of m_additive, m_subtractive, m_exclusive_or
|
|
|
|
// from the state of modifier keys SHIFT, CTRL, ALT and the OS
|
|
|
|
|
|
|
|
// on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
|
2021-06-09 19:32:58 +00:00
|
|
|
// Due to the fact ALT key modifier cannot be used freely on Windows and Linux,
|
2021-03-25 09:28:20 +00:00
|
|
|
// actions are different on OSX and others OS
|
|
|
|
// Especially, ALT key cannot be used to force showing the full selection choice
|
|
|
|
// context menu (the menu is immediately closed on Windows )
|
|
|
|
//
|
|
|
|
// No modifier = select items and deselect previous selection
|
|
|
|
// ALT (on OSX) = skip heuristic and show full selection choice
|
|
|
|
// ALT (on others) = exclusive OR of selected items (inverse selection)
|
|
|
|
//
|
|
|
|
// CTRL/CMD (on OSX) = exclusive OR of selected items (inverse selection)
|
|
|
|
// CTRL (on others) = skip heuristic and show full selection choice
|
|
|
|
//
|
|
|
|
// SHIFT = add selected items to the current selection
|
|
|
|
//
|
|
|
|
// CTRL/CMD+SHIFT (on OSX) = remove selected items to the current selection
|
|
|
|
// CTRL+SHIFT (on others) = unused (can be used for a new action)
|
|
|
|
//
|
|
|
|
// CTRL/CMT+ALT (on OSX) = unused (can be used for a new action)
|
|
|
|
// CTRL+ALT (on others) = do nothing (same as no modifier)
|
|
|
|
//
|
|
|
|
// SHIFT+ALT (on OSX) = do nothing (same as no modifier)
|
|
|
|
// SHIFT+ALT (on others) = remove selected items to the current selection
|
|
|
|
|
|
|
|
#ifdef __WXOSX_MAC__
|
|
|
|
m_subtractive = aCtrlState && aShiftState && !aAltState;
|
|
|
|
m_additive = aShiftState && !aCtrlState && !aAltState;
|
|
|
|
m_exclusive_or = aCtrlState && !aShiftState && !aAltState;
|
|
|
|
m_skip_heuristics = aAltState && !aShiftState && !aCtrlState;
|
|
|
|
|
|
|
|
#else
|
|
|
|
m_subtractive = aShiftState && !aCtrlState && aAltState;
|
|
|
|
m_additive = aShiftState && !aCtrlState && !aAltState;
|
|
|
|
m_exclusive_or = !aShiftState && !aCtrlState && aAltState;
|
|
|
|
|
|
|
|
// Is the user requesting that the selection list include all possible
|
|
|
|
// items without removing less likely selection candidates
|
|
|
|
// Cannot use the Alt key on windows or the disambiguation context menu is immediately
|
|
|
|
// dismissed rendering it useless.
|
|
|
|
m_skip_heuristics = aCtrlState && !aShiftState && !aAltState;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-20 18:51:24 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
KIID lastRolloverItem = niluuid;
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
bool displayWireCursor = false;
|
2021-02-15 14:57:06 +00:00
|
|
|
bool displayBusCursor = false;
|
2021-02-17 19:43:07 +00:00
|
|
|
bool displayLineCursor = false;
|
2020-11-29 16:31:43 +00:00
|
|
|
KIID rolloverItem = lastRolloverItem;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
// on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
|
|
|
|
evt->Modifier( MD_ALT ) );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
|
|
|
|
|
|
|
|
MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Single click? Select single object
|
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
EE_COLLECTOR collector;
|
2020-10-02 20:18:07 +00:00
|
|
|
bool continueSelect = true;
|
2020-10-01 23:53:47 +00:00
|
|
|
|
|
|
|
// Collect items at the clicked location (doesn't select them yet)
|
2021-01-19 21:10:04 +00:00
|
|
|
if( CollectHits( collector, evt->Position()) )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( collector.GetCount() == 1 && !m_isSymbolEditor && !modifier_enabled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
// Check if we want to auto start wires
|
2020-12-03 15:10:23 +00:00
|
|
|
VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
|
|
|
|
LAYER_CONNECTABLE, nullptr );
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
2020-10-03 19:05:28 +00:00
|
|
|
&& collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2021-02-15 14:57:06 +00:00
|
|
|
OPT_TOOL_EVENT newEvt;
|
|
|
|
SCH_CONNECTION* connection = collector[0]->Connection();
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
|
2021-06-10 14:10:55 +00:00
|
|
|
|| collector[0]->Type() == SCH_SYMBOL_T )
|
2021-02-17 19:43:07 +00:00
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawWire.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( connection && connection->IsBus() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( collector[0]->Type() == SCH_LINE_T
|
|
|
|
&& static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
2021-02-17 19:43:07 +00:00
|
|
|
newEvt = EE_ACTIONS::drawLines.MakeEvent();
|
2021-02-15 14:57:06 +00:00
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2021-02-15 14:57:06 +00:00
|
|
|
auto* params = newEvt->Parameter<DRAW_SEGMENT_EVENT_PARAMS*>();
|
|
|
|
auto* newParams = new DRAW_SEGMENT_EVENT_PARAMS();
|
2020-10-02 20:18:07 +00:00
|
|
|
|
|
|
|
*newParams= *params;
|
|
|
|
newParams->quitOnDraw = true;
|
|
|
|
newEvt->SetParameter( newParams );
|
|
|
|
|
2021-01-29 22:07:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( true, snappedCursorPos );
|
2020-10-08 03:57:26 +00:00
|
|
|
newEvt->SetMousePosition( snappedCursorPos );
|
2021-01-29 22:07:49 +00:00
|
|
|
newEvt->SetHasPosition( true );
|
2021-02-21 12:45:50 +00:00
|
|
|
newEvt->SetForceImmediate( true );
|
2020-10-02 20:18:07 +00:00
|
|
|
m_toolMgr->ProcessEvent( *newEvt );
|
2021-01-29 22:07:49 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
continueSelect = false;
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( collector[0]->IsHypertext() )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
collector[0]->DoHypertextMenu( m_frame );
|
2020-10-05 10:54:37 +00:00
|
|
|
continueSelect = false;
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( continueSelect )
|
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
// If we didn't click on an anchor, we perform a normal select, pass in the
|
|
|
|
// items we previously collected
|
2020-10-05 10:54:37 +00:00
|
|
|
selectPoint( collector, nullptr, nullptr, m_additive, m_subtractive,
|
2020-10-02 20:18:07 +00:00
|
|
|
m_exclusive_or );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2020-11-23 19:46:17 +00:00
|
|
|
// right click? if there is any object - show the context menu
|
2019-04-21 23:45:34 +00:00
|
|
|
bool selectionCancelled = false;
|
|
|
|
|
2021-01-31 14:59:18 +00:00
|
|
|
if( m_selection.Empty() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-10-29 15:11:06 +00:00
|
|
|
ClearSelection();
|
2020-05-24 23:35:04 +00:00
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
|
|
|
|
&selectionCancelled );
|
2019-04-21 23:45:34 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
2021-01-31 14:59:18 +00:00
|
|
|
// If the cursor has moved off the bounding box of the selection by more than
|
|
|
|
// a grid square, check to see if there is another item available for selection
|
|
|
|
// under the cursor. If there is, the user likely meant to get the context menu
|
|
|
|
// for that item. If there is no new item, then keep the original selection and
|
|
|
|
// show the context menu for it.
|
|
|
|
else if( !m_selection.GetBoundingBox().Inflate(
|
|
|
|
grid.GetGrid().x, grid.GetGrid().y ).Contains(
|
|
|
|
(wxPoint) evt->Position() ) )
|
|
|
|
{
|
|
|
|
EE_SELECTION saved_selection = m_selection;
|
|
|
|
|
2021-04-05 17:51:48 +00:00
|
|
|
for( const auto& item : saved_selection )
|
2021-01-31 14:59:18 +00:00
|
|
|
RemoveItemFromSel( item, true );
|
|
|
|
|
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
|
|
|
|
&selectionCancelled );
|
|
|
|
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
2021-03-22 02:01:45 +00:00
|
|
|
for( const auto& item : saved_selection )
|
2021-01-31 14:59:18 +00:00
|
|
|
AddItemToSel( item, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( !selectionCancelled )
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
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 ) )
|
|
|
|
{
|
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-03-05 00:01:17 +00:00
|
|
|
// Is another tool already moving a new object? Don't allow a drag start
|
2021-05-30 21:04:07 +00:00
|
|
|
if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
|
2021-03-05 00:01:17 +00:00
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// drag with LMB? Select multiple objects (or at least draw a selection box) or
|
|
|
|
// drag them
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
if( modifier_enabled || drag_action == MOUSE_DRAG_ACTION::SELECT )
|
2021-01-11 11:48:51 +00:00
|
|
|
{
|
|
|
|
selectMultiple();
|
|
|
|
}
|
2021-01-11 15:46:41 +00:00
|
|
|
else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-23 17:40:29 +00:00
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-01 20:03:14 +00:00
|
|
|
if( m_isSymbolEditor )
|
|
|
|
{
|
|
|
|
if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
|
|
|
|
m_selection = RequestSelection( movableSymbolAliasItems );
|
|
|
|
else
|
|
|
|
m_selection = RequestSelection( movableSymbolItems );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-23 22:57:34 +00:00
|
|
|
m_selection = RequestSelection( movableSchematicItems );
|
2021-07-01 20:03:14 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Check if dragging has started within any of selected items bounding box
|
|
|
|
if( selectionContains( evt->Position() ) )
|
|
|
|
{
|
|
|
|
// Yes -> run the move tool and wait till it finishes
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2021-07-01 20:03:14 +00:00
|
|
|
m_toolMgr->InvokeTool( "eeschema.SymbolMoveTool" );
|
2020-04-23 22:57:34 +00:00
|
|
|
else
|
|
|
|
m_toolMgr->InvokeTool( "eeschema.InteractiveMove" );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
// No -> drag a selection box
|
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2020-11-23 19:46:17 +00:00
|
|
|
// context sub-menu selection? Handle unit selection or bus unfolding
|
2019-05-02 20:03:03 +00:00
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
2021-06-10 14:10:55 +00:00
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
|
2019-05-02 20:44:23 +00:00
|
|
|
int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
|
2019-05-02 20:03:03 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( symbol )
|
|
|
|
static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( symbol, unit );
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
2019-05-05 14:16:29 +00:00
|
|
|
else if( evt->GetCommandId().get() >= ID_POPUP_SCH_UNFOLD_BUS
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
|
|
|
{
|
|
|
|
wxString* net = new wxString( *evt->Parameter<wxString*>() );
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::unfoldBus, true, net );
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-05-06 20:55:35 +00:00
|
|
|
}
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
else if( evt->IsMotion() && !m_isSymbolEditor && m_frame->ToolStackIsEmpty() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-11-29 16:31:43 +00:00
|
|
|
rolloverItem = niluuid;
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
|
|
|
// We are checking if we should display a pencil when hovering over anchors
|
|
|
|
// for "auto starting" wires when clicked
|
2021-01-19 21:10:04 +00:00
|
|
|
if( CollectHits( collector, evt->Position()) )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
if( collector.GetCount() == 1 && !modifier_enabled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-12-03 15:10:23 +00:00
|
|
|
VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
|
|
|
|
LAYER_CONNECTABLE, nullptr );
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
2020-10-03 19:05:28 +00:00
|
|
|
&& collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2021-02-15 14:57:06 +00:00
|
|
|
SCH_CONNECTION* connection = collector[0]->Connection();
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
|
2021-06-10 14:10:55 +00:00
|
|
|
|| collector[0]->Type() == SCH_SYMBOL_T )
|
2021-02-17 19:43:07 +00:00
|
|
|
{
|
|
|
|
displayWireCursor = true;
|
|
|
|
}
|
|
|
|
else if( connection && connection->IsBus() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
|
|
|
displayBusCursor = true;
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( collector[0]->Type() == SCH_LINE_T
|
|
|
|
&& static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
|
2021-02-15 14:57:06 +00:00
|
|
|
{
|
2021-02-17 19:43:07 +00:00
|
|
|
displayLineCursor = true;
|
2021-02-15 14:57:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:07:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( true, snappedCursorPos );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( collector[0]->IsHypertext()
|
2020-11-18 12:02:52 +00:00
|
|
|
&& !collector[0]->IsSelected()
|
|
|
|
&& !m_additive && !m_subtractive && !m_exclusive_or )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
rolloverItem = collector[0]->m_Uuid;
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 22:07:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
getViewControls()->ForceCursorPosition( false );
|
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-05-28 14:39:14 +00:00
|
|
|
else
|
2020-11-23 19:46:17 +00:00
|
|
|
{
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-23 19:46:17 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( rolloverItem != lastRolloverItem )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_frame->GetItem( lastRolloverItem );
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
item->ClearFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = niluuid;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item = m_frame->GetItem( rolloverItem );
|
|
|
|
|
2020-10-12 09:32:51 +00:00
|
|
|
if( item )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
item->SetFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = rolloverItem;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
if( displayWireCursor )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_WIRE_ADD;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-02-15 14:57:06 +00:00
|
|
|
else if( displayBusCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_BUS;
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( displayLineCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_GRAPHIC;
|
|
|
|
}
|
2020-10-02 20:18:07 +00:00
|
|
|
else if( rolloverItem != niluuid )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::HAND;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-01-11 11:48:51 +00:00
|
|
|
else if( !m_selection.Empty()
|
2021-01-11 15:46:41 +00:00
|
|
|
&& drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
|
2021-01-11 11:48:51 +00:00
|
|
|
&& evt->HasPosition()
|
|
|
|
&& selectionContains( evt->Position() ) ) //move/drag option prediction
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::MOVING;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
else
|
2020-10-08 00:50:28 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::ARROW;
|
2020-10-08 00:50:28 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 15:23:05 +00:00
|
|
|
void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
2020-12-30 00:51:34 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() && !m_multiple )
|
2020-11-18 15:23:05 +00:00
|
|
|
{
|
|
|
|
wxMouseState keyboardState = wxGetMouseState();
|
|
|
|
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
|
|
|
|
keyboardState.AltDown() );
|
2020-11-18 15:23:05 +00:00
|
|
|
|
|
|
|
if( m_additive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD );
|
|
|
|
else if( m_subtractive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT );
|
|
|
|
else if( m_exclusive_or )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( m_nonModifiedCursor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::GetSelection()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
return m_selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
2020-10-02 20:18:07 +00:00
|
|
|
const KICAD_T* aFilterList )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
aCollector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-05-09 03:11:36 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
aCollector.Collect( symbol->GetDrawItems(), aFilterList, (wxPoint) aWhere, m_unit,
|
2020-10-02 20:18:07 +00:00
|
|
|
m_convert );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
aCollector.Collect( m_frame->GetScreen(), aFilterList, (wxPoint) aWhere, m_unit,
|
|
|
|
m_convert );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
return aCollector.GetCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere,
|
|
|
|
bool aCheckLocked )
|
|
|
|
{
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
if( !Selectable( collector[i] ) )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( aCheckLocked && collector[i]->IsLocked() )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-11 20:17:05 +00:00
|
|
|
|
|
|
|
// SelectPoint, unlike other selection routines, can select line ends
|
2020-10-02 20:18:07 +00:00
|
|
|
if( collector[i]->Type() == SCH_LINE_T )
|
2019-06-11 20:17:05 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) collector[i];
|
2019-06-11 20:17:05 +00:00
|
|
|
line->ClearFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
2019-06-11 20:17:05 +00:00
|
|
|
line->SetFlags( STARTPOINT );
|
2020-10-02 20:18:07 +00:00
|
|
|
else if( HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
2019-06-11 20:17:05 +00:00
|
|
|
line->SetFlags( ENDPOINT );
|
|
|
|
else
|
|
|
|
line->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
|
2020-10-02 20:18:07 +00:00
|
|
|
if( collector.GetCount() > 1 && !m_skip_heuristics )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
GuessSelectionCandidates( collector, aWhere );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem,
|
2020-10-02 20:18:07 +00:00
|
|
|
bool* aSelectionCancelledFlag, bool aAdd, bool aSubtract,
|
|
|
|
bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// If still more than one item we're going to have to ask the user.
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 1 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-25 20:25:44 +00:00
|
|
|
// Must call selectionMenu via RunAction() to avoid event-loop contention
|
2020-10-01 23:53:47 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &aCollector );
|
2019-04-25 20:25:44 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.m_MenuCancelled )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aSelectionCancelledFlag )
|
|
|
|
*aSelectionCancelledFlag = true;
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( !aAdd && !aSubtract && !aExclusiveOr )
|
|
|
|
ClearSelection();
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 0 )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
for( int i = 0; i < aCollector.GetCount(); ++i )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aSubtract || ( aExclusiveOr && aCollector[i]->IsSelected() ) )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
unselect( aCollector[i] );
|
2020-05-27 15:18:12 +00:00
|
|
|
anySubtracted = true;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
select( aCollector[i] );
|
2020-05-27 15:18:12 +00:00
|
|
|
anyAdded = true;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
if( anyAdded )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aItem && aCollector.GetCount() == 1 )
|
|
|
|
*aItem = aCollector[0];
|
2020-05-24 23:35:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( anySubtracted )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
|
2020-10-05 10:54:37 +00:00
|
|
|
EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
|
|
|
|
bool aCheckLocked, bool aAdd, bool aSubtract,
|
|
|
|
bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
if( !CollectHits( collector, aWhere, aFilterList ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
return false;
|
2020-10-02 20:18:07 +00:00
|
|
|
|
|
|
|
narrowSelection( collector, aWhere, aCheckLocked );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
return selectPoint( collector, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
// hold all visible items
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
|
|
|
|
|
|
|
|
// Filter the view items based on the selection box
|
|
|
|
BOX2I selectionBox;
|
|
|
|
|
|
|
|
selectionBox.SetMaximum();
|
|
|
|
view->Query( selectionBox, selectedItems ); // Get the list of selected items
|
|
|
|
|
|
|
|
// Sheet pins aren't in the view; add them by hand
|
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
int layer = pair.second;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
|
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
|
2020-08-20 23:05:21 +00:00
|
|
|
{
|
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
|
|
|
|
{
|
|
|
|
if( Selectable( item ) )
|
|
|
|
select( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_multiple = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 19:11:26 +00:00
|
|
|
void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
// There are certain parent/child and enclosure combinations that can be handled
|
2019-05-16 23:48:39 +00:00
|
|
|
// automatically.
|
|
|
|
|
2019-06-28 19:11:26 +00:00
|
|
|
// Prefer exact hits to sloppy ones
|
2019-06-26 18:43:37 +00:00
|
|
|
int exactHits = 0;
|
|
|
|
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-05-16 23:48:39 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
|
2019-06-26 18:43:37 +00:00
|
|
|
if( item->HitTest( (wxPoint) aPos, 0 ) )
|
|
|
|
exactHits++;
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 18:43:37 +00:00
|
|
|
if( exactHits > 0 && exactHits < collector.GetCount() )
|
|
|
|
{
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
|
|
|
|
if( !item->HitTest( (wxPoint) aPos, 0 ) )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( item );
|
2019-06-26 18:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prefer a non-sheet to a sheet
|
2019-05-16 23:48:39 +00:00
|
|
|
for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-16 23:48:39 +00:00
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
|
|
|
|
|
2019-06-26 18:43:37 +00:00
|
|
|
if( item->Type() != SCH_SHEET_T && other->Type() == SCH_SHEET_T )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( other );
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:41:51 +00:00
|
|
|
// Prefer a symbol to a pin or the opposite, when both a symbol and a pin are selected
|
|
|
|
// We need to be able to select only a pin:
|
|
|
|
// - to display its characteristics (especially if an ERC is attached to the pin)
|
|
|
|
// - for cross probing, to select the corresponding pad.
|
|
|
|
// Note also the case happens only in schematic editor. In symbol editor, the symbol
|
|
|
|
// itself is never selected
|
2019-05-16 23:48:39 +00:00
|
|
|
for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
|
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
SCH_ITEM* item = collector[i];
|
|
|
|
SCH_ITEM* other = collector[( i + 1 ) % 2];
|
2019-05-16 23:48:39 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T && other->Type() == SCH_PIN_T )
|
2019-12-19 11:41:51 +00:00
|
|
|
{
|
2020-11-23 19:46:17 +00:00
|
|
|
// Make sure we aren't clicking on the pin anchor itself, only the rest of the
|
|
|
|
// pin should select the symbol with this setting
|
2020-10-01 23:53:47 +00:00
|
|
|
// To avoid conflict with the auto-start wires option
|
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2020-12-03 15:10:23 +00:00
|
|
|
wxPoint cursorPos = wxPoint( grid.BestSnapAnchor( aPos, LAYER_CONNECTABLE,
|
|
|
|
nullptr ) );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-12-03 15:10:23 +00:00
|
|
|
if( !m_isSymbolEditor
|
|
|
|
&& m_frame->eeconfig()->m_Selection.select_pin_selects_symbol
|
|
|
|
&& !other->IsPointClickableAnchor( cursorPos ) )
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( other );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
2019-12-19 11:41:51 +00:00
|
|
|
else
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( item );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
2019-12-19 11:41:51 +00:00
|
|
|
}
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 17:13:38 +00:00
|
|
|
// Prefer things that are generally smaller than a symbol to a symbol
|
|
|
|
const std::set<KICAD_T> preferred =
|
|
|
|
{
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_MARKER_T
|
|
|
|
};
|
|
|
|
|
2019-05-16 23:48:39 +00:00
|
|
|
for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( preferred.count( item->Type() ) && other->Type() == SCH_SYMBOL_T )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( other );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2019-06-11 20:17:05 +00:00
|
|
|
|
|
|
|
// No need for multiple wires at a single point; if there's a junction select that;
|
|
|
|
// otherwise any of the wires will do
|
|
|
|
bool junction = false;
|
|
|
|
bool wiresOnly = true;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : collector )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
junction = true;
|
|
|
|
else if( item->Type() != SCH_LINE_T )
|
|
|
|
wiresOnly = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wiresOnly )
|
|
|
|
{
|
|
|
|
for( int j = collector.GetCount() - 1; j >= 0; --j )
|
|
|
|
{
|
|
|
|
if( junction && collector[ j ]->Type() != SCH_JUNCTION_T )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( j );
|
2019-06-11 20:17:05 +00:00
|
|
|
else if( !junction && j > 0 )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( j );
|
2019-06-11 20:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-19 14:55:05 +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.
|
|
|
|
EDA_ITEM* closest = nullptr;
|
|
|
|
int closestDist = INT_MAX;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : collector )
|
|
|
|
{
|
2021-08-13 02:04:24 +00:00
|
|
|
int dist = EuclideanNorm( item->GetBoundingBox().GetCenter() - wxPoint( aPos ) );
|
|
|
|
|
|
|
|
// For wires, if we hit one of the endpoints, consider that perfect
|
|
|
|
if( item->Type() == SCH_LINE_T && ( item->GetFlags() & ( STARTPOINT | ENDPOINT ) ) )
|
|
|
|
dist = 0;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
|
|
|
if( dist < closestDist )
|
|
|
|
{
|
|
|
|
closestDist = dist;
|
|
|
|
closest = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
|
2020-09-19 14:55:05 +00:00
|
|
|
{
|
2020-09-30 02:28:23 +00:00
|
|
|
EDA_RECT tightBox = closest->GetBoundingBox();
|
|
|
|
tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[i];
|
|
|
|
|
|
|
|
if( item == closest )
|
|
|
|
continue;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
if( !item->HitTest( tightBox, true ) )
|
|
|
|
collector.Transfer( item );
|
|
|
|
}
|
2020-09-19 14:55:05 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] )
|
2019-04-23 12:51:48 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
|
|
|
|
|
|
|
|
ClearSelection();
|
|
|
|
SelectPoint( cursorPos, aFilterList );
|
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
}
|
|
|
|
else // Trim an existing selection by aFilterList
|
2019-04-23 17:12:10 +00:00
|
|
|
{
|
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 );
|
2019-04-23 17:12:10 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
if( !item->IsType( aFilterList ) )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
|
|
|
unselect( item );
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
}
|
2019-04-23 17:12:10 +00:00
|
|
|
}
|
2019-05-20 15:42:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
updateReferencePoint();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectMultiple()
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
bool cancelled = false; // Was the tool canceled while it was running?
|
2019-04-23 17:40:29 +00:00
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
KIGFX::PREVIEW::SELECTION_AREA area;
|
|
|
|
view->Add( &area );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-09 01:24:26 +00:00
|
|
|
int width = area.GetEnd().x - area.GetOrigin().x;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
bool windowSelection = width >= 0;
|
|
|
|
|
|
|
|
if( view->IsMirroredX() )
|
|
|
|
windowSelection = !windowSelection;
|
|
|
|
|
2021-03-07 11:58:11 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( windowSelection ? KICURSOR::SELECT_WINDOW
|
|
|
|
: KICURSOR::SELECT_LASSO );
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
if( !m_additive && !m_subtractive && !m_exclusive_or )
|
|
|
|
ClearSelection();
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Start drawing a selection box
|
|
|
|
area.SetOrigin( evt->DragOrigin() );
|
|
|
|
area.SetEnd( evt->Position() );
|
|
|
|
area.SetAdditive( m_additive );
|
|
|
|
area.SetSubtractive( m_subtractive );
|
2019-07-09 19:50:40 +00:00
|
|
|
area.SetExclusiveOr( m_exclusive_or );
|
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 );
|
|
|
|
|
|
|
|
// Mark items within the selection box as selected
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
2021-02-01 16:39:26 +00:00
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> children;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
// Filter the view items based on the selection box
|
|
|
|
BOX2I selectionBox = area.ViewBBox();
|
|
|
|
view->Query( selectionBox, selectedItems ); // Get the list of selected items
|
|
|
|
|
2021-02-01 16:39:26 +00:00
|
|
|
// Some children aren't in the view; add them by hand.
|
|
|
|
// DO NOT add them directly to selectedItems. If we add enough to cause the vector
|
|
|
|
// to grow it will re-allocate and invalidate the top-level for-loop iterator.
|
2019-09-03 16:24:24 +00:00
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2019-09-03 16:24:24 +00:00
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
|
2019-08-29 14:59:36 +00:00
|
|
|
|
2019-09-03 16:24:24 +00:00
|
|
|
if( sheet )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2019-08-29 14:59:36 +00:00
|
|
|
int layer = pair.second;
|
2019-08-27 20:08:09 +00:00
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
2021-02-01 16:39:26 +00:00
|
|
|
children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pair.first );
|
2021-02-01 16:39:26 +00:00
|
|
|
|
|
|
|
if( symbol )
|
|
|
|
{
|
|
|
|
int layer = pair.second;
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
|
|
|
children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &field, layer ) );
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
2021-03-07 14:32:49 +00:00
|
|
|
|
|
|
|
SCH_GLOBALLABEL* gLabel = dynamic_cast<SCH_GLOBALLABEL*>( pair.first );
|
|
|
|
|
|
|
|
if( gLabel )
|
|
|
|
{
|
|
|
|
int layer = pair.second;
|
|
|
|
SCH_FIELD* intersheetRef = gLabel->GetIntersheetRefs();
|
|
|
|
|
|
|
|
children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( intersheetRef, layer ) );
|
|
|
|
}
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 16:39:26 +00:00
|
|
|
selectedItems.insert( selectedItems.end(), children.begin(), children.end() );
|
2019-09-04 10:46:18 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
int height = area.GetEnd().y - area.GetOrigin().y;
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
// Construct an EDA_RECT to determine EDA_ITEM selection
|
2019-07-09 19:50:40 +00:00
|
|
|
EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
selectionRect.Normalize();
|
|
|
|
|
2019-09-03 16:24:24 +00:00
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2019-09-03 16:24:24 +00:00
|
|
|
EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
if( item && Selectable( item ) && item->HitTest( selectionRect, windowSelection ) )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
|
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
unselect( item );
|
2019-07-09 19:50:40 +00:00
|
|
|
anySubtracted = true;
|
|
|
|
}
|
2019-05-05 10:33:34 +00:00
|
|
|
else
|
2019-06-18 19:22:29 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
select( item );
|
2019-06-18 19:22:29 +00:00
|
|
|
item->SetFlags( STARTPOINT | ENDPOINT );
|
2019-07-09 19:50:40 +00:00
|
|
|
anyAdded = true;
|
2019-06-18 19:22:29 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Inform other potentially interested tools
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anyAdded )
|
2019-04-23 17:40:29 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anySubtracted )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
break; // Stop waiting for events
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
// Stop drawing the selection box
|
|
|
|
view->Remove( &area );
|
|
|
|
m_multiple = false; // Multiple selection mode is inactive
|
|
|
|
|
|
|
|
if( !cancelled )
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
static KICAD_T nodeTypes[] =
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL_LOCATE_POWER_T,
|
2020-04-10 13:08:14 +00:00
|
|
|
SCH_PIN_T,
|
2019-04-30 13:54:32 +00:00
|
|
|
SCH_LINE_LOCATE_WIRE_T,
|
|
|
|
SCH_LINE_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_JUNCTION_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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-01-29 22:28:26 +00:00
|
|
|
int thresholdMax = KiROUND(
|
|
|
|
m_toolMgr->GetView()->GetGAL()->GetGridSize().EuclideanNorm() );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
|
|
|
for( int threshold : { 0, thresholdMax/2, thresholdMax } )
|
|
|
|
{
|
|
|
|
collector.m_Threshold = threshold;
|
2019-06-25 23:39:58 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), nodeTypes, (wxPoint) aPosition );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
|
|
|
if( collector.GetCount() > 0 )
|
|
|
|
break;
|
|
|
|
}
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
return collector.GetCount() ? collector[ 0 ] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2021-05-09 17:14:41 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
SelectPoint( cursorPos, nodeTypes );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2020-04-02 17:03:53 +00:00
|
|
|
static KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
|
2019-04-30 17:02:38 +00:00
|
|
|
|
2020-04-02 17:03:53 +00:00
|
|
|
RequestSelection( wiresAndBuses );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2019-05-01 21:50:11 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) m_selection.Front();
|
2019-04-30 13:54:32 +00:00
|
|
|
EDA_ITEMS items;
|
|
|
|
|
|
|
|
m_frame->GetScreen()->ClearDrawingState();
|
2020-12-14 21:11:33 +00:00
|
|
|
std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( SCH_ITEM* item : conns )
|
2019-06-25 23:39:58 +00:00
|
|
|
select( item );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2019-05-03 08:48:53 +00:00
|
|
|
if( m_selection.GetSize() > 1 )
|
2019-04-30 13:54:32 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::AddItemToSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-01 20:15:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
|
2019-05-01 20:15:51 +00:00
|
|
|
{
|
|
|
|
if( aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
select( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
2019-05-01 20:15:51 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::AddItemsToSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-03 22:46:44 +00:00
|
|
|
AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-03 22:46:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 22:46:44 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
if( aList )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-03 22:46:44 +00:00
|
|
|
for( EDA_ITEM* item : *aList )
|
|
|
|
select( item );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 22:46:44 +00:00
|
|
|
// Inform other potentially interested tools
|
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::RemoveItemFromSel( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-01 20:15:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-01 20:15:51 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
|
2019-05-01 20:15:51 +00:00
|
|
|
{
|
|
|
|
if( aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-01 20:15:51 +00:00
|
|
|
unselect( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
2019-05-01 20:15:51 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::RemoveItemsFromSel( const TOOL_EVENT& aEvent )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2019-05-03 22:46:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
|
2019-05-03 22:46:44 +00:00
|
|
|
{
|
|
|
|
if( aList )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : *aList )
|
|
|
|
unselect( item );
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 12:51:32 +00:00
|
|
|
void EE_SELECTION_TOOL::RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode )
|
|
|
|
{
|
|
|
|
EDA_ITEMS removeItems;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
|
|
|
if( alg::contains( *aList, item->m_Uuid ) )
|
|
|
|
removeItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveItemsFromSel( &removeItems, aQuietMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-18 13:11:34 +00:00
|
|
|
void EE_SELECTION_TOOL::BrightenItem( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
highlight( aItem, BRIGHTENED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void EE_SELECTION_TOOL::UnbrightenItem( EDA_ITEM* aItem )
|
2019-05-18 13:11:34 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
unhighlight( aItem, BRIGHTENED );
|
2019-05-18 13:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
void EE_SELECTION_TOOL::RebuildSelection()
|
|
|
|
{
|
|
|
|
m_selection.Clear();
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2019-05-11 10:06:28 +00:00
|
|
|
|
2020-03-06 12:05:21 +00:00
|
|
|
for( LIB_ITEM& item : start->GetDrawItems() )
|
2020-01-04 23:05:57 +00:00
|
|
|
{
|
|
|
|
if( item.IsSelected() )
|
|
|
|
select( static_cast<EDA_ITEM*>( &item ) );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-11 10:06:28 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
|
2019-10-27 17:47:26 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// If the field and symbol are selected, only use the symbol
|
2020-02-05 04:48:33 +00:00
|
|
|
if( item->IsSelected() )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
select( item );
|
|
|
|
}
|
2020-02-05 04:48:33 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->IsSelected() )
|
|
|
|
select( aChild );
|
|
|
|
} );
|
2020-02-05 04:48:33 +00:00
|
|
|
}
|
2019-10-27 17:47:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
|
|
|
|
updateReferencePoint();
|
2019-06-29 18:57:23 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-05-11 10:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-10 19:22:26 +00:00
|
|
|
EE_COLLECTOR* collector = aEvent.Parameter<EE_COLLECTOR*>();
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2019-04-25 20:25:44 +00:00
|
|
|
if( !doSelectionMenu( collector ) )
|
|
|
|
collector->m_MenuCancelled = true;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
bool EE_SELECTION_TOOL::doSelectionMenu( EE_COLLECTOR* aCollector )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-14 11:14:00 +00:00
|
|
|
EDA_ITEM* current = nullptr;
|
2020-05-24 23:35:04 +00:00
|
|
|
bool selectAll = false;
|
2020-07-07 04:51:12 +00:00
|
|
|
bool expandSelection = false;
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
do
|
2019-04-23 12:51:48 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
/// The user has requested the full, non-limited list of selection items
|
|
|
|
if( expandSelection )
|
|
|
|
aCollector->Combine();
|
2020-05-24 23:35:04 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
expandSelection = false;
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
int limit = std::min( 9, aCollector->GetCount() );
|
|
|
|
ACTION_MENU menu( true );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
for( int i = 0; i < limit; ++i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
wxString text;
|
|
|
|
EDA_ITEM* item = ( *aCollector )[i];
|
|
|
|
text = item->GetSelectMenuText( m_frame->GetUserUnits() );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
|
|
|
|
menu.Add( menuText, i + 1, item->GetMenuImage() );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.AppendSeparator();
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
|
2020-05-24 23:35:04 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
if( !expandSelection && aCollector->HasAdditionalItems() )
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
|
2020-07-07 04:51:12 +00:00
|
|
|
|
|
|
|
if( aCollector->m_MenuTitle.Length() )
|
|
|
|
{
|
|
|
|
menu.SetTitle( aCollector->m_MenuTitle );
|
2021-03-08 02:59:07 +00:00
|
|
|
menu.SetIcon( BITMAPS::info );
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.DisplayTitle( true );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
menu.DisplayTitle( false );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
SetContextMenu( &menu, CMENU_NOW );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->Action() == TA_CHOICE_MENU_UPDATE )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
if( selectAll )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
unhighlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
}
|
|
|
|
else if( current )
|
|
|
|
{
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = *evt->GetCommandId();
|
|
|
|
|
|
|
|
// User has pointed an item, so show it in a different way
|
|
|
|
if( id > 0 && id <= limit )
|
|
|
|
{
|
|
|
|
current = ( *aCollector )[id - 1];
|
|
|
|
highlight( current, BRIGHTENED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User has pointed on the "Select All" option
|
|
|
|
if( id == limit + 1 )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
highlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
selectAll = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
if( selectAll )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < aCollector->GetCount(); ++i )
|
|
|
|
unhighlight( ( *aCollector )[i], BRIGHTENED );
|
|
|
|
}
|
|
|
|
else if( current )
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
|
|
|
|
OPT<int> id = evt->GetCommandId();
|
|
|
|
|
|
|
|
// User has selected the "Select All" option
|
|
|
|
if( id == limit + 1 )
|
|
|
|
{
|
|
|
|
selectAll = true;
|
|
|
|
current = nullptr;
|
|
|
|
}
|
2021-02-24 10:55:35 +00:00
|
|
|
else if( id == limit + 2 )
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
current = nullptr;
|
|
|
|
expandSelection = true;
|
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
// User has selected an item, so this one will be returned
|
|
|
|
else if( id && ( *id > 0 ) && ( *id <= limit ) )
|
|
|
|
{
|
|
|
|
selectAll = false;
|
|
|
|
current = ( *aCollector )[*id - 1];
|
|
|
|
}
|
2021-02-24 10:55:35 +00:00
|
|
|
// User has cancelled the menu (either by <esc> or clicking out of it)
|
2020-07-07 04:51:12 +00:00
|
|
|
else
|
|
|
|
{
|
2021-02-24 10:55:35 +00:00
|
|
|
selectAll = false;
|
|
|
|
current = nullptr;
|
2020-07-07 04:51:12 +00:00
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-07-07 04:51:12 +00:00
|
|
|
break;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-07-07 04:51:12 +00:00
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-07-07 04:51:12 +00:00
|
|
|
} while( expandSelection );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
if( selectAll )
|
|
|
|
return true;
|
|
|
|
else if( current )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
aCollector->Empty();
|
|
|
|
aCollector->Append( current );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-01 04:31:19 +00:00
|
|
|
bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, 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:
|
2019-12-19 08:11:34 +00:00
|
|
|
if( !static_cast<const SCH_PIN*>( aItem )->IsVisible() && !m_frame->GetShowAllPins() )
|
2019-04-21 23:45:34 +00:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
|
2019-04-21 23:45:34 +00:00
|
|
|
return false;
|
|
|
|
|
2020-06-01 13:13:32 +00:00
|
|
|
case LIB_FIELD_T: // LIB_FIELD object can always be edited.
|
2019-12-12 15:44:53 +00:00
|
|
|
break;
|
|
|
|
|
2019-08-15 07:09:52 +00:00
|
|
|
case LIB_ARC_T:
|
|
|
|
case LIB_CIRCLE_T:
|
|
|
|
case LIB_TEXT_T:
|
|
|
|
case LIB_RECTANGLE_T:
|
|
|
|
case LIB_POLYLINE_T:
|
|
|
|
case LIB_BEZIER_T:
|
2019-05-08 18:56:03 +00:00
|
|
|
case LIB_PIN_T:
|
|
|
|
{
|
2020-11-23 19:46:17 +00:00
|
|
|
if( symEditFrame )
|
2019-12-12 16:42:11 +00:00
|
|
|
{
|
|
|
|
LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
if( lib_item->GetUnit() && lib_item->GetUnit() != symEditFrame->GetUnit() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
if( lib_item->GetConvert() && lib_item->GetConvert() != symEditFrame->GetConvert() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
case SCH_MARKER_T: // Always selectable
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default: // Suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void EE_SELECTION_TOOL::ClearSelection()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( m_selection.GetSize() )
|
2019-05-05 10:33:34 +00:00
|
|
|
unhighlight( (EDA_ITEM*) m_selection.Front(), SELECTED, &m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
getView()->Update( &m_selection );
|
|
|
|
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::select( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
highlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::unselect( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
unhighlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
KICAD_T itemType = aItem->Type();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( aMode == SELECTED )
|
|
|
|
aItem->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aItem->SetBrightened();
|
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Add( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Highlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2020-11-17 16:02:47 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
aChild->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
2021-01-15 12:52:11 +00:00
|
|
|
aChild->SetBrightened();
|
2020-11-17 16:02:47 +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 )
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->Update( aItem->GetParent() );
|
|
|
|
else
|
|
|
|
getView()->Update( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
KICAD_T itemType = aItem->Type();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( aMode == SELECTED )
|
|
|
|
aItem->ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aItem->ClearBrightened();
|
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Remove( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Unhighlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2020-11-17 16:02:47 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
aChild->ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aChild->ClearBrightened();
|
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
|
2019-04-23 17:40:29 +00:00
|
|
|
getView()->Update( aItem->GetParent() );
|
|
|
|
else
|
|
|
|
getView()->Update( aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
const unsigned GRIP_MARGIN = 20;
|
|
|
|
VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
|
|
|
|
|
|
|
|
// Check if the point is located within any of the currently selected items bounding boxes
|
2020-12-14 21:11:33 +00:00
|
|
|
for( EDA_ITEM* item : m_selection )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
BOX2I itemBox = item->ViewBBox();
|
|
|
|
itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
|
|
|
|
|
|
|
|
if( itemBox.Contains( aPoint ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::setTransitions()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::Main, EE_ACTIONS::selectionActivate.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectNode, EE_ACTIONS::selectNode.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectConnection, EE_ACTIONS::selectConnection.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::ClearSelection, EE_ACTIONS::clearSelection.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::AddItemToSel, EE_ACTIONS::addItemToSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::AddItemsToSel, EE_ACTIONS::addItemsToSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::RemoveItemFromSel, EE_ACTIONS::removeItemFromSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::RemoveItemsFromSel, EE_ACTIONS::removeItemsFromSel.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectionMenu, EE_ACTIONS::selectionMenu.MakeEvent() );
|
2020-08-20 23:05:21 +00:00
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectAll, EE_ACTIONS::selectAll.MakeEvent() );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:34:58 +00:00
|
|
|
|