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
|
2019-04-21 23:45:34 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_SCH_SELECTION_TOOL_H
|
|
|
|
#define KICAD_SCH_SELECTION_TOOL_H
|
|
|
|
|
|
|
|
#include <tool/tool_interactive.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>
|
2019-05-02 10:59:36 +00:00
|
|
|
#include <sch_component.h>
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
class SCH_BASE_FRAME;
|
|
|
|
class SCH_ITEM;
|
|
|
|
|
|
|
|
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 Empty;
|
|
|
|
static SELECTION_CONDITION Idle;
|
|
|
|
static SELECTION_CONDITION IdleSelection;
|
|
|
|
|
|
|
|
static SELECTION_CONDITION SingleSymbol;
|
|
|
|
static SELECTION_CONDITION SingleDeMorganSymbol;
|
2019-05-02 20:03:03 +00:00
|
|
|
static SELECTION_CONDITION SingleMultiUnitSymbol;
|
2019-05-02 10:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
class EE_SELECTION_TOOL : public TOOL_INTERACTIVE
|
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;
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int UpdateMenu( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
|
|
|
* Function Main()
|
|
|
|
*
|
|
|
|
* The main loop.
|
|
|
|
*/
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSelection()
|
|
|
|
*
|
|
|
|
* Returns the set of currently selected items.
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* Function RequestSelection()
|
|
|
|
*
|
2019-04-23 17:12:10 +00:00
|
|
|
* Returns either an existing selection (filtered), or the selection at the current
|
|
|
|
* cursor if the existing selection is empty.
|
2019-04-23 12:51:48 +00:00
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& RequestSelection( const KICAD_T* aFilterList = EE_COLLECTOR::AllItems );
|
2019-04-23 12:51:48 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
2020-05-24 23:35:04 +00:00
|
|
|
* Function SelectPoint()
|
|
|
|
* Selects one or all items pointed by the parameter aWhere.
|
|
|
|
* If there is more than one item at that place,
|
|
|
|
* there is a menu displayed that allows one to choose the item or all of them.
|
2019-04-21 23:45:34 +00:00
|
|
|
*
|
|
|
|
* @param aWhere is the place where the item should be selected.
|
2020-05-24 23:35:04 +00:00
|
|
|
* @param aItem is set to the newly selected item if only one was selected, otherwise is unchanged.
|
2019-04-21 23:45:34 +00:00
|
|
|
* @param aSelectionCancelledFlag allows the function to inform its caller that a selection
|
|
|
|
* was cancelled (for instance, by clicking outside of the disambiguation menu).
|
2020-05-24 23:35:04 +00:00
|
|
|
* @param aCheckLocked indicates if locked items should be excluded.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
2020-05-24 23:35:04 +00:00
|
|
|
bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
|
|
|
|
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
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
int AddItemToSel( const TOOL_EVENT& aEvent );
|
2019-05-03 22:46:44 +00:00
|
|
|
void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
|
2019-04-30 13:54:32 +00:00
|
|
|
int AddItemsToSel( const TOOL_EVENT& aEvent );
|
2019-05-03 22:46:44 +00:00
|
|
|
void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
int RemoveItemFromSel( const TOOL_EVENT& aEvent );
|
2019-05-03 22:46:44 +00:00
|
|
|
void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
|
2019-04-30 13:54:32 +00:00
|
|
|
int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
|
2019-05-03 22:46:44 +00:00
|
|
|
void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-18 13:11:34 +00:00
|
|
|
void BrightenItem( EDA_ITEM* aItem );
|
2019-05-19 21:04:04 +00:00
|
|
|
void UnbrightenItem( EDA_ITEM* aItem );
|
2019-05-18 13:11:34 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
///> Find (but don't select) node under cursor
|
2019-05-05 10:33:34 +00:00
|
|
|
EDA_ITEM* GetNode( VECTOR2I aPosition );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
///> Select node under cursor
|
|
|
|
int SelectNode( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
///> If node selected then expand to connection, otherwise select connection under cursor
|
|
|
|
int SelectConnection( const TOOL_EVENT& aEvent );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
///> Clear current selection event handler.
|
|
|
|
int ClearSelection( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
void ClearSelection();
|
|
|
|
|
2019-08-01 04:31:19 +00:00
|
|
|
/**
|
|
|
|
* Function Selectable()
|
|
|
|
* Checks conditions for an item to be selected.
|
|
|
|
* @return True if the item fulfills conditions to be selected.
|
|
|
|
*/
|
|
|
|
bool Selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
|
|
|
|
|
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-04-21 23:45:34 +00:00
|
|
|
/**
|
|
|
|
* Function SelectionMenu()
|
2019-04-23 12:51:48 +00:00
|
|
|
* Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single
|
|
|
|
* item.
|
|
|
|
*
|
|
|
|
* NOTE: this routine DOES NOT modify the selection.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
|
|
|
int SelectionMenu( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
/**
|
|
|
|
* Rebuilds 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.
|
|
|
|
*/
|
|
|
|
void RebuildSelection();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
private:
|
2019-04-23 17:40:29 +00:00
|
|
|
/**
|
|
|
|
* Function selectMultiple()
|
|
|
|
* Handles drawing a selection box that allows one to select many items at
|
|
|
|
* the same time.
|
|
|
|
*
|
|
|
|
* @return true if the function was cancelled (i.e. CancelEvent was received).
|
|
|
|
*/
|
|
|
|
bool selectMultiple();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
|
|
|
* Allows the selection of a single item from a list via pop-up menu. The items are
|
|
|
|
* highlighted on the canvas when hovered in the menu. The collector is trimmed to
|
|
|
|
* the picked item.
|
|
|
|
* @return true if an item was picked
|
|
|
|
*/
|
2019-05-10 19:22:26 +00:00
|
|
|
bool doSelectionMenu( EE_COLLECTOR* aItems );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function select()
|
|
|
|
* Takes necessary action mark an item as selected.
|
|
|
|
*
|
|
|
|
* @param aItem is an item to be selected.
|
|
|
|
*/
|
2019-05-03 22:46:44 +00:00
|
|
|
void select( EDA_ITEM* aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function unselect()
|
|
|
|
* Takes necessary action mark an item as unselected.
|
|
|
|
*
|
|
|
|
* @param aItem is an item to be unselected.
|
|
|
|
*/
|
2019-05-03 22:46:44 +00:00
|
|
|
void unselect( EDA_ITEM* aItem );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function highlight()
|
|
|
|
* Highlights the item visually.
|
|
|
|
* @param aItem is an item to be be highlighted.
|
|
|
|
* @param aHighlightMode should be either SELECTED or BRIGHTENED
|
|
|
|
* @param aGroup is the group to add the item to in the BRIGHTENED mode.
|
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function unhighlight()
|
|
|
|
* Unhighlights the item visually.
|
|
|
|
* @param aItem is an item to be be highlighted.
|
|
|
|
* @param aHighlightMode should be either SELECTED or BRIGHTENED
|
|
|
|
* @param aGroup is the group to remove the item from.
|
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-31 18:23:49 +00:00
|
|
|
/**
|
|
|
|
* Sets the reference point to the anchor of the top-left item.
|
|
|
|
*/
|
|
|
|
void updateReferencePoint();
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
/**
|
|
|
|
* Function selectionContains()
|
2019-08-20 17:22:30 +00:00
|
|
|
* @return True if the given point is contained in any of selected items' bounding box.
|
2019-04-21 23:45:34 +00:00
|
|
|
*/
|
|
|
|
bool selectionContains( const VECTOR2I& aPoint ) const;
|
|
|
|
|
|
|
|
///> Sets up handlers for various events.
|
|
|
|
void setTransitions() override;
|
2019-05-25 08:09:26 +00:00
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
private:
|
2019-06-08 21:48:22 +00:00
|
|
|
SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
|
|
|
|
EE_SELECTION m_selection; // Current state of selection
|
|
|
|
|
|
|
|
bool m_additive; // Items should be added to selection (instead of replacing)
|
|
|
|
bool m_subtractive; // Items should be removed from selection
|
2019-07-09 19:50:40 +00:00
|
|
|
bool m_exclusive_or; // Items' selection state should be toggled
|
2019-06-08 21:48:22 +00:00
|
|
|
bool m_multiple; // Multiple selection mode is active
|
|
|
|
bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
|
|
|
|
|
|
|
|
bool m_isLibEdit; // True when libedit is the parent frame
|
|
|
|
bool m_isLibView; // True when libview is the parent frame
|
|
|
|
int m_unit; // Fixed unit filter (for symbol editor)
|
|
|
|
int m_convert; // Fixed DeMorgan filter (for symbol editor)
|
2019-04-21 23:45:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //KICAD_SCH_SELECTION_TOOL_H
|