KiCad PCB EDA Suite
DRAWING_TOOL Class Reference

Class DRAWING_TOOL. More...

#include <drawing_tool.h>

Inheritance diagram for DRAWING_TOOL:
PCB_TOOL_BASE TOOL_INTERACTIVE TOOL_BASE

Public Types

enum  MODE {
  MODE::NONE, MODE::LINE, MODE::CIRCLE, MODE::ARC,
  MODE::TEXT, MODE::ANCHOR, MODE::DXF, MODE::DIMENSION,
  MODE::KEEPOUT, MODE::ZONE, MODE::GRAPHIC_POLYGON, MODE::VIA
}
 

The possible drawing modes of DRAWING_TOOL

More...
 
enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 

Determines the reason of reset for a tool

More...
 

Public Member Functions

 DRAWING_TOOL ()
 
 ~DRAWING_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...
 
MODE GetDrawingMode () const
 Function GetDrawingMode. More...
 
int DrawLine (const TOOL_EVENT &aEvent)
 Function DrawLine() Starts interactively drawing a line. More...
 
int DrawCircle (const TOOL_EVENT &aEvent)
 Function DrawCircle() Starts interactively drawing a circle. More...
 
int DrawArc (const TOOL_EVENT &aEvent)
 Function DrawArc() Starts interactively drawing an arc. More...
 
int PlaceText (const TOOL_EVENT &aEvent)
 Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets the user decide where to place the text in editor. More...
 
int DrawDimension (const TOOL_EVENT &aEvent)
 Function DrawDimension() Starts interactively drawing a dimension. More...
 
int DrawZone (const TOOL_EVENT &aEvent)
 Function DrawZone() Starts interactively drawing a zone. More...
 
int DrawVia (const TOOL_EVENT &aEvent)
 
int PlaceImportedGraphics (const TOOL_EVENT &aEvent)
 Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor. More...
 
int SetAnchor (const TOOL_EVENT &aEvent)
 Function SetAnchor() Places the footprint anchor (only in module editor). More...
 
void setTransitions () override
 

Sets up handlers for various events.

More...
 
void SetEditModules (bool aEnabled)
 Function SetEditModules() More...
 
bool EditingModules () const
 
void Activate ()
 Function Activate() Runs the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_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...
 
