KiCad PCB EDA Suite
GERBVIEW_SELECTION_TOOL Class Reference

Class GERBVIEW_SELECTION_TOOL. More...

#include <selection_tool.h>

Inheritance diagram for GERBVIEW_SELECTION_TOOL:
TOOL_INTERACTIVE TOOL_BASE

Public Types

enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 

Determines the reason of reset for a tool

More...
 

Public Member Functions

 GERBVIEW_SELECTION_TOOL ()
 
 ~GERBVIEW_SELECTION_TOOL ()
 
bool Init () override
 Function Init() Init() is called once upon a registration of the tool. More...
 
void Reset (RESET_REASON aReason) override
 Function Reset() Brings the tool to a known, initial state. More...
 
int Main (const TOOL_EVENT &aEvent)
 Function Main() More...
 
SELECTIONGetSelection ()
 Function GetSelection() More...
 
TOOL_MENUGetToolMenu ()
 
int CursorSelection (const TOOL_EVENT &aEvent)
 

Select a single item under cursor event handler.

More...
 
int ClearSelection (const TOOL_EVENT &aEvent)
 

Clear current selection event handler.

More...
 
int SelectItem (const TOOL_EVENT &aEvent)
 

Item selection event handler.

More...
 
int SelectItems (const TOOL_EVENT &aEvent)
 

Multiple item selection event handler

More...
 
int UnselectItem (const TOOL_EVENT &aEvent)
 

Item unselection event handler.

More...
 
int UnselectItems (const TOOL_EVENT &aEvent)
 

Multiple item unselection event handler

More...
 
int MeasureTool (const TOOL_EVENT &aEvent)
 

Launches a tool to measure between points

More...
 
void setTransitions () override
 

Sets up handlers for various events.

More...
 
void zoomFitSelection (void)
 

Zooms the screen to center and fit the current selection.

More...
 
void Activate ()
 Function Activate() Runs the tool. More...
 
