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
|
2019-04-15 14:34:58 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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-05-10 17:19:48 +00:00
|
|
|
#include <ee_actions.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <core/typeinfo.h>
|
2019-05-10 19:57:24 +00:00
|
|
|
#include <sch_item.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_selection_tool.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <sch_base_frame.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2019-05-06 02:32:01 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2019-12-19 14:05:46 +00:00
|
|
|
#include <lib_view_frame.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2019-04-27 23:50:35 +00:00
|
|
|
#include <sch_field.h>
|
2019-06-11 20:17:05 +00:00
|
|
|
#include <sch_line.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view_group.h>
|
2019-04-23 17:40:29 +00:00
|
|
|
#include <preview_items/selection_area.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2019-05-10 19:22:26 +00:00
|
|
|
#include <ee_collectors.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <painter.h>
|
|
|
|
#include <eeschema_id.h>
|
2019-04-23 12:51:48 +00:00
|
|
|
#include <menus_helpers.h>
|
2019-04-15 14:34:58 +00:00
|
|
|
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::Empty = [] (const SELECTION& aSelection )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
return aSelection.Empty();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::Idle = [] (const SELECTION& aSelection )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::IdleSelection = [] (const SELECTION& aSelection )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = [] (const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = dynamic_cast<SCH_COMPONENT*>( aSel.Front() );
|
|
|
|
|
|
|
|
if( comp )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
return !comp->GetPartRef() || !comp->GetPartRef()->IsPower();
|
2019-05-02 10:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleDeMorganSymbol = [] ( const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = dynamic_cast<SCH_COMPONENT*>( aSel.Front() );
|
|
|
|
|
|
|
|
if( comp )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
return comp->GetPartRef() && comp->GetPartRef()->HasConversion();
|
2019-05-02 10:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleMultiUnitSymbol = [] ( const SELECTION& aSel )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = dynamic_cast<SCH_COMPONENT*>( aSel.Front() );
|
|
|
|
|
|
|
|
if( comp )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
return comp->GetPartRef() && comp->GetPartRef()->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 ),
|
2019-05-06 02:32:01 +00:00
|
|
|
m_isLibEdit( false ),
|
2019-05-25 08:09:26 +00:00
|
|
|
m_isLibView( 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
using E_C = EE_CONDITIONS;
|
2019-04-21 23:45:34 +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>();
|
|
|
|
|
2019-05-25 08:09:26 +00:00
|
|
|
LIB_VIEW_FRAME* libViewFrame = dynamic_cast<LIB_VIEW_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
LIB_EDIT_FRAME* libEditFrame = dynamic_cast<LIB_EDIT_FRAME*>( m_frame );
|
|
|
|
|
|
|
|
if( libEditFrame )
|
|
|
|
{
|
|
|
|
m_isLibEdit = true;
|
|
|
|
m_unit = libEditFrame->GetUnit();
|
|
|
|
m_convert = libEditFrame->GetConvert();
|
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
|
|
|
m_isLibView = libViewFrame != nullptr;
|
|
|
|
|
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 };
|
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 );
|
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
|
2019-05-16 22:50:54 +00:00
|
|
|
auto schEditCondition = [this] ( const SELECTION& aSel ) {
|
2019-05-25 08:09:26 +00:00
|
|
|
return !m_isLibEdit && !m_isLibView;
|
2019-05-08 18:56:03 +00:00
|
|
|
};
|
2019-05-13 20:42:40 +00:00
|
|
|
auto belowRootSheetCondition = [this] ( const SELECTION& aSel ) {
|
2019-05-25 08:09:26 +00:00
|
|
|
return !m_isLibEdit && !m_isLibView && g_CurrentSheet->Last() != g_RootSheet;
|
2019-05-03 22:48:24 +00:00
|
|
|
};
|
2019-05-16 22:50:54 +00:00
|
|
|
auto havePartCondition = [ this ] ( const SELECTION& sel ) {
|
|
|
|
return m_isLibEdit && ( (LIB_EDIT_FRAME*) m_frame )->GetCurPart();
|
|
|
|
};
|
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 );
|
2019-06-16 13:42:40 +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 );
|
2019-06-16 13:42:40 +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 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::importSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2019-05-16 22:50:54 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::symbolProperties, havePartCondition && EE_CONDITIONS::Empty, 400 );
|
|
|
|
menu.AddItem( EE_ACTIONS::pinTable, havePartCondition && 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
|
|
|
|
|
|
|
LIB_EDIT_FRAME* libEditFrame = dynamic_cast<LIB_EDIT_FRAME*>( m_frame );
|
2019-05-25 08:09:26 +00:00
|
|
|
LIB_VIEW_FRAME* libViewFrame = dynamic_cast<LIB_VIEW_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
|
|
|
if( libEditFrame )
|
|
|
|
{
|
|
|
|
m_isLibEdit = true;
|
|
|
|
m_unit = libEditFrame->GetUnit();
|
|
|
|
m_convert = libEditFrame->GetConvert();
|
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
|
|
|
m_isLibView = libViewFrame != 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-05-20 18:51:24 +00:00
|
|
|
const KICAD_T movableItems[] =
|
|
|
|
{
|
|
|
|
SCH_MARKER_T,
|
|
|
|
SCH_JUNCTION_T,
|
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_BITMAP_T,
|
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_FIELD_T,
|
|
|
|
SCH_COMPONENT_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
EOT
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
m_additive = m_subtractive = m_exclusive_or = false;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
|
|
|
|
m_subtractive = true;
|
|
|
|
else if( evt->Modifier( MD_SHIFT ) )
|
|
|
|
m_additive = true;
|
|
|
|
else if( evt->Modifier( MD_CTRL ) )
|
|
|
|
m_exclusive_or = true;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Is the user requesting that the selection list include all possible
|
|
|
|
// items without removing less likely selection candidates
|
|
|
|
m_skip_heuristics = !!evt->Modifier( MD_ALT );
|
|
|
|
|
|
|
|
// Single click? Select single object
|
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, false,
|
|
|
|
m_additive, m_subtractive, m_exclusive_or );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// right click? if there is any object - show the context menu
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
bool selectionCancelled = false;
|
|
|
|
|
2019-10-29 15:11:06 +00:00
|
|
|
if( m_selection.Empty() ||
|
|
|
|
!m_selection.GetBoundingBox().Contains( wxPoint( evt->Position() ) ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-10-29 15:11:06 +00:00
|
|
|
ClearSelection();
|
2019-05-10 19:22:26 +00:00
|
|
|
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, &selectionCancelled );
|
2019-04-21 23:45:34 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !selectionCancelled )
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// double click? Display the properties window
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
SelectPoint( evt->Position());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
|
|
|
|
else if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2019-08-15 11:52:38 +00:00
|
|
|
if( m_additive || m_subtractive || m_exclusive_or || m_frame->GetDragSelects() )
|
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
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
// selection is empty? try to start dragging the item under the point where drag
|
|
|
|
// started
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
m_selection = RequestSelection( movableItems );
|
|
|
|
|
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
|
2019-05-20 18:51:24 +00:00
|
|
|
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-05-05 14:16:29 +00:00
|
|
|
// context sub-menu selection? Handle unit selection or bus unfolding
|
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
|
|
|
{
|
|
|
|
if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
|
|
|
|
&& evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = dynamic_cast<SCH_COMPONENT*>( 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
|
|
|
|
|
|
|
if( component )
|
2019-05-05 10:33:34 +00:00
|
|
|
static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( component, 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
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-05-06 20:55:35 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-06 20:55:35 +00:00
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:39:14 +00:00
|
|
|
else
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This tool is supposed to be active forever
|
|
|
|
assert( false );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EDA_ITEM* EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
|
2019-07-09 19:50:40 +00:00
|
|
|
bool* aSelectionCancelledFlag, bool aCheckLocked,
|
|
|
|
bool aAdd, bool aSubtract, bool aExclusiveOr )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-10 19:22:26 +00:00
|
|
|
EDA_ITEM* start;
|
|
|
|
EE_COLLECTOR collector;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-06 02:32:01 +00:00
|
|
|
if( m_isLibEdit )
|
|
|
|
start = static_cast<LIB_EDIT_FRAME*>( m_frame )->GetCurPart();
|
|
|
|
else
|
|
|
|
start = m_frame->GetScreen()->GetDrawItems();
|
|
|
|
|
2019-05-09 03:11:36 +00:00
|
|
|
// Empty schematics have no draw items
|
|
|
|
if( !start )
|
|
|
|
return nullptr;
|
|
|
|
|
2019-05-16 23:48:39 +00:00
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
collector.Collect( start, aFilterList, (wxPoint) aWhere, m_unit, m_convert );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-06-11 20:17:05 +00:00
|
|
|
// Post-process collected items
|
2019-04-21 23:45:34 +00:00
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
2019-08-01 04:31:19 +00:00
|
|
|
if( !Selectable( collector[ i ] ) )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( aCheckLocked && collector[ i ]->IsLocked() )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +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
|
|
|
|
if( collector[ i ]->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) collector[ i ];
|
|
|
|
line->ClearFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
|
|
|
if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
|
|
|
line->SetFlags( STARTPOINT );
|
|
|
|
else if (HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
|
|
|
|
line->SetFlags( ENDPOINT );
|
|
|
|
else
|
|
|
|
line->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
|
|
|
|
if( collector.GetCount() > 1 && !m_skip_heuristics )
|
|
|
|
{
|
2019-06-28 19:11:26 +00:00
|
|
|
GuessSelectionCandidates( collector, aWhere );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If still more than one item we're going to have to ask the user.
|
|
|
|
if( collector.GetCount() > 1 )
|
|
|
|
{
|
2019-04-25 20:25:44 +00:00
|
|
|
collector.m_MenuTitle = _( "Clarify Selection" );
|
|
|
|
// Must call selectionMenu via RunAction() to avoid event-loop contention
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &collector );
|
2019-04-25 20:25:44 +00:00
|
|
|
|
|
|
|
if( collector.m_MenuCancelled )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aSelectionCancelledFlag )
|
|
|
|
*aSelectionCancelledFlag = true;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( !aAdd && !aSubtract && !aExclusiveOr )
|
|
|
|
ClearSelection();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( collector.GetCount() == 1 )
|
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = collector[ 0 ];
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( aSubtract || ( aExclusiveOr && item->IsSelected() ) )
|
|
|
|
{
|
|
|
|
unselect( item );
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
select( item );
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
return item;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 ) )
|
|
|
|
collector.Remove( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 )
|
2019-05-16 23:48:39 +00:00
|
|
|
collector.Remove( other );
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
|
|
|
|
|
2019-06-26 18:43:37 +00:00
|
|
|
if( item->Type() == SCH_COMPONENT_T && other->Type() == SCH_PIN_T )
|
2019-12-19 11:41:51 +00:00
|
|
|
{
|
|
|
|
if( m_frame->GetSelectPinSelectSymbol() )
|
|
|
|
collector.Remove( other );
|
|
|
|
else
|
|
|
|
collector.Remove( item );
|
|
|
|
}
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prefer a field to a symbol
|
|
|
|
for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
|
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T && other->Type() == SCH_COMPONENT_T )
|
|
|
|
collector.Remove( 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 )
|
|
|
|
collector.Remove( j );
|
|
|
|
else if( !junction && j > 0 )
|
|
|
|
collector.Remove( j );
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2019-05-07 09:38:34 +00:00
|
|
|
// Filter an existing selection
|
|
|
|
if( !m_selection.Empty() )
|
2019-04-23 17:12:10 +00:00
|
|
|
{
|
2019-04-27 23:50:35 +00:00
|
|
|
for( int i = m_selection.GetSize() - 1; i >= 0; --i )
|
|
|
|
{
|
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-07 09:38:34 +00:00
|
|
|
|
|
|
|
// If nothing was selected, or we filtered everything out, do a hover selection
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-05-07 09:38:34 +00:00
|
|
|
SelectPoint( cursorPos, aFilterList );
|
|
|
|
m_selection.SetIsHover( true );
|
2019-05-20 15:42:49 +00:00
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2019-05-22 02:42:33 +00:00
|
|
|
if( m_isLibEdit )
|
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
|
|
|
{
|
|
|
|
bool cancelled = false; // Was the tool cancelled while it was running?
|
|
|
|
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
|
|
|
{
|
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;
|
2019-09-04 10:46:18 +00:00
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
|
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
|
|
|
|
|
2019-08-27 20:08:09 +00:00
|
|
|
// Sheet pins aren't in the view; add them by hand
|
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
|
|
|
|
|
|
|
for( SCH_SHEET_PIN& pin : sheet->GetPins() )
|
2019-09-04 10:46:18 +00:00
|
|
|
sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &pin, layer ) );
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 10:46:18 +00:00
|
|
|
selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
int width = area.GetEnd().x - area.GetOrigin().x;
|
|
|
|
int height = area.GetEnd().y - area.GetOrigin().y;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2019-06-13 18:57:11 +00:00
|
|
|
bool windowSelection = width >= 0;
|
2019-07-09 19:50:40 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
if( view->IsMirroredX() )
|
|
|
|
windowSelection = !windowSelection;
|
|
|
|
|
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
|
|
|
|
2019-09-03 16:24:24 +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[] =
|
|
|
|
{
|
|
|
|
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-06-25 06:31:22 +00:00
|
|
|
if( m_frame->GetScreen()->GetDrawItems() == nullptr ) // Empty schematics
|
|
|
|
return nullptr;
|
|
|
|
|
2019-05-10 19:22:26 +00:00
|
|
|
EE_COLLECTOR collector;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2019-05-15 17:00:49 +00:00
|
|
|
int thresholdMax = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
|
|
|
|
for( int threshold : { 0, thresholdMax/2, thresholdMax } )
|
|
|
|
{
|
|
|
|
collector.m_Threshold = threshold;
|
|
|
|
collector.Collect( m_frame->GetScreen()->GetDrawItems(), nodeTypes, (wxPoint) aPosition );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-30 17:02:38 +00:00
|
|
|
static KICAD_T wiresAndBusses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
|
|
|
|
|
|
|
|
RequestSelection( wiresAndBusses );
|
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();
|
|
|
|
m_frame->GetScreen()->MarkConnections( line );
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
for( EDA_ITEM* item = m_frame->GetScreen()->GetDrawItems(); item; item = item->Next() )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2019-08-27 12:12:34 +00:00
|
|
|
if( item->HasFlag( CANDIDATE ) )
|
2019-04-30 13:54:32 +00:00
|
|
|
select( item );
|
2019-05-03 08:48:53 +00:00
|
|
|
}
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
EDA_ITEM* start = nullptr;
|
|
|
|
|
|
|
|
if( m_isLibEdit )
|
|
|
|
start = static_cast<LIB_EDIT_FRAME*>( m_frame )->GetCurPart();
|
|
|
|
else
|
|
|
|
start = m_frame->GetScreen()->GetDrawItems();
|
|
|
|
|
|
|
|
INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
|
|
|
|
{
|
2019-10-27 17:47:26 +00:00
|
|
|
// If the field and component are selected, only use the component
|
|
|
|
if( item->IsSelected() && !( item->Type() == SCH_FIELD_T && item->GetParent()
|
|
|
|
&& item->GetParent()->IsSelected() ) )
|
|
|
|
{
|
2019-05-11 10:06:28 +00:00
|
|
|
select( item );
|
2019-10-27 17:47:26 +00:00
|
|
|
}
|
2019-05-11 10:06:28 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2019-05-11 10:06:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EDA_ITEM::IterateForward( start, inspector, nullptr, EE_COLLECTOR::AllItems );
|
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;
|
2019-06-15 00:29:42 +00:00
|
|
|
ACTION_MENU menu( true );
|
2019-04-23 12:51:48 +00:00
|
|
|
|
|
|
|
int limit = std::min( MAX_SELECT_ITEM_IDS, aCollector->GetCount() );
|
|
|
|
|
|
|
|
for( int i = 0; i < limit; ++i )
|
|
|
|
{
|
|
|
|
wxString text;
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = ( *aCollector )[i];
|
2019-04-23 12:51:48 +00:00
|
|
|
text = item->GetSelectMenuText( m_frame->GetUserUnits() );
|
|
|
|
|
|
|
|
wxString menuText = wxString::Format("&%d. %s", i + 1, text );
|
|
|
|
menu.Add( menuText, i + 1, item->GetMenuImage() );
|
|
|
|
}
|
|
|
|
|
2019-04-25 20:25:44 +00:00
|
|
|
if( aCollector->m_MenuTitle.Length() )
|
|
|
|
menu.SetTitle( aCollector->m_MenuTitle );
|
2019-04-23 12:51:48 +00:00
|
|
|
|
|
|
|
menu.SetIcon( info_xpm );
|
|
|
|
menu.DisplayTitle( true );
|
2019-04-21 23:45:34 +00:00
|
|
|
SetContextMenu( &menu, CMENU_NOW );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
if( evt->Action() == TA_CHOICE_MENU_UPDATE )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2019-06-17 13:43:22 +00:00
|
|
|
current = nullptr;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( current )
|
|
|
|
unhighlight( current, BRIGHTENED );
|
|
|
|
|
|
|
|
OPT<int> id = evt->GetCommandId();
|
|
|
|
|
|
|
|
// User has selected an item, so this one will be returned
|
|
|
|
if( id && ( *id > 0 ) )
|
|
|
|
current = ( *aCollector )[*id - 1];
|
|
|
|
else
|
2019-06-17 13:43:22 +00:00
|
|
|
current = nullptr;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( current )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
// NOTE: in the future this is where eeschema layer/itemtype visibility will be handled
|
2019-12-19 08:11:34 +00:00
|
|
|
LIB_EDIT_FRAME* symbeditFrame = dynamic_cast< LIB_EDIT_FRAME* >( m_frame );
|
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;
|
|
|
|
|
|
|
|
case LIB_PART_T: // In libedit we do not want to select the symbol itself.
|
|
|
|
return false;
|
|
|
|
|
2019-12-12 15:44:53 +00:00
|
|
|
case LIB_FIELD_T:
|
|
|
|
{
|
2019-12-19 08:11:34 +00:00
|
|
|
if( symbeditFrame )
|
2019-12-12 16:42:11 +00:00
|
|
|
{
|
2019-12-19 08:11:34 +00:00
|
|
|
LIB_PART* currentPart = symbeditFrame->GetCurPart();
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2019-12-12 16:42:11 +00:00
|
|
|
// Nothing in derived symbols is editable at the moment.
|
|
|
|
if( currentPart && currentPart->IsAlias() )
|
|
|
|
return false;
|
|
|
|
}
|
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:
|
|
|
|
{
|
2019-12-19 08:11:34 +00:00
|
|
|
if( symbeditFrame )
|
2019-12-12 16:42:11 +00:00
|
|
|
{
|
|
|
|
LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-12-19 08:11:34 +00:00
|
|
|
if( lib_item->GetUnit() && lib_item->GetUnit() != symbeditFrame->GetUnit() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2019-12-19 08:11:34 +00:00
|
|
|
if( lib_item->GetConvert() && lib_item->GetConvert() != symbeditFrame->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 );
|
|
|
|
|
|
|
|
// Highlight pins and fields. (All the other component children are currently only
|
2019-04-23 17:40:29 +00:00
|
|
|
// represented in the LIB_PART and will inherit the settings of the parent component.)
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_COMPONENT_T )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-23 17:40:29 +00:00
|
|
|
SCH_PINS& pins = static_cast<SCH_COMPONENT*>( aItem )->GetPins();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
for( SCH_PIN& pin : pins )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
pin.SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
pin.SetBrightened();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SCH_FIELD*> fields;
|
|
|
|
static_cast<SCH_COMPONENT*>( aItem )->GetFields( fields, false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
for( SCH_FIELD* field : fields )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
field->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
field->SetBrightened();
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 16:45:27 +00:00
|
|
|
else if( itemType == SCH_SHEET_T )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PINS& pins = static_cast<SCH_SHEET*>( aItem )->GetPins();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
for( SCH_SHEET_PIN& pin : pins )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
pin.SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
pin.SetBrightened();
|
|
|
|
}
|
|
|
|
}
|
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 );
|
|
|
|
|
|
|
|
// Unhighlight pins and fields. (All the other component children are currently only
|
|
|
|
// represented in the LIB_PART.)
|
2019-05-17 16:45:27 +00:00
|
|
|
if( itemType == SCH_COMPONENT_T )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-23 17:40:29 +00:00
|
|
|
SCH_PINS& pins = static_cast<SCH_COMPONENT*>( aItem )->GetPins();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
for( SCH_PIN& pin : pins )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
pin.ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
pin.ClearBrightened();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SCH_FIELD*> fields;
|
|
|
|
static_cast<SCH_COMPONENT*>( aItem )->GetFields( fields, false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
for( SCH_FIELD* field : fields )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
field->ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
field->ClearBrightened();
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 16:45:27 +00:00
|
|
|
else if( itemType == SCH_SHEET_T )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PINS& pins = static_cast<SCH_SHEET*>( aItem )->GetPins();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
for( SCH_SHEET_PIN& pin : pins )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
pin.ClearSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
pin.ClearBrightened();
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
for( auto item : m_selection )
|
|
|
|
{
|
|
|
|
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() );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:34:58 +00:00
|
|
|
|