KiCad PCB EDA Suite
DRAWING_TOOL Class Reference

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::RECTANGLE, 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 DrawRectangle (const TOOL_EVENT &aEvent)
 Function DrawRectangle() Starts interactively drawing a rectangle. 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 footprint editor. More...
 
int SetAnchor (const TOOL_EVENT &aEvent)
 Function SetAnchor() Places the footprint anchor (only in footprint editor). More...
 
void setTransitions () override
 

Sets up handlers for various events.

More...
 
void SetIsFootprintEditor (bool aEnabled)
 Function SetIsFootprintEditor() More...
 
bool IsFootprintEditor () 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...
 
bool IsToolActive () const
 

Protected Types

enum  INTERACTIVE_PLACEMENT_OPTIONS { IPO_ROTATE = 0x01, IPO_FLIP = 0x02, IPO_SINGLE_CLICK = 0x04, IPO_REPEAT = 0x08 }
 Options for placing items interactively. More...
 

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
 
FOOTPRINTfootprint () const
 
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_isFootprintEditor
 
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
 

Private Member Functions

bool drawSegment (const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
 Starts drawing a selected shape (i.e. More...
 
bool drawArc (const std::string &aTool, PCB_SHAPE **aGraphic, bool aImmediateMode)
 Starts drawing an arc. More...
 
bool getSourceZoneForAction (ZONE_MODE aMode, ZONE **aZone)
 Draws a polygon, that is added as a zone or a keepout area. More...
 
void constrainDimension (DIMENSION_BASE *aDim)
 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...
 

Private Attributes

KIGFX::VIEWm_view
 
KIGFX::VIEW_CONTROLSm_controls
 
BOARDm_board
 
PCB_BASE_EDIT_FRAMEm_frame
 
MODE m_mode
 
unsigned int m_lineWidth
 

Static Private Attributes

static const unsigned int WIDTH_STEP = Millimeter2iu( 0.1 )
 

Friends

class ZONE_CREATE_HELPER
 

Detailed Description

DRAWING_TOOL.

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

Definition at line 50 of file drawing_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Options for placing items interactively.

Enumerator
IPO_ROTATE 

Handle the rotate action in the loop by calling the item's rotate method.

IPO_FLIP 

Handle flip action in the loop by calling the item's flip method.

IPO_SINGLE_CLICK 

Create an item immediately on placement starting, otherwise show the pencil cursor until the item is created.

IPO_REPEAT 

Allow repeat placement of the item.

Definition at line 111 of file pcb_tool_base.h.

111  {
113  IPO_ROTATE = 0x01,
114 
116  IPO_FLIP = 0x02,
117 
120  IPO_SINGLE_CLICK = 0x04,
121 
123  IPO_REPEAT = 0x08
124  };
Handle flip action in the loop by calling the item's flip method.
Allow repeat placement of the item.
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
Handle the rotate action in the loop by calling the item's rotate method.

◆ MODE

enum DRAWING_TOOL::MODE
strong

The possible drawing modes of DRAWING_TOOL

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

Definition at line 63 of file drawing_tool.h.

64  {
65  NONE,
66  LINE,
67  RECTANGLE,
68  CIRCLE,
69  ARC,
70  TEXT,
71  ANCHOR,
72  DXF,
73  DIMENSION,
74  KEEPOUT,
75  ZONE,
77  VIA
78  };
Definition: track.h:354
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
Definition: track.h:272

◆ 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 145 of file drawing_tool.cpp.

145  :
146  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
147  m_view( nullptr ), m_controls( nullptr ),
148  m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
149  m_lineWidth( 1 )
150 {
151 }
BOARD * m_board
Definition: drawing_tool.h:228
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
unsigned int m_lineWidth
Definition: drawing_tool.h:232
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:227
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:78

◆ ~DRAWING_TOOL()

DRAWING_TOOL::~DRAWING_TOOL ( )

Definition at line 154 of file drawing_tool.cpp.

155 {
156 }

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(), EDIT_TOOL::doMoveSelection(), DrawArc(), DrawCircle(), DrawDimension(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DrawRectangle(), 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(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), 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_TOOL::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 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 160 of file pcb_tool_base.h.

160 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), PCB_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), FOOTPRINT_EDITOR_TOOLS::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), drawArc(), DrawDimension(), drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), SELECTION_TOOL::filterSelection(), PCB_TOOL_BASE::footprint(), SELECTION_TOOL::GetBoard(), SELECTION_TOOL::getCollectorsGuide(), GROUP_TOOL::Group(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::MoveExact(), FOOTPRINT_EDITOR_TOOLS::NewFootprint(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PAD_TOOL::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), SELECTION_TOOL::RebuildSelection(), PAD_TOOL::recombinePad(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::RepairBoard(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), SELECTION_TOOL::Selectable(), SELECTION_TOOL::selectAllItemsOnNet(), SELECTION_TOOL::selectAllItemsOnSheet(), SELECTION_TOOL::selectConnectedTracks(), SELECTION_TOOL::selectPoint(), PCBNEW_CONTROL::TrackDisplayMode(), GROUP_TOOL::Ungroup(), 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_BASE aDim)
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 629 of file drawing_tool.cpp.

630 {
631  const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() };
632 
633  aDim->SetEnd( wxPoint( VECTOR2I( aDim->GetStart() ) + GetVectorSnapped45( lineVector ) ) );
634 }
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition: dimension.h:121
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
virtual void SetEnd(const wxPoint &aPoint)
Definition: dimension.cpp:303
virtual const wxPoint & GetEnd() const
Definition: dimension.h:124

References DIMENSION_BASE::GetEnd(), DIMENSION_BASE::GetStart(), GetVectorSnapped45(), and DIMENSION_BASE::SetEnd().

Referenced by DrawDimension().

◆ controls()

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

◆ 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 
53  // Add a VIEW_GROUP that serves as a preview for the new item
54  PCBNEW_SELECTION preview;
55  view()->Add( &preview );
56 
57  aPlacer->m_board = board();
58  aPlacer->m_frame = frame();
59  aPlacer->m_modifiers = 0;
60 
61  auto makeNewItem =
62  [&]( 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_FOOTPRINT_T )
73  {
74  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
75 
76  // footprints have more drawable parts
77  fp->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  auto setCursor =
86  [&]()
87  {
88  if( !newItem )
90  else
92  };
93 
94  // Set initial cursor
95  setCursor();
96 
97  // Main loop: keep receiving events
98  while( TOOL_EVENT* evt = Wait() )
99  {
100  setCursor();
101 
102  VECTOR2I cursorPos = controls()->GetCursorPosition();
103  aPlacer->m_modifiers = evt->Modifier();
104 
105  auto cleanup =
106  [&] ()
107  {
108  newItem = nullptr;
109  preview.Clear();
110  view()->Update( &preview );
111  controls()->SetAutoPan( false );
112  controls()->CaptureCursor( false );
113  controls()->ShowCursor( true );
114  };
115 
116  if( evt->IsCancelInteractive() )
117  {
118  if( aOptions & IPO_SINGLE_CLICK )
119  {
120  cleanup();
121  frame()->PopTool( aTool );
122  break;
123  }
124  else if( newItem )
125  cleanup();
126  else
127  {
128  frame()->PopTool( aTool );
129  break;
130  }
131  }
132  else if( evt->IsActivate() )
133  {
134  if( newItem )
135  cleanup();
136 
137  if( evt->IsPointEditor() )
138  {
139  // don't exit (the point editor runs in the background)
140  }
141  else if( evt->IsMoveTool() )
142  {
143  // leave ourselves on the stack so we come back after the move
144  break;
145  }
146  else
147  {
148  frame()->PopTool( aTool );
149  break;
150  }
151  }
152  else if( evt->IsClick( BUT_LEFT ) )
153  {
154  if( !newItem )
155  {
156  // create the item if possible
157  makeNewItem( cursorPos );
158 
159  // no item created, so wait for another click
160  if( !newItem )
161  continue;
162 
163  controls()->CaptureCursor( true );
164  controls()->SetAutoPan( true );
165  }
166  else
167  {
168  auto oldFlags = newItem->GetFlags();
169  newItem->ClearFlags();
170 
171  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
172  {
173  newItem->SetFlags( oldFlags );
174  continue;
175  }
176 
177  preview.Clear();
178  newItem.release();
179  commit.Push( aCommitMessage );
180 
181  controls()->CaptureCursor( false );
182  controls()->SetAutoPan( false );
183  controls()->ShowCursor( true );
184 
185  if( !( aOptions & IPO_REPEAT ) )
186  break;
187 
188  if( aOptions & IPO_SINGLE_CLICK )
189  makeNewItem( controls()->GetCursorPosition() );
190 
191  setCursor();
192  }
193  }
194  else if( evt->IsClick( BUT_RIGHT ) )
195  {
197  }
198  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
199  {
201  }
202  else if( newItem && evt->Category() == TC_COMMAND )
203  {
204  /*
205  * Handle any events that can affect the item as we move it around
206  */
207  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
208  {
209  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
210  newItem->Rotate( newItem->GetPosition(), rotationAngle );
211  view()->Update( &preview );
212  }
213  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
214  {
215  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
216  view()->Update( &preview );
217  }
218  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
219  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
220  {
221  // Refresh preview after event runs
223  }
224  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
225  {
226  preview.Clear();
227  newItem.release();
228 
229  makeNewItem( (wxPoint) cursorPos );
230  aPlacer->SnapItem( newItem.get() );
231  view()->Update( &preview );
232  }
233  }
234  else if( newItem && evt->IsMotion() )
235  {
236  // track the cursor
237  newItem->SetPosition( (wxPoint) cursorPos );
238  aPlacer->SnapItem( newItem.get() );
239 
240  // Show a preview of the item
241  view()->Update( &preview );
242  }
243  else
244  {
245  evt->SetPassEvent();
246  }
247  }
248 
249  view()->Remove( &preview );
251 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
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
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
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)
Handle flip action in the loop by calling the item's flip method.
BOARD * board() const
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:296
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
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 PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:299
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
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)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:94
const PCBNEW_SELECTION & selection() const
Allow repeat placement of the item.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
KIGFX::PCB_VIEW * view() const
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
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.
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:108
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
PCBNEW_SETTINGS & Settings()
void Activate()
Function Activate() Runs the tool.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Function RunOnChildren.
Definition: footprint.cpp:1066
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:59
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:65
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
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:297
static TOOL_ACTION refreshPreview
Definition: actions.h:104
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(), ARROW, 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(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_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, PCBNEW_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, TOOL_BASE::m_toolMgr, PCB_FOOTPRINT_T, PENCIL, PLACE, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), FOOTPRINT::RunOnChildren(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, PCB_ACTIONS::trackViaSizeChanged, KIGFX::PCB_VIEW::Update(), PCB_ACTIONS::viaSizeDec, PCB_ACTIONS::viaSizeInc, PCB_TOOL_BASE::view(), and TOOL_INTERACTIVE::Wait().

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint(), DrawVia(), and PAD_TOOL::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 371 of file drawing_tool.cpp.

372 {
374  return 0;
375 
376  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
377  PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
378  BOARD_COMMIT commit( m_frame );
379  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
380  bool immediateMode = aEvent.HasPosition();
381 
382  arc->SetShape( S_ARC );
383  arc->SetFlags( IS_NEW );
384 
385  std::string tool = aEvent.GetCommandStr().get();
386  m_frame->PushTool( tool );
387  Activate();
388 
389  while( drawArc( tool, &arc, immediateMode ) )
390  {
391  if( arc )
392  {
393  if( m_isFootprintEditor )
394  static_cast<FP_SHAPE*>( arc )->SetLocalCoord();
395 
396  commit.Add( arc );
397  commit.Push( _( "Draw an arc" ) );
398 
400  }
401 
402  arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
403  arc->SetShape( S_ARC );
404  arc->SetFlags( IS_NEW );
405  immediateMode = false;
406  }
407 
408  return 0;
409 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
Arcs (with rounded ends)
Definition: board_item.h:54
RAII class that sets an value at construction and resets it to the original value at destruction.
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
bool drawArc(const std::string &aTool, PCB_SHAPE **aGraphic, bool aImmediateMode)
Starts drawing an arc.
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
void Activate()
Function Activate() Runs the tool.
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:260
#define IS_NEW
New item, just created.
Definition: eda_item.h:106

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), ARC, drawArc(), TOOL_EVENT::GetCommandStr(), PCB_BASE_FRAME::GetModel(), TOOL_EVENT::HasPosition(), IS_NEW, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, TOOL_BASE::m_toolMgr, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), TOOL_MANAGER::RunAction(), S_ARC, PCB_ACTIONS::selectItem, and PCB_SHAPE::SetShape().