void SetContextMenu (CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Function SetContextMenu() More...
 
void RunMainStack (std::function< void()> aFunc)
 Function RunMainStack() More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Go() More...
 
OPT_TOOL_EVENT Wait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Wait() More...
 
TOOL_TYPE GetType () const
 Function GetType() Returns the type of the tool. More...
 
TOOL_ID GetId () const
 Function GetId() Returns the unique identifier of the tool. More...
 
const std::string & GetName () const
 Function GetName() Returns the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool. More...
 
TOOL_SETTINGSGetSettings ()
 
bool IsToolActive () const
 

Static Public Attributes

static const TOOL_EVENT SelectedEvent
 

Event sent after an item is selected.

More...
 
static const TOOL_EVENT UnselectedEvent
 

Event sent after an item is unselected.

More...
 
static const TOOL_EVENT ClearedEvent
 

Event sent after selection is cleared.

More...
 

Protected Member Functions

const TOOL_EVENT evActivate (std::string aToolName="")
 functions below are not yet implemented - their interface may change More...
 
const TOOL_EVENT evCommand (int aCommandId=-1)
 
const TOOL_EVENT evCommand (std::string aCommandStr="")
 
const TOOL_EVENT evMotion ()
 
const TOOL_EVENT evClick (int aButton=BUT_ANY)
 
const TOOL_EVENT evDrag (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonUp (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonDown (int aButton=BUT_ANY)
 
void attachManager (TOOL_MANAGER *aManager)
 Function attachManager() More...
 
KIGFX::VIEWgetView () const
 Function getView() More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Function getViewControls() More...
 
template<typename T >
T * getEditFrame () const
 Function getEditFrame() More...
 
template<typename T >
T * getModel () const
 Function getModel() More...
 

Protected Attributes

TOOL_TYPE m_type
 

Stores the type of the tool.

More...
 
TOOL_ID m_toolId
 

Unique identifier for the tool, assigned by a TOOL_MANAGER instance.

More...
 
std::string m_toolName
 

Name of the tool.

More...
 
TOOL_MANAGERm_toolMgr
 
TOOL_SETTINGS m_toolSettings
 

Private Member Functions

bool selectPoint (const VECTOR2I &aWhere, bool aOnDrag=false)
 Function selectPoint() Selects an item pointed by the parameter aWhere. More...
 
bool selectCursor (bool aSelectAlways=false)
 Function selectCursor() Selects an item under the cursor unless there is something already selected or aSelectAlways is true. More...
 
bool selectMultiple ()
 Function selectMultiple() Handles drawing a selection box that allows one to select many items at the same time. More...
 
void clearSelection ()
 Function clearSelection() Clears the current selection. More...
 
EDA_ITEMdisambiguationMenu (GERBER_COLLECTOR *aItems)
 Function disambiguationMenu() Handles the menu that allows one to select one of many items in case there is more than one item at the selected point (. More...
 
void toggleSelection (EDA_ITEM *aItem)
 Function toggleSelection() Changes selection status of a given item. More...
 
bool selectable (const EDA_ITEM *aItem) const
 Function selectable() Checks conditions for an item to be selected. More...
 
void select (EDA_ITEM *aItem)
 Function select() Takes necessary action mark an item as selected. More...
 
void unselect (EDA_ITEM *aItem)
 Function unselect() Takes necessary action mark an item as unselected. More...
 
void selectVisually (EDA_ITEM *aItem)
 Function selectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST. More...
 
void unselectVisually (EDA_ITEM *aItem)
 Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST. More...
 
bool selectionContains (const VECTOR2I &aPoint) const
 Function selectionContains() Checks if the given point is placed within any of selected items' bounding box. More...
 
void guessSelectionCandidates (GERBER_COLLECTOR &aCollector) const
 Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items are clicked, by doing some braindead heuristics. More...
 

Private Attributes

GERBVIEW_FRAMEm_frame
 Pointer to the parent frame. More...
 
SELECTION m_selection
 Current state of selection. More...
 
bool m_additive
 Flag saying if items should be added to the current selection or rather replace it. More...
 
bool m_subtractive
 Flag saying if items should be removed from the current selection. More...
 
bool m_multiple
 Flag saying if multiple selection mode is active. More...
 
bool m_preliminary
 Determines if the selection is preliminary or final. More...
 
TOOL_MENU m_menu
 Menu model displayed by the tool. More...
 

Detailed Description

Class GERBVIEW_SELECTION_TOOL.

Selection tool for GerbView, based on the one in PcbNew

Definition at line 49 of file gerbview/tools/selection_tool.h.

Member Enumeration Documentation

enum TOOL_BASE::RESET_REASON
inherited

Determines the reason of reset for a tool

Enumerator
RUN 

Tool is invoked after being inactive.

MODEL_RELOAD 

Model changes (required full reload)

GAL_SWITCH 

Rendering engine changes.

Definition at line 80 of file tool_base.h.

81  {
82  RUN,
83  MODEL_RELOAD,
84  GAL_SWITCH
85  };
Model changes (required full reload)
Definition: tool_base.h:83
Tool is invoked after being inactive.
Definition: tool_base.h:82
Rendering engine changes.
Definition: tool_base.h:84

Constructor & Destructor Documentation

GERBVIEW_SELECTION_TOOL::GERBVIEW_SELECTION_TOOL ( )

Definition at line 141 of file gerbview/tools/selection_tool.cpp.

References m_preliminary.

141  :
142  TOOL_INTERACTIVE( "gerbview.InteractiveSelection" ),
143  m_frame( NULL ), m_additive( false ), m_subtractive( false ),
144  m_multiple( false ),
145  m_menu( *this )
146 {
147  // these members are initialized to avoid warnings about non initialized vars
148  m_preliminary = true;
149 }
bool m_preliminary
Determines if the selection is preliminary or final.
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
TOOL_MENU m_menu
Menu model displayed by the tool.
bool m_multiple
Flag saying if multiple selection mode is active.
bool m_subtractive
Flag saying if items should be removed from the current selection.
GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL ( )

Definition at line 152 of file gerbview/tools/selection_tool.cpp.

References TOOL_BASE::getView(), m_selection, and KIGFX::VIEW::Remove().

153 {
154  getView()->Remove( &m_selection );
155 }
SELECTION m_selection
Current state of selection.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35

Member Function Documentation

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

After activation, the tool starts receiving events until it is finished.

Definition at line 49 of file tool_interactive.cpp.

References TOOL_MANAGER::InvokeTool(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

Referenced by AUTOPLACE_TOOL::autoplace(), PCBNEW_CONTROL::DeleteItemCursor(), EDIT_TOOL::doCopyToClipboard(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), EDIT_TOOL::pickCopyReferencePoint(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), and PCB_EDITOR_CONTROL::ShowLocalRatsnest().

50 {
52 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:210
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Function attachManager()

Sets the TOOL_MANAGER the tool will belong to. Called by TOOL_MANAGER::RegisterTool()

Definition at line 59 of file tool_base.cpp.

References TOOL_BASE::m_toolMgr, TOOL_BASE::m_toolSettings, and TOOL_BASE::TOOL_SETTINGS.

Referenced by TOOL_MANAGER::RegisterTool().

60 {
61  m_toolMgr = aManager;
62  m_toolSettings = TOOL_SETTINGS( this );
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:216
friend class TOOL_SETTINGS
Definition: tool_base.h:155
int GERBVIEW_SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 498 of file gerbview/tools/selection_tool.cpp.

References clearSelection().

Referenced by setTransitions().

499 {
500  clearSelection();
501 
502  return 0;
503 }
void clearSelection()
Function clearSelection() Clears the current selection.
void GERBVIEW_SELECTION_TOOL::clearSelection ( )
private

Function clearSelection() Clears the current selection.

Definition at line 580 of file gerbview/tools/selection_tool.cpp.

References ClearedEvent, SELECTION::Empty(), m_frame, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), GERBVIEW_FRAME::SetCurItem(), and unselectVisually().

Referenced by ClearSelection(), CursorSelection(), Main(), Reset(), selectCursor(), selectPoint(), and toggleSelection().

581 {
582  if( m_selection.Empty() )
583  return;
584 
585  for( auto item : m_selection )
586  unselectVisually( static_cast<EDA_ITEM*>( item ) );
587 
588  m_selection.Clear();
589 
590  m_frame->SetCurItem( NULL );
591 
592  // Inform other potentially interested tools
594 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
void SetCurItem(GERBER_DRAW_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
SELECTION m_selection
Current state of selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselectVisually(EDA_ITEM *aItem)
Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
int GERBVIEW_SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Select a single item under cursor event handler.

Definition at line 484 of file gerbview/tools/selection_tool.cpp.

References clearSelection(), SELECTION::Empty(), m_selection, and selectCursor().

Referenced by setTransitions().

485 {
486  if( m_selection.Empty() ) // Try to find an item that could be modified
487  {
488  selectCursor( true );
489 
490  clearSelection();
491  return 0;
492  }
493 
494  return 0;
495 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
SELECTION m_selection
Current state of selection.
bool selectCursor(bool aSelectAlways=false)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
void clearSelection()
Function clearSelection() Clears the current selection.
EDA_ITEM * GERBVIEW_SELECTION_TOOL::disambiguationMenu ( GERBER_COLLECTOR aItems)
private

Function disambiguationMenu() Handles the menu that allows one to select one of many items in case there is more than one item at the selected point (.

See also
selectCursor()).
Parameters
aItemscontains list of items that are displayed to the user.

Definition at line 620 of file gerbview/tools/selection_tool.cpp.

References KIGFX::VIEW_GROUP::Add(), CONTEXT_MENU::Add(), KIGFX::VIEW::Add(), EDA_ITEM::ClearBrightened(), CMENU_NOW, CONTEXT_MENU::DisplayTitle(), COLLECTOR::GetCount(), EDA_ITEM::GetMenuImage(), EDA_ITEM::GetSelectMenuText(), EDA_DRAW_FRAME::GetUserUnits(), TOOL_BASE::getView(), KIGFX::VIEW::Hide(), i, EDA_ITEM::IsBrightened(), LAYER_SELECT_OVERLAY, m_frame, KIGFX::VIEW::MarkTargetDirty(), min, KIGFX::VIEW_GROUP::Remove(), KIGFX::VIEW::Remove(), EDA_ITEM::SetBrightened(), TOOL_INTERACTIVE::SetContextMenu(), CONTEXT_MENU::SetIcon(), KIGFX::VIEW_GROUP::SetLayer(), CONTEXT_MENU::SetTitle(), TA_CONTEXT_MENU_CHOICE, TA_CONTEXT_MENU_UPDATE, KIGFX::TARGET_OVERLAY, and TOOL_INTERACTIVE::Wait().

Referenced by selectPoint().

621 {
622  EDA_ITEM* current = NULL;
623  KIGFX::VIEW_GROUP highlightGroup;
624  CONTEXT_MENU menu;
625 
626  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
627  getView()->Add( &highlightGroup );
628 
629  int limit = std::min( 10, aCollector->GetCount() );
630 
631  for( int i = 0; i < limit; ++i )
632  {
633  wxString text;
634  EDA_ITEM* item = ( *aCollector )[i];
635  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
636  menu.Add( text, i + 1, item->GetMenuImage() );
637  }
638 
639  menu.SetTitle( _( "Clarify selection" ) );
640  menu.SetIcon( info_xpm );
641  menu.DisplayTitle( true );
642  SetContextMenu( &menu, CMENU_NOW );
643 
644  while( OPT_TOOL_EVENT evt = Wait() )
645  {
646  if( evt->Action() == TA_CONTEXT_MENU_UPDATE )
647  {
648  if( current )
649  {
650  current->ClearBrightened();
651  getView()->Hide( current, false );
652  highlightGroup.Remove( current );
654  }
655 
656  int id = *evt->GetCommandId();
657 
658  // User has pointed an item, so show it in a different way
659  if( id > 0 && id <= limit )
660  {
661  current = ( *aCollector )[id - 1];
662  current->SetBrightened();
663  getView()->Hide( current, true );
664  highlightGroup.Add( current );
666  }
667  else
668  {
669  current = NULL;
670  }
671  }
672  else if( evt->Action() == TA_CONTEXT_MENU_CHOICE )
673  {
674  OPT<int> id = evt->GetCommandId();
675 
676  // User has selected an item, so this one will be returned
677  if( id && ( *id > 0 ) )
678  current = ( *aCollector )[*id - 1];
679  else
680  current = NULL;
681 
682  break;
683  }
684  }
685 
686  if( current && current->IsBrightened() )
687  {
688  current->ClearBrightened();
689  getView()->Hide( current, false );
691  }
692 
693  getView()->Remove( &highlightGroup );
694 
695  return current;
696 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1497
bool IsBrightened() const
Definition: base_struct.h:227
Class CONTEXT_MENU.
Definition: context_menu.h:44
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
void SetBrightened()
Definition: base_struct.h:232
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
Function Add() Adds an entry to the menu.
void ClearBrightened()
Definition: base_struct.h:236
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
void SetContextMenu(CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
virtual void SetLayer(int aLayer)
Function SetLayer() Sets layer used to draw the group.
Definition: view_group.h:115
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the context menu.
size_t i
Definition: json11.cpp:597
currently selected items overlay
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
boost::optional< T > OPT
Definition: optional.h:7
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
#define min(a, b)
Definition: auxiliary.h:85
const TOOL_EVENT TOOL_INTERACTIVE::evActivate ( std::string  aToolName = "")
protectedinherited

functions below are not yet implemented - their interface may change

const TOOL_EVENT TOOL_INTERACTIVE::evButtonDown ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evButtonUp ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evClick ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( int  aCommandId = -1)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( std::string  aCommandStr = "")
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evDrag ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evMotion ( )
protectedinherited
template<typename T >
T* TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Function getEditFrame()

Returns the application window object, casted to requested user type.

Definition at line 188 of file tool_base.h.

Referenced by ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), and TOOL_SETTINGS::getConfigBase().

189  {
190  return static_cast<T*>( getEditFrameInt() );
191  }
wxWindow * getEditFrameInt() const
Definition: tool_base.cpp:47
TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Function GetId() Returns the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 122 of file tool_base.h.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::isActive(), TOOL_MANAGER::RegisterTool(), ACTION_MANAGER::RunHotKey(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::saveViewControls().

123  {
124  return m_toolId;
125  }
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:210
TOOL_MANAGER* TOOL_BASE::GetManager ( ) const
inlineinherited

Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER. If there is no TOOL_MANAGER associated, it returns NULL.

Definition at line 144 of file tool_base.h.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL::doInteractiveItemPlacement(), CONTEXT_MENU::getToolManager(), CONTEXT_MENU::onMenuEvent(), and ZONE_CREATE_HELPER::performZoneCutout().

145  {
146  return m_toolMgr;
147  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
template<typename T >
T* TOOL_BASE::getModel ( ) const
inlineprotectedinherited

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 199 of file tool_base.h.

Referenced by ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), ZONE_CREATE_HELPER::createZoneFromExisting(), and ZONE_CREATE_HELPER::performZoneCutout().

200  {
201  EDA_ITEM* m = getModelInt();
202 
203  return static_cast<T*>( m );
204  }
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:53
const std::string& TOOL_BASE::GetName ( void  ) const
inlineinherited

Function GetName() Returns the name of the tool.

Tool names are expected to obey the format: application.ToolName (eg. pcbnew.InteractiveSelection).

Returns
The name of the tool.

Definition at line 133 of file tool_base.h.

Referenced by TOOL_SETTINGS::getKeyName(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::invokeTool(), and TOOL_MANAGER::RegisterTool().

134  {
135  return m_toolName;
136  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:214
SELECTION & GERBVIEW_SELECTION_TOOL::GetSelection ( )

Function GetSelection()

Returns the set of currently selected items.

Definition at line 257 of file gerbview/tools/selection_tool.cpp.

References m_selection.

258 {
259  return m_selection;
260 }
SELECTION m_selection
Current state of selection.
TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 77 of file tool_base.cpp.

Referenced by GERBVIEW_CONTROL::HighlightControl(), ROUTER_TOOL::Init(), and ROUTER_TOOL::~ROUTER_TOOL().

78 {
79  return m_toolSettings;
80 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:216
TOOL_MENU& GERBVIEW_SELECTION_TOOL::GetToolMenu ( )
inline

Definition at line 75 of file gerbview/tools/selection_tool.h.

76  {
77  return m_menu;
78  }
TOOL_MENU m_menu
Menu model displayed by the tool.
TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 111 of file tool_base.h.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InvokeTool(), TOOL_MANAGER::ResetTools(), and TOOL_MANAGER::runTool().

112  {
113  return m_type;
114  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:207
KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Function getView()

Returns the instance of VIEW object used in the application. It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 35 of file tool_base.cpp.

References TOOL_MANAGER::GetView(), and TOOL_BASE::m_toolMgr.

Referenced by ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), COMMON_TOOLS::CenterContents(), PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), COMMON_TOOLS::CursorControl(), disambiguationMenu(), SELECTION_TOOL::doSelectionMenu(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findCallback(), ROUTER_TOOL::getStartLayer(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), SELECTION_TOOL::guessSelectionCandidates(), SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCBNEW_CONTROL::LayerAlphaDec(), PCBNEW_CONTROL::LayerAlphaInc(), CVPCB_SELECTION_TOOL::MeasureTool(), MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), DRAWING_TOOL::Reset(), Reset(), SELECTION_TOOL::Reset(), select(), selectable(), SELECTION_TOOL::selectable(), selectionContains(), SELECTION_TOOL::selectionContains(), selectMultiple(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), selectVisually(), SELECTION_TOOL::unhighlight(), unselect(), unselectVisually(), POINT_EDITOR::updateEditedPoint(), COMMON_TOOLS::updateGrid(), PCBNEW_CONTROL::updateGrid(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), COMMON_TOOLS::ZoomFitScreen(), zoomFitSelection(), SELECTION_TOOL::zoomFitSelection(), CVPCB_SELECTION_TOOL::~CVPCB_SELECTION_TOOL(), ~GERBVIEW_SELECTION_TOOL(), and SELECTION_TOOL::~SELECTION_TOOL().

36 {
37  return m_toolMgr->GetView();
38 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited

Function getViewControls()

Returns the instance of VIEW_CONTROLS object used in the application. It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.)

Returns
The instance of VIEW_CONTROLS.

Definition at line 41 of file tool_base.cpp.

References TOOL_MANAGER::GetViewControls(), and TOOL_BASE::m_toolMgr.

Referenced by POINT_EDITOR::addCorner(), COMMON_TOOLS::CursorControl(), COMMON_TOOLS::doZoomToPreset(), MICROWAVE_TOOL::drawMicrowaveInductor(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findMove(), PCB_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNetCursor(), PICKER_TOOL::Main(), CVPCB_SELECTION_TOOL::Main(), Main(), EDIT_TOOL::Main(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), CVPCB_CONTROL::ResetCoords(), GERBVIEW_CONTROL::ResetCoords(), PCBNEW_CONTROL::ResetCoords(), selectCursor(), SELECTION_TOOL::selectCursor(), selectMultiple(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), PICKER_TOOL::setControls(), POINT_EDITOR::setEditedPoint(), EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

42 {
43  return m_toolMgr->GetViewControls();
44 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:257
template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited
void GERBVIEW_SELECTION_TOOL::guessSelectionCandidates ( GERBER_COLLECTOR aCollector) const
private

Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items are clicked, by doing some braindead heuristics.

Parameters
aCollectoris the collector that has a list of items to be queried.
bool GERBVIEW_SELECTION_TOOL::Init ( )
overridevirtual

Function Init() Init() is called once upon a registration of the tool.

Returns
True if the initialization went fine, false - otherwise.

Reimplemented from TOOL_BASE.

Definition at line 158 of file gerbview/tools/selection_tool.cpp.

References CONDITIONAL_MENU::AddMenu(), TOOL_MENU::AddStandardSubMenus(), TOOL_MENU::AddSubMenu(), TOOL_MENU::GetMenu(), m_menu, and SELECTION_CONDITIONS::ShowAlways().

159 {
160  auto selectMenu = std::make_shared<HIGHLIGHT_MENU>();
161  selectMenu->SetTool( this );
162  m_menu.AddSubMenu( selectMenu );
163 
164  auto& menu = m_menu.GetMenu();
165 
166  menu.AddMenu( selectMenu.get(), false );
167  menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
168 
169  m_menu.AddStandardSubMenus( *getEditFrame<GERBVIEW_FRAME>() );
170 
171  return true;
172 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
void AddSubMenu(std::shared_ptr< CONTEXT_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:55
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
void AddMenu(CONTEXT_MENU *aMenu, bool aExpand=false, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
TOOL_MENU m_menu
Menu model displayed by the tool.
bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 30 of file tool_base.cpp.

References TOOL_MANAGER::IsToolActive(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

31 {
32  return m_toolMgr->IsToolActive( m_toolId );
33 }
bool IsToolActive(TOOL_ID aId) const
Function IsToolActive() Returns true if a tool with given id is active (executing) ...
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:210
int GERBVIEW_SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

The main loop.

Definition at line 198 of file gerbview/tools/selection_tool.cpp.

References BUT_LEFT, BUT_RIGHT, clearSelection(), TOOL_MENU::CloseContextMenu(), SELECTION::Empty(), EDA_DRAW_FRAME::GetToolId(), TOOL_BASE::getViewControls(), ID_NO_TOOL_SELECTED, m_additive, m_frame, m_menu, m_selection, selectPoint(), KIGFX::VIEW_CONTROLS::SetAdditionalPanButtons(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TA_CONTEXT_MENU_CLOSED, TA_UNDO_REDO_PRE, and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

199 {
200  // Main loop: keep receiving events
201  while( OPT_TOOL_EVENT evt = Wait() )
202  {
203  // This is kind of hacky: activate RMB drag on any event.
204  // There doesn't seem to be any other good way to tell when another tool
205  // is canceled and control returns to the selection tool, except by the
206  // fact that the selection tool starts to get events again.
208  {
209  getViewControls()->SetAdditionalPanButtons( false, true );
210  }
211 
212  // Disable RMB pan for other tools; they can re-enable if desired
213  if( evt->IsActivate() )
214  {
215  getViewControls()->SetAdditionalPanButtons( false, false );
216  }
217 
218  // single click? Select single object
219  if( evt->IsClick( BUT_LEFT ) )
220  {
221  if( !m_additive )
222  clearSelection();
223 
224  selectPoint( evt->Position() );
225  }
226 
227  // right click? if there is any object - show the context menu
228  else if( evt->IsClick( BUT_RIGHT ) )
229  {
230  if( m_selection.Empty() )
231  {
232  selectPoint( evt->Position() );
233  m_selection.SetIsHover( true );
234  }
235 
237  }
238 
239  else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
240  {
241  clearSelection();
242  }
243 
244  else if( evt->Action() == TA_CONTEXT_MENU_CLOSED )
245  {
246  m_menu.CloseContextMenu( evt );
247  }
248  }
249 
250  // This tool is supposed to be active forever
251  assert( false );
252 
253  return 0;
254 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
SELECTION m_selection
Current state of selection.
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void SetIsHover(bool aIsHover)
Definition: selection.h:64
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
void SetAdditionalPanButtons(bool aLeft=false, bool aRight=false)
void CloseContextMenu(OPT_TOOL_EVENT &evt)
Function CloseContextMenu.
Definition: tool_menu.cpp:82
int GetToolId() const
Definition: draw_frame.h:519
void clearSelection()
Function clearSelection() Clears the current selection.
TOOL_MENU m_menu
Menu model displayed by the tool.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
int GERBVIEW_SELECTION_TOOL::MeasureTool ( const TOOL_EVENT aEvent)

Launches a tool to measure between points

Definition at line 799 of file gerbview/tools/selection_tool.cpp.

References TOOL_INTERACTIVE::Activate(), BUT_LEFT, BUT_RIGHT, EDA_RECT::Centre(), ClearedEvent, KIGFX::GEOMETRY, SELECTION::GetCenter(), EDA_RECT::GetOrigin(), EDA_RECT::GetSize(), EDA_DRAW_FRAME::GetUserUnits(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), i, ID_TB_MEASUREMENT_TOOL, m_frame, m_menu, m_selection, MD_CTRL, EDA_RECT::Merge(), SelectedEvent, KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetAngleSnap(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetEnd(), EDA_DRAW_FRAME::SetNoToolSelected(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetOrigin(), EDA_DRAW_FRAME::SetToolID(), TOOL_MENU::ShowContextMenu(), TA_ACTION, TC_MESSAGE, UnselectedEvent, SELECTION::updateDrawList(), SELECTION::ViewBBox(), and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

800 {
801  auto& view = *getView();
802  auto& controls = *getViewControls();
803  auto previous_settings = controls.GetSettings();
804 
805  Activate();
806  m_frame->SetToolID( ID_TB_MEASUREMENT_TOOL, wxCURSOR_PENCIL,
807  _( "Measure distance" ) );
808 
810  KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() );
811 
812  view.Add( &ruler );
813  view.SetVisible( &ruler, false );
814 
815  bool originSet = false;
816 
817  controls.ShowCursor( true );
818  controls.SetSnapping( true );
819  controls.SetAdditionalPanButtons( false, true );
820 
821  while( auto evt = Wait() )
822  {
823  const VECTOR2I cursorPos = controls.GetCursorPosition();
824 
825  if( evt->IsCancel() || evt->IsActivate() )
826  {
827  break;
828  }
829 
830  // click or drag starts
831  else if( !originSet &&
832  ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
833  {
834  if( !evt->IsDrag( BUT_LEFT ) )
835  {
836  twoPtMgr.SetOrigin( cursorPos );
837  twoPtMgr.SetEnd( cursorPos );
838  }
839 
840  controls.CaptureCursor( true );
841  controls.SetAutoPan( true );
842 
843  originSet = true;
844  }
845 
846  else if( !originSet && evt->IsMotion() )
847  {
848  // make sure the origin is set before a drag starts
849  // otherwise you can miss a step
850  twoPtMgr.SetOrigin( cursorPos );
851  twoPtMgr.SetEnd( cursorPos );
852  }
853 
854  // second click or mouse up after drag ends
855  else if( originSet &&
856  ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
857  {
858  originSet = false;
859 
860  controls.SetAutoPan( false );
861  controls.CaptureCursor( false );
862 
863  view.SetVisible( &ruler, false );
864  }
865 
866  // move or drag when origin set updates rules
867  else if( originSet &&
868  ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
869  {
870  twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
871  twoPtMgr.SetEnd( cursorPos );
872 
873  view.SetVisible( &ruler, true );
874  view.Update( &ruler, KIGFX::GEOMETRY );
875  }
876 
877  else if( evt->IsClick( BUT_RIGHT ) )
878  {
880  }
881  }
882 
883  view.SetVisible( &ruler, false );
884  view.Remove( &ruler );
885 
886  controls.ApplySettings( previous_settings );
887 
889 
890  return 0;
891 }
SELECTION m_selection
Current state of selection.
Class TWO_POINT_GEOMETRY_MANAGER.
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the ruler (the fixed end)
Class RULER_ITEM.
Definition: ruler_item.h:43
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Set the tool command ID to aId and sets the cursor to aCursor.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
void Activate()
Function Activate() Runs the tool.
TOOL_MENU m_menu
Menu model displayed by the tool.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.
Color has changed.
Definition: view_item.h:57
void GERBVIEW_SELECTION_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Function Reset() Brings the tool to a known, initial state.

If the tool claimed anything from the model or the view, it must release it when its reset.

Parameters
aReasoncontains information about the reason of tool reset.

Implements TOOL_BASE.

Definition at line 175 of file gerbview/tools/selection_tool.cpp.

References KIGFX::VIEW::Add(), SELECTION::Clear(), clearSelection(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), m_frame, m_preliminary, m_selection, TOOL_BASE::MODEL_RELOAD, KIGFX::VIEW::Remove(), and KIGFX::RENDER_SETTINGS::SetHighlight().

176 {
177  m_frame = getEditFrame<GERBVIEW_FRAME>();
178  m_preliminary = true;
179 
180  if( aReason == TOOL_BASE::MODEL_RELOAD )
181  {
182  // Remove pointers to the selected items from containers
183  // without changing their properties (as they are already deleted
184  // while a new file is loaded)
185  m_selection.Clear();
186  getView()->GetPainter()->GetSettings()->SetHighlight( false );
187  }
188  else
189  // Restore previous properties of selected items and remove them from containers
190  clearSelection();
191 
192  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
193  getView()->Remove( &m_selection );
194  getView()->Add( &m_selection );
195 }
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:90
Model changes (required full reload)
Definition: tool_base.h:83
bool m_preliminary
Determines if the selection is preliminary or final.
SELECTION m_selection
Current state of selection.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void clearSelection()
Function clearSelection() Clears the current selection.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
void SetHighlight(bool aEnabled, int aNetcode=-1)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
Definition: painter.h:140
void TOOL_INTERACTIVE::RunMainStack ( std::function< void()>  aFunc)
inherited

Function RunMainStack()

Calls a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 85 of file tool_interactive.cpp.

References TOOL_BASE::m_toolMgr, and TOOL_MANAGER::RunMainStack().

Referenced by DRAWING_TOOL::PlaceText().

86 {
87  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
88 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
void GERBVIEW_SELECTION_TOOL::select ( EDA_ITEM aItem)
private

Function select() Takes necessary action mark an item as selected.

Parameters
aItemis an item to be selected.

Definition at line 715 of file gerbview/tools/selection_tool.cpp.

References SELECTION::Add(), KIGFX::VIEW::Add(), TOOL_BASE::getView(), EDA_ITEM::IsSelected(), m_frame, m_selection, selectVisually(), GERBVIEW_FRAME::SetCurItem(), and SELECTION::Size().

Referenced by SelectItem(), SelectItems(), selectMultiple(), and toggleSelection().

716 {
717  if( aItem->IsSelected() )
718  {
719  return;
720  }
721 
722  m_selection.Add( aItem );
723  getView()->Add( &m_selection );
724  selectVisually( aItem );
725 
726  if( m_selection.Size() == 1 )
727  {
728  // Set as the current item, so the information about selection is displayed
729  m_frame->SetCurItem( static_cast<GERBER_DRAW_ITEM*>( aItem ), true );
730  }
731  else if( m_selection.Size() == 2 ) // Check only for 2, so it will not be
732  { // called for every next selected item
733  // If multiple items are selected, do not show the information about the selected item
734  m_frame->SetCurItem( NULL, true );
735  }
736 }
void SetCurItem(GERBER_DRAW_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
SELECTION m_selection
Current state of selection.
bool IsSelected() const
Definition: base_struct.h:224
void selectVisually(EDA_ITEM *aItem)
Function selectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
int Size() const
Returns the number of selected parts.
Definition: selection.h:122
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
bool GERBVIEW_SELECTION_TOOL::selectable ( const EDA_ITEM aItem) const
private

Function selectable() Checks conditions for an item to be selected.

Returns
True if the item fulfills conditions to be selected.

Definition at line 699 of file gerbview/tools/selection_tool.cpp.

References KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), and TOOL_BASE::getView().

Referenced by selectMultiple(), selectPoint(), and toggleSelection().

700 {
701  auto item = static_cast<const GERBER_DRAW_ITEM*>( aItem );
702 
703  if( item->GetLayerPolarity() )
704  {
705  // Don't allow selection of invisible negative items
706  auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( getView()->GetPainter()->GetSettings() );
707  if( !rs->IsShowNegativeItems() )
708  return false;
709  }
710 
711  return getEditFrame<GERBVIEW_FRAME>()->IsLayerVisible( item->GetLayer() );
712 }
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
Class GERBVIEW_RENDER_SETTINGS Stores GerbView specific render settings.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
bool GERBVIEW_SELECTION_TOOL::selectCursor ( bool  aSelectAlways = false)
private

Function selectCursor() Selects an item under the cursor unless there is something already selected or aSelectAlways is true.

Parameters
aSelectAlwaysforces to select an item even if there is an item already selected.
Returns
true if eventually there is an item selected, false otherwise.

Definition at line 350 of file gerbview/tools/selection_tool.cpp.

References clearSelection(), SELECTION::Empty(), TOOL_BASE::getViewControls(), m_selection, and selectPoint().

Referenced by CursorSelection().

351 {
352  if( aSelectAlways || m_selection.Empty() )
353  {
354  clearSelection();
355  selectPoint( getViewControls()->GetCursorPosition( false ) );
356  }
357 
358  return !m_selection.Empty();
359 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
SELECTION m_selection
Current state of selection.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
void clearSelection()
Function clearSelection() Clears the current selection.
bool GERBVIEW_SELECTION_TOOL::selectionContains ( const VECTOR2I aPoint) const
private

Function selectionContains() Checks if the given point is placed within any of selected items' bounding box.

Returns
True if the given point is contained in any of selected items' bouding box.

Definition at line 780 of file gerbview/tools/selection_tool.cpp.

References BOX2< Vec >::Contains(), TOOL_BASE::getView(), BOX2< Vec >::Inflate(), m_selection, KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

781 {
782  const unsigned GRIP_MARGIN = 20;
783  VECTOR2D margin = getView()->ToWorld( VECTOR2D( GRIP_MARGIN, GRIP_MARGIN ), false );
784 
785  // Check if the point is located within any of the currently selected items bounding boxes
786  for( auto item : m_selection )
787  {
788  BOX2I itemBox = item->ViewBBox();
789  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
790 
791  if( itemBox.Contains( aPoint ) )
792  return true;
793  }
794 
795  return false;
796 }
SELECTION m_selection
Current state of selection.
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:300
int GERBVIEW_SELECTION_TOOL::SelectItem ( const TOOL_EVENT aEvent)

Item selection event handler.

Definition at line 526 of file gerbview/tools/selection_tool.cpp.

References TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), select(), and SelectedEvent.

Referenced by setTransitions().

527 {
528  // Check if there is an item to be selected
529  EDA_ITEM* item = aEvent.Parameter<EDA_ITEM*>();
530 
531  if( item )
532  {
533  select( item );
534 
535  // Inform other potentially interested tools
537  }
538 
539  return 0;
540 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:387
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
int GERBVIEW_SELECTION_TOOL::SelectItems ( const TOOL_EVENT aEvent)

Multiple item selection event handler

Definition at line 506 of file gerbview/tools/selection_tool.cpp.

References TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), select(), and SelectedEvent.

507 {
508  std::vector<EDA_ITEM*>* items = aEvent.Parameter<std::vector<EDA_ITEM*>*>();
509 
510  if( items )
511  {
512  // Perform individual selection of each item
513  // before processing the event.
514  for( auto item : *items )
515  {
516  select( item );
517  }
518 
520  }
521 
522  return 0;
523 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:387
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool GERBVIEW_SELECTION_TOOL::selectMultiple ( )
private

Function selectMultiple() Handles drawing a selection box that allows one to select many items at the same time.

Returns
true if the function was cancelled (i.e. CancelEvent was received).

Definition at line 362 of file gerbview/tools/selection_tool.cpp.

References KIGFX::VIEW::Add(), BUT_LEFT, BOX2< Vec >::Contains(), SELECTION::Empty(), SELECTION::Front(), KIGFX::PREVIEW::SELECTION_AREA::GetEnd(), KIGFX::PREVIEW::SELECTION_AREA::GetOrigin(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), m_additive, m_frame, m_multiple, m_selection, m_subtractive, TOOL_BASE::m_toolMgr, EDA_RECT::Normalize(), TOOL_MANAGER::ProcessEvent(), KIGFX::VIEW::Query(), KIGFX::VIEW::Remove(), select(), selectable(), SelectedEvent, KIGFX::PREVIEW::SELECTION_AREA::SetAdditive(), KIGFX::VIEW_CONTROLS::SetAutoPan(), GERBVIEW_FRAME::SetCurItem(), KIGFX::PREVIEW::SELECTION_AREA::SetEnd(), KIGFX::PREVIEW::SELECTION_AREA::SetOrigin(), KIGFX::PREVIEW::SELECTION_AREA::SetSubtractive(), KIGFX::VIEW::SetVisible(), SELECTION::Size(), unselect(), KIGFX::VIEW::Update(), KIGFX::PREVIEW::SELECTION_AREA::ViewBBox(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

363 {
364  bool cancelled = false; // Was the tool cancelled while it was running?
365  m_multiple = true; // Multiple selection mode is active
366  KIGFX::VIEW* view = getView();
367  getViewControls()->SetAutoPan( true );
368 
370  view->Add( &area );
371 
372  while( OPT_TOOL_EVENT evt = Wait() )
373  {
374  if( evt->IsCancel() )
375  {
376  cancelled = true;
377  break;
378  }
379 
380  if( evt->IsDrag( BUT_LEFT ) )
381  {
382 
383  // Start drawing a selection box
384  area.SetOrigin( evt->DragOrigin() );
385  area.SetEnd( evt->Position() );
386  area.SetAdditive( m_additive );
388 
389  view->SetVisible( &area, true );
390  view->Update( &area );
391  }
392 
393  if( evt->IsMouseUp( BUT_LEFT ) )
394  {
395  // End drawing the selection box
396  view->SetVisible( &area, false );
397 
398  // Mark items within the selection box as selected
399  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
400 
401  // Filter the view items based on the selection box
402  BOX2I selectionBox = area.ViewBBox();
403  view->Query( selectionBox, selectedItems ); // Get the list of selected items
404 
405  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
406 
407  int width = area.GetEnd().x - area.GetOrigin().x;
408  int height = area.GetEnd().y - area.GetOrigin().y;
409 
410  // Construct an EDA_RECT to determine EDA_ITEM selection
411  EDA_RECT selectionRect( wxPoint( area.GetOrigin().x, area.GetOrigin().y ),
412  wxSize( width, height ) );
413 
414  selectionRect.Normalize();
415 
416  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
417  {
418  auto item = static_cast<GERBER_DRAW_ITEM*>( it->first );
419 
420  if( !item || !selectable( item ) )
421  continue;
422 
423  /* Selection mode depends on direction of drag-selection:
424  * Left > Right : Select objects that are fully enclosed by selection
425  * Right > Left : Select objects that are crossed by selection
426  */
427 
428  if( width >= 0 )
429  {
430  if( selectionBox.Contains( item->ViewBBox() ) )
431  {
432  if( m_subtractive )
433  unselect( item );
434  else
435  select( item );
436  }
437  }
438  else
439  {
440  if( item->HitTest( selectionRect ) )
441  {
442  if( m_subtractive )
443  unselect( item );
444  else
445  select( item );
446  }
447 
448  }
449  }
450 
451  if( m_selection.Size() == 1 )
452  m_frame->SetCurItem( static_cast<GERBER_DRAW_ITEM*>( m_selection.Front() ) );
453  else
454  m_frame->SetCurItem( NULL );
455 
456  // Inform other potentially interested tools
457  if( !m_selection.Empty() )
459 
460  break; // Stop waiting for events
461  }
462  }
463 
464  // Stop drawing the selection box
465  view->Remove( &area );
466  m_multiple = false; // Multiple selection mode is inactive
467  getViewControls()->SetAutoPan( false );
468 
469  return cancelled;
470 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:450
void SetOrigin(VECTOR2I aOrigin)
Set the origin of the rectange (the fixed corner)
void SetCurItem(GERBER_DRAW_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
SELECTION m_selection
Current state of selection.
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
EDA_ITEM * Front() const
Definition: selection.h:152
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
bool selectable(const EDA_ITEM *aItem) const
Function selectable() Checks conditions for an item to be selected.
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
void Normalize()
Function Normalize ensures that the height ant width are positive.
void SetSubtractive(bool aSubtractive)
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1476
Class SELECTION_AREA.
int Size() const
Returns the number of selected parts.
Definition: selection.h:122
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
bool m_multiple
Flag saying if multiple selection mode is active.
Class VIEW.
Definition: view.h:61
void SetAdditive(bool aAdditive)
bool m_subtractive
Flag saying if items should be removed from the current selection.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
bool GERBVIEW_SELECTION_TOOL::selectPoint ( const VECTOR2I aWhere,
bool  aOnDrag = false 
)
private

Function selectPoint() 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 one to choose the item.

Parameters
aWhereis the place where the item should be selected.
aAllowDisambiguationdecides what to do in case of disambiguation. If true, then a menu is shown, otherise function finishes without selecting anything.
Returns
True if an item was selected, false otherwise.

Definition at line 291 of file gerbview/tools/selection_tool.cpp.

References GERBER_COLLECTOR::AllItems, BUT_LEFT, clearSelection(), GERBER_COLLECTOR::Collect(), disambiguationMenu(), COLLECTOR::GetCount(), i, m_additive, COLLECTOR::Remove(), selectable(), TA_MOUSE_UP, TC_ANY, toggleSelection(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Main(), and selectCursor().

292 {
293  EDA_ITEM* item = NULL;
294  GERBER_COLLECTOR collector;
295  EDA_ITEM* model = getModel<EDA_ITEM>();
296 
297  collector.Collect( model, GERBER_COLLECTOR::AllItems, wxPoint( aWhere.x, aWhere.y ) );
298 
299  bool anyCollected = collector.GetCount() != 0;
300 
301  // Remove unselectable items
302  for( int i = collector.GetCount() - 1; i >= 0; --i )
303  {
304  if( !selectable( collector[i] ) )
305  collector.Remove( i );
306  }
307 
308  switch( collector.GetCount() )
309  {
310  case 0:
311  if( !m_additive && anyCollected )
312  clearSelection();
313 
314  return false;
315 
316  case 1:
317  toggleSelection( collector[0] );
318 
319  return true;
320 
321  default:
322  // Let's see if there is still disambiguation in selection..
323  if( collector.GetCount() == 1 )
324  {
325  toggleSelection( collector[0] );
326 
327  return true;
328  }
329  else if( collector.GetCount() > 1 )
330  {
331  if( aOnDrag )
333 
334  item = disambiguationMenu( &collector );
335 
336  if( item )
337  {
338  toggleSelection( item );
339 
340  return true;
341  }
342  }
343  break;
344  }
345 
346  return false;
347 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
Class GERBER_COLLECTOR is intended for use when the right click button is pressed, or when the plain "arrow" tool is in effect.
EDA_ITEM * disambiguationMenu(GERBER_COLLECTOR *aItems)
Function disambiguationMenu() Handles the menu that allows one to select one of many items in case th...
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
static const KICAD_T AllItems[]
A scan list for all selectable gerber items.
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:143
bool selectable(const EDA_ITEM *aItem) const
Function selectable() Checks conditions for an item to be selected.
void Collect(EDA_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos)
Function Collect scans an EDA_ITEM using this class&#39;s Inspector method, which does the collection...
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
Class TOOL_EVENT.
Definition: tool_event.h:168
void toggleSelection(EDA_ITEM *aItem)
Function toggleSelection() Changes selection status of a given item.
size_t i
Definition: json11.cpp:597
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void clearSelection()
Function clearSelection() Clears the current selection.
void GERBVIEW_SELECTION_TOOL::selectVisually ( EDA_ITEM aItem)
private

Function selectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.

Parameters
aItemis an item to be be marked.

Definition at line 755 of file gerbview/tools/selection_tool.cpp.

References GetLayer(), TOOL_BASE::getView(), KIGFX::VIEW::Hide(), m_frame, m_selection, GERBVIEW_FRAME::SetActiveLayer(), EDA_ITEM::SetSelected(), and KIGFX::VIEW::Update().

Referenced by select().

756 {
757  // Move the item's layer to the front
758  int layer = static_cast<GERBER_DRAW_ITEM*>( aItem )->GetLayer();
759  m_frame->SetActiveLayer( layer, true );
760 
761  // Hide the original item, so it is shown only on overlay
762  aItem->SetSelected();
763  getView()->Hide( aItem, true );
764 
765  getView()->Update( &m_selection );
766 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1497
SELECTION m_selection
Current state of selection.
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function SetActiveLayer will change the currently active layer to aLayer and also update the GERBER_L...
void SetSelected()
Definition: base_struct.h:230
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
void TOOL_INTERACTIVE::SetContextMenu ( CONTEXT_MENU aMenu,
CONTEXT_MENU_TRIGGER  aTrigger = CMENU_BUTTON 
)
inherited

Function SetContextMenu()

Assigns a context menu and tells when it should be activated.

Parameters
aMenuis the menu to be assigned.
aTriggerdetermines conditions upon which the context menu is activated.

Definition at line 74 of file tool_interactive.cpp.

References CMENU_OFF, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ScheduleContextMenu(), and CONTEXT_MENU::SetTool().

Referenced by disambiguationMenu(), SELECTION_TOOL::doSelectionMenu(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), and TOOL_MENU::ShowContextMenu().

75 {
76  if( aMenu )
77  aMenu->SetTool( this );
78  else
79  aTrigger = CMENU_OFF;
80 
81  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
82 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
void ScheduleContextMenu(TOOL_BASE *aTool, CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool&#39;s context popup menu.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void GERBVIEW_SELECTION_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Implements TOOL_INTERACTIVE.

Definition at line 473 of file gerbview/tools/selection_tool.cpp.

References ClearSelection(), CursorSelection(), TOOL_INTERACTIVE::Go(), Main(), GERBVIEW_ACTIONS::measureTool, MeasureTool(), GERBVIEW_ACTIONS::selectionActivate, GERBVIEW_ACTIONS::selectionClear, GERBVIEW_ACTIONS::selectionCursor, GERBVIEW_ACTIONS::selectItem, SelectItem(), GERBVIEW_ACTIONS::unselectItem, and UnselectItem().

474 {
481 }
static TOOL_ACTION selectionClear
Clears the current selection.
int CursorSelection(const TOOL_EVENT &aEvent)
Select a single item under cursor event handler.
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
int Main(const TOOL_EVENT &aEvent)
Function Main()
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int UnselectItem(const TOOL_EVENT &aEvent)
Item unselection event handler.
static TOOL_ACTION measureTool
int MeasureTool(const TOOL_EVENT &aEvent)
Launches a tool to measure between points
int SelectItem(const TOOL_EVENT &aEvent)
Item selection event handler.
static TOOL_ACTION selectionActivate
Activation of the selection tool.
static TOOL_ACTION unselectItem
Unselects an item (specified as the event parameter).
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void GERBVIEW_SELECTION_TOOL::toggleSelection ( EDA_ITEM aItem)
private

Function toggleSelection() Changes selection status of a given item.

Parameters
aItemis the item to have selection status changed.

Definition at line 263 of file gerbview/tools/selection_tool.cpp.

References clearSelection(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), EDA_ITEM::IsSelected(), m_additive, m_frame, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), selectable(), SelectedEvent, unselect(), and UnselectedEvent.

Referenced by selectPoint().

264 {
265  if( aItem->IsSelected() )
266  {
267  unselect( aItem );
268 
269  // Inform other potentially interested tools
271  }
272  else
273  {
274  if( !m_additive )
275  clearSelection();
276 
277  // Prevent selection of invisible or inactive items
278  if( selectable( aItem ) )
279  {
280  select( aItem );
281 
282  // Inform other potentially interested tools
284  }
285  }
286 
288 }
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool IsSelected() const
Definition: base_struct.h:224
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
bool selectable(const EDA_ITEM *aItem) const
Function selectable() Checks conditions for an item to be selected.
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void clearSelection()
Function clearSelection() Clears the current selection.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:921
void GERBVIEW_SELECTION_TOOL::unselect ( EDA_ITEM aItem)
private

Function unselect() Takes necessary action mark an item as unselected.

Parameters
aItemis an item to be unselected.

Definition at line 739 of file gerbview/tools/selection_tool.cpp.

References SELECTION::Empty(), TOOL_BASE::getView(), EDA_ITEM::IsSelected(), m_frame, m_selection, SELECTION::Remove(), KIGFX::VIEW::Remove(), GERBVIEW_FRAME::SetCurItem(), and unselectVisually().

Referenced by selectMultiple(), toggleSelection(), UnselectItem(), and UnselectItems().

740 {
741  if( !aItem->IsSelected() )
742  return;
743 
744  unselectVisually( aItem );
745  m_selection.Remove( aItem );
746 
747  if( m_selection.Empty() )
748  {
749  m_frame->SetCurItem( NULL );
750  getView()->Remove( &m_selection );
751  }
752 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
void SetCurItem(GERBER_DRAW_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
SELECTION m_selection
Current state of selection.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
bool IsSelected() const
Definition: base_struct.h:224
void unselectVisually(EDA_ITEM *aItem)
Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:82
int GERBVIEW_SELECTION_TOOL::UnselectItem ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 563 of file gerbview/tools/selection_tool.cpp.

References TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), unselect(), and UnselectedEvent.

Referenced by setTransitions().

564 {
565  // Check if there is an item to be selected
566  EDA_ITEM* item = aEvent.Parameter<EDA_ITEM*>();
567 
568  if( item )
569  {
570  unselect( item );
571 
572  // Inform other potentially interested tools
574  }
575 
576  return 0;
577 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:387
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
int GERBVIEW_SELECTION_TOOL::UnselectItems ( const TOOL_EVENT aEvent)

Multiple item unselection event handler

Definition at line 543 of file gerbview/tools/selection_tool.cpp.

References TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), unselect(), and UnselectedEvent.

544 {
545  std::vector<EDA_ITEM*>* items = aEvent.Parameter<std::vector<EDA_ITEM*>*>();
546 
547  if( items )
548  {
549  // Perform individual unselection of each item
550  // before processing the event
551  for( auto item : *items )
552  {
553  unselect( item );
554  }
555 
557  }
558 
559  return 0;
560 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:387
void GERBVIEW_SELECTION_TOOL::unselectVisually ( EDA_ITEM aItem)
private

Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.

Parameters
aItemis an item to be be marked.

Definition at line 769 of file gerbview/tools/selection_tool.cpp.

References KIGFX::ALL, EDA_ITEM::ClearSelected(), TOOL_BASE::getView(), KIGFX::VIEW::Hide(), m_selection, and KIGFX::VIEW::Update().

Referenced by clearSelection(), and unselect().

770 {
771  // Restore original item visibility
772  aItem->ClearSelected();
773  getView()->Hide( aItem, false );
774  getView()->Update( aItem, KIGFX::ALL );
775 
776  getView()->Update( &m_selection );
777 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1497
void ClearSelected()
Definition: base_struct.h:234
SELECTION m_selection
Current state of selection.
Item needs to be redrawn.
Definition: view_item.h:61
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST aEventList = TOOL_EVENTTC_ANYTA_ANY ))
inherited

Function Wait()

Suspends execution of the tool until an event specified in aEventList arrives. No parameters means waiting for any event.

Definition at line 55 of file tool_interactive.cpp.

References TOOL_BASE::m_toolMgr, and TOOL_MANAGER::ScheduleWait().

Referenced by PCBNEW_CONTROL::DeleteItemCursor(), disambiguationMenu(), PCB_TOOL::doInteractiveItemPlacement(), SELECTION_TOOL::doSelectionMenu(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), PICKER_TOOL::Main(), CVPCB_SELECTION_TOOL::Main(), Main(), EDIT_TOOL::Main(), SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), selectMultiple(), SELECTION_TOOL::selectMultiple(), selectPoint(), SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), and PCB_EDITOR_CONTROL::ShowLocalRatsnest().

56 {
57  return m_toolMgr->ScheduleWait( this, aEventList );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
OPT< TOOL_EVENT > ScheduleWait(TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
Pauses execution of a given tool until one or more events matching aConditions arrives.
void GERBVIEW_SELECTION_TOOL::zoomFitSelection ( void  )

Zooms the screen to center and fit the current selection.

Definition at line 597 of file gerbview/tools/selection_tool.cpp.

References EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), TOOL_BASE::getView(), m_frame, m_selection, max, scale, SELECTION::ViewBBox(), VECTOR2< T >::x, and VECTOR2< T >::y.

598 {
599  //Should recalculate the view to zoom in on the selection
600  auto selectionBox = m_selection.ViewBBox();
601  auto canvas = m_frame->GetGalCanvas();
602  auto view = getView();
603 
604  VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false );
605 
606  if( !( selectionBox.GetWidth() == 0 ) || !( selectionBox.GetHeight() == 0 ) )
607  {
608  VECTOR2D vsize = selectionBox.GetSize();
609  double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
610  fabs( vsize.y / screenSize.y ) );
611  view->SetScale( scale );
612  view->SetCenter( selectionBox.Centre() );
613  view->Add( &m_selection );
614  }
615 
617 }
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
SELECTION m_selection
Current state of selection.
const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers...
Definition: selection.cpp:132
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
const int scale
#define max(a, b)
Definition: auxiliary.h:86
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:921

Member Data Documentation

const TOOL_EVENT GERBVIEW_SELECTION_TOOL::ClearedEvent
static

Event sent after selection is cleared.

Definition at line 108 of file gerbview/tools/selection_tool.h.

Referenced by clearSelection(), and MeasureTool().

bool GERBVIEW_SELECTION_TOOL::m_additive
private

Flag saying if items should be added to the current selection or rather replace it.

Definition at line 232 of file gerbview/tools/selection_tool.h.

Referenced by Main(), selectMultiple(), selectPoint(), and toggleSelection().

GERBVIEW_FRAME* GERBVIEW_SELECTION_TOOL::m_frame
private
TOOL_MENU GERBVIEW_SELECTION_TOOL::m_menu
private

Menu model displayed by the tool.

Definition at line 244 of file gerbview/tools/selection_tool.h.

Referenced by Init(), Main(), and MeasureTool().

bool GERBVIEW_SELECTION_TOOL::m_multiple
private

Flag saying if multiple selection mode is active.

Definition at line 238 of file gerbview/tools/selection_tool.h.

Referenced by selectMultiple().

bool GERBVIEW_SELECTION_TOOL::m_preliminary
private

Determines if the selection is preliminary or final.

Definition at line 241 of file gerbview/tools/selection_tool.h.

Referenced by GERBVIEW_SELECTION_TOOL(), and Reset().

bool GERBVIEW_SELECTION_TOOL::m_subtractive
private

Flag saying if items should be removed from the current selection.

Definition at line 235 of file gerbview/tools/selection_tool.h.

Referenced by selectMultiple().

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

Unique identifier for the tool, assigned by a TOOL_MANAGER instance.

Definition at line 210 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), and TOOL_BASE::IsToolActive().

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 215 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), TOOL_BASE::attachManager(), PCB_EDITOR_CONTROL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), PCB_EDITOR_CONTROL::ClearHighlight(), clearSelection(), SELECTION_TOOL::clearSelection(), PAD_TOOL::copyPadSettings(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_EDITOR_CONTROL::CrossProbePcbToSch(), PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), COMMON_TOOLS::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), EDIT_TOOL::Duplicate(), EDIT_TOOL::editFootprintInFpEditor(), MODULE_EDITOR_TOOLS::EnumeratePads(), EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::expandSelectedConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::findCallback(), SELECTION_TOOL::findMove(), EDIT_TOOL::Flip(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::getModelInt(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), GERBVIEW_CONTROL::HighlightControl(), PCB_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), POINT_EDITOR::Init(), POSITION_RELATIVE_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), TOOL_BASE::IsToolActive(), ZOOM_TOOL::Main(), PICKER_TOOL::Main(), EDIT_TOOL::Main(), SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), EDIT_TOOL::pickCopyReferencePoint(), PCBNEW_CONTROL::placeBoardItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), SELECTION_TOOL::RequestSelection(), CVPCB_CONTROL::ResetCoords(), PCBNEW_CONTROL::ResetCoords(), TOOL_INTERACTIVE::resetTransitions(), EDIT_TOOL::Rotate(), TOOL_INTERACTIVE::RunMainStack(), ZONE_FILLER_TOOL::SegzoneDeleteFill(), SELECTION_TOOL::selectCopper(), PCB_TOOL::selection(), SelectItem(), SELECTION_TOOL::SelectItem(), SelectItems(), SELECTION_TOOL::SelectItems(), selectMultiple(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectNet(), SELECTION_TOOL::selectOnSheetFromEeschema(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), SELECTION_TOOL::selectSameSheet(), TOOL_INTERACTIVE::SetContextMenu(), PCB_EDITOR_CONTROL::ShowLocalRatsnest(), toggleSelection(), SELECTION_TOOL::toggleSelection(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), UnselectItem(), SELECTION_TOOL::UnselectItem(), UnselectItems(), SELECTION_TOOL::UnselectItems(), PCB_EDITOR_CONTROL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), and PCB_EDITOR_CONTROL::ZoneMerge().

std::string TOOL_BASE::m_toolName
protectedinherited

Name of the tool.

Names are expected to obey the format application.ToolName

(eg. pcbnew.InteractiveSelection).

Definition at line 214 of file tool_base.h.

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 216 of file tool_base.h.

Referenced by TOOL_BASE::attachManager().

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 207 of file tool_base.h.

const TOOL_EVENT GERBVIEW_SELECTION_TOOL::SelectedEvent
static

Event sent after an item is selected.

Definition at line 102 of file gerbview/tools/selection_tool.h.

Referenced by MeasureTool(), SelectItem(), SelectItems(), selectMultiple(), and toggleSelection().

const TOOL_EVENT GERBVIEW_SELECTION_TOOL::UnselectedEvent
static

Event sent after an item is unselected.

Definition at line 105 of file gerbview/tools/selection_tool.h.

Referenced by MeasureTool(), toggleSelection(), UnselectItem(), and UnselectItems().


The documentation for this class was generated from the following files: