KiCad PCB EDA Suite
DRAWING_TOOL Class Reference

Class DRAWING_TOOL. More...

#include <drawing_tool.h>

Inheritance diagram for DRAWING_TOOL:
PCB_TOOL TOOL_INTERACTIVE TOOL_BASE

Public Types

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

The possible drawing modes of DRAWING_TOOL

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

Determines the reason of reset for a tool

More...
 

Public Member Functions

 DRAWING_TOOL ()
 
 ~DRAWING_TOOL ()
 
bool Init () override
 Function Init() Init() is called once upon a registration of the tool. More...
 
void Reset (RESET_REASON aReason) override
 Function Reset() Brings the tool to a known, initial state. More...
 
TOOL_MENUGetToolMenu ()
 

Get the DRAWING_TOOL top-level context menu

More...
 
MODE GetDrawingMode () const
 Function GetDrawingMode. More...
 
int DrawLine (const TOOL_EVENT &aEvent)
 Function DrawLine() Starts interactively drawing a line. More...
 
int DrawCircle (const TOOL_EVENT &aEvent)
 Function DrawCircle() Starts interactively drawing a circle. More...
 
int DrawArc (const TOOL_EVENT &aEvent)
 Function DrawArc() Starts interactively drawing an arc. More...
 
int PlaceText (const TOOL_EVENT &aEvent)
 Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets the user decide where to place the text in editor. More...
 
int DrawDimension (const TOOL_EVENT &aEvent)
 Function DrawDimension() Starts interactively drawing a dimension. More...
 
int DrawZone (const TOOL_EVENT &aEvent)
 Function DrawZone() Starts interactively drawing a zone. More...
 
int DrawGraphicPolygon (const TOOL_EVENT &aEvent)
 
int DrawVia (const TOOL_EVENT &aEvent)
 
int DrawZoneKeepout (const TOOL_EVENT &aEvent)
 Function DrawZoneKeepout() Starts interactively drawing a keepout area. More...
 
int DrawZoneCutout (const TOOL_EVENT &aEvent)
 Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone. More...
 
int DrawSimilarZone (const TOOL_EVENT &aEvent)
 Function DrawSimilarZone() Starts interactively drawing a zone with same settings as an existing zone. More...
 
int PlaceImportedGraphics (const TOOL_EVENT &aEvent)
 Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor. More...
 
int SetAnchor (const TOOL_EVENT &aEvent)
 Function SetAnchor() Places the footprint anchor (only in module editor). More...
 
void setTransitions () override
 

Sets up handlers for various events.

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

Protected Types

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

Protected Member Functions

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

Protected Attributes

TOOL_MENU m_menu
 Menu model displayed by the tool. More...
 
bool m_editModules
 
TOOL_TYPE m_type
 

Stores the type of the tool.

More...
 
TOOL_ID m_toolId
 

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

More...
 
std::string m_toolName
 

Name of the tool.

More...
 
TOOL_MANAGERm_toolMgr
 
TOOL_SETTINGS m_toolSettings
 

Private Types

enum  ZONE_MODE { ZONE_MODE::ADD, ZONE_MODE::CUTOUT, ZONE_MODE::SIMILAR, ZONE_MODE::GRAPHIC_POLYGON }
 

Private Member Functions

bool drawSegment (int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint=NULLOPT)
 

Starts drawing a selected shape (i.e.

More...
 
bool drawArc (DRAWSEGMENT *&aGraphic)
 

Starts drawing an arc.

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

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

More...
 
PCB_LAYER_ID getDrawingLayer () const
 

Selects a non-copper layer for drawing

More...
 

Private Attributes

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

Static Private Attributes

static const unsigned int WIDTH_STEP = 100000
 

Friends

class ZONE_CREATE_HELPER
 

Detailed Description

Class DRAWING_TOOL.

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

Definition at line 49 of file drawing_tool.h.

Member Enumeration Documentation

enum PCB_TOOL::INTERACTIVE_PLACEMENT_OPTIONS
protectedinherited
Enumerator
IPO_ROTATE 
IPO_FLIP 
IPO_PROPERTIES 
IPO_SINGLE_CLICK 
IPO_REPEAT 

Definition at line 109 of file pcb_tool.h.

enum DRAWING_TOOL::MODE
strong

The possible drawing modes of DRAWING_TOOL

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

Definition at line 68 of file drawing_tool.h.

69  {
70  NONE,
71  LINE,
72  CIRCLE,
73  ARC,
74  TEXT,
75  ANCHOR,
76  DXF,
77  DIMENSION,
78  KEEPOUT,
79  ZONE,
80  GRAPHIC_POLYGON,
81  VIA
82  };
Class DIMENSION.
enum TOOL_BASE::RESET_REASON
inherited

Determines the reason of reset for a tool

Enumerator
RUN 

Tool is invoked after being inactive.

MODEL_RELOAD 

Model changes (required full reload)

GAL_SWITCH 

Rendering engine changes.

Definition at line 80 of file tool_base.h.

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

Add a new zone/keepout with fresh settings.

CUTOUT 

Make a cutout to an existing zone.

SIMILAR 

Add a new zone with the same settings as an existing one.

GRAPHIC_POLYGON 

Definition at line 187 of file drawing_tool.h.

188  {
189  ADD,
190  CUTOUT,
191  SIMILAR,
192  GRAPHIC_POLYGON
193  };
Definition: am_param.h:150

Constructor & Destructor Documentation

DRAWING_TOOL::DRAWING_TOOL ( )

Definition at line 150 of file drawing_tool.cpp.

150  :
151  PCB_TOOL( "pcbnew.InteractiveDrawing" ),
152  m_view( nullptr ), m_controls( nullptr ),
153  m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
154  m_lineWidth( 1 )
155 {
156 }
BOARD * m_board
Definition: drawing_tool.h:263
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:71
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:268
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
DRAWING_TOOL::~DRAWING_TOOL ( )

Definition at line 159 of file drawing_tool.cpp.

160 {
161 }

Member Function Documentation

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

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

Definition at line 49 of file tool_interactive.cpp.

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

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

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

Function attachManager()

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

Definition at line 59 of file tool_base.cpp.

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

Referenced by TOOL_MANAGER::RegisterTool().

60 {
61  m_toolMgr = aManager;
62  m_toolSettings = TOOL_SETTINGS( this );
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:216
friend class TOOL_SETTINGS
Definition: tool_base.h:155
BOARD* PCB_TOOL::board ( ) const
inlineprotectedinherited

Definition at line 140 of file pcb_tool.h.

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_EDITOR_CONTROL::calculateSelectionRatsnest(), EDIT_TOOL::changeTrackWidthOnClick(), PCB_EDITOR_CONTROL::ClearHighlight(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), EDIT_TOOL::doCopyToClipboard(), PCB_TOOL::doInteractiveItemPlacement(), drawArc(), DrawDimension(), drawSegment(), MODULE_EDITOR_TOOLS::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::filterSelection(), POINT_EDITOR::finishItem(), SELECTION_TOOL::getCollectorsGuide(), PCBNEW_CONTROL::GraphicDisplayMode(), PAD_TOOL::haveFootprints(), highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCBNEW_CONTROL::ModuleEdgeOutlines(), PCBNEW_CONTROL::ModuleTextOutlines(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::PasteItemsFromClipboard(), PCBNEW_CONTROL::placeBoardItems(), MODULE_EDITOR_TOOLS::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), PlaceText(), ROUTER_TOOL::prepareInteractive(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), ZONE_FILLER_TOOL::SegzoneDeleteFill(), SELECTION_TOOL::selectable(), SELECTION_TOOL::selectAllItemsConnectedToItem(), SELECTION_TOOL::selectAllItemsConnectedToTrack(), SELECTION_TOOL::selectAllItemsOnNet(), SELECTION_TOOL::selectAllItemsOnSheet(), SELECTION_TOOL::selectPoint(), PCB_EDITOR_CONTROL::ShowLocalRatsnest(), PCBNEW_CONTROL::TrackDisplayMode(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCBNEW_CONTROL::ViaDisplayMode(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), PCBNEW_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), ZONE_FILLER_TOOL::ZoneFillAll(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

140 { return getModel<BOARD>(); }
void DRAWING_TOOL::constrainDimension ( DIMENSION dimension)
private

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

Parameters
aDimensionis the dimension element currently being drawn

Definition at line 479 of file drawing_tool.cpp.

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

Referenced by DrawDimension().

480 {
481  const VECTOR2I lineVector{ dimension->GetEnd() - dimension->GetOrigin() };
482 
483  dimension->SetEnd( wxPoint(
484  VECTOR2I( dimension->GetOrigin() ) + GetVectorSnapped45( lineVector ) ) );
485 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const wxPoint & GetEnd()
Function GetEnd.
const wxPoint & GetOrigin() const
Function GetOrigin.
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec)
Snap a vector onto the nearest 0, 45 or 90 degree line.
PCB_DISPLAY_OPTIONS * PCB_TOOL::displayOptions ( ) const
protectedinherited

Definition at line 235 of file pcb_tool.cpp.

References PCB_TOOL::frame(), and PCB_BASE_FRAME::GetDisplayOptions().

Referenced by PCBNEW_CONTROL::GraphicDisplayMode(), PCBNEW_CONTROL::HighContrastMode(), PCBNEW_CONTROL::ModuleEdgeOutlines(), PCBNEW_CONTROL::ModuleTextOutlines(), PCBNEW_CONTROL::PadDisplayMode(), PNS::TOOL_BASE::pickSingleItem(), PCBNEW_CONTROL::TrackDisplayMode(), PCBNEW_CONTROL::ViaDisplayMode(), and PCBNEW_CONTROL::ZoneDisplayMode().

236 {
237  return static_cast<PCB_DISPLAY_OPTIONS*>( frame()->GetDisplayOptions() );
238 }
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
void PCB_TOOL::doInteractiveItemPlacement ( 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 39 of file pcb_tool.cpp.

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

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

42 {
43  using namespace std::placeholders;
44  std::unique_ptr<BOARD_ITEM> newItem;
45 
46  Activate();
47 
48  BOARD_COMMIT commit( frame() );
49 
51 
52  // do not capture or auto-pan until we start placing an item
53  controls()->ShowCursor( true );
54  controls()->SetSnapping( true );
55 
56  // Add a VIEW_GROUP that serves as a preview for the new item
57  SELECTION preview;
58  view()->Add( &preview );
59 
60  aPlacer->m_board = board();
61  aPlacer->m_frame = frame();
62  aPlacer->m_modifiers = 0;
63 
64  if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
65  {
66  VECTOR2I cursorPos = controls()->GetCursorPosition();
67 
68  newItem = aPlacer->CreateItem();
69 
70  if( newItem )
71  {
72  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
73  preview.Add( newItem.get() );
74  }
75  }
76 
77  // Main loop: keep receiving events
78  while( OPT_TOOL_EVENT evt = Wait() )
79  {
80  VECTOR2I cursorPos = controls()->GetCursorPosition();
81  aPlacer->m_modifiers = evt->Modifier();
82 
84  {
85  if( newItem )
86  {
87  // Delete the old item and have another try
88  newItem = nullptr;
89 
90  preview.Clear();
91 
92  if( aOptions & IPO_SINGLE_CLICK )
93  break;
94 
95  controls()->SetAutoPan( false );
96  controls()->CaptureCursor( false );
97  controls()->ShowCursor( true );
98  }
99  else
100  {
101  break;
102  }
103 
104  if( evt->IsActivate() ) // now finish unconditionally
105  break;
106  }
107  else if( evt->IsClick( BUT_LEFT ) )
108  {
109  if( !newItem )
110  {
111  // create the item if possible
112  newItem = aPlacer->CreateItem();
113 
114  // no item created, so wait for another click
115  if( !newItem )
116  continue;
117 
118  controls()->CaptureCursor( true );
119  controls()->SetAutoPan( true );
120 
121  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
122 
123  preview.Add( newItem.get() );
124 
125  if( newItem->Type() == PCB_MODULE_T )
126  {
127  auto module = dyn_cast<MODULE*>( newItem.get() );
128 
129  // modules have more drawable parts
130  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
131  }
132  }
133  else
134  {
135  newItem->ClearFlags();
136  preview.Remove( newItem.get() );
137 
138  aPlacer->PlaceItem( newItem.get(), commit );
139 
140  if( newItem->Type() == PCB_MODULE_T )
141  {
142  auto module = dyn_cast<MODULE*>( newItem.get() );
143  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) );
144  }
145 
146  newItem.release();
147  commit.Push( aCommitMessage );
148 
149  controls()->CaptureCursor( false );
150  controls()->SetAutoPan( false );
151  controls()->ShowCursor( true );
152 
153  if( !( aOptions & IPO_REPEAT ) )
154  break;
155 
156  if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
157  {
159 
160  newItem = aPlacer->CreateItem();
161 
162  if( newItem )
163  {
164  newItem->SetPosition( wxPoint( pos.x, pos.y ) );
165  preview.Add( newItem.get() );
166  }
167  }
168  }
169  }
170  else if( evt->IsClick( BUT_RIGHT ) )
171  {
173  }
174  else if( newItem && evt->Category() == TC_COMMAND )
175  {
176  /*
177  * Handle any events that can affect the item as we move
178  * it around, eg rotate and flip
179  */
180 
181  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
182  {
183  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
184  newItem->Rotate( newItem->GetPosition(), rotationAngle );
185  view()->Update( &preview );
186  }
187  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
188  {
189  newItem->Flip( newItem->GetPosition() );
190  view()->Update( &preview );
191  }
192  }
193 
194  else if( newItem && evt->IsMotion() )
195  {
196  // track the cursor
197  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
198  aPlacer->SnapItem( newItem.get() );
199 
200  // Show a preview of the item
201  view()->Update( &preview );
202  }
203  }
204 
205  view()->Remove( &preview );
206 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Definition: pcb_tool.cpp:265
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:90
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
PCB_EDIT_FRAME * m_frame
Definition: pcb_tool.h:58
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
virtual void SnapItem(BOARD_ITEM *aItem)
Definition: pcb_tool.cpp:260
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:138
class MODULE, a footprint
Definition: typeinfo.h:89
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
MODULE * module() const
Definition: pcb_tool.h:141
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
KIGFX::PCB_VIEW * view() const
Definition: pcb_tool.h:137
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
void Activate()
Function Activate() Runs the tool.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
BOARD * board() const
Definition: pcb_tool.h:140
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:82
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 287 of file drawing_tool.cpp.

References COMMIT::Add(), ARC, drawArc(), PCB_BASE_EDIT_FRAME::GetModel(), ID_MODEDIT_ARC_TOOL, ID_PCB_ARC_BUTT, PCB_TOOL::m_editModules, m_frame, m_mode, BOARD_COMMIT::Push(), EDA_DRAW_FRAME::SetNoToolSelected(), and PCB_BASE_FRAME::SetToolID().

Referenced by setTransitions().

288 {
289  if( m_editModules && !m_frame->GetModel() )
290  return 0;
291 
293  DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
294  BOARD_COMMIT commit( m_frame );
295 
296  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
297 
299  wxCURSOR_PENCIL, _( "Add graphic arc" ) );
300 
301  while( drawArc( arc ) )
302  {
303  if( arc )
304  {
305  commit.Add( arc );
306  commit.Push( _( "Draw an arc" ) );
307  }
308 
309  arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
310  }
311 
313 
314  return 0;
315 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
bool drawArc(DRAWSEGMENT *&aGraphic)
Starts drawing an arc.
bool DRAWING_TOOL::drawArc ( DRAWSEGMENT *&  aGraphic)
private

Starts drawing an arc.

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

Definition at line 1161 of file drawing_tool.cpp.

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

Referenced by DrawArc().

1162 {
1164 
1166 
1167  // Arc geometric construction manager
1169 
1170  // Arc drawing assistant overlay
1171  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1172 
1173  // Add a VIEW_GROUP that serves as a preview for the new item
1174  SELECTION preview;
1175  m_view->Add( &preview );
1176  m_view->Add( &arcAsst );
1177  GRID_HELPER grid( m_frame );
1178 
1179  m_controls->ShowCursor( true );
1180  m_controls->SetSnapping( true );
1181 
1182  Activate();
1183 
1184  bool firstPoint = false;
1185 
1186  // Main loop: keep receiving events
1187  while( OPT_TOOL_EVENT evt = Wait() )
1188  {
1189  PCB_LAYER_ID layer = getDrawingLayer();
1190  aGraphic->SetLayer( layer );
1191 
1192  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1193  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1194  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1195  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), aGraphic );
1196  m_controls->ForceCursorPosition( true, cursorPos );
1197 
1198  if( evt->IsClick( BUT_LEFT ) )
1199  {
1200  if( !firstPoint )
1201  {
1202  m_controls->SetAutoPan( true );
1203  m_controls->CaptureCursor( true );
1204 
1206 
1207  // Init the new item attributes
1208  // (non-geometric, those are handled by the manager)
1209  aGraphic->SetShape( S_ARC );
1210  aGraphic->SetWidth( m_lineWidth );
1211 
1212  preview.Add( aGraphic );
1213  firstPoint = true;
1214  }
1215 
1216  arcManager.AddPoint( cursorPos, true );
1217  }
1218  else if( evt->IsAction( &deleteLastPoint ) )
1219  {
1220  arcManager.RemoveLastPoint();
1221  }
1222  else if( evt->IsMotion() )
1223  {
1224  // set angle snap
1225  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1226 
1227  // update, but don't step the manager state
1228  arcManager.AddPoint( cursorPos, false );
1229  }
1230  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
1231  {
1232  preview.Clear();
1233  delete aGraphic;
1234  aGraphic = nullptr;
1235  break;
1236  }
1237  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1238  {
1240  aGraphic->SetLayer( getDrawingLayer() );
1241  aGraphic->SetWidth( m_lineWidth );
1242  m_view->Update( &preview );
1243  frame()->SetMsgPanel( aGraphic );
1244  }
1245  else if( evt->IsClick( BUT_RIGHT ) )
1246  {
1248  }
1249  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1250  {
1252  aGraphic->SetWidth( m_lineWidth );
1253  m_view->Update( &preview );
1254  frame()->SetMsgPanel( aGraphic );
1255  }
1256  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1257  {
1259  aGraphic->SetWidth( m_lineWidth );
1260  m_view->Update( &preview );
1261  frame()->SetMsgPanel( aGraphic );
1262  }
1263  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1264  {
1265  arcManager.ToggleClockwise();
1266  }
1267 
1268  if( arcManager.IsComplete() )
1269  {
1270  break;
1271  }
1272  else if( arcManager.HasGeometryChanged() )
1273  {
1274  updateArcFromConstructionMgr( arcManager, *aGraphic );
1275  m_view->Update( &preview );
1276  m_view->Update( &arcAsst );
1277 
1278  if(firstPoint)
1279  frame()->SetMsgPanel( aGraphic );
1280  else
1281  frame()->SetMsgPanel( board() );
1282  }
1283  }
1284 
1285  preview.Remove( aGraphic );
1286  m_view->Remove( &arcAsst );
1287  m_view->Remove( &preview );
1288  frame()->SetMsgPanel( board() );
1289  m_controls->SetAutoPan( false );
1290  m_controls->CaptureCursor( false );
1291  m_controls->ForceCursorPosition( false );
1292 
1293  return !arcManager.IsReset();
1294 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
Class ARC_GEOM_MANAGER.
void SetShape(STROKE_T aShape)
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:192
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
static TOOL_ACTION deleteLastPoint("pcbnew.InteractiveDrawing.deleteLastPoint", AS_CONTEXT, WXK_BACK, _("Delete Last Point"), _("Delete the last point added to the current item"), undo_xpm)
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:271
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:375
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, DRAWSEGMENT &aArc)
Update an arc DRAWSEGMENT from the current state of an Arc Geometry Manager.
void AddPoint(const VECTOR2I &aPt, bool aLockIn)
Add a point to the construction manager.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:195
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
PCB_LAYER_ID
A quick note on layer IDs:
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:281
Arcs (with rounded ends)
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:268
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:262
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
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:264
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:198
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
void ToggleClockwise()
Reverse the current are direction
Class SELECTION_AREA.
Definition: arc_assistant.h:38
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
void Activate()
Function Activate() Runs the tool.
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:345
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
BOARD * board() const
Definition: pcb_tool.h:140
void SetWidth(int aWidth)
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 256 of file drawing_tool.cpp.

References COMMIT::Add(), CIRCLE, drawSegment(), PCB_BASE_EDIT_FRAME::GetModel(), ID_MODEDIT_CIRCLE_TOOL, ID_PCB_CIRCLE_BUTT, PCB_TOOL::m_editModules, m_frame, m_mode, BOARD_COMMIT::Push(), S_CIRCLE, EDA_DRAW_FRAME::SetNoToolSelected(), and PCB_BASE_FRAME::SetToolID().

Referenced by setTransitions().

257 {
258  if( m_editModules && !m_frame->GetModel() )
259  return 0;
260 
262  DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
263  BOARD_COMMIT commit( m_frame );
264 
265  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
266 
268  wxCURSOR_PENCIL, _( "Add graphic circle" ) );
269 
270  while( drawSegment( S_CIRCLE, circle ) )
271  {
272  if( circle )
273  {
274  commit.Add( circle );
275  commit.Push( _( "Draw a circle" ) );
276  }
277 
278  circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
279  }
280 
282 
283  return 0;
284 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
bool drawSegment(int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint=NULLOPT)
Starts drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
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 488 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), DIMENSION::AdjustDimensionDetails(), PNS::angle(), GRID_HELPER::BestSnapAnchor(), PCB_TOOL::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), PCB_ACTIONS::decWidth, delta, DIMENSION, Dwgs_User, Edge_Cuts, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL::frame(), DIMENSION::GetAngle(), BOARD::GetDesignSettings(), getDrawingLayer(), DIMENSION::GetEnd(), BOARD_DESIGN_SETTINGS::GetLineThickness(), PCB_BASE_EDIT_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), DIMENSION::GetOrigin(), DIMENSION::GetPosition(), BOARD_DESIGN_SETTINGS::GetTextItalic(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), EDA_DRAW_FRAME::GetUserUnits(), DIMENSION::GetWidth(), ID_PCB_DIMENSION_BUTT, PCB_ACTIONS::incWidth, TOOL_EVT_UTILS::IsCancelInteractive(), m_board, m_controls, PCB_TOOL::m_editModules, DIMENSION::m_featureLineDO, m_frame, m_lineWidth, PCB_TOOL::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MD_ALT, MD_CTRL, MD_SHIFT, BOARD_COMMIT::Push(), SELECTION::Remove(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), DIMENSION::SetEnd(), DIMENSION::SetHeight(), EDA_TEXT::SetItalic(), DIMENSION::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), EDA_DRAW_FRAME::SetNoToolSelected(), DIMENSION::SetOrigin(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), PCB_BASE_FRAME::SetToolID(), DIMENSION::SetUnits(), GRID_HELPER::SetUseGrid(), DIMENSION::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), DIMENSION::Text(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), WIDTH_STEP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setTransitions().

489 {
490  if( m_editModules && !m_frame->GetModel() )
491  return 0;
492 
493  DIMENSION* dimension = NULL;
494  BOARD_COMMIT commit( m_frame );
495  GRID_HELPER grid( m_frame );
496 
497  // Add a VIEW_GROUP that serves as a preview for the new item
498  SELECTION preview;
499 
500  m_view->Add( &preview );
501 
503  m_controls->ShowCursor( true );
504  m_controls->SetSnapping( true );
505 
506  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
507 
508  Activate();
509  m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
510 
511  enum DIMENSION_STEPS
512  {
513  SET_ORIGIN = 0,
514  SET_END,
515  SET_HEIGHT,
516  FINISHED
517  };
518  int step = SET_ORIGIN;
519 
520  // Main loop: keep receiving events
521  while( OPT_TOOL_EVENT evt = Wait() )
522  {
523  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
524  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
525  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
526  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), nullptr );
527  m_controls->ForceCursorPosition( true, cursorPos );
528 
530  {
531  m_controls->SetAutoPan( false );
532 
533  if( step != SET_ORIGIN ) // start from the beginning
534  {
535  preview.Clear();
536 
537  delete dimension;
538  step = SET_ORIGIN;
539  }
540  else
541  break;
542 
543  if( evt->IsActivate() ) // now finish unconditionally
544  break;
545  }
546  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
547  {
549  dimension->SetWidth( m_lineWidth );
550  m_view->Update( &preview );
551  frame()->SetMsgPanel( dimension );
552  }
553  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
554  {
555  if( m_lineWidth > WIDTH_STEP )
556  {
558  dimension->SetWidth( m_lineWidth );
559  m_view->Update( &preview );
560  frame()->SetMsgPanel( dimension );
561  }
562  }
563  else if( evt->IsClick( BUT_RIGHT ) )
564  {
566  }
567  else if( evt->IsClick( BUT_LEFT ) )
568  {
569  switch( step )
570  {
571  case SET_ORIGIN:
572  {
573  PCB_LAYER_ID layer = getDrawingLayer();
574  const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
575 
576  if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
577  layer = Dwgs_User;
578 
579  // Init the new item attributes
580  dimension = new DIMENSION( m_board );
581  dimension->SetLayer( layer );
582  dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
583  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
584  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
585  dimension->Text().SetThickness( boardSettings.GetTextThickness( layer ) );
586  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
587  dimension->SetWidth( boardSettings.GetLineThickness( layer ) );
588  dimension->SetUnits( m_frame->GetUserUnits(), false );
589  dimension->AdjustDimensionDetails();
590 
591  preview.Add( dimension );
592  frame()->SetMsgPanel( dimension );
593 
594  m_controls->SetAutoPan( true );
595  m_controls->CaptureCursor( true );
596  }
597  break;
598 
599  case SET_END:
600  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
601 
602  if( !!evt->Modifier( MD_CTRL ) )
603  constrainDimension( dimension );
604 
605  // Dimensions that have origin and end in the same spot are not valid
606  if( dimension->GetOrigin() == dimension->GetEnd() )
607  --step;
608 
609  break;
610 
611  case SET_HEIGHT:
612  {
613  if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
614  {
615  assert( dimension->GetOrigin() != dimension->GetEnd() );
616  assert( dimension->GetWidth() > 0 );
617 
618  preview.Remove( dimension );
619 
620  commit.Add( dimension );
621  commit.Push( _( "Draw a dimension" ) );
622  }
623  }
624  break;
625  }
626 
627  if( ++step == FINISHED )
628  {
629  step = SET_ORIGIN;
630  m_controls->SetAutoPan( false );
631  m_controls->CaptureCursor( false );
632  }
633  }
634  else if( evt->IsMotion() )
635  {
636  switch( step )
637  {
638  case SET_END:
639  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
640 
641  if( !!evt->Modifier( MD_CTRL ) )
642  constrainDimension( dimension );
643 
644  break;
645 
646  case SET_HEIGHT:
647  {
648  // Calculating the direction of travel perpendicular to the selected axis
649  double angle = dimension->GetAngle() + ( M_PI / 2 );
650 
651  wxPoint pos( cursorPos.x, cursorPos.y );
652  wxPoint delta( pos - dimension->m_featureLineDO );
653  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
654  dimension->SetHeight( height );
655  }
656  break;
657  }
658 
659  // Show a preview of the item
660  m_view->Update( &preview );
661  if( step )
662  frame()->SetMsgPanel( dimension );
663  else
664  frame()->SetMsgPanel( board() );
665  }
666  }
667 
668  if( step != SET_ORIGIN )
669  delete dimension;
670 
671  m_controls->SetAutoPan( false );
672 
673  m_view->Remove( &preview );
674  frame()->SetMsgPanel( board() );
676 
677  return 0;
678 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:90
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
BOARD * m_board
Definition: drawing_tool.h:263
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:192
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
int GetWidth() const
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:271
void SetItalic(bool isItalic)
Definition: eda_text.h:182
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:375
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
double GetAngle() const
Function GetAngle Returns angle of the crossbar.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
static const int delta[8][2]
Definition: solve.cpp:112
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:195
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
PCB_LAYER_ID
A quick note on layer IDs:
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
RAII class that sets an value at construction and resets it to the original value at destruction...
const wxPoint & GetEnd()
Function GetEnd.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
const wxPoint & GetOrigin() const
Function GetOrigin.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:281
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:268
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
void AdjustDimensionDetails()
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
void SetUnits(EDA_UNITS_T aUnits, bool aUseMils)
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
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:264
bool m_editModules
Definition: pcb_tool.h:150
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
void constrainDimension(DIMENSION *dimension)
Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees...
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
TEXTE_PCB & Text()
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
const wxPoint GetPosition() const override
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:345
void SetWidth(int aWidth)
wxPoint m_featureLineDO
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
Class DIMENSION.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
BOARD * board() const
Definition: pcb_tool.h:140
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:82
int DRAWING_TOOL::DrawGraphicPolygon ( const TOOL_EVENT aEvent)

Definition at line 711 of file drawing_tool.cpp.

References drawZone(), PCB_BASE_EDIT_FRAME::GetModel(), GRAPHIC_POLYGON, ID_MODEDIT_POLYGON_TOOL, ID_PCB_ADD_POLYGON_BUTT, PCB_TOOL::m_editModules, m_frame, m_mode, and PCB_BASE_FRAME::SetToolID().

Referenced by setTransitions().

712 {
713  if( m_editModules && !m_frame->GetModel() )
714  return 0;
715 
716  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::GRAPHIC_POLYGON );
717 
719  wxCURSOR_PENCIL, _( "Add graphic polygon" ) );
720 
721  return drawZone( false, ZONE_MODE::GRAPHIC_POLYGON );
722 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
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 218 of file drawing_tool.cpp.

References drawSegment(), DRAWSEGMENT::GetEnd(), PCB_BASE_EDIT_FRAME::GetModel(), ID_MODEDIT_LINE_TOOL, ID_PCB_ADD_LINE_BUTT, LINE, PCB_TOOL::m_editModules, m_frame, m_mode, NULLOPT, S_SEGMENT, EDA_DRAW_FRAME::SetNoToolSelected(), and PCB_BASE_FRAME::SetToolID().

Referenced by setTransitions().

219 {
220  if( m_editModules && !m_frame->GetModel() )
221  return 0;
222 
224  DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
225 
226  auto startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
227  BOARD_COMMIT commit( m_frame );
228 
229  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
230 
232  wxCURSOR_PENCIL, _( "Add graphic line" ) );
233 
234  while( drawSegment( S_SEGMENT, line, startingPoint ) )
235  {
236  if( line )
237  {
238  commit.Add( line );
239  commit.Push( _( "Draw a line segment" ) );
240  startingPoint = VECTOR2D( line->GetEnd() );
241  }
242  else
243  {
244  startingPoint = NULLOPT;
245  }
246 
247  line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
248  }
249 
251 
252  return 0;
253 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
bool drawSegment(int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint=NULLOPT)
Starts drawing a selected shape (i.e.
usual segment : line with rounded ends
RAII class that sets an value at construction and resets it to the original value at destruction...
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
bool DRAWING_TOOL::drawSegment ( int  aShape,
DRAWSEGMENT *&  aGraphic,
OPT< VECTOR2D aStartingPoint = NULLOPT 
)
private

Starts drawing a selected shape (i.e.

DRAWSEGMENT).

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

Definition at line 929 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), GRID_HELPER::BestSnapAnchor(), PCB_TOOL::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_ACTIONS::decWidth, dyn_cast(), COMMIT::Empty(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL::frame(), getDrawingLayer(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetLength(), PCB_BASE_EDIT_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), PCB_BASE_FRAME::GetScreen(), getSegmentWidth(), GRID_HELPER::GetSnapped(), DRAWSEGMENT::GetStart(), GetVectorSnapped45(), PCB_ACTIONS::incWidth, TOOL_EVT_UTILS::IsCancelInteractive(), PCB_ACTIONS::layerChanged, m_controls, PCB_TOOL::m_editModules, m_frame, m_lineWidth, PCB_TOOL::m_menu, BASE_SCREEN::m_O_Curseur, TOOL_BASE::m_toolMgr, PCB_GENERAL_SETTINGS::m_use45DegreeGraphicSegments, m_view, MD_ALT, MD_CTRL, MD_SHIFT, mod, BOARD_COMMIT::Push(), KIGFX::VIEW::Remove(), PCB_ACTIONS::resetCoords, TOOL_MANAGER::RunAction(), S_CIRCLE, S_SEGMENT, PCB_ACTIONS::selectionClear, PCB_BASE_FRAME::SetActiveLayer(), KIGFX::VIEW_CONTROLS::SetAutoPan(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), DRAWSEGMENT::SetShape(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), DRAWSEGMENT::SetStart(), PCB_BASE_FRAME::Settings(), GRID_HELPER::SetUseGrid(), DRAWSEGMENT::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), WIDTH_STEP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawCircle(), and DrawLine().

