2013-08-02 14:53:50 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-19 15:02:57 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2013-08-02 14:53:50 +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 __SELECTION_TOOL_H
|
|
|
|
#define __SELECTION_TOOL_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <tool/tool_interactive.h>
|
2013-09-26 16:38:58 +00:00
|
|
|
#include <tool/context_menu.h>
|
2013-12-18 13:33:34 +00:00
|
|
|
#include <class_undoredo_container.h>
|
2013-08-02 14:53:50 +00:00
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
#include "selection_conditions.h"
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
class PCB_BASE_FRAME;
|
2013-08-02 14:53:50 +00:00
|
|
|
class SELECTION_AREA;
|
|
|
|
class BOARD_ITEM;
|
|
|
|
class GENERAL_COLLECTOR;
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
namespace KIGFX
|
2013-10-02 08:21:05 +00:00
|
|
|
{
|
|
|
|
class VIEW_GROUP;
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
struct SELECTION
|
|
|
|
{
|
|
|
|
/// Set of selected items
|
|
|
|
PICKED_ITEMS_LIST items;
|
|
|
|
|
|
|
|
/// VIEW_GROUP that holds currently selected items
|
|
|
|
KIGFX::VIEW_GROUP* group;
|
|
|
|
|
|
|
|
/// Checks if there is anything selected
|
|
|
|
bool Empty() const
|
|
|
|
{
|
|
|
|
return ( items.GetCount() == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of selected parts
|
|
|
|
int Size() const
|
|
|
|
{
|
|
|
|
return items.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Alias to make code shorter and clearer
|
|
|
|
template <typename T>
|
|
|
|
T* Item( unsigned int aIndex ) const
|
|
|
|
{
|
|
|
|
return static_cast<T*>( items.GetPickedItem( aIndex ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Clears both the VIEW_GROUP and set of selected items. Please note that it does not
|
|
|
|
/// change properties of selected items (e.g. selection flag).
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
friend class SELECTION_TOOL;
|
|
|
|
};
|
|
|
|
|
2013-08-02 14:53:50 +00:00
|
|
|
/**
|
2013-08-06 07:31:08 +00:00
|
|
|
* Class SELECTION_TOOL
|
2013-08-02 14:53:50 +00:00
|
|
|
*
|
|
|
|
* Our sample selection tool: currently supports:
|
|
|
|
* - pick single objects (click LMB)
|
|
|
|
* - add objects to existing selection (Shift+LMB)
|
|
|
|
* - draw selection box (drag LMB)
|
2014-07-09 11:50:27 +00:00
|
|
|
* - handles MODULEs properly (i.e. selects either MODULE or its PADs, TEXTs, etc.)
|
2013-09-19 15:02:57 +00:00
|
|
|
* - takes into account high-contrast & layer visibility settings
|
2013-12-03 15:09:03 +00:00
|
|
|
* - invokes InteractiveEdit tool when user starts to drag selected items
|
2013-08-02 14:53:50 +00:00
|
|
|
*/
|
|
|
|
class SELECTION_TOOL : public TOOL_INTERACTIVE
|
|
|
|
{
|
2013-08-06 07:31:08 +00:00
|
|
|
public:
|
2013-08-09 13:04:10 +00:00
|
|
|
SELECTION_TOOL();
|
|
|
|
~SELECTION_TOOL();
|
2013-08-02 14:53:50 +00:00
|
|
|
|
2013-09-26 16:38:58 +00:00
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
2013-12-09 09:42:38 +00:00
|
|
|
void Reset( RESET_REASON aReason );
|
2013-09-04 08:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Main()
|
|
|
|
*
|
|
|
|
* The main loop.
|
|
|
|
*/
|
2013-08-08 12:59:59 +00:00
|
|
|
int Main( TOOL_EVENT& aEvent );
|
2013-09-04 08:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSelection()
|
|
|
|
*
|
|
|
|
* Returns the set of currently selected items.
|
|
|
|
*/
|
2013-10-02 08:21:05 +00:00
|
|
|
const SELECTION& GetSelection() const
|
2013-08-30 08:23:18 +00:00
|
|
|
{
|
2013-10-02 08:21:05 +00:00
|
|
|
return m_selection;
|
2013-08-30 08:23:18 +00:00
|
|
|
}
|
2013-08-02 14:53:50 +00:00
|
|
|
|
2013-09-26 16:38:58 +00:00
|
|
|
/**
|
2013-12-18 13:33:34 +00:00
|
|
|
* Function AddMenuItem()
|
2013-09-26 16:38:58 +00:00
|
|
|
*
|
|
|
|
* Adds a menu entry to run a TOOL_ACTION on selected items.
|
|
|
|
* @param aAction is a menu entry to be added.
|
2014-07-09 13:10:32 +00:00
|
|
|
* @param aCondition is a condition that has to be fulfilled to enable the menu entry.
|
2013-09-26 16:38:58 +00:00
|
|
|
*/
|
2014-07-09 13:10:32 +00:00
|
|
|
void AddMenuItem( const TOOL_ACTION& aAction,
|
|
|
|
const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways );
|
2013-09-26 16:38:58 +00:00
|
|
|
|
2014-07-09 12:23:13 +00:00
|
|
|
/**
|
|
|
|
* Function AddSubMenu()
|
|
|
|
*
|
|
|
|
* Adds a submenu to the selection tool right-click context menu.
|
|
|
|
* @param aMenu is the submenu to be added.
|
|
|
|
* @param aLabel is the label of added submenu.
|
2014-07-09 13:10:32 +00:00
|
|
|
* @param aCondition is a condition that has to be fulfilled to enable the submenu entry.
|
2014-07-09 12:23:13 +00:00
|
|
|
*/
|
2014-07-09 13:10:32 +00:00
|
|
|
void AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel,
|
|
|
|
const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2014-07-09 10:10:27 +00:00
|
|
|
/**
|
|
|
|
* Function EditModules()
|
2014-07-09 13:10:32 +00:00
|
|
|
*
|
2014-07-09 10:10:27 +00:00
|
|
|
* Toggles edit module mode. When enabled, one may select parts of modules individually
|
|
|
|
* (graphics, pads, etc.), so they can be modified.
|
|
|
|
* @param aEnabled decides if the mode should be enabled.
|
|
|
|
*/
|
|
|
|
void EditModules( bool aEnabled )
|
|
|
|
{
|
|
|
|
m_editModules = aEnabled;
|
|
|
|
}
|
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
///> Checks if the user has agreed to modify locked items for the given selection.
|
|
|
|
bool CheckLock();
|
|
|
|
|
2014-11-21 10:49:28 +00:00
|
|
|
///> Select a single item under cursor event handler.
|
|
|
|
int CursorSelection( TOOL_EVENT& aEvent );
|
2014-07-09 14:50:31 +00:00
|
|
|
|
|
|
|
///> Clear current selection event handler.
|
|
|
|
int ClearSelection( TOOL_EVENT& aEvent );
|
|
|
|
|
2014-11-21 10:50:13 +00:00
|
|
|
///> Item selection event handler.
|
|
|
|
int SelectItem( TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
///> Item unselection event handler.
|
|
|
|
int UnselectItem( TOOL_EVENT& aEvent );
|
|
|
|
|
2014-03-18 10:04:52 +00:00
|
|
|
///> Event sent after an item is selected.
|
2014-02-27 16:27:58 +00:00
|
|
|
const TOOL_EVENT SelectedEvent;
|
2014-03-18 10:04:52 +00:00
|
|
|
|
2014-11-21 10:49:54 +00:00
|
|
|
///> Event sent after an item is unselected.
|
|
|
|
const TOOL_EVENT UnselectedEvent;
|
2014-03-18 10:04:52 +00:00
|
|
|
|
|
|
|
///> Event sent after selection is cleared.
|
2014-02-27 16:27:58 +00:00
|
|
|
const TOOL_EVENT ClearedEvent;
|
|
|
|
|
2013-08-06 07:31:08 +00:00
|
|
|
private:
|
2014-07-09 11:50:27 +00:00
|
|
|
/**
|
2014-11-21 10:49:28 +00:00
|
|
|
* Function selectCursor()
|
2014-07-09 11:50:27 +00:00
|
|
|
* Selects an item pointed by the parameter aWhere. If there is more than one item at that
|
|
|
|
* place, there is a menu displayed that allows to choose the item.
|
|
|
|
*
|
|
|
|
* @param aWhere is the place where the item should be selected.
|
|
|
|
* @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then
|
|
|
|
* a menu is shown, otherise function finishes without selecting anything.
|
|
|
|
* @return True if an item was selected, false otherwise.
|
|
|
|
*/
|
2014-11-21 10:49:28 +00:00
|
|
|
bool selectCursor( const VECTOR2I& aWhere, bool aAllowDisambiguation = true );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2013-09-04 08:56:06 +00:00
|
|
|
/**
|
|
|
|
* Function selectMultiple()
|
|
|
|
* Handles drawing a selection box that allows to select many items at the same time.
|
2013-09-06 14:04:12 +00:00
|
|
|
*
|
2014-07-09 09:59:24 +00:00
|
|
|
* @return true if the function was cancelled (i.e. CancelEvent was received).
|
2013-09-04 08:56:06 +00:00
|
|
|
*/
|
2013-09-06 14:04:12 +00:00
|
|
|
bool selectMultiple();
|
2013-09-04 08:56:06 +00:00
|
|
|
|
2014-10-13 13:25:16 +00:00
|
|
|
///> Find dialog callback.
|
|
|
|
void findCallback( BOARD_ITEM* aItem );
|
|
|
|
|
|
|
|
///> Find an item.
|
|
|
|
int find( TOOL_EVENT& aEvent );
|
|
|
|
|
2014-10-13 13:22:14 +00:00
|
|
|
///> Find an item and start moving.
|
|
|
|
int findMove( TOOL_EVENT& aEvent );
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
///> Sets up handlers for various events.
|
|
|
|
void setTransitions();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ClearSelection()
|
|
|
|
* Clears the current selection.
|
|
|
|
*/
|
|
|
|
void clearSelection();
|
|
|
|
|
2013-09-04 08:56:06 +00:00
|
|
|
/**
|
|
|
|
* Function disambiguationMenu()
|
|
|
|
* Handles the menu that allows to select one of many items in case there is more than one
|
2014-11-21 10:49:28 +00:00
|
|
|
* item at the selected point (@see selectCursor()).
|
2013-09-04 08:56:06 +00:00
|
|
|
*
|
|
|
|
* @param aItems contains list of items that are displayed to the user.
|
|
|
|
*/
|
2013-08-06 08:30:09 +00:00
|
|
|
BOARD_ITEM* disambiguationMenu( GENERAL_COLLECTOR* aItems );
|
2013-09-04 08:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function pickSmallestComponent()
|
|
|
|
* Allows to find the smallest (in terms of bounding box area) item from the list.
|
|
|
|
*
|
|
|
|
* @param aCollector containes the list of items.
|
|
|
|
*/
|
2013-08-06 07:31:08 +00:00
|
|
|
BOARD_ITEM* pickSmallestComponent( GENERAL_COLLECTOR* aCollector );
|
2013-09-04 08:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function toggleSelection()
|
|
|
|
* Changes selection status of a given item.
|
|
|
|
*
|
|
|
|
* @param aItem is the item to have selection status changed.
|
|
|
|
*/
|
2013-08-09 08:18:48 +00:00
|
|
|
void toggleSelection( BOARD_ITEM* aItem );
|
2013-09-04 08:56:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function selectable()
|
|
|
|
* Checks conditions for an item to be selected.
|
|
|
|
*
|
|
|
|
* @return True if the item fulfills conditions to be selected.
|
|
|
|
*/
|
2013-09-26 12:09:56 +00:00
|
|
|
bool selectable( const BOARD_ITEM* aItem ) const;
|
2013-09-04 08:56:06 +00:00
|
|
|
|
2013-09-26 16:38:58 +00:00
|
|
|
/**
|
|
|
|
* Function selectItem()
|
|
|
|
* Takes necessary action mark an item as selected.
|
|
|
|
*
|
|
|
|
* @param aItem is an item to be selected.
|
|
|
|
*/
|
2013-12-18 13:33:34 +00:00
|
|
|
void select( BOARD_ITEM* aItem );
|
2013-09-26 16:38:58 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-21 10:49:54 +00:00
|
|
|
* Function unselectItem()
|
|
|
|
* Takes necessary action mark an item as unselected.
|
2013-09-26 16:38:58 +00:00
|
|
|
*
|
2014-11-21 10:49:54 +00:00
|
|
|
* @param aItem is an item to be unselected.
|
2013-09-26 16:38:58 +00:00
|
|
|
*/
|
2014-11-21 10:49:54 +00:00
|
|
|
void unselect( BOARD_ITEM* aItem );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-21 10:49:54 +00:00
|
|
|
* Function unselectVisually()
|
2013-12-18 13:33:34 +00:00
|
|
|
* Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
|
|
|
|
* @param aItem is an item to be be marked.
|
|
|
|
*/
|
|
|
|
void selectVisually( BOARD_ITEM* aItem ) const;
|
|
|
|
|
|
|
|
/**
|
2014-11-21 10:49:54 +00:00
|
|
|
* Function unselectVisually()
|
2013-12-18 13:33:34 +00:00
|
|
|
* Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
|
|
|
|
* @param aItem is an item to be be marked.
|
|
|
|
*/
|
2014-11-21 10:49:54 +00:00
|
|
|
void unselectVisually( BOARD_ITEM* aItem ) const;
|
2013-09-26 16:38:58 +00:00
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
/**
|
|
|
|
* Function containsSelected()
|
|
|
|
* Checks if the given point is placed within any of selected items' bounding box.
|
|
|
|
*
|
|
|
|
* @return True if the given point is contained in any of selected items' bouding box.
|
|
|
|
*/
|
2014-02-27 15:13:27 +00:00
|
|
|
bool selectionContains( const VECTOR2I& aPoint ) const;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2014-04-04 15:40:00 +00:00
|
|
|
/**
|
|
|
|
* Function highlightNet()
|
|
|
|
* Looks for a BOARD_CONNECTED_ITEM in a given spot, and if one is found - it enables
|
|
|
|
* highlight for its net.
|
|
|
|
* @param aPoint is the point where an item is expected (world coordinates).
|
|
|
|
*/
|
|
|
|
void highlightNet( const VECTOR2I& aPoint );
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
/**
|
|
|
|
* Function prefer()
|
|
|
|
* Checks if collector's list contains only single entry of asked types. If so, it returns it.
|
|
|
|
* @param aCollector is the collector that has a list of items to be queried.
|
|
|
|
* @param aTypes is the list of searched/preferred types.
|
|
|
|
* @return Pointer to the preferred item, if there is only one entry of given type or NULL
|
|
|
|
* if there are more entries or no entries at all.
|
|
|
|
*/
|
|
|
|
BOARD_ITEM* prefer( GENERAL_COLLECTOR& aCollector, const KICAD_T aTypes[] ) const;
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/**
|
|
|
|
* Function generateMenu()
|
|
|
|
* Creates a copy of context menu that is filtered by menu conditions and displayed to
|
|
|
|
* the user.
|
|
|
|
*/
|
|
|
|
void generateMenu();
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
/// Pointer to the parent frame.
|
|
|
|
PCB_BASE_FRAME* m_frame;
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Visual representation of selection box.
|
2013-08-06 07:31:08 +00:00
|
|
|
SELECTION_AREA* m_selArea;
|
2013-09-04 08:56:06 +00:00
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Current state of selection.
|
2013-10-02 08:21:05 +00:00
|
|
|
SELECTION m_selection;
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Flag saying if items should be added to the current selection or rather replace it.
|
2013-08-09 08:18:48 +00:00
|
|
|
bool m_additive;
|
2013-09-09 08:10:02 +00:00
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Flag saying if multiple selection mode is active.
|
2013-09-09 08:10:02 +00:00
|
|
|
bool m_multiple;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Right click popup menu (master instance).
|
2013-09-26 16:38:58 +00:00
|
|
|
CONTEXT_MENU m_menu;
|
2014-07-09 10:10:27 +00:00
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Copy of the context menu that is filtered by menu conditions and displayed to the user.
|
|
|
|
CONTEXT_MENU m_menuCopy;
|
|
|
|
|
|
|
|
/// Edit module mode flag.
|
2014-07-09 10:10:27 +00:00
|
|
|
bool m_editModules;
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
/// Can other tools modify locked items.
|
|
|
|
bool m_locked;
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/// Conditions for specific context menu entries.
|
|
|
|
std::deque<SELECTION_CONDITION> m_menuConditions;
|
2013-08-02 14:53:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|