TOOL_EVENTWait (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
 

Protected Types

enum  INTERACTIVE_PLACEMENT_OPTIONS { IPO_ROTATE = 1, IPO_FLIP = 2, IPO_SINGLE_CLICK = 4, IPO_REPEAT = 8 }
 

Protected Member Functions

void doInteractiveItemPlacement (const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
 Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc. More...
 
KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
MODULEmodule () const
 
PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const PCBNEW_SELECTIONselection () const
 
PCBNEW_SELECTIONselection ()
 
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

bool m_editModules
 
TOOL_MENU m_menu
 functions below are not yet implemented - their interface may change More...
 
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 drawSegment (const std::string &aTool, int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint)
 

Starts drawing a selected shape (i.e.

More...
 
bool drawArc (const std::string &aTool, DRAWSEGMENT *&aGraphic, bool aImmediateMode)
 

Starts drawing an arc.

More...
 
bool getSourceZoneForAction (ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
 Draws a polygon, that is added as a zone or a keepout area. More...
 
void runPolygonEventLoop (POLYGON_GEOM_MANAGER &aPolyGeomMgr)
 Run the event loop for polygon creation, sending user input on to the given POLYGON_GEOM_MANAGER for processing into a complete polygon. More...
 
void constrainDimension (DIMENSION *dimension)
 Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees. More...
 
int getSegmentWidth (PCB_LAYER_ID aLayer) const
 

Returns the appropriate width for a segment depending on the settings.

More...
 
PCB_LAYER_ID getDrawingLayer () const
 

Selects a non-copper layer for drawing

More...
 

Private Attributes

KIGFX::VIEWm_view
 
KIGFX::VIEW_CONTROLSm_controls
 
BOARDm_board
 
PCB_BASE_EDIT_FRAMEm_frame
 
MODE m_mode
 
unsigned int m_lineWidth
 Stores the current line width for multisegment drawing. More...
 

Static Private Attributes

static const unsigned int WIDTH_STEP = Millimeter2iu( 0.1 )
 

Friends

class ZONE_CREATE_HELPER
 

Detailed Description

Class DRAWING_TOOL.

Tool responsible for drawing graphical elements like lines, arcs, circles, etc.

Definition at line 49 of file drawing_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Enumerator
IPO_ROTATE 
IPO_FLIP 
IPO_SINGLE_CLICK 
IPO_REPEAT 

Definition at line 109 of file pcb_tool_base.h.

◆ MODE

enum DRAWING_TOOL::MODE
strong

The possible drawing modes of DRAWING_TOOL

Enumerator
NONE 
LINE 
CIRCLE 
ARC 
TEXT 
ANCHOR 
DXF 
DIMENSION 
KEEPOUT 
ZONE 
GRAPHIC_POLYGON 
VIA 

Definition at line 62 of file drawing_tool.h.

63  {
64  NONE,
65  LINE,
66  CIRCLE,
67  ARC,
68  TEXT,
69  ANCHOR,
70  DXF,
71  DIMENSION,
72  KEEPOUT,
73  ZONE,
75  VIA
76  };
Class DIMENSION.

◆ RESET_REASON

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

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

Constructor & Destructor Documentation

◆ DRAWING_TOOL()

DRAWING_TOOL::DRAWING_TOOL ( )

Definition at line 64 of file drawing_tool.cpp.

64  :
65  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
66  m_view( nullptr ), m_controls( nullptr ),
67  m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
68  m_lineWidth( 1 )
69 {
70 }
BOARD * m_board
Definition: drawing_tool.h:225
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:230
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:71

◆ ~DRAWING_TOOL()

DRAWING_TOOL::~DRAWING_TOOL ( )

Definition at line 73 of file drawing_tool.cpp.

74 {
75 }

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

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

Definition at line 51 of file tool_interactive.cpp.

52 {
54 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.

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

Referenced by AUTOPLACE_TOOL::autoplace(), EDIT_TOOL::copyToClipboard(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DrawArc(), DrawCircle(), DrawDimension(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), SetAnchor(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ attachManager()

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 60 of file tool_base.cpp.

61 {
62  m_toolMgr = aManager;
63  m_toolSettings = TOOL_SETTINGS( this );
64 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220
friend class TOOL_SETTINGS
Definition: tool_base.h:154

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

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 151 of file pcb_tool_base.h.

151 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::changeTrackWidthOnClick(), ZONE_FILLER_TOOL::CheckAllZones(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), PCB_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), drawArc(), DrawDimension(), drawSegment(), PAD_TOOL::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ZONE_FILLER_TOOL::FillAllZones(), SELECTION_TOOL::filterSelection(), SELECTION_TOOL::getCollectorsGuide(), PCBNEW_CONTROL::GraphicDisplayMode(), PAD_TOOL::haveFootprints(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PCB_TOOL_BASE::module(), PCBNEW_CONTROL::ModuleEdgeOutlines(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), ROUTER_TOOL::prepareInteractive(), SELECTION_TOOL::RebuildSelection(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), SELECTION_TOOL::Selectable(), SELECTION_TOOL::selectAllItemsConnectedToItem(), SELECTION_TOOL::selectAllItemsConnectedToTrack(), SELECTION_TOOL::selectAllItemsOnNet(), SELECTION_TOOL::selectAllItemsOnSheet(), SELECTION_TOOL::selectPoint(), DRC::testDisabledLayers(), DRC::TestZoneToZoneOutline(), PCBNEW_CONTROL::TrackDisplayMode(), PCBNEW_CONTROL::ViaDisplayMode(), PCBNEW_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ canvas()

◆ constrainDimension()

void DRAWING_TOOL::constrainDimension ( DIMENSION dimension)
private

Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees.

Parameters
aDimensionis the dimension element currently being drawn

Definition at line 449 of file drawing_tool.cpp.

450 {
451  const VECTOR2I lineVector{ dimension->GetEnd() - dimension->GetOrigin() };
452 
453  dimension->SetEnd( wxPoint(
454  VECTOR2I( dimension->GetOrigin() ) + GetVectorSnapped45( lineVector ) ) );
455 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const wxPoint & GetEnd()
Function GetEnd.
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
const wxPoint & GetOrigin() const
Function GetOrigin.
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec)
Snap a vector onto the nearest 0, 45 or 90 degree line.

References DIMENSION::GetEnd(), DIMENSION::GetOrigin(), GetVectorSnapped45(), and DIMENSION::SetEnd().

Referenced by DrawDimension().

◆ controls()

◆ displayOptions()

◆ doInteractiveItemPlacement()

void PCB_TOOL_BASE::doInteractiveItemPlacement ( const std::string &  aTool,
INTERACTIVE_PLACER_BASE aPlacer,
const wxString &  aCommitMessage,
int  aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT 
)
protectedinherited

Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc.

More complex interactive processes are not supported here, you should implement a customised event loop for those.

Parameters
aItemCreatorthe callable that will attempt to create the item
aCommitMessagethe message used on a successful commit

Definition at line 36 of file pcb_tool_base.cpp.

39 {
40  using namespace std::placeholders;
41  std::unique_ptr<BOARD_ITEM> newItem;
42 
43  frame()->PushTool( aTool );
44  Activate();
45 
46  BOARD_COMMIT commit( frame() );
47 
49 
50  // do not capture or auto-pan until we start placing an item
51  controls()->ShowCursor( true );
52  controls()->SetSnapping( true );
53 
54  // Add a VIEW_GROUP that serves as a preview for the new item
55  PCBNEW_SELECTION preview;
56  view()->Add( &preview );
57 
58  aPlacer->m_board = board();
59  aPlacer->m_frame = frame();
60  aPlacer->m_modifiers = 0;
61 
62  auto makeNewItem = [&] ( VECTOR2I aPosition )
63  {
64  if( frame()->GetModel() )
65  newItem = aPlacer->CreateItem();
66 
67  if( newItem )
68  {
69  newItem->SetPosition( (wxPoint) aPosition );
70  preview.Add( newItem.get() );
71 
72  if( newItem->Type() == PCB_MODULE_T )
73  {
74  auto module = dyn_cast<MODULE*>( newItem.get() );
75 
76  // modules have more drawable parts
77  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
78  }
79  }
80  };
81 
82  if( aOptions & IPO_SINGLE_CLICK )
83  makeNewItem( controls()->GetCursorPosition() );
84 
85  // Main loop: keep receiving events
86  while( TOOL_EVENT* evt = Wait() )
87  {
88  VECTOR2I cursorPos = controls()->GetCursorPosition();
89  aPlacer->m_modifiers = evt->Modifier();
90 
91  auto cleanup = [&] ()
92  {
93  newItem = nullptr;
94  preview.Clear();
95  view()->Update( &preview );
96  controls()->SetAutoPan( false );
97  controls()->CaptureCursor( false );
98  controls()->ShowCursor( true );
99  };
100 
101  if( evt->IsCancelInteractive() )
102  {
103  if( aOptions & IPO_SINGLE_CLICK )
104  {
105  cleanup();
106  frame()->PopTool( aTool );
107  break;
108  }
109  else if( newItem )
110  cleanup();
111  else
112  {
113  frame()->PopTool( aTool );
114  break;
115  }
116  }
117  else if( evt->IsActivate() )
118  {
119  if( newItem )
120  cleanup();
121 
122  if( evt->IsPointEditor() )
123  {
124  // don't exit (the point editor runs in the background)
125  }
126  else if( evt->IsMoveTool() )
127  {
128  // leave ourselves on the stack so we come back after the move
129  break;
130  }
131  else
132  {
133  frame()->PopTool( aTool );
134  break;
135  }
136  }
137  else if( evt->IsClick( BUT_LEFT ) )
138  {
139  if( !newItem )
140  {
141  // create the item if possible
142  makeNewItem( cursorPos );
143 
144  // no item created, so wait for another click
145  if( !newItem )
146  continue;
147 
148  controls()->CaptureCursor( true );
149  controls()->SetAutoPan( true );
150  }
151  else
152  {
153  auto oldFlags = newItem->GetFlags();
154  newItem->ClearFlags();
155 
156  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
157  {
158  newItem->SetFlags( oldFlags );
159  continue;
160  }
161 
162  preview.Clear();
163  newItem.release();
164  commit.Push( aCommitMessage );
165 
166  controls()->CaptureCursor( false );
167  controls()->SetAutoPan( false );
168  controls()->ShowCursor( true );
169 
170  if( !( aOptions & IPO_REPEAT ) )
171  break;
172 
173  if( aOptions & IPO_SINGLE_CLICK )
174  makeNewItem( controls()->GetCursorPosition() );
175  }
176  }
177  else if( evt->IsClick( BUT_RIGHT ) )
178  {
180  }
181  else if( newItem && evt->Category() == TC_COMMAND )
182  {
183  /*
184  * Handle any events that can affect the item as we move
185  * it around, eg rotate and flip
186  */
187 
188  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
189  {
190  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
191  newItem->Rotate( newItem->GetPosition(), rotationAngle );
192  view()->Update( &preview );
193  }
194  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
195  {
196  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
197  view()->Update( &preview );
198  }
199  }
200 
201  else if( newItem && evt->IsMotion() )
202  {
203  // track the cursor
204  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
205  aPlacer->SnapItem( newItem.get() );
206 
207  // Show a preview of the item
208  view()->Update( &preview );
209  }
210 
211  else
212  evt->SetPassEvent();
213  }
214 
215  view()->Remove( &preview );
216 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
BOARD * board() const
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
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:109
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
class MODULE, a footprint
Definition: typeinfo.h:89
const PCBNEW_SELECTION & selection() const
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PCB_GENERAL_SETTINGS & Settings()
Class TOOL_EVENT.
Definition: tool_event.h:168
KIGFX::PCB_VIEW * view() const
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
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:115
KIGFX::VIEW_CONTROLS * controls() const
MODULE * module() const
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:58
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References TOOL_INTERACTIVE::Activate(), KIGFX::PCB_VIEW::Add(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_TOOL_BASE::controls(), INTERACTIVE_PLACER_BASE::CreateItem(), PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_EDIT_FRAME::GetModel(), PCB_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, PCB_GENERAL_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, PCB_TOOL_BASE::module(), PCB_MODULE_T, INTERACTIVE_PLACER_BASE::PlaceItem(), EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, KIGFX::PCB_VIEW::Update(), PCB_TOOL_BASE::view(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint(), DrawVia(), and MODULE_EDITOR_TOOLS::PlacePad().

◆ DrawArc()

int DRAWING_TOOL::DrawArc ( const TOOL_EVENT aEvent)

Function DrawArc() Starts interactively drawing an arc.

After invoking the function it expects the user to first click on a point that is going to be used as the center of the arc. The second click determines the origin and radius, the third one - the angle.

Definition at line 218 of file drawing_tool.cpp.

219 {
220  if( m_editModules && !m_frame->GetModel() )
221  return 0;
222 
223  MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
225  BOARD_COMMIT commit( m_frame );
226  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
227  bool immediateMode = aEvent.HasPosition();
228 
229  arc->SetFlags( IS_NEW );
230 
231  std::string tool = aEvent.GetCommandStr().get();
232  m_frame->PushTool( tool );
233  Activate();
234 
235  while( drawArc( tool, arc, immediateMode ) )
236  {
237  if( arc )
238  {
239  if( m_editModules )
240  static_cast<EDGE_MODULE*>( arc )->SetLocalCoord();
241 
242  commit.Add( arc );
243  commit.Push( _( "Draw an arc" ) );
244 
246  }
247 
248  arc = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
249  arc->SetFlags( IS_NEW );
250  immediateMode = false;
251  }
252 
253  return 0;
254 }
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
bool drawArc(const std::string &aTool, DRAWSEGMENT *&aGraphic, bool aImmediateMode)
Starts drawing an arc.
RAII class that sets an value at construction and resets it to the original value at destruction.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
#define _(s)
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
MODULE * module() const
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), ARC, drawArc(), TOOL_EVENT::GetCommandStr(), PCB_BASE_EDIT_FRAME::GetModel(), TOOL_EVENT::HasPosition(), IS_NEW, PCB_TOOL_BASE::m_editModules, m_frame, m_mode, TOOL_BASE::m_toolMgr, PCB_TOOL_BASE::module(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectItem, and EDA_ITEM::SetFlags().

Referenced by setTransitions().

◆ drawArc()

bool DRAWING_TOOL::drawArc ( const std::string &  aTool,
DRAWSEGMENT *&  aGraphic,
bool  aImmediateMode 
)
private

Starts drawing an arc.

Parameters
aGraphicis an object that is going to be used by the tool for drawing. It has to be already created. The tool deletes the object if it is not added to a BOARD.
Returns
False if the tool was cancelled before the origin was set or origin and end are the same point.

Definition at line 1155 of file drawing_tool.cpp.

1156 {
1158 
1159  // Arc geometric construction manager
1161 
1162  // Arc drawing assistant overlay
1163  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1164 
1165  // Add a VIEW_GROUP that serves as a preview for the new item
1166  PCBNEW_SELECTION preview;
1167  m_view->Add( &preview );
1168  m_view->Add( &arcAsst );
1169  GRID_HELPER grid( m_frame );
1170 
1171  m_controls->ShowCursor( true );
1172  m_controls->SetSnapping( true );
1173 
1174  bool firstPoint = false;
1175  bool cancelled = false;
1176 
1177  // Prime the pump
1179 
1180  if( aImmediateMode )
1182 
1183  // Main loop: keep receiving events
1184  while( TOOL_EVENT* evt = Wait() )
1185  {
1186  PCB_LAYER_ID layer = getDrawingLayer();
1187  aGraphic->SetLayer( layer );
1188 
1189  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
1190  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1191  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1192  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1193  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), aGraphic );
1194  m_controls->ForceCursorPosition( true, cursorPos );
1195 
1196  auto cleanup = [&] () {
1197  preview.Clear();
1198  delete aGraphic;
1199  aGraphic = nullptr;
1200  };
1201 
1202  if( evt->IsCancelInteractive() )
1203  {
1204  if( firstPoint )
1205  cleanup();
1206  else
1207  {
1208  m_frame->PopTool( aTool );
1209  cancelled = true;
1210  }
1211 
1212  break;
1213  }
1214  else if( evt->IsActivate() )
1215  {
1216  if( evt->IsPointEditor() )
1217  {
1218  // don't exit (the point editor runs in the background)
1219  }
1220  else if( evt->IsMoveTool() )
1221  {
1222  if( firstPoint )
1223  cleanup();
1224 
1225  // leave ourselves on the stack so we come back after the move
1226  cancelled = true;
1227  break;
1228  }
1229  else
1230  {
1231  if( firstPoint )
1232  cleanup();
1233 
1234  m_frame->PopTool( aTool );
1235  cancelled = true;
1236  break;
1237  }
1238  }
1239  else if( evt->IsClick( BUT_LEFT ) )
1240  {
1241  if( !firstPoint )
1242  {
1244 
1245  m_controls->SetAutoPan( true );
1246  m_controls->CaptureCursor( true );
1247 
1249 
1250  // Init the new item attributes
1251  // (non-geometric, those are handled by the manager)
1252  aGraphic->SetShape( S_ARC );
1253  aGraphic->SetWidth( m_lineWidth );
1254 
1255  preview.Add( aGraphic );
1256  firstPoint = true;
1257  }
1258 
1259  arcManager.AddPoint( cursorPos, true );
1260  }
1261  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1262  {
1263  arcManager.RemoveLastPoint();
1264  }
1265  else if( evt->IsMotion() )
1266  {
1267  // set angle snap
1268  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1269 
1270  // update, but don't step the manager state
1271  arcManager.AddPoint( cursorPos, false );
1272  }
1273  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1274  {
1276  aGraphic->SetLayer( getDrawingLayer() );
1277  aGraphic->SetWidth( m_lineWidth );
1278  m_view->Update( &preview );
1279  frame()->SetMsgPanel( aGraphic );
1280  }
1281  else if( evt->IsClick( BUT_RIGHT ) )
1282  {
1284  }
1285  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1286  {
1288  aGraphic->SetWidth( m_lineWidth );
1289  m_view->Update( &preview );
1290  frame()->SetMsgPanel( aGraphic );
1291  }
1292  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1293  {
1295  aGraphic->SetWidth( m_lineWidth );
1296  m_view->Update( &preview );
1297  frame()->SetMsgPanel( aGraphic );
1298  }
1299  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1300  {
1301  arcManager.ToggleClockwise();
1302  }
1303  else
1304  evt->SetPassEvent();
1305 
1306  if( arcManager.IsComplete() )
1307  {
1308  break;
1309  }
1310  else if( arcManager.HasGeometryChanged() )
1311  {
1312  updateArcFromConstructionMgr( arcManager, *aGraphic );
1313  m_view->Update( &preview );
1314  m_view->Update( &arcAsst );
1315 
1316  if( firstPoint )
1317  frame()->SetMsgPanel( aGraphic );
1318  else
1319  frame()->SetMsgPanel( board() );
1320  }
1321  }
1322 
1323  preview.Remove( aGraphic );
1324  m_view->Remove( &arcAsst );
1325  m_view->Remove( &preview );
1326  frame()->SetMsgPanel( board() );
1327  m_controls->SetAutoPan( false );
1328  m_controls->CaptureCursor( false );
1329  m_controls->ForceCursorPosition( false );
1330 
1331  return !cancelled;
1332 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
void SetShape(STROKE_T aShape)
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:168
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:233
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
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:109
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, DRAWSEGMENT &aArc)
Update an arc DRAWSEGMENT from the current state of an Arc Geometry Manager.
void AddPoint(const VECTOR2I &aPt, bool aLockIn)
Add a point to the construction manager.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
PCB_BASE_EDIT_FRAME * frame() const
PCB_LAYER_ID
A quick note on layer IDs:
const PCBNEW_SELECTION & selection() const
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
Arcs (with rounded ends)
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:230
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
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:1540
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:174
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:276
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
void ToggleClockwise()
Reverse the current are direction
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
Class SELECTION_AREA.
Definition: arc_assistant.h:38
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:164
virtual void PopTool(const std::string &actionName)
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
static TOOL_ACTION refreshPreview
Definition: actions.h:100
static TOOL_ACTION cursorClick
Definition: actions.h:114
void SetWidth(int aWidth)

References KIGFX::VIEW::Add(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::AddPoint(), PCB_ACTIONS::arcPosture, GRID_HELPER::BestSnapAnchor(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, PCB_ACTIONS::deleteLastPoint, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), getDrawingLayer(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSegmentWidth(), EDA_BASE_FRAME::GetUserUnits(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::HasGeometryChanged(), PCB_ACTIONS::incWidth, KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::IsComplete(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, m_view, MD_ALT, MD_CTRL, MD_SHIFT, EDA_BASE_FRAME::PopTool(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint(), TOOL_MANAGER::RunAction(), S_ARC, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SetAngleSnap(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), DRAWSEGMENT::SetShape(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), GRID_HELPER::SetUseGrid(), DRAWSEGMENT::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::ToggleClockwise(), KIGFX::VIEW::Update(), updateArcFromConstructionMgr(), TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by DrawArc().

◆ DrawCircle()

int DRAWING_TOOL::DrawCircle ( const TOOL_EVENT aEvent)

Function DrawCircle() Starts interactively drawing a circle.

After invoking the function it expects the user to first click on a point that is going to be used as the center of the circle. The second click determines the circle radius.

Definition at line 176 of file drawing_tool.cpp.

177 {
178  if( m_editModules && !m_frame->GetModel() )
179  return 0;
180 
181  MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
182  DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
183  BOARD_COMMIT commit( m_frame );
184  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
185  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
186 
187  circle->SetFlags( IS_NEW );
188 
189  if( aEvent.HasPosition() )
190  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
191 
192  std::string tool = aEvent.GetCommandStr().get();
193  m_frame->PushTool( tool );
194  Activate();
195 
196  while( drawSegment( tool, S_CIRCLE, circle, startingPoint ) )
197  {
198  if( circle )
199  {
200  if( m_editModules )
201  static_cast<EDGE_MODULE*>( circle )->SetLocalCoord();
202 
203  commit.Add( circle );
204  commit.Push( _( "Draw a circle" ) );
205 
206  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
207  }
208 
209  circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
210  circle->SetFlags( IS_NEW );
211  startingPoint = NULLOPT;
212  }
213 
214  return 0;
215 }
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
RAII class that sets an value at construction and resets it to the original value at destruction.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
#define _(s)
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:334
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
MODULE * module() const
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
bool drawSegment(const std::string &aTool, int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), CIRCLE, drawSegment(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_EDIT_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, PCB_TOOL_BASE::m_editModules, m_frame, m_mode, TOOL_BASE::m_toolMgr, MD_ALT, TOOL_EVENT::Modifier(), PCB_TOOL_BASE::module(), NULLOPT, BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), TOOL_MANAGER::RunAction(), S_CIRCLE, PCB_ACTIONS::selectItem, and EDA_ITEM::SetFlags().

Referenced by setTransitions().

◆ DrawDimension()

int DRAWING_TOOL::DrawDimension ( const TOOL_EVENT aEvent)

Function DrawDimension() Starts interactively drawing a dimension.

After invoking the function it expects the user to first click on a point that is going to be used as the origin of the dimension. The second click determines the end and the third click modifies its height.

Definition at line 458 of file drawing_tool.cpp.

459 {
460  if( m_editModules && !m_frame->GetModel() )
461  return 0;
462 
463  POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
464  DIMENSION* dimension = NULL;
465  BOARD_COMMIT commit( m_frame );
466  GRID_HELPER grid( m_frame );
467 
468  // Add a VIEW_GROUP that serves as a preview for the new item
469  PCBNEW_SELECTION preview;
470 
471  m_view->Add( &preview );
472 
474  m_controls->ShowCursor( true );
475  m_controls->SetSnapping( true );
476 
477  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
478 
479  std::string tool = aEvent.GetCommandStr().get();
480  m_frame->PushTool( tool );
481  Activate();
482 
483  enum DIMENSION_STEPS
484  {
485  SET_ORIGIN = 0,
486  SET_END,
487  SET_HEIGHT,
488  FINISHED
489  };
490  int step = SET_ORIGIN;
491 
492  // Prime the pump
494 
495  if( aEvent.HasPosition() )
497 
498  // Main loop: keep receiving events
499  while( TOOL_EVENT* evt = Wait() )
500  {
501  if( !pointEditor->HasPoint() )
502  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
503 
504  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
505  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
506  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
507  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), nullptr );
508  m_controls->ForceCursorPosition( true, cursorPos );
509 
510  auto cleanup = [&] () {
511  preview.Clear();
512  delete dimension;
513  dimension = nullptr;
514  step = SET_ORIGIN;
515  };
516 
517  if( evt->IsCancelInteractive() )
518  {
519  m_controls->SetAutoPan( false );
520 
521  if( step != SET_ORIGIN ) // start from the beginning
522  cleanup();
523  else
524  {
525  m_frame->PopTool( tool );
526  break;
527  }
528  }
529  else if( evt->IsActivate() )
530  {
531  if( step != SET_ORIGIN )
532  cleanup();
533 
534  if( evt->IsPointEditor() )
535  {
536  // don't exit (the point editor runs in the background)
537  }
538  else if( evt->IsMoveTool() )
539  {
540  // leave ourselves on the stack so we come back after the move
541  break;
542  }
543  else
544  {
545  m_frame->PopTool( tool );
546  break;
547  }
548  }
549  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
550  {
552  dimension->SetWidth( m_lineWidth );
553  m_view->Update( &preview );
554  frame()->SetMsgPanel( dimension );
555  }
556  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
557  {
558  if( m_lineWidth > WIDTH_STEP )
559  {
561  dimension->SetWidth( m_lineWidth );
562  m_view->Update( &preview );
563  frame()->SetMsgPanel( dimension );
564  }
565  }
566  else if( evt->IsClick( BUT_RIGHT ) )
567  {
569  }
570  else if( evt->IsClick( BUT_LEFT ) )
571  {
572  switch( step )
573  {
574  case SET_ORIGIN:
575  {
577 
578  PCB_LAYER_ID layer = getDrawingLayer();
579  const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
580 
581  if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
582  layer = Dwgs_User;
583 
584  // Init the new item attributes
585  dimension = new DIMENSION( m_board );
586  dimension->SetLayer( layer );
587  dimension->SetOrigin( (wxPoint) cursorPos );
588  dimension->SetEnd( (wxPoint) cursorPos );
589  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
590  dimension->Text().SetThickness( boardSettings.GetTextThickness( layer ) );
591  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
592  dimension->SetWidth( boardSettings.GetLineThickness( layer ) );
593  dimension->SetUnits( m_frame->GetUserUnits(), false );
594  dimension->AdjustDimensionDetails();
595 
596  preview.Add( dimension );
597  frame()->SetMsgPanel( dimension );
598 
599  m_controls->SetAutoPan( true );
600  m_controls->CaptureCursor( true );
601  }
602  break;
603 
604  case SET_END:
605  dimension->SetEnd( (wxPoint) cursorPos );
606 
607  if( !!evt->Modifier( MD_CTRL ) )
608  constrainDimension( dimension );
609 
610  // Dimensions that have origin and end in the same spot are not valid
611  if( dimension->GetOrigin() == dimension->GetEnd() )
612  --step;
613 
614  break;
615 
616  case SET_HEIGHT:
617  {
618  if( (wxPoint) cursorPos != dimension->GetPosition() )
619  {
620  assert( dimension->GetOrigin() != dimension->GetEnd() );
621  assert( dimension->GetWidth() > 0 );
622 
623  preview.Remove( dimension );
624 
625  commit.Add( dimension );
626  commit.Push( _( "Draw a dimension" ) );
627 
628  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
629  }
630  }
631  break;
632  }
633 
634  if( ++step == FINISHED )
635  {
636  step = SET_ORIGIN;
637  m_controls->SetAutoPan( false );
638  m_controls->CaptureCursor( false );
639  }
640  }
641  else if( evt->IsMotion() )
642  {
643  switch( step )
644  {
645  case SET_END:
646  dimension->SetEnd( (wxPoint) cursorPos );
647 
648  if( !!evt->Modifier( MD_CTRL ) )
649  constrainDimension( dimension );
650 
651  break;
652 
653  case SET_HEIGHT:
654  {
655  // Calculating the direction of travel perpendicular to the selected axis
656  double angle = dimension->GetAngle() + ( M_PI / 2 );
657 
658  wxPoint delta( (wxPoint) cursorPos - dimension->m_featureLineDO );
659  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
660  dimension->SetHeight( height );
661  }
662  break;
663  }
664 
665  // Show a preview of the item
666  m_view->Update( &preview );
667  if( step )
668  frame()->SetMsgPanel( dimension );
669  else
670  frame()->SetMsgPanel( board() );
671  }
672  else
673  evt->SetPassEvent();
674  }
675 
676  if( step != SET_ORIGIN )
677  delete dimension;
678 
679  m_controls->SetAutoPan( false );
681 
682  m_view->Remove( &preview );
683  frame()->SetMsgPanel( board() );
684  return 0;
685 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
BOARD * board() const
BOARD * m_board
Definition: drawing_tool.h:225
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:168
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:233
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
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:109
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
PCB_BASE_EDIT_FRAME * frame() const
bool GetTextItalic(PCB_LAYER_ID aLayer) const
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
PCB_LAYER_ID
A quick note on layer IDs:
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:230
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
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:1540
#define _(s)
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
void constrainDimension(DIMENSION *dimension)
Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees.
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
bool HasPoint()
Indicates the cursor is over an edit point.
Definition: point_editor.h:65
Class POINT_EDITOR.
Definition: point_editor.h:43
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
Class DIMENSION.
static TOOL_ACTION refreshPreview
Definition: actions.h:100
static TOOL_ACTION cursorClick
Definition: actions.h:114
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:85

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), PNS::angle(), GRID_HELPER::BestSnapAnchor(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, DIMENSION, Dwgs_User, Edge_Cuts, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetDesignSettings(), getDrawingLayer(), BOARD_DESIGN_SETTINGS::GetLineThickness(), PCB_BASE_EDIT_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), BOARD_DESIGN_SETTINGS::GetTextItalic(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), TOOL_MANAGER::GetTool(), EDA_BASE_FRAME::GetUserUnits(), POINT_EDITOR::HasPoint(), TOOL_EVENT::HasPosition(), PCB_ACTIONS::incWidth, m_board, m_controls, PCB_TOOL_BASE::m_editModules, m_frame, m_lineWidth, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MD_ALT, MD_CTRL, MD_SHIFT, EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), ACTIONS::refreshPreview, SELECTION::Remove(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), EDA_DRAW_FRAME::SetMsgPanel(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), GRID_HELPER::SetUseGrid(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by setTransitions().

◆ DrawLine()

int DRAWING_TOOL::DrawLine ( const TOOL_EVENT aEvent)

Function DrawLine() Starts interactively drawing a line.

After invoking the function it expects the user to click at least two times to determine the origin and the end for a line. If there are more clicks, the line is drawn as a continous polyline.

Definition at line 132 of file drawing_tool.cpp.

133 {
134  if( m_editModules && !m_frame->GetModel() )
135  return 0;
136 
137  MODULE* module = dynamic_cast<MODULE*>( m_frame->GetModel() );
138  DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
139  BOARD_COMMIT commit( m_frame );
140  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
141  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
142 
143  line->SetFlags( IS_NEW );
144 
145  if( aEvent.HasPosition() )
146  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
147 
148  std::string tool = aEvent.GetCommandStr().get();
149  m_frame->PushTool( tool );
150  Activate();
151 
152  while( drawSegment( tool, S_SEGMENT, line, startingPoint ) )
153  {
154  if( line )
155  {
156  if( m_editModules )
157  static_cast<EDGE_MODULE*>( line )->SetLocalCoord();
158 
159  commit.Add( line );
160  commit.Push( _( "Draw a line segment" ) );
161  startingPoint = VECTOR2D( line->GetEnd() );
162  }
163  else
164  {
165  startingPoint = NULLOPT;
166  }
167 
168  line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT;
169  line->SetFlags( IS_NEW );
170  }
171 
172  return 0;
173 }
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
usual segment : line with rounded ends
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
RAII class that sets an value at construction and resets it to the original value at destruction.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
#define _(s)
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:334
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
MODULE * module() const
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
bool drawSegment(const std::string &aTool, int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), drawSegment(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_EDIT_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, LINE, PCB_TOOL_BASE::m_editModules, m_frame, m_mode, MD_ALT, TOOL_EVENT::Modifier(), PCB_TOOL_BASE::module(), NULLOPT, BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), S_SEGMENT, and EDA_ITEM::SetFlags().

Referenced by setTransitions().

◆ drawSegment()

bool DRAWING_TOOL::drawSegment ( const std::string &  aTool,
int  aShape,
DRAWSEGMENT *&  aGraphic,
OPT< VECTOR2D aStartingPoint 
)
private

Starts drawing a selected shape (i.e.

DRAWSEGMENT).

Parameters
aShapeis the type of created shape (
See also
STROKE_T).
Parameters
aGraphicis an object that is going to be used by the tool for drawing. It has to be already created. The tool deletes the object if it is not added to a BOARD.
aStartingPointis a starting point for this new DRAWSEGMENT. If exists the new item has its start point set to aStartingPoint, and its settings (width, layer) set to the current default values.
Returns
False if the tool was cancelled before the origin was set or origin and end are the same point.

Definition at line 889 of file drawing_tool.cpp.

891 {
892  // Only two shapes are currently supported
893  assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
894  GRID_HELPER grid( m_frame );
895  POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
896 
899 
900  // Add a VIEW_GROUP that serves as a preview for the new item
901  PCBNEW_SELECTION preview;
902  m_view->Add( &preview );
903 
904  m_controls->ShowCursor( true );
905 
906  bool direction45 = false; // 45 degrees only mode
907  bool started = false;
908  bool cancelled = false;
909  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
910  VECTOR2I cursorPos = m_controls->GetMousePosition();
911 
912  // Prime the pump
914 
915  if( aStartingPoint )
917 
918  // Main loop: keep receiving events
919  while( TOOL_EVENT* evt = Wait() )
920  {
921  if( !pointEditor->HasPoint() )
922  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
923 
924  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
925  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
926  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
927  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), getDrawingLayer() );
928  m_controls->ForceCursorPosition( true, cursorPos );
929 
930  // 45 degree angle constraint enabled with an option and toggled with Ctrl
931  bool limit45 = frame()->Settings().m_Use45DegreeGraphicSegments;
932 
933  if( evt->Modifier( MD_CTRL ) )
934  limit45 = !limit45;
935 
936  if( direction45 != limit45 && started && aShape == S_SEGMENT )
937  {
938  direction45 = limit45;
939 
940  if( direction45 )
941  {
942  const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
943 
944  // get a restricted 45/H/V line from the last fixed point to the cursor
945  auto newEnd = GetVectorSnapped45( lineVector );
946  aGraphic->SetEnd( aGraphic->GetStart() + (wxPoint) newEnd );
947  m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
948  }
949  else
950  {
951  aGraphic->SetEnd( (wxPoint) cursorPos );
952  }
953 
954  m_view->Update( &preview );
955  frame()->SetMsgPanel( aGraphic );
956  }
957 
958  auto cleanup = [&] () {
959  preview.Clear();
960  m_view->Update( &preview );
961  delete aGraphic;
962  aGraphic = nullptr;
963 
964  if( !isLocalOriginSet )
965  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
966  };
967 
968  if( evt->IsCancelInteractive() )
969  {
970  if( started )
971  cleanup();
972  else
973  {
974  m_frame->PopTool( aTool );
975  cancelled = true;
976  }
977 
978  break;
979  }
980  else if( evt->IsActivate() )
981  {
982  if( evt->IsPointEditor() )
983  {
984  // don't exit (the point editor runs in the background)
985  }
986  else if( evt->IsMoveTool() )
987  {
988  if( started )
989  cleanup();
990 
991  // leave ourselves on the stack so we come back after the move
992  cancelled = true;
993  break;
994  }
995  else
996  {
997  if( started )
998  cleanup();
999 
1000  m_frame->PopTool( aTool );
1001  cancelled = true;
1002  break;
1003  }
1004  }
1005  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1006  {
1008  aGraphic->SetLayer( getDrawingLayer() );
1009  aGraphic->SetWidth( m_lineWidth );
1010  m_view->Update( &preview );
1011  frame()->SetMsgPanel( aGraphic );
1012  }
1013  else if( evt->IsClick( BUT_RIGHT ) )
1014  {
1016  }
1017  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1018  {
1019  if( !started )
1020  {
1022 
1023  if( aStartingPoint )
1024  {
1025  cursorPos = aStartingPoint.get();
1026  aStartingPoint = NULLOPT;
1027  }
1028 
1030 
1031  // Init the new item attributes
1032  aGraphic->SetShape( (STROKE_T) aShape );
1033  aGraphic->SetWidth( m_lineWidth );
1034  aGraphic->SetStart( (wxPoint) cursorPos );
1035  aGraphic->SetEnd( (wxPoint) cursorPos );
1036  aGraphic->SetLayer( getDrawingLayer() );
1037 
1038  if( !isLocalOriginSet )
1039  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1040 
1041  preview.Add( aGraphic );
1042  frame()->SetMsgPanel( aGraphic );
1043  m_controls->SetAutoPan( true );
1044  m_controls->CaptureCursor( true );
1045 
1046  started = true;
1047  }
1048  else
1049  {
1050  auto snapItem = dyn_cast<DRAWSEGMENT*>( grid.GetSnapped() );
1051 
1052  if( aGraphic->GetEnd() == aGraphic->GetStart()
1053  || ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT )
1054  || snapItem )
1055  // User has clicked twice in the same spot
1056  // or clicked on the end of an existing segment (closing a path)
1057  {
1058  BOARD_COMMIT commit( m_frame );
1059 
1060  // If the user clicks on an existing snap point from a drawsegment
1061  // we finish the segment as they are likely closing a path
1062  if( snapItem && aGraphic->GetLength() > 0.0 )
1063  {
1064  commit.Add( aGraphic );
1065  commit.Push( _( "Draw a line segment" ) );
1066  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, aGraphic );
1067  }
1068  else
1069  {
1070  delete aGraphic;
1071  }
1072 
1073  aGraphic = nullptr;
1074  }
1075 
1076  preview.Clear();
1077  break;
1078  }
1079  }
1080  else if( evt->IsMotion() )
1081  {
1082  // 45 degree lines
1083  if( direction45 && aShape == S_SEGMENT )
1084  {
1085  const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
1086 
1087  // get a restricted 45/H/V line from the last fixed point to the cursor
1088  auto newEnd = GetVectorSnapped45( lineVector );
1089  aGraphic->SetEnd( aGraphic->GetStart() + (wxPoint) newEnd );
1090  m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
1091  }
1092  else
1093  aGraphic->SetEnd( (wxPoint) cursorPos );
1094 
1095  m_view->Update( &preview );
1096 
1097  if( started )
1098  frame()->SetMsgPanel( aGraphic );
1099  else
1100  frame()->SetMsgPanel( board() );
1101  }
1102  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1103  {
1105  aGraphic->SetWidth( m_lineWidth );
1106  m_view->Update( &preview );
1107  frame()->SetMsgPanel( aGraphic );
1108  }
1109  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1110  {
1112  aGraphic->SetWidth( m_lineWidth );
1113  m_view->Update( &preview );
1114  frame()->SetMsgPanel( aGraphic );
1115  }
1116  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1117  {
1118  isLocalOriginSet = true;
1119  }
1120  else
1121  evt->SetPassEvent();
1122  }
1123 
1124  if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before
1125  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1126 
1127  m_view->Remove( &preview );
1128  frame()->SetMsgPanel( board() );
1129  m_controls->SetAutoPan( false );
1130  m_controls->CaptureCursor( false );
1131  m_controls->ForceCursorPosition( false );
1132 
1133  return !cancelled;
1134 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
void SetShape(STROKE_T aShape)
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:168
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:233
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
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:109
usual segment : line with rounded ends
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
PCB_BASE_EDIT_FRAME * frame() const
const PCBNEW_SELECTION & selection() const
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PCB_GENERAL_SETTINGS & Settings()
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:230
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
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:1540
#define _(s)
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
void SetStart(const wxPoint &aStart)
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:276
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
bool HasPoint()
Indicates the cursor is over an edit point.
Definition: point_editor.h:65
Class POINT_EDITOR.
Definition: point_editor.h:43
static TOOL_ACTION resetLocalCoords
Definition: actions.h:139
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetEnd(const wxPoint &aEnd)
virtual void PopTool(const std::string &actionName)
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec)
Snap a vector onto the nearest 0, 45 or 90 degree line.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
static TOOL_ACTION refreshPreview
Definition: actions.h:100
static TOOL_ACTION cursorClick
Definition: actions.h:114
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:114
void SetWidth(int aWidth)

References _, SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), GRID_HELPER::BestSnapAnchor(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), getDrawingLayer(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetLength(), KIGFX::VIEW_CONTROLS::GetMousePosition(), PCB_BASE_FRAME::GetScreen(), getSegmentWidth(), GRID_HELPER::GetSnapped(), DRAWSEGMENT::GetStart(), TOOL_MANAGER::GetTool(), GetVectorSnapped45(), POINT_EDITOR::HasPoint(), PCB_ACTIONS::incWidth, PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, BASE_SCREEN::m_LocalOrigin, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, PCB_GENERAL_SETTINGS::m_Use45DegreeGraphicSegments, m_view, MD_ALT, MD_CTRL, MD_SHIFT, NULLOPT, EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), ACTIONS::resetLocalCoords, TOOL_MANAGER::RunAction(), S_CIRCLE, S_SEGMENT, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, PCB_BASE_FRAME::SetActiveLayer(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), DRAWSEGMENT::SetShape(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), DRAWSEGMENT::SetStart(), PCB_BASE_FRAME::Settings(), GRID_HELPER::SetUseGrid(), DRAWSEGMENT::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by DrawCircle(), and DrawLine().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 1562 of file drawing_tool.cpp.

1563 {
1564  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
1565  {
1566  GRID_HELPER m_gridHelper;
1567 
1568  VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame )
1569  {}
1570 
1571  TRACK* findTrack( VIA* aVia )
1572  {
1573  const LSET lset = aVia->GetLayerSet();
1574  wxPoint position = aVia->GetPosition();
1575  BOX2I bbox = aVia->GetBoundingBox();
1576 
1577  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
1578  auto view = m_frame->GetCanvas()->GetView();
1579  std::vector<TRACK*> possible_tracks;
1580 
1581  view->Query( bbox, items );
1582 
1583  for( auto it : items )
1584  {
1585  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
1586 
1587  if( !(item->GetLayerSet() & lset ).any() )
1588  continue;
1589 
1590  if( auto track = dyn_cast<TRACK*>( item ) )
1591  {
1592  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
1593  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
1594  possible_tracks.push_back( track );
1595  }
1596  }
1597 
1598  TRACK* return_track = nullptr;
1599  int min_d = std::numeric_limits<int>::max();
1600  for( auto track : possible_tracks )
1601  {
1602  SEG test( track->GetStart(), track->GetEnd() );
1603  auto dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
1604 
1605  if( dist < min_d )
1606  {
1607  min_d = dist;
1608  return_track = track;
1609  }
1610  }
1611 
1612  return return_track;
1613  }
1614 
1615 
1616  bool hasDRCViolation( VIA* aVia )
1617  {
1618  const LSET lset = aVia->GetLayerSet();
1619  wxPoint position = aVia->GetPosition();
1620  int drillRadius = aVia->GetDrillValue() / 2;
1621  BOX2I bbox = aVia->GetBoundingBox();
1622 
1623  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
1624  int net = 0;
1625  int clearance = 0;
1626  auto view = m_frame->GetCanvas()->GetView();
1627  int holeToHoleMin = m_frame->GetBoard()->GetDesignSettings().m_HoleToHoleMin;
1628 
1629  view->Query( bbox, items );
1630 
1631  for( auto it : items )
1632  {
1633  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
1634 
1635  if( !(item->GetLayerSet() & lset ).any() )
1636  continue;
1637 
1638  if( auto track = dyn_cast<TRACK*>( item ) )
1639  {
1640  int max_clearance = std::max( clearance, track->GetClearance() );
1641 
1642  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
1643  ( track->GetWidth() + aVia->GetWidth() ) / 2 + max_clearance ) )
1644  {
1645  if( net && track->GetNetCode() != net )
1646  return true;
1647 
1648  net = track->GetNetCode();
1649  clearance = track->GetClearance();
1650  }
1651  }
1652 
1653  if( auto via = dyn_cast<VIA*>( item ) )
1654  {
1655  int dist = KiROUND( GetLineLength( position, via->GetPosition() ) );
1656 
1657  if( dist < drillRadius + via->GetDrillValue() / 2 + holeToHoleMin )
1658  return true;
1659  }
1660 
1661  if( auto mod = dyn_cast<MODULE*>( item ) )
1662  {
1663  for( D_PAD* pad : mod->Pads() )
1664  {
1665  int max_clearance = std::max( clearance, pad->GetClearance() );
1666 
1667  if( pad->HitTest( aVia->GetBoundingBox(), false, max_clearance ) )
1668  {
1669  if( net && pad->GetNetCode() != net )
1670  return true;
1671 
1672  net = pad->GetNetCode();
1673  clearance = pad->GetClearance();
1674  }
1675 
1676  if( pad->GetDrillSize().x && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
1677  {
1678  int dist = KiROUND( GetLineLength( position, pad->GetPosition() ) );
1679 
1680  if( dist < drillRadius + pad->GetDrillSize().x / 2 + holeToHoleMin )
1681  return true;
1682  }
1683  }
1684  }
1685  }
1686 
1687  return false;
1688  }
1689 
1690 
1691  int findStitchedZoneNet( VIA* aVia )
1692  {
1693  const wxPoint position = aVia->GetPosition();
1694  const LSET lset = aVia->GetLayerSet();
1695 
1696  for( auto mod : m_board->Modules() )
1697  {
1698  for( D_PAD* pad : mod->Pads() )
1699  {
1700  if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
1701  return -1;
1702  }
1703  }
1704 
1705  std::vector<ZONE_CONTAINER*> foundZones;
1706 
1707  for( ZONE_CONTAINER* zone : m_board->Zones() )
1708  {
1709  if( zone->HitTestFilledArea( position ) )
1710  foundZones.push_back( zone );
1711  }
1712 
1713  std::sort( foundZones.begin(), foundZones.end(),
1714  [] ( const ZONE_CONTAINER* a, const ZONE_CONTAINER* b )
1715  {
1716  return a->GetLayer() < b->GetLayer();
1717  } );
1718 
1719  // first take the net of the active layer
1720  for( ZONE_CONTAINER* z : foundZones )
1721  {
1722  if( m_frame->GetActiveLayer() == z->GetLayer() )
1723  return z->GetNetCode();
1724  }
1725 
1726  // none? take the topmost visible layer
1727  for( ZONE_CONTAINER* z : foundZones )
1728  {
1729  if( m_board->IsLayerVisible( z->GetLayer() ) )
1730  return z->GetNetCode();
1731  }
1732 
1733  return -1;
1734  }
1735 
1736  void SnapItem( BOARD_ITEM *aItem ) override
1737  {
1738  // If you place a Via on a track but not on its centerline, the current
1739  // connectivity algorithm will require us to put a kink in the track when
1740  // we break it (so that each of the two segments ends on the via center).
1741  // That's not ideal, and is in fact probably worse than forcing snap in
1742  // this situation.
1743 
1744  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
1745  auto via = static_cast<VIA*>( aItem );
1746  wxPoint position = via->GetPosition();
1747  TRACK* track = findTrack( via );
1748 
1749  if( track )
1750  {
1751  SEG trackSeg( track->GetStart(), track->GetEnd() );
1752  VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
1753 
1754  aItem->SetPosition( (wxPoint) snap );
1755  }
1756  }
1757 
1758  bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
1759  {
1760  VIA* via = static_cast<VIA*>( aItem );
1761  wxPoint viaPos = via->GetPosition();
1762  int newNet;
1763  TRACK* track = findTrack( via );
1764 
1765  if( hasDRCViolation( via ) )
1766  return false;
1767 
1768  if( track )
1769  {
1770  if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
1771  {
1772  aCommit.Modify( track );
1773  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
1774  track->SetEnd( viaPos );
1775  newTrack->SetStart( viaPos );
1776  aCommit.Add( newTrack );
1777  }
1778 
1779  newNet = track->GetNetCode();
1780  }
1781  else
1782  newNet = findStitchedZoneNet( via );
1783 
1784  if( newNet > 0 )
1785  via->SetNetCode( newNet );
1786 
1787  aCommit.Add( aItem );
1788  return true;
1789  }
1790 
1791  std::unique_ptr<BOARD_ITEM> CreateItem() override
1792  {
1793  auto& ds = m_board->GetDesignSettings();
1794  VIA* via = new VIA( m_board );
1795 
1796  via->SetNetCode( 0 );
1797  via->SetViaType( ds.m_CurrentViaType );
1798 
1799  // for microvias, the size and hole will be changed later.
1800  via->SetWidth( ds.GetCurrentViaSize() );
1801  via->SetDrill( ds.GetCurrentViaDrill() );
1802 
1803  // Usual via is from copper to component.
1804  // layer pair is B_Cu and F_Cu.
1805  via->SetLayerPair( B_Cu, F_Cu );
1806 
1807  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
1808  PCB_LAYER_ID last_layer;
1809 
1810  // prepare switch to new active layer:
1811  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
1812  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
1813  else
1814  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
1815 
1816  // Adjust the actual via layer pair
1817  switch( via->GetViaType() )
1818  {
1819  case VIA_BLIND_BURIED:
1820  via->SetLayerPair( first_layer, last_layer );
1821  break;
1822 
1823  case VIA_MICROVIA: // from external to the near neighbor inner layer
1824  {
1825  PCB_LAYER_ID last_inner_layer =
1826  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
1827 
1828  if( first_layer == B_Cu )
1829  last_layer = last_inner_layer;
1830  else if( first_layer == F_Cu )
1831  last_layer = In1_Cu;
1832  else if( first_layer == last_inner_layer )
1833  last_layer = B_Cu;
1834  else if( first_layer == In1_Cu )
1835  last_layer = F_Cu;
1836 
1837  // else error: will be removed later
1838  via->SetLayerPair( first_layer, last_layer );
1839 
1840  // Update diameter and hole size, which where set previously
1841  // for normal vias
1842  NETINFO_ITEM* net = via->GetNet();
1843 
1844  if( net )
1845  {
1846  via->SetWidth( net->GetMicroViaSize() );
1847  via->SetDrill( net->GetMicroViaDrillSize() );
1848  }
1849  }
1850  break;
1851 
1852  default:
1853  break;
1854  }
1855 
1856  return std::unique_ptr<BOARD_ITEM>( via );
1857  }
1858  };
1859 
1860  VIA_PLACER placer( frame() );
1861 
1862  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
1863 
1864  doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
1866 
1867  return 0;
1868 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:123
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetNetCode() const
Function GetNetCode.
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:202
static const int dist[10][10]
Definition: ar_matrix.cpp:320
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
BOARD * m_board
Definition: drawing_tool.h:225
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:347
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
virtual void SetPosition(const wxPoint &aPos)=0
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:105
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxPoint & GetStart() const
Definition: class_track.h:109
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:178
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_track.cpp:68
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
void SetWidth(int aWidth)
Definition: class_track.h:102
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID
A quick note on layer IDs:
int m_HoleToHoleMin
Min width of peninsula between two drilled holes.
Class LSET is a set of PCB_LAYER_IDs.
RAII class that sets an value at construction and resets it to the original value at destruction.
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
MODULES & Modules()
Definition: class_board.h:236
KIGFX::PCB_VIEW * view() const
VIATYPE_T GetViaType() const
Definition: class_track.h:346
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:46
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer.
#define _(s)
const wxPoint GetPosition() const override
Definition: class_track.h:319
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
void SetSnap(bool aSnap)
Definition: grid_helper.h:66
Definition: seg.h:36
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:459
ZONE_CONTAINERS & Zones()
Definition: class_board.h:250
int GetWidth() const
Definition: class_track.h:103
Common, abstract interface for edit frames.
#define max(a, b)
Definition: auxiliary.h:86
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:354
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const wxPoint & GetEnd() const
Definition: class_track.h:106
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:182
void SetStart(const wxPoint &aStart)
Definition: class_track.h:108
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:452
void doInteractiveItemPlacement(const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
BOARD * GetBoard() const
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:126
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:162
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
#define mod(a, n)
Definition: greymap.cpp:24
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:45
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...

References _, COMMIT::Add(), GRID_HELPER::AlignToSegment(), B_Cu, TRACK::Clone(), dist, PCB_TOOL_BASE::doInteractiveItemPlacement(), EuclideanNorm(), F_Cu, PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_FRAME::GetBoard(), TRACK::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetCopperLayerCount(), BOARD::GetDesignSettings(), VIA::GetDrillValue(), TRACK::GetEnd(), ZONE_CONTAINER::GetLayer(), BOARD_ITEM::GetLayerSet(), VIA::GetLayerSet(), GetLineLength(), NETINFO_ITEM::GetMicroViaDrillSize(), NETINFO_ITEM::GetMicroViaSize(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetCode(), VIA::GetPosition(), PCB_BASE_FRAME::GetScreen(), TRACK::GetStart(), VIA::GetViaType(), PCB_DRAW_PANEL_GAL::GetView(), TRACK::GetWidth(), In1_Cu, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_SINGLE_CLICK, BOARD::IsLayerVisible(), KiROUND(), m_board, m_frame, BOARD_DESIGN_SETTINGS::m_HoleToHoleMin, m_mode, PCB_SCREEN::m_Route_Layer_BOTTOM, PCB_SCREEN::m_Route_Layer_TOP, max, MD_SHIFT, mod, COMMIT::Modify(), BOARD::Modules(), PAD_DRILL_SHAPE_CIRCLE, KIGFX::VIEW::Query(), VIA::SetDrill(), TRACK::SetEnd(), VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), BOARD_ITEM::SetPosition(), GRID_HELPER::SetSnap(), TRACK::SetStart(), VIA::SetViaType(), TRACK::SetWidth(), TestSegmentHit(), ToLAYER_ID(), VIA, VIA_BLIND_BURIED, VIA_MICROVIA, PCB_TOOL_BASE::view(), and BOARD::Zones().

Referenced by setTransitions().

◆ DrawZone()

int DRAWING_TOOL::DrawZone ( const TOOL_EVENT aEvent)

Function DrawZone() Starts interactively drawing a zone.

After invoking the function a zone settings dialog is displayed. After confirmation it allows the user to set points that are going to be used as a boundary polygon of the zone. Double click or clicking on the origin of the boundary polyline finishes the drawing.

The event parameter indicates which type of zone to draw: ADD add a new zone/keepout with fresh settings CUTOUT add a cutout to an existing zone SIMILAR add a new zone with the same settings as an existing one

Definition at line 1369 of file drawing_tool.cpp.

1370 {
1371  if( m_editModules && !m_frame->GetModel() )
1372  return 0;
1373 
1374  ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
1375  MODE drawMode = MODE::ZONE;
1376 
1377  if( aEvent.IsAction( &PCB_ACTIONS::drawZoneKeepout ) )
1378  drawMode = MODE::KEEPOUT;
1379 
1380  if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
1381  drawMode = MODE::GRAPHIC_POLYGON;
1382 
1383  SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
1384 
1385  // get a source zone, if we need one. We need it for:
1386  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1387  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1388  ZONE_CONTAINER* sourceZone = nullptr;
1389 
1390  if( !getSourceZoneForAction( zoneMode, sourceZone ) )
1391  return 0;
1392 
1394 
1395  params.m_keepout = drawMode == MODE::KEEPOUT;
1396  params.m_mode = zoneMode;
1397  params.m_sourceZone = sourceZone;
1398 
1399  if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON )
1400  params.m_layer = getDrawingLayer();
1401  else if( zoneMode == ZONE_MODE::SIMILAR )
1402  params.m_layer = sourceZone->GetLayer();
1403  else
1404  params.m_layer = m_frame->GetActiveLayer();
1405 
1406  ZONE_CREATE_HELPER zoneTool( *this, params );
1407 
1408  // the geometry manager which handles the zone geometry, and
1409  // hands the calculated points over to the zone creator tool
1410  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1411 
1412  std::string tool = aEvent.GetCommandStr().get();
1413  m_frame->PushTool( tool );
1414  Activate(); // register for events
1415 
1416  m_controls->ShowCursor( true );
1417  m_controls->SetSnapping( true );
1418 
1419  bool started = false;
1420  GRID_HELPER grid( m_frame );
1421  STATUS_TEXT_POPUP status( m_frame );
1422  status.SetTextColor( wxColour( 255, 0, 0 ) );
1423  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
1424 
1425  // Prime the pump
1426  if( aEvent.HasPosition() )
1428 
1429  // Main loop: keep receiving events
1430  while( TOOL_EVENT* evt = Wait() )
1431  {
1432  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
1433  LSET layers( m_frame->GetActiveLayer() );
1434  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1435  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1436  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1437  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), layers );
1438  m_controls->ForceCursorPosition( true, cursorPos );
1439 
1440  auto cleanup = [&] () {
1441  polyGeomMgr.Reset();
1442  started = false;
1443  m_controls->SetAutoPan( false );
1444  m_controls->CaptureCursor( false );
1445  };
1446 
1447  if( evt->IsCancelInteractive())
1448  {
1449  if( polyGeomMgr.IsPolygonInProgress() )
1450  cleanup();
1451  else
1452  {
1453  m_frame->PopTool( tool );
1454  break;
1455  }
1456  }
1457  else if( evt->IsActivate() )
1458  {
1459  if( polyGeomMgr.IsPolygonInProgress() )
1460  cleanup();
1461 
1462  if( evt->IsPointEditor() )
1463  {
1464  // don't exit (the point editor runs in the background)
1465  }
1466  else if( evt->IsMoveTool() )
1467  {
1468  // leave ourselves on the stack so we come back after the move
1469  break;
1470  }
1471  else
1472  {
1473  m_frame->PopTool( tool );
1474  break;
1475  }
1476  }
1477  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1478  {
1479  if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON )
1480  params.m_layer = getDrawingLayer();
1481  else if( zoneMode == ZONE_MODE::ADD || zoneMode == ZONE_MODE::CUTOUT )
1482  params.m_layer = frame()->GetActiveLayer();
1483  }
1484  else if( evt->IsClick( BUT_RIGHT ) )
1485  {
1487  }
1488  // events that lock in nodes
1489  else if( evt->IsClick( BUT_LEFT )
1490  || evt->IsDblClick( BUT_LEFT )
1491  || evt->IsAction( &PCB_ACTIONS::closeZoneOutline ) )
1492  {
1493  // Check if it is double click / closing line (so we have to finish the zone)
1494  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
1495  || evt->IsAction( &PCB_ACTIONS::closeZoneOutline )
1496  || polyGeomMgr.NewPointClosesOutline( cursorPos );
1497 
1498  if( endPolygon )
1499  {
1500  polyGeomMgr.SetFinished();
1501  polyGeomMgr.Reset();
1502 
1503  started = false;
1504  m_controls->SetAutoPan( false );
1505  m_controls->CaptureCursor( false );
1506  }
1507 
1508  // adding a corner
1509  else if( polyGeomMgr.AddPoint( cursorPos ) )
1510  {
1511  if( !started )
1512  {
1513  started = true;
1514  m_controls->SetAutoPan( true );
1515  m_controls->CaptureCursor( true );
1516  }
1517  }
1518  }
1519  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1520  {
1521  polyGeomMgr.DeleteLastCorner();
1522 
1523  if( !polyGeomMgr.IsPolygonInProgress() )
1524  {
1525  // report finished as an empty shape
1526  polyGeomMgr.SetFinished();
1527 
1528  // start again
1529  started = false;
1530  m_controls->SetAutoPan( false );
1531  m_controls->CaptureCursor( false );
1532  }
1533  }
1534  else if( polyGeomMgr.IsPolygonInProgress()
1535  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1536  {
1537  polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
1540 
1541  if( polyGeomMgr.IsSelfIntersecting( true ) )
1542  {
1543  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
1544  status.Move( p );
1545  status.PopupFor( 1500 );
1546  }
1547  else
1548  {
1549  status.Hide();
1550  }
1551  }
1552  else
1553  evt->SetPassEvent();
1554 
1555  } // end while
1556 
1557  m_controls->ForceCursorPosition( false );
1558  return 0;
1559 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
Add a new zone with the same settings as an existing one.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
Class STATUS_TEXT_POPUP.
Definition: status_popup.h:79
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static TOOL_ACTION drawZoneKeepout
Definition: pcb_actions.h:157
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:178
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
PCB_LAYER_ID m_layer
Layer to begin drawing
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:150
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
Draws a polygon, that is added as a zone or a keepout area.
Parameters used to fully describe a zone creation process.
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:63
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
Unconstrained point-to-point
Class LSET is a set of PCB_LAYER_IDs.
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
Class TOOL_EVENT.
Definition: tool_event.h:168
Add a new zone/keepout with fresh settings.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
#define _(s)
ZONE_MODE
Definition: pcb_actions.h:47
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
Make a cutout to an existing zone.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
static TOOL_ACTION closeZoneOutline
Definition: pcb_actions.h:165
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:62
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:276
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry ...
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:164
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257
bool m_keepout
Should create a keepout zone?
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
ZONE_MODE m_mode
The zone mode to operate in
static TOOL_ACTION cursorClick
Definition: actions.h:114

References _, TOOL_INTERACTIVE::Activate(), ADD, POLYGON_GEOM_MANAGER::AddPoint(), GRID_HELPER::BestSnapAnchor(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_ACTIONS::closeZoneOutline, ACTIONS::cursorClick, CUTOUT, POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), PCB_ACTIONS::deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawZoneKeepout, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), getDrawingLayer(), ZONE_CONTAINER::GetLayer(), PCB_BASE_EDIT_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSourceZoneForAction(), GRAPHIC_POLYGON, GRAPHIC_POLYGON, TOOL_EVENT::HasPosition(), TOOL_EVENT::IsAction(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), KEEPOUT, PCB_ACTIONS::layerChanged, m_controls, PCB_TOOL_BASE::m_editModules, m_frame, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_layer, TOOL_INTERACTIVE::m_menu, ZONE_CREATE_HELPER::PARAMS::m_mode, m_mode, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, TOOL_BASE::m_toolMgr, MD_ALT, MD_CTRL, MD_SHIFT, STATUS_POPUP::Move(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), TOOL_EVENT::Parameter(), EDA_BASE_FRAME::PopTool(), STATUS_POPUP::PopupFor(), EDA_BASE_FRAME::PushTool(), POLYGON_GEOM_MANAGER::Reset(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), POLYGON_GEOM_MANAGER::SetCursorPosition(), POLYGON_GEOM_MANAGER::SetFinished(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), STATUS_TEXT_POPUP::SetText(), STATUS_TEXT_POPUP::SetTextColor(), GRID_HELPER::SetUseGrid(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), SIMILAR, TOOL_INTERACTIVE::Wait(), and ZONE.

Referenced by setTransitions().

◆ EditingModules()

bool PCB_TOOL_BASE::EditingModules ( ) const
inlineinherited

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 146 of file pcb_tool_base.h.

147  {
148  return getEditFrame<PCB_BASE_EDIT_FRAME>();
149  }

Referenced by POINT_EDITOR::addCorner(), MICROWAVE_TOOL::addMicrowaveFootprint(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), EDIT_TOOL::changeTrackWidthOnClick(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), MODULE_EDITOR_TOOLS::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawVia(), DrawZone(), PAD_TOOL::EnumeratePads(), PCB_EDITOR_CONTROL::ExportSpecctraDSN(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), MODULE_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), PAD_TOOL::Init(), SELECTION_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCBNEW_PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), POINT_EDITOR::updateItem(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ getDrawingLayer()

PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer ( ) const
private

Selects a non-copper layer for drawing

Definition at line 1878 of file drawing_tool.cpp.

1879 {
1880  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1881 
1883  && IsCopperLayer( layer ) )
1884  {
1885  if( layer == F_Cu )
1886  layer = F_SilkS;
1887  else if( layer == B_Cu )
1888  layer = B_SilkS;
1889  else
1890  layer = Dwgs_User;
1891 
1892  m_frame->SetActiveLayer( layer );
1893  }
1894 
1895  return layer;
1896 }
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID
A quick note on layer IDs:
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
MODE GetDrawingMode() const
Function GetDrawingMode.

References B_Cu, B_SilkS, DIMENSION, Dwgs_User, F_Cu, F_SilkS, PCB_BASE_FRAME::GetActiveLayer(), GetDrawingMode(), GRAPHIC_POLYGON, IsCopperLayer(), m_frame, and PCB_BASE_FRAME::SetActiveLayer().

Referenced by ZONE_CREATE_HELPER::commitZone(), drawArc(), DrawDimension(), drawSegment(), and DrawZone().

◆ GetDrawingMode()

DRAWING_TOOL::MODE DRAWING_TOOL::GetDrawingMode ( ) const

Function GetDrawingMode.

Returns the current drawing mode of the DRAWING_TOOL, or MODE::NONE if not currently in any drawing mode

Definition at line 126 of file drawing_tool.cpp.

127 {
128  return m_mode;
129 }

References m_mode.

Referenced by getDrawingLayer(), and PCB_EDITOR_CONTROL::Init().

◆ getEditFrame()

template<typename T >
T* TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Function getEditFrame()

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

Definition at line 187 of file tool_base.h.

188  {
189 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
190  wxASSERT( dynamic_cast<T*>( getEditFrameInt() ) );
191 #endif
192  return static_cast<T*>( getEditFrameInt() );
193  }
EDA_BASE_FRAME * getEditFrameInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getEditFrameInt().

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

◆ GetId()

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

122  {
123  return m_toolId;
124  }
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214

References TOOL_BASE::m_toolId.

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

◆ GetManager()

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

144  {
145  return m_toolMgr;
146  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ACTION_MENU::getToolManager(), LIB_TREE::onContextMenu(), ZONE_CREATE_HELPER::OnFirstPoint(), ACTION_MENU::OnMenuEvent(), and ZONE_CREATE_HELPER::performZoneCutout().

◆ getModel()

template<typename T >
T* TOOL_BASE::getModel ( ) const
inlineprotectedinherited

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 201 of file tool_base.h.

202  {
203  EDA_ITEM* m = getModelInt();
204 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
205  wxASSERT( dynamic_cast<T*>( m ) );
206 #endif
207  return static_cast<T*>( m );
208  }
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:54
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163

References TOOL_BASE::getModelInt().

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

◆ GetName()

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

133  {
134  return m_toolName;
135  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:218

References TOOL_BASE::m_toolName.

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

◆ getSegmentWidth()

int DRAWING_TOOL::getSegmentWidth ( PCB_LAYER_ID  aLayer) const
private

Returns the appropriate width for a segment depending on the settings.

Definition at line 1871 of file drawing_tool.cpp.

1872 {
1873  assert( m_board );
1874  return m_board->GetDesignSettings().GetLineThickness( aLayer );
1875 }
BOARD * m_board
Definition: drawing_tool.h:225
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...

References BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetLineThickness(), and m_board.

Referenced by drawArc(), and drawSegment().

◆ GetSettings()

TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 78 of file tool_base.cpp.

79 {
80  return m_toolSettings;
81 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220

References TOOL_BASE::m_toolSettings.

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

◆ getSourceZoneForAction()

bool DRAWING_TOOL::getSourceZoneForAction ( ZONE_MODE  aMode,
ZONE_CONTAINER *&  aZone 
)
private

Draws a polygon, that is added as a zone or a keepout area.

Parameters
aKeepoutdictates if the drawn polygon is a zone or a keepout area.
aModedictates the mode of the zone tool: ADD add a new zone/keepout with fresh settings CUTOUT add a cutout to an existing zone SIMILAR add a new zone with the same settings as an existing oneFunction getSourceZoneForAction()

Gets a source zone item for an action that takes an existing zone into account (for example a cutout of an existing zone). The source zone is taken from the current selection

Parameters
aModemode of the zone tool
aZoneupdated pointer to a suitable source zone, or nullptr if none found, or the action doesn't need a source
Returns
true if a suitable zone was found, or the action doesn't need a zone. False if the action needs a zone but none was found.

Definition at line 1335 of file drawing_tool.cpp.

1336 {
1337  bool clearSelection = false;
1338  aZone = nullptr;
1339 
1340  // not an action that needs a source zone
1341  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1342  return true;
1343 
1345  const PCBNEW_SELECTION& selection = selTool->GetSelection();
1346 
1347  if( selection.Empty() )
1348  {
1349  clearSelection = true;
1351  }
1352 
1353  // we want a single zone
1354  if( selection.Size() == 1 )
1355  aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
1356 
1357  // expected a zone, but didn't get one
1358  if( !aZone )
1359  {
1360  if( clearSelection )
1362 
1363  return false;
1364  }
1365 
1366  return true;
1367 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
const PCBNEW_SELECTION & selection() const
Add a new zone/keepout with fresh settings.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:70

References ADD, SELECTION::Empty(), SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), GRAPHIC_POLYGON, TOOL_BASE::m_toolMgr, TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionCursor, and SELECTION::Size().

Referenced by DrawZone().

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 110 of file tool_base.h.

111  {
112  return m_type;
113  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:211

References TOOL_BASE::m_type.

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

◆ getView()

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 36 of file tool_base.cpp.

37 {
38  return m_toolMgr->GetView();
39 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:241
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219

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

Referenced by EE_POINT_EDITOR::addCornerCondition(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), COMMON_TOOLS::CenterContents(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), COMMON_TOOLS::CursorControl(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_EDIT_TOOL::DoDelete(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), MICROWAVE_TOOL::drawMicrowaveInductor(), PL_DRAWING_TOOLS::DrawShape(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), COMMON_TOOLS::GridPreset(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), SELECTION_TOOL::GuessSelectionCandidates(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCB_INSPECTION_TOOL::highlightNet(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), PL_EDIT_TOOL::moveItem(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), Reset(), EE_SELECTION_TOOL::Reset(), SELECTION_TOOL::Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), SELECTION_TOOL::Selectable(), GERBVIEW_SELECTION_TOOL::selectable(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), EE_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), PL_EDITOR_CONTROL::ToggleBackgroundColor(), COMMON_TOOLS::ToggleGrid(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), PL_SELECTION_TOOL::unhighlight(), EE_SELECTION_TOOL::unhighlight(), SELECTION_TOOL::unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PCBNEW_CONTROL::updateGrid(), EE_POINT_EDITOR::updateItem(), PL_POINT_EDITOR::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateView(), PCB_TOOL_BASE::view(), COMMON_TOOLS::ZoomFitScreen(), SELECTION_TOOL::zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and SELECTION_TOOL::~SELECTION_TOOL().

◆ getViewControls()

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 42 of file tool_base.cpp.

43 {
44  return m_toolMgr->GetViewControls();
45 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:246

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), DrawCircle(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), COMMON_TOOLS::GridPreset(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LIB_DRAWING_TOOLS::PlaceAnchor(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), POINT_EDITOR::Reset(), Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), SELECTION_TOOL::selectCursor(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PICKER_TOOL::setControls(), PCBNEW_PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), LIB_MOVE_TOOL::updateModificationPoint(), PL_EDIT_TOOL::updateModificationPoint(), EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

◆ Go()

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 129 of file tool_interactive.h.

131 {
132  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
133 
134  goInternal( sptr, aConditions );
135 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by LENGTH_TUNER_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_CONTROL::setTransitions(), LIB_PIN_TOOL::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), COMMON_CONTROL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), SCH_MOVE_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), POINT_EDITOR::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), LIB_CONTROL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), MODULE_EDITOR_TOOLS::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), setTransitions(), EDIT_TOOL::setTransitions(), SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), EE_SELECTION_TOOL::setTransitions(), and DRC::setTransitions().

◆ Init()

bool DRAWING_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 PCB_TOOL_BASE.

Definition at line 78 of file drawing_tool.cpp.

79 {
80  auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
81  return m_mode != MODE::NONE;
82  };
83 
84  // some interactive drawing tools can undo the last point
85  auto canUndoPoint = [ this ] ( const SELECTION& aSel ) {
86  return m_mode == MODE::ARC || m_mode == MODE::ZONE;
87  };
88 
89  // functor for zone-only actions
90  auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) {
91  return m_mode == MODE::ZONE;
92  };
93 
94  auto& ctxMenu = m_menu.GetMenu();
95 
96  // cancel current tool goes in main context menu at the top if present
97  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
98  ctxMenu.AddSeparator( 1 );
99 
100  // tool-specific actions
101  ctxMenu.AddItem( PCB_ACTIONS::closeZoneOutline, zoneActiveFunctor, 200 );
102  ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
103 
104  ctxMenu.AddSeparator( 500 );
105 
106  // Type-specific sub-menus will be added for us by other tools
107  // For example, zone fill/unfill is provided by the PCB control tool
108 
109  // Finally, add the standard zoom/grid items
110  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
111 
112  return true;
113 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
static TOOL_ACTION closeZoneOutline
Definition: pcb_actions.h:165
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:164
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()

