KiCad PCB EDA Suite
MODULE_EDITOR_TOOLS Class Reference

Class MODULE_EDITOR_TOOLS. More...

#include <module_editor_tools.h>

Inheritance diagram for MODULE_EDITOR_TOOLS:
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

 MODULE_EDITOR_TOOLS ()
 
 ~MODULE_EDITOR_TOOLS ()
 
void Reset (RESET_REASON aReason) override
 Function Reset() Brings the tool to a known, initial state. More...
 
int PlacePad (const TOOL_EVENT &aEvent)
 Function PlacePad() Places a pad in module editor. More...
 
int EnumeratePads (const TOOL_EVENT &aEvent)
 Function EnumeratePads() Tool for quick pad enumeration. More...
 
int CopyItems (const TOOL_EVENT &aEvent)
 Function CopyItems() More...
 
int PasteItems (const TOOL_EVENT &aEvent)
 Function PastePad() More...
 
int CreateArray (TOOL_EVENT &aEvent)
 Function CreateArray. More...
 
int ModuleTextOutlines (const TOOL_EVENT &aEvent)
 Function ModuleTextOutlines() More...
 
int ModuleEdgeOutlines (const TOOL_EVENT &aEvent)
 Function ModuleEdgeOutlines() More...
 
void SetTransitions () override
 

Sets up handlers for various events.

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...
 
virtual bool Init ()
 Function Init() Init() is called once upon a registration of the tool. 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 ()
 

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 Attributes

KIGFX::VIEWm_view
 
KIGFX::VIEW_CONTROLSm_controls
 
BOARDm_board
 
PCB_EDIT_FRAMEm_frame
 

Detailed Description

Class MODULE_EDITOR_TOOLS.

Module editor specific tools.

Definition at line 43 of file module_editor_tools.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

MODULE_EDITOR_TOOLS::MODULE_EDITOR_TOOLS ( )

Definition at line 82 of file module_editor_tools.cpp.

82  :
83  TOOL_INTERACTIVE( "pcbnew.ModuleEditor" ), m_view( NULL ), m_controls( NULL ),
84  m_board( NULL ), m_frame( NULL )
85 {
86 }
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
PCB_EDIT_FRAME * m_frame
KIGFX::VIEW_CONTROLS * m_controls
MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS ( )

Definition at line 89 of file module_editor_tools.cpp.

90 {
91 }

Member Function Documentation

void TOOL_INTERACTIVE::Activate ( )
inherited
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 54 of file tool_base.cpp.

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

Referenced by TOOL_MANAGER::RegisterTool().

