2019-04-21 23:45:34 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2022-08-20 09:27:35 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-21 23:45:34 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_SCH_SELECTION_TOOL_H
|
|
|
|
#define KICAD_SCH_SELECTION_TOOL_H
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
#include <tool/selection_tool.h>
|
2019-05-14 11:14:00 +00:00
|
|
|
#include <tool/action_menu.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <tool/tool_menu.h>
|
2019-06-08 21:48:22 +00:00
|
|
|
#include <tools/ee_selection.h>
|
2019-05-10 19:22:26 +00:00
|
|
|
#include <ee_collectors.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-04-05 01:35:01 +00:00
|
|
|
#include <gal/cursors.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
class SCH_BASE_FRAME;
|
|
|
|
class SCH_ITEM;
|
2022-02-14 00:53:47 +00:00
|
|
|
class EE_GRID_HELPER;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class GAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
class EE_CONDITIONS : public SELECTION_CONDITIONS
|
2019-05-02 10:59:36 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static SELECTION_CONDITION SingleSymbol;
|
2021-02-17 00:14:23 +00:00
|
|
|
static SELECTION_CONDITION SingleSymbolOrPower;
|
2019-05-02 10:59:36 +00:00
|
|
|
static SELECTION_CONDITION SingleDeMorganSymbol;
|
2019-05-02 20:03:03 +00:00
|
|
|
static SELECTION_CONDITION SingleMultiUnitSymbol;
|
2023-08-28 11:29:47 +00:00
|
|
|
static SELECTION_CONDITION SingleMultiFunctionPin;
|
2021-12-30 16:51:04 +00:00
|
|
|
static SELECTION_CONDITION SingleNonExcludedMarker;
|
2022-12-22 19:00:10 +00:00
|
|
|
static SELECTION_CONDITION MultipleSymbolsOrPower;
|
2023-09-28 14:27:27 +00:00
|
|
|
static SELECTION_CONDITION AllPins;
|
2019-05-02 10:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
class EE_SELECTION_TOOL : public SELECTION_TOOL
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL();
|
|
|
|
~EE_SELECTION_TOOL();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_BASE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_BASE::Reset()
|
|
|
|
void Reset( RESET_REASON aReason ) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main loop.
|
|
|
|
*/
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
2020-11-18 15:23:05 +00:00
|
|
|
void OnIdle( wxIdleEvent& aEvent );
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
///< Zoom the screen to fit the bounding box for cross probing/selection sync.
|
2022-08-31 12:56:58 +00:00
|
|
|
void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
|
2022-07-19 15:00:35 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* @return the set of currently selected items.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& GetSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-23 12:51:48 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Return either an existing selection (filtered), or the selection at the current cursor
|
|
|
|
* position if the existing selection is empty.
|
2022-08-21 19:54:07 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aScanTypes [optional] List of item types that are acceptable for selection.
|
2022-08-21 19:54:07 +00:00
|
|
|
* @return either the current selection or, if empty, the selection at the cursor.
|
2019-04-23 12:51:48 +00:00
|
|
|
*/
|
2022-08-21 19:54:07 +00:00
|
|
|
EE_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Perform a click-type selection at a point (usually the cursor position).
|
2019-04-21 23:45:34 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aWhere Point from which the selection should be made.
|
|
|
|
* @param aScanTypes [optional] List of item types that are acceptable for selection.
|
|
|
|
* @param aItem [out, optional] The newly selected item if only one was selected, otherwise
|
2020-10-05 10:54:37 +00:00
|
|
|
* unchanged.
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aSelectionCancelledFlag [out] Allows the function to inform its caller that a
|
|
|
|
* selection was canceled (for instance, by clicking outside of
|
|
|
|
* the disambiguation menu).
|
|
|
|
* @param aCheckLocked Indicates if locked items should be excluded.
|
|
|
|
* @param aAdd Indicates if found item(s) should be added to the selection.
|
|
|
|
* @param aSubtract Indicates if found item(s) should be subtracted from the selection.
|
|
|
|
* @param aExclusiveOr Indicates if found item(s) should be toggle in the selection.
|
|
|
|
* @return true if the selection was modified.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2022-08-20 09:27:35 +00:00
|
|
|
bool SelectPoint( const VECTOR2I& aWhere,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
|
2020-05-24 23:35:04 +00:00
|
|
|
EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
|
|
|
|
bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
|
|
|
|
bool aExclusiveOr = false );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2022-08-22 10:58:09 +00:00
|
|
|
/**
|
|
|
|
* Finds a connected item at a point (usually the cursor position). Iterative process with a
|
|
|
|
* decreasing slop factor.
|
|
|
|
* @param aPosition Cursor position from which the search should be made.
|
|
|
|
* @return a connected item or nullptr.
|
|
|
|
*/
|
2023-07-15 22:11:24 +00:00
|
|
|
EDA_ITEM* GetNode( const VECTOR2I& aPosition );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2022-08-22 10:58:09 +00:00
|
|
|
/**
|
|
|
|
* Selects the connected item at the current cursor position. Iterative process with a
|
|
|
|
* decreasing slop factor.
|
|
|
|
*/
|
2019-04-30 13:54:32 +00:00
|
|
|
int SelectNode( const TOOL_EVENT& aEvent );
|
|
|
|
|
2022-08-22 10:58:09 +00:00
|
|
|
/**
|
|
|
|
* If a connected item is selected then expand the selection to the entire connection,
|
|
|
|
* otherwise select connection under the current cursor position.
|
|
|
|
*/
|
2019-04-30 13:54:32 +00:00
|
|
|
int SelectConnection( const TOOL_EVENT& aEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Clear current selection event handler.
|
2019-04-21 23:45:34 +00:00
|
|
|
int ClearSelection( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Select all visible items in sheet
|
2020-08-20 23:05:21 +00:00
|
|
|
int SelectAll( const TOOL_EVENT& aEvent );
|
|
|
|
|
2023-09-06 23:44:39 +00:00
|
|
|
///< Unselect all visible items in sheet
|
|
|
|
int UnselectAll( const TOOL_EVENT& aEvent );
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
void ClearSelection( bool aQuietMode = false );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2019-08-01 04:31:19 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Check conditions for an item to be selected.
|
|
|
|
*
|
2019-08-01 04:31:19 +00:00
|
|
|
* @return True if the item fulfills conditions to be selected.
|
|
|
|
*/
|
2021-09-19 10:05:58 +00:00
|
|
|
bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
|
|
|
|
bool checkVisibilityOnly = false ) const;
|
2019-08-01 04:31:19 +00:00
|
|
|
|
2019-06-28 19:11:26 +00:00
|
|
|
/**
|
|
|
|
* Apply heuristics to try and determine a single object when multiple are found under the
|
|
|
|
* cursor.
|
|
|
|
*/
|
|
|
|
void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Rebuild the selection from the EDA_ITEMs' selection flags.
|
|
|
|
*
|
|
|
|
* Commonly called after rolling back an undo state to make sure there aren't any stale
|
|
|
|
* pointers.
|
2019-05-11 10:06:28 +00:00
|
|
|
*/
|
|
|
|
void RebuildSelection();
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Collect one or more items at a given point. This method does not attempt to disambiguate
|
|
|
|
* multiple items and is simply "collecting".
|
2020-10-02 20:18:07 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aCollector [in, out] Provides collection conditions and stores collected items.
|
|
|
|
* @param aWhere Point from which the collection should be made.
|
|
|
|
* @param aScanTypes [optional] A list of item types that are acceptable for collection.
|
2020-10-02 20:18:07 +00:00
|
|
|
*/
|
2021-01-19 21:10:04 +00:00
|
|
|
bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
///< Set selection to items passed by parameter.
|
|
|
|
///< Zooms to fit, if enabled.
|
2023-07-15 22:11:24 +00:00
|
|
|
void 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
|
|
|
|
2022-07-12 01:03:45 +00:00
|
|
|
protected:
|
|
|
|
SELECTION& selection() override { return m_selection; }
|
|
|
|
|
2021-01-19 21:10:04 +00:00
|
|
|
private:
|
2022-02-14 00:53:47 +00:00
|
|
|
OPT_TOOL_EVENT autostartEvent( TOOL_EVENT* aEvent, EE_GRID_HELPER& aGrid, SCH_ITEM* aItem );
|
|
|
|
|
2020-10-02 20:18:07 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Apply rules to narrow the collection down to selectable objects, and then heuristics
|
2020-10-02 20:18:07 +00:00
|
|
|
* to try and narrow it to a single object.
|
2021-09-23 21:39:29 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aCollector [in, out] Provides collection conditions and stores collected items.
|
2021-09-23 21:39:29 +00:00
|
|
|
* @param aWhere point where we should narrow (if relevant)
|
|
|
|
* @param aCheckLocked If false, remove locked elements from #collector
|
2022-09-06 15:11:56 +00:00
|
|
|
* @param aSelectedOnly If true, remove non-selected items from #collector
|
2020-10-02 20:18:07 +00:00
|
|
|
*/
|
2022-09-06 15:11:56 +00:00
|
|
|
void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
|
|
|
|
bool aSelectedOnly = false );
|
2020-10-02 20:18:07 +00:00
|
|
|
|
2020-10-05 10:54:37 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Perform a click-type selection at a point (usually the cursor position).
|
2020-10-05 10:54:37 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aCollector [in, out] Provides collection conditions and stores collected items.
|
|
|
|
* @param aWhere Point from which the selection should be made.
|
|
|
|
* @param aItem [out, optional] The newly selected item if only one was selected, otherwise
|
2020-10-05 10:54:37 +00:00
|
|
|
* unchanged.
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aSelectionCancelledFlag [out] Allows the function to inform its caller that a
|
|
|
|
* selection was canceled (for instance, by clicking outside of
|
|
|
|
* the disambiguation menu).
|
|
|
|
* @param aAdd Indicates if found item(s) should be added to the selection.
|
|
|
|
* @param aSubtract Indicates if found item(s) should be subtracted from the selection.
|
|
|
|
* @param aExclusiveOr Indicates if found item(s) should be toggle in the selection.
|
|
|
|
* @return true if the selection was modified.
|
2020-10-05 10:54:37 +00:00
|
|
|
*/
|
2022-03-03 14:35:57 +00:00
|
|
|
bool selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
|
2020-10-05 10:54:37 +00:00
|
|
|
bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
|
|
|
|
bool aSubtract = false, bool aExclusiveOr = false );
|
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Handle drawing a selection box that allows one to select many items at the same time.
|
2019-04-23 17:40:29 +00:00
|
|
|
*
|
2021-01-26 15:23:37 +00:00
|
|
|
* @return true if the function was canceled (i.e. CancelEvent was received).
|
2019-04-23 17:40:29 +00:00
|
|
|
*/
|
|
|
|
bool selectMultiple();
|
|
|
|
|
2021-09-05 20:37:52 +00:00
|
|
|
/**
|
|
|
|
* Handle disambiguation actions including displaying the menu.
|
|
|
|
*/
|
|
|
|
int disambiguateCursor( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Take necessary action to mark an item as selected.
|
2019-04-21 23:45:34 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aItem The item to be selected.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2022-07-12 01:03:45 +00:00
|
|
|
void select( EDA_ITEM* aItem ) override;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* Take necessary action to mark an item as unselected.
|
2019-04-21 23:45:34 +00:00
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aItem The item to be unselected.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2022-07-12 01:03:45 +00:00
|
|
|
void unselect( EDA_ITEM* aItem ) override;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Highlight the item visually.
|
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aItem The item to be highlighted.
|
|
|
|
* @param aHighlightMode Either SELECTED or BRIGHTENED
|
|
|
|
* @param aGroup [otpional] A group to add the item to.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2022-07-12 01:03:45 +00:00
|
|
|
void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Unhighlight the item visually.
|
|
|
|
*
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aItem is an item to be highlighted.
|
2019-04-21 23:45:34 +00:00
|
|
|
* @param aHighlightMode should be either SELECTED or BRIGHTENED
|
2022-08-22 10:58:09 +00:00
|
|
|
* @param aGroup [optional] A group to remove the item from.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2022-07-12 01:03:45 +00:00
|
|
|
void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Set the reference point to the anchor of the top-left item.
|
2019-05-31 18:23:49 +00:00
|
|
|
*/
|
|
|
|
void updateReferencePoint();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
2022-08-22 10:58:09 +00:00
|
|
|
* @return true if the given point is contained in any of selected items' bounding boxes.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
|
|
|
bool selectionContains( const VECTOR2I& aPoint ) const;
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Set up handlers for various events.
|
2019-04-21 23:45:34 +00:00
|
|
|
void setTransitions() override;
|
2019-05-25 08:09:26 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
private:
|
2021-03-25 09:28:20 +00:00
|
|
|
|
2020-11-18 15:23:05 +00:00
|
|
|
SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
|
|
|
|
EE_SELECTION m_selection; // Current state of selection
|
|
|
|
|
|
|
|
KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
|
|
|
|
|
|
|
|
bool m_isSymbolEditor; // True when the symbol editor is the parent frame
|
2020-12-25 23:37:01 +00:00
|
|
|
bool m_isSymbolViewer; // True when the symbol browser is the parent frame
|
2020-11-18 15:23:05 +00:00
|
|
|
int m_unit; // Fixed unit filter (for symbol editor)
|
2024-01-26 16:16:13 +00:00
|
|
|
int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
|
2019-04-21 23:45:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //KICAD_SCH_SELECTION_TOOL_H
|