Referenced by setTransitions().

◆ drawArc()

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

Starts drawing an arc.

Parameters
aGraphicis an object that is going to be used by the tool for drawing. Must 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 1565 of file drawing_tool.cpp.

1566 {
1567  PCB_SHAPE*& graphic = *aGraphic;
1569 
1570  // Arc geometric construction manager
1572 
1573  // Arc drawing assistant overlay
1574  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1575 
1576  // Add a VIEW_GROUP that serves as a preview for the new item
1577  PCBNEW_SELECTION preview;
1578  m_view->Add( &preview );
1579  m_view->Add( &arcAsst );
1581 
1582  m_controls->ShowCursor( true );
1583 
1584  bool firstPoint = false;
1585  bool cancelled = false;
1586 
1587  // Prime the pump
1589 
1590  if( aImmediateMode )
1592 
1593  // Set initial cursor
1594  auto setCursor =
1595  [&]()
1596  {
1598  };
1599 
1600  setCursor();
1601 
1602  // Main loop: keep receiving events
1603  while( TOOL_EVENT* evt = Wait() )
1604  {
1605  if( firstPoint )
1606  m_frame->SetMsgPanel( graphic );
1607 
1608  setCursor();
1609 
1610  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1611  graphic->SetLayer( layer );
1612 
1613  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1614  grid.SetUseGrid( m_frame->IsGridVisible() );
1615  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
1616  m_controls->ForceCursorPosition( true, cursorPos );
1617 
1618  auto cleanup =
1619  [&] ()
1620  {
1621  preview.Clear();
1622  delete *aGraphic;
1623  *aGraphic = nullptr;
1624  };
1625 
1626  if( evt->IsCancelInteractive() )
1627  {
1628  cleanup();
1629 
1630  if( !firstPoint )
1631  {
1632  m_frame->PopTool( aTool );
1633  cancelled = true;
1634  }
1635 
1636  break;
1637  }
1638  else if( evt->IsActivate() )
1639  {
1640  if( evt->IsPointEditor() )
1641  {
1642  // don't exit (the point editor runs in the background)
1643  }
1644  else if( evt->IsMoveTool() )
1645  {
1646  cleanup();
1647  // leave ourselves on the stack so we come back after the move
1648  cancelled = true;
1649  break;
1650  }
1651  else
1652  {
1653  cleanup();
1654  m_frame->PopTool( aTool );
1655  cancelled = true;
1656  break;
1657  }
1658  }
1659  else if( evt->IsClick( BUT_LEFT ) )
1660  {
1661  if( !firstPoint )
1662  {
1664 
1665  m_controls->SetAutoPan( true );
1666  m_controls->CaptureCursor( true );
1667 
1669 
1670  // Init the new item attributes
1671  // (non-geometric, those are handled by the manager)
1672  graphic->SetShape( S_ARC );
1673  graphic->SetWidth( m_lineWidth );
1674 
1675  preview.Add( graphic );
1676  frame()->SetMsgPanel( graphic );
1677  firstPoint = true;
1678  }
1679 
1680  arcManager.AddPoint( cursorPos, true );
1681  }
1682  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1683  {
1684  arcManager.RemoveLastPoint();
1685  }
1686  else if( evt->IsMotion() )
1687  {
1688  // set angle snap
1689  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1690 
1691  // update, but don't step the manager state
1692  arcManager.AddPoint( cursorPos, false );
1693  }
1694  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1695  {
1697  graphic->SetLayer( m_frame->GetActiveLayer() );
1698  graphic->SetWidth( m_lineWidth );
1699  m_view->Update( &preview );
1700  frame()->SetMsgPanel( graphic );
1701  }
1702  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1703  {
1704  if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_START )
1705  {
1706  graphic->SetAngle( 900, true );
1707  frame()->OnEditItemRequest( graphic );
1708  m_view->Update( &preview );
1709  frame()->SetMsgPanel( graphic );
1710  break;
1711  }
1712  else if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
1713  {
1714  frame()->OnEditItemRequest( graphic );
1715  m_view->Update( &preview );
1716  frame()->SetMsgPanel( graphic );
1717  break;
1718  }
1719  else
1720  {
1721  evt->SetPassEvent();
1722  }
1723  }
1724  else if( evt->IsClick( BUT_RIGHT ) )
1725  {
1727  }
1728  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1729  {
1731  graphic->SetWidth( m_lineWidth );
1732  m_view->Update( &preview );
1733  frame()->SetMsgPanel( graphic );
1734  }
1735  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1736  {
1738  graphic->SetWidth( m_lineWidth );
1739  m_view->Update( &preview );
1740  frame()->SetMsgPanel( graphic );
1741  }
1742  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1743  {
1744  arcManager.ToggleClockwise();
1745  }
1746  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1747  {
1748  arcAsst.SetUnits( frame()->GetUserUnits() );
1749  m_view->Update( &arcAsst );
1750  evt->SetPassEvent();
1751  }
1752  else
1753  {
1754  evt->SetPassEvent();
1755  }
1756 
1757  if( arcManager.IsComplete() )
1758  {
1759  break;
1760  }
1761  else if( arcManager.HasGeometryChanged() )
1762  {
1763  updateArcFromConstructionMgr( arcManager, *graphic );
1764  m_view->Update( &preview );
1765  m_view->Update( &arcAsst );
1766 
1767  if( firstPoint )
1768  frame()->SetMsgPanel( graphic );
1769  else
1770  frame()->SetMsgPanel( board() );
1771  }
1772  }
1773 
1774  preview.Remove( graphic );
1775  m_view->Remove( &arcAsst );
1776  m_view->Remove( &preview );
1777  m_frame->SetMsgPanel( board() );
1778 
1780  m_controls->SetAutoPan( false );
1781  m_controls->CaptureCursor( false );
1782  m_controls->ForceCursorPosition( false );
1783 
1784  return !cancelled;
1785 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
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
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
int GetUserUnits()
Returns the currently selected user unit value for the interface.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: board_item.h:206
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, PCB_SHAPE &aArc)
Update an arc PCB_SHAPE from the current state of an Arc Geometry Manager.
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 OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
Arcs (with rounded ends)
Definition: board_item.h:54
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_LAYER_ID
A quick note on layer IDs:
const PCBNEW_SELECTION & selection() const
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
Waiting to lock in origin point
bool IsGridVisible() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
unsigned int m_lineWidth
Definition: drawing_tool.h:232
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:227
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:229
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:174
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
static TOOL_ACTION updateUnits
Definition: actions.h:145
Waiting to lock in the arc start point
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
Represents an assistant draw when interactively drawing an arc on a canvas.
Definition: arc_assistant.h:38
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:164
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: pcb_shape.cpp:444
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:104
static TOOL_ACTION cursorClick
Definition: actions.h:121
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513

