2019-05-20 10:23:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-20 10:23:32 +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 PL_SELECTION_TOOL_H
|
|
|
|
#define PL_SELECTION_TOOL_H
|
|
|
|
|
|
|
|
#include <tool/tool_interactive.h>
|
|
|
|
#include <tool/tool_menu.h>
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "tools/pl_selection.h"
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
class PL_EDITOR_FRAME;
|
|
|
|
class SCH_ITEM;
|
|
|
|
class COLLECTOR;
|
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class GAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PL_SELECTION_TOOL : public TOOL_INTERACTIVE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PL_SELECTION_TOOL();
|
2019-07-09 19:50:40 +00:00
|
|
|
~PL_SELECTION_TOOL() override { }
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_BASE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
|
|
|
void Reset( RESET_REASON aReason ) override;
|
|
|
|
|
|
|
|
int UpdateMenu( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main loop.
|
|
|
|
*/
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the set of currently selected items.
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& GetSelection();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return either an existing selection (filtered), or the selection at the current
|
2019-05-20 10:23:32 +00:00
|
|
|
* cursor if the existing selection is empty.
|
|
|
|
*/
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION& RequestSelection();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Select an item pointed by the parameter aWhere. If there is more than one item at that
|
2019-05-20 10:23:32 +00:00
|
|
|
* place, there is a menu displayed that allows one to choose the item.
|
|
|
|
*
|
|
|
|
* @param aWhere is the place where the item should be selected.
|
|
|
|
* @param aSelectionCancelledFlag allows the function to inform its caller that a selection
|
2021-01-27 22:15:38 +00:00
|
|
|
* was canceled (for instance, by clicking outside of the
|
|
|
|
* disambiguation menu).
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
2020-08-10 13:24:40 +00:00
|
|
|
void SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag = nullptr );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
int AddItemToSel( const TOOL_EVENT& aEvent );
|
|
|
|
void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
|
|
|
|
int AddItemsToSel( const TOOL_EVENT& aEvent );
|
|
|
|
void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
|
|
|
|
|
|
|
|
int RemoveItemFromSel( const TOOL_EVENT& aEvent );
|
|
|
|
void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
|
|
|
|
int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
|
|
|
|
void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
|
|
|
|
|
2019-06-25 14:12:40 +00:00
|
|
|
void BrightenItem( EDA_ITEM* aItem );
|
|
|
|
void UnbrightenItem( EDA_ITEM* aItem );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
int ClearSelection( const TOOL_EVENT& aEvent );
|
|
|
|
void ClearSelection();
|
|
|
|
|
2019-05-24 10:11:18 +00:00
|
|
|
/**
|
|
|
|
* Rebuild the selection from the flags in the view items. Useful after a hard redraw
|
|
|
|
* or an undo or redo operation.
|
|
|
|
*/
|
|
|
|
void RebuildSelection();
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
/**
|
|
|
|
* Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single
|
|
|
|
* item.
|
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* @note This routine **does not** modify the selection.
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
|
|
|
int SelectionMenu( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Handle drawing a selection box that allows one to select many items at the same time.
|
2019-05-20 10:23:32 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* @return true if the function was canceled (i.e. CancelEvent was received).
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
|
|
|
bool selectMultiple();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply heuristics to try and determine a single object when multiple are found under the
|
|
|
|
* cursor.
|
|
|
|
*/
|
|
|
|
void guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aWhere );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Allow the selection of a single item from a list via pop-up menu. The items are
|
2019-05-20 10:23:32 +00:00
|
|
|
* highlighted on the canvas when hovered in the menu. The collector is trimmed to
|
|
|
|
* the picked item.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
|
|
|
* @return true if an item was picked.
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
|
|
|
bool doSelectionMenu( COLLECTOR* aItems );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes necessary action mark an item as selected.
|
|
|
|
*
|
|
|
|
* @param aItem is an item to be selected.
|
|
|
|
*/
|
|
|
|
void select( EDA_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Take necessary action mark an item as unselected.
|
2019-05-20 10:23:32 +00:00
|
|
|
*
|
|
|
|
* @param aItem is an item to be unselected.
|
|
|
|
*/
|
|
|
|
void unselect( EDA_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Highlight the item visually.
|
|
|
|
*
|
2019-05-20 10:23:32 +00:00
|
|
|
* @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, PL_SELECTION* aGroup = nullptr );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Unhighlight the item visually.
|
|
|
|
*
|
2019-05-20 10:23:32 +00:00
|
|
|
* @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, PL_SELECTION* aGroup = nullptr );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-20 17:22:30 +00:00
|
|
|
* @return True if the given point is contained in any of selected items' bounding box.
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
|
|
|
bool selectionContains( const VECTOR2I& aPoint ) const;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Set up handlers for various events.
|
2019-05-20 10:23:32 +00:00
|
|
|
void setTransitions() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame
|
2019-06-08 21:48:22 +00:00
|
|
|
PL_SELECTION m_selection; // Current state of selection
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
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-05-20 10:23:32 +00:00
|
|
|
bool m_multiple; // Multiple selection mode is active
|
|
|
|
bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PL_SELECTION_TOOL_H
|