931 {
932  // Only two shapes are currently supported
933  assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
934  GRID_HELPER grid( m_frame );
935 
938 
939  // Add a VIEW_GROUP that serves as a preview for the new item
940  SELECTION preview;
941  m_view->Add( &preview );
942 
944  m_controls->ShowCursor( true );
945 
946  Activate();
947 
948  bool direction45 = false; // 45 degrees only mode
949  bool started = false;
950  bool IsOCurseurSet = ( m_frame->GetScreen()->m_O_Curseur != wxPoint( 0, 0 ) );
951  VECTOR2I cursorPos = m_controls->GetMousePosition();
952 
953  if( aStartingPoint )
954  {
955  // Init the new item attributes
956  aGraphic->SetShape( (STROKE_T) aShape );
957  aGraphic->SetWidth( m_lineWidth );
958  aGraphic->SetLayer( getDrawingLayer() );
959  aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) );
960 
961  cursorPos = grid.BestSnapAnchor( cursorPos, aGraphic );
962  m_controls->ForceCursorPosition( true, cursorPos );
963  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
964 
965  preview.Add( aGraphic );
966  m_controls->SetAutoPan( true );
967  m_controls->CaptureCursor( true );
968 
969  if( !IsOCurseurSet )
970  m_frame->GetScreen()->m_O_Curseur = wxPoint( aStartingPoint->x, aStartingPoint->y );
971 
972  started = true;
973  }
974 
975  // Main loop: keep receiving events
976  while( OPT_TOOL_EVENT evt = Wait() )
977  {
978  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
979  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
980  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
981  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), getDrawingLayer() );
982  m_controls->ForceCursorPosition( true, cursorPos );
983 
984  // 45 degree angle constraint enabled with an option and toggled with Ctrl
985  const bool limit45 = ( frame()->Settings().m_use45DegreeGraphicSegments != !!( evt->Modifier( MD_CTRL ) ) );
986 
987  if( direction45 != limit45 && started && aShape == S_SEGMENT )
988  {
989  direction45 = limit45;
990 
991  if( direction45 )
992  {
993  const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
994 
995  // get a restricted 45/H/V line from the last fixed point to the cursor
996  auto newEnd = GetVectorSnapped45( lineVector );
997  aGraphic->SetEnd( aGraphic->GetStart() + wxPoint( newEnd.x, newEnd.y ) );
998  m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
999  }
1000  else
1001  {
1002  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1003  }
1004 
1005  m_view->Update( &preview );
1006  frame()->SetMsgPanel( aGraphic );
1007  }
1008 
1010  {
1011  preview.Clear();
1012  m_view->Update( &preview );
1013  delete aGraphic;
1014  aGraphic = NULL;
1015  if( !IsOCurseurSet )
1016  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1017  break;
1018  }
1019  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1020  {
1022  aGraphic->SetLayer( getDrawingLayer() );
1023  aGraphic->SetWidth( m_lineWidth );
1024  m_view->Update( &preview );
1025  frame()->SetMsgPanel( aGraphic );
1026  }
1027  else if( evt->IsClick( BUT_RIGHT ) )
1028  {
1030  }
1031  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1032  {
1033  if( !started )
1034  {
1036 
1037  // Init the new item attributes
1038  aGraphic->SetShape( (STROKE_T) aShape );
1039  aGraphic->SetWidth( m_lineWidth );
1040  aGraphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
1041  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1042  aGraphic->SetLayer( getDrawingLayer() );
1043 
1044  if( !IsOCurseurSet )
1045  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
1046 
1047  preview.Add( aGraphic );
1048  frame()->SetMsgPanel( aGraphic );
1049  m_controls->SetAutoPan( true );
1050  m_controls->CaptureCursor( true );
1051 
1052  started = true;
1053  }
1054  else
1055  {
1056  auto snapItem = dyn_cast<DRAWSEGMENT*>( grid.GetSnapped() );
1057  auto mod = dyn_cast<MODULE*>( m_frame->GetModel() );
1058 
1059  if( aGraphic->GetEnd() == aGraphic->GetStart()
1060  || ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT )
1061  || snapItem )
1062  // User has clicked twice in the same spot
1063  // or clicked on the end of an existing segment (closing a path)
1064  {
1065  BOARD_COMMIT commit( m_frame );
1066 
1067  // If the user clicks on an existing snap point from a drawsegment
1068  // we finish the segment as they are likely closing a path
1069  if( snapItem && aGraphic->GetLength() > 0.0 )
1070  {
1071  DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( mod ) : new DRAWSEGMENT;
1072 
1073  *l = *aGraphic;
1074  commit.Add( l );
1075  }
1076 
1077  if( !commit.Empty() )
1078  commit.Push( _( "Draw a line" ) );
1079 
1080  delete aGraphic;
1081  aGraphic = NULL;
1082  }
1083 
1084  preview.Clear();
1085  break;
1086  }
1087  }
1088  else if( evt->IsMotion() )
1089  {
1090  // 45 degree lines
1091  if( direction45 && aShape == S_SEGMENT )
1092  {
1093  const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) );
1094 
1095  // get a restricted 45/H/V line from the last fixed point to the cursor
1096  auto newEnd = GetVectorSnapped45( lineVector );
1097  aGraphic->SetEnd( aGraphic->GetStart() + wxPoint( newEnd.x, newEnd.y ) );
1098  m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) );
1099  }
1100  else
1101  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1102 
1103  m_view->Update( &preview );
1104 
1105  if( started )
1106  frame()->SetMsgPanel( aGraphic );
1107  else
1108  frame()->SetMsgPanel( board() );
1109  }
1110  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1111  {
1113  aGraphic->SetWidth( m_lineWidth );
1114  m_view->Update( &preview );
1115  frame()->SetMsgPanel( aGraphic );
1116  }
1117  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1118  {
1120  aGraphic->SetWidth( m_lineWidth );
1121  m_view->Update( &preview );
1122  frame()->SetMsgPanel( aGraphic );
1123  }
1124  else if( evt->IsAction( &PCB_ACTIONS::resetCoords ) )
1125  {
1126  IsOCurseurSet = true;
1127  }
1128  }
1129 
1130  if( !IsOCurseurSet ) // reset the relative coordinte if it was not set before
1131  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1132 
1133  m_view->Remove( &preview );
1134  frame()->SetMsgPanel( board() );
1135  m_controls->SetAutoPan( false );
1136  m_controls->CaptureCursor( false );
1137  m_controls->ForceCursorPosition( false );
1138 
1139  return started;
1140 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
void SetShape(STROKE_T aShape)
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:90
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:192
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:271
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:375
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
usual segment : line with rounded ends
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
static TOOL_ACTION resetCoords
Definition: pcb_actions.h:369
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:195
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
static bool m_use45DegreeGraphicSegments
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
PCB_GENERAL_SETTINGS & Settings()
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:268
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
void SetStart(const wxPoint &aStart)
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
void SetEnd(const wxPoint &aEnd)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec)
Snap a vector onto the nearest 0, 45 or 90 degree line.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:345
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
#define mod(a, n)
Definition: greymap.cpp:24
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
BOARD * board() const
Definition: pcb_tool.h:140
void SetWidth(int aWidth)
int DRAWING_TOOL::DrawSimilarZone ( const TOOL_EVENT aEvent)

Function DrawSimilarZone() Starts interactively drawing a zone with same settings as an existing zone.

The normal zone interactive tool is used, but the zone settings dialog is not shown at the start.

Definition at line 725 of file drawing_tool.cpp.

References drawZone(), ID_PCB_ZONES_BUTT, m_frame, m_mode, PCB_BASE_FRAME::SetToolID(), SIMILAR, and ZONE.

Referenced by setTransitions().