References KIGFX::VIEW::Add(), PCB_ACTIONS::arcPosture, ARROW, 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::GetActiveLayer(), PCB_BASE_FRAME::GetCanvas(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSegmentWidth(), EDA_BASE_FRAME::GetUserUnits(), GetUserUnits(), PCB_ACTIONS::incWidth, EDA_DRAW_FRAME::IsGridVisible(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, m_view, MD_CTRL, MD_SHIFT, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PENCIL, TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), S_ARC, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_START, PCB_SHAPE::SetAngle(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_SHAPE::SetShape(), PCB_SHAPE::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), updateArcFromConstructionMgr(), ACTIONS::updateUnits, 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 325 of file drawing_tool.cpp.

326 {
328  return 0;
329 
330  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
331  PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
332  BOARD_COMMIT commit( m_frame );
333  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
334  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
335 
336  circle->SetShape( S_CIRCLE );
337  circle->SetFilled( false );
338  circle->SetFlags( IS_NEW );
339 
340  if( aEvent.HasPosition() )
341  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
342 
343  std::string tool = aEvent.GetCommandStr().get();
344  m_frame->PushTool( tool );
345  Activate();
346 
347  while( drawSegment( tool, &circle, startingPoint ) )
348  {
349  if( circle )
350  {
351  if( m_isFootprintEditor )
352  static_cast<FP_SHAPE*>( circle )->SetLocalCoord();
353 
354  commit.Add( circle );
355  commit.Push( _( "Draw a circle" ) );
356 
357  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
358  }
359 
360  circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
361  circle->SetShape( S_CIRCLE );
362  circle->SetFilled( false );
363  circle->SetFlags( IS_NEW );
364  startingPoint = NULLOPT;
365  }
366 
367  return 0;
368 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:342
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
boost::optional< T > OPT
Definition: optional.h:7
ring
Definition: board_item.h:55
void Activate()
Function Activate() Runs the tool.
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:260
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
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_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, TOOL_BASE::m_toolMgr, MD_ALT, TOOL_EVENT::Modifier(), NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), TOOL_MANAGER::RunAction(), S_CIRCLE, PCB_ACTIONS::selectItem, and PCB_SHAPE::SetShape().

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 637 of file drawing_tool.cpp.

638 {
640  return 0;
641 
642  TOOL_EVENT originalEvent = aEvent;
643  DIMENSION_BASE* dimension = nullptr;
644  BOARD_COMMIT commit( m_frame );
646 
647  const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
648 
649  // Add a VIEW_GROUP that serves as a preview for the new item
650  PCBNEW_SELECTION preview;
651 
652  m_view->Add( &preview );
653 
655  m_controls->ShowCursor( true );
656 
657  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
658 
659  std::string tool = aEvent.GetCommandStr().get();
660  m_frame->PushTool( tool );
661  Activate();
662 
663  enum DIMENSION_STEPS
664  {
665  SET_ORIGIN = 0,
666  SET_END,
667  SET_HEIGHT,
668  FINISHED
669  };
670  int step = SET_ORIGIN;
671 
672  // Prime the pump
674 
675  if( aEvent.HasPosition() )
676  m_toolMgr->PrimeTool( aEvent.Position() );
677 
678  auto setCursor =
679  [&]()
680  {
682  };
683 
684  // Set initial cursor
685  setCursor();
686 
687  // Main loop: keep receiving events
688  while( TOOL_EVENT* evt = Wait() )
689  {
690  if( step > SET_ORIGIN )
691  frame()->SetMsgPanel( dimension );
692 
693  setCursor();
694 
695  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
696  grid.SetUseGrid( m_frame->IsGridVisible() );
697  VECTOR2I cursorPos = evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition();
698  cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
699  m_controls->ForceCursorPosition( true, cursorPos );
700 
701  auto cleanup =
702  [&]()
703  {
704  m_controls->SetAutoPan( false );
705  m_controls->CaptureCursor( false );
706 
707  preview.Clear();
708  m_view->Update( &preview );
709 
710  delete dimension;
711  dimension = nullptr;
712  step = SET_ORIGIN;
713  };
714 
715  if( evt->IsCancelInteractive() )
716  {
717  m_controls->SetAutoPan( false );
718 
719  if( step != SET_ORIGIN ) // start from the beginning
720  {
721  cleanup();
722  }
723  else
724  {
725  m_frame->PopTool( tool );
726  break;
727  }
728  }
729  else if( evt->IsActivate() )
730  {
731  if( step != SET_ORIGIN )
732  cleanup();
733 
734  if( evt->IsPointEditor() )
735  {
736  // don't exit (the point editor runs in the background)
737  }
738  else if( evt->IsMoveTool() )
739  {
740  // leave ourselves on the stack so we come back after the move
741  break;
742  }
743  else
744  {
745  m_frame->PopTool( tool );
746  break;
747  }
748  }
749  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
750  {
752  dimension->SetLineThickness( m_lineWidth );
753  m_view->Update( &preview );
754  frame()->SetMsgPanel( dimension );
755  }
756  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
757  {
758  if( m_lineWidth > WIDTH_STEP )
759  {
761  dimension->SetLineThickness( m_lineWidth );
762  m_view->Update( &preview );
763  frame()->SetMsgPanel( dimension );
764  }
765  }
766  else if( evt->IsClick( BUT_RIGHT ) )
767  {
769  }
770  else if( evt->IsClick( BUT_LEFT ) )
771  {
772  switch( step )
773  {
774  case SET_ORIGIN:
775  {
777 
779 
780  // Init the new item attributes
781  auto setMeasurementAttributes =
782  [&]( DIMENSION_BASE* aDim )
783  {
784  aDim->SetUnitsMode( boardSettings.m_DimensionUnitsMode );
785  aDim->SetUnitsFormat( boardSettings.m_DimensionUnitsFormat );
786  aDim->SetPrecision( boardSettings.m_DimensionPrecision );
787  aDim->SetSuppressZeroes( boardSettings.m_DimensionSuppressZeroes );
788  aDim->SetTextPositionMode( boardSettings.m_DimensionTextPosition );
789  aDim->SetKeepTextAligned( boardSettings.m_DimensionKeepTextAligned );
790 
791  if( boardSettings.m_DimensionUnitsMode == DIM_UNITS_MODE::AUTOMATIC )
792  aDim->SetUnits( m_frame->GetUserUnits() );
793  };
794 
795  if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) )
796  {
797  dimension = new ALIGNED_DIMENSION( m_board );
798  setMeasurementAttributes( dimension );
799  }
800  else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) )
801  {
802  dimension = new ORTHOGONAL_DIMENSION( m_board );
803  setMeasurementAttributes( dimension );
804  }
805  else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) )
806  {
807  dimension = new CENTER_DIMENSION( m_board );
808  }
809  else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) )
810  {
811  dimension = new LEADER( m_board );
812  dimension->Text().SetPosition( wxPoint( cursorPos ) );
813  }
814  else
815  {
816  wxFAIL_MSG( "Unhandled action in DRAWING_TOOL::DrawDimension" );
817  }
818 
819  dimension->SetLayer( layer );
820  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
821  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
822  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
823  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
824  dimension->SetArrowLength( boardSettings.m_DimensionArrowLength );
825  dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset );
826  dimension->SetStart( (wxPoint) cursorPos );
827  dimension->SetEnd( (wxPoint) cursorPos );
828 
829  preview.Add( dimension );
830  frame()->SetMsgPanel( dimension );
831 
832  m_controls->SetAutoPan( true );
833  m_controls->CaptureCursor( true );
834  }
835  break;
836 
837  case SET_END:
838  {
839  dimension->SetEnd( (wxPoint) cursorPos );
840 
841  if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T )
842  constrainDimension( dimension );
843 
844  // Dimensions that have origin and end in the same spot are not valid
845  if( dimension->GetStart() == dimension->GetEnd() )
846  --step;
847  else if( dimension->Type() == PCB_DIM_LEADER_T )
848  dimension->SetText( wxT( "?" ) );
849 
850  if( dimension->Type() == PCB_DIM_CENTER_T )
851  {
852  // No separate height/text step
853  ++step;
855  }
856  else
857  {
858  break;
859  }
860  }
861 
862  case SET_HEIGHT:
863  if( dimension->Type() == PCB_DIM_LEADER_T )
864  {
865  assert( dimension->GetStart() != dimension->GetEnd() );
866  assert( dimension->GetLineThickness() > 0 );
867 
868  preview.Remove( dimension );
869 
870  commit.Add( dimension );
871  commit.Push( _( "Draw a leader" ) );
872 
873  // Run the edit immediately to set the leader text
874  m_toolMgr->RunAction( PCB_ACTIONS::properties, true, dimension );
875  }
876  else if( (wxPoint) cursorPos != dimension->GetPosition() )
877  {
878  assert( dimension->GetStart() != dimension->GetEnd() );
879  assert( dimension->GetLineThickness() > 0 );
880 
881  preview.Remove( dimension );
882 
883  commit.Add( dimension );
884  commit.Push( _( "Draw a dimension" ) );
885 
886  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
887  }
888 
889  break;
890  }
891 
892  if( ++step == FINISHED )
893  {
894  step = SET_ORIGIN;
895  m_controls->SetAutoPan( false );
896  m_controls->CaptureCursor( false );
897  }
898  }
899  else if( evt->IsMotion() )
900  {
901  switch( step )
902  {
903  case SET_END:
904  dimension->SetEnd( (wxPoint) cursorPos );
905 
906  if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T )
907  constrainDimension( dimension );
908 
909  break;
910 
911  case SET_HEIGHT:
912  {
913  if( dimension->Type() == PCB_DIM_ALIGNED_T )
914  {
915  ALIGNED_DIMENSION* aligned = static_cast<ALIGNED_DIMENSION*>( dimension );
916 
917  // Calculating the direction of travel perpendicular to the selected axis
918  double angle = aligned->GetAngle() + ( M_PI / 2 );
919 
920  wxPoint delta( (wxPoint) cursorPos - dimension->GetEnd() );
921  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
922  aligned->SetHeight( height );
923  }
924  else if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
925  {
926  ORTHOGONAL_DIMENSION* ortho = static_cast<ORTHOGONAL_DIMENSION*>( dimension );
927 
928  BOX2I bounds( dimension->GetStart(),
929  dimension->GetEnd() - dimension->GetStart() );
930  VECTOR2I direction( cursorPos - bounds.Centre() );
931  bool vert = std::abs( direction.y ) < std::abs( direction.x );
932 
933  // Only change the orientation when we move outside the bounds
934  if( !bounds.Contains( cursorPos ) )
935  {
938  }
939  else
940  {
942  }
943 
944  VECTOR2I heightVector( cursorPos - dimension->GetStart() );
945  ortho->SetHeight( vert ? heightVector.x : heightVector.y );
946  }
947  else if( dimension->Type() == PCB_DIM_LEADER_T )
948  {
949  // Leader: SET_HEIGHT actually sets the text position directly
950  VECTOR2I lineVector( cursorPos - dimension->GetEnd() );
951  dimension->Text().SetPosition( wxPoint( VECTOR2I( dimension->GetEnd() ) +
952  GetVectorSnapped45( lineVector ) ) );
953  dimension->Update();
954  }
955  }
956  break;
957  }
958 
959  // Show a preview of the item
960  m_view->Update( &preview );
961  }
962  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
963  {
964  if( step == SET_END || step == SET_HEIGHT )
965  {
966  frame()->OnEditItemRequest( dimension );
967  dimension->Update();
968  frame()->SetMsgPanel( dimension );
969  break;
970  }
971  else
972  {
973  evt->SetPassEvent();
974  }
975  }
976  else
977  {
978  evt->SetPassEvent();
979  }
980  }
981 
982  if( step != SET_ORIGIN )
983  delete dimension;
984 
985  m_controls->SetAutoPan( false );
987  m_controls->CaptureCursor( false );
989 
990  m_view->Remove( &preview );
991  m_frame->SetMsgPanel( board() );
992  return 0;
993 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
static TOOL_ACTION drawCenterDimension
Definition: pcb_actions.h:152
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
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:228
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:168
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:77
virtual void SetStart(const wxPoint &aPoint)
Definition: dimension.cpp:296
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: dimension.cpp:212
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
void SetItalic(bool isItalic)
Definition: eda_text.h:185
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:151
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition: dimension.h:121
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
static TOOL_ACTION drawOrthogonalDimension
Definition: pcb_actions.h:153
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void PrimeTool(const VECTOR2D &aPosition)
Function PrimeTool() "Primes" a tool by sending a cursor left-click event with the mouse position set...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:559
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
void Update()
Updates the dimension's cached text and geometry.
Definition: dimension.h:146
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
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:67
int GetLineThickness() const
Definition: dimension.h:187
double GetAngle() const
Function GetAngle Returns angle of the crossbar.
Definition: dimension.h:383
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
PCB_BASE_EDIT_FRAME * frame() const
void constrainDimension(DIMENSION_BASE *aDim)
Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees.
virtual PCB_LAYER_ID GetActiveLayer() const
void SetText(const wxString &aNewText)
Sets the override text - has no effect if m_overrideValue == false.
Definition: dimension.cpp:199
PCB_LAYER_ID
A quick note on layer IDs:
void SetHeight(int aHeight)
Sets the distance from the feature points to the crossbar line.
Definition: dimension.cpp:529
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.
bool IsGridVisible() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PCB_TEXT & Text()
Definition: dimension.h:209
TOOL_EVENT.
Definition: tool_event.h:171
DIR GetOrientation() const
Definition: dimension.h:441
unsigned int m_lineWidth
Definition: drawing_tool.h:232
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
Definition: dimension.h:407
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:227
void SetExtensionOffset(int aOffset)
Definition: dimension.h:184
bool m_isFootprintEditor
void SetOrientation(DIR aOrientation)
Sets the orientation of the dimension line (so, perpendicular to the feature lines)
Definition: dimension.h:440
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:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
wxPoint GetPosition() const override
Definition: dimension.h:127
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:154
#define _(s)
Definition: 3d_actions.cpp:33
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:65
void SetArrowLength(int aLength)
Definition: dimension.h:182
void Activate()
Function Activate() Runs the tool.
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
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:260
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
void SetLineThickness(int aWidth)
Definition: dimension.h:188
For better understanding of the points that make a dimension:
Definition: dimension.h:329
Abstract dimension API.
Definition: dimension.h:95
virtual void SetEnd(const wxPoint &aPoint)
Definition: dimension.cpp:303
virtual const wxPoint & GetEnd() const
Definition: dimension.h:124
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
const VECTOR2D Position() const
Returns mouse cursor position in world coordinates.
Definition: tool_event.h:274
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:104
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:86
Marks the center of a circle or arc with a cross shape The size and orientation of the cross is adjus...
Definition: dimension.h:509

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), PNS::angle(), ARROW, AUTOMATIC, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), PCB_ACTIONS::decWidth, DIMENSION, PCB_ACTIONS::drawAlignedDimension, PCB_ACTIONS::drawCenterDimension, PCB_ACTIONS::drawLeader, PCB_ACTIONS::drawOrthogonalDimension, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), ALIGNED_DIMENSION::GetAngle(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetDesignSettings(), DIMENSION_BASE::GetEnd(), DIMENSION_BASE::GetLineThickness(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), ORTHOGONAL_DIMENSION::GetOrientation(), DIMENSION_BASE::GetPosition(), DIMENSION_BASE::GetStart(), EDA_BASE_FRAME::GetUserUnits(), GetVectorSnapped45(), TOOL_EVENT::HasPosition(), ORTHOGONAL_DIMENSION::HORIZONTAL, PCB_ACTIONS::incWidth, TOOL_EVENT::IsAction(), EDA_DRAW_FRAME::IsGridVisible(), KI_FALLTHROUGH, LEADER, m_board, m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_lineWidth, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MD_CTRL, MD_SHIFT, MEASURE, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, TOOLS_HOLDER::PopTool(), TOOL_EVENT::Position(), TOOL_MANAGER::PrimeTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, SELECTION::Remove(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, DIMENSION_BASE::SetArrowLength(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), DIMENSION_BASE::SetEnd(), DIMENSION_BASE::SetExtensionOffset(), ALIGNED_DIMENSION::SetHeight(), EDA_TEXT::SetItalic(), DIMENSION_BASE::SetLayer(), DIMENSION_BASE::SetLineThickness(), EDA_DRAW_FRAME::SetMsgPanel(), ORTHOGONAL_DIMENSION::SetOrientation(), PCB_TEXT::SetPosition(), DIMENSION_BASE::SetStart(), DIMENSION_BASE::SetText(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), DIMENSION_BASE::Text(), EDA_ITEM::Type(), KIGFX::VIEW::Update(), DIMENSION_BASE::Update(), ORTHOGONAL_DIMENSION::VERTICAL, 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 233 of file drawing_tool.cpp.

234 {
236  return 0;
237 
238  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
239  PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
240  BOARD_COMMIT commit( m_frame );
241  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
242  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
243 
244  line->SetShape( S_SEGMENT );
245  line->SetFlags( IS_NEW );
246 
247  if( aEvent.HasPosition() )
248  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
249 
250  std::string tool = aEvent.GetCommandStr().get();
251  m_frame->PushTool( tool );
252  Activate();
253 
254  while( drawSegment( tool, &line, startingPoint ) )
255  {
256  if( line )
257  {
258  if( m_isFootprintEditor )
259  static_cast<FP_SHAPE*>( line )->SetLocalCoord();
260 
261  commit.Add( line );
262  commit.Push( _( "Draw a line segment" ) );
263  startingPoint = VECTOR2D( line->GetEnd() );
264  }
265  else
266  {
267  startingPoint = NULLOPT;
268  }
269 
270  line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
271  line->SetShape( S_SEGMENT );
272  line->SetFlags( IS_NEW );
273  }
274 
275  return 0;
276 }
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
usual segment : line with rounded ends
Definition: board_item.h:52
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:342
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Function Activate() Runs the tool.
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:260
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
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_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, LINE, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, MD_ALT, TOOL_EVENT::Modifier(), NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), S_SEGMENT, and PCB_SHAPE::SetShape().

Referenced by setTransitions().

◆ DrawRectangle()

int DRAWING_TOOL::DrawRectangle ( const TOOL_EVENT aEvent)

Function DrawRectangle() Starts interactively drawing a rectangle.

After invoking the function it expects the user to first click on a point that is going to be used as the top-left of the rectangle. The second click determines the bottom-right.

Definition at line 279 of file drawing_tool.cpp.

280 {
282  return 0;
283 
284  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
285  PCB_SHAPE* rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
286  BOARD_COMMIT commit( m_frame );
287  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
288  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
289 
290  rect->SetShape( S_RECT );
291  rect->SetFilled( false );
292  rect->SetFlags(IS_NEW );
293 
294  if( aEvent.HasPosition() )
295  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
296 
297  std::string tool = aEvent.GetCommandStr().get();
298  m_frame->PushTool( tool );
299  Activate();
300 
301  while( drawSegment( tool, &rect, startingPoint ) )
302  {
303  if( rect )
304  {
305  if( m_isFootprintEditor )
306  static_cast<FP_SHAPE*>( rect )->SetLocalCoord();
307 
308  commit.Add( rect );
309  commit.Push( _( "Draw a rectangle" ) );
310 
312  }
313 
314  rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
315  rect->SetShape( S_RECT );
316  rect->SetFilled( false );
317  rect->SetFlags(IS_NEW );
318  startingPoint = NULLOPT;
319  }
320 
321  return 0;
322 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
segment with non rounded ends
Definition: board_item.h:53
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:342
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Function Activate() Runs the tool.
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:260
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
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_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, TOOL_BASE::m_toolMgr, MD_ALT, TOOL_EVENT::Modifier(), NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), RECTANGLE, TOOL_MANAGER::RunAction(), S_RECT, PCB_ACTIONS::selectItem, and PCB_SHAPE::SetShape().

Referenced by setTransitions().

◆ drawSegment()

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

Starts drawing a selected shape (i.e.

PCB_SHAPE).

Parameters
aGraphicis an object that is going to be used by the tool for drawing. Must be already created. The tool deletes the object if it is not added to a BOARD.
aStartingPointis a starting point for this new PCB_SHAPE. If it 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 1261 of file drawing_tool.cpp.

1263 {
1264  int shape = (*aGraphic)->GetShape();
1265  // Only three shapes are currently supported
1266  assert( shape == S_SEGMENT || shape == S_CIRCLE || shape == S_RECT );
1267 
1268  EDA_UNITS userUnits = m_frame->GetUserUnits();
1270  PCB_SHAPE*& graphic = *aGraphic;
1271 
1273 
1274  // geometric construction manager
1276 
1277  // drawing assistant overlay
1278  // TODO: workaround because PCB_SHAPE_TYPE_T is not visible from commons.
1279  KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
1280  KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, userUnits, geomShape );
1281 
1282  // Add a VIEW_GROUP that serves as a preview for the new item
1283  PCBNEW_SELECTION preview;
1284  m_view->Add( &preview );
1285  m_view->Add( &twoPointAsst );
1286 
1287  m_controls->ShowCursor( true );
1288 
1289  bool started = false;
1290  bool cancelled = false;
1291  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
1292  VECTOR2I cursorPos = m_controls->GetMousePosition();
1293 
1294  // Prime the pump
1296 
1297  if( aStartingPoint )
1299 
1300  auto setCursor =
1301  [&]()
1302  {
1304  };
1305 
1306  // Set initial cursor
1307  setCursor();
1308 
1309  // Main loop: keep receiving events
1310  while( TOOL_EVENT* evt = Wait() )
1311  {
1312  setCursor();
1313 
1314  if( started )
1315  m_frame->SetMsgPanel( graphic );
1316 
1317  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1318  grid.SetUseGrid( m_frame->IsGridVisible() );
1319  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() );
1320  m_controls->ForceCursorPosition( true, cursorPos );
1321 
1322  // 45 degree angle constraint enabled with an option and toggled with Ctrl
1323  bool limit45 = frame()->Settings().m_Use45DegreeGraphicSegments;
1324 
1325  if( evt->Modifier( MD_CTRL ) )
1326  limit45 = !limit45;
1327 
1328  auto cleanup =
1329  [&]()
1330  {
1331  preview.Clear();
1332  m_view->Update( &preview );
1333  delete graphic;
1334  graphic = nullptr;
1335 
1336  if( !isLocalOriginSet )
1337  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1338  };
1339 
1340  if( evt->IsCancelInteractive() )
1341  {
1342  cleanup();
1343 
1344  if( !started )
1345  {
1346  m_frame->PopTool( aTool );
1347  cancelled = true;
1348  }
1349 
1350  break;
1351  }
1352  else if( evt->IsActivate() )
1353  {
1354  if( evt->IsPointEditor() )
1355  {
1356  // don't exit (the point editor runs in the background)
1357  }
1358  else if( evt->IsMoveTool() )
1359  {
1360  cleanup();
1361  // leave ourselves on the stack so we come back after the move
1362  cancelled = true;
1363  break;
1364  }
1365  else
1366  {
1367  cleanup();
1368  m_frame->PopTool( aTool );
1369  cancelled = true;
1370  break;
1371  }
1372  }
1373  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1374  {
1376  graphic->SetLayer( m_frame->GetActiveLayer() );
1377  graphic->SetWidth( m_lineWidth );
1378  m_view->Update( &preview );
1379  frame()->SetMsgPanel( graphic );
1380  }
1381  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1382  {
1383  if( started )
1384  {
1385  frame()->OnEditItemRequest( graphic );
1386  m_view->Update( &preview );
1387  frame()->SetMsgPanel( graphic );
1388  break;
1389  }
1390  else
1391  {
1392  evt->SetPassEvent();
1393  }
1394  }
1395  else if( evt->IsClick( BUT_RIGHT ) )
1396  {
1398  }
1399  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1400  {
1401  if( !started )
1402  {
1404 
1405  if( aStartingPoint )
1406  {
1407  cursorPos = aStartingPoint.get();
1408  aStartingPoint = NULLOPT;
1409  }
1410 
1412 
1413  // Init the new item attributes
1414  graphic->SetShape( (PCB_SHAPE_TYPE_T) shape );
1415  graphic->SetFilled( false );
1416  graphic->SetWidth( m_lineWidth );
1417  graphic->SetLayer( m_frame->GetActiveLayer() );
1418  grid.SetSkipPoint( cursorPos );
1419 
1420  twoPointManager.SetOrigin( (wxPoint) cursorPos );
1421  twoPointManager.SetEnd( (wxPoint) cursorPos );
1422 
1423  if( !isLocalOriginSet )
1424  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1425 
1426  preview.Add( graphic );
1427  frame()->SetMsgPanel( graphic );
1428  m_controls->SetAutoPan( true );
1429  m_controls->CaptureCursor( true );
1430 
1431  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1432 
1433  started = true;
1434  }
1435  else
1436  {
1437  PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
1438 
1439  if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
1440  || ( evt->IsDblClick( BUT_LEFT ) && shape == S_SEGMENT ) || snapItem )
1441  // User has clicked twice in the same spot
1442  // or clicked on the end of an existing segment (closing a path)
1443  {
1444  BOARD_COMMIT commit( m_frame );
1445 
1446  // If the user clicks on an existing snap point from a drawsegment
1447  // we finish the segment as they are likely closing a path
1448  if( snapItem && ( shape == S_RECT || graphic->GetLength() > 0.0 ) )
1449  {
1450  commit.Add( graphic );
1451  commit.Push( _( "Draw a line segment" ) );
1452  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, graphic );
1453  }
1454  else
1455  {
1456  delete graphic;
1457  }
1458 
1459  graphic = nullptr;
1460  }
1461 
1462  preview.Clear();
1463  twoPointManager.Reset();
1464  break;
1465  }
1466 
1467  twoPointManager.SetEnd( cursorPos );
1468  }
1469  else if( evt->IsMotion() )
1470  {
1471  // 45 degree lines
1472  if( started && ( ( limit45 && shape == S_SEGMENT )
1473  || ( evt->Modifier( MD_CTRL ) && shape == S_RECT ) ) )
1474  {
1475  const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
1476 
1477  // get a restricted 45/H/V line from the last fixed point to the cursor
1478  auto newEnd = GetVectorSnapped45( lineVector, ( shape == S_RECT ) );
1479  m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
1480  twoPointManager.SetEnd( twoPointManager.GetOrigin() + (wxPoint) newEnd );
1481  twoPointManager.SetAngleSnap( true );
1482  }
1483  else
1484  {
1485  twoPointManager.SetEnd( (wxPoint) cursorPos );
1486  twoPointManager.SetAngleSnap( false );
1487  }
1488 
1489  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1490  m_view->Update( &preview );
1491  m_view->Update( &twoPointAsst );
1492  }
1493  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1494  {
1496  graphic->SetWidth( m_lineWidth );
1497  m_view->Update( &preview );
1498  frame()->SetMsgPanel( graphic );
1499  }
1500  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1501  {
1503  graphic->SetWidth( m_lineWidth );
1504  m_view->Update( &preview );
1505  frame()->SetMsgPanel( graphic );
1506  }
1507  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1508  {
1509  isLocalOriginSet = true;
1510  evt->SetPassEvent();
1511  }
1512  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1513  {
1514  if( frame()->GetUserUnits() != userUnits )
1515  {
1516  userUnits = frame()->GetUserUnits();
1517  twoPointAsst.SetUnits( userUnits );
1518  m_view->Update( &twoPointAsst );
1519  }
1520  evt->SetPassEvent();
1521  }
1522  else
1523  {
1524  evt->SetPassEvent();
1525  }
1526  }
1527 
1528  if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before
1529  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1530 
1531  m_view->Remove( &twoPointAsst );
1532  m_view->Remove( &preview );
1533  m_frame->SetMsgPanel( board() );
1534 
1536  m_controls->SetAutoPan( false );
1537  m_controls->CaptureCursor( false );
1538  m_controls->ForceCursorPosition( false );
1539 
1540  return !cancelled;
1541 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
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:94
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
Represents an assistant draw when interactively drawing a line or circle on a canvas.
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 OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
usual segment : line with rounded ends
Definition: board_item.h:52
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
segment with non rounded ends
Definition: board_item.h:53
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
static void updateSegmentFromGeometryMgr(const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER &aMgr, PCB_SHAPE *aGraphic)
Update an PCB_SHAPE from the current state of a TWO_POINT_GEOMETRY_MANAGER.
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:171
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
bool m_Use45DegreeGraphicSegments
PCB_SHAPE_TYPE_T
Enum PCB_SHAPE_TYPE_T is the set of shapes for PCB graphics and tracks and footprint graphics in the ...
Definition: board_item.h:50
const PCBNEW_SELECTION & selection() const
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool IsGridVisible() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
unsigned int m_lineWidth
Definition: drawing_tool.h:232
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:227
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:229
EDA_UNITS
Definition: eda_units.h:38
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
static TOOL_ACTION updateUnits
Definition: actions.h:145
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
PCBNEW_SETTINGS & Settings()
static TOOL_ACTION resetLocalCoords
Definition: actions.h:148
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
ring
Definition: board_item.h:55
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:104
static TOOL_ACTION cursorClick
Definition: actions.h:121
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:89