55 {
56  m_toolMgr = aManager;
57  m_toolSettings = TOOL_SETTINGS( this );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:221
friend class TOOL_SETTINGS
Definition: tool_base.h:160
int MODULE_EDITOR_TOOLS::CopyItems ( const TOOL_EVENT aEvent)

Function CopyItems()

Copies selected items to the clipboard. Works only in "edit modules" mode.

Definition at line 331 of file module_editor_tools.cpp.

References TOOL_INTERACTIVE::Activate(), MODULE::Add(), BUT_LEFT, CTL_FOR_CLIPBOARD, EDA_DRAW_FRAME::DisplayToolMsg(), PCB_IO::Format(), Format(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), MODULE::GetPosition(), PCB_IO::GetStringOutput(), TOOL_MANAGER::GetTool(), m_board, m_controls, m_frame, BOARD::m_Modules, TOOL_BASE::m_toolMgr, MODULE::MoveAnchorPosition(), TOOL_MANAGER::SaveClipboard(), KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetSnapping(), KIGFX::VIEW_CONTROLS::ShowCursor(), SELECTION::Size(), TEXTE_MODULE::TEXT_is_DIVERS, TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetTransitions().

332 {
333  const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
334 
335  Activate();
336 
337  m_controls->SetSnapping( true );
338  m_controls->ShowCursor( true );
339  m_controls->SetAutoPan( true );
340 
341  m_frame->DisplayToolMsg( _( "Select reference point" ) );
342 
343  bool cancelled = false;
344  VECTOR2I cursorPos = m_controls->GetCursorPosition();
345 
346  while( OPT_TOOL_EVENT evt = Wait() )
347  {
348  if( evt->IsMotion() )
349  {
350  cursorPos = m_controls->GetCursorPosition();
351  }
352  else if( evt->IsClick( BUT_LEFT ) )
353  {
354  break;
355  }
356  else if( evt->IsCancel() || evt->IsActivate() )
357  {
358  cancelled = true;
359  break;
360  }
361  }
362 
363  if( !cancelled )
364  {
366 
367  // Create a temporary module that contains selected items to ease serialization
368  MODULE module( m_board );
369 
370  for( auto item : selection )
371  {
372  auto clone = static_cast<BOARD_ITEM*>( item->Clone() );
373 
374  // Do not add reference/value - convert them to the common type
375  if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
376  text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
377 
378  module.Add( clone );
379  }
380 
381  // Set the new relative internal local coordinates of copied items
382  MODULE* editedModule = m_board->m_Modules;
383  wxPoint moveVector = module.GetPosition() + editedModule->GetPosition() -
384  wxPoint( cursorPos.x, cursorPos.y );
385  module.MoveAnchorPosition( moveVector );
386 
387  io.Format( &module, 0 );
388  std::string data = io.GetStringOutput( true );
389  m_toolMgr->SaveClipboard( data );
390  }
391 
392  m_frame->DisplayToolMsg( wxString::Format( _( "Copied %d item(s)" ), selection.Size() ) );
393 
394  return 0;
395 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
bool SaveClipboard(const std::string &aText)
Stores an information to the system clipboard.
Class SELECTION_TOOL.
const wxPoint & GetPosition() const override
Definition: class_module.h:144
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
PCB_EDIT_FRAME * m_frame
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
KIGFX::VIEW_CONTROLS * m_controls
#define CTL_FOR_CLIPBOARD
Format output for the clipboard instead of footprint library or BOARD.
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
DLIST< MODULE > m_Modules
Definition: class_board.h:243
void Activate()
Function Activate() Runs the tool.
int MODULE_EDITOR_TOOLS::CreateArray ( TOOL_EVENT aEvent)

Function CreateArray.

Creates an array of objects using settings from a dialog

int MODULE_EDITOR_TOOLS::EnumeratePads ( const TOOL_EVENT aEvent)

Function EnumeratePads() Tool for quick pad enumeration.

Definition at line 189 of file module_editor_tools.cpp.

References TOOL_INTERACTIVE::Activate(), BUT_LEFT, GENERAL_COLLECTOR::Collect(), EDA_DRAW_FRAME::DisplayToolMsg(), COLLECTOR::Empty(), EOT, EuclideanNorm(), Format(), PCB_BASE_FRAME::GetCollectorsGuide(), COLLECTOR::GetCount(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), DIALOG_ENUM_PADS::GetPrefix(), DIALOG_ENUM_PADS::GetStartNumber(), TOOL_BASE::getView(), TOOL_MANAGER::GetView(), m_board, m_controls, m_frame, BOARD::m_Modules, TOOL_BASE::m_toolMgr, COMMIT::Modify(), D_PAD::Next(), MODULE::Pads(), PCB_PAD_T, BOARD_COMMIT::Push(), BOARD_COMMIT::Revert(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesRefs(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesVals(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsMarkedNoShow(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnFront(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetTransitions().

190 {
191  if( !m_board->m_Modules || !m_board->m_Modules->Pads() )
192  return 0;
193 
194  Activate();
195 
196  GENERAL_COLLECTOR collector;
197  const KICAD_T types[] = { PCB_PAD_T, EOT };
198 
200  guide.SetIgnoreMTextsMarkedNoShow( true );
201  guide.SetIgnoreMTextsOnBack( true );
202  guide.SetIgnoreMTextsOnFront( true );
203  guide.SetIgnoreModulesVals( true );
204  guide.SetIgnoreModulesRefs( true );
205 
206  DIALOG_ENUM_PADS settingsDlg( m_frame );
207 
208  if( settingsDlg.ShowModal() == wxID_CANCEL )
209  return 0;
210 
211  int padNumber = settingsDlg.GetStartNumber();
212  wxString padPrefix = settingsDlg.GetPrefix();
213 
214  m_frame->DisplayToolMsg( _( "Hold left mouse button and move cursor over pads to enumerate them" ) );
215 
217  m_controls->ShowCursor( true );
218 
219  KIGFX::VIEW* view = m_toolMgr->GetView();
220  VECTOR2I oldCursorPos = m_controls->GetCursorPosition();
221  std::list<D_PAD*> selectedPads;
222  BOARD_COMMIT commit( m_frame );
223  std::map<wxString, wxString> oldNames;
224 
225  while( OPT_TOOL_EVENT evt = Wait() )
226  {
227  if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
228  {
229  selectedPads.clear();
230  VECTOR2I cursorPos = m_controls->GetCursorPosition();
231 
232  if( evt->IsClick( BUT_LEFT ) )
233  {
234  oldCursorPos = m_controls->GetCursorPosition();
235  collector.Empty();
236  collector.Collect( m_board, types, wxPoint( cursorPos.x, cursorPos.y ), guide );
237 
238  for( int i = 0; i < collector.GetCount(); ++i )
239  {
240  if( collector[i]->Type() == PCB_PAD_T )
241  selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
242  }
243  }
244  else //evt->IsDrag( BUT_LEFT )
245  {
246  // wxWidgets deliver mouse move events not frequently enough, resulting in skipping
247  // pads if the user moves cursor too fast. To solve it, create a line that approximates
248  // the mouse move and select items intersecting with the line.
249  int distance = ( cursorPos - oldCursorPos ).EuclideanNorm();
250  int segments = distance / 100000 + 1;
251  const wxPoint LINE_STEP( ( cursorPos - oldCursorPos ).x / segments,
252  ( cursorPos - oldCursorPos ).y / segments );
253 
254  collector.Empty();
255  for( int j = 0; j < segments; ++j ) {
256  collector.Collect( m_board, types,
257  wxPoint( oldCursorPos.x, oldCursorPos.y ) + j * LINE_STEP,
258  guide );
259 
260  for( int i = 0; i < collector.GetCount(); ++i )
261  {
262  if( collector[i]->Type() == PCB_PAD_T )
263  selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
264  }
265  }
266 
267  selectedPads.unique();
268  }
269 
270  for( D_PAD* pad : selectedPads )
271  {
272  // If pad was not selected, then enumerate it
273  if( !pad->IsSelected() )
274  {
275  commit.Modify( pad );
276 
277  // Rename pad and store the old name
278  wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ );
279  oldNames[newName] = pad->GetPadName();
280  pad->SetPadName( newName );
281  pad->SetSelected();
282  getView()->Update( pad );
283  }
284 
285  // ..or restore the old name if it was enumerated and clicked again
286  else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
287  {
288  auto it = oldNames.find( pad->GetPadName() );
289  wxASSERT( it != oldNames.end() );
290 
291  if( it != oldNames.end() )
292  {
293  pad->SetPadName( it->second );
294  oldNames.erase( it );
295  }
296 
297  pad->ClearSelected();
298  getView()->Update( pad );
299  }
300  }
301 
302  oldCursorPos = cursorPos;
303  }
304 
305  else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
306  evt->IsDblClick( BUT_LEFT ) )
307  {
308  commit.Push( _( "Enumerate pads" ) );
309  break;
310  }
311 
312  else if( evt->IsCancel() || evt->IsActivate() )
313  {
314  commit.Revert();
315  break;
316  }
317  }
318 
319  for( D_PAD* p = m_board->m_Modules->Pads(); p; p = p->Next() )
320  {
321  p->ClearSelected();
322  view->Update( p );
323  }
324 
325  m_frame->DisplayToolMsg( wxEmptyString );
326 
327  return 0;
328 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
void Empty()
Function Empty sets the list to empty.
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
int GetCount() const
Function GetCount returns the number of objects in the list.
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Function Collect scans a BOARD_ITEM using this class's Inspector method, which does the collection...
Definition: collectors.cpp:447
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:577
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:584
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
Implementing DIALOG_ENUM_PADS_BASE.
search types array terminator (End Of Types)
Definition: typeinfo.h:94
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
PCB_EDIT_FRAME * m_frame
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:535
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
KIGFX::VIEW_CONTROLS * m_controls
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:542
D_PAD * Next() const
Definition: class_pad.h:106
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:528
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
DLIST< MODULE > m_Modules
Definition: class_board.h:243
Class GENERAL_COLLECTOR is intended for use when the right click button is pressed, or when the plain "arrow" tool is in effect.
Definition: collectors.h:211
void Activate()
Function Activate() Runs the tool.
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
Class VIEW.
Definition: view.h:58
Class GENERAL_COLLECTORS_GUIDE is a general implementation of a COLLECTORS_GUIDE. ...
Definition: collectors.h:378
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
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 193 of file tool_base.h.

References TOOL_BASE::getEditFrameInt().

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

194  {
195  return static_cast<T*>( getEditFrameInt() );
196  }
T
enum T contains all this lexer's tokens.
wxWindow * getEditFrameInt() const
Definition: tool_base.cpp:42
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.

References TOOL_BASE::m_toolId.

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

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:215
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.

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), PCB_TOOL::doInteractiveItemPlacement(), CONTEXT_MENU::getToolManager(), EDIT_TOOL::MeasureTool(), and CONTEXT_MENU::onMenuEvent().

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

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 204 of file tool_base.h.

References TOOL_BASE::getModelInt().

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

205  {
206  EDA_ITEM* m = getModelInt();
207 
208  return static_cast<T*>( m );
209  }
T
enum T contains all this lexer's tokens.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:48
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.

References TOOL_BASE::m_toolName.

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:219
TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 72 of file tool_base.cpp.

References TOOL_BASE::m_toolSettings.

Referenced by ROUTER_TOOL::Init(), SELECTION_TOOL::selectable(), and ROUTER_TOOL::~ROUTER_TOOL().

73 {
74  return m_toolSettings;
75 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:221
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.

References TOOL_BASE::m_type.

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

112  {
113  return m_type;
114  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:212
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 30 of file tool_base.cpp.

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

Referenced by PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), PCBNEW_CONTROL::CursorControl(), SELECTION_TOOL::disambiguationMenu(), PCB_TOOL::doInteractiveItemPlacement(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), EnumeratePads(), SELECTION_TOOL::findCallback(), ROUTER_TOOL::getStartLayer(), PCBNEW_CONTROL::GridSetOrigin(), PCBNEW_CONTROL::HighContrastMode(), PNS::TOOL_BASE::highlightNet(), PCB_EDITOR_CONTROL::HighlightNet(), PCBNEW_CONTROL::LayerAlphaDec(), PCBNEW_CONTROL::LayerAlphaInc(), EDIT_TOOL::Main(), EDIT_TOOL::MeasureTool(), ModuleEdgeOutlines(), ModuleTextOutlines(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::PanControl(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PCB_EDITOR_CONTROL::Reset(), PCBNEW_CONTROL::Reset(), Reset(), PNS::TOOL_BASE::Reset(), DRAWING_TOOL::Reset(), SELECTION_TOOL::Reset(), SELECTION_TOOL::selectable(), SELECTION_TOOL::selectionContains(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), PCBNEW_CONTROL::TrackDisplayMode(), POINT_EDITOR::updateEditedPoint(), PNS::TOOL_BASE::updateEndItem(), COMMON_TOOLS::updateGrid(), PCBNEW_CONTROL::updateGrid(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCBNEW_CONTROL::ViaDisplayMode(), PCB_TOOL::view(), PCBNEW_CONTROL::ZoneDisplayMode(), PCB_EDITOR_CONTROL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneFillAll(), PCB_EDITOR_CONTROL::ZoneUnfill(), PCB_EDITOR_CONTROL::ZoneUnfillAll(), COMMON_TOOLS::ZoomFitScreen(), SELECTION_TOOL::zoomFitSelection(), COMMON_TOOLS::ZoomInOutCenter(), and SELECTION_TOOL::~SELECTION_TOOL().

31 {
32  return m_toolMgr->GetView();
33 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited
template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited

Function Go()

Defines which state (aStateFunc) to go when a certain event arrives (aConditions). No conditions means any event.

Definition at line 122 of file tool_interactive.h.

References TOOL_INTERACTIVE::goInternal().

Referenced by LENGTH_TUNER_TOOL::Reset(), ZOOM_TOOL::SetTransitions(), LENGTH_TUNER_TOOL::SetTransitions(), ROUTER_TOOL::SetTransitions(), PAD_TOOL::SetTransitions(), MICROWAVE_TOOL::SetTransitions(), POINT_EDITOR::SetTransitions(), COMMON_TOOLS::SetTransitions(), PLACEMENT_TOOL::SetTransitions(), PCBNEW_CONTROL::SetTransitions(), SetTransitions(), PICKER_TOOL::SetTransitions(), PCB_EDITOR_CONTROL::SetTransitions(), SELECTION_TOOL::SetTransitions(), EDIT_TOOL::SetTransitions(), and DRAWING_TOOL::SetTransitions().

124 {
125  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
126 
127  goInternal( sptr, aConditions );
128 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:59
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
virtual bool TOOL_BASE::Init ( )
inlinevirtualinherited

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

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

Reimplemented in SELECTION_TOOL, DRAWING_TOOL, EDIT_TOOL, PCB_EDITOR_CONTROL, POINT_EDITOR, MICROWAVE_TOOL, PAD_TOOL, PLACEMENT_TOOL, and ROUTER_TOOL.

Definition at line 93 of file tool_base.h.

Referenced by TOOL_MANAGER::InitTools().

94  {
95  return true;
96  }
int MODULE_EDITOR_TOOLS::ModuleEdgeOutlines ( const TOOL_EVENT aEvent)

Function ModuleEdgeOutlines()

Toggles display mode for module edges (outline/filled).

Definition at line 550 of file module_editor_tools.cpp.

References B_Adhes, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Mask, F_Paste, F_SilkS, KIGFX::GEOMETRY, EDA_DRAW_FRAME::GetGalCanvas(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), KIGFX::PCB_RENDER_SETTINGS::GetSketchMode(), TOOL_BASE::getView(), m_frame, MODULE::Next(), BOARD_ITEM::Next(), PCB_MODULE_EDGE_T, EDA_DRAW_PANEL_GAL::Refresh(), KIGFX::PCB_RENDER_SETTINGS::SetSketchMode(), and KIGFX::VIEW::Update().

Referenced by SetTransitions().

551 {
552  KIGFX::VIEW* view = getView();
553  KIGFX::PCB_RENDER_SETTINGS* settings =
554  static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
555 
556  const PCB_LAYER_ID layers[] = { F_Adhes, B_Adhes, F_Paste, B_Paste,
559 
560  bool enable = !settings->GetSketchMode( layers[0] );
561 
562  for( LAYER_NUM layer : layers )
563  settings->SetSketchMode( layer, enable );
564 
565  for( MODULE* module = getModel<BOARD>()->m_Modules; module; module = module->Next() )
566  {
567  for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item ->Next() )
568  {
569  if( item->Type() == PCB_MODULE_EDGE_T )
570  view->Update( item, KIGFX::GEOMETRY );
571  }
572  }
573 
575 
576  return 0;
577 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
MODULE * Next() const
Definition: class_module.h:100
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
bool GetSketchMode(int aItemLayer) const
Function GetSketchMode Returns sketch mode setting for a given item layer.
Definition: pcb_painter.h:124
PCB_EDIT_FRAME * m_frame
BOARD_ITEM * Next() const
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
PCB_LAYER_ID
A quick note on layer IDs:
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void SetSketchMode(int aItemLayer, bool aEnabled)
Function SetSketchMode Turns on/off sketch mode for given item layer.
Definition: pcb_painter.h:114
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:803
Class VIEW.
Definition: view.h:58
Color has changed.
Definition: view_item.h:57
int MODULE_EDITOR_TOOLS::ModuleTextOutlines ( const TOOL_EVENT aEvent)

Function ModuleTextOutlines()

Toggles display mode for module texts (outline/filled).

Definition at line 515 of file module_editor_tools.cpp.

References KIGFX::GEOMETRY, EDA_DRAW_FRAME::GetGalCanvas(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), KIGFX::PCB_RENDER_SETTINGS::GetSketchMode(), TOOL_BASE::getView(), LAYER_MOD_REFERENCES, LAYER_MOD_TEXT_BK, LAYER_MOD_TEXT_FR, LAYER_MOD_TEXT_INVISIBLE, LAYER_MOD_VALUES, m_frame, MODULE::Next(), BOARD_ITEM::Next(), PCB_MODULE_TEXT_T, EDA_DRAW_PANEL_GAL::Refresh(), KIGFX::PCB_RENDER_SETTINGS::SetSketchMode(), and KIGFX::VIEW::Update().

Referenced by SetTransitions().

516 {
517  KIGFX::VIEW* view = getView();
518  KIGFX::PCB_RENDER_SETTINGS* settings =
519  static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
520 
521  const LAYER_NUM layers[] = { LAYER_MOD_TEXT_BK,
526 
527  bool enable = !settings->GetSketchMode( layers[0] );
528 
529  for( LAYER_NUM layer : layers )
530  settings->SetSketchMode( layer, enable );
531 
532  for( MODULE* module = getModel<BOARD>()->m_Modules; module; module = module->Next() )
533  {
534  for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item ->Next() )
535  {
536  if( item->Type() == PCB_MODULE_TEXT_T )
537  view->Update( item, KIGFX::GEOMETRY );
538  }
539 
540  view->Update( &module->Reference(), KIGFX::GEOMETRY );
541  view->Update( &module->Value(), KIGFX::GEOMETRY );
542  }
543 
545 
546  return 0;
547 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
MODULE * Next() const
Definition: class_module.h:100
show modules values (when texts are visibles)
bool GetSketchMode(int aItemLayer) const
Function GetSketchMode Returns sketch mode setting for a given item layer.
Definition: pcb_painter.h:124
PCB_EDIT_FRAME * m_frame
BOARD_ITEM * Next() const
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void SetSketchMode(int aItemLayer, bool aEnabled)
Function SetSketchMode Turns on/off sketch mode for given item layer.
Definition: pcb_painter.h:114
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:803
Class VIEW.
Definition: view.h:58
show modules references (when texts are visibles)
Color has changed.
Definition: view_item.h:57
int MODULE_EDITOR_TOOLS::PasteItems ( const TOOL_EVENT aEvent)

Function PastePad()

Pastes items from the clipboard. Works only in "edit modules" mode.

Definition at line 398 of file module_editor_tools.cpp.

References TOOL_INTERACTIVE::Activate(), KIGFX::VIEW_GROUP::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), BUT_LEFT, KIGFX::VIEW_GROUP::Clear(), CTL_FOR_CLIPBOARD, EDA_DRAW_FRAME::DisplayToolMsg(), dyn_cast(), PCB_ACTIONS::flip, MODULE::Flip(), TOOL_MANAGER::GetClipboard(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), MODULE::GetOrientation(), MODULE::GetPosition(), MODULE::GraphicalItems(), TOOL_EVT_UTILS::IsRotateToolEvt(), m_board, m_controls, m_frame, BOARD::m_Status_Pcb, TOOL_BASE::m_toolMgr, m_view, D_PAD::Next(), BOARD_ITEM::Next(), MODULE::Pads(), PCB_IO::Parse(), PCB_MODULE_T, BOARD_COMMIT::Push(), KIGFX::VIEW::Remove(), MODULE::Rotate(), BOARD_ITEM::Rotate(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_ITEM::SetParent(), MODULE::SetPosition(), KIGFX::VIEW_CONTROLS::SetSnapping(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_COMMAND, TEXTE_MODULE::TEXT_is_DIVERS, EDA_ITEM::Type(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetTransitions().

399 {
400  // Parse clipboard
402  MODULE* pastedModule = NULL;
403 
404  try
405  {
406  BOARD_ITEM* item = io.Parse( wxString( m_toolMgr->GetClipboard().c_str(), wxConvUTF8 ) );
407  assert( item->Type() == PCB_MODULE_T );
408  pastedModule = dyn_cast<MODULE*>( item );
409  }
410  catch( ... )
411  {
412  m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
413  return 0;
414  }
415 
416  // Placement tool part
417  VECTOR2I cursorPos = m_controls->GetCursorPosition();
418 
419  // Add a VIEW_GROUP that serves as a preview for the new item
420  KIGFX::VIEW_GROUP preview( m_view );
421  pastedModule->SetParent( m_board );
422  pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
423  pastedModule->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add,
424  std::ref( preview ), _1 ) );
425  preview.Add( pastedModule );
426  m_view->Add( &preview );
427 
429  m_controls->ShowCursor( true );
430  m_controls->SetSnapping( true );
431  m_controls->SetAutoPan( true );
432 
433  Activate();
434 
435  // Main loop: keep receiving events
436  while( OPT_TOOL_EVENT evt = Wait() )
437  {
438  cursorPos = m_controls->GetCursorPosition();
439 
440  if( evt->IsMotion() )
441  {
442  pastedModule->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
443  m_view->Update( &preview );
444  }
445 
446  else if( evt->Category() == TC_COMMAND )
447  {
448  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
449  {
450  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
451  *m_frame, *evt );
452  pastedModule->Rotate( pastedModule->GetPosition(), rotationAngle );
453  m_view->Update( &preview );
454  }
455  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
456  {
457  pastedModule->Flip( pastedModule->GetPosition() );
458  m_view->Update( &preview );
459  }
460  else if( evt->IsCancel() || evt->IsActivate() )
461  {
462  preview.Clear();
463  break;
464  }
465  }
466 
467  else if( evt->IsClick( BUT_LEFT ) )
468  {
469  BOARD_COMMIT commit( m_frame );
470 
471  m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
472 
473  // MODULE::RunOnChildren is infeasible here: we need to create copies of items, do not
474  // directly modify them
475 
476  for( D_PAD* pad = pastedModule->Pads(); pad; pad = pad->Next() )
477  {
478  D_PAD* clone = static_cast<D_PAD*>( pad->Clone() );
479  commit.Add( clone );
480  }
481 
482  for( BOARD_ITEM* drawing = pastedModule->GraphicalItems();
483  drawing; drawing = drawing->Next() )
484  {
485  BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( drawing->Clone() );
486 
487  if( TEXTE_MODULE* text = dyn_cast<TEXTE_MODULE*>( clone ) )
488  {
489  // Do not add reference/value - convert them to the common type
490  text->SetType( TEXTE_MODULE::TEXT_is_DIVERS );
491 
492  // Whyyyyyyyyyyyyyyyyyyyyyy?! All other items conform to rotation performed
493  // on its parent module, but texts are so independent..
494  text->Rotate( text->GetPosition(), pastedModule->GetOrientation() );
495  commit.Add( text );
496  }
497 
498  commit.Add( clone );
499  }
500 
501  commit.Push( _( "Paste clipboard contents" ) );
502  preview.Clear();
503 
504  break;
505  }
506  }
507 
508  delete pastedModule;
509  m_view->Remove( &preview );
510 
511  return 0;
512 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
const wxPoint & GetPosition() const override
Definition: class_module.h:144
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:341
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:137
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
PCB_EDIT_FRAME * m_frame
BOARD_ITEM * Next() const
class MODULE, a footprint
Definition: typeinfo.h:101
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
KIGFX::VIEW_CONTROLS * m_controls
double GetOrientation() const
Definition: class_module.h:148
#define CTL_FOR_CLIPBOARD
Format output for the clipboard instead of footprint library or BOARD.
D_PAD * Next() const
Definition: class_pad.h:106
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
void SetPosition(const wxPoint &aPos) override
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
std::string GetClipboard() const
Returns the information currently stored in the system clipboard.
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:90
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
void Activate()
Function Activate() Runs the tool.
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
DLIST< D_PAD > & Pads()
Definition: class_module.h:134
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
int MODULE_EDITOR_TOOLS::PlacePad ( const TOOL_EVENT aEvent)

Function PlacePad() Places a pad in module editor.

Definition at line 104 of file module_editor_tools.cpp.

References TOOL_INTERACTIVE::Activate(), KIGFX::VIEW_GROUP::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), BUT_LEFT, KIGFX::VIEW_GROUP::Clear(), PCB_ACTIONS::flip, D_PAD::Flip(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), D_PAD::GetPosition(), ID_MODEDIT_PAD_TOOL, ID_NO_TOOL_SELECTED, PCB_BASE_FRAME::Import_Pad_Settings(), D_PAD::IncrementPadName(), TOOL_EVT_UTILS::IsRotateToolEvt(), m_board, m_controls, m_frame, BOARD::m_Modules, BOARD::m_Status_Pcb, TOOL_BASE::m_toolMgr, m_view, BOARD_COMMIT::Push(), KIGFX::VIEW_GROUP::Remove(), KIGFX::VIEW::Remove(), D_PAD::Rotate(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, D_PAD::SetPosition(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::SetToolID(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_COMMAND, KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetTransitions().

105 {
106  m_frame->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) );
107 
108  assert( m_board->m_Modules );
109 
110  D_PAD* pad = new D_PAD( m_board->m_Modules );
111  m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad
112 
113  VECTOR2I cursorPos = m_controls->GetCursorPosition();
114  pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
115 
116  // Add a VIEW_GROUP that serves as a preview for the new item
117  KIGFX::VIEW_GROUP preview( m_view );
118  preview.Add( pad );
119  m_view->Add( &preview );
120 
122  m_controls->ShowCursor( true );
123  m_controls->SetSnapping( true );
124 
125  Activate();
126 
127  // Main loop: keep receiving events
128  while( OPT_TOOL_EVENT evt = Wait() )
129  {
130  cursorPos = m_controls->GetCursorPosition();
131 
132  if( evt->IsMotion() )
133  {
134  pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
135  m_view->Update( &preview );
136  }
137 
138  else if( evt->Category() == TC_COMMAND )
139  {
140  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
141  {
142  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
143  *m_frame, *evt );
144  pad->Rotate( pad->GetPosition(), rotationAngle );
145  m_view->Update( &preview );
146  }
147  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
148  {
149  pad->Flip( pad->GetPosition() );
150  m_view->Update( &preview );
151  }
152  else if( evt->IsCancel() || evt->IsActivate() )
153  {
154  preview.Clear();
155  delete pad;
156  break;
157  }
158  }
159 
160  else if( evt->IsClick( BUT_LEFT ) )
161  {
162  BOARD_COMMIT commit( m_frame );
163  commit.Add( pad );
164 
165  m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
166 
167  // Take the next available pad number
168  pad->IncrementPadName( true, true );
169 
170  // Handle the view aspect
171  preview.Remove( pad );
172  commit.Push( _( "Add a pad" ) );
173 
174  // Start placing next pad
175  pad = new D_PAD( m_board->m_Modules );
176  m_frame->Import_Pad_Settings( pad, false );
177  pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
178  preview.Add( pad );
179  }
180  }
181 
182  m_view->Remove( &preview );
183  m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
184 
185  return 0;
186 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
bool IncrementPadName(bool aSkipUnconnectable, bool aFillSequenceGaps)
Function IncrementPadName.
Definition: class_pad.cpp:475
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Function SetToolID sets the tool command ID to aId and sets the cursor to aCursor.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:1077
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:341
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
PCB_EDIT_FRAME * m_frame
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
KIGFX::VIEW_CONTROLS * m_controls
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:90
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Definition: class_pad.cpp:364
DLIST< MODULE > m_Modules
Definition: class_board.h:243
void Activate()
Function Activate() Runs the tool.
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void Import_Pad_Settings(D_PAD *aPad, bool aDraw)
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
void MODULE_EDITOR_TOOLS::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 94 of file module_editor_tools.cpp.

References TOOL_BASE::getView(), TOOL_BASE::getViewControls(), m_board, m_controls, m_frame, and m_view.

95 {
96  // Init variables used by every drawing tool
97  m_view = getView();
99  m_board = getModel<BOARD>();
100  m_frame = getEditFrame<PCB_EDIT_FRAME>();
101 }
PCB_EDIT_FRAME * m_frame
KIGFX::VIEW_CONTROLS * m_controls
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
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 78 of file tool_interactive.cpp.

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

Referenced by DRAWING_TOOL::PlaceText().

79 {
80  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
81 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
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 67 of file tool_interactive.cpp.

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

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

68 {
69  if( aMenu )
70  aMenu->SetTool( this );
71  else
72  aTrigger = CMENU_OFF;
73 
74  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
75 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void ScheduleContextMenu(TOOL_BASE *aTool, CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool's context popup menu.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void MODULE_EDITOR_TOOLS::SetTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from TOOL_BASE.

Definition at line 580 of file module_editor_tools.cpp.

References CopyItems(), PCB_ACTIONS::copyItems, EnumeratePads(), PCB_ACTIONS::enumeratePads, TOOL_INTERACTIVE::Go(), ModuleEdgeOutlines(), PCB_ACTIONS::moduleEdgeOutlines, ModuleTextOutlines(), PCB_ACTIONS::moduleTextOutlines, PasteItems(), PCB_ACTIONS::pasteItems, PlacePad(), and PCB_ACTIONS::placePad.

581 {
588 }
static TOOL_ACTION enumeratePads
Tool for quick pad enumeration.
Definition: pcb_actions.h:270
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
Definition: pcb_actions.h:267
static TOOL_ACTION copyItems
Copying module items to clipboard.
Definition: pcb_actions.h:276
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int PasteItems(const TOOL_EVENT &aEvent)
Function PastePad()
static TOOL_ACTION pasteItems
Pasting module items from clipboard.
Definition: pcb_actions.h:279
int ModuleTextOutlines(const TOOL_EVENT &aEvent)
Function ModuleTextOutlines()
int PlacePad(const TOOL_EVENT &aEvent)
Function PlacePad() Places a pad in module editor.
int CopyItems(const TOOL_EVENT &aEvent)
Function CopyItems()
static TOOL_ACTION moduleEdgeOutlines
Display module edges as outlines.
Definition: pcb_actions.h:282
int ModuleEdgeOutlines(const TOOL_EVENT &aEvent)
Function ModuleEdgeOutlines()
static TOOL_ACTION moduleTextOutlines
Display module texts as outlines.
Definition: pcb_actions.h:285
int EnumeratePads(const TOOL_EVENT &aEvent)
Function EnumeratePads() Tool for quick pad enumeration.
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 CopyItems(), PCBNEW_CONTROL::DeleteItemCursor(), SELECTION_TOOL::disambiguationMenu(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), PCB_EDITOR_CONTROL::DrillOrigin(), EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), PICKER_TOOL::Main(), EDIT_TOOL::Main(), SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), PasteItems(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::runPolygonEventLoop(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectPoint(), ZOOM_TOOL::selectRegion(), and DRAWING_TOOL::SetAnchor().

56 {
57  return m_toolMgr->ScheduleWait( this, aEventList );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
boost::optional< 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.

Member Data Documentation

BOARD* MODULE_EDITOR_TOOLS::m_board
private

Definition at line 105 of file module_editor_tools.h.

Referenced by CopyItems(), EnumeratePads(), PasteItems(), PlacePad(), and Reset().

KIGFX::VIEW_CONTROLS* MODULE_EDITOR_TOOLS::m_controls
private

Definition at line 104 of file module_editor_tools.h.

Referenced by CopyItems(), EnumeratePads(), PasteItems(), PlacePad(), and Reset().

PCB_EDIT_FRAME* MODULE_EDITOR_TOOLS::m_frame
private
TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 215 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), TOOL_BASE::GetId(), and EDIT_TOOL::getModificationPoint().

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 220 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), PCBNEW_CONTROL::AppendBoard(), PAD_TOOL::applyPadSettings(), TOOL_BASE::attachManager(), SELECTION_TOOL::clearSelection(), CopyItems(), PAD_TOOL::copyPadSettings(), PCB_EDITOR_CONTROL::CrossProbePcbToSch(), PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), PCBNEW_CONTROL::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(), EnumeratePads(), EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::findCallback(), SELECTION_TOOL::findMove(), EDIT_TOOL::Flip(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), EDIT_TOOL::getModificationPoint(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::Init(), PLACEMENT_TOOL::Init(), PAD_TOOL::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), 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(), PasteItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EDIT_TOOL::Remove(), SELECTION_TOOL::RequestSelection(), EDIT_TOOL::Rotate(), TOOL_INTERACTIVE::RunMainStack(), SELECTION_TOOL::SanitizeSelection(), SELECTION_TOOL::selectConnection(), SELECTION_TOOL::selectCopper(), SELECTION_TOOL::SelectItem(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectNet(), SELECTION_TOOL::selectOnSheetFromEeschema(), SELECTION_TOOL::selectSameSheet(), TOOL_INTERACTIVE::SetContextMenu(), SELECTION_TOOL::toggleSelection(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), SELECTION_TOOL::UnselectItem(), PCB_EDITOR_CONTROL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), PCB_EDITOR_CONTROL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and PCB_EDITOR_CONTROL::ZoneUnfill().

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 219 of file tool_base.h.

Referenced by TOOL_BASE::GetName().

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 221 of file tool_base.h.

Referenced by TOOL_BASE::attachManager(), and TOOL_BASE::GetSettings().

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 212 of file tool_base.h.

Referenced by TOOL_BASE::GetType().

KIGFX::VIEW* MODULE_EDITOR_TOOLS::m_view
private

Definition at line 103 of file module_editor_tools.h.

Referenced by PasteItems(), PlacePad(), and Reset().


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