References CONDITIONAL_MENU::AddItem(), ARC, ACTIONS::cancelInteractive, PCB_ACTIONS::closeZoneOutline, PCB_ACTIONS::deleteLastPoint, TOOL_MENU::GetMenu(), TOOL_INTERACTIVE::m_menu, m_mode, NONE, and ZONE.

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

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

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

◆ module()

◆ PlaceImportedGraphics()

int DRAWING_TOOL::PlaceImportedGraphics ( const TOOL_EVENT aEvent)

Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor.

Definition at line 688 of file drawing_tool.cpp.

689 {
690  if( !m_frame->GetModel() )
691  return 0;
692 
693  // Note: PlaceImportedGraphics() will convert PCB_LINE_T and PCB_TEXT_T to module graphic
694  // items if needed
696  int dlgResult = dlg.ShowModal();
697 
698  auto& list = dlg.GetImportedItems();
699 
700  if( dlgResult != wxID_OK )
701  return 0;
702 
703  // Ensure the list is not empty:
704  if( list.empty() )
705  {
706  wxMessageBox( _( "No graphic items found in file to import") );
707  return 0;
708  }
709 
711 
712  // Add a VIEW_GROUP that serves as a preview for the new item
713  PCBNEW_SELECTION preview;
714  BOARD_COMMIT commit( m_frame );
715 
716  // Build the undo list & add items to the current view
717  for( auto& ptr : list)
718  {
719  EDA_ITEM* item = ptr.get();
720 
721  if( m_editModules )
722  wxASSERT( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_MODULE_TEXT_T );
723  else
724  wxASSERT( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
725 
726  if( dlg.IsPlacementInteractive() )
727  preview.Add( item );
728  else
729  commit.Add( item );
730 
731  ptr.release();
732  }
733 
734  if( !dlg.IsPlacementInteractive() )
735  {
736  commit.Push( _( "Place a DXF_SVG drawing" ) );
737  return 0;
738  }
739 
740  BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
741  m_view->Add( &preview );
742 
744  m_controls->ShowCursor( true );
745  m_controls->SetSnapping( true );
747 
748  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
749 
750  // Now move the new items to the current cursor position:
751  VECTOR2I cursorPos = m_controls->GetCursorPosition();
752  VECTOR2I delta = cursorPos - firstItem->GetPosition();
753 
754  for( EDA_ITEM* item : preview )
755  static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
756 
757  m_view->Update( &preview );
758 
759  std::string tool = aEvent.GetCommandStr().get();
760  m_frame->PushTool( tool );
761  Activate();
762 
763  // Main loop: keep receiving events
764  while( TOOL_EVENT* evt = Wait() )
765  {
766  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
767  cursorPos = m_controls->GetCursorPosition();
768 
769  if( evt->IsCancelInteractive() || evt->IsActivate() )
770  {
771  preview.FreeItems();
772 
773  m_frame->PopTool( tool );
774  break;
775  }
776  else if( evt->IsMotion() )
777  {
778  delta = cursorPos - firstItem->GetPosition();
779 
780  for( auto item : preview )
781  static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
782 
783  m_view->Update( &preview );
784  }
785  else if( evt->Category() == TC_COMMAND )
786  {
787  // TODO it should be handled by EDIT_TOOL, so add items and select?
788  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
789  {
790  const auto rotationPoint = (wxPoint) cursorPos;
791  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *m_frame, *evt );
792 
793  for( auto item : preview )
794  static_cast<BOARD_ITEM*>( item )->Rotate( rotationPoint, rotationAngle );
795 
796  m_view->Update( &preview );
797  }
798  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
799  {
800  bool leftRight = m_frame->Settings().m_FlipLeftRight;
801 
802  for( auto item : preview )
803  static_cast<BOARD_ITEM*>( item )->Flip( (wxPoint) cursorPos, leftRight);
804 
805  m_view->Update( &preview );
806  }
807  }
808  else if( evt->IsClick( BUT_RIGHT ) )
809  {
811  }
812  else if( evt->IsClick( BUT_LEFT ) )
813  {
814  // Place the imported drawings
815  for( auto item : preview )
816  commit.Add( item );
817 
818  commit.Push( _( "Place a DXF_SVG drawing" ) );
819  break;
820  }
821  else
822  evt->SetPassEvent();
823  }
824 
825  preview.Clear();
826  m_view->Remove( &preview );
827  return 0;
828 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
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:109
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
PCB_GENERAL_SETTINGS & Settings()
Class TOOL_EVENT.
Definition: tool_event.h:168
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
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:1540
#define _(s)
virtual const wxPoint GetPosition() const =0
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:115
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:182
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), BUT_LEFT, BUT_RIGHT, ACTIONS::cancelInteractive, DXF, PCB_ACTIONS::flip, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), SELECTION::Front(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), DIALOG_IMPORT_GFX::GetImportedItems(), PCB_BASE_EDIT_FRAME::GetModel(), BOARD_ITEM::GetPosition(), DIALOG_IMPORT_GFX::IsPlacementInteractive(), TOOL_EVT_UTILS::IsRotateToolEvt(), m_controls, PCB_TOOL_BASE::m_editModules, PCB_GENERAL_SETTINGS::m_FlipLeftRight, m_frame, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PCB_TEXT_T, EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, EDA_DRAW_PANEL_GAL::SetCurrentCursor(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_COMMAND, EDA_ITEM::Type(), KIGFX::VIEW::Update(), and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

◆ PlaceText()

int DRAWING_TOOL::PlaceText ( const TOOL_EVENT aEvent)

Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets the user decide where to place the text in editor.

Definition at line 257 of file drawing_tool.cpp.

258 {
259  if( m_editModules && !m_frame->GetModel() )
260  return 0;
261 
262  BOARD_ITEM* text = NULL;
263  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
264  BOARD_COMMIT commit( m_frame );
265 
267  m_controls->ShowCursor( true );
268  m_controls->SetSnapping( true );
269  // do not capture or auto-pan until we start placing some text
270 
271  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
272 
273  std::string tool = aEvent.GetCommandStr().get();
274  m_frame->PushTool( tool );
275  Activate();
276 
277  bool reselect = false;
278 
279  // Prime the pump
280  if( aEvent.HasPosition() )
282 
283  // Main loop: keep receiving events
284  while( TOOL_EVENT* evt = Wait() )
285  {
286  m_frame->GetCanvas()->SetCurrentCursor( text ? wxCURSOR_ARROW : wxCURSOR_PENCIL );
287  VECTOR2I cursorPos = m_controls->GetCursorPosition();
288 
289  if( reselect && text )
291 
292  auto cleanup = [&] () {
295  m_controls->ShowCursor( true );
296  m_controls->SetAutoPan( false );
297  m_controls->CaptureCursor( false );
298  delete text;
299  text = NULL;
300  };
301 
302  if( evt->IsCancelInteractive() )
303  {
304  if( text )
305  cleanup();
306  else
307  {
308  m_frame->PopTool( tool );
309  break;
310  }
311  }
312  else if( evt->IsActivate() )
313  {
314  if( text )
315  cleanup();
316 
317  if( evt->IsMoveTool() )
318  {
319  // leave ourselves on the stack so we come back after the move
320  break;
321  }
322  else
323  {
324  m_frame->PopTool( tool );
325  break;
326  }
327  }
328  else if( evt->IsClick( BUT_RIGHT ) )
329  {
331  }
332  else if( evt->IsClick( BUT_LEFT ) )
333  {
334  bool placing = text != nullptr;
335 
336  if( !text )
337  {
340 
341  // Init the new item attributes
342  if( m_editModules )
343  {
344  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() );
345 
346  textMod->SetLayer( layer );
347  textMod->SetTextSize( dsnSettings.GetTextSize( layer ) );
348  textMod->SetThickness( dsnSettings.GetTextThickness( layer ) );
349  textMod->SetItalic( dsnSettings.GetTextItalic( layer ) );
350  textMod->SetKeepUpright( dsnSettings.GetTextUpright( layer ) );
351  textMod->SetTextPos( (wxPoint) cursorPos );
352 
353  text = textMod;
354 
355  DIALOG_TEXT_PROPERTIES textDialog( m_frame, textMod );
356  bool cancelled;
357 
358  RunMainStack([&]() {
359  cancelled = !textDialog.ShowModal() || textMod->GetText().IsEmpty();
360  } );
361 
362  if( cancelled )
363  {
364  delete text;
365  text = nullptr;
366  }
367  else if( textMod->GetTextPos() != (wxPoint) cursorPos )
368  {
369  // If the user modified the location then go ahead and place it there.
370  // Otherwise we'll drag.
371  placing = true;
372  }
373  }
374  else
375  {
376  TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() );
377  // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
378  textPcb->SetFlags( IS_NEW );
379 
380  textPcb->SetLayer( layer );
381 
382  // Set the mirrored option for layers on the BACK side of the board
383  if( IsBackLayer( layer ) )
384  textPcb->SetMirrored( true );
385 
386  textPcb->SetTextSize( dsnSettings.GetTextSize( layer ) );
387  textPcb->SetThickness( dsnSettings.GetTextThickness( layer ) );
388  textPcb->SetItalic( dsnSettings.GetTextItalic( layer ) );
389  textPcb->SetTextPos( (wxPoint) cursorPos );
390 
391  RunMainStack([&]() {
392  m_frame->InstallTextOptionsFrame( textPcb );
393  } );
394 
395  if( textPcb->GetText().IsEmpty() )
396  delete textPcb;
397  else
398  text = textPcb;
399  }
400 
401  if( text )
402  {
403  m_controls->WarpCursor( text->GetPosition(), true );
405  }
406  }
407 
408  if( placing )
409  {
410  text->ClearFlags();
412 
413  commit.Add( text );
414  commit.Push( _( "Place a text" ) );
415 
417 
418  text = nullptr;
419  }
420 
422  m_controls->ShowCursor( true );
423  m_controls->CaptureCursor( text != nullptr );
424  m_controls->SetAutoPan( text != nullptr );
425  }
426  else if( text && evt->IsMotion() )
427  {
428  text->SetPosition( (wxPoint) cursorPos );
429  selection().SetReferencePoint( cursorPos );
430  m_view->Update( &selection() );
431  frame()->SetMsgPanel( text );
432  }
433 
434  else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
435  {
436  // Calling 'Properties' action clears the selection, so we need to restore it
437  reselect = true;
438  }
439 
440  else
441  evt->SetPassEvent();
442  }
443 
444  frame()->SetMsgPanel( board() );
445  return 0;
446 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
void SetKeepUpright(bool aKeepUpright)
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
BOARD * board() const
virtual void SetPosition(const wxPoint &aPos)=0
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetItalic(bool isItalic)
Definition: eda_text.h:163
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:229
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
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:109
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:220
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void InstallTextOptionsFrame(BOARD_ITEM *aText)
Routine for main window class to launch text properties dialog.
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
bool GetTextUpright(PCB_LAYER_ID aLayer) const
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
PCB_BASE_EDIT_FRAME * frame() const
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:243
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
PCB_LAYER_ID
A quick note on layer IDs:
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
Class TOOL_EVENT.
Definition: tool_event.h:168
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
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:1540
#define _(s)
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
virtual const wxPoint GetPosition() const =0
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
virtual void PopTool(const std::string &actionName)
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:266
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
const wxPoint & GetTextPos() const
Definition: eda_text.h:230
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:257
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
static TOOL_ACTION cursorClick
Definition: actions.h:114
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), EDA_ITEM::ClearFlags(), ACTIONS::cursorClick, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetDesignSettings(), PCB_BASE_EDIT_FRAME::GetModel(), BOARD_ITEM::GetPosition(), EDA_TEXT::GetText(), BOARD_DESIGN_SETTINGS::GetTextItalic(), EDA_TEXT::GetTextPos(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), BOARD_DESIGN_SETTINGS::GetTextUpright(), TOOL_EVENT::HasPosition(), PCB_BASE_EDIT_FRAME::InstallTextOptionsFrame(), IS_NEW, IsBackLayer(), m_controls, PCB_TOOL_BASE::m_editModules, m_frame, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, EDA_BASE_FRAME::PopTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), TOOL_MANAGER::RunAction(), TOOL_INTERACTIVE::RunMainStack(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), EDA_ITEM::SetFlags(), EDA_TEXT::SetItalic(), TEXTE_MODULE::SetKeepUpright(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), EDA_DRAW_FRAME::SetMsgPanel(), BOARD_ITEM::SetPosition(), SELECTION::SetReferencePoint(), KIGFX::VIEW_CONTROLS::SetSnapping(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), TEXT, KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), and KIGFX::VIEW_CONTROLS::WarpCursor().