References _, SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), ARROW, 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::GetActiveLayer(), PCB_BASE_FRAME::GetCanvas(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), PCB_BASE_FRAME::GetScreen(), getSegmentWidth(), EDA_BASE_FRAME::GetUserUnits(), GetVectorSnapped45(), PCB_ACTIONS::incWidth, EDA_DRAW_FRAME::IsGridVisible(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, BASE_SCREEN::m_LocalOrigin, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, PCBNEW_SETTINGS::m_Use45DegreeGraphicSegments, m_view, MD_CTRL, MD_SHIFT, NULLOPT, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PENCIL, TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), ACTIONS::resetLocalCoords, TOOL_MANAGER::RunAction(), S_CIRCLE, S_RECT, S_SEGMENT, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_BASE_FRAME::Settings(), KIGFX::PREVIEW::TWO_POINT_ASSISTANT::SetUnits(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), updateSegmentFromGeometryMgr(), ACTIONS::updateUnits, TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by DrawCircle(), DrawLine(), and DrawRectangle().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 2056 of file drawing_tool.cpp.

2057 {
2058  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
2059  {
2060  GRID_HELPER m_gridHelper;
2061 
2062  VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
2063  m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() )
2064  {}
2065 
2066  virtual ~VIA_PLACER()
2067  {
2068  }
2069 
2070  TRACK* findTrack( VIA* aVia )
2071  {
2072  const LSET lset = aVia->GetLayerSet();
2073  wxPoint position = aVia->GetPosition();
2074  BOX2I bbox = aVia->GetBoundingBox();
2075 
2076  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2077  auto view = m_frame->GetCanvas()->GetView();
2078  std::vector<TRACK*> possible_tracks;
2079 
2080  view->Query( bbox, items );
2081 
2082  for( auto it : items )
2083  {
2084  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
2085 
2086  if( !(item->GetLayerSet() & lset ).any() )
2087  continue;
2088 
2089  if( auto track = dyn_cast<TRACK*>( item ) )
2090  {
2091  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
2092  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
2093  possible_tracks.push_back( track );
2094  }
2095  }
2096 
2097  TRACK* return_track = nullptr;
2098  int min_d = std::numeric_limits<int>::max();
2099  for( auto track : possible_tracks )
2100  {
2101  SEG test( track->GetStart(), track->GetEnd() );
2102  auto dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
2103 
2104  if( dist < min_d )
2105  {
2106  min_d = dist;
2107  return_track = track;
2108  }
2109  }
2110 
2111  return return_track;
2112  }
2113 
2114 
2115  bool hasDRCViolation( VIA* aVia )
2116  {
2117  const LSET lset = aVia->GetLayerSet();
2118  wxPoint position = aVia->GetPosition();
2119  int drillRadius = aVia->GetDrillValue() / 2;
2120  BOX2I bbox = aVia->GetBoundingBox();
2121 
2122  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2123  int net = 0;
2124  int clearance = 0;
2125  auto view = m_frame->GetCanvas()->GetView();
2126  int holeToHoleMin = m_frame->GetBoard()->GetDesignSettings().m_HoleToHoleMin;
2127 
2128  view->Query( bbox, items );
2129 
2130  for( auto it : items )
2131  {
2132  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
2133 
2134  if( !(item->GetLayerSet() & lset ).any() )
2135  continue;
2136 
2137  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2138  {
2139  int max_clearance = std::max( clearance,
2140  track->GetOwnClearance( track->GetLayer() ) );
2141 
2142  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
2143  ( track->GetWidth() + aVia->GetWidth() ) / 2 + max_clearance ) )
2144  {
2145  if( net && track->GetNetCode() != net )
2146  return true;
2147 
2148  net = track->GetNetCode();
2149  clearance = track->GetOwnClearance( track->GetLayer() );
2150  }
2151  }
2152 
2153  if( VIA* via = dyn_cast<VIA*>( item ) )
2154  {
2155  int dist = KiROUND( GetLineLength( position, via->GetPosition() ) );
2156 
2157  if( dist < drillRadius + via->GetDrillValue() / 2 + holeToHoleMin )
2158  return true;
2159  }
2160 
2161  if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
2162  {
2163  for( PAD* pad : footprint->Pads() )
2164  {
2165  for( PCB_LAYER_ID layer : pad->GetLayerSet().Seq() )
2166  {
2167  int max_clearance = std::max( clearance, pad->GetOwnClearance( layer ) );
2168 
2169  if( pad->HitTest( aVia->GetBoundingBox(), false, max_clearance ) )
2170  {
2171  if( net && pad->GetNetCode() != net )
2172  return true;
2173 
2174  net = pad->GetNetCode();
2175  clearance = pad->GetOwnClearance( layer );
2176  }
2177 
2178  if( pad->GetDrillSize().x && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
2179  {
2180  int dist = KiROUND( GetLineLength( position, pad->GetPosition() ) );
2181 
2182  if( dist < drillRadius + pad->GetDrillSize().x / 2 + holeToHoleMin )
2183  return true;
2184  }
2185  }
2186  }
2187  }
2188  }
2189 
2190  return false;
2191  }
2192 
2193 
2194  int findStitchedZoneNet( VIA* aVia )
2195  {
2196  const wxPoint position = aVia->GetPosition();
2197  const LSET lset = aVia->GetLayerSet();
2198 
2199  for( FOOTPRINT* footprint : m_board->Footprints() )
2200  {
2201  for( PAD* pad : footprint->Pads() )
2202  {
2203  if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
2204  return -1;
2205  }
2206  }
2207 
2208  std::vector<ZONE*> foundZones;
2209 
2210  for( ZONE* zone : m_board->Zones() )
2211  {
2212  for( PCB_LAYER_ID layer : LSET( zone->GetLayerSet() & lset ).Seq() )
2213  {
2214  if( zone->HitTestFilledArea( layer, position ) )
2215  foundZones.push_back( zone );
2216  }
2217  }
2218 
2219  std::sort( foundZones.begin(), foundZones.end(),
2220  [] ( const ZONE* a, const ZONE* b )
2221  {
2222  return a->GetLayer() < b->GetLayer();
2223  } );
2224 
2225  // first take the net of the active layer
2226  for( ZONE* z : foundZones )
2227  {
2228  if( m_frame->GetActiveLayer() == z->GetLayer() )
2229  return z->GetNetCode();
2230  }
2231 
2232  // none? take the topmost visible layer
2233  for( ZONE* z : foundZones )
2234  {
2235  if( m_board->IsLayerVisible( z->GetLayer() ) )
2236  return z->GetNetCode();
2237  }
2238 
2239  return -1;
2240  }
2241 
2242  void SnapItem( BOARD_ITEM *aItem ) override
2243  {
2244  // If you place a Via on a track but not on its centerline, the current
2245  // connectivity algorithm will require us to put a kink in the track when
2246  // we break it (so that each of the two segments ends on the via center).
2247  // That's not ideal, and is in fact probably worse than forcing snap in
2248  // this situation.
2249 
2250  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
2251  auto via = static_cast<VIA*>( aItem );
2252  wxPoint position = via->GetPosition();
2253  TRACK* track = findTrack( via );
2254 
2255  if( track )
2256  {
2257  SEG trackSeg( track->GetStart(), track->GetEnd() );
2258  VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
2259 
2260  aItem->SetPosition( (wxPoint) snap );
2261  }
2262  }
2263 
2264  bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
2265  {
2266  VIA* via = static_cast<VIA*>( aItem );
2267  wxPoint viaPos = via->GetPosition();
2268  int newNet;
2269  TRACK* track = findTrack( via );
2270 
2271  if( hasDRCViolation( via ) )
2272  return false;
2273 
2274  if( track )
2275  {
2276  if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
2277  {
2278  aCommit.Modify( track );
2279 
2280  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
2281  const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
2282 
2283  track->SetEnd( viaPos );
2284  newTrack->SetStart( viaPos );
2285  aCommit.Add( newTrack );
2286  }
2287 
2288  newNet = track->GetNetCode();
2289  }
2290  else
2291  newNet = findStitchedZoneNet( via );
2292 
2293  if( newNet > 0 )
2294  via->SetNetCode( newNet );
2295 
2296  aCommit.Add( aItem );
2297  return true;
2298  }
2299 
2300  std::unique_ptr<BOARD_ITEM> CreateItem() override
2301  {
2302  auto& ds = m_board->GetDesignSettings();
2303  VIA* via = new VIA( m_board );
2304 
2305  via->SetNetCode( 0 );
2306  via->SetViaType( ds.m_CurrentViaType );
2307 
2308  // for microvias, the size and hole will be changed later.
2309  via->SetWidth( ds.GetCurrentViaSize() );
2310  via->SetDrill( ds.GetCurrentViaDrill() );
2311 
2312  // Usual via is from copper to component.
2313  // layer pair is B_Cu and F_Cu.
2314  via->SetLayerPair( B_Cu, F_Cu );
2315 
2316  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
2317  PCB_LAYER_ID last_layer;
2318 
2319  // prepare switch to new active layer:
2320  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
2321  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
2322  else
2323  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
2324 
2325  // Adjust the actual via layer pair
2326  switch( via->GetViaType() )
2327  {
2328  case VIATYPE::BLIND_BURIED:
2329  via->SetLayerPair( first_layer, last_layer );
2330  break;
2331 
2332  case VIATYPE::MICROVIA: // from external to the near neighbor inner layer
2333  {
2334  PCB_LAYER_ID last_inner_layer =
2335  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
2336 
2337  if( first_layer == B_Cu )
2338  last_layer = last_inner_layer;
2339  else if( first_layer == F_Cu )
2340  last_layer = In1_Cu;
2341  else if( first_layer == last_inner_layer )
2342  last_layer = B_Cu;
2343  else if( first_layer == In1_Cu )
2344  last_layer = F_Cu;
2345 
2346  // else error: will be removed later
2347  via->SetLayerPair( first_layer, last_layer );
2348 
2349  // Update diameter and hole size, which where set previously
2350  // for normal vias
2351  NETINFO_ITEM* net = via->GetNet();
2352 
2353  if( net )
2354  {
2355  via->SetWidth( net->GetMicroViaSize() );
2356  via->SetDrill( net->GetMicroViaDrillSize() );
2357  }
2358  }
2359  break;
2360 
2361  default:
2362  break;
2363  }
2364 
2365  return std::unique_ptr<BOARD_ITEM>( via );
2366  }
2367  };
2368 
2369  VIA_PLACER placer( frame() );
2370 
2371  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
2372 
2373  doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
2375 
2376  return 0;
2377 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:134
Definition: track.h:354
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)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:209
ZONES & Zones()
Definition: board.h:289
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: track.cpp:363
BOARD * m_board
Definition: drawing_tool.h:228
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:326
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
void SetEnd(const wxPoint &aEnd)
Definition: track.h:112
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: track.h:116
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: track.cpp:217
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: track.cpp:50
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:559
PADS & Pads()
Definition: footprint.h:182
void SetWidth(int aWidth)
Definition: track.h:109
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
Definition: kiid.h:44
PCB_LAYER_ID
A quick note on layer IDs:
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 ...
Definition: track.cpp:170
Allow repeat placement of the item.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: zone.cpp:215
FOOTPRINTS & Footprints()
Definition: board.h:283
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:39
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.
Definition: track.cpp:401
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
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:229
void SetSnap(bool aSnap)
Definition: grid_helper.h:82
const KIID m_Uuid
Definition: eda_item.h:151
Definition: seg.h:39
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:443
int GetWidth() const
Definition: track.h:110
Common, abstract interface for edit frames.
#define _(s)
Definition: 3d_actions.cpp:33
int GetCopperLayerCount() const
Definition: board.cpp:425
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: track.h:485
VIATYPE GetViaType() const
Definition: track.h:384
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const wxPoint & GetEnd() const
Definition: track.h:113
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:188
void SetStart(const wxPoint &aStart)
Definition: track.h:115
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:433
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
Definition: pad.h:59
wxPoint GetPosition() const override
Definition: track.h:422
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:168
void SetViaType(VIATYPE aViaType)
Definition: track.h:385
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:898
Definition: track.h:83
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:38
virtual LSET GetLayerSet() const
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:191