726 {
727  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
728 
729  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add similar zone" ) );
730 
731  return drawZone( false, ZONE_MODE::SIMILAR );
732 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
Add a new zone with the same settings as an existing one.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 1487 of file drawing_tool.cpp.

References COMMIT::Add(), GRID_HELPER::AlignToSegment(), B_Cu, TRACK::Clone(), PCB_TOOL::doInteractiveItemPlacement(), F_Cu, PCB_TOOL::frame(), PCB_BASE_FRAME::GetActiveLayer(), BOARD::GetCopperLayerCount(), BOARD::GetDesignSettings(), TRACK::GetEnd(), ZONE_CONTAINER::GetLayer(), VIA::GetLayerSet(), NETINFO_ITEM::GetMicroViaDrillSize(), NETINFO_ITEM::GetMicroViaSize(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetCode(), VIA::GetPosition(), PCB_BASE_FRAME::GetScreen(), TRACK::GetStart(), VIA::GetViaType(), TRACK::GetWidth(), ID_NO_TOOL_SELECTED, ID_PCB_DRAW_VIA_BUTT, In1_Cu, PCB_TOOL::IPO_FLIP, PCB_TOOL::IPO_REPEAT, PCB_TOOL::IPO_ROTATE, PCB_TOOL::IPO_SINGLE_CLICK, BOARD::IsLayerVisible(), m_board, m_frame, m_mode, PCB_SCREEN::m_Route_Layer_BOTTOM, PCB_SCREEN::m_Route_Layer_TOP, MD_SHIFT, mod, COMMIT::Modify(), BOARD::Modules(), VIA::SetDrill(), TRACK::SetEnd(), VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), BOARD_ITEM::SetPosition(), GRID_HELPER::SetSnap(), TRACK::SetStart(), PCB_BASE_FRAME::SetToolID(), VIA::SetViaType(), TRACK::SetWidth(), TestSegmentHit(), ToLAYER_ID(), BOARD::Tracks(), VIA, VIA_BLIND_BURIED, VIA_MICROVIA, and BOARD::Zones().

Referenced by setTransitions().

1488 {
1489  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
1490  {
1491  GRID_HELPER m_gridHelper;
1492 
1493  VIA_PLACER( PCB_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame )
1494  {}
1495 
1496  TRACK* findTrack( VIA* aVia )
1497  {
1498  const LSET lset = aVia->GetLayerSet();
1499 
1500  for( TRACK* track : m_board->Tracks() )
1501  {
1502  if( !(track->GetLayerSet() & lset ).any() )
1503  continue;
1504 
1505  if( TestSegmentHit( aVia->GetPosition(), track->GetStart(), track->GetEnd(),
1506  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
1507  return track;
1508  }
1509 
1510  return nullptr;
1511  }
1512 
1513  int findStitchedZoneNet( VIA* aVia )
1514  {
1515  const auto pos = aVia->GetPosition();
1516  const auto lset = aVia->GetLayerSet();
1517 
1518  for( auto mod : m_board->Modules() )
1519  {
1520  for( D_PAD* pad : mod->Pads() )
1521  {
1522  if( pad->HitTest( pos ) && ( pad->GetLayerSet() & lset ).any() )
1523  return -1;
1524  }
1525  }
1526 
1527  std::vector<ZONE_CONTAINER*> foundZones;
1528 
1529  for( auto zone : m_board->Zones() )
1530  {
1531  if( zone->HitTestFilledArea( pos ) )
1532  {
1533  foundZones.push_back( zone );
1534  }
1535  }
1536 
1537  std::sort( foundZones.begin(), foundZones.end(),
1538  [] ( const ZONE_CONTAINER* a, const ZONE_CONTAINER* b ) {
1539  return a->GetLayer() < b->GetLayer();
1540  } );
1541 
1542  // first take the net of the active layer
1543  for( auto z : foundZones )
1544  {
1545  if( m_frame->GetActiveLayer() == z->GetLayer() )
1546  return z->GetNetCode();
1547  }
1548 
1549  // none? take the topmost visible layer
1550  for( auto z : foundZones )
1551  {
1552  if( m_board->IsLayerVisible( z->GetLayer() ) )
1553  return z->GetNetCode();
1554  }
1555 
1556  return -1;
1557  }
1558 
1559  void SnapItem( BOARD_ITEM *aItem ) override
1560  {
1561  // If you place a Via on a track but not on its centerline, the current
1562  // connectivity algorithm will require us to put a kink in the track when
1563  // we break it (so that each of the two segments ends on the via center).
1564  // That's not ideal, and is in fact probably worse than forcing snap in
1565  // this situation.
1566 
1567 // bool do_snap = ( m_frame->Settings().m_magneticTracks == CAPTURE_CURSOR_IN_TRACK_TOOL
1568 // || m_frame->Settings().m_magneticTracks == CAPTURE_ALWAYS );
1569  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
1570  auto via = static_cast<VIA*>( aItem );
1571  wxPoint pos = via->GetPosition();
1572  TRACK* track = findTrack( via );
1573 
1574  if( track )
1575  {
1576  SEG trackSeg( track->GetStart(), track->GetEnd() );
1577  VECTOR2I snap = m_gridHelper.AlignToSegment( pos, trackSeg );
1578 
1579  aItem->SetPosition( wxPoint( snap.x, snap.y ) );
1580  }
1581  }
1582 
1583  void PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
1584  {
1585  auto via = static_cast<VIA*>( aItem );
1586  int newNet;
1587  TRACK* track = findTrack( via );
1588 
1589  if( track )
1590  {
1591  aCommit.Modify( track );
1592  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
1593  track->SetEnd( via->GetPosition() );
1594  newTrack->SetStart( via->GetPosition() );
1595  aCommit.Add( newTrack );
1596 
1597  newNet = track->GetNetCode();
1598  }
1599  else
1600  newNet = findStitchedZoneNet( via );
1601 
1602  if( newNet > 0 )
1603  via->SetNetCode( newNet );
1604 
1605  aCommit.Add( aItem );
1606  }
1607 
1608  std::unique_ptr<BOARD_ITEM> CreateItem() override
1609  {
1610  auto& ds = m_board->GetDesignSettings();
1611  VIA* via = new VIA( m_board );
1612 
1613  via->SetNetCode( 0 );
1614  via->SetViaType( ds.m_CurrentViaType );
1615 
1616  // for microvias, the size and hole will be changed later.
1617  via->SetWidth( ds.GetCurrentViaSize() );
1618  via->SetDrill( ds.GetCurrentViaDrill() );
1619 
1620  // Usual via is from copper to component.
1621  // layer pair is B_Cu and F_Cu.
1622  via->SetLayerPair( B_Cu, F_Cu );
1623 
1624  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
1625  PCB_LAYER_ID last_layer;
1626 
1627  // prepare switch to new active layer:
1628  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
1629  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
1630  else
1631  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
1632 
1633  // Adjust the actual via layer pair
1634  switch( via->GetViaType() )
1635  {
1636  case VIA_BLIND_BURIED:
1637  via->SetLayerPair( first_layer, last_layer );
1638  break;
1639 
1640  case VIA_MICROVIA: // from external to the near neighbor inner layer
1641  {
1642  PCB_LAYER_ID last_inner_layer =
1643  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
1644 
1645  if( first_layer == B_Cu )
1646  last_layer = last_inner_layer;
1647  else if( first_layer == F_Cu )
1648  last_layer = In1_Cu;
1649  else if( first_layer == last_inner_layer )
1650  last_layer = B_Cu;
1651  else if( first_layer == In1_Cu )
1652  last_layer = F_Cu;
1653 
1654  // else error: will be removed later
1655  via->SetLayerPair( first_layer, last_layer );
1656 
1657  // Update diameter and hole size, which where set previously
1658  // for normal vias
1659  NETINFO_ITEM* net = via->GetNet();
1660 
1661  if( net )
1662  {
1663  via->SetWidth( net->GetMicroViaSize() );
1664  via->SetDrill( net->GetMicroViaDrillSize() );
1665  }
1666  }
1667  break;
1668 
1669  default:
1670  break;
1671  }
1672 
1673  return std::unique_ptr<BOARD_ITEM>( via );
1674  }
1675  };
1676 
1677  VIA_PLACER placer( frame() );
1678 
1679  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
1680 
1681  frame()->SetToolID( ID_PCB_DRAW_VIA_BUTT, wxCURSOR_PENCIL, _( "Add vias" ) );
1682 
1683  doInteractiveItemPlacement( &placer, _( "Place via" ),
1685 
1686  frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
1687 
1688  return 0;
1689 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
BOARD * m_board
Definition: drawing_tool.h:263
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:462
virtual void SetPosition(const wxPoint &aPos)=0
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:122
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
int GetCopperLayerCount() const
Function GetCopperLayerCount.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
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.
const wxPoint & GetEnd() const
Definition: class_track.h:123
void SetWidth(int aWidth)
Definition: class_track.h:119
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
RAII class that sets an value at construction and resets it to the original value at destruction...
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:255
VIATYPE_T GetViaType() const
Definition: class_track.h:461
const wxPoint & GetStart() const
Definition: class_track.h:126
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:46
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
const wxPoint GetPosition() const override
Definition: class_track.h:433
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
void SetSnap(bool aSnap)
Definition: grid_helper.h:72
int GetNetCode() const
Function GetNetCode.
Definition: seg.h:36
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
ZONE_CONTAINERS & Zones()
Definition: class_board.h:257
int GetWidth() const
Definition: class_track.h:120
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:469
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:186
void SetStart(const wxPoint &aStart)
Definition: class_track.h:125
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:254
void doInteractiveItemPlacement(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...
Definition: pcb_tool.cpp:39
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:166
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
#define mod(a, n)
Definition: greymap.cpp:24
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:45
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:458
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.

Definition at line 681 of file drawing_tool.cpp.

References ADD, drawZone(), ID_PCB_ZONES_BUTT, m_frame, m_mode, PCB_BASE_FRAME::SetToolID(), and ZONE.

Referenced by setTransitions().

682 {
683  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
684 
685  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
686 
687  return drawZone( false, ZONE_MODE::ADD );
688 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
Add a new zone/keepout with fresh settings.
int DRAWING_TOOL::drawZone ( bool  aKeepout,
ZONE_MODE  aMode 
)
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 one

Definition at line 1331 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), ADD, POLYGON_GEOM_MANAGER::AddPoint(), GRID_HELPER::BestSnapAnchor(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), closeZoneOutline, CUTOUT, POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, STATUS_POPUP::Expire(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL::frame(), PCB_BASE_FRAME::GetActiveLayer(), getDrawingLayer(), ZONE_CONTAINER::GetLayer(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSourceZoneForAction(), GRAPHIC_POLYGON, TOOL_EVT_UTILS::IsCancelInteractive(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), PCB_ACTIONS::layerChanged, m_controls, m_frame, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_layer, PCB_TOOL::m_menu, ZONE_CREATE_HELPER::PARAMS::m_mode, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, TOOL_BASE::m_toolMgr, MD_ALT, MD_CTRL, MD_SHIFT, STATUS_POPUP::Move(), POLYGON_GEOM_MANAGER::NewPointClosesOutline(), STATUS_POPUP::Popup(), POLYGON_GEOM_MANAGER::Reset(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), POLYGON_GEOM_MANAGER::SetCursorPosition(), POLYGON_GEOM_MANAGER::SetFinished(), EDA_DRAW_FRAME::SetNoToolSelected(), GRID_HELPER::SetSnap(), KIGFX::VIEW_CONTROLS::SetSnapping(), STATUS_TEXT_POPUP::SetText(), STATUS_TEXT_POPUP::SetTextColor(), GRID_HELPER::SetUseGrid(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), SIMILAR, and TOOL_INTERACTIVE::Wait().

Referenced by DrawGraphicPolygon(), DrawSimilarZone(), DrawZone(), DrawZoneCutout(), and DrawZoneKeepout().

1332 {
1333  // get a source zone, if we need one. We need it for:
1334  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1335  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1336  ZONE_CONTAINER* sourceZone = nullptr;
1337 
1338  if( !getSourceZoneForAction( aMode, sourceZone ) )
1339  {
1341  return 0;
1342  }
1343 
1345 
1346  params.m_keepout = aKeepout;
1347  params.m_mode = aMode;
1348  params.m_sourceZone = sourceZone;
1349 
1350  if( aMode == ZONE_MODE::GRAPHIC_POLYGON )
1351  params.m_layer = getDrawingLayer();
1352  else if( aMode == ZONE_MODE::SIMILAR )
1353  params.m_layer = sourceZone->GetLayer();
1354  else
1355  params.m_layer = m_frame->GetActiveLayer();
1356 
1357  ZONE_CREATE_HELPER zoneTool( *this, params );
1358 
1359  // the geometry manager which handles the zone geometry, and
1360  // hands the calculated points over to the zone creator tool
1361  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1362 
1363  Activate(); // register for events
1364 
1365  m_controls->ShowCursor( true );
1366  m_controls->SetSnapping( true );
1367 
1368  bool started = false;
1369  GRID_HELPER grid( m_frame );
1370  STATUS_TEXT_POPUP status( m_frame );
1371  status.SetTextColor( wxColour( 255, 0, 0 ) );
1372  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
1373 
1374  while( OPT_TOOL_EVENT evt = Wait() )
1375  {
1376  LSET layers( m_frame->GetActiveLayer() );
1377  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1378  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1379  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1380  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), layers );
1381  m_controls->ForceCursorPosition( true, cursorPos );
1382 
1384  {
1385  // pre-empted by another tool, give up
1386  // cancelled without an inprogress polygon, give up
1387  if( !polyGeomMgr.IsPolygonInProgress() || evt->IsActivate() )
1388  {
1389  break;
1390  }
1391 
1392  polyGeomMgr.Reset();
1393  // start again
1394  started = false;
1395 
1396  m_controls->SetAutoPan( false );
1397  m_controls->CaptureCursor( false );
1398  }
1399  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1400  {
1401  if( aMode == ZONE_MODE::GRAPHIC_POLYGON )
1402  params.m_layer = getDrawingLayer();
1403  else if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::CUTOUT )
1404  params.m_layer = frame()->GetActiveLayer();
1405  }
1406  else if( evt->IsClick( BUT_RIGHT ) )
1407  {
1409  }
1410  // events that lock in nodes
1411  else if( evt->IsClick( BUT_LEFT )
1412  || evt->IsDblClick( BUT_LEFT )
1413  || evt->IsAction( &closeZoneOutline ) )
1414  {
1415  // Check if it is double click / closing line (so we have to finish the zone)
1416  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
1417  || evt->IsAction( &closeZoneOutline )
1418  || polyGeomMgr.NewPointClosesOutline( cursorPos );
1419 
1420  if( endPolygon )
1421  {
1422  polyGeomMgr.SetFinished();
1423  polyGeomMgr.Reset();
1424 
1425  // ready to start again
1426  started = false;
1427  m_controls->SetAutoPan( false );
1428  m_controls->CaptureCursor( false );
1429  }
1430 
1431  // adding a corner
1432  else if( polyGeomMgr.AddPoint( cursorPos ) )
1433  {
1434  if( !started )
1435  {
1436  started = true;
1437  m_controls->SetAutoPan( true );
1438  m_controls->CaptureCursor( true );
1439  }
1440  }
1441 
1442  }
1443  else if( evt->IsAction( &deleteLastPoint ) )
1444  {
1445  polyGeomMgr.DeleteLastCorner();
1446 
1447  if( !polyGeomMgr.IsPolygonInProgress() )
1448  {
1449  // report finished as an empty shape
1450  polyGeomMgr.SetFinished();
1451 
1452  // start again
1453  started = false;
1454  m_controls->SetAutoPan( false );
1455  m_controls->CaptureCursor( false );
1456  }
1457  }
1458  else if( polyGeomMgr.IsPolygonInProgress()
1459  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1460  {
1461  polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
1464 
1465  if( polyGeomMgr.IsSelfIntersecting( true ) )
1466  {
1467  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
1468  status.Move( p );
1469  status.Popup( m_frame );
1470  status.Expire( 1500 );
1471  }
1472  else
1473  {
1474  status.Hide();
1475  }
1476  }
1477  } // end while
1478 
1481  m_controls->ForceCursorPosition( false );
1482 
1483  return 0;
1484 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
static TOOL_ACTION closeZoneOutline("pcbnew.InteractiveDrawing.closeZoneOutline", AS_CONTEXT, 0, _("Close Zone Outline"), _("Close the outline of a zone in progress"), checked_ok_xpm)
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
static TOOL_ACTION deleteLastPoint("pcbnew.InteractiveDrawing.deleteLastPoint", AS_CONTEXT, WXK_BACK, _("Delete Last Point"), _("Delete the last point added to the current item"), undo_xpm)
Class STATUS_TEXT_POPUP.
Definition: status_popup.h:79
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
PCB_LAYER_ID m_layer
Layer to begin drawing
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
Function getSourceZoneForAction()
Parameters used to fully describe a zone creation process.
Add a new zone with the same settings as an existing one.
Unconstrained point-to-point
Class LSET is a set of PCB_LAYER_IDs.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
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:262
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
DRAWING_TOOL::ZONE_MODE m_mode
The zone mode to operate in
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry ...
void Activate()
Function Activate() Runs the tool.
bool m_keepout
Should create a keepout zone?
Add a new zone/keepout with fresh settings.
Make a cutout to an existing zone.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
int DRAWING_TOOL::DrawZoneCutout ( const TOOL_EVENT aEvent)

Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone.

The normal zone interactive tool is used, but the zone settings dialog is not shown (since the cutout affects only shape of an existing zone).

Definition at line 701 of file drawing_tool.cpp.

References CUTOUT, drawZone(), ID_PCB_ZONES_BUTT, m_frame, m_mode, PCB_BASE_FRAME::SetToolID(), and ZONE.

Referenced by setTransitions().

702 {
703  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
704 
705  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zone cutout" ) );
706 
707  return drawZone( false, ZONE_MODE::CUTOUT );
708 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
Make a cutout to an existing zone.
int DRAWING_TOOL::DrawZoneKeepout ( const TOOL_EVENT aEvent)

Function DrawZoneKeepout() Starts interactively drawing a keepout area.

After invoking the function an area 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 area. Double click or clicking on the origin of the boundary polyline finishes the drawing.

Definition at line 691 of file drawing_tool.cpp.

References ADD, drawZone(), ID_PCB_KEEPOUT_AREA_BUTT, KEEPOUT, m_frame, m_mode, and PCB_BASE_FRAME::SetToolID().

Referenced by setTransitions().

692 {
693  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::KEEPOUT );
694 
695  m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
696 
697  return drawZone( true, ZONE_MODE::ADD );
698 }
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
RAII class that sets an value at construction and resets it to the original value at destruction...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
Add a new zone/keepout with fresh settings.
bool PCB_TOOL::EditingModules ( ) const
inlineinherited
const TOOL_EVENT TOOL_INTERACTIVE::evActivate ( std::string  aToolName = "")
protectedinherited

functions below are not yet implemented - their interface may change

const TOOL_EVENT TOOL_INTERACTIVE::evButtonDown ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evButtonUp ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evClick ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( int  aCommandId = -1)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( std::string  aCommandStr = "")
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evDrag ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evMotion ( )
protectedinherited
PCB_EDIT_FRAME* PCB_TOOL::frame ( ) const
inlineprotectedinherited

Definition at line 139 of file pcb_tool.h.

Referenced by POINT_EDITOR::addCorner(), MICROWAVE_TOOL::addMicrowaveFootprint(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL::canvas(), EDIT_TOOL::changeTrackWidthOnClick(), PNS::TOOL_BASE::checkSnap(), PCB_EDITOR_CONTROL::ClearHighlight(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_TOOL::displayOptions(), EDIT_TOOL::doCopyToClipboard(), PCB_TOOL::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawVia(), drawZone(), MODULE_EDITOR_TOOLS::EnumeratePads(), EDIT_TOOL::ExchangeFootprints(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ROUTER_TOOL::finishInteractive(), getMicrowaveItemCreator(), highlightNet(), PAD_TOOL::Init(), EDIT_TOOL::Init(), SELECTION_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PICKER_TOOL::Main(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PasteItemsFromClipboard(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), MODULE_EDITOR_TOOLS::PlacePad(), PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::RouteDiffPair(), ROUTER_TOOL::RouteSingleTrace(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ROUTER_TOOL::SettingsDialog(), ROUTER_TOOL::switchLayerOnViaPlacement(), LENGTH_TUNER_TOOL::TuneDiffPair(), LENGTH_TUNER_TOOL::TuneDiffPairSkew(), LENGTH_TUNER_TOOL::TuneSingleTrace(), POINT_EDITOR::updateItem(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

139 { return getEditFrame<PCB_EDIT_FRAME>(); }
PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer ( ) const
private

Selects a non-copper layer for drawing

Definition at line 1717 of file drawing_tool.cpp.

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

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

1718 {
1719  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1720 
1721  if( IsCopperLayer( layer ) )
1722  {
1723  if( layer == F_Cu )
1724  layer = F_SilkS;
1725  else if( layer == B_Cu )
1726  layer = B_SilkS;
1727  else
1728  layer = Dwgs_User;
1729 
1730  m_frame->SetActiveLayer( layer );
1731  }
1732 
1733  return layer;
1734 }
PCB_LAYER_ID
A quick note on layer IDs:
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
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 212 of file drawing_tool.cpp.

References m_mode.

Referenced by PCB_EDITOR_CONTROL::Init().

213 {
214  return m_mode;
215 }
template<typename T >
T* TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Function getEditFrame()

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

Definition at line 188 of file tool_base.h.

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

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

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

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 122 of file tool_base.h.

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

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

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

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

Definition at line 144 of file tool_base.h.

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

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

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 199 of file tool_base.h.

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

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

Function GetName() Returns the name of the tool.

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

Returns
The name of the tool.

Definition at line 133 of file tool_base.h.

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

134  {
135  return m_toolName;
136  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:214
int DRAWING_TOOL::getSegmentWidth ( PCB_LAYER_ID  aLayer) const
private

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

Definition at line 1710 of file drawing_tool.cpp.

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

Referenced by drawArc(), and drawSegment().

1711 {
1712  assert( m_board );
1713  return m_board->GetDesignSettings().GetLineThickness( aLayer );
1714 }
BOARD * m_board
Definition: drawing_tool.h:263
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 77 of file tool_base.cpp.

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

78 {
79  return m_toolSettings;
80 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:216
bool DRAWING_TOOL::getSourceZoneForAction ( ZONE_MODE  aMode,
ZONE_CONTAINER *&  aZone 
)
private

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

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

Referenced by drawZone().

1298 {
1299  bool clearSelection = false;
1300  aZone = nullptr;
1301 
1302  // not an action that needs a source zone
1303  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1304  return true;
1305 
1307  const SELECTION& selection = selTool->GetSelection();
1308 
1309  if( selection.Empty() )
1310  {
1311  clearSelection = true;
1313  }
1314 
1315  // we want a single zone
1316  if( selection.Size() == 1 )
1317  aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
1318 
1319  // expected a zone, but didn't get one
1320  if( !aZone )
1321  {
1322  if( clearSelection )
1324 
1325  return false;
1326  }
1327 
1328  return true;
1329 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION & GetSelection()
Function GetSelection()
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
Add a new zone/keepout with fresh settings.
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50
TOOL_MENU& DRAWING_TOOL::GetToolMenu ( )
inline

Get the DRAWING_TOOL top-level context menu

Definition at line 62 of file drawing_tool.h.

Referenced by PCB_EDITOR_CONTROL::Init().

63  {
64  return m_menu;
65  }
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 111 of file tool_base.h.

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

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

Function getView()

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

Returns
The instance of VIEW.

Definition at line 35 of file tool_base.cpp.

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

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

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

Function getViewControls()

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

Returns
The instance of VIEW_CONTROLS.

Definition at line 41 of file tool_base.cpp.

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

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

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

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

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

Reimplemented from PCB_TOOL.

Definition at line 164 of file drawing_tool.cpp.

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

165 {
166  auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
167  return m_mode != MODE::NONE;
168  };
169 
170  // some interactive drawing tools can undo the last point
171  auto canUndoPoint = [ this ] ( const SELECTION& aSel ) {
172  return m_mode == MODE::ARC || m_mode == MODE::ZONE;
173  };
174 
175  // functor for zone-only actions
176  auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) {
177  return m_mode == MODE::ZONE;
178  };
179 
180  auto& ctxMenu = m_menu.GetMenu();
181 
182  // cancel current tool goes in main context menu at the top if present
183  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
184  ctxMenu.AddSeparator( activeToolFunctor, 1 );
185 
186  // tool-specific actions
187  ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 200 );
188  ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 200 );
189 
190  ctxMenu.AddSeparator( canUndoPoint, 500 );
191 
192  // Type-specific sub-menus will be added for us by other tools
193  // For example, zone fill/unfill is provided by the PCB control tool
194 
195  // Finally, add the standard zoom/grid items
196  m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
197 
198  return true;
199 }
static TOOL_ACTION closeZoneOutline("pcbnew.InteractiveDrawing.closeZoneOutline", AS_CONTEXT, 0, _("Close Zone Outline"), _("Close the outline of a zone in progress"), checked_ok_xpm)
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
static TOOL_ACTION deleteLastPoint("pcbnew.InteractiveDrawing.deleteLastPoint", AS_CONTEXT, WXK_BACK, _("Delete Last Point"), _("Delete the last point added to the current item"), undo_xpm)
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
static TOOL_ACTION cancelInteractive
Definition: actions.h:45
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 30 of file tool_base.cpp.

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

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

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

Definition at line 735 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), BUT_LEFT, BUT_RIGHT, delta, DXF, PCB_ACTIONS::flip, Flip(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), SELECTION::Front(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), DIALOG_IMPORT_GFX::GetImportedItems(), PCB_BASE_EDIT_FRAME::GetModel(), BOARD_ITEM::GetPosition(), TOOL_EVT_UTILS::IsCancelInteractive(), DIALOG_IMPORT_GFX::IsPlacementInteractive(), TOOL_EVT_UTILS::IsRotateToolEvt(), m_controls, PCB_TOOL::m_editModules, m_frame, PCB_TOOL::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PCB_TEXT_T, BOARD_COMMIT::Push(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, EDA_DRAW_FRAME::SetNoToolSelected(), KIGFX::VIEW_CONTROLS::SetSnapping(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_COMMAND, EDA_ITEM::Type(), KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setTransitions().

736 {
737  if( !m_frame->GetModel() )
738  return 0;
739 
740  // Note: PlaceImportedGraphics() will convert PCB_LINE_T and PCB_TEXT_T to module graphic items
741  // if needed
743  int dlgResult = dlg.ShowModal();
744 
745  auto& list = dlg.GetImportedItems();
746 
747  if( dlgResult != wxID_OK )
748  return 0;
749 
750  // Ensure the list is not empty:
751  if( list.empty() )
752  {
753  wxMessageBox( _( "No graphic items found in file to import") );
754  return 0;
755  }
756 
757 
759 
760  // Add a VIEW_GROUP that serves as a preview for the new item
761  SELECTION preview;
762  BOARD_COMMIT commit( m_frame );
763 
764  // Build the undo list & add items to the current view
765  for( auto it = list.begin(), itEnd = list.end(); it != itEnd; ++it )
766  {
767  EDA_ITEM* item = it->get();
768 
769  if( m_editModules )
770  {
771  wxASSERT( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_MODULE_TEXT_T );
772  }
773  else
774  {
775  wxASSERT( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
776  }
777 
778  if( dlg.IsPlacementInteractive() )
779  preview.Add( item );
780  else
781  commit.Add( item );
782 
783  it->release();
784  }
785 
786  if( !dlg.IsPlacementInteractive() )
787  {
788  commit.Push( _( "Place a DXF_SVG drawing" ) );
789  return 0;
790  }
791 
792  BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
793  m_view->Add( &preview );
794 
796  m_controls->ShowCursor( true );
797  m_controls->SetSnapping( true );
799 
800  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
801 
802  // Now move the new items to the current cursor position:
803  VECTOR2I cursorPos = m_controls->GetCursorPosition();
804  VECTOR2I delta = cursorPos - firstItem->GetPosition();
805 
806  for( auto item : preview )
807  static_cast<BOARD_ITEM*>( item )->Move( wxPoint( delta.x, delta.y ) );
808 
809  m_view->Update( &preview );
810 
811  Activate();
812 
813  // Main loop: keep receiving events
814  while( OPT_TOOL_EVENT evt = Wait() )
815  {
816  cursorPos = m_controls->GetCursorPosition();
817 
818  if( evt->IsMotion() )
819  {
820  delta = cursorPos - firstItem->GetPosition();
821 
822  for( auto item : preview )
823  static_cast<BOARD_ITEM*>( item )->Move( wxPoint( delta.x, delta.y ) );
824 
825  m_view->Update( &preview );
826  }
827  else if( evt->Category() == TC_COMMAND )
828  {
829  // TODO it should be handled by EDIT_TOOL, so add items and select?
830  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
831  {
832  const auto rotationPoint = wxPoint( cursorPos.x, cursorPos.y );
833  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
834  *m_frame, *evt );
835 
836  for( auto item : preview )
837  {
838  static_cast<BOARD_ITEM*>( item )->Rotate( rotationPoint, rotationAngle );
839  }
840 
841  m_view->Update( &preview );
842  }
843  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
844  {
845  for( auto item : preview )
846  static_cast<BOARD_ITEM*>( item )->Flip( wxPoint( cursorPos.x, cursorPos.y ) );
847 
848  m_view->Update( &preview );
849  }
850  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
851  {
852  preview.FreeItems();
853  break;
854  }
855  }
856  else if( evt->IsClick( BUT_RIGHT ) )
857  {
859  }
860  else if( evt->IsClick( BUT_LEFT ) )
861  {
862  // Place the imported drawings
863  for( auto item : preview )
864  commit.Add( item );
865 
866  commit.Push( _( "Place a DXF_SVG drawing" ) );
867  break;
868  }
869  }
870 
871  preview.Clear();
872  m_view->Remove( &preview );
873 
874  return 0;
875 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_ITEM * Front() const
Definition: selection.h:152
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:375
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
static const int delta[8][2]
Definition: solve.cpp:112
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
RAII class that sets an value at construction and resets it to the original value at destruction...
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
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:262
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
virtual const wxPoint GetPosition() const =0
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:345
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void Flip(T &aValue)
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
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 318 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), COMMIT::Add(), PCB_TOOL::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), EDA_ITEM::ClearFlags(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL::frame(), PCB_BASE_FRAME::GetActiveLayer(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetDesignSettings(), PCB_BASE_EDIT_FRAME::GetModel(), BOARD_ITEM::GetPosition(), SELECTION_TOOL::GetSelection(), EDA_TEXT::GetText(), BOARD_DESIGN_SETTINGS::GetTextItalic(), BOARD_DESIGN_SETTINGS::GetTextSize(), BOARD_DESIGN_SETTINGS::GetTextThickness(), BOARD_DESIGN_SETTINGS::GetTextUpright(), TOOL_MANAGER::GetTool(), ID_MODEDIT_TEXT_TOOL, ID_PCB_ADD_TEXT_BUTT, PCB_BASE_EDIT_FRAME::InstallTextOptionsFrame(), IS_NEW, IsBackLayer(), TOOL_EVT_UTILS::IsCancelInteractive(), m_controls, PCB_TOOL::m_editModules, m_frame, PCB_TOOL::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOL_MANAGER::RunAction(), TOOL_INTERACTIVE::RunMainStack(), PCB_TOOL::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_ITEM::SetFlags(), EDA_TEXT::SetItalic(), TEXTE_MODULE::SetKeepUpright(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), EDA_DRAW_FRAME::SetMsgPanel(), EDA_DRAW_FRAME::SetNoToolSelected(), BOARD_ITEM::SetPosition(), KIGFX::VIEW_CONTROLS::SetSnapping(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), PCB_BASE_FRAME::SetToolID(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), TEXT, KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), KIGFX::VIEW_CONTROLS::WarpCursor(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setTransitions().

319 {
320  if( m_editModules && !m_frame->GetModel() )
321  return 0;
322 
323  BOARD_ITEM* text = NULL;
324  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
326  SELECTION& selection = selTool->GetSelection();
327  BOARD_COMMIT commit( m_frame );
328 
330  m_controls->ShowCursor( true );
331  m_controls->SetSnapping( true );
332  // do not capture or auto-pan until we start placing some text
333 
334  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
335 
336  Activate();
338  wxCURSOR_PENCIL, _( "Add text" ) );
339 
340  bool reselect = false;
341 
342  // Main loop: keep receiving events
343  while( OPT_TOOL_EVENT evt = Wait() )
344  {
345  VECTOR2I cursorPos = m_controls->GetCursorPosition();
346 
347  if( reselect && text )
349 
351  {
352  if( text )
353  {
355 
356  // Delete the old text and have another try
357  delete text;
358  text = NULL;
359 
360  m_controls->SetAutoPan( false );
361  m_controls->CaptureCursor( false );
362  m_controls->ShowCursor( true );
363  }
364  else
365  break;
366 
367  if( evt->IsActivate() ) // now finish unconditionally
368  break;
369  }
370  else if( evt->IsClick( BUT_RIGHT ) )
371  {
373  }
374  else if( evt->IsClick( BUT_LEFT ) )
375  {
376  if( !text )
377  {
380 
381  // Init the new item attributes
382  if( m_editModules )
383  {
384  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() );
385 
386  textMod->SetLayer( layer );
387  textMod->SetTextSize( dsnSettings.GetTextSize( layer ) );
388  textMod->SetThickness( dsnSettings.GetTextThickness( layer ) );
389  textMod->SetItalic( dsnSettings.GetTextItalic( layer ) );
390  textMod->SetKeepUpright( dsnSettings.GetTextUpright( layer ) );
391  textMod->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
392 
393  DIALOG_TEXT_PROPERTIES textDialog( m_frame, textMod, NULL );
394  bool placing;
395 
396  RunMainStack([&]() {
397  placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 );
398  } );
399 
400  if( placing )
401  text = textMod;
402  else
403  delete textMod;
404  }
405  else
406  {
407  TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() );
408  // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
409  textPcb->SetFlags( IS_NEW );
410 
411  textPcb->SetLayer( layer );
412 
413  // Set the mirrored option for layers on the BACK side of the board
414  if( IsBackLayer( layer ) )
415  textPcb->SetMirrored( true );
416 
417  textPcb->SetTextSize( dsnSettings.GetTextSize( layer ) );
418  textPcb->SetThickness( dsnSettings.GetTextThickness( layer ) );
419  textPcb->SetItalic( dsnSettings.GetTextItalic( layer ) );
420  textPcb->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
421 
422  RunMainStack([&]() {
423  m_frame->InstallTextOptionsFrame( textPcb, NULL );
424  } );
425 
426  if( textPcb->GetText().IsEmpty() )
427  delete textPcb;
428  else
429  text = textPcb;
430  }
431 
432  if( text == NULL )
433  continue;
434 
435  m_controls->WarpCursor( text->GetPosition(), true );
437  m_controls->CaptureCursor( true );
438  m_controls->SetAutoPan( true );
439 
441  }
442  else
443  {
444  text->ClearFlags();
446 
447  commit.Add( text );
448  commit.Push( _( "Place a text" ) );
449 
450  m_controls->CaptureCursor( false );
451  m_controls->SetAutoPan( false );
452  m_controls->ShowCursor( true );
453 
454  text = NULL;
455  }
456  }
457  else if( text && evt->IsMotion() )
458  {
459  text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
460  selection.SetReferencePoint( cursorPos );
461  m_view->Update( &selection );
462  frame()->SetMsgPanel( text );
463  }
464 
465  else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
466  {
467  // Calling 'Properties' action clears the selection, so we need to restore it
468  reselect = true;
469  }
470  }
471 
472  frame()->SetMsgPanel( board() );
474 
475  return 0;
476 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:191
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
void SetKeepUpright(bool aKeepUpright)
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual void SetPosition(const wxPoint &aPos)=0
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;s a back layer.
Class SELECTION_TOOL.
void SetItalic(bool isItalic)
Definition: eda_text.h:182
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:111
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
void InstallTextOptionsFrame(BOARD_ITEM *aText, wxDC *aDC)
Routine for main window class to launch text properties dialog.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
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...
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
SELECTION & GetSelection()
Function GetSelection()
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
virtual const wxPoint GetPosition() const =0
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
bool m_editModules
Definition: pcb_tool.h:150
bool GetTextUpright(PCB_LAYER_ID aLayer) const
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
BOARD * board() const
Definition: pcb_tool.h:140
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.

Definition at line 202 of file drawing_tool.cpp.

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

203 {
204  // Init variables used by every drawing tool
205  m_view = getView();
207  m_board = getModel<BOARD>();
208  m_frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
209 }
BOARD * m_board
Definition: drawing_tool.h:263
KIGFX::VIEW * m_view
Definition: drawing_tool.h:261
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:264
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
void TOOL_INTERACTIVE::RunMainStack ( std::function< void()>  aFunc)
inherited

Function RunMainStack()

Calls a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 85 of file tool_interactive.cpp.

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

Referenced by PlaceText().

86 {
87  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
88 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
void DRAWING_TOOL::runPolygonEventLoop ( POLYGON_GEOM_MANAGER aPolyGeomMgr)
private

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

const SELECTION & PCB_TOOL::selection ( ) const
protectedinherited

Definition at line 245 of file pcb_tool.cpp.

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_EDITOR_CONTROL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::CreateArray(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_EDITOR_CONTROL::CrossProbePcbToSch(), deleteItem(), EDIT_TOOL::doCopyToClipboard(), EDIT_TOOL::Duplicate(), EDIT_TOOL::editFootprintInFpEditor(), EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::expandSelectedConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::filterSelection(), EDIT_TOOL::Flip(), getSourceZoneForAction(), highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EDIT_TOOL::Rotate(), ZONE_FILLER_TOOL::SegzoneDeleteFill(), SELECTION_TOOL::selectCopper(), PCB_TOOL::selection(), SELECTION_TOOL::selectNet(), showLocalRatsnest(), PCB_EDITOR_CONTROL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

246 {
247  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
248  const auto& selection = selTool->GetSelection();
249  return selection;
250 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
SELECTION & PCB_TOOL::selection ( )
protectedinherited

Definition at line 252 of file pcb_tool.cpp.

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

253 {
254  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
255  auto& selection = selTool->GetSelection();
256  return selection;
257 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
int DRAWING_TOOL::SetAnchor ( const TOOL_EVENT aEvent)

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

Definition at line 878 of file drawing_tool.cpp.

References TOOL_INTERACTIVE::Activate(), ANCHOR, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_EDIT_FRAME::GetModel(), MODULE::GetPosition(), ID_MODEDIT_ANCHOR_TOOL, TOOL_EVT_UTILS::IsCancelInteractive(), m_controls, PCB_TOOL::m_editModules, m_frame, PCB_TOOL::m_menu, m_mode, COMMIT::Modify(), PCB_TOOL::module(), MODULE::MoveAnchorPosition(), BOARD_COMMIT::Push(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_FRAME::SetNoToolSelected(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::SetToolID(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setTransitions().

879 {
880  assert( m_editModules );
881 
882  if( !m_frame->GetModel() )
883  return 0;
884 
885  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
886 
887  Activate();
888  m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL,
889  _( "Place the footprint anchor" ) );
890 
891  m_controls->ShowCursor( true );
892  m_controls->SetSnapping( true );
893  m_controls->SetAutoPan( true );
894  m_controls->CaptureCursor( false );
895 
896  while( OPT_TOOL_EVENT evt = Wait() )
897  {
898  if( evt->IsClick( BUT_LEFT ) )
899  {
901  BOARD_COMMIT commit( m_frame );
902  commit.Modify( module );
903 
904  // set the new relative internal local coordinates of footprint items
905  VECTOR2I cursorPos = m_controls->GetCursorPosition();
906  wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
907  module->MoveAnchorPosition( moveVector );
908 
909  commit.Push( _( "Move the footprint reference anchor" ) );
910 
911  // Usually, we do not need to change twice the anchor position,
912  // so deselect the active tool
913  break;
914  }
915  else if( evt->IsClick( BUT_RIGHT ) )
916  {
918  }
919  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
920  break;
921  }
922 
924 
925  return 0;
926 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
void MoveAnchorPosition(const wxPoint &aMoveVector)
Function MoveAnchorPosition Move the reference point of the footprint It looks like a move footprint:...
RAII class that sets an value at construction and resets it to the original value at destruction...
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
MODULE * module() const
Definition: pcb_tool.h:141
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:262
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
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:264
bool m_editModules
Definition: pcb_tool.h:150
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
const wxPoint GetPosition() const override
Definition: class_module.h:183
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
void TOOL_INTERACTIVE::SetContextMenu ( CONTEXT_MENU aMenu,
CONTEXT_MENU_TRIGGER  aTrigger = CMENU_BUTTON 
)
inherited

Function SetContextMenu()

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

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

Definition at line 74 of file tool_interactive.cpp.

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

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

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

Function SetEditModules()

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

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 97 of file pcb_tool.h.

98  {
99  m_editModules = aEnabled;
100  }
bool m_editModules
Definition: pcb_tool.h:150
void DRAWING_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from PCB_TOOL.

Definition at line 1692 of file drawing_tool.cpp.

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

1693 {
1707 }
static TOOL_ACTION drawLine
Activation of the drawing tool (line)
Definition: pcb_actions.h:147
int DrawCircle(const TOOL_EVENT &aEvent)
Function DrawCircle() Starts interactively drawing a circle.
static TOOL_ACTION placeImportedGraphics
Activation of the drawing tool (placing a drawing imported from DXF or SVG file)
Definition: pcb_actions.h:186
int DrawVia(const TOOL_EVENT &aEvent)
int DrawZone(const TOOL_EVENT &aEvent)
Function DrawZone() Starts interactively drawing a zone.
static TOOL_ACTION drawSimilarZone
Activation of the drawing tool (drawing a similar ZONE to another one)
Definition: pcb_actions.h:177
static TOOL_ACTION drawArc
Activation of the drawing tool (arc)
Definition: pcb_actions.h:156
int DrawLine(const TOOL_EVENT &aEvent)
Function DrawLine() Starts interactively drawing a line.
static TOOL_ACTION drawZoneKeepout
Activation of the drawing tool (drawing a keepout area)
Definition: pcb_actions.h:171
static TOOL_ACTION setAnchor
Activation of the drawing tool (placing the footprint anchor)
Definition: pcb_actions.h:189
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION placeText
Activation of the drawing tool (text)
Definition: pcb_actions.h:159
static TOOL_ACTION drawGraphicPolygon
Definition: pcb_actions.h:150
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor...
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets t...
static TOOL_ACTION drawDimension
Activation of the drawing tool (dimension)
Definition: pcb_actions.h:162
int DrawZoneKeepout(const TOOL_EVENT &aEvent)
Function DrawZoneKeepout() Starts interactively drawing a keepout area.
static TOOL_ACTION drawVia
Activation of the drawing tool (drawing a VIA)
Definition: pcb_actions.h:168
static TOOL_ACTION drawZoneCutout
Activation of the drawing tool (drawing a ZONE cutout)
Definition: pcb_actions.h:174
int DrawZoneCutout(const TOOL_EVENT &aEvent)
Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone...
static TOOL_ACTION drawCircle
Activation of the drawing tool (circle)
Definition: pcb_actions.h:153
int SetAnchor(const TOOL_EVENT &aEvent)
Function SetAnchor() Places the footprint anchor (only in module editor).
int DrawGraphicPolygon(const TOOL_EVENT &aEvent)
int DrawSimilarZone(const TOOL_EVENT &aEvent)
Function DrawSimilarZone() Starts interactively drawing a zone with same settings as an existing zone...
int DrawArc(const TOOL_EVENT &aEvent)
Function DrawArc() Starts interactively drawing an arc.
static TOOL_ACTION drawZone
Activation of the drawing tool (drawing a ZONE)
Definition: pcb_actions.h:165
int DrawDimension(const TOOL_EVENT &aEvent)
Function DrawDimension() Starts interactively drawing a dimension.
OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST aEventList = TOOL_EVENTTC_ANYTA_ANY ))
inherited

Function Wait()

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

Definition at line 55 of file tool_interactive.cpp.

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

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

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

Friends And Related Function Documentation

friend class ZONE_CREATE_HELPER
friend

Definition at line 275 of file drawing_tool.h.

Member Data Documentation

BOARD* DRAWING_TOOL::m_board
private

Definition at line 263 of file drawing_tool.h.

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

KIGFX::VIEW_CONTROLS* DRAWING_TOOL::m_controls
private
unsigned int DRAWING_TOOL::m_lineWidth
private

Stores the current line width for multisegment drawing.

Definition at line 268 of file drawing_tool.h.

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

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 210 of file tool_base.h.

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

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 215 of file tool_base.h.

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

std::string TOOL_BASE::m_toolName
protectedinherited

Name of the tool.

Names are expected to obey the format application.ToolName

(eg. pcbnew.InteractiveSelection).

Definition at line 214 of file tool_base.h.

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 216 of file tool_base.h.

Referenced by TOOL_BASE::attachManager().

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 207 of file tool_base.h.

KIGFX::VIEW* DRAWING_TOOL::m_view
private
const unsigned int DRAWING_TOOL::WIDTH_STEP = 100000
staticprivate

Definition at line 271 of file drawing_tool.h.

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


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