Referenced by setTransitions().

◆ Reset()

void DRAWING_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.

Reimplemented from PCB_TOOL_BASE.

Definition at line 116 of file drawing_tool.cpp.

117 {
118  // Init variables used by every drawing tool
119  m_view = getView();
121  m_board = getModel<BOARD>();
122  m_frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
123 }
BOARD * m_board
Definition: drawing_tool.h:225
KIGFX::VIEW * m_view
Definition: drawing_tool.h:223
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42

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

◆ RunMainStack()

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 87 of file tool_interactive.cpp.

88 {
89  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
90 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)

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

Referenced by PlaceText().

◆ runPolygonEventLoop()

void DRAWING_TOOL::runPolygonEventLoop ( POLYGON_GEOM_MANAGER aPolyGeomMgr)
private

Run the event loop for polygon creation, sending user input on to the given POLYGON_GEOM_MANAGER for processing into a complete polygon.

◆ selection() [1/2]

const PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 257 of file pcb_tool_base.cpp.

258 {
259  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
260  const auto& selection = selTool->GetSelection();
261  return selection;
262 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const PCBNEW_SELECTION & selection() const

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::changeTrackWidthOnClick(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), PCB_TOOL_BASE::doInteractiveItemPlacement(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawZone(), EDIT_TOOL::Duplicate(), EDIT_TOOL::EditFpInFpEditor(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::filterSelection(), EDIT_TOOL::Flip(), getSourceZoneForAction(), PCB_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), PCBNEW_CONTROL::placeBoardItems(), PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EDIT_TOOL::Rotate(), SELECTION_TOOL::selectCopper(), PCB_TOOL_BASE::selection(), SELECTION_TOOL::selectNet(), SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

◆ selection() [2/2]

PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( )
protectedinherited

Definition at line 265 of file pcb_tool_base.cpp.

266 {
267  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
268  auto& selection = selTool->GetSelection();
269  return selection;
270 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const PCBNEW_SELECTION & selection() const

References TOOL_MANAGER::GetTool(), TOOL_BASE::m_toolMgr, and PCB_TOOL_BASE::selection().

◆ SetAnchor()

int DRAWING_TOOL::SetAnchor ( const TOOL_EVENT aEvent)

Function SetAnchor() Places the footprint anchor (only in module editor).

Definition at line 831 of file drawing_tool.cpp.

832 {
833  assert( m_editModules );
834 
835  if( !m_frame->GetModel() )
836  return 0;
837 
838  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
839 
840  std::string tool = aEvent.GetCommandStr().get();
841  m_frame->PushTool( tool );
842  Activate();
843 
845  m_controls->ShowCursor( true );
846  m_controls->SetSnapping( true );
847  m_controls->SetAutoPan( true );
848  m_controls->CaptureCursor( false );
849 
850  while( TOOL_EVENT* evt = Wait() )
851  {
852  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
853 
854  if( evt->IsClick( BUT_LEFT ) )
855  {
857  BOARD_COMMIT commit( m_frame );
858  commit.Modify( module );
859 
860  // set the new relative internal local coordinates of footprint items
861  VECTOR2I cursorPos = m_controls->GetCursorPosition();
862  wxPoint moveVector = module->GetPosition() - (wxPoint) cursorPos;
863  module->MoveAnchorPosition( moveVector );
864 
865  commit.Push( _( "Move the footprint reference anchor" ) );
866 
867  // Usually, we do not need to change twice the anchor position,
868  // so deselect the active tool
869  m_frame->PopTool( tool );
870  break;
871  }
872  else if( evt->IsClick( BUT_RIGHT ) )
873  {
875  }
876  else if( evt->IsCancelInteractive() || evt->IsActivate() )
877  {
878  m_frame->PopTool( tool );
879  break;
880  }
881  else
882  evt->SetPassEvent();
883  }
884 
885  return 0;
886 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
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:109
void MoveAnchorPosition(const wxPoint &aMoveVector)
Function MoveAnchorPosition Move the reference point of the footprint It looks like a move footprint:...
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
Class TOOL_EVENT.
Definition: tool_event.h:168
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:224
#define _(s)
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:226
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
MODULE * module() const
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
const wxPoint GetPosition() const override
Definition: class_module.h:188
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), ANCHOR, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_EDIT_FRAME::GetModel(), MODULE::GetPosition(), m_controls, PCB_TOOL_BASE::m_editModules, m_frame, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, COMMIT::Modify(), PCB_TOOL_BASE::module(), MODULE::MoveAnchorPosition(), EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), KIGFX::VIEW_CONTROLS::SetSnapping(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

◆ SetContextMenu()

void TOOL_INTERACTIVE::SetContextMenu ( ACTION_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 76 of file tool_interactive.cpp.

77 {
78  if( aMenu )
79  aMenu->SetTool( this );
80  else
81  aTrigger = CMENU_OFF;
82 
83  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
84 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void ScheduleContextMenu(TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool's context popup menu.

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ SetEditModules()

void PCB_TOOL_BASE::SetEditModules ( bool  aEnabled)
inlineinherited

Function SetEditModules()

Toggles edit module mode. When enabled, one may select parts of modules individually (graphics, pads, etc.), so they can be modified.

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 97 of file pcb_tool_base.h.

98  {
99  m_editModules = aEnabled;
100  }

References PCB_TOOL_BASE::m_editModules.

◆ setTransitions()

void DRAWING_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from PCB_TOOL_BASE.

Definition at line 1902 of file drawing_tool.cpp.

1903 {
1917 }
static TOOL_ACTION drawLine
Definition: pcb_actions.h:149
int DrawCircle(const TOOL_EVENT &aEvent)
Function DrawCircle() Starts interactively drawing a circle.
static TOOL_ACTION placeImportedGraphics
Definition: pcb_actions.h:162
int DrawVia(const TOOL_EVENT &aEvent)
int DrawZone(const TOOL_EVENT &aEvent)
Function DrawZone() Starts interactively drawing a zone.
static TOOL_ACTION drawSimilarZone
Definition: pcb_actions.h:159
static TOOL_ACTION drawArc
Definition: pcb_actions.h:152
int DrawLine(const TOOL_EVENT &aEvent)
Function DrawLine() Starts interactively drawing a line.
static TOOL_ACTION drawZoneKeepout
Definition: pcb_actions.h:157
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:150
static TOOL_ACTION setAnchor
Definition: pcb_actions.h:163
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION placeText
Definition: pcb_actions.h:153
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor.
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets t...
static TOOL_ACTION drawDimension
Definition: pcb_actions.h:154
static TOOL_ACTION drawVia
Definition: pcb_actions.h:156
static TOOL_ACTION drawZoneCutout
Definition: pcb_actions.h:158
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:151
int SetAnchor(const TOOL_EVENT &aEvent)
Function SetAnchor() Places the footprint anchor (only in module editor).
int DrawArc(const TOOL_EVENT &aEvent)
Function DrawArc() Starts interactively drawing an arc.
static TOOL_ACTION drawZone
Definition: pcb_actions.h:155
int DrawDimension(const TOOL_EVENT &aEvent)
Function DrawDimension() Starts interactively drawing a dimension.

References DrawArc(), PCB_ACTIONS::drawArc, DrawCircle(), PCB_ACTIONS::drawCircle, DrawDimension(), PCB_ACTIONS::drawDimension, DrawLine(), PCB_ACTIONS::drawLine, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawSimilarZone, DrawVia(), PCB_ACTIONS::drawVia, DrawZone(), PCB_ACTIONS::drawZone, PCB_ACTIONS::drawZoneCutout, PCB_ACTIONS::drawZoneKeepout, TOOL_INTERACTIVE::Go(), PlaceImportedGraphics(), PCB_ACTIONS::placeImportedGraphics, PlaceText(), PCB_ACTIONS::placeText, SetAnchor(), and PCB_ACTIONS::setAnchor.

◆ view()

◆ Wait()

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 57 of file tool_interactive.cpp.

58 {
59  return m_toolMgr->ScheduleWait( this, aEventList );
60 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
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.

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), PL_EDIT_TOOL::Main(), CVPCB_CONTROL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), EDIT_TOOL::Remove(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), GERBVIEW_SELECTION_TOOL::selectPoint(), SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

Friends And Related Function Documentation

◆ ZONE_CREATE_HELPER

friend class ZONE_CREATE_HELPER
friend

Definition at line 237 of file drawing_tool.h.

Member Data Documentation

◆ m_board

BOARD* DRAWING_TOOL::m_board
private

Definition at line 225 of file drawing_tool.h.

Referenced by DrawDimension(), DrawVia(), getSegmentWidth(), and Reset().

◆ m_controls

KIGFX::VIEW_CONTROLS* DRAWING_TOOL::m_controls
private

◆ m_editModules

◆ m_frame

◆ m_lineWidth

unsigned int DRAWING_TOOL::m_lineWidth
private

Stores the current line width for multisegment drawing.

Definition at line 230 of file drawing_tool.h.

Referenced by drawArc(), DrawDimension(), and drawSegment().

◆ m_menu

TOOL_MENU TOOL_INTERACTIVE::m_menu
protectedinherited

functions below are not yet implemented - their interface may change

Definition at line 108 of file tool_interactive.h.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DrawZone(), PAD_TOOL::EnumeratePads(), TOOL_INTERACTIVE::GetToolMenu(), PICKER_TOOL::Init(), SCH_EDIT_TOOL::Init(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init(), PL_EDIT_TOOL::Init(), LIB_DRAWING_TOOLS::Init(), MODULE_EDITOR_TOOLS::Init(), PL_DRAWING_TOOLS::Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), SCH_DRAWING_TOOLS::Init(), GERBVIEW_SELECTION_TOOL::Init(), Init(), PL_SELECTION_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), SELECTION_TOOL::Init(), EDIT_TOOL::Init(), PCB_TOOL_BASE::Init(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ m_mode

◆ m_toolId

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 214 of file tool_base.h.

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

◆ m_toolMgr

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 219 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), PL_SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::AddItemsToSel(), PL_SELECTION_TOOL::AddItemToSel(), EE_SELECTION_TOOL::AddItemToSel(), SELECTION_TOOL::AddItemToSel(), CVPCB_ASSOCIATION_TOOL::Associate(), TOOL_BASE::attachManager(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), PCB_INSPECTION_TOOL::ClearHighlight(), SCH_EDITOR_CONTROL::ClearHighlight(), PL_SELECTION_TOOL::ClearSelection(), GERBVIEW_SELECTION_TOOL::clearSelection(), EE_SELECTION_TOOL::ClearSelection(), SELECTION_TOOL::clearSelection(), SCH_EDIT_TOOL::ConvertDeMorgan(), LIB_EDIT_TOOL::Copy(), PL_EDIT_TOOL::Copy(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), COMMON_TOOLS::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), SCH_EDITOR_CONTROL::Cut(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), LIB_EDIT_TOOL::DoDelete(), SCH_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), DrawArc(), drawArc(), DrawCircle(), DrawDimension(), drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::Duplicate(), EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::editComponentFieldText(), EDIT_TOOL::EditFpInFpEditor(), LIB_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithLibEdit(), SCH_EDITOR_CONTROL::EnterSheet(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::findCallback(), SCH_EDITOR_CONTROL::FindComponentAndItem(), POINT_EDITOR::finishItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), EDIT_TOOL::Flip(), EDIT_TOOL::GetAndPlace(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), GERBVIEW_CONTROL::HighlightControl(), PCB_INSPECTION_TOOL::HighlightItem(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::ImportWorksheetContent(), LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), PAD_TOOL::Init(), GLOBAL_EDIT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), PL_DRAWING_TOOLS::Init(), LIB_CONTROL::Init(), PL_POINT_EDITOR::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), POSITION_RELATIVE_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), TOOL_BASE::IsToolActive(), SCH_EDITOR_CONTROL::LeaveSheet(), COMMON_CONTROL::ListHotKeys(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), CVPCB_CONTROL::Main(), LIB_MOVE_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LIB_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), LIB_CONTROL::OnDeMorgan(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), EDIT_TOOL::pickCopyReferencePoint(), LIB_EDIT_TOOL::PinTable(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), PCBNEW_CONTROL::Print(), GERBVIEW_CONTROL::Print(), LIB_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EE_SELECTION_TOOL::RebuildSelection(), LIB_EDIT_TOOL::Redo(), SCH_EDITOR_CONTROL::Redo(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PL_SELECTION_TOOL::RemoveItemFromSel(), EE_SELECTION_TOOL::RemoveItemFromSel(), PL_SELECTION_TOOL::RemoveItemsFromSel(), EE_SELECTION_TOOL::RemoveItemsFromSel(), SCH_EDIT_TOOL::RepeatDrawItem(), LIB_DRAWING_TOOLS::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), SELECTION_TOOL::RequestSelection(), COMMON_TOOLS::ResetLocalCoords(), TOOL_INTERACTIVE::resetTransitions(), LIB_EDIT_TOOL::Rotate(), SCH_EDIT_TOOL::Rotate(), EDIT_TOOL::Rotate(), TOOL_INTERACTIVE::RunMainStack(), DRC::RunTests(), EE_SELECTION_TOOL::SelectConnection(), SELECTION_TOOL::selectCopper(), PCB_TOOL_BASE::selection(), COMMON_TOOLS::SelectionTool(), GERBVIEW_SELECTION_TOOL::SelectItem(), GERBVIEW_SELECTION_TOOL::SelectItems(), SELECTION_TOOL::SelectItems(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectNet(), PL_SELECTION_TOOL::SelectPoint(), GERBVIEW_SELECTION_TOOL::selectPoint(), EE_SELECTION_TOOL::SelectPoint(), SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), SELECTION_TOOL::selectSameSheet(), SELECTION_TOOL::selectSheetContents(), SetAnchor(), TOOL_INTERACTIVE::SetContextMenu(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), LIB_EDIT_TOOL::Undo(), SCH_EDITOR_CONTROL::Undo(), SCH_LINE_WIRE_BUS_TOOL::UnfoldBus(), GERBVIEW_SELECTION_TOOL::UnselectItem(), SELECTION_TOOL::UnselectItem(), GERBVIEW_SELECTION_TOOL::UnselectItems(), SELECTION_TOOL::UnselectItems(), EE_INSPECTION_TOOL::UpdateMessagePanel(), GERBVIEW_CONTROL::UpdateMessagePanel(), PL_EDITOR_CONTROL::UpdateMessagePanel(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), and PCB_EDITOR_CONTROL::ZoneMerge().

◆ m_toolName

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

Referenced by TOOL_BASE::GetName().

◆ m_toolSettings

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 220 of file tool_base.h.

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

◆ m_type

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 211 of file tool_base.h.

Referenced by TOOL_BASE::GetType().

◆ m_view

KIGFX::VIEW* DRAWING_TOOL::m_view
private

◆ WIDTH_STEP

const unsigned int DRAWING_TOOL::WIDTH_STEP = Millimeter2iu( 0.1 )
staticprivate

Definition at line 233 of file drawing_tool.h.

Referenced by drawArc(), DrawDimension(), and drawSegment().


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