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
|
2024-03-14 09:01:58 +00:00
|
|
|
* Copyright (C) 2019-2024 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
|
|
|
|
*/
|
|
|
|
|
2023-09-24 23:33:05 +00:00
|
|
|
#include <advanced_config.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>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2021-11-01 21:05:30 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <ee_actions.h>
|
|
|
|
#include <ee_collectors.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <ee_selection_tool.h>
|
2022-07-12 01:03:45 +00:00
|
|
|
#include <eeschema_id.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <math/util.h>
|
2021-09-19 10:05:58 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2022-07-23 22:26:03 +00:00
|
|
|
#include <sch_painter.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <preview_items/selection_area.h>
|
|
|
|
#include <sch_base_frame.h>
|
2023-09-28 14:27:27 +00:00
|
|
|
#include <sch_commit.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-02-01 16:39:26 +00:00
|
|
|
#include <sch_field.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_item.h>
|
2019-06-11 20:17:05 +00:00
|
|
|
#include <sch_line.h>
|
2021-12-30 20:05:32 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2021-12-30 16:51:04 +00:00
|
|
|
#include <sch_marker.h>
|
2023-09-28 14:27:27 +00:00
|
|
|
#include <sch_no_connect.h>
|
2024-05-03 16:57:58 +00:00
|
|
|
#include <sch_render_settings.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>
|
2023-11-25 12:38:24 +00:00
|
|
|
#include <sch_table.h>
|
|
|
|
#include <sch_tablecell.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2020-10-01 23:53:47 +00:00
|
|
|
#include <tools/ee_grid_helper.h>
|
2021-09-29 17:50:22 +00:00
|
|
|
#include <tools/ee_point_editor.h>
|
2019-06-16 13:42:40 +00:00
|
|
|
#include <tools/sch_line_wire_bus_tool.h>
|
2022-07-09 17:55:40 +00:00
|
|
|
#include <tools/sch_editor_control.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-01-04 23:05:57 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
2021-11-13 16:38:19 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2024-05-16 14:14:44 +00:00
|
|
|
#include "symb_transforms_utils.h"
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = []( const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2021-06-15 12:31:28 +00:00
|
|
|
return !symbol->GetLibSymbolRef() || !symbol->GetLibSymbolRef()->IsPower();
|
2019-05-02 10:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleSymbolOrPower = []( const SELECTION& aSel )
|
2021-02-17 00:14:23 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_SYMBOL_T;
|
2021-02-17 00:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-22 00:35:37 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleDeMorganSymbol = []( const SELECTION& aSel )
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
|
2019-05-02 10:59:36 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2024-01-26 16:16:13 +00:00
|
|
|
return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->HasAlternateBodyStyle();
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-28 11:29:47 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleMultiFunctionPin = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
if( aSel.GetSize() == 1 )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aSel.Front() );
|
|
|
|
|
|
|
|
if( pin && pin->GetLibPin() )
|
|
|
|
return !pin->GetLibPin()->GetAlternates().empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-12-30 16:51:04 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::SingleNonExcludedMarker = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
if( aSel.CountType( SCH_MARKER_T ) != 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !static_cast<SCH_MARKER*>( aSel.Front() )->IsExcluded();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-12-22 19:00:10 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::MultipleSymbolsOrPower = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return aSel.GetSize() > 1 && aSel.OnlyContains( { SCH_SYMBOL_T } );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-28 14:27:27 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::AllPins = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return aSel.GetSize() >= 1 && aSel.OnlyContains( { SCH_PIN_T } );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
SELECTION_CONDITION EE_CONDITIONS::AllPinsOrSheetPins = []( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return aSel.GetSize() >= 1 && aSel.OnlyContains( { SCH_PIN_T, SCH_SHEET_PIN_T } );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 19:28:16 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::EE_SELECTION_TOOL() :
|
2022-07-12 01:03:45 +00:00
|
|
|
SELECTION_TOOL( "eeschema.InteractiveSelection" ),
|
2019-04-28 23:34:43 +00:00
|
|
|
m_frame( nullptr ),
|
2020-11-21 20:57:13 +00:00
|
|
|
m_nonModifiedCursor( KICURSOR::ARROW ),
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor( false ),
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer( false ),
|
2019-05-06 02:32:01 +00:00
|
|
|
m_unit( 0 ),
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle( 0 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2024-02-25 22:39:14 +00:00
|
|
|
m_filter.SetDefaults();
|
2020-08-20 23:05:21 +00:00
|
|
|
m_selection.Clear();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL::~EE_SELECTION_TOOL()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2019-05-17 16:45:27 +00:00
|
|
|
using E_C = EE_CONDITIONS;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
static std::vector<KICAD_T> connectedTypes =
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
|
|
|
SCH_SYMBOL_LOCATE_POWER_T,
|
|
|
|
SCH_PIN_T,
|
|
|
|
SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_BUS_WIRE_ENTRY_T,
|
|
|
|
SCH_BUS_BUS_ENTRY_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_HIER_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_SHEET_PIN_T,
|
|
|
|
SCH_DIRECTIVE_LABEL_T,
|
|
|
|
SCH_JUNCTION_T
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::Init()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-06 02:32:01 +00:00
|
|
|
m_frame = getEditFrame<SCH_BASE_FRAME>();
|
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
|
|
|
|
SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditorFrame )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
m_isSymbolEditor = true;
|
|
|
|
m_unit = symbolEditorFrame->GetUnit();
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = symbolEditorFrame->GetBodyStyle();
|
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
|
|
|
|
2023-12-19 19:29:17 +00:00
|
|
|
auto linesSelection = E_C::MoreThan( 0 ) &&
|
|
|
|
E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_ITEM_LOCATE_GRAPHIC_LINE_T } );
|
|
|
|
auto wireOrBusSelection = E_C::Count( 1 ) &&
|
|
|
|
E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_ITEM_LOCATE_BUS_T } );
|
2022-02-27 20:14:22 +00:00
|
|
|
auto connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes );
|
2022-08-20 09:27:35 +00:00
|
|
|
auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } );
|
2023-11-25 12:38:24 +00:00
|
|
|
auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( { SCH_SYMBOL_T, SCH_PIN_T, SCH_SHEET_T } );
|
|
|
|
auto tableCellSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( { SCH_TABLECELL_T } );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2020-12-11 20:02:20 +00:00
|
|
|
auto schEditSheetPageNumberCondition =
|
2021-02-19 14:51:18 +00:00
|
|
|
[&] ( const SELECTION& aSel )
|
2020-12-11 20:02:20 +00:00
|
|
|
{
|
2021-02-19 14:51:18 +00:00
|
|
|
if( m_isSymbolEditor || m_isSymbolViewer )
|
|
|
|
return false;
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
return E_C::LessThan( 2 )( aSel ) && E_C::OnlyTypes( { SCH_SHEET_T } )( aSel );
|
2020-12-11 20:02:20 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
auto schEditCondition =
|
|
|
|
[this] ( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
return !m_isSymbolEditor && !m_isSymbolViewer;
|
2020-07-07 10:17:30 +00:00
|
|
|
};
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
auto belowRootSheetCondition =
|
|
|
|
[&]( const SELECTION& aSel )
|
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-12-25 23:37:01 +00:00
|
|
|
return editFrame
|
|
|
|
&& editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
auto haveHighlight =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
2023-05-17 00:06:21 +00:00
|
|
|
return editFrame && !editFrame->GetHighlightedConnection().IsEmpty();
|
2022-07-10 23:14:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto haveSymbol =
|
2020-05-13 02:00:37 +00:00
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
return m_isSymbolEditor &&
|
|
|
|
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
auto symbolDisplayNameIsEditable =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
if ( !m_isSymbolEditor )
|
|
|
|
return false;
|
|
|
|
|
2022-09-20 16:08:24 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2022-09-14 22:11:37 +00:00
|
|
|
|
2022-09-20 16:08:24 +00:00
|
|
|
return symbEditorFrame
|
|
|
|
&& symbEditorFrame->GetCurSymbol()
|
|
|
|
&& symbEditorFrame->GetCurSymbol()->IsMulti()
|
|
|
|
&& symbEditorFrame->IsSymbolEditable()
|
|
|
|
&& !symbEditorFrame->IsSymbolAlias();
|
2022-09-14 22:11:37 +00:00
|
|
|
};
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
auto& menu = m_menu.GetMenu();
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::clearHighlight, haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
menu.AddSeparator( haveHighlight && EE_CONDITIONS::Idle, 1 );
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
menu.AddItem( ACTIONS::selectColumns, tableCellSelection && EE_CONDITIONS::Idle, 2 );
|
|
|
|
menu.AddItem( ACTIONS::selectRows, tableCellSelection && EE_CONDITIONS::Idle, 2 );
|
|
|
|
menu.AddItem( ACTIONS::selectTable, tableCellSelection && EE_CONDITIONS::Idle, 2 );
|
2023-11-25 12:38: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 );
|
2023-12-19 19:29:17 +00:00
|
|
|
menu.AddItem( ACTIONS::finishInteractive,
|
|
|
|
SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus, 100 );
|
2019-05-10 17:19:48 +00:00
|
|
|
|
2023-12-17 22:06:28 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 150 );
|
2023-12-19 19:29:17 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::selectOnPCB,
|
|
|
|
crossProbingSelection && EE_CONDITIONS::Idle, 150 );
|
2023-12-17 22:06:28 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 150 );
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 200 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2021-10-12 20:05:37 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeClassLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2019-06-15 00:29:42 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
2022-12-15 15:26:48 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::breakWire, linesSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::slice, linesSelection && EE_CONDITIONS::Idle, 250 );
|
2024-02-25 14:23:59 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::placeSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
|
|
|
menu.AddItem( EE_ACTIONS::syncSheetPins, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
2020-07-07 10:17:30 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
|
2020-12-11 20:02:20 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2022-07-10 23:14:29 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::symbolProperties, haveSymbol && EE_CONDITIONS::Empty, 400 );
|
|
|
|
menu.AddItem( EE_ACTIONS::pinTable, haveSymbol && EE_CONDITIONS::Empty, 400 );
|
2022-09-14 22:11:37 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::setUnitDisplayName,
|
|
|
|
haveSymbol && symbolDisplayNameIsEditable && EE_CONDITIONS::Empty, 400 );
|
2019-05-01 13:24:51 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
menu.AddSeparator( 1000 );
|
2019-06-11 14:38:21 +00:00
|
|
|
m_frame->AddStandardSubMenus( m_menu );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.SetOwner( this );
|
2023-12-19 19:29:17 +00:00
|
|
|
Connect( wxEVT_TIMER, wxTimerEventHandler( EE_SELECTION_TOOL::onDisambiguationExpire ),
|
|
|
|
nullptr, this );
|
2021-09-05 20:37:52 +00:00
|
|
|
|
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
|
|
|
|
2023-04-04 16:04:24 +00:00
|
|
|
if( aReason != TOOL_BASE::REDRAW )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
// 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();
|
2023-04-04 16:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 10:50:56 +00:00
|
|
|
if( aReason == TOOL_BASE::MODEL_RELOAD || aReason == TOOL_BASE::SUPERMODEL_RELOAD )
|
2023-04-04 16:04:24 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
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();
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = symbolEditFrame->GetBodyStyle();
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
2019-05-25 08:09:26 +00:00
|
|
|
else
|
2022-07-12 01:03:45 +00:00
|
|
|
{
|
2020-12-25 23:37:01 +00:00
|
|
|
m_isSymbolViewer = symbolViewerFrame != nullptr;
|
2022-07-12 01:03:45 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
|
|
|
|
getView()->Remove( &m_selection );
|
|
|
|
getView()->Add( &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-20 18:51:24 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
KIID lastRolloverItem = niluuid;
|
2023-02-16 22:14:08 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
auto pinOrientation =
|
|
|
|
[]( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem );
|
|
|
|
|
|
|
|
if( pin )
|
2024-05-16 14:14:44 +00:00
|
|
|
{
|
|
|
|
const SCH_SYMBOL* parent = dynamic_cast<const SCH_SYMBOL*>( pin->GetParentSymbol() );
|
|
|
|
|
|
|
|
if( !parent )
|
|
|
|
return pin->GetOrientation();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_PIN dummy( *pin );
|
|
|
|
RotateAndMirrorPin( dummy, parent->GetOrientation() );
|
|
|
|
return dummy.GetOrientation();
|
|
|
|
}
|
|
|
|
}
|
2024-05-01 22:49:35 +00:00
|
|
|
|
|
|
|
SCH_SHEET_PIN* sheetPin = dynamic_cast<SCH_SHEET_PIN*>( aItem );
|
|
|
|
|
|
|
|
if( sheetPin )
|
|
|
|
{
|
|
|
|
switch( sheetPin->GetSide() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SHEET_SIDE::LEFT: return PIN_ORIENTATION::PIN_RIGHT;
|
|
|
|
case SHEET_SIDE::RIGHT: return PIN_ORIENTATION::PIN_LEFT;
|
|
|
|
case SHEET_SIDE::TOP: return PIN_ORIENTATION::PIN_DOWN;
|
|
|
|
case SHEET_SIDE::BOTTOM: return PIN_ORIENTATION::PIN_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PIN_ORIENTATION::PIN_LEFT;
|
|
|
|
};
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
bool selCancelled = false;
|
2020-10-08 00:50:28 +00:00
|
|
|
bool displayWireCursor = false;
|
2021-02-15 14:57:06 +00:00
|
|
|
bool displayBusCursor = false;
|
2021-02-17 19:43:07 +00:00
|
|
|
bool displayLineCursor = false;
|
2020-11-29 16:31:43 +00:00
|
|
|
KIID rolloverItem = lastRolloverItem;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
// on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
|
|
|
|
evt->Modifier( MD_ALT ) );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-02-24 19:26:50 +00:00
|
|
|
MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
if( evt->IsMouseDown( BUT_LEFT ) )
|
|
|
|
{
|
2023-05-06 10:27:29 +00:00
|
|
|
if( !m_frame->ToolStackIsEmpty() )
|
|
|
|
{
|
|
|
|
// Avoid triggering when running under other tools
|
|
|
|
}
|
|
|
|
else if( m_toolMgr->GetTool<EE_POINT_EDITOR>()
|
|
|
|
&& m_toolMgr->GetTool<EE_POINT_EDITOR>()->HasPoint() )
|
|
|
|
{
|
|
|
|
// Distinguish point editor from selection modification by checking modifiers
|
|
|
|
if( hasModifier() )
|
|
|
|
{
|
|
|
|
m_originalCursor = m_toolMgr->GetMousePosition();
|
2023-09-24 23:33:05 +00:00
|
|
|
m_disambiguateTimer.StartOnce( ADVANCED_CFG::GetCfg().m_DisambiguationMenuDelay );
|
2023-05-06 10:27:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-09-09 23:23:00 +00:00
|
|
|
{
|
|
|
|
m_originalCursor = m_toolMgr->GetMousePosition();
|
2023-09-24 23:33:05 +00:00
|
|
|
m_disambiguateTimer.StartOnce( ADVANCED_CFG::GetCfg().m_DisambiguationMenuDelay );
|
2021-09-09 23:23:00 +00:00
|
|
|
}
|
2021-09-05 20:37:52 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
// Single click? Select single object
|
2021-09-05 20:37:52 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
// If the timer has stopped, then we have already run the disambiguate routine
|
|
|
|
// and we don't want to register an extra click here
|
|
|
|
if( !m_disambiguateTimer.IsRunning() )
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
// Collect items at the clicked location (doesn't select them yet)
|
2020-10-01 23:53:47 +00:00
|
|
|
EE_COLLECTOR collector;
|
2022-02-14 00:53:47 +00:00
|
|
|
CollectHits( collector, evt->Position() );
|
2022-03-03 14:35:57 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-12-08 19:09:30 +00:00
|
|
|
if( collector.GetCount() == 1 && !m_isSymbolEditor && !hasModifier() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT autostart = autostartEvent( evt, grid, collector[0] );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostart )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
DRAW_SEGMENT_EVENT_PARAMS* params = new DRAW_SEGMENT_EVENT_PARAMS();
|
2020-10-03 19:05:28 +00:00
|
|
|
|
2023-06-21 13:06:25 +00:00
|
|
|
params->layer = autostart->Parameter<const DRAW_SEGMENT_EVENT_PARAMS*>()->layer;
|
2022-02-14 00:53:47 +00:00
|
|
|
params->quitOnDraw = true;
|
|
|
|
params->sourceSegment = dynamic_cast<SCH_LINE*>( collector[0] );
|
2021-02-17 19:43:07 +00:00
|
|
|
|
2023-06-21 13:06:25 +00:00
|
|
|
autostart->SetParameter<const DRAW_SEGMENT_EVENT_PARAMS*>( params );
|
2022-02-14 00:53:47 +00:00
|
|
|
m_toolMgr->ProcessEvent( *autostart );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
selCancelled = true;
|
|
|
|
}
|
|
|
|
else if( collector[0]->IsHypertext() )
|
|
|
|
{
|
2022-08-27 18:14:57 +00:00
|
|
|
collector[ 0 ]->DoHypertextAction( m_frame );
|
2022-02-14 00:53:47 +00:00
|
|
|
selCancelled = true;
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2023-06-09 18:34:40 +00:00
|
|
|
else if( collector[0]->IsBrightened() )
|
|
|
|
{
|
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
|
|
|
{
|
|
|
|
NET_NAVIGATOR_ITEM_DATA itemData( schframe->GetCurrentSheet(),
|
|
|
|
collector[0] );
|
|
|
|
|
|
|
|
schframe->SelectNetNavigatorItem( &itemData );
|
|
|
|
}
|
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( !selCancelled )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
selectPoint( collector, evt->Position(), nullptr, nullptr, m_additive,
|
|
|
|
m_subtractive, m_exclusive_or );
|
2021-12-02 16:54:13 +00:00
|
|
|
m_selection.SetIsHover( false );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// right click? if there is any object - show the context menu
|
2021-01-31 14:59:18 +00:00
|
|
|
if( m_selection.Empty() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-10-29 15:11:06 +00:00
|
|
|
ClearSelection();
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
|
2019-04-21 23:45:34 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
2021-01-31 14:59:18 +00:00
|
|
|
// If the cursor has moved off the bounding box of the selection by more than
|
|
|
|
// a grid square, check to see if there is another item available for selection
|
|
|
|
// under the cursor. If there is, the user likely meant to get the context menu
|
|
|
|
// for that item. If there is no new item, then keep the original selection and
|
|
|
|
// show the context menu for it.
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( !m_selection.GetBoundingBox().Inflate( grid.GetGrid().x, grid.GetGrid().y )
|
|
|
|
.Contains( evt->Position() ) )
|
2021-01-31 14:59:18 +00:00
|
|
|
{
|
2022-12-22 19:16:38 +00:00
|
|
|
EE_COLLECTOR collector;
|
2021-01-31 14:59:18 +00:00
|
|
|
|
2022-12-22 19:16:38 +00:00
|
|
|
if( CollectHits( collector, evt->Position(), { SCH_LOCATE_ANY_T } ) )
|
2021-01-31 14:59:18 +00:00
|
|
|
{
|
2022-12-22 19:16:38 +00:00
|
|
|
ClearSelection();
|
2021-01-31 14:59:18 +00:00
|
|
|
|
2022-12-22 19:16:38 +00:00
|
|
|
SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
|
2021-01-31 14:59:18 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
}
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( !selCancelled )
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-06 19:26:20 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// double click? Display the properties window
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
if( m_selection.Empty() )
|
2020-11-23 19:46:17 +00:00
|
|
|
SelectPoint( evt->Position() );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-03 20:14:03 +00:00
|
|
|
EDA_ITEM* item = m_selection.Front();
|
|
|
|
|
|
|
|
if( item && item->Type() == SCH_SHEET_T )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::enterSheet );
|
2019-05-03 20:14:03 +00:00
|
|
|
else
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::properties );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2020-09-17 00:19:31 +00:00
|
|
|
else if( evt->IsDblClick( BUT_MIDDLE ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// Middle double click? Do zoom to fit or zoom to objects
|
2021-03-05 06:43:03 +00:00
|
|
|
if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitObjects );
|
2020-09-17 00:19:31 +00:00
|
|
|
else
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitScreen );
|
2020-09-17 00:19:31 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
else if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2021-03-05 00:01:17 +00:00
|
|
|
// Is another tool already moving a new object? Don't allow a drag start
|
2021-05-30 21:04:07 +00:00
|
|
|
if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
|
2021-03-05 00:01:17 +00:00
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// drag with LMB? Select multiple objects (or at least draw a selection box) or
|
|
|
|
// drag them
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
|
|
|
if( CollectHits( collector, evt->DragOrigin(), { SCH_TABLECELL_T } ) )
|
|
|
|
{
|
|
|
|
selectTableCells( static_cast<SCH_TABLE*>( collector[0]->GetParent() ) );
|
|
|
|
}
|
|
|
|
else if( hasModifier() || drag_action == MOUSE_DRAG_ACTION::SELECT )
|
2021-01-11 11:48:51 +00:00
|
|
|
{
|
|
|
|
selectMultiple();
|
|
|
|
}
|
2021-01-11 15:46:41 +00:00
|
|
|
else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-04-23 17:40:29 +00:00
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-01 20:03:14 +00:00
|
|
|
if( m_isSymbolEditor )
|
|
|
|
{
|
|
|
|
if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
m_selection = RequestSelection( { SCH_FIELD_T } );
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2021-07-01 20:03:14 +00:00
|
|
|
else
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
m_selection = RequestSelection( { SCH_SHAPE_T,
|
2024-04-14 18:04:53 +00:00
|
|
|
SCH_TEXT_T,
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_TEXTBOX_T,
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN_T,
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD_T } );
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2021-07-01 20:03:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
m_selection = RequestSelection( EE_COLLECTOR::MovableItems );
|
2021-07-01 20:03:14 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// Check if dragging has started within any of selected items bounding box
|
2022-11-19 21:01:45 +00:00
|
|
|
if( selectionContains( evt->DragOrigin() ) )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2023-07-26 06:58:22 +00:00
|
|
|
// drag_is_move option exists only in schematic editor, not in symbol editor
|
|
|
|
// (m_frame->eeconfig() returns nullptr in Symbol Editor)
|
|
|
|
if( m_isSymbolEditor || m_frame->eeconfig()->m_Input.drag_is_move )
|
2023-07-15 22:11:24 +00:00
|
|
|
m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, nullptr );
|
2020-04-23 22:57:34 +00:00
|
|
|
else
|
2023-07-15 22:11:24 +00:00
|
|
|
m_toolMgr->RunSynchronousAction( EE_ACTIONS::drag, nullptr );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-09 19:50:40 +00:00
|
|
|
// No -> drag a selection box
|
|
|
|
selectMultiple();
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 21:56:17 +00:00
|
|
|
else if( evt->IsMouseDown( BUT_AUX1 ) )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::navigateBack );
|
2022-06-02 21:56:17 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsMouseDown( BUT_AUX2 ) )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::navigateForward );
|
2022-06-02 21:56:17 +00:00
|
|
|
}
|
2019-06-15 00:29:42 +00:00
|
|
|
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
|
2019-05-02 20:03:03 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-11-23 19:46:17 +00:00
|
|
|
// context sub-menu selection? Handle unit selection or bus unfolding
|
2023-08-28 11:29:47 +00:00
|
|
|
if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_UNIT_END )
|
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() );
|
2023-08-28 11:29:47 +00:00
|
|
|
int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
|
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
|
|
|
}
|
2023-08-28 11:29:47 +00:00
|
|
|
else if( *evt->GetCommandId() >= ID_POPUP_SCH_ALT_PIN_FUNCTION
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_ALT_PIN_FUNCTION_END )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( m_selection.Front() );
|
|
|
|
wxString alt = *evt->Parameter<wxString*>();
|
|
|
|
|
|
|
|
if( pin )
|
|
|
|
static_cast<SCH_EDIT_FRAME*>( m_frame )->SetAltPinFunction( pin, alt );
|
|
|
|
}
|
2023-09-28 14:27:27 +00:00
|
|
|
else if( *evt->GetCommandId() >= ID_POPUP_SCH_PIN_TRICKS_START
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_PIN_TRICKS_END )
|
|
|
|
{
|
2024-05-01 22:49:35 +00:00
|
|
|
if( !m_selection.OnlyContains( { SCH_PIN_T, SCH_SHEET_PIN_T } )
|
|
|
|
|| m_selection.Empty() )
|
|
|
|
{
|
2023-09-28 14:27:27 +00:00
|
|
|
return 0;
|
2024-05-01 22:49:35 +00:00
|
|
|
}
|
2023-09-28 14:27:27 +00:00
|
|
|
|
|
|
|
// Keep track of new items so we make them the new selection at the end
|
|
|
|
EDA_ITEMS newItems;
|
|
|
|
SCH_COMMIT commit( static_cast<SCH_EDIT_FRAME*>( m_frame ) );
|
|
|
|
|
|
|
|
if( *evt->GetCommandId() == ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
2024-05-01 22:49:35 +00:00
|
|
|
SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( item->GetPosition() );
|
2023-09-28 14:27:27 +00:00
|
|
|
commit.Add( nc, m_frame->GetScreen() );
|
|
|
|
newItems.push_back( nc );
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( wxS( "No Connect Pins" ) );
|
|
|
|
ClearSelection();
|
|
|
|
}
|
2023-09-28 19:06:31 +00:00
|
|
|
else if( *evt->GetCommandId() == ID_POPUP_SCH_PIN_TRICKS_WIRE )
|
|
|
|
{
|
|
|
|
VECTOR2I wireGrid = grid.GetGridSize( GRID_HELPER_GRIDS::GRID_WIRES );
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
2024-05-01 22:49:35 +00:00
|
|
|
SCH_LINE* wire = new SCH_LINE( item->GetPosition(), LAYER_WIRE );
|
2023-09-28 19:06:31 +00:00
|
|
|
|
|
|
|
// Add some length to the wire as nothing in our code base handles
|
|
|
|
// 0 length wires very well, least of all the ortho drag algorithm
|
|
|
|
VECTOR2I stub;
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
switch( pinOrientation( item ) )
|
2023-09-28 19:06:31 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
default:
|
2023-12-19 19:29:17 +00:00
|
|
|
case PIN_ORIENTATION::PIN_RIGHT:
|
|
|
|
stub = VECTOR2I( -1 * wireGrid.x, 0 );
|
|
|
|
break;
|
2024-04-20 09:44:34 +00:00
|
|
|
case PIN_ORIENTATION::PIN_LEFT:
|
|
|
|
stub = VECTOR2I( 1 * wireGrid.x, 0 );
|
|
|
|
break;
|
2023-12-19 19:29:17 +00:00
|
|
|
case PIN_ORIENTATION::PIN_UP:
|
|
|
|
stub = VECTOR2I( 0, 1 * wireGrid.y );
|
|
|
|
break;
|
|
|
|
case PIN_ORIENTATION::PIN_DOWN:
|
|
|
|
stub = VECTOR2I( 0, -1 * wireGrid.y );
|
|
|
|
break;
|
2023-09-28 19:06:31 +00:00
|
|
|
}
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
wire->SetEndPoint( item->GetPosition() + stub );
|
2023-09-28 19:06:31 +00:00
|
|
|
|
|
|
|
m_frame->AddToScreen( wire, m_frame->GetScreen() );
|
|
|
|
commit.Added( wire, m_frame->GetScreen() );
|
|
|
|
newItems.push_back( wire );
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSelection();
|
|
|
|
AddItemsToSel( &newItems );
|
|
|
|
|
|
|
|
// Select only the ends so we can immediately start dragging them
|
|
|
|
for( EDA_ITEM* item : newItems )
|
|
|
|
static_cast<SCH_LINE*>( item )->SetFlags( ENDPOINT );
|
|
|
|
|
|
|
|
// Put the mouse on the nearest point of the first wire
|
|
|
|
SCH_LINE* first = static_cast<SCH_LINE*>( newItems[0] );
|
|
|
|
getViewControls()->SetCrossHairCursorPosition( first->GetEndPoint(), false );
|
|
|
|
getViewControls()->WarpMouseCursor( getViewControls()->GetCursorPosition(),
|
|
|
|
true );
|
|
|
|
|
|
|
|
// Start the drag tool, canceling will remove the wires
|
|
|
|
if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::drag, &commit, false ) )
|
|
|
|
commit.Push( wxS( "Wire Pins" ) );
|
|
|
|
else
|
|
|
|
commit.Revert();
|
|
|
|
}
|
2023-09-28 14:27:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// For every pin in the selection, add a label according to menu item
|
|
|
|
// selected by the user
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
2024-05-01 22:49:35 +00:00
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
|
|
|
|
SCH_SHEET_PIN* sheetPin = dynamic_cast<SCH_SHEET_PIN*>( item );
|
|
|
|
SCH_EDIT_FRAME* sf = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
2023-09-28 14:27:27 +00:00
|
|
|
SCH_LABEL_BASE* label = nullptr;
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
wxString labelText;
|
|
|
|
|
|
|
|
if( pin )
|
|
|
|
labelText = pin->GetShownName();
|
|
|
|
else if( sheetPin && sf )
|
|
|
|
labelText = sheetPin->GetShownText( &sf->GetCurrentSheet(), false );
|
|
|
|
|
2023-09-28 14:27:27 +00:00
|
|
|
switch( *evt->GetCommandId() )
|
|
|
|
{
|
|
|
|
case ID_POPUP_SCH_PIN_TRICKS_NET_LABEL:
|
2024-05-01 22:49:35 +00:00
|
|
|
label = new SCH_LABEL( item->GetPosition(), labelText );
|
2023-09-28 14:27:27 +00:00
|
|
|
break;
|
|
|
|
case ID_POPUP_SCH_PIN_TRICKS_HIER_LABEL:
|
2024-05-01 22:49:35 +00:00
|
|
|
label = new SCH_HIERLABEL( item->GetPosition(), labelText );
|
2023-09-28 14:27:27 +00:00
|
|
|
break;
|
|
|
|
case ID_POPUP_SCH_PIN_TRICKS_GLOBAL_LABEL:
|
2024-05-01 22:49:35 +00:00
|
|
|
label = new SCH_GLOBALLABEL( item->GetPosition(), labelText );
|
2023-09-28 14:27:27 +00:00
|
|
|
break;
|
|
|
|
default: continue;
|
|
|
|
}
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
switch( pinOrientation( item ) )
|
2023-09-28 14:27:27 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
default:
|
2023-09-28 14:27:27 +00:00
|
|
|
case PIN_ORIENTATION::PIN_RIGHT:
|
|
|
|
label->SetSpinStyle( SPIN_STYLE::SPIN::LEFT );
|
|
|
|
break;
|
2024-04-20 09:44:34 +00:00
|
|
|
case PIN_ORIENTATION::PIN_LEFT:
|
|
|
|
label->SetSpinStyle( SPIN_STYLE::SPIN::RIGHT );
|
|
|
|
break;
|
2023-09-28 14:27:27 +00:00
|
|
|
case PIN_ORIENTATION::PIN_UP:
|
|
|
|
label->SetSpinStyle( SPIN_STYLE::SPIN::BOTTOM );
|
|
|
|
break;
|
|
|
|
case PIN_ORIENTATION::PIN_DOWN:
|
|
|
|
label->SetSpinStyle( SPIN_STYLE::SPIN::UP );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-01 22:49:35 +00:00
|
|
|
ELECTRICAL_PINTYPE pinType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
|
|
|
|
|
|
|
|
if( pin )
|
|
|
|
{
|
|
|
|
pinType = pin->GetType();
|
|
|
|
}
|
|
|
|
else if( sheetPin )
|
|
|
|
{
|
|
|
|
switch( sheetPin->GetLabelShape() )
|
|
|
|
{
|
|
|
|
case LABEL_INPUT: pinType = ELECTRICAL_PINTYPE::PT_INPUT; break;
|
|
|
|
case LABEL_OUTPUT: pinType = ELECTRICAL_PINTYPE::PT_OUTPUT; break;
|
|
|
|
case LABEL_BIDI: pinType = ELECTRICAL_PINTYPE::PT_BIDI; break;
|
|
|
|
case LABEL_TRISTATE: pinType = ELECTRICAL_PINTYPE::PT_TRISTATE; break;
|
|
|
|
case LABEL_PASSIVE: pinType = ELECTRICAL_PINTYPE::PT_PASSIVE; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( pinType )
|
2023-09-28 14:27:27 +00:00
|
|
|
{
|
|
|
|
case ELECTRICAL_PINTYPE::PT_BIDI:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
|
|
|
|
break;
|
|
|
|
case ELECTRICAL_PINTYPE::PT_INPUT:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
|
|
|
|
break;
|
|
|
|
case ELECTRICAL_PINTYPE::PT_OUTPUT:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
|
|
|
|
break;
|
|
|
|
case ELECTRICAL_PINTYPE::PT_TRISTATE:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
|
|
|
|
break;
|
|
|
|
case ELECTRICAL_PINTYPE::PT_UNSPECIFIED:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Add( label, m_frame->GetScreen() );
|
|
|
|
newItems.push_back( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( wxS( "Label Pins" ) );
|
|
|
|
|
2023-12-19 19:29:17 +00:00
|
|
|
// Many users will want to drag these items to wire off of the pins, so
|
|
|
|
// pre-select them.
|
2023-09-28 14:27:27 +00:00
|
|
|
ClearSelection();
|
|
|
|
AddItemsToSel( &newItems );
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 20:58:43 +00:00
|
|
|
else if( *evt->GetCommandId() >= ID_POPUP_SCH_UNFOLD_BUS
|
|
|
|
&& *evt->GetCommandId() <= ID_POPUP_SCH_UNFOLD_BUS_END )
|
2019-05-05 14:16:29 +00:00
|
|
|
{
|
|
|
|
wxString* net = new wxString( *evt->Parameter<wxString*>() );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<wxString*>( EE_ACTIONS::unfoldBus, net );
|
2019-05-05 14:16:29 +00:00
|
|
|
}
|
2019-05-02 20:03:03 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2023-05-06 10:27:29 +00:00
|
|
|
// We didn't set these, but we have reports that they leak out of some other tools,
|
|
|
|
// so we clear them here.
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2022-07-09 17:55:40 +00:00
|
|
|
if( !GetSelection().Empty() )
|
|
|
|
{
|
|
|
|
ClearSelection();
|
|
|
|
}
|
2022-07-18 21:03:14 +00:00
|
|
|
else if( evt->FirstResponder() == this && evt->GetCommandId() == (int) WXK_ESCAPE )
|
2022-07-09 17:55:40 +00:00
|
|
|
{
|
|
|
|
SCH_EDITOR_CONTROL* editor = m_toolMgr->GetTool<SCH_EDITOR_CONTROL>();
|
|
|
|
|
2022-07-23 09:32:21 +00:00
|
|
|
if( editor && m_frame->eeconfig()->m_Input.esc_clears_net_highlight )
|
2022-07-09 17:55:40 +00:00
|
|
|
editor->ClearHighlight( *evt );
|
|
|
|
}
|
2019-05-06 20:55:35 +00:00
|
|
|
}
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
2020-12-14 21:11:33 +00:00
|
|
|
if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
|
2020-05-13 02:00:37 +00:00
|
|
|
schframe->FocusOnItem( nullptr );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
2022-07-09 17:55:40 +00:00
|
|
|
else if( evt->IsMotion() && !m_isSymbolEditor && evt->FirstResponder() == this )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
// Update cursor and rollover item
|
2020-11-29 16:31:43 +00:00
|
|
|
rolloverItem = niluuid;
|
2020-10-02 20:18:07 +00:00
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
2021-10-06 03:26:59 +00:00
|
|
|
getViewControls()->ForceCursorPosition( false );
|
|
|
|
|
2021-09-18 17:18:41 +00:00
|
|
|
if( CollectHits( collector, evt->Position() ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
narrowSelection( collector, evt->Position(), false );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-12-08 19:09:30 +00:00
|
|
|
if( collector.GetCount() == 1 && !hasModifier() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT autostartEvt = autostartEvent( evt, grid, collector[0] );
|
2021-10-01 00:25:33 +00:00
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostartEvt )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2022-02-14 00:53:47 +00:00
|
|
|
if( autostartEvt->Matches( EE_ACTIONS::drawBus.MakeEvent() ) )
|
2021-02-15 14:57:06 +00:00
|
|
|
displayBusCursor = true;
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( autostartEvt->Matches( EE_ACTIONS::drawWire.MakeEvent() ) )
|
|
|
|
displayWireCursor = true;
|
|
|
|
else if( autostartEvt->Matches( EE_ACTIONS::drawLines.MakeEvent() ) )
|
2021-02-17 19:43:07 +00:00
|
|
|
displayLineCursor = true;
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
else if( collector[0]->IsHypertext() && !collector[0]->IsSelected() )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
rolloverItem = collector[0]->m_Uuid;
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 14:39:14 +00:00
|
|
|
else
|
2020-11-23 19:46:17 +00:00
|
|
|
{
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-23 19:46:17 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( rolloverItem != lastRolloverItem )
|
|
|
|
{
|
2022-08-27 18:14:57 +00:00
|
|
|
if( EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
item->ClearFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = niluuid;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
2022-08-27 18:14:57 +00:00
|
|
|
}
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2023-07-01 02:39:41 +00:00
|
|
|
if( rolloverItem != niluuid )
|
2022-08-27 18:14:57 +00:00
|
|
|
{
|
2023-07-01 02:39:41 +00:00
|
|
|
EDA_ITEM* item = m_frame->GetItem( rolloverItem );
|
|
|
|
|
|
|
|
if( item && !( item->GetFlags() & IS_ROLLOVER ) )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
|
|
|
item->SetFlags( IS_ROLLOVER );
|
|
|
|
lastRolloverItem = rolloverItem;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( item );
|
2020-10-02 20:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
if( displayWireCursor )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_WIRE_ADD;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-02-15 14:57:06 +00:00
|
|
|
else if( displayBusCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_BUS;
|
|
|
|
}
|
2021-02-17 19:43:07 +00:00
|
|
|
else if( displayLineCursor )
|
|
|
|
{
|
|
|
|
m_nonModifiedCursor = KICURSOR::LINE_GRAPHIC;
|
|
|
|
}
|
2020-10-02 20:18:07 +00:00
|
|
|
else if( rolloverItem != niluuid )
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::HAND;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2021-01-11 11:48:51 +00:00
|
|
|
else if( !m_selection.Empty()
|
2021-01-11 15:46:41 +00:00
|
|
|
&& drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
|
2021-01-11 11:48:51 +00:00
|
|
|
&& evt->HasPosition()
|
|
|
|
&& selectionContains( evt->Position() ) ) //move/drag option prediction
|
2020-11-18 12:02:52 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::MOVING;
|
2020-11-18 12:02:52 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
else
|
2020-10-08 00:50:28 +00:00
|
|
|
{
|
2020-11-18 15:23:05 +00:00
|
|
|
m_nonModifiedCursor = KICURSOR::ARROW;
|
2020-10-08 00:50:28 +00:00
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_disambiguateTimer.Stop();
|
|
|
|
|
2020-10-30 13:57:59 +00:00
|
|
|
// Shutting down; clear the selection
|
|
|
|
m_selection.Clear();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT EE_SELECTION_TOOL::autostartEvent( TOOL_EVENT* aEvent, EE_GRID_HELPER& aGrid,
|
|
|
|
SCH_ITEM* aItem )
|
|
|
|
{
|
2023-07-23 17:51:42 +00:00
|
|
|
VECTOR2I pos = aGrid.BestSnapAnchor( aEvent->Position(), aGrid.GetItemGrid( aItem ) );
|
2022-02-14 00:53:47 +00:00
|
|
|
|
|
|
|
if( m_frame->eeconfig()->m_Drawing.auto_start_wires
|
|
|
|
&& !m_toolMgr->GetTool<EE_POINT_EDITOR>()->HasPoint()
|
|
|
|
&& aItem->IsPointClickableAnchor( pos ) )
|
|
|
|
{
|
|
|
|
OPT_TOOL_EVENT newEvt = EE_ACTIONS::drawWire.MakeEvent();
|
|
|
|
|
|
|
|
if( aItem->Type() == SCH_BUS_BUS_ENTRY_T )
|
|
|
|
{
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
|
|
|
|
{
|
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry = static_cast<SCH_BUS_WIRE_ENTRY*>( aItem );
|
|
|
|
|
|
|
|
if( !busEntry->m_connected_bus_item )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
|
|
|
|
|
|
|
|
if( line->IsBus() )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
else if( line->IsGraphicLine() )
|
|
|
|
newEvt = EE_ACTIONS::drawLines.MakeEvent();
|
|
|
|
}
|
2023-01-12 20:10:23 +00:00
|
|
|
else if( aItem->Type() == SCH_LABEL_T || aItem->Type() == SCH_HIER_LABEL_T
|
|
|
|
|| aItem->Type() == SCH_SHEET_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
|
|
|
|
SCH_CONNECTION possibleConnection( label->Schematic()->ConnectionGraph() );
|
|
|
|
possibleConnection.ConfigureFromLabel( label->GetText() );
|
|
|
|
|
|
|
|
if( possibleConnection.IsBus() )
|
|
|
|
newEvt = EE_ACTIONS::drawBus.MakeEvent();
|
|
|
|
}
|
2024-04-21 14:54:34 +00:00
|
|
|
else if( aItem->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( aItem );
|
|
|
|
|
|
|
|
wxCHECK( symbol, OPT_TOOL_EVENT() );
|
|
|
|
|
|
|
|
const SCH_PIN* pin = symbol->GetPin( pos );
|
|
|
|
|
|
|
|
wxCHECK( pin, OPT_TOOL_EVENT() );
|
|
|
|
|
2024-05-03 16:57:58 +00:00
|
|
|
if( !pin->IsVisible()
|
|
|
|
&& !( m_frame->eeconfig()->m_Appearance.show_hidden_pins
|
|
|
|
|| m_frame->GetRenderSettings()->m_ShowHiddenPins ) )
|
|
|
|
{
|
2024-04-21 14:54:34 +00:00
|
|
|
return OPT_TOOL_EVENT();
|
2024-05-03 16:57:58 +00:00
|
|
|
}
|
2024-04-21 14:54:34 +00:00
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
|
|
|
|
newEvt->SetMousePosition( pos );
|
|
|
|
newEvt->SetHasPosition( true );
|
|
|
|
newEvt->SetForceImmediate( true );
|
|
|
|
|
|
|
|
getViewControls()->ForceCursorPosition( true, pos );
|
|
|
|
|
|
|
|
return newEvt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPT_TOOL_EVENT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
int EE_SELECTION_TOOL::disambiguateCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-02-26 00:14:41 +00:00
|
|
|
wxMouseState keyboardState = wxGetMouseState();
|
|
|
|
|
|
|
|
setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
|
|
|
|
keyboardState.AltDown() );
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
m_skip_heuristics = true;
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( m_originalCursor, { SCH_LOCATE_ANY_T }, nullptr, &m_canceledMenu, false,
|
2021-09-24 19:44:26 +00:00
|
|
|
m_additive, m_subtractive, m_exclusive_or );
|
2021-09-05 20:37:52 +00:00
|
|
|
m_skip_heuristics = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 15:23:05 +00:00
|
|
|
void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
2020-12-30 00:51:34 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() && !m_multiple )
|
2020-11-18 15:23:05 +00:00
|
|
|
{
|
|
|
|
wxMouseState keyboardState = wxGetMouseState();
|
|
|
|
|
2021-03-25 09:28:20 +00:00
|
|
|
setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
|
|
|
|
keyboardState.AltDown() );
|
2020-11-18 15:23:05 +00:00
|
|
|
|
|
|
|
if( m_additive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD );
|
|
|
|
else if( m_subtractive )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT );
|
|
|
|
else if( m_exclusive_or )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( m_nonModifiedCursor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::GetSelection()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
return m_selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-19 10:05:58 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2021-11-28 18:59:55 +00:00
|
|
|
int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 );
|
2021-09-19 10:05:58 +00:00
|
|
|
aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
|
2022-07-23 22:26:03 +00:00
|
|
|
aCollector.m_ShowPinElectricalTypes = m_frame->GetRenderSettings()->m_ShowPinsElectricalType;
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol )
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-05-09 03:11:36 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
aCollector.Collect( symbol->GetDrawItems(), aScanTypes, aWhere, m_unit, m_bodyStyle );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
aCollector.Collect( m_frame->GetScreen(), aScanTypes, aWhere, m_unit, m_bodyStyle );
|
2022-07-19 08:47:34 +00:00
|
|
|
|
2024-03-03 03:18:51 +00:00
|
|
|
// If pins are disabled in the filter, they will be removed later. Let's add the parent
|
|
|
|
// so that people can use pins to select symbols in this case.
|
|
|
|
if( !m_filter.pins )
|
2022-07-19 08:47:34 +00:00
|
|
|
{
|
|
|
|
int originalCount = aCollector.GetCount();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < originalCount; ++ii )
|
|
|
|
{
|
|
|
|
if( aCollector[ii]->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aCollector[ii] );
|
|
|
|
|
|
|
|
if( !aCollector.HasItem( pin->GetParentSymbol() ) )
|
|
|
|
aCollector.Append( pin->GetParentSymbol() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
return aCollector.GetCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere,
|
2022-09-06 15:11:56 +00:00
|
|
|
bool aCheckLocked, bool aSelectedOnly )
|
2020-10-02 20:18:07 +00:00
|
|
|
{
|
2024-03-14 09:01:58 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2024-03-14 09:01:58 +00:00
|
|
|
if( symbolEditorFrame )
|
|
|
|
{
|
|
|
|
// Do not select invisible items if they are not displayed
|
2024-04-12 21:00:41 +00:00
|
|
|
EDA_ITEM* item = collector[i];
|
2024-03-14 09:01:58 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( item->Type() == SCH_FIELD_T )
|
2024-03-14 09:01:58 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( !static_cast<SCH_FIELD*>( item )->IsVisible()
|
2024-03-14 09:01:58 +00:00
|
|
|
&& !symbolEditorFrame->GetShowInvisibleFields() )
|
|
|
|
{
|
|
|
|
collector.Remove( i );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-20 09:44:34 +00:00
|
|
|
else if( item->Type() == SCH_PIN_T )
|
2024-03-14 09:01:58 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
if( !static_cast<SCH_PIN*>( item )->IsVisible()
|
2024-03-14 09:01:58 +00:00
|
|
|
&& !symbolEditorFrame->GetShowInvisiblePins() )
|
|
|
|
{
|
|
|
|
collector.Remove( i );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
if( !Selectable( collector[i], &aWhere ) )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
if( aCheckLocked && collector[i]->IsLocked() )
|
2019-06-14 11:00:39 +00:00
|
|
|
{
|
2020-10-02 20:18:07 +00:00
|
|
|
collector.Remove( i );
|
2019-06-14 11:00:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-09-06 15:11:56 +00:00
|
|
|
|
2024-02-25 22:39:14 +00:00
|
|
|
if( !itemPassesFilter( collector[i] ) )
|
|
|
|
{
|
|
|
|
collector.Remove( i );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:11:56 +00:00
|
|
|
if( aSelectedOnly && !collector[i]->IsSelected() )
|
|
|
|
{
|
|
|
|
collector.Remove( i );
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
|
2020-10-02 20:18:07 +00:00
|
|
|
if( collector.GetCount() > 1 && !m_skip_heuristics )
|
|
|
|
GuessSelectionCandidates( collector, aWhere );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
|
|
|
EDA_ITEM** aItem, bool* aSelectionCancelledFlag, bool aAdd,
|
|
|
|
bool aSubtract, bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
// If still more than one item we're going to have to ask the user.
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 1 )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2021-09-13 17:14:59 +00:00
|
|
|
// Try to call selectionMenu via RunAction() to avoid event-loop contention
|
|
|
|
// But it we cannot handle the event, then we don't have an active tool loop, so
|
|
|
|
// handle it directly.
|
2023-06-26 22:16:51 +00:00
|
|
|
if( !m_toolMgr->RunAction<COLLECTOR*>( EE_ACTIONS::selectionMenu, &aCollector ) )
|
2021-09-23 18:46:07 +00:00
|
|
|
{
|
|
|
|
if( !doSelectionMenu( &aCollector ) )
|
|
|
|
aCollector.m_MenuCancelled = true;
|
|
|
|
}
|
2021-09-13 17:14:59 +00:00
|
|
|
|
|
|
|
if( aCollector.m_MenuCancelled )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aSelectionCancelledFlag )
|
|
|
|
*aSelectionCancelledFlag = true;
|
|
|
|
|
2020-05-24 23:35:04 +00:00
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( !aAdd && !aSubtract && !aExclusiveOr )
|
|
|
|
ClearSelection();
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
int addedCount = 0;
|
2020-05-24 23:35:04 +00:00
|
|
|
bool anySubtracted = false;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aCollector.GetCount() > 0 )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2020-10-01 23:53:47 +00:00
|
|
|
for( int i = 0; i < aCollector.GetCount(); ++i )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
EDA_ITEM_FLAGS flags = 0;
|
2022-12-01 19:59:22 +00:00
|
|
|
bool isLine = aCollector[i]->Type() == SCH_LINE_T;
|
2022-03-03 14:35:57 +00:00
|
|
|
|
|
|
|
// Handle line ends specially
|
2022-12-01 19:59:22 +00:00
|
|
|
if( isLine )
|
2022-03-03 14:35:57 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) aCollector[i];
|
|
|
|
|
|
|
|
if( HitTestPoints( line->GetStartPoint(), aWhere, aCollector.m_Threshold ) )
|
|
|
|
flags = STARTPOINT;
|
|
|
|
else if( HitTestPoints( line->GetEndPoint(), aWhere, aCollector.m_Threshold ) )
|
|
|
|
flags = ENDPOINT;
|
|
|
|
else
|
|
|
|
flags = STARTPOINT | ENDPOINT;
|
|
|
|
}
|
|
|
|
|
2022-12-01 19:59:22 +00:00
|
|
|
if( aSubtract
|
|
|
|
|| ( aExclusiveOr && aCollector[i]->IsSelected()
|
|
|
|
&& ( !isLine || ( isLine && aCollector[i]->HasFlag( flags ) ) ) ) )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
aCollector[i]->ClearFlags( flags );
|
2022-07-12 01:03:45 +00:00
|
|
|
|
2023-12-19 19:29:17 +00:00
|
|
|
// Need to update end shadows after ctrl-click unselecting one of two selected
|
|
|
|
// endpoints.
|
2022-12-01 19:59:22 +00:00
|
|
|
if( isLine )
|
|
|
|
getView()->Update( aCollector[i] );
|
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
if( !aCollector[i]->HasFlag( STARTPOINT ) && !aCollector[i]->HasFlag( ENDPOINT ) )
|
|
|
|
{
|
|
|
|
unselect( aCollector[i] );
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
aCollector[i]->SetFlags( flags );
|
2020-10-01 23:53:47 +00:00
|
|
|
select( aCollector[i] );
|
2022-07-19 15:00:35 +00:00
|
|
|
addedCount++;
|
2020-05-24 23:35:04 +00:00
|
|
|
}
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
if( addedCount == 1 )
|
2020-05-24 23:35:04 +00:00
|
|
|
{
|
2022-07-19 15:00:35 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::PointSelectedEvent );
|
2020-05-24 23:35:04 +00:00
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
if( aItem && aCollector.GetCount() == 1 )
|
|
|
|
*aItem = aCollector[0];
|
2020-05-24 23:35:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-19 15:00:35 +00:00
|
|
|
else if( addedCount > 1 )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-24 23:35:04 +00:00
|
|
|
else if( anySubtracted )
|
|
|
|
{
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes,
|
2020-10-05 10:54:37 +00:00
|
|
|
EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
|
|
|
|
bool aCheckLocked, bool aAdd, bool aSubtract,
|
|
|
|
bool aExclusiveOr )
|
2020-10-01 23:53:47 +00:00
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
if( !CollectHits( collector, aWhere, aScanTypes ) )
|
2020-10-01 23:53:47 +00:00
|
|
|
return false;
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-09-06 15:11:56 +00:00
|
|
|
narrowSelection( collector, aWhere, aCheckLocked, aSubtract );
|
2020-10-01 23:53:47 +00:00
|
|
|
|
2022-03-03 14:35:57 +00:00
|
|
|
return selectPoint( collector, aWhere, aItem, aSelectionCancelledFlag, aAdd, aSubtract,
|
|
|
|
aExclusiveOr );
|
2020-10-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
// hold all visible items
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
|
|
|
|
|
|
|
|
// Filter the view items based on the selection box
|
|
|
|
BOX2I selectionBox;
|
|
|
|
|
|
|
|
selectionBox.SetMaximum();
|
|
|
|
view->Query( selectionBox, selectedItems ); // Get the list of selected items
|
|
|
|
|
|
|
|
// Sheet pins aren't in the view; add them by hand
|
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
int layer = pair.second;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
|
|
|
|
|
2020-12-14 21:11:33 +00:00
|
|
|
for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
|
2020-08-20 23:05:21 +00:00
|
|
|
{
|
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
|
|
|
|
{
|
2024-03-05 23:27:41 +00:00
|
|
|
if( Selectable( item ) && itemPassesFilter( item ) )
|
2022-04-11 18:32:16 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
item->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
select( item );
|
2022-04-11 18:32:16 +00:00
|
|
|
}
|
2020-08-20 23:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_multiple = false;
|
|
|
|
|
2022-11-13 22:53:41 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-06 23:44:39 +00:00
|
|
|
int EE_SELECTION_TOOL::UnselectAll( 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;
|
|
|
|
|
|
|
|
// Filter the view items based on the selection box
|
|
|
|
BOX2I selectionBox;
|
|
|
|
|
|
|
|
selectionBox.SetMaximum();
|
|
|
|
view->Query( selectionBox, selectedItems ); // Get the list of selected items
|
|
|
|
|
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pin );
|
2023-09-20 15:59:39 +00:00
|
|
|
|
|
|
|
if( item && Selectable( item ) )
|
2023-09-06 23:44:39 +00:00
|
|
|
unselect( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first ) )
|
|
|
|
{
|
|
|
|
if( Selectable( item ) )
|
|
|
|
unselect( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_multiple = false;
|
|
|
|
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 23:05:21 +00:00
|
|
|
|
2019-06-28 19:11:26 +00:00
|
|
|
void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-06-28 19:11:26 +00:00
|
|
|
// Prefer exact hits to sloppy ones
|
2021-09-19 10:05:58 +00:00
|
|
|
std::set<EDA_ITEM*> exactHits;
|
2019-06-26 18:43:37 +00:00
|
|
|
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
2019-05-16 23:48:39 +00:00
|
|
|
{
|
2022-07-19 08:47:34 +00:00
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( item );
|
2023-11-25 12:38:24 +00:00
|
|
|
SCH_TABLE* table = dynamic_cast<SCH_TABLE*>( item );
|
2019-05-16 23:48:39 +00:00
|
|
|
|
2021-09-21 17:15:41 +00:00
|
|
|
// Lines are hard to hit. Give them a bit more slop to still be considered "exact".
|
2023-01-07 23:02:03 +00:00
|
|
|
if( line || ( shape && shape->GetShape() == SHAPE_T::POLY )
|
|
|
|
|| ( shape && shape->GetShape() == SHAPE_T::ARC ) )
|
2021-09-21 17:15:41 +00:00
|
|
|
{
|
2023-01-07 23:02:03 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( 6 ) );
|
2022-07-19 08:47:34 +00:00
|
|
|
|
|
|
|
if( item->HitTest( aPos, pixelThreshold ) )
|
|
|
|
exactHits.insert( item );
|
|
|
|
}
|
2023-11-25 12:38:24 +00:00
|
|
|
else if( table )
|
|
|
|
{
|
|
|
|
// Consider table cells exact, but not the table itself
|
|
|
|
}
|
2021-09-21 17:15:41 +00:00
|
|
|
else
|
|
|
|
{
|
2024-05-06 17:36:20 +00:00
|
|
|
|
|
|
|
if( m_frame->GetRenderSettings()->m_ShowPinsElectricalType )
|
|
|
|
item->SetFlags( SHOW_ELEC_TYPE );
|
|
|
|
|
2022-02-14 00:53:47 +00:00
|
|
|
if( item->HitTest( aPos, 0 ) )
|
2021-09-21 17:15:41 +00:00
|
|
|
exactHits.insert( item );
|
2024-05-06 17:36:20 +00:00
|
|
|
|
|
|
|
item->ClearFlags( SHOW_ELEC_TYPE );
|
2021-09-21 17:15:41 +00:00
|
|
|
}
|
2019-05-16 23:48:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
|
2019-06-26 18:43:37 +00:00
|
|
|
{
|
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[ i ];
|
|
|
|
|
2024-04-20 20:50:40 +00:00
|
|
|
if( !exactHits.contains( item ) )
|
2020-07-07 04:51:12 +00:00
|
|
|
collector.Transfer( item );
|
2019-06-26 18:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
// Find the closest item. (Note that at this point all hits are either exact or non-exact.)
|
2024-04-27 12:47:56 +00:00
|
|
|
SEG poss( aPos, aPos );
|
2020-09-19 14:55:05 +00:00
|
|
|
EDA_ITEM* closest = nullptr;
|
2024-02-19 09:25:17 +00:00
|
|
|
int closestDist = INT_MAX / 4;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : collector )
|
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = item->GetBoundingBox();
|
2024-02-19 09:25:17 +00:00
|
|
|
int dist = INT_MAX / 4;
|
2021-09-19 10:05:58 +00:00
|
|
|
|
2024-05-23 03:25:28 +00:00
|
|
|
// A dominating item is one that would unfairly win distance tests
|
|
|
|
// and mask out other items. For example, a filled rectangle "wins"
|
|
|
|
// with a zero distance over anything inside it.
|
|
|
|
bool dominating = false;
|
|
|
|
|
2024-04-20 20:50:40 +00:00
|
|
|
if( exactHits.contains( item ) )
|
2021-09-19 10:05:58 +00:00
|
|
|
{
|
2021-09-23 22:58:46 +00:00
|
|
|
if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
closest = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
2023-10-03 13:35:46 +00:00
|
|
|
SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( item );
|
2021-11-01 21:05:30 +00:00
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
2024-02-19 09:25:17 +00:00
|
|
|
EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( item );
|
2021-11-01 21:05:30 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
2021-09-21 17:15:41 +00:00
|
|
|
|
2021-09-23 22:58:46 +00:00
|
|
|
if( line )
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
dist = KiROUND( DistanceLinePoint( line->GetStartPoint(),
|
2024-04-20 20:50:40 +00:00
|
|
|
line->GetEndPoint(), aPos ) );
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
2023-10-03 13:35:46 +00:00
|
|
|
else if( field )
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2023-10-03 13:35:46 +00:00
|
|
|
BOX2I box = field->GetBoundingBox();
|
|
|
|
EDA_ANGLE orient = field->GetTextAngle();
|
|
|
|
|
|
|
|
if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
|
2022-11-23 13:19:23 +00:00
|
|
|
{
|
2023-10-03 13:35:46 +00:00
|
|
|
if( static_cast<SCH_SYMBOL*>( field->GetParent() )->GetTransform().y1 )
|
2022-11-23 13:19:23 +00:00
|
|
|
{
|
2023-10-03 13:35:46 +00:00
|
|
|
if( orient.IsHorizontal() )
|
|
|
|
orient = ANGLE_VERTICAL;
|
|
|
|
else
|
|
|
|
orient = ANGLE_HORIZONTAL;
|
2022-11-23 13:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 09:25:17 +00:00
|
|
|
field->GetEffectiveTextShape( false, box, orient )
|
|
|
|
->Collide( poss, INT_MAX / 4, &dist );
|
2023-10-03 13:35:46 +00:00
|
|
|
}
|
|
|
|
else if( text )
|
|
|
|
{
|
2024-02-19 09:25:17 +00:00
|
|
|
text->GetEffectiveTextShape( false )->Collide( poss, INT_MAX / 4, &dist );
|
|
|
|
}
|
|
|
|
else if( shape )
|
|
|
|
{
|
|
|
|
std::vector<SHAPE*> shapes = shape->MakeEffectiveShapes();
|
|
|
|
|
|
|
|
for( SHAPE* s : shapes )
|
|
|
|
{
|
|
|
|
int shapeDist = dist;
|
|
|
|
s->Collide( poss, INT_MAX / 4, &shapeDist );
|
|
|
|
|
|
|
|
if( shapeDist < dist )
|
|
|
|
dist = shapeDist;
|
|
|
|
|
|
|
|
delete s;
|
|
|
|
}
|
2024-05-23 03:25:28 +00:00
|
|
|
|
|
|
|
// Filled shapes win hit tests anywhere inside them
|
|
|
|
dominating = shape->IsFilled();
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
else if( symbol )
|
|
|
|
{
|
2023-10-03 13:35:46 +00:00
|
|
|
bbox = symbol->GetBodyBoundingBox();
|
2021-11-13 16:38:19 +00:00
|
|
|
|
2021-11-01 21:05:30 +00:00
|
|
|
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
|
|
|
|
2024-04-20 20:50:40 +00:00
|
|
|
if( bbox.Contains( aPos ) )
|
|
|
|
dist = KiROUND( EuclideanNorm( bbox.GetCenter() - aPos ) );
|
2021-11-01 21:05:30 +00:00
|
|
|
else
|
|
|
|
rect.Collide( poss, closestDist, &dist );
|
|
|
|
}
|
2021-09-21 17:15:41 +00:00
|
|
|
else
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2024-04-20 20:50:40 +00:00
|
|
|
dist = KiROUND( EuclideanNorm( bbox.GetCenter() - aPos ) );
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
2021-09-19 10:05:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
2021-11-01 21:05:30 +00:00
|
|
|
rect.Collide( poss, collector.m_Threshold, &dist );
|
2021-09-19 10:05:58 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:25:28 +00:00
|
|
|
// Don't promote dominating items to be the closest item
|
|
|
|
// (they'll always win) - they'll still be available for selection, but they
|
|
|
|
// won't boot out worthy competitors.
|
|
|
|
if ( !dominating )
|
2022-03-19 16:36:32 +00:00
|
|
|
{
|
2024-05-23 03:25:28 +00:00
|
|
|
if( dist == closestDist )
|
|
|
|
{
|
|
|
|
if( item->GetParent() == closest )
|
|
|
|
closest = item;
|
|
|
|
}
|
|
|
|
else if( dist < closestDist )
|
|
|
|
{
|
|
|
|
closestDist = dist;
|
2022-03-19 16:36:32 +00:00
|
|
|
closest = item;
|
2024-05-23 03:25:28 +00:00
|
|
|
}
|
2020-09-19 14:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
// Construct a tight box (1/2 height and width) around the center of the closest item.
|
|
|
|
// All items which exist at least partly outside this box have sufficient other areas
|
|
|
|
// for selection and can be dropped.
|
2020-09-30 02:28:23 +00:00
|
|
|
if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
|
2020-09-19 14:55:05 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I tightBox = closest->GetBoundingBox();
|
2020-09-30 02:28:23 +00:00
|
|
|
tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = collector[i];
|
|
|
|
|
|
|
|
if( item == closest )
|
|
|
|
continue;
|
2020-09-19 14:55:05 +00:00
|
|
|
|
2020-09-30 02:28:23 +00:00
|
|
|
if( !item->HitTest( tightBox, true ) )
|
|
|
|
collector.Transfer( item );
|
|
|
|
}
|
2020-09-19 14:55:05 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const std::vector<KICAD_T>& aScanTypes,
|
|
|
|
bool aPromoteCellSelections )
|
2019-04-23 12:51:48 +00:00
|
|
|
{
|
2023-11-25 12:38:24 +00:00
|
|
|
bool anyUnselected = false;
|
|
|
|
bool anySelected = false;
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
if( m_selection.Empty() )
|
|
|
|
{
|
|
|
|
VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
|
|
|
|
|
|
|
|
ClearSelection();
|
2022-08-21 19:54:07 +00:00
|
|
|
SelectPoint( cursorPos, aScanTypes );
|
2020-03-06 20:02:58 +00:00
|
|
|
m_selection.SetIsHover( true );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
}
|
|
|
|
else // Trim an existing selection by aFilterList
|
2019-04-23 17:12:10 +00:00
|
|
|
{
|
2021-10-18 12:24:06 +00:00
|
|
|
bool isMoving = false;
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
|
2019-04-27 23:50:35 +00:00
|
|
|
{
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
|
2021-11-06 16:03:41 +00:00
|
|
|
isMoving |= static_cast<SCH_ITEM*>( item )->IsMoving();
|
2019-04-23 17:12:10 +00:00
|
|
|
|
2022-08-21 19:54:07 +00:00
|
|
|
if( !item->IsType( aScanTypes ) )
|
2019-07-09 19:50:40 +00:00
|
|
|
{
|
|
|
|
unselect( item );
|
2022-07-03 17:23:08 +00:00
|
|
|
anyUnselected = true;
|
2019-07-09 19:50:40 +00:00
|
|
|
}
|
2019-04-23 17:12:10 +00:00
|
|
|
}
|
2019-05-20 15:42:49 +00:00
|
|
|
|
2021-10-18 12:24:06 +00:00
|
|
|
if( !isMoving )
|
|
|
|
updateReferencePoint();
|
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
if( aPromoteCellSelections )
|
|
|
|
{
|
|
|
|
std::set<EDA_ITEM*> parents;
|
|
|
|
|
|
|
|
for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
|
|
|
|
|
|
|
|
if( item->Type() == SCH_TABLECELL_T )
|
|
|
|
{
|
|
|
|
parents.insert( item->GetParent() );
|
|
|
|
unselect( item );
|
|
|
|
anyUnselected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( EDA_ITEM* parent : parents )
|
|
|
|
{
|
|
|
|
if( !parent->IsSelected() )
|
|
|
|
{
|
|
|
|
select( parent );
|
|
|
|
anySelected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( anyUnselected )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
|
|
|
if( anySelected )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
return m_selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-25 22:39:14 +00:00
|
|
|
bool EE_SELECTION_TOOL::itemPassesFilter( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
if( !aItem )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Locking is not yet exposed uniformly in the schematic
|
|
|
|
#if 0
|
|
|
|
if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( schItem->IsLocked() && !m_filter.lockedItems )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
if( !m_filter.symbols )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_PIN_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
if( !m_filter.pins )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
switch( static_cast<SCH_LINE*>( aItem )->GetLayer() )
|
|
|
|
{
|
|
|
|
case LAYER_WIRE:
|
|
|
|
case LAYER_BUS:
|
|
|
|
if( !m_filter.wires )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if( !m_filter.graphics )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_SHAPE_T:
|
|
|
|
if( !m_filter.graphics )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
case SCH_TABLE_T:
|
|
|
|
case SCH_TABLECELL_T:
|
|
|
|
case SCH_FIELD_T:
|
|
|
|
if( !m_filter.text )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
if( !m_filter.labels )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_BITMAP_T:
|
|
|
|
if( !m_filter.images )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if( !m_filter.otherItems )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
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 )
|
2024-04-06 13:14:44 +00:00
|
|
|
refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
|
2019-05-07 09:38:34 +00:00
|
|
|
|
2019-05-22 21:09:20 +00:00
|
|
|
m_selection.SetReferencePoint( refP );
|
2019-04-23 12:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-07 23:00:39 +00:00
|
|
|
// Some navigation actions are allowed in selectMultiple
|
|
|
|
const TOOL_ACTION* allowedActions[] = { &ACTIONS::panUp, &ACTIONS::panDown,
|
|
|
|
&ACTIONS::panLeft, &ACTIONS::panRight,
|
|
|
|
&ACTIONS::cursorUp, &ACTIONS::cursorDown,
|
|
|
|
&ACTIONS::cursorLeft, &ACTIONS::cursorRight,
|
|
|
|
&ACTIONS::cursorUpFast, &ACTIONS::cursorDownFast,
|
|
|
|
&ACTIONS::cursorLeftFast, &ACTIONS::cursorRightFast,
|
|
|
|
&ACTIONS::zoomIn, &ACTIONS::zoomOut,
|
|
|
|
&ACTIONS::zoomInCenter, &ACTIONS::zoomOutCenter,
|
|
|
|
&ACTIONS::zoomCenter, &ACTIONS::zoomFitScreen,
|
|
|
|
&ACTIONS::zoomFitObjects, nullptr };
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectMultiple()
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
bool cancelled = false; // Was the tool canceled while it was running?
|
2019-04-23 17:40:29 +00:00
|
|
|
m_multiple = true; // Multiple selection mode is active
|
2022-07-23 13:08:51 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
KIGFX::PREVIEW::SELECTION_AREA area;
|
|
|
|
view->Add( &area );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2020-10-09 01:24:26 +00:00
|
|
|
int width = area.GetEnd().x - area.GetOrigin().x;
|
2021-12-10 18:43:35 +00:00
|
|
|
int height = area.GetEnd().y - area.GetOrigin().y;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
|
|
|
/* Selection mode depends on direction of drag-selection:
|
|
|
|
* Left > Right : Select objects that are fully enclosed by selection
|
|
|
|
* Right > Left : Select objects that are crossed by selection
|
|
|
|
*/
|
2022-10-10 19:16:54 +00:00
|
|
|
bool isGreedy = width < 0;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
|
|
|
if( view->IsMirroredX() )
|
2022-10-10 19:16:54 +00:00
|
|
|
isGreedy = !isGreedy;
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2022-10-10 19:16:54 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( isGreedy ? KICURSOR::SELECT_LASSO
|
|
|
|
: KICURSOR::SELECT_WINDOW );
|
2020-10-09 01:24:26 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2021-09-05 20:37:52 +00:00
|
|
|
if( !m_drag_additive && !m_drag_subtractive )
|
2019-07-09 19:50:40 +00:00
|
|
|
ClearSelection();
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Start drawing a selection box
|
|
|
|
area.SetOrigin( evt->DragOrigin() );
|
|
|
|
area.SetEnd( evt->Position() );
|
2021-09-05 20:37:52 +00:00
|
|
|
area.SetAdditive( m_drag_additive );
|
|
|
|
area.SetSubtractive( m_drag_subtractive );
|
|
|
|
area.SetExclusiveOr( false );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
view->SetVisible( &area, true );
|
|
|
|
view->Update( &area );
|
|
|
|
getViewControls()->SetAutoPan( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsMouseUp( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
// End drawing the selection box
|
|
|
|
view->SetVisible( &area, false );
|
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
// Fetch items from the RTree that are in our area of interest
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> nearbyViewItems;
|
|
|
|
view->Query( area.ViewBBox(), nearbyViewItems );
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
// Build lists of nearby items and their children
|
2022-07-23 14:09:16 +00:00
|
|
|
std::unordered_set<EDA_ITEM*> nearbyItems;
|
|
|
|
std::vector<EDA_ITEM*> nearbyChildren;
|
|
|
|
std::vector<EDA_ITEM*> flaggedItems;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2022-07-23 13:08:51 +00:00
|
|
|
if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first ) )
|
2019-08-27 20:08:09 +00:00
|
|
|
{
|
2022-07-23 14:09:16 +00:00
|
|
|
if( nearbyItems.insert( item ).second )
|
2022-07-23 13:08:51 +00:00
|
|
|
{
|
2022-07-23 14:09:16 +00:00
|
|
|
item->ClearFlags( CANDIDATE );
|
|
|
|
|
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
2022-09-09 12:39:55 +00:00
|
|
|
// Filter pins by unit
|
2023-06-24 17:19:44 +00:00
|
|
|
if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aChild ) )
|
2022-09-09 12:39:55 +00:00
|
|
|
{
|
|
|
|
int unit = pin->GetLibPin()->GetUnit();
|
|
|
|
|
|
|
|
if( unit && unit != pin->GetParentSymbol()->GetUnit() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-23 14:09:16 +00:00
|
|
|
nearbyChildren.push_back( aChild );
|
|
|
|
} );
|
|
|
|
}
|
2022-07-23 13:08:51 +00:00
|
|
|
}
|
2021-03-07 14:32:49 +00:00
|
|
|
}
|
2019-08-27 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
BOX2I selectionRect( area.GetOrigin(), VECTOR2I( width, height ) );
|
2021-12-10 18:43:35 +00:00
|
|
|
selectionRect.Normalize();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
2022-02-10 18:38:40 +00:00
|
|
|
|
2022-10-10 19:16:54 +00:00
|
|
|
auto selectItem =
|
2022-12-10 18:16:28 +00:00
|
|
|
[&]( EDA_ITEM* aItem, EDA_ITEM_FLAGS flags )
|
2022-10-10 19:16:54 +00:00
|
|
|
{
|
|
|
|
if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
|
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
if ( m_exclusive_or )
|
|
|
|
aItem->XorFlags( flags );
|
|
|
|
else
|
|
|
|
aItem->ClearFlags( flags );
|
2022-10-10 19:16:54 +00:00
|
|
|
|
|
|
|
if( !aItem->HasFlag( STARTPOINT ) && !aItem->HasFlag( ENDPOINT ) )
|
|
|
|
{
|
|
|
|
unselect( aItem );
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
2022-12-10 18:16:28 +00:00
|
|
|
|
|
|
|
// We changed one line endpoint on a selected line,
|
|
|
|
// update the view at least.
|
|
|
|
if( flags && !anySubtracted )
|
|
|
|
getView()->Update( aItem );
|
2022-10-10 19:16:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aItem->SetFlags( flags );
|
|
|
|
select( aItem );
|
|
|
|
anyAdded = true;
|
|
|
|
}
|
|
|
|
};
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-12 17:38:16 +00:00
|
|
|
for( EDA_ITEM* item : nearbyItems )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
bool selected = false;
|
|
|
|
EDA_ITEM_FLAGS flags = 0;
|
|
|
|
|
2022-07-23 22:26:03 +00:00
|
|
|
if( m_frame->GetRenderSettings()->m_ShowPinsElectricalType )
|
|
|
|
item->SetFlags( SHOW_ELEC_TYPE );
|
|
|
|
|
2024-02-25 22:39:14 +00:00
|
|
|
if( Selectable( item ) && itemPassesFilter( item ) )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
2022-12-12 20:04:33 +00:00
|
|
|
if( ( isGreedy && line->HitTest( selectionRect, false ) )
|
|
|
|
|| ( selectionRect.Contains( line->GetEndPoint() )
|
|
|
|
&& selectionRect.Contains( line->GetStartPoint() ) ) )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= STARTPOINT | ENDPOINT;
|
|
|
|
}
|
|
|
|
else if( !isGreedy )
|
|
|
|
{
|
2022-12-12 20:04:33 +00:00
|
|
|
if( selectionRect.Contains( line->GetStartPoint() )
|
|
|
|
&& line->IsStartDangling() )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= STARTPOINT;
|
|
|
|
}
|
|
|
|
|
2022-12-12 20:04:33 +00:00
|
|
|
if( selectionRect.Contains( line->GetEndPoint() )
|
|
|
|
&& line->IsEndDangling() )
|
2022-12-10 18:16:28 +00:00
|
|
|
{
|
|
|
|
selected = true;
|
|
|
|
flags |= ENDPOINT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selected = item->HitTest( selectionRect, !isGreedy );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( selected )
|
2021-12-10 18:43:35 +00:00
|
|
|
{
|
2022-03-03 14:35:57 +00:00
|
|
|
item->SetFlags( CANDIDATE );
|
2022-04-16 22:44:34 +00:00
|
|
|
flaggedItems.push_back( item );
|
2022-12-10 18:16:28 +00:00
|
|
|
selectItem( item, flags );
|
2021-12-10 18:43:35 +00:00
|
|
|
}
|
2022-07-23 22:26:03 +00:00
|
|
|
|
|
|
|
item->ClearFlags( SHOW_ELEC_TYPE );
|
2021-12-10 18:43:35 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-12-12 17:38:16 +00:00
|
|
|
for( EDA_ITEM* item : nearbyChildren )
|
2021-12-10 18:43:35 +00:00
|
|
|
{
|
2022-07-23 22:26:03 +00:00
|
|
|
if( m_frame->GetRenderSettings()->m_ShowPinsElectricalType )
|
|
|
|
item->SetFlags( SHOW_ELEC_TYPE );
|
|
|
|
|
2021-12-10 18:43:35 +00:00
|
|
|
if( Selectable( item )
|
2024-02-25 22:39:14 +00:00
|
|
|
&& itemPassesFilter( item )
|
2022-03-03 14:35:57 +00:00
|
|
|
&& !item->GetParent()->HasFlag( CANDIDATE )
|
2022-10-10 19:16:54 +00:00
|
|
|
&& item->HitTest( selectionRect, !isGreedy ) )
|
2019-04-23 17:40:29 +00:00
|
|
|
{
|
2022-12-10 18:16:28 +00:00
|
|
|
selectItem( item, 0 );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
2022-07-23 22:26:03 +00:00
|
|
|
|
|
|
|
item->ClearFlags( SHOW_ELEC_TYPE );
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-16 22:44:34 +00:00
|
|
|
for( EDA_ITEM* item : flaggedItems )
|
|
|
|
item->ClearFlags( CANDIDATE );
|
|
|
|
|
2019-06-13 18:57:11 +00:00
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
// Inform other potentially interested tools
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anyAdded )
|
2019-04-23 17:40:29 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
2019-07-09 19:50:40 +00:00
|
|
|
if( anySubtracted )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
break; // Stop waiting for events
|
|
|
|
}
|
2021-12-07 23:00:39 +00:00
|
|
|
|
|
|
|
// Allow some actions for navigation
|
|
|
|
for( int i = 0; allowedActions[i]; ++i )
|
|
|
|
{
|
|
|
|
if( evt->IsAction( allowedActions[i] ) )
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
// Stop drawing the selection box
|
|
|
|
view->Remove( &area );
|
|
|
|
m_multiple = false; // Multiple selection mode is inactive
|
|
|
|
|
|
|
|
if( !cancelled )
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectTableCells( SCH_TABLE* aTable )
|
|
|
|
{
|
|
|
|
bool cancelled = false; // Was the tool canceled while it was running?
|
|
|
|
m_multiple = true; // Multiple selection mode is active
|
|
|
|
|
|
|
|
for( SCH_TABLECELL* cell : aTable->GetCells() )
|
|
|
|
{
|
|
|
|
if( cell->IsSelected() )
|
|
|
|
cell->SetFlags( CANDIDATE );
|
|
|
|
else
|
|
|
|
cell->ClearFlags( CANDIDATE );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto wasSelected =
|
|
|
|
[]( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return ( aItem->GetFlags() & CANDIDATE ) > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
getViewControls()->SetAutoPan( true );
|
|
|
|
|
|
|
|
BOX2I selectionRect( evt->DragOrigin(), evt->Position() - evt->DragOrigin() );
|
|
|
|
selectionRect.Normalize();
|
|
|
|
|
|
|
|
for( SCH_TABLECELL* cell : aTable->GetCells() )
|
|
|
|
{
|
|
|
|
bool doSelect = false;
|
|
|
|
|
|
|
|
if( cell->HitTest( selectionRect, false ) )
|
|
|
|
{
|
|
|
|
if( m_subtractive )
|
|
|
|
doSelect = false;
|
|
|
|
else if( m_exclusive_or )
|
|
|
|
doSelect = !wasSelected( cell );
|
|
|
|
else
|
|
|
|
doSelect = true;
|
|
|
|
}
|
|
|
|
else if( wasSelected( cell ) )
|
|
|
|
{
|
|
|
|
doSelect = m_additive || m_subtractive || m_exclusive_or;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( doSelect && !cell->IsSelected() )
|
|
|
|
select( cell );
|
|
|
|
else if( !doSelect && cell->IsSelected() )
|
|
|
|
unselect( cell );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
|
|
|
|
bool anyAdded = false;
|
|
|
|
bool anySubtracted = false;
|
|
|
|
|
|
|
|
for( SCH_TABLECELL* cell : aTable->GetCells() )
|
|
|
|
{
|
|
|
|
if( cell->IsSelected() && !wasSelected( cell ) )
|
|
|
|
anyAdded = true;
|
|
|
|
else if( wasSelected( cell ) && !cell->IsSelected() )
|
|
|
|
anySubtracted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
if( anyAdded )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
if( anySubtracted )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
|
|
|
|
|
|
|
|
break; // Stop waiting for events
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Allow some actions for navigation
|
|
|
|
for( int i = 0; allowedActions[i]; ++i )
|
|
|
|
{
|
|
|
|
if( evt->IsAction( allowedActions[i] ) )
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
|
|
|
|
m_multiple = false; // Multiple selection mode is inactive
|
|
|
|
|
|
|
|
if( !cancelled )
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
return cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-15 22:11:24 +00:00
|
|
|
EDA_ITEM* EE_SELECTION_TOOL::GetNode( const VECTOR2I& aPosition )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2019-05-10 19:22:26 +00:00
|
|
|
EE_COLLECTOR collector;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
//TODO(snh): Reimplement after exposing KNN interface
|
2021-09-19 10:05:58 +00:00
|
|
|
int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
|
|
|
|
int thresholdMax = std::max( pixelThreshold, gridThreshold );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
|
2019-05-15 17:00:49 +00:00
|
|
|
{
|
|
|
|
collector.m_Threshold = threshold;
|
2022-08-20 09:27:35 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), connectedTypes, aPosition );
|
2019-05-15 17:00:49 +00:00
|
|
|
|
|
|
|
if( collector.GetCount() > 0 )
|
|
|
|
break;
|
|
|
|
}
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
return collector.GetCount() ? collector[ 0 ] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2021-05-09 17:14:41 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
SelectPoint( cursorPos, connectedTypes );
|
2019-04-30 13:54:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
|
2019-04-30 13:54:32 +00:00
|
|
|
{
|
2023-08-02 01:22:35 +00:00
|
|
|
RequestSelection( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_ITEM_LOCATE_GRAPHIC_LINE_T } );
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2022-05-29 21:51:07 +00:00
|
|
|
unsigned done = false;
|
2019-04-30 13:54:32 +00:00
|
|
|
|
|
|
|
m_frame->GetScreen()->ClearDrawingState();
|
|
|
|
|
2023-08-03 15:27:29 +00:00
|
|
|
for( EDA_ITEM* selItem : m_selection.GetItems() )
|
2022-05-29 21:51:07 +00:00
|
|
|
{
|
2023-08-03 15:27:29 +00:00
|
|
|
if( selItem->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
2022-05-29 21:51:07 +00:00
|
|
|
|
2023-08-03 15:27:29 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( selItem );
|
2022-05-29 21:51:07 +00:00
|
|
|
|
2023-08-03 15:27:29 +00:00
|
|
|
std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line, false );
|
2022-05-29 21:51:07 +00:00
|
|
|
for( SCH_ITEM* item : conns )
|
2023-08-03 15:27:29 +00:00
|
|
|
{
|
|
|
|
if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T,
|
|
|
|
SCH_ITEM_LOCATE_GRAPHIC_LINE_T } )
|
|
|
|
&& !item->IsSelected() )
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
2022-05-29 21:51:07 +00:00
|
|
|
select( item );
|
2023-08-03 15:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !done )
|
|
|
|
{
|
|
|
|
conns = m_frame->GetScreen()->MarkConnections( line, true );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : conns )
|
|
|
|
select( item );
|
|
|
|
}
|
2022-05-29 21:51:07 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
int EE_SELECTION_TOOL::SelectColumns( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
std::set<std::pair<SCH_TABLE*, int>> columns;
|
|
|
|
bool added = false;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
|
|
|
if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
|
|
|
|
{
|
|
|
|
SCH_TABLE* table = static_cast<SCH_TABLE*>( cell->GetParent() );
|
|
|
|
columns.insert( std::make_pair( table, cell->GetColumn() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& [ table, col ] : columns )
|
|
|
|
{
|
|
|
|
for( int row = 0; row < table->GetRowCount(); ++row )
|
|
|
|
{
|
|
|
|
SCH_TABLECELL* cell = table->GetCell( row, col );
|
|
|
|
|
|
|
|
if( !cell->IsSelected() )
|
|
|
|
{
|
|
|
|
select( table->GetCell( row, col ) );
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( added )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EE_SELECTION_TOOL::SelectRows( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
std::set<std::pair<SCH_TABLE*, int>> rows;
|
|
|
|
bool added = false;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
|
|
|
if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
|
|
|
|
{
|
|
|
|
SCH_TABLE* table = static_cast<SCH_TABLE*>( cell->GetParent() );
|
|
|
|
rows.insert( std::make_pair( table, cell->GetRow() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& [ table, row ] : rows )
|
|
|
|
{
|
2024-03-10 20:54:59 +00:00
|
|
|
for( int col = 0; col < table->GetColCount(); ++col )
|
2023-11-25 12:38:24 +00:00
|
|
|
{
|
|
|
|
SCH_TABLECELL* cell = table->GetCell( row, col );
|
|
|
|
|
|
|
|
if( !cell->IsSelected() )
|
|
|
|
{
|
|
|
|
select( table->GetCell( row, col ) );
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( added )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EE_SELECTION_TOOL::SelectTable( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
std::set<SCH_TABLE*> tables;
|
|
|
|
bool added = false;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_selection )
|
|
|
|
{
|
|
|
|
if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
|
|
|
|
tables.insert( static_cast<SCH_TABLE*>( cell->GetParent() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSelection();
|
|
|
|
|
|
|
|
for( SCH_TABLE* table : tables )
|
|
|
|
{
|
|
|
|
if( !table->IsSelected() )
|
|
|
|
{
|
|
|
|
select( table );
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( added )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
ClearSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
void EE_SELECTION_TOOL::ZoomFitCrossProbeBBox( const BOX2I& aBBox )
|
2022-07-19 15:00:35 +00:00
|
|
|
{
|
2022-08-31 12:56:58 +00:00
|
|
|
if( aBBox.GetWidth() == 0 )
|
2022-07-19 15:00:35 +00:00
|
|
|
return;
|
|
|
|
|
2022-08-31 12:56:58 +00:00
|
|
|
BOX2I bbox = aBBox;
|
2022-07-19 15:00:35 +00:00
|
|
|
bbox.Normalize();
|
|
|
|
|
2024-04-20 20:50:40 +00:00
|
|
|
VECTOR2I bbSize = bbox.Inflate( KiROUND( bbox.GetWidth() * 0.2f ) ).GetSize();
|
2022-07-19 15:00:35 +00:00
|
|
|
VECTOR2D screenSize = getView()->GetViewport().GetSize();
|
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// This code tries to come up with a zoom factor that doesn't simply zoom in to the cross
|
|
|
|
// probed symbol, but instead shows a reasonable amount of the circuit around it to provide
|
|
|
|
// context. This reduces the need to manually change the zoom because it's too close.
|
|
|
|
|
|
|
|
// Using the default text height as a constant to compare against, use the height of the
|
|
|
|
// bounding box of visible items for a footprint to figure out if this is a big symbol (like
|
|
|
|
// a processor) or a small symbol (like a resistor). This ratio is not useful by itself as a
|
|
|
|
// scaling factor. It must be "bent" to provide good scaling at varying symbol sizes. Bigger
|
|
|
|
// symbols need less scaling than small ones.
|
2022-09-16 23:42:20 +00:00
|
|
|
double currTextHeight = schIUScale.MilsToIU( DEFAULT_TEXT_SIZE );
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
double compRatio = bbSize.y / currTextHeight; // Ratio of symbol to text height
|
|
|
|
double compRatioBent = 1.0;
|
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// LUT to scale zoom ratio to provide reasonable schematic context. Must work with symbols
|
|
|
|
// of varying sizes (e.g. 0402 package and 200 pin BGA).
|
|
|
|
// Each entry represents a compRatio (symbol height / default text height) and an amount to
|
|
|
|
// scale by.
|
|
|
|
std::vector<std::pair<double, double>> lut{ { 1.25, 16 },
|
|
|
|
{ 2.5, 12 },
|
|
|
|
{ 5, 8 },
|
|
|
|
{ 6, 6 },
|
|
|
|
{ 10, 4 },
|
|
|
|
{ 20, 2 },
|
|
|
|
{ 40, 1.5 },
|
|
|
|
{ 100, 1 } };
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
std::vector<std::pair<double, double>>::iterator it;
|
|
|
|
|
|
|
|
// Large symbol default is last LUT entry (1:1).
|
|
|
|
compRatioBent = lut.back().second;
|
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// Use LUT to do linear interpolation of "compRatio" within "first", then use that result to
|
|
|
|
// linearly interpolate "second" which gives the scaling factor needed.
|
2022-07-19 15:00:35 +00:00
|
|
|
if( compRatio >= lut.front().first )
|
|
|
|
{
|
2024-04-20 20:50:40 +00:00
|
|
|
for( it = lut.begin(); it < lut.end() - 1; ++it )
|
2022-07-19 15:00:35 +00:00
|
|
|
{
|
|
|
|
if( it->first <= compRatio && next( it )->first >= compRatio )
|
|
|
|
{
|
|
|
|
double diffx = compRatio - it->first;
|
|
|
|
double diffn = next( it )->first - it->first;
|
|
|
|
|
|
|
|
compRatioBent = it->second + ( next( it )->second - it->second ) * diffx / diffn;
|
|
|
|
break; // We have our interpolated value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compRatioBent = lut.front().second; // Small symbol default is first entry
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// This is similar to the original KiCad code that scaled the zoom to make sure symbols were
|
|
|
|
// visible on screen. It's simply a ratio of screen size to symbol size, and its job is to
|
|
|
|
// zoom in to make the component fullscreen. Earlier in the code the symbol BBox is given a
|
|
|
|
// 20% margin to add some breathing room. We compare the height of this enlarged symbol bbox
|
|
|
|
// to the default text height. If a symbol will end up with the sides clipped, we adjust
|
|
|
|
// later to make sure it fits on screen.
|
2022-07-19 15:00:35 +00:00
|
|
|
screenSize.x = std::max( 10.0, screenSize.x );
|
|
|
|
screenSize.y = std::max( 10.0, screenSize.y );
|
|
|
|
double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
|
|
|
|
|
|
|
|
// Original KiCad code for how much to scale the zoom
|
2024-04-17 10:03:07 +00:00
|
|
|
double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
|
|
|
|
fabs( bbSize.y / screenSize.y ) );
|
2022-07-19 15:00:35 +00:00
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// If the width of the part we're probing is bigger than what the screen width will be after
|
|
|
|
// the zoom, then punt and use the KiCad zoom algorithm since it guarantees the part's width
|
|
|
|
// will be encompassed within the screen.
|
2022-07-19 15:00:35 +00:00
|
|
|
if( bbSize.x > screenSize.x * ratio * compRatioBent )
|
|
|
|
{
|
|
|
|
// Use standard KiCad zoom for parts too wide to fit on screen/
|
|
|
|
ratio = kicadRatio;
|
|
|
|
compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
|
|
|
|
wxLogTrace( "CROSS_PROBE_SCALE",
|
|
|
|
"Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f", ratio );
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:03:07 +00:00
|
|
|
// Now that "compRatioBent" holds our final scaling factor we apply it to the original
|
|
|
|
// fullscreen zoom ratio to arrive at the final ratio itself.
|
2022-07-19 15:00:35 +00:00
|
|
|
ratio *= compRatioBent;
|
|
|
|
|
|
|
|
bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
|
|
|
|
|
|
|
|
// Try not to zoom on every cross-probe; it gets very noisy
|
|
|
|
if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
|
|
|
|
getView()->SetScale( getView()->GetScale() / ratio );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-15 22:11:24 +00:00
|
|
|
void EE_SELECTION_TOOL::SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath,
|
|
|
|
SCH_ITEM* focusItem, const std::vector<SCH_ITEM*>& items )
|
2022-07-19 15:00:35 +00:00
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
|
|
|
|
|
2023-07-15 22:11:24 +00:00
|
|
|
if( !editFrame )
|
|
|
|
return;
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
if( targetSheetPath && targetSheetPath != editFrame->Schematic().CurrentSheet() )
|
|
|
|
{
|
|
|
|
editFrame->Schematic().SetCurrentSheet( *targetSheetPath );
|
|
|
|
editFrame->DisplayCurrentSheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSelection( items.size() > 0 ? true /*quiet mode*/ : false );
|
|
|
|
|
|
|
|
// Perform individual selection of each item before processing the event.
|
|
|
|
for( SCH_ITEM* item : items )
|
2023-08-07 17:49:27 +00:00
|
|
|
{
|
2024-02-08 14:01:23 +00:00
|
|
|
SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( item->GetParent() );
|
|
|
|
|
2023-08-07 17:49:27 +00:00
|
|
|
// Make sure we only select items on the current screen
|
2024-02-08 14:01:23 +00:00
|
|
|
if( m_frame->GetScreen()->CheckIfOnDrawList( item )
|
|
|
|
|| ( parent && m_frame->GetScreen()->CheckIfOnDrawList( parent ) ) )
|
|
|
|
{
|
2023-08-07 17:49:27 +00:00
|
|
|
select( item );
|
2024-02-08 14:01:23 +00:00
|
|
|
}
|
2023-08-07 17:49:27 +00:00
|
|
|
}
|
2022-07-19 15:00:35 +00:00
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = m_selection.GetBoundingBox();
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
|
|
|
|
{
|
|
|
|
if( m_frame->eeconfig()->m_CrossProbing.center_on_items )
|
|
|
|
{
|
|
|
|
if( m_frame->eeconfig()->m_CrossProbing.zoom_to_fit )
|
|
|
|
ZoomFitCrossProbeBBox( bbox );
|
|
|
|
|
|
|
|
editFrame->FocusOnItem( focusItem );
|
|
|
|
|
|
|
|
if( !focusItem )
|
|
|
|
editFrame->FocusOnLocation( bbox.Centre() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_selection.Size() > 0 )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM& item : start->GetDrawItems() )
|
2020-01-04 23:05:57 +00:00
|
|
|
{
|
|
|
|
if( item.IsSelected() )
|
2022-07-12 01:03:45 +00:00
|
|
|
select( &item );
|
2020-01-04 23:05:57 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-11 10:06:28 +00:00
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
|
2019-10-27 17:47:26 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// If the field and symbol are selected, only use the symbol
|
2020-02-05 04:48:33 +00:00
|
|
|
if( item->IsSelected() )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
select( item );
|
|
|
|
}
|
2020-02-05 04:48:33 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-17 16:02:47 +00:00
|
|
|
item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->IsSelected() )
|
|
|
|
select( aChild );
|
|
|
|
} );
|
2020-02-05 04:48:33 +00:00
|
|
|
}
|
2019-10-27 17:47:26 +00:00
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2019-05-31 18:23:49 +00:00
|
|
|
|
|
|
|
updateReferencePoint();
|
2019-06-29 18:57:23 +00:00
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
|
2019-05-11 10:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
|
|
|
|
bool checkVisibilityOnly ) const
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
// NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
|
2021-03-07 11:58:11 +00:00
|
|
|
|
|
|
|
SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
2020-11-23 19:46:17 +00:00
|
|
|
|
|
|
|
// Do not allow selection of anything except fields when the current symbol in the symbol
|
|
|
|
// editor is a derived symbol.
|
2024-04-12 21:00:41 +00:00
|
|
|
if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != SCH_FIELD_T )
|
2020-11-23 19:46:17 +00:00
|
|
|
return false;
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case SCH_PIN_T:
|
2021-09-19 10:05:58 +00:00
|
|
|
{
|
|
|
|
const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
if( symEditFrame )
|
|
|
|
{
|
|
|
|
if( pin->GetUnit() && pin->GetUnit() != symEditFrame->GetUnit() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( pin->GetBodyStyle() && pin->GetBodyStyle() != symEditFrame->GetBodyStyle() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-19 10:05:58 +00:00
|
|
|
if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
|
2019-04-21 23:45:34 +00:00
|
|
|
return false;
|
2021-09-19 10:05:58 +00:00
|
|
|
|
2024-03-03 03:18:51 +00:00
|
|
|
if( !m_filter.pins )
|
2021-09-19 10:05:58 +00:00
|
|
|
{
|
|
|
|
// Pin anchors have to be allowed for auto-starting wires.
|
|
|
|
if( aPos )
|
|
|
|
{
|
2024-04-17 09:44:26 +00:00
|
|
|
EE_GRID_HELPER grid( m_toolMgr );
|
|
|
|
GRID_HELPER_GRIDS pinGrid = grid.GetItemGrid( pin );
|
2021-09-19 10:05:58 +00:00
|
|
|
|
2024-04-17 09:44:26 +00:00
|
|
|
if( pin->IsPointClickableAnchor( grid.BestSnapAnchor( *aPos, pinGrid ) ) )
|
2021-09-19 10:05:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-14 00:53:47 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
break;
|
2022-02-14 00:53:47 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2023-04-27 16:59:53 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
|
|
|
if( !m_frame->eeconfig()->m_Appearance.show_directive_labels )
|
|
|
|
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;
|
|
|
|
|
2024-04-14 18:04:53 +00:00
|
|
|
case SCH_FIELD_T: // SCH_FIELD objects are not unit/body-style-specific.
|
2024-04-17 09:44:26 +00:00
|
|
|
{
|
|
|
|
const SCH_FIELD* field = static_cast<const SCH_FIELD*>( aItem );
|
|
|
|
|
|
|
|
if( !field->IsVisible() && !( symEditFrame && symEditFrame->GetShowInvisibleFields() ) )
|
|
|
|
return false;
|
|
|
|
|
2019-12-12 15:44:53 +00:00
|
|
|
break;
|
2024-04-17 09:44:26 +00:00
|
|
|
}
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
case SCH_SHAPE_T:
|
2024-04-14 18:04:53 +00:00
|
|
|
case SCH_TEXT_T:
|
2024-04-15 20:18:54 +00:00
|
|
|
case SCH_TEXTBOX_T:
|
2020-11-23 19:46:17 +00:00
|
|
|
if( symEditFrame )
|
2019-12-12 16:42:11 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
const SCH_ITEM* sch_item = static_cast<const SCH_ITEM*>( aItem );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
if( sch_item->GetUnit() && sch_item->GetUnit() != symEditFrame->GetUnit() )
|
2019-12-12 16:42:11 +00:00
|
|
|
return false;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
if( sch_item->GetBodyStyle() && sch_item->GetBodyStyle() != symEditFrame->GetBodyStyle() )
|
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;
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
case SCH_TABLECELL_T:
|
|
|
|
{
|
|
|
|
const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aItem );
|
|
|
|
|
|
|
|
if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
default: // Suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
void EE_SELECTION_TOOL::ClearSelection( bool aQuietMode )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( m_selection.Empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
while( m_selection.GetSize() )
|
2022-07-12 01:03:45 +00:00
|
|
|
unhighlight( m_selection.Front(), SELECTED, &m_selection );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
getView()->Update( &m_selection );
|
|
|
|
|
|
|
|
m_selection.SetIsHover( false );
|
|
|
|
m_selection.ClearReferencePoint();
|
|
|
|
|
|
|
|
// Inform other potentially interested tools
|
2022-07-19 15:00:35 +00:00
|
|
|
if( !aQuietMode )
|
|
|
|
m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::select( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
highlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::unselect( EDA_ITEM* aItem )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
unhighlight( aItem, SELECTED, &m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
|
|
|
aItem->SetSelected();
|
|
|
|
else if( aMode == BRIGHTENED )
|
|
|
|
aItem->SetBrightened();
|
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Add( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Highlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2021-10-12 20:05:37 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
aChild->SetSelected();
|
2023-02-16 22:14:08 +00:00
|
|
|
getView()->Hide( aChild, true );
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
aChild->SetBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2023-02-15 04:46:35 +00:00
|
|
|
if( aGroup && aMode != BRIGHTENED )
|
|
|
|
getView()->Hide( aItem, true );
|
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
if( aItem->GetParent() && aItem->GetParent()->Type() != SCHEMATIC_T )
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
|
2024-04-20 20:50:40 +00:00
|
|
|
|
2024-02-28 07:02:44 +00:00
|
|
|
getView()->Update( aItem, KIGFX::REPAINT );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
2022-03-03 14:35:57 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
aItem->ClearSelected();
|
2022-03-03 14:35:57 +00:00
|
|
|
// Lines need endpoints cleared here
|
|
|
|
if( aItem->Type() == SCH_LINE_T )
|
|
|
|
aItem->ClearFlags( STARTPOINT | ENDPOINT );
|
2023-02-15 04:46:35 +00:00
|
|
|
|
|
|
|
if( aMode != BRIGHTENED )
|
|
|
|
getView()->Hide( aItem, false );
|
2022-03-03 14:35:57 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2019-04-21 23:45:34 +00:00
|
|
|
aItem->ClearBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Remove( aItem );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Unhighlight pins and fields. (All the other symbol children are currently only
|
2021-06-10 18:51:46 +00:00
|
|
|
// represented in the LIB_SYMBOL.)
|
2020-11-17 22:28:10 +00:00
|
|
|
if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
|
|
|
{
|
|
|
|
sch_item->RunOnChildren(
|
2022-07-12 01:03:45 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aMode == SELECTED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2022-07-12 01:03:45 +00:00
|
|
|
aChild->ClearSelected();
|
2023-02-16 22:14:08 +00:00
|
|
|
getView()->Hide( aChild, false );
|
|
|
|
}
|
2022-07-12 01:03:45 +00:00
|
|
|
else if( aMode == BRIGHTENED )
|
2023-02-16 22:14:08 +00:00
|
|
|
{
|
2022-07-12 01:03:45 +00:00
|
|
|
aChild->ClearBrightened();
|
2023-02-16 22:14:08 +00:00
|
|
|
}
|
2023-11-22 14:21:42 +00:00
|
|
|
|
|
|
|
if( aGroup )
|
|
|
|
aGroup->Remove( aChild );
|
2022-07-12 01:03:45 +00:00
|
|
|
} );
|
2020-11-17 22:28:10 +00:00
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
if( aItem->GetParent() && aItem->GetParent()->Type() != SCHEMATIC_T )
|
2023-02-15 04:46:35 +00:00
|
|
|
getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
|
2024-04-20 20:50:40 +00:00
|
|
|
|
2024-02-28 07:02:44 +00:00
|
|
|
getView()->Update( aItem, KIGFX::REPAINT );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
const unsigned GRIP_MARGIN = 20;
|
2024-04-20 20:50:40 +00:00
|
|
|
int margin = KiROUND( getView()->ToWorld( GRIP_MARGIN ) );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
// Check if the point is located within any of the currently selected items bounding boxes
|
2020-12-14 21:11:33 +00:00
|
|
|
for( EDA_ITEM* item : m_selection )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
BOX2I itemBox = item->ViewBBox();
|
2022-11-20 19:24:16 +00:00
|
|
|
itemBox.Inflate( margin ); // Give some margin for gripping an item
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
if( itemBox.Contains( aPoint ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_SELECTION_TOOL::setTransitions()
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::Main, EE_ACTIONS::selectionActivate.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectNode, EE_ACTIONS::selectNode.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectConnection, EE_ACTIONS::selectConnection.MakeEvent() );
|
2024-01-15 17:29:55 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::SelectColumns, ACTIONS::selectColumns.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectRows, ACTIONS::selectRows.MakeEvent() );
|
|
|
|
Go( &EE_SELECTION_TOOL::SelectTable, ACTIONS::selectTable.MakeEvent() );
|
2023-11-25 12:38:24 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
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() );
|
2023-09-06 23:44:39 +00:00
|
|
|
Go( &EE_SELECTION_TOOL::UnselectAll, EE_ACTIONS::unselectAll.MakeEvent() );
|
2021-09-05 20:37:52 +00:00
|
|
|
|
|
|
|
Go( &EE_SELECTION_TOOL::disambiguateCursor, EVENTS::DisambiguatePoint );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:34:58 +00:00
|
|
|
|