References _, COMMIT::Add(), GRID_HELPER::AlignToSegment(), B_Cu, BLIND_BURIED, TRACK::Clone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EuclideanNorm(), F_Cu, PCB_TOOL_BASE::footprint(), BOARD::Footprints(), 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::GetLayer(), BOARD_ITEM::GetLayerSet(), VIA::GetLayerSet(), GetLineLength(), PCB_BASE_FRAME::GetMagneticItemsSettings(), NETINFO_ITEM::GetMicroViaDrillSize(), NETINFO_ITEM::GetMicroViaSize(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetCode(), VIA::GetPosition(), PCB_BASE_FRAME::GetScreen(), TRACK::GetStart(), TOOLS_HOLDER::GetToolManager(), 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, EDA_ITEM::m_Uuid, MD_SHIFT, MICROVIA, COMMIT::Modify(), PAD_DRILL_SHAPE_CIRCLE, FOOTPRINT::Pads(), KIGFX::VIEW::Query(), VIA::SetDrill(), TRACK::SetEnd(), VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), EDA_ITEM::SetPosition(), GRID_HELPER::SetSnap(), TRACK::SetStart(), VIA::SetViaType(), TRACK::SetWidth(), TestSegmentHit(), ToLAYER_ID(), VIA, 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 1822 of file drawing_tool.cpp.

1823 {
1824  if( m_isFootprintEditor && !m_frame->GetModel() )
1825  return 0;
1826 
1827  ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
1828  MODE drawMode = MODE::ZONE;
1829 
1830  if( aEvent.IsAction( &PCB_ACTIONS::drawRuleArea ) )
1831  drawMode = MODE::KEEPOUT;
1832 
1833  if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
1834  drawMode = MODE::GRAPHIC_POLYGON;
1835 
1836  SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
1837 
1838  // get a source zone, if we need one. We need it for:
1839  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1840  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1841  ZONE* sourceZone = nullptr;
1842 
1843  if( !getSourceZoneForAction( zoneMode, &sourceZone ) )
1844  return 0;
1845 
1846  // Turn zones on if they are off, so that the created object will be visible after completion
1848 
1850 
1851  params.m_keepout = drawMode == MODE::KEEPOUT;
1852  params.m_mode = zoneMode;
1853  params.m_sourceZone = sourceZone;
1854 
1855  if( zoneMode == ZONE_MODE::SIMILAR )
1856  params.m_layer = sourceZone->GetLayer();
1857  else
1858  params.m_layer = m_frame->GetActiveLayer();
1859 
1860  ZONE_CREATE_HELPER zoneTool( *this, params );
1861 
1862  // the geometry manager which handles the zone geometry, and
1863  // hands the calculated points over to the zone creator tool
1864  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1865  bool constrainAngle = false;
1866 
1867  std::string tool = aEvent.GetCommandStr().get();
1868  m_frame->PushTool( tool );
1869  Activate(); // register for events
1870 
1871  m_controls->ShowCursor( true );
1872 
1873  bool started = false;
1875  STATUS_TEXT_POPUP status( m_frame );
1876  status.SetTextColor( wxColour( 255, 0, 0 ) );
1877  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
1878 
1879  // Prime the pump
1880  if( aEvent.HasPosition() )
1881  m_toolMgr->PrimeTool( aEvent.Position() );
1882 
1883  auto setCursor =
1884  [&]()
1885  {
1887  };
1888 
1889  // Set initial cursor
1890  setCursor();
1891 
1892  // Main loop: keep receiving events
1893  while( TOOL_EVENT* evt = Wait() )
1894  {
1895  setCursor();
1896 
1897  LSET layers( m_frame->GetActiveLayer() );
1898  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1899  grid.SetUseGrid( m_frame->IsGridVisible() );
1900  VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position()
1902  layers );
1903  m_controls->ForceCursorPosition( true, cursorPos );
1904 
1905  if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || evt->Modifier( MD_CTRL ) )
1906  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
1907  else
1908  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
1909 
1910  auto cleanup =
1911  [&] ()
1912  {
1913  polyGeomMgr.Reset();
1914  started = false;
1915  grid.ClearSkipPoint();
1916  m_controls->SetAutoPan( false );
1917  m_controls->CaptureCursor( false );
1918  };
1919 
1920  if( evt->IsCancelInteractive() )
1921  {
1922  if( polyGeomMgr.IsPolygonInProgress() )
1923  cleanup();
1924  else
1925  {
1926  m_frame->PopTool( tool );
1927  break;
1928  }
1929  }
1930  else if( evt->IsActivate() )
1931  {
1932  if( polyGeomMgr.IsPolygonInProgress() )
1933  cleanup();
1934 
1935  if( evt->IsPointEditor() )
1936  {
1937  // don't exit (the point editor runs in the background)
1938  }
1939  else if( evt->IsMoveTool() )
1940  {
1941  // leave ourselves on the stack so we come back after the move
1942  break;
1943  }
1944  else
1945  {
1946  m_frame->PopTool( tool );
1947  break;
1948  }
1949  }
1950  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1951  {
1952  if( zoneMode != ZONE_MODE::SIMILAR )
1953  params.m_layer = frame()->GetActiveLayer();
1954  }
1955  else if( evt->IsClick( BUT_RIGHT ) )
1956  {
1958  }
1959  // events that lock in nodes
1960  else if( evt->IsClick( BUT_LEFT )
1961  || evt->IsDblClick( BUT_LEFT )
1962  || evt->IsAction( &PCB_ACTIONS::closeOutline ) )
1963  {
1964  // Check if it is double click / closing line (so we have to finish the zone)
1965  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
1966  || evt->IsAction( &PCB_ACTIONS::closeOutline )
1967  || polyGeomMgr.NewPointClosesOutline( cursorPos );
1968 
1969  if( endPolygon )
1970  {
1971  polyGeomMgr.SetFinished();
1972  polyGeomMgr.Reset();
1973 
1974  started = false;
1975  m_controls->SetAutoPan( false );
1976  m_controls->CaptureCursor( false );
1977  }
1978  // adding a corner
1979  else if( polyGeomMgr.AddPoint( cursorPos ) )
1980  {
1981  if( !started )
1982  {
1983  started = true;
1984  constrainAngle = ( polyGeomMgr.GetLeaderMode() ==
1986  m_controls->SetAutoPan( true );
1987  m_controls->CaptureCursor( true );
1988  }
1989  }
1990  }
1991  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1992  {
1993  polyGeomMgr.DeleteLastCorner();
1994 
1995  if( !polyGeomMgr.IsPolygonInProgress() )
1996  {
1997  // report finished as an empty shape
1998  polyGeomMgr.SetFinished();
1999 
2000  // start again
2001  started = false;
2002  m_controls->SetAutoPan( false );
2003  m_controls->CaptureCursor( false );
2004  }
2005  }
2006  else if( polyGeomMgr.IsPolygonInProgress()
2007  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
2008  {
2009  polyGeomMgr.SetCursorPosition( cursorPos );
2010 
2011  if( polyGeomMgr.IsSelfIntersecting( true ) )
2012  {
2013  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
2014  status.Move( p );
2015  status.PopupFor( 1500 );
2016  }
2017  else
2018  {
2019  status.Hide();
2020  }
2021  }
2022  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
2023  {
2024  if( started )
2025  {
2026  frame()->OnEditItemRequest( zoneTool.GetZone() );
2027  zoneTool.OnGeometryChange( polyGeomMgr );
2028  frame()->SetMsgPanel( zoneTool.GetZone() );
2029  }
2030  else
2031  {
2032  evt->SetPassEvent();
2033  }
2034  }
2035  /*else if( evt->IsAction( &ACTIONS::updateUnits ) )
2036  {
2037  // If we ever have an assistant here that reports dimensions, we'll want to
2038  // update its units here....
2039  // zoneAsst.SetUnits( frame()->GetUserUnits() );
2040  // m_view->Update( &zoneAsst );
2041  evt->SetPassEvent();
2042  }*/
2043  else
2044  {
2045  evt->SetPassEvent();
2046  }
2047 
2048  } // end while
2049 
2051  m_controls->ForceCursorPosition( false );
2052  return 0;
2053 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
void SetObjectVisible(GAL_LAYER_ID aLayer, bool aVisible=true)
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.
ZONE * m_sourceZone
Zone settings source (for similar and cutout zones)
Control for copper zone opacity/visibility (color ignored)
STATUS_TEXT_POPUP.
Definition: status_popup.h:82
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 OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
PCB_LAYER_ID m_layer
Layer to begin drawing
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:146
void PrimeTool(const VECTOR2D &aPosition)
Function PrimeTool() "Primes" a tool by sending a cursor left-click event with the mouse position set...
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
Parameters used to fully describe a zone creation process.
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
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:67
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
Unconstrained point-to-point
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
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool IsGridVisible() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: zone.cpp:215
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
TOOL_EVENT.
Definition: tool_event.h:171
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:227
bool m_isFootprintEditor
bool GetHV45() const
Definition: zone.h:817
ZONE_MODE
Definition: pcb_actions.h:36
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:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:63
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE **aZone)
Draws a polygon, that is added as a zone or a keepout area.
static TOOL_ACTION drawRuleArea
Definition: pcb_actions.h:157
#define _(s)
Definition: 3d_actions.cpp:33
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
void Activate()
Function Activate() Runs the tool.
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:260
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...
const VECTOR2D Position() const
Returns mouse cursor position in world coordinates.
Definition: tool_event.h:274
ZONE_MODE m_mode
The zone mode to operate in
static TOOL_ACTION closeOutline
Definition: pcb_actions.h:165

References _, TOOL_INTERACTIVE::Activate(), POLYGON_GEOM_MANAGER::AddPoint(), ARROW, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_ACTIONS::closeOutline, POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), PCB_ACTIONS::deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawRuleArea, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), ZONE::GetHV45(), ZONE::GetLayer(), POLYGON_GEOM_MANAGER::GetLeaderMode(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSourceZoneForAction(), ZONE_CREATE_HELPER::GetZone(), GRAPHIC_POLYGON, TOOL_EVENT::HasPosition(), TOOL_EVENT::IsAction(), EDA_DRAW_FRAME::IsGridVisible(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), KEEPOUT, LAYER_ZONES, PCB_ACTIONS::layerChanged, m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, 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_CTRL, MD_SHIFT, POLYGON_GEOM_MANAGER::NewPointClosesOutline(), PCB_BASE_EDIT_FRAME::OnEditItemRequest(), ZONE_CREATE_HELPER::OnGeometryChange(), TOOL_EVENT::Parameter(), PENCIL, TOOLS_HOLDER::PopTool(), TOOL_EVENT::Position(), TOOL_MANAGER::PrimeTool(), PCB_ACTIONS::properties, TOOLS_HOLDER::PushTool(), POLYGON_GEOM_MANAGER::Reset(), PCB_TOOL_BASE::selection(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), POLYGON_GEOM_MANAGER::SetCursorPosition(), POLYGON_GEOM_MANAGER::SetFinished(), POLYGON_GEOM_MANAGER::SetLeaderMode(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_BASE_EDIT_FRAME::SetObjectVisible(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), SIMILAR, TOOL_INTERACTIVE::Wait(), and ZONE.

Referenced by setTransitions().

◆ footprint()

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 155 of file pcb_tool_base.h.

156  {
157  return getEditFrame<PCB_BASE_EDIT_FRAME>();
158  }

Referenced by POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_TOOLS::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawVia(), DrawZone(), PAD_TOOL::EditPad(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), PCB_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), FOOTPRINT_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_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::MoveExact(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), GROUP_TOOL::PickNewMember(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), PAD_TOOL::recombinePad(), 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(), PCB_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ 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 227 of file drawing_tool.cpp.

228 {
229  return m_mode;
230 }

References m_mode.

Referenced by 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*>( getToolHolderInt() ) );
191 #endif
192  return static_cast<T*>( getToolHolderInt() );
193  }
TOOLS_HOLDER * getToolHolderInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getToolHolderInt().

Referenced by ZONE_CREATE_HELPER::createNewZone().

◆ 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(), TOOL_MANAGER::saveViewControls(), and TOOL_MANAGER::ShutdownTool().

◆ 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
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148

References TOOL_BASE::getModelInt().

Referenced by ZONE_CREATE_HELPER::commitZone(), 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_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 2380 of file drawing_tool.cpp.

2381 {
2382  assert( m_board );
2383  return m_board->GetDesignSettings().GetLineThickness( aLayer );
2384 }
BOARD * m_board
Definition: drawing_tool.h:228
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:559
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().

◆ getSourceZoneForAction()

bool DRAWING_TOOL::getSourceZoneForAction ( ZONE_MODE  aMode,
ZONE **  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 1788 of file drawing_tool.cpp.

1789 {
1790  bool clearSelection = false;
1791  *aZone = nullptr;
1792 
1793  // not an action that needs a source zone
1794  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1795  return true;
1796 
1798  const PCBNEW_SELECTION& selection = selTool->GetSelection();
1799 
1800  if( selection.Empty() )
1801  {
1802  clearSelection = true;
1804  }
1805 
1806  // we want a single zone
1807  if( selection.Size() == 1 )
1808  *aZone = dyn_cast<ZONE*>( selection[0] );
1809 
1810  // expected a zone, but didn't get one
1811  if( !*aZone )
1812  {
1813  if( clearSelection )
1815 
1816  return false;
1817  }
1818 
1819  return true;
1820 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
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:141
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:120
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:59

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(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::ShutdownTool().

◆ 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:290
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(), SCH_EDIT_TOOL::ChangeTextType(), EE_INSPECTION_TOOL::CheckSymbol(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::collectHits(), SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint(), 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(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), MICROWAVE_TOOL::drawMicrowaveInductor(), PL_DRAWING_TOOLS::DrawShape(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_EDITOR_CONTROL::FindComponentAndItem(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), 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(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), PL_EDIT_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), 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(), GERBVIEW_SELECTION_TOOL::selectable(), SELECTION_TOOL::Selectable(), SELECTION_TOOL::SelectAll(), EE_SELECTION_TOOL::SelectAll(), 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(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), 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(), PL_POINT_EDITOR::updateItem(), POINT_EDITOR::updateItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCB_VIEWER_TOOLS::view(), PCB_TOOL_BASE::view(), 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:292

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDITOR_CONTROL::AssignNetclass(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), EDIT_TOOL::copyToClipboard(), SCH_DRAWING_TOOLS::createSheetPin(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), DrawCircle(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DrawRectangle(), 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(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), FOOTPRINT_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), 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::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), 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(), POINT_EDITOR::updateItem(), 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 ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), PCB_REANNOTATE_TOOL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), LIB_PIN_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), DRC_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), POINT_EDITOR::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), PAD_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), PL_EDIT_TOOL::setTransitions(), FOOTPRINT_EDITOR_TOOLS::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), setTransitions(), EDIT_TOOL::setTransitions(), SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ Init()

bool DRAWING_TOOL::Init ( void  )
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 159 of file drawing_tool.cpp.

160 {
161  auto activeToolFunctor = [this]( const SELECTION& aSel )
162  {
163  return m_mode != MODE::NONE;
164  };
165 
166  // some interactive drawing tools can undo the last point
167  auto canUndoPoint = [this]( const SELECTION& aSel )
168  {
169  return ( m_mode == MODE::ARC
170  || m_mode == MODE::ZONE
171  || m_mode == MODE::KEEPOUT
173  };
174 
175  // functor for tools that can automatically close the outline
176  auto canCloseOutline = [this]( const SELECTION& aSel )
177  {
178  return ( m_mode == MODE::ZONE
179  || m_mode == MODE::KEEPOUT
181  };
182 
183  auto viaToolActive = [this]( const SELECTION& aSel )
184  {
185  return m_mode == MODE::VIA;
186  };
187 
188  auto& ctxMenu = m_menu.GetMenu();
189 
190  // cancel current tool goes in main context menu at the top if present
191  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
192  ctxMenu.AddSeparator( 1 );
193 
194  // tool-specific actions
195  ctxMenu.AddItem( PCB_ACTIONS::closeOutline, canCloseOutline, 200 );
196  ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
197 
198  ctxMenu.AddSeparator( 500 );
199 
200  std::shared_ptr<VIA_SIZE_MENU> viaSizeMenu = std::make_shared<VIA_SIZE_MENU>();
201  viaSizeMenu->SetTool( this );
202  m_menu.AddSubMenu( viaSizeMenu );
203  ctxMenu.AddMenu( viaSizeMenu.get(), viaToolActive, 500 );
204 
205  ctxMenu.AddSeparator( 500 );
206 
207  // Type-specific sub-menus will be added for us by other tools
208  // For example, zone fill/unfill is provided by the PCB control tool
209 
210  // Finally, add the standard zoom/grid items
211  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
212 
213  return true;
214 }
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
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:164
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Adds a menu entry to run a TOOL_ACTION on selected items.
static TOOL_ACTION closeOutline
Definition: pcb_actions.h:165

References CONDITIONAL_MENU::AddItem(), TOOL_MENU::AddSubMenu(), ARC, ACTIONS::cancelInteractive, PCB_ACTIONS::closeOutline, PCB_ACTIONS::deleteLastPoint, TOOL_MENU::GetMenu(), GRAPHIC_POLYGON, KEEPOUT, TOOL_INTERACTIVE::m_menu, m_mode, NONE, VIA, and ZONE.

◆ IsFootprintEditor()

bool PCB_TOOL_BASE::IsFootprintEditor ( ) const
inlineinherited

◆ 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.

Referenced by EDIT_TOOL::isRouterActive(), and ROUTER_TOOL::onViaCommand().

◆ PlaceImportedGraphics()

int DRAWING_TOOL::PlaceImportedGraphics ( const TOOL_EVENT aEvent)

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

Definition at line 996 of file drawing_tool.cpp.

997 {
998  if( !m_frame->GetModel() )
999  return 0;
1000 
1001  // Note: PlaceImportedGraphics() will convert PCB_SHAPE_T and PCB_TEXT_T to footprint
1002  // items if needed
1004  int dlgResult = dlg.ShowModal();
1005 
1006  std::list<std::unique_ptr<EDA_ITEM>>& list = dlg.GetImportedItems();
1007 
1008  if( dlgResult != wxID_OK )
1009  return 0;
1010 
1011  // Ensure the list is not empty:
1012  if( list.empty() )
1013  {
1014  wxMessageBox( _( "No graphic items found in file to import") );
1015  return 0;
1016  }
1017 
1019 
1020  // Add a VIEW_GROUP that serves as a preview for the new item
1021  PCBNEW_SELECTION preview;
1022  BOARD_COMMIT commit( m_frame );
1023  PCB_GROUP* grp = nullptr;
1024 
1025  if( dlg.ShouldGroupItems() )
1026  {
1027  if( m_isFootprintEditor )
1028  grp = new PCB_GROUP( m_frame->GetBoard()->GetFirstFootprint() );
1029  else
1030  grp = new PCB_GROUP( m_frame->GetBoard() );
1031  }
1032 
1033  // Build the undo list & add items to the current view
1034  for( auto& ptr : list)
1035  {
1036  EDA_ITEM* item = ptr.get();
1037 
1038  if( m_isFootprintEditor )
1039  wxASSERT( item->Type() == PCB_FP_SHAPE_T || item->Type() == PCB_FP_TEXT_T );
1040  else
1041  wxASSERT( item->Type() == PCB_SHAPE_T || item->Type() == PCB_TEXT_T );
1042 
1043  if( grp )
1044  grp->AddItem( static_cast<BOARD_ITEM*>( item ) );
1045  else if( dlg.IsPlacementInteractive() )
1046  preview.Add( item );
1047  else
1048  commit.Add( item );
1049 
1050  ptr.release();
1051  }
1052 
1053  if( !dlg.IsPlacementInteractive() )
1054  {
1055  if( grp )
1056  {
1057  grp->AddChildrenToCommit( commit );
1058  commit.Add( grp );
1059  }
1060 
1061  commit.Push( _( "Place a DXF_SVG drawing" ) );
1062  return 0;
1063  }
1064 
1065  if( grp )
1066  preview.Add( grp );
1067 
1068  std::vector<BOARD_ITEM*> newItems;
1069 
1070  for( EDA_ITEM* item : preview )
1071  newItems.push_back( static_cast<BOARD_ITEM*>( item ) );
1072 
1073  BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
1074  m_view->Add( &preview );
1075 
1076  // Clear the current selection then select the drawings so that edit tools work on them
1078  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems );
1079 
1080  m_controls->ShowCursor( true );
1081  m_controls->ForceCursorPosition( false );
1082 
1083  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
1084 
1085  // Now move the new items to the current cursor position:
1086  VECTOR2I cursorPos = m_controls->GetCursorPosition();
1087  VECTOR2I delta = cursorPos - firstItem->GetPosition();
1088 
1089  for( EDA_ITEM* item : preview )
1090  static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
1091 
1092  m_view->Update( &preview );
1093 
1094  std::string tool = aEvent.GetCommandStr().get();
1095  m_frame->PushTool( tool );
1096  Activate();
1097 
1098  auto setCursor =
1099  [&]()
1100  {
1102  };
1103 
1104  // Set initial cursor
1105  setCursor();
1106 
1107  // Main loop: keep receiving events
1108  while( TOOL_EVENT* evt = Wait() )
1109  {
1110  setCursor();
1111  cursorPos = m_controls->GetCursorPosition();
1112 
1113  if( evt->IsCancelInteractive() || evt->IsActivate() )
1114  {
1116 
1117  // If a group is being used, we must delete the items themselves,
1118  // since they are only in the group and not in the preview
1119  if( grp )
1120  {
1121  grp->RunOnChildren( [&]( BOARD_ITEM* bItem )
1122  {
1123  delete bItem ;
1124  } );
1125  }
1126 
1127  preview.FreeItems();
1128  break;
1129  }
1130  else if( evt->IsMotion() )
1131  {
1132  delta = cursorPos - firstItem->GetPosition();
1133 
1134  for( auto item : preview )
1135  static_cast<BOARD_ITEM*>( item )->Move( (wxPoint) delta );
1136 
1137  m_view->Update( &preview );
1138  }
1139  else if( evt->IsClick( BUT_RIGHT ) )
1140  {
1142  }
1143  else if( evt->IsClick( BUT_LEFT ) )
1144  {
1145  // Place the imported drawings
1146  for( EDA_ITEM* item : preview )
1147  {
1148  if( item->Type() == PCB_GROUP_T )
1149  static_cast<PCB_GROUP*>( item )->AddChildrenToCommit( commit );
1150 
1151  commit.Add( item );
1152  }
1153 
1154  commit.Push( _( "Place a DXF_SVG drawing" ) );
1155  break; // This is a one-shot command, not a tool
1156  }
1157  else
1158  {
1159  evt->SetPassEvent();
1160  }
1161  }
1162 
1163  preview.Clear();
1164  m_view->Remove( &preview );
1165 
1167  m_frame->PopTool( tool );
1168  return 0;
1169 }
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:69
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
bool AddItem(BOARD_ITEM *aItem)
Adds item to group.
Definition: pcb_group.cpp:38
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
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 PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
void AddChildrenToCommit(BOARD_COMMIT &aCommit) const
Add all the immediate children of this group to the board commit.
Definition: pcb_group.h:181
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:348
virtual void PopTool(const std::string &actionName)
TOOL_EVENT.
Definition: tool_event.h:171
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:227
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invokes a function on all members of the group.
Definition: pcb_group.cpp:313
void Activate()
Function Activate() Runs the tool.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
BOARD * GetBoard() const
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), PCB_GROUP::AddChildrenToCommit(), PCB_GROUP::AddItem(), ARROW, BUT_LEFT, BUT_RIGHT, ACTIONS::cancelInteractive, DXF, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), BOARD::GetFirstFootprint(), DIALOG_IMPORT_GFX::GetImportedItems(), PCB_BASE_FRAME::GetModel(), EDA_ITEM::GetPosition(), DIALOG_IMPORT_GFX::IsPlacementInteractive(), m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MOVING, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_GROUP_T, PCB_SHAPE_T, PCB_TEXT_T, TOOLS_HOLDER::PopTool(), BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_GROUP::RunOnChildren(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItems, EDA_DRAW_PANEL_GAL::SetCurrentCursor(), DIALOG_IMPORT_GFX::ShouldGroupItems(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), 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 412 of file drawing_tool.cpp.

413 {
415  return 0;
416 
417  BOARD_ITEM* text = NULL;
418  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
419  BOARD_COMMIT commit( m_frame );
420 
422  m_controls->ShowCursor( true );
423  // do not capture or auto-pan until we start placing some text
424 
425  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
426 
427  std::string tool = aEvent.GetCommandStr().get();
428  m_frame->PushTool( tool );
429  Activate();
430 
431  // Prime the pump
432  if( aEvent.HasPosition() )
434 
435  auto setCursor =
436  [&]()
437  {
438  if( text )
440  else
442  };
443 
444  // Set initial cursor
445  setCursor();
446 
447  // Main loop: keep receiving events
448  while( TOOL_EVENT* evt = Wait() )
449  {
450  setCursor();
451  VECTOR2I cursorPos = m_controls->GetCursorPosition();
452 
453  auto cleanup =
454  [&]()
455  {
458  m_controls->ShowCursor( true );
459  m_controls->SetAutoPan( false );
460  m_controls->CaptureCursor( false );
461  delete text;
462  text = NULL;
463  };
464 
465  if( evt->IsCancelInteractive() )
466  {
467  if( text )
468  cleanup();
469  else
470  {
471  m_frame->PopTool( tool );
472  break;
473  }
474  }
475  else if( evt->IsActivate() )
476  {
477  if( text )
478  cleanup();
479 
480  if( evt->IsMoveTool() )
481  {
482  // leave ourselves on the stack so we come back after the move
483  break;
484  }
485  else
486  {
487  m_frame->PopTool( tool );
488  break;
489  }
490  }
491  else if( evt->IsClick( BUT_RIGHT ) )
492  {
494  }
495  else if( evt->IsClick( BUT_LEFT ) )
496  {
497  bool placing = text != nullptr;
498 
499  if( !text )
500  {
502 
505 
506  // Init the new item attributes
507  if( m_isFootprintEditor )
508  {
509  FP_TEXT* fpText = new FP_TEXT( (FOOTPRINT*) m_frame->GetModel() );
510 
511  fpText->SetLayer( layer );
512  fpText->SetTextSize( dsnSettings.GetTextSize( layer ) );
513  fpText->SetTextThickness( dsnSettings.GetTextThickness( layer ) );
514  fpText->SetItalic( dsnSettings.GetTextItalic( layer ) );
515  fpText->SetKeepUpright( dsnSettings.GetTextUpright( layer ) );
516  fpText->SetTextPos( (wxPoint) cursorPos );
517 
518  text = fpText;
519 
520  DIALOG_TEXT_PROPERTIES textDialog( m_frame, fpText );
521  bool cancelled;
522 
523  RunMainStack( [&]()
524  {
525  cancelled = !textDialog.ShowModal()
526  || fpText->GetText().IsEmpty();
527  } );
528 
529  if( cancelled )
530  {
531  delete text;
532  text = nullptr;
533  }
534  else if( fpText->GetTextPos() != (wxPoint) cursorPos )
535  {
536  // If the user modified the location then go ahead and place it there.
537  // Otherwise we'll drag.
538  placing = true;
539  }
540  }
541  else
542  {
543  PCB_TEXT* pcbText = new PCB_TEXT( m_frame->GetModel() );
544  // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
545  pcbText->SetFlags( IS_NEW );
546 
547  pcbText->SetLayer( layer );
548 
549  // Set the mirrored option for layers on the BACK side of the board
550  if( IsBackLayer( layer ) )
551  pcbText->SetMirrored( true );
552 
553  pcbText->SetTextSize( dsnSettings.GetTextSize( layer ) );
554  pcbText->SetTextThickness( dsnSettings.GetTextThickness( layer ) );
555  pcbText->SetItalic( dsnSettings.GetTextItalic( layer ) );
556  pcbText->SetTextPos( (wxPoint) cursorPos );
557 
558  RunMainStack( [&]()
559  {
560  m_frame->ShowTextPropertiesDialog( pcbText );
561  } );
562 
563  if( pcbText->GetText().IsEmpty() )
564  delete pcbText;
565  else
566  text = pcbText;
567  }
568 
569  if( text )
570  {
571  m_controls->WarpCursor( text->GetPosition(), true );
573  m_view->Update( &selection() );
574 
575  // update the cursor so it looks correct before another event
576  setCursor();
577  }
578  }
579 
580  if( placing )
581  {
582  text->ClearFlags();
584 
585  commit.Add( text );
586  commit.Push( _( "Place a text" ) );
587 
589 
590  text = nullptr;
591  }
592 
594  m_controls->ShowCursor( true );
595  m_controls->CaptureCursor( text != nullptr );
596  m_controls->SetAutoPan( text != nullptr );
597  }
598  else if( text && evt->IsMotion() )
599  {
600  text->SetPosition( (wxPoint) cursorPos );
601  selection().SetReferencePoint( cursorPos );
602  m_view->Update( &selection() );
603  }
604  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
605  {
606  if( text )
607  {
608  frame()->OnEditItemRequest( text );
609  m_view->Update( &selection() );
610  frame()->SetMsgPanel( text );
611  }
612  else
613  {
614  evt->SetPassEvent();
615  }
616  }
617  else
618  {
619  evt->SetPassEvent();
620  }
621  }
622 
624  m_frame->SetMsgPanel( board() );
625  return 0;
626 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:194
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
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
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
BOARD * board() const
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: board_item.h:206
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:326
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
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:185
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
void ShowTextPropertiesDialog(BOARD_ITEM *aText)
Routine for main window class to launch text properties dialog.
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
bool GetTextUpright(PCB_LAYER_ID aLayer) const
PCB_BASE_EDIT_FRAME * frame() const
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:262
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: eda_item.h:220
#define NULL
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
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:227
bool m_isFootprintEditor
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:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:113
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:221
void Activate()
Function Activate() Runs the tool.
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
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:260
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
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:121
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), ARROW, 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_FRAME::GetModel(), EDA_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(), IS_NEW, IsBackLayer(), m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MOVING, NULL, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::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(), FP_TEXT::SetKeepUpright(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), EDA_DRAW_FRAME::SetMsgPanel(), EDA_ITEM::SetPosition(), SELECTION::SetReferencePoint(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), PCB_BASE_EDIT_FRAME::ShowTextPropertiesDialog(), TEXT, 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 217 of file drawing_tool.cpp.

218 {
219  // Init variables used by every drawing tool
220  m_view = getView();
222  m_board = getModel<BOARD>();
223  m_frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
224 }
BOARD * m_board
Definition: drawing_tool.h:228
KIGFX::VIEW * m_view
Definition: drawing_tool.h:226
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:227
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
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().

◆ selection() [1/2]

const PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 291 of file pcb_tool_base.cpp.

292 {
294 
295  return selTool->GetSelection();
296 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION & GetSelection()
Function GetSelection()

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), PCB_INSPECTION_TOOL::doHideNet(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawZone(), EDIT_TOOL::Duplicate(), PCB_EDITOR_CONTROL::EditFpInFpEditor(), PAD_TOOL::EditPad(), GROUP_TOOL::EnterGroup(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::FilletTracks(), SELECTION_TOOL::filterSelection(), EDIT_TOOL::Flip(), getSourceZoneForAction(), GROUP_TOOL::Group(), PCB_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::InspectClearance(), PCB_INSPECTION_TOOL::InspectConstraints(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PCBNEW_CONTROL::placeBoardItems(), PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), GROUP_TOOL::RemoveFromGroup(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), SELECTION_TOOL::selectNet(), SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), GROUP_TOOL::Ungroup(), 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 299 of file pcb_tool_base.cpp.

300 {
302 
303  return selTool->GetSelection();
304 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION & GetSelection()
Function GetSelection()

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

◆ SetAnchor()

int DRAWING_TOOL::SetAnchor ( const TOOL_EVENT aEvent)

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

Definition at line 1172 of file drawing_tool.cpp.

1173 {
1174  wxASSERT( m_isFootprintEditor );
1175 
1176  if( !m_frame->GetModel() )
1177  return 0;
1178 
1179  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
1181 
1182  std::string tool = aEvent.GetCommandStr().get();
1183  m_frame->PushTool( tool );
1184  Activate();
1185 
1187  m_controls->ShowCursor( true );
1188  m_controls->SetAutoPan( true );
1189  m_controls->CaptureCursor( false );
1190 
1191  auto setCursor =
1192  [&]()
1193  {
1195  };
1196 
1197  // Set initial cursor
1198  setCursor();
1199 
1200  while( TOOL_EVENT* evt = Wait() )
1201  {
1202  setCursor();
1203 
1204  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1205  grid.SetUseGrid( m_frame->IsGridVisible() );
1206  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(),
1207  LSET::AllLayersMask() );
1208  m_controls->ForceCursorPosition( true, cursorPos );
1209 
1210  if( evt->IsClick( BUT_LEFT ) )
1211  {
1213  BOARD_COMMIT commit( m_frame );
1214  commit.Modify( footprint );
1215 
1216  // set the new relative internal local coordinates of footprint items
1217  wxPoint moveVector = footprint->GetPosition() - (wxPoint) cursorPos;
1218  footprint->MoveAnchorPosition( moveVector );
1219 
1220  commit.Push( _( "Move the footprint reference anchor" ) );
1221 
1222  // Usually, we do not need to change twice the anchor position,
1223  // so deselect the active tool
1224  m_frame->PopTool( tool );
1225  break;
1226  }
1227  else if( evt->IsClick( BUT_RIGHT ) )
1228  {
1230  }
1231  else if( evt->IsCancelInteractive() || evt->IsActivate() )
1232  {
1233  m_frame->PopTool( tool );
1234  break;
1235  }
1236  else
1237  {
1238  evt->SetPassEvent();
1239  }
1240  }
1241 
1243  return 0;
1244 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
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
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.
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 PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCBNEW_SELECTION & selection() const
bool IsGridVisible() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
FOOTPRINT * footprint() const
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
void MoveAnchorPosition(const wxPoint &aMoveVector)
Function MoveAnchorPosition Move the reference point of the footprint It looks like a move footprint:...
Definition: footprint.cpp:1366
static LSET AllLayersMask()
Definition: lset.cpp:787
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:227
bool m_isFootprintEditor
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:229
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
#define _(s)
Definition: 3d_actions.cpp:33
wxPoint GetPosition() const override
Definition: footprint.h:200
void Activate()
Function Activate() Runs the tool.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59

References _, TOOL_INTERACTIVE::Activate(), LSET::AllLayersMask(), ANCHOR, ARROW, BULLSEYE, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_TOOL_BASE::footprint(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), FOOTPRINT::GetPosition(), EDA_DRAW_FRAME::IsGridVisible(), m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, MD_SHIFT, COMMIT::Modify(), FOOTPRINT::MoveAnchorPosition(), TOOLS_HOLDER::PopTool(), BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), 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)
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(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ SetIsFootprintEditor()

void PCB_TOOL_BASE::SetIsFootprintEditor ( bool  aEnabled)
inlineinherited

Function SetIsFootprintEditor()

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

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 104 of file pcb_tool_base.h.

104 { m_isFootprintEditor = aEnabled; }
bool m_isFootprintEditor
Definition