KiCad PCB EDA Suite
DRAWING_TOOL Class Reference

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

#include <drawing_tool.h>

Inheritance diagram for DRAWING_TOOL:
PCB_TOOL_BASE TOOL_INTERACTIVE TOOL_BASE

Public Types

enum  MODE {
  MODE::NONE, MODE::LINE, MODE::RECTANGLE, MODE::CIRCLE,
  MODE::ARC, MODE::TEXT, MODE::ANCHOR, MODE::DXF,
  MODE::DIMENSION, MODE::KEEPOUT, MODE::ZONE, MODE::GRAPHIC_POLYGON,
  MODE::VIA
}
 
enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 Determine the reason of reset for a tool. More...
 

Public Member Functions

 DRAWING_TOOL ()
 
 ~DRAWING_TOOL ()
 
bool Init () override
 Init() is called once upon a registration of the tool. More...
 
void Reset (RESET_REASON aReason) override
 Bring the tool to a known, initial state. More...
 
MODE GetDrawingMode () const
 Return the current drawing mode of the DRAWING_TOOL or #MODE::NONE if not currently in any drawing mode. More...
 
std::vector< BOARD_ITEM * > DrawBoardCharacteristics (const wxPoint &origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
 
std::vector< BOARD_ITEM * > DrawSpecificationStackup (const wxPoint &origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
 
int PlaceCharacteristics (const TOOL_EVENT &aEvent)
 
int PlaceStackup (const TOOL_EVENT &aEvent)
 
int DrawLine (const TOOL_EVENT &aEvent)
 Start interactively drawing a line. More...
 
int DrawRectangle (const TOOL_EVENT &aEvent)
 Start interactively drawing a rectangle. More...
 
int DrawCircle (const TOOL_EVENT &aEvent)
 Start interactively drawing a circle. More...
 
int DrawArc (const TOOL_EVENT &aEvent)
 Start interactively drawing an arc. More...
 
int PlaceText (const TOOL_EVENT &aEvent)
 Display 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)
 Start interactively drawing a dimension. More...
 
int DrawZone (const TOOL_EVENT &aEvent)
 Start interactively drawing a zone. More...
 
int DrawVia (const TOOL_EVENT &aEvent)
 
int PlaceImportedGraphics (const TOOL_EVENT &aEvent)
 Place a drawing imported from a DXF or SVG file in footprint editor. More...
 
int InteractivePlaceWithPreview (const TOOL_EVENT &aEvent, std::vector< BOARD_ITEM * > &aItems, std::vector< BOARD_ITEM * > &aPreview, LSET *aLayers)
 Interactively place a set of BOARD_ITEM. More...
 
int SetAnchor (const TOOL_EVENT &aEvent)
 Place the footprint anchor (only in footprint editor). More...
 
int ToggleLine45degMode (const TOOL_EVENT &aEvent)
 Toggle the 45 degree angle constraint for graphic lines. More...
 
void setTransitions () override
 This method is meant to be overridden in order to specify handlers for events. More...
 
void SetIsFootprintEditor (bool aEnabled)
 Function SetIsFootprintEditor() More...
 
bool IsFootprintEditor () const
 
bool Is45Limited () const
 Should the tool use its 45° mode option? More...
 
void Activate ()
 Run the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Assign a context menu and tells when it should be activated. More...
 
void RunMainStack (std::function< void()> aFunc)
 Call a function using the main stack. More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Define which state (aStateFunc) to go when a certain event arrives (aConditions). More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Suspend execution of the tool until an event specified in aEventList arrives. More...
 
TOOL_TYPE GetType () const
 Return the type of the tool. More...
 
TOOL_ID GetId () const
 Return the unique identifier of the tool. More...
 
const std::string & GetName () const
 Return the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Return the instance of TOOL_MANAGER that takes care of the tool. More...
 
bool IsToolActive () const
 

Protected Types

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

Protected Member Functions

void doInteractiveItemPlacement (const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
 Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc. More...
 
KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
FOOTPRINTfootprint () const
 
const PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const PCB_SELECTIONselection () const
 
PCB_SELECTIONselection ()
 
void attachManager (TOOL_MANAGER *aManager)
 Set the TOOL_MANAGER the tool will belong to. More...
 
KIGFX::VIEWgetView () const
 Returns the instance of #VIEW object used in the application. More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Return the instance of VIEW_CONTROLS object used in the application. More...
 
template<typename T >
T * getEditFrame () const
 Return the application window object, casted to requested user type. More...
 
template<typename T >
T * getModel () const
 Return the model object if it matches the requested type. More...
 

Protected Attributes

bool m_isFootprintEditor
 
TOOL_MENU m_menu
 The functions below are not yet implemented - their interface may change. More...
 
TOOL_TYPE m_type
 Unique identifier for the tool, assigned by a TOOL_MANAGER instance. More...
 
TOOL_ID m_toolId
 Name of the tool. More...
 
std::string m_toolName
 
TOOL_MANAGERm_toolMgr
 

Private Member Functions

bool drawSegment (const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
 Start drawing a selected shape (i.e. More...
 
bool drawArc (const std::string &aTool, PCB_SHAPE **aGraphic, bool aImmediateMode)
 Start drawing an arc. More...
 
bool getSourceZoneForAction (ZONE_MODE aMode, ZONE **aZone)
 Draw a polygon, that is added as a zone or a keepout area. More...
 
void constrainDimension (PCB_DIMENSION_BASE *aDim)
 Force the dimension lime to be drawn on multiple of 45 degrees. More...
 
int getSegmentWidth (PCB_LAYER_ID aLayer) const
 

Private Attributes

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

Static Private Attributes

static const unsigned int WIDTH_STEP = Millimeter2iu( 0.1 )
 

Friends

class ZONE_CREATE_HELPER
 

Detailed Description

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

Definition at line 50 of file drawing_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Options for placing items interactively.

Enumerator
IPO_ROTATE 

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

IPO_FLIP 

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

IPO_SINGLE_CLICK 

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

IPO_REPEAT 

Allow repeat placement of the item.

Definition at line 116 of file pcb_tool_base.h.

116  {
118  IPO_ROTATE = 0x01,
119 
121  IPO_FLIP = 0x02,
122 
125  IPO_SINGLE_CLICK = 0x04,
126 
128  IPO_REPEAT = 0x08
129  };
Handle flip action in the loop by calling the item's flip method.
Allow repeat placement of the item.
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
Handle the rotate action in the loop by calling the item's rotate method.

◆ MODE

enum DRAWING_TOOL::MODE
strong
Enumerator
NONE 
LINE 
RECTANGLE 
CIRCLE 
ARC 
TEXT 
ANCHOR 
DXF 
DIMENSION 
KEEPOUT 
ZONE 
GRAPHIC_POLYGON 
VIA 

Definition at line 63 of file drawing_tool.h.

64  {
65  NONE,
66  LINE,
67  RECTANGLE,
68  CIRCLE,
69  ARC,
70  TEXT,
71  ANCHOR,
72  DXF,
73  DIMENSION,
74  KEEPOUT,
75  ZONE,
77  VIA
78  };
Normal via.
Definition: router_tool.cpp:70
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:32
No updates are required.
Definition: view_item.h:46

◆ RESET_REASON

enum TOOL_BASE::RESET_REASON
inherited

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

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

Constructor & Destructor Documentation

◆ DRAWING_TOOL()

DRAWING_TOOL::DRAWING_TOOL ( )

Definition at line 158 of file drawing_tool.cpp.

158  :
159  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
160  m_view( nullptr ),
161  m_controls( nullptr ),
162  m_board( nullptr ),
163  m_frame( nullptr ),
164  m_mode( MODE::NONE ),
165  m_inDrawingTool( false ),
166  m_lineWidth( 1 )
167 {
168 }
BOARD * m_board
Definition: drawing_tool.h:266
bool m_inDrawingTool
Definition: drawing_tool.h:269
KIGFX::VIEW * m_view
Definition: drawing_tool.h:264
unsigned int m_lineWidth
Definition: drawing_tool.h:271
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:265
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:77

◆ ~DRAWING_TOOL()

DRAWING_TOOL::~DRAWING_TOOL ( )

Definition at line 171 of file drawing_tool.cpp.

172 {
173 }

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Run the tool.

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

Definition at line 51 of file tool_interactive.cpp.

52 {
54 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.

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

Referenced by AUTOPLACE_TOOL::autoplace(), EDIT_TOOL::copyToClipboard(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::DragArcTrack(), DrawArc(), DrawCircle(), DrawDimension(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DrawRectangle(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCB_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), InteractivePlaceWithPreview(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), PCB_PICKER_TOOL::Main(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), LIB_TREE::onContextMenu(), PCB_POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), SetAnchor(), DRC_TOOL::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ attachManager()

void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Set the TOOL_MANAGER the tool will belong to.

Called by TOOL_MANAGER::RegisterTool()

Definition at line 60 of file tool_base.cpp.

61 {
62  m_toolMgr = aManager;
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 165 of file pcb_tool_base.h.

165 { return getModel<BOARD>(); }

Referenced by PCB_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), BOARD_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::DragArcTrack(), drawArc(), DrawDimension(), drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportNetlist(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), PCB_SELECTION_TOOL::filterSelection(), PCB_TOOL_BASE::footprint(), PCB_SELECTION_TOOL::GetBoard(), PCB_SELECTION_TOOL::getCollectorsGuide(), GROUP_TOOL::Group(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::highlightNet(), InteractivePlaceWithPreview(), PCB_CONTROL::LayerNext(), PCB_CONTROL::LayerPrev(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::MoveExact(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), PCB_CONTROL::Paste(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PAD_TOOL::PlacePad(), BOARD_EDITOR_CONTROL::PlaceTarget(), PlaceText(), PCB_SELECTION_TOOL::RebuildSelection(), PAD_TOOL::recombinePad(), BOARD_EDITOR_CONTROL::RepairBoard(), FOOTPRINT_EDITOR_CONTROL::RepairFootprint(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::selectAllItemsOnNet(), PCB_SELECTION_TOOL::selectAllItemsOnSheet(), PCB_SELECTION_TOOL::selectConnectedTracks(), PCB_SELECTION_TOOL::selectionContains(), PCB_SELECTION_TOOL::selectPoint(), PCB_CONTROL::TrackDisplayMode(), PCB_CONTROL::unfilledZoneCheck(), GROUP_TOOL::Ungroup(), ROUTER_TOOL::updateMessagePanel(), PCB_CONTROL::ViaDisplayMode(), PCB_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), BOARD_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ canvas()

◆ constrainDimension()

void DRAWING_TOOL::constrainDimension ( PCB_DIMENSION_BASE aDim)
private

Force the dimension lime to be drawn on multiple of 45 degrees.

Parameters
aDimensionis the dimension element currently being drawn.Return the appropriate width for a segment depending on the settings.

Definition at line 683 of file drawing_tool.cpp.

684 {
685  const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() };
686 
687  aDim->SetEnd( wxPoint( VECTOR2I( aDim->GetStart() ) + GetVectorSnapped45( lineVector ) ) );
688  aDim->Update();
689 }
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
virtual void SetEnd(const wxPoint &aPoint)
virtual const wxPoint & GetEnd() const
void Update()
Update the dimension's cached text and geometry.

References PCB_DIMENSION_BASE::GetEnd(), PCB_DIMENSION_BASE::GetStart(), GetVectorSnapped45(), PCB_DIMENSION_BASE::SetEnd(), and PCB_DIMENSION_BASE::Update().

Referenced by DrawDimension().

◆ controls()

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

◆ doInteractiveItemPlacement()

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

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

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

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

Definition at line 37 of file pcb_tool_base.cpp.

40 {
41  using namespace std::placeholders;
42  std::unique_ptr<BOARD_ITEM> newItem;
43 
44  frame()->PushTool( aTool );
45 
46  BOARD_COMMIT commit( frame() );
47 
49 
50  Activate();
51  // Must be done after Activate() so that it gets set into the correct context
52  controls()->ShowCursor( true );
53  // do not capture or auto-pan until we start placing an item
54 
55  PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
56 
57  // Add a VIEW_GROUP that serves as a preview for the new item
58  PCB_SELECTION preview;
59  view()->Add( &preview );
60 
61  aPlacer->m_board = board();
62  aPlacer->m_frame = frame();
63  aPlacer->m_modifiers = 0;
64 
65  auto makeNewItem =
66  [&]( VECTOR2I aPosition )
67  {
68  if( frame()->GetModel() )
69  newItem = aPlacer->CreateItem();
70 
71  if( newItem )
72  {
73  newItem->SetPosition( (wxPoint) aPosition );
74  preview.Add( newItem.get() );
75 
76  if( newItem->Type() == PCB_FOOTPRINT_T )
77  {
78  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
79 
80  // footprints have more drawable parts
81  fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
82  }
83  }
84  };
85 
86  if( aOptions & IPO_SINGLE_CLICK )
87  makeNewItem( controls()->GetCursorPosition() );
88 
89  auto setCursor =
90  [&]()
91  {
92  if( !newItem )
94  else
96  };
97 
98  // Set initial cursor
99  setCursor();
100 
101  // Main loop: keep receiving events
102  while( TOOL_EVENT* evt = Wait() )
103  {
104  setCursor();
105 
106  grid.SetSnap( false ); // Interactive placement tools need to set their own item snaps
107  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
108  VECTOR2I cursorPos = grid.BestSnapAnchor( controls()->GetMousePosition(), nullptr );
109 
110  aPlacer->m_modifiers = evt->Modifier();
111 
112  auto cleanup =
113  [&] ()
114  {
115  newItem = nullptr;
116  preview.Clear();
117  view()->Update( &preview );
118  controls()->SetAutoPan( false );
119  controls()->CaptureCursor( false );
120  controls()->ShowCursor( true );
121  };
122 
123  if( evt->IsCancelInteractive() )
124  {
125  if( aOptions & IPO_SINGLE_CLICK )
126  {
127  cleanup();
128  frame()->PopTool( aTool );
129  break;
130  }
131  else if( newItem )
132  {
133  cleanup();
134  }
135  else
136  {
137  frame()->PopTool( aTool );
138  break;
139  }
140  }
141  else if( evt->IsActivate() )
142  {
143  if( newItem )
144  cleanup();
145 
146  if( evt->IsPointEditor() )
147  {
148  // don't exit (the point editor runs in the background)
149  }
150  else if( evt->IsMoveTool() )
151  {
152  // leave ourselves on the stack so we come back after the move
153  break;
154  }
155  else
156  {
157  frame()->PopTool( aTool );
158  break;
159  }
160  }
161  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
162  {
163  if( !newItem )
164  {
165  // create the item if possible
166  makeNewItem( cursorPos );
167 
168  // no item created, so wait for another click
169  if( !newItem )
170  continue;
171 
172  controls()->CaptureCursor( true );
173  controls()->SetAutoPan( true );
174  }
175  else
176  {
177  auto oldFlags = newItem->GetFlags();
178  newItem->ClearFlags();
179 
180  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
181  {
182  newItem->SetFlags( oldFlags );
183  continue;
184  }
185 
186  preview.Clear();
187  newItem.release();
188  commit.Push( aCommitMessage );
189 
190  controls()->CaptureCursor( false );
191  controls()->SetAutoPan( false );
192  controls()->ShowCursor( true );
193 
194  if( !( aOptions & IPO_REPEAT ) )
195  break;
196 
197  if( aOptions & IPO_SINGLE_CLICK )
198  makeNewItem( controls()->GetCursorPosition() );
199 
200  setCursor();
201  }
202  }
203  else if( evt->IsClick( BUT_RIGHT ) )
204  {
206  }
207  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
208  {
210  }
211  else if( newItem && evt->Category() == TC_COMMAND )
212  {
213  /*
214  * Handle any events that can affect the item as we move it around
215  */
216  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
217  {
218  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
219  newItem->Rotate( newItem->GetPosition(), rotationAngle );
220  view()->Update( &preview );
221  }
222  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
223  {
224  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
225  view()->Update( &preview );
226  }
227  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
228  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
229  {
230  // Refresh preview after event runs
232  }
233  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
234  {
235  frame()->OnEditItemRequest( newItem.get() );
236 
237  // Notify other tools of the changes
239  }
240  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
241  {
242  preview.Clear();
243  newItem.release();
244 
245  makeNewItem( (wxPoint) cursorPos );
246  aPlacer->SnapItem( newItem.get() );
247  view()->Update( &preview );
248  }
249  else
250  {
251  evt->SetPassEvent();
252  }
253  }
254  else if( newItem && evt->IsMotion() )
255  {
256  // track the cursor
257  newItem->SetPosition( (wxPoint) cursorPos );
258  aPlacer->SnapItem( newItem.get() );
259 
260  // Show a preview of the item
261  view()->Update( &preview );
262  }
263  else
264  {
265  evt->SetPassEvent();
266  }
267  }
268 
269  view()->Remove( &preview );
271  controls()->SetAutoPan( false );
272  controls()->CaptureCursor( false );
273 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:83
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Handle flip action in the loop by calling the item's flip method.
BOARD * board() const
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:298
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:301
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
const PCB_SELECTION & selection() const
Allow repeat placement of the item.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
KIGFX::PCB_VIEW * view() const
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:57
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
PCBNEW_SETTINGS & Settings()
void Activate()
Run the tool.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all BOARD_ITEMs that belong to the footprint (pads, drawings,...
Definition: footprint.cpp:1280
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:299
static TOOL_ACTION refreshPreview
Definition: actions.h:106

References TOOL_INTERACTIVE::Activate(), KIGFX::PCB_VIEW::Add(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_TOOL_BASE::controls(), INTERACTIVE_PLACER_BASE::CreateItem(), PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_FRAME::GetModel(), TOOL_BASE::getView(), grid, PCB_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, PCBNEW_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, TOOL_BASE::m_toolMgr, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PCB_FOOTPRINT_T, PENCIL, PLACE, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::ProcessEvent(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), FOOTPRINT::RunOnChildren(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, PCB_ACTIONS::trackViaSizeChanged, KIGFX::PCB_VIEW::Update(), PCB_ACTIONS::viaSizeDec, PCB_ACTIONS::viaSizeInc, PCB_TOOL_BASE::view(), and TOOL_INTERACTIVE::Wait().

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

◆ DrawArc()

int DRAWING_TOOL::DrawArc ( const TOOL_EVENT aEvent)

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

405 {
407  return 0;
408 
409  if( m_inDrawingTool )
410  return 0;
411 
413 
414  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
415  PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
416  BOARD_COMMIT commit( m_frame );
417  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
418  bool immediateMode = aEvent.HasPosition();
419 
420  arc->SetShape( SHAPE_T::ARC );
421  arc->SetFlags( IS_NEW );
422 
423  std::string tool = aEvent.GetCommandStr().get();
424  m_frame->PushTool( tool );
425  Activate();
426 
427  while( drawArc( tool, &arc, immediateMode ) )
428  {
429  if( arc )
430  {
431  if( m_isFootprintEditor )
432  static_cast<FP_SHAPE*>( arc )->SetLocalCoord();
433 
434  commit.Add( arc );
435  commit.Push( _( "Draw an arc" ) );
436 
438  }
439 
440  arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
441  arc->SetShape( SHAPE_T::ARC );
442  arc->SetFlags( IS_NEW );
443  immediateMode = false;
444  }
445 
446  return 0;
447 }
#define IS_NEW
New item, just created.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool m_inDrawingTool
Definition: drawing_tool.h:269
RAII class that sets an value at construction and resets it to the original value at destruction.
#define _(s)
bool drawArc(const std::string &aTool, PCB_SHAPE **aGraphic, bool aImmediateMode)
Start drawing an arc.
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:91
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:240

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

Referenced by setTransitions().

◆ drawArc()

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

Start drawing an arc.

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

Definition at line 1727 of file drawing_tool.cpp.

1728 {
1729  PCB_SHAPE*& graphic = *aGraphic;
1730  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1731 
1732  m_lineWidth = getSegmentWidth( drawingLayer );
1733 
1734  // Arc geometric construction manager
1736 
1737  // Arc drawing assistant overlay
1738  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1739 
1740  // Add a VIEW_GROUP that serves as a preview for the new item
1741  PCB_SELECTION preview;
1742  m_view->Add( &preview );
1743  m_view->Add( &arcAsst );
1745 
1746  auto setCursor =
1747  [&]()
1748  {
1750  };
1751 
1752  auto cleanup =
1753  [&] ()
1754  {
1755  preview.Clear();
1756  delete *aGraphic;
1757  *aGraphic = nullptr;
1758  };
1759 
1760  m_controls->ShowCursor( true );
1761  // Set initial cursor
1762  setCursor();
1763 
1764  bool firstPoint = false;
1765  bool cancelled = false;
1766 
1767  // Prime the pump
1769 
1770  if( aImmediateMode )
1772 
1773  // Main loop: keep receiving events
1774  while( TOOL_EVENT* evt = Wait() )
1775  {
1776  if( firstPoint )
1777  m_frame->SetMsgPanel( graphic );
1778 
1779  setCursor();
1780 
1781  graphic->SetLayer( drawingLayer );
1782 
1783  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1784  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1785  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
1786  m_controls->ForceCursorPosition( true, cursorPos );
1787 
1788  if( evt->IsCancelInteractive() )
1789  {
1790  cleanup();
1791 
1792  if( !firstPoint )
1793  {
1794  // We've handled the cancel event. Don't cancel other tools
1795  evt->SetPassEvent( false );
1796  m_frame->PopTool( aTool );
1797  cancelled = true;
1798  }
1799 
1800  break;
1801  }
1802  else if( evt->IsActivate() )
1803  {
1804  if( evt->IsPointEditor() )
1805  {
1806  // don't exit (the point editor runs in the background)
1807  }
1808  else if( evt->IsMoveTool() )
1809  {
1810  cleanup();
1811  // leave ourselves on the stack so we come back after the move
1812  cancelled = true;
1813  break;
1814  }
1815  else
1816  {
1817  cleanup();
1818  m_frame->PopTool( aTool );
1819  cancelled = true;
1820  break;
1821  }
1822  }
1823  else if( evt->IsClick( BUT_LEFT ) )
1824  {
1825  if( !firstPoint )
1826  {
1828 
1829  m_controls->SetAutoPan( true );
1830  m_controls->CaptureCursor( true );
1831 
1832  drawingLayer = m_frame->GetActiveLayer();
1833  m_lineWidth = getSegmentWidth( drawingLayer );
1834 
1835  // Init the new item attributes
1836  // (non-geometric, those are handled by the manager)
1837  graphic->SetShape( SHAPE_T::ARC );
1838  graphic->SetWidth( m_lineWidth );
1839 
1840  if( !m_view->IsLayerVisible( drawingLayer ) )
1841  {
1842  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1843  m_frame->GetCanvas()->Refresh();
1844  }
1845 
1846  preview.Add( graphic );
1847  frame()->SetMsgPanel( graphic );
1848  firstPoint = true;
1849  }
1850 
1851  arcManager.AddPoint( cursorPos, true );
1852  }
1853  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1854  {
1855  arcManager.RemoveLastPoint();
1856  }
1857  else if( evt->IsMotion() )
1858  {
1859  // set angle snap
1860  arcManager.SetAngleSnap( Is45Limited() );
1861 
1862  // update, but don't step the manager state
1863  arcManager.AddPoint( cursorPos, false );
1864  }
1865  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1866  {
1867  drawingLayer = m_frame->GetActiveLayer();
1868  m_lineWidth = getSegmentWidth( drawingLayer );
1869 
1870  if( graphic )
1871  {
1872  if( !m_view->IsLayerVisible( drawingLayer ) )
1873  {
1874  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1875  m_frame->GetCanvas()->Refresh();
1876  }
1877 
1878  graphic->SetLayer( drawingLayer );
1879  graphic->SetWidth( m_lineWidth );
1880  m_view->Update( &preview );
1881  frame()->SetMsgPanel( graphic );
1882  }
1883  else
1884  {
1885  evt->SetPassEvent();
1886  }
1887  }
1888  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1889  {
1891  {
1892  graphic->SetArcAngleAndEnd( 900 );
1893  frame()->OnEditItemRequest( graphic );
1894  m_view->Update( &preview );
1895  frame()->SetMsgPanel( graphic );
1896  break;
1897  }
1898  else if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
1899  {
1900  frame()->OnEditItemRequest( graphic );
1901  m_view->Update( &preview );
1902  frame()->SetMsgPanel( graphic );
1903  break;
1904  }
1905  else
1906  {
1907  evt->SetPassEvent();
1908  }
1909  }
1910  else if( evt->IsClick( BUT_RIGHT ) )
1911  {
1913  }
1914  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1915  {
1917  graphic->SetWidth( m_lineWidth );
1918  m_view->Update( &preview );
1919  frame()->SetMsgPanel( graphic );
1920  }
1921  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1922  {
1924  graphic->SetWidth( m_lineWidth );
1925  m_view->Update( &preview );
1926  frame()->SetMsgPanel( graphic );
1927  }
1928  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1929  {
1930  arcManager.ToggleClockwise();
1931  }
1932  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1933  {
1934  arcAsst.SetUnits( frame()->GetUserUnits() );
1935  m_view->Update( &arcAsst );
1936  evt->SetPassEvent();
1937  }
1938  else
1939  {
1940  evt->SetPassEvent();
1941  }
1942 
1943  if( arcManager.IsComplete() )
1944  {
1945  break;
1946  }
1947  else if( arcManager.HasGeometryChanged() )
1948  {
1949  updateArcFromConstructionMgr( arcManager, *graphic );
1950  m_view->Update( &preview );
1951  m_view->Update( &arcAsst );
1952 
1953  if( firstPoint )
1954  frame()->SetMsgPanel( graphic );
1955  else
1956  frame()->SetMsgPanel( board() );
1957  }
1958  }
1959 
1960  preview.Remove( graphic );
1961  m_view->Remove( &arcAsst );
1962  m_view->Remove( &preview );
1963  m_frame->SetMsgPanel( board() );
1964 
1966  m_controls->SetAutoPan( false );
1967  m_controls->CaptureCursor( false );
1968  m_controls->ForceCursorPosition( false );
1969 
1970  return !cancelled;
1971 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
Manage the construction of a circular arc though sequential setting of critical points: center,...
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:167
int GetUserUnits()
Return the currently selected user unit value for the interface.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, PCB_SHAPE &aArc)
Update an arc PCB_SHAPE from the current state of an Arc Geometry Manager.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:272
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:348
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
void SetArcAngleAndEnd(double aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:509
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
APPEARANCE_CONTROLS * GetAppearancePanel()
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:170
KIGFX::VIEW * m_view
Definition: drawing_tool.h:264
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
const PCB_SELECTION & selection() const
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
Waiting to lock in the arc start point.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
unsigned int m_lineWidth
Definition: drawing_tool.h:271
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
void SetWidth(int aWidth)
Definition: eda_shape.h:88
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:265
bool Is45Limited() const
Should the tool use its 45° mode option?
int getSegmentWidth(PCB_LAYER_ID aLayer) const
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn 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:267
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:173
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
static TOOL_ACTION updateUnits
Definition: actions.h:147
Waiting to lock in the arc end point.
void ToggleClockwise()
Set angle snapping (for the next point)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
ARC_STEPS GetStep() const
Get the current step the manager is on (useful when drawing something depends on the current state)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:91
Represents an assistant draw when interactively drawing an arc on a canvas.
Definition: arc_assistant.h:38
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:163
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:106
static TOOL_ACTION cursorClick
Definition: actions.h:123
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1512
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405

References KIGFX::VIEW::Add(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::AddPoint(), ARC, PCB_ACTIONS::arcPosture, ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, PCB_ACTIONS::deleteLastPoint, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSegmentWidth(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetStep(), EDA_BASE_FRAME::GetUserUnits(), GetUserUnits(), TOOL_BASE::getView(), grid, KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::HasGeometryChanged(), PCB_ACTIONS::incWidth, PCB_TOOL_BASE::Is45Limited(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::IsComplete(), KIGFX::VIEW::IsLayerVisible(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, m_view, MD_SHIFT, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PENCIL, TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, EDA_DRAW_PANEL_GAL::Refresh(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_START, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SetAngleSnap(), EDA_SHAPE::SetArcAngleAndEnd(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), BOARD_ITEM::SetLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), EDA_DRAW_FRAME::SetMsgPanel(), EDA_SHAPE::SetShape(), EDA_SHAPE::SetWidth(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::ToggleClockwise(), KIGFX::VIEW::Update(), updateArcFromConstructionMgr(), ACTIONS::updateUnits, TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by DrawArc().

◆ DrawBoardCharacteristics()

std::vector< BOARD_ITEM * > DRAWING_TOOL::DrawBoardCharacteristics ( const wxPoint &  origin,
PCB_LAYER_ID  aLayer,
bool  aDrawNow,
wxPoint *  tablesize 
)

Definition at line 372 of file drawing_stackup_table_tool.cpp.

376 {
377  BOARD_COMMIT commit( m_frame );
378  std::vector<BOARD_ITEM*> objects;
380  BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
381 
382  wxPoint cursorPos = aOrigin;
383 
384  // Style : Section header
385  PCB_TEXT* headStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
386  headStyle->SetLayer( Eco1_User );
387  headStyle->SetTextSize( wxSize( Millimeter2iu( 2.0 ), Millimeter2iu( 2.0 ) ) );
388  headStyle->SetTextThickness( Millimeter2iu( 0.4 ) );
389  headStyle->SetItalic( false );
390  headStyle->SetTextPos( wxPoint( 0, 0 ) );
392  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
393 
394  // Style : Data
395  PCB_TEXT* dataStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
396  dataStyle->SetLayer( Eco1_User );
397  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
398  dataStyle->SetTextThickness( Millimeter2iu( 0.2 ) );
399  dataStyle->SetItalic( false );
400  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
402  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
403 
404  PCB_TEXT* t;
405 
406  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
407  t->SetText( _( "BOARD CHARACTERISTICS" ) );
408  t->SetPosition( cursorPos );
409  objects.push_back( t );
410 
411  cursorPos.y = cursorPos.y + t->GetBoundingBox().GetHeight()
413 
414  std::vector<std::vector<PCB_TEXT*>> texts;
415  std::vector<PCB_TEXT*> colLabel1;
416  std::vector<PCB_TEXT*> colData1;
417  std::vector<PCB_TEXT*> colbreak;
418  std::vector<PCB_TEXT*> colLabel2;
419  std::vector<PCB_TEXT*> colData2;
420  wxString text = wxString( "" );
421 
422  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
423  t->SetText( _( "Copper Layer Count: " ) );
424  colLabel1.push_back( t );
425 
426  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
428  colData1.push_back( t );
429 
430  EDA_RECT size = m_frame->GetBoard()->ComputeBoundingBox( true );
431  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
432  t->SetText( _( "Board overall dimensions: " ) );
433  colLabel1.push_back( t );
434 
435  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
436  t->SetText( wxString::Format( "%s x %s",
438  MessageTextFromValue( m_frame->GetUserUnits(), size.GetHeight(), true ) ) );
439  colData1.push_back( t );
440 
441  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
442  t->SetText( _( "Min track/spacing: " ) );
443  colLabel1.push_back( t );
444 
445  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
446  t->SetText( wxString::Format( "%s / %s",
448  MessageTextFromValue( m_frame->GetUserUnits(), settings.m_MinClearance, true ) ) );
449  colData1.push_back( t );
450 
451  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
452  t->SetText( _( "Copper Finish: " ) );
453  colLabel1.push_back( t );
454 
455  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
456  t->SetText( stackup.m_FinishType );
457  colData1.push_back( t );
458 
459  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
460  t->SetText( _( "Castellated pads: " ) );
461  colLabel1.push_back( t );
462 
463  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
464  t->SetText( stackup.m_CastellatedPads ? _( "Yes" ) : _( "No" ) );
465  colData1.push_back( t );
466 
467  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
468  t->SetText( _( "Board Thickness: " ) );
469  colLabel2.push_back( t );
470 
471  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
473 
474  t->SetText( text );
475  colData2.push_back( t );
476 
477  // some empty cells
478  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
479  colLabel2.push_back( t );
480  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
481  colData2.push_back( t );
482 
483  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
484  t->SetText( _( "Min hole diameter: " ) );
485  colLabel2.push_back( t );
486  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
487 
488  double holeSize = std::min( settings.m_MinThroughDrill, settings.m_ViasMinSize );
489  text = MessageTextFromValue( m_frame->GetUserUnits(), holeSize, true );
490  t->SetText( text );
491  colData2.push_back( t );
492 
493  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
494  t->SetText( _( "Impedance Control: " ) );
495  colLabel2.push_back( t );
496 
497  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
498  t->SetText( stackup.m_HasDielectricConstrains ? _( "Yes" ) : _( "No" ) );
499  colData2.push_back( t );
500 
501  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
502  t->SetText( _( "Plated Board Edge: " ) );
503  colLabel2.push_back( t );
504 
505  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
506  t->SetText( stackup.m_EdgePlating ? _( "Yes" ) : _( "No" ) );
507  colData2.push_back( t );
508 
509  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
510  t->SetText( _( "Edge card connectors: " ) );
511  colLabel1.push_back( t );
512 
513  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
514  switch( stackup.m_EdgeConnectorConstraints )
515  {
516  case BS_EDGE_CONNECTOR_NONE: t->SetText( _( "No" ) ); break;
517  case BS_EDGE_CONNECTOR_IN_USE: t->SetText( _( "Yes" ) ); break;
518  case BS_EDGE_CONNECTOR_BEVELLED: t->SetText( _( "Yes, Bevelled" ) ); break;
519  }
520  colData1.push_back( t );
521 
522  texts.push_back( colLabel1 );
523  texts.push_back( colData1 );
524  texts.push_back( colbreak );
525  texts.push_back( colLabel2 );
526  texts.push_back( colData2 );
527  wxPoint tableSize2 = wxPoint();
528 
529  std::vector<BOARD_ITEM*> table = initTextTable( texts, cursorPos, Eco1_User, &tableSize2,
530  false );
531 
532  for( BOARD_ITEM* item : table )
533  objects.push_back( item );
534 
535  if( aDrawNow )
536  {
537  for( auto item : objects )
538  commit.Add( item );
539 
540  commit.Push( "Board Characteristics" );
541  }
542 
543  tableSize->x = tableSize2.x;
544  tableSize->y = cursorPos.y + tableSize2.y + From_User_Unit( EDA_UNITS::MILLIMETRES, 2.0 );
545 
546  return objects;
547 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:81
Manage layers needed to make a physical board.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
wxString m_FinishType
The name of external copper finish.
bool m_EdgePlating
True if the edge board is plated.
void SetItalic(bool isItalic)
Definition: eda_text.h:179
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specified in job file: BS_EDGE_CONNECTO...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:246
int GetWidth() const
Definition: eda_rect.h:109
bool m_CastellatedPads
True if castellated pads exist.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
static std::vector< BOARD_ITEM * > initTextTable(std::vector< std::vector< PCB_TEXT * >> aContent, wxPoint origin, PCB_LAYER_ID aLayer, wxPoint *aTableSize, bool aDrawFrame=true)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
BOARD_STACKUP & GetStackupDescriptor()
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:202
#define _(s)
int GetHeight() const
Definition: eda_rect.h:110
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
Handle the component boundary box.
Definition: eda_rect.h:42
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1082
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:169
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:159
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:132
BOARD * GetBoard() const
static constexpr int Millimeter2iu(double mm)
double From_User_Unit(EDA_UNITS aUnits, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:282
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Container for design settings for a BOARD object.

References _, COMMIT::Add(), BS_EDGE_CONNECTOR_BEVELLED, BS_EDGE_CONNECTOR_IN_USE, BS_EDGE_CONNECTOR_NONE, BOARD::ComputeBoundingBox(), BOARD_ITEM::Duplicate(), Eco1_User, Format(), From_User_Unit(), PCB_BASE_FRAME::GetBoard(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), PCB_TEXT::GetBoundingBox(), BOARD_DESIGN_SETTINGS::GetCopperLayerCount(), BOARD::GetDesignSettings(), EDA_RECT::GetHeight(), PCB_BASE_FRAME::GetModel(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), EDA_BASE_FRAME::GetUserUnits(), EDA_RECT::GetWidth(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, initTextTable(), BOARD_STACKUP::m_CastellatedPads, BOARD_STACKUP::m_EdgeConnectorConstraints, BOARD_STACKUP::m_EdgePlating, BOARD_STACKUP::m_FinishType, m_frame, BOARD_STACKUP::m_HasDielectricConstrains, BOARD_DESIGN_SETTINGS::m_MinClearance, BOARD_DESIGN_SETTINGS::m_MinThroughDrill, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinSize, MessageTextFromValue(), Millimeter2iu(), MILLIMETRES, BOARD_COMMIT::Push(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), BOARD_ITEM::SetLayer(), PCB_TEXT::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetVertJustify(), StringFromValue(), text, and UNSCALED.

Referenced by PlaceCharacteristics().

◆ DrawCircle()

int DRAWING_TOOL::DrawCircle ( const TOOL_EVENT aEvent)

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

354 {
356  return 0;
357 
358  if( m_inDrawingTool )
359  return 0;
360 
362 
363  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
364  PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
365  BOARD_COMMIT commit( m_frame );
366  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
367  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
368 
369  circle->SetShape( SHAPE_T::CIRCLE );
370  circle->SetFilled( false );
371  circle->SetFlags( IS_NEW );
372 
373  if( aEvent.HasPosition() )
374  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
375 
376  std::string tool = aEvent.GetCommandStr().get();
377  m_frame->PushTool( tool );
378  Activate();
379 
380  while( drawSegment( tool, &circle, startingPoint ) )
381  {
382  if( circle )
383  {
384  if( m_isFootprintEditor )
385  static_cast<FP_SHAPE*>( circle )->SetLocalCoord();
386 
387  commit.Add( circle );
388  commit.Push( _( "Draw a circle" ) );
389 
390  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
391  }
392 
393  circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
394  circle->SetShape( SHAPE_T::CIRCLE );
395  circle->SetFilled( false );
396  circle->SetFlags( IS_NEW );
397  startingPoint = NULLOPT;
398  }
399 
400  return 0;
401 }
#define IS_NEW
New item, just created.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool m_inDrawingTool
Definition: drawing_tool.h:269
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:91
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:240
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), CIRCLE, CIRCLE, TOOL_EVENT::DisableGridSnapping(), drawSegment(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, m_frame, m_inDrawingTool, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, TOOL_BASE::m_toolMgr, NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectItem, and EDA_SHAPE::SetShape().

Referenced by setTransitions().

◆ DrawDimension()

int DRAWING_TOOL::DrawDimension ( const TOOL_EVENT aEvent)

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

693 {
695  return 0;
696 
697  if( m_inDrawingTool )
698  return 0;
699 
701 
702  enum DIMENSION_STEPS
703  {
704  SET_ORIGIN = 0,
705  SET_END,
706  SET_HEIGHT,
707  FINISHED
708  };
709 
710  TOOL_EVENT originalEvent = aEvent;
711  PCB_DIMENSION_BASE* dimension = nullptr;
712  BOARD_COMMIT commit( m_frame );
714  BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
715  PCB_SELECTION preview; // A VIEW_GROUP that serves as a preview for the new item(s)
716  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
717  int step = SET_ORIGIN;
718 
719  m_view->Add( &preview );
720 
721  auto cleanup =
722  [&]()
723  {
724  m_controls->SetAutoPan( false );
725  m_controls->CaptureCursor( false );
726 
727  preview.Clear();
728  m_view->Update( &preview );
729 
730  delete dimension;
731  dimension = nullptr;
732  step = SET_ORIGIN;
733  };
734 
735  auto setCursor =
736  [&]()
737  {
739  };
740 
742 
743  std::string tool = aEvent.GetCommandStr().get();
744  m_frame->PushTool( tool );
745 
746  Activate();
747  // Must be done after Activate() so that it gets set into the correct context
748  m_controls->ShowCursor( true );
749  // Set initial cursor
750  setCursor();
751 
752  // Prime the pump
754 
755  if( aEvent.HasPosition() )
756  m_toolMgr->PrimeTool( aEvent.Position() );
757 
758  // Main loop: keep receiving events
759  while( TOOL_EVENT* evt = Wait() )
760  {
761  if( step > SET_ORIGIN )
762  frame()->SetMsgPanel( dimension );
763 
764  setCursor();
765 
766  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
767  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
768 
769  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
770 
771  cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
772  m_controls->ForceCursorPosition( true, cursorPos );
773 
774  if( evt->IsCancelInteractive() )
775  {
776  m_controls->SetAutoPan( false );
777 
778  if( step != SET_ORIGIN ) // start from the beginning
779  {
780  cleanup();
781  }
782  else
783  {
784  m_frame->PopTool( tool );
785  break;
786  }
787  }
788  else if( evt->IsActivate() )
789  {
790  if( step != SET_ORIGIN )
791  cleanup();
792 
793  if( evt->IsPointEditor() )
794  {
795  // don't exit (the point editor runs in the background)
796  }
797  else if( evt->IsMoveTool() )
798  {
799  // leave ourselves on the stack so we come back after the move
800  break;
801  }
802  else
803  {
804  m_frame->PopTool( tool );
805  break;
806  }
807  }
808  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
809  {
811  dimension->SetLineThickness( m_lineWidth );
812  m_view->Update( &preview );
813  frame()->SetMsgPanel( dimension );
814  }
815  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
816  {
817  if( m_lineWidth > WIDTH_STEP )
818  {
820  dimension->SetLineThickness( m_lineWidth );
821  m_view->Update( &preview );
822  frame()->SetMsgPanel( dimension );
823  }
824  }
825  else if( evt->IsClick( BUT_RIGHT ) )
826  {
828  }
829  else if( evt->IsClick( BUT_LEFT ) )
830  {
831  switch( step )
832  {
833  case SET_ORIGIN:
834  {
836 
838 
839  // Init the new item attributes
840  auto setMeasurementAttributes =
841  [&]( PCB_DIMENSION_BASE* aDim )
842  {
843  aDim->SetUnitsMode( boardSettings.m_DimensionUnitsMode );
844  aDim->SetUnitsFormat( boardSettings.m_DimensionUnitsFormat );
845  aDim->SetPrecision( boardSettings.m_DimensionPrecision );
846  aDim->SetSuppressZeroes( boardSettings.m_DimensionSuppressZeroes );
847  aDim->SetTextPositionMode( boardSettings.m_DimensionTextPosition );
848  aDim->SetKeepTextAligned( boardSettings.m_DimensionKeepTextAligned );
849 
850  if( boardSettings.m_DimensionUnitsMode == DIM_UNITS_MODE::AUTOMATIC )
851  aDim->SetUnits( m_frame->GetUserUnits() );
852  };
853 
854  if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) )
855  {
856  dimension = new PCB_DIM_ALIGNED( m_board );
857  setMeasurementAttributes( dimension );
858  }
859  else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) )
860  {
861  dimension = new PCB_DIM_ORTHOGONAL( m_board );
862  setMeasurementAttributes( dimension );
863  }
864  else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) )
865  {
866  dimension = new PCB_DIM_CENTER( m_board );
867  }
868  else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) )
869  {
870  dimension = new PCB_DIM_LEADER( m_board );
871  dimension->Text().SetPosition( wxPoint( cursorPos ) );
872  }
873  else
874  {
875  wxFAIL_MSG( "Unhandled action in DRAWING_TOOL::DrawDimension" );
876  }
877 
878  dimension->SetLayer( layer );
879  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
880  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
881  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
882  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
883  dimension->SetArrowLength( boardSettings.m_DimensionArrowLength );
884  dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset );
885  dimension->SetStart( (wxPoint) cursorPos );
886  dimension->SetEnd( (wxPoint) cursorPos );
887  dimension->Update();
888 
889  if( !m_view->IsLayerVisible( layer ) )
890  {
891  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
892  m_frame->GetCanvas()->Refresh();
893  }
894 
895  preview.Add( dimension );
896  frame()->SetMsgPanel( dimension );
897 
898  m_controls->SetAutoPan( true );
899  m_controls->CaptureCursor( true );
900  break;
901  }
902 
903  case SET_END:
904  {
905  dimension->SetEnd( (wxPoint) cursorPos );
906  dimension->Update();
907 
908  if( Is45Limited() || dimension->Type() == PCB_DIM_CENTER_T )
909  constrainDimension( dimension );
910 
911  // Dimensions that have origin and end in the same spot are not valid
912  if( dimension->GetStart() == dimension->GetEnd() )
913  --step;
914  else if( dimension->Type() == PCB_DIM_LEADER_T )
915  dimension->SetText( wxT( "?" ) );
916 
917  if( dimension->Type() == PCB_DIM_CENTER_T )
918  {
919  // No separate height/text step
920  ++step;
922  }
923  else
924  {
925  break;
926  }
927  }
928 
929  case SET_HEIGHT:
930  if( dimension->Type() == PCB_DIM_LEADER_T )
931  {
932  assert( dimension->GetStart() != dimension->GetEnd() );
933  assert( dimension->GetLineThickness() > 0 );
934 
935  preview.Remove( dimension );
936 
937  commit.Add( dimension );
938  commit.Push( _( "Draw a leader" ) );
939 
940  // Run the edit immediately to set the leader text
941  m_toolMgr->RunAction( PCB_ACTIONS::properties, true, dimension );
942  }
943  else if( (wxPoint) cursorPos != dimension->GetPosition() )
944  {
945  assert( dimension->GetStart() != dimension->GetEnd() );
946  assert( dimension->GetLineThickness() > 0 );
947 
948  preview.Remove( dimension );
949 
950  commit.Add( dimension );
951  commit.Push( _( "Draw a dimension" ) );
952 
953  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
954  }
955 
956  break;
957  }
958 
959  if( ++step == FINISHED )
960  {
961  step = SET_ORIGIN;
962  m_controls->SetAutoPan( false );
963  m_controls->CaptureCursor( false );
964  }
965  }
966  else if( evt->IsMotion() )
967  {
968  switch( step )
969  {
970  case SET_END:
971  dimension->SetEnd( (wxPoint) cursorPos );
972 
973  if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
974  {
975  PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
976 
977  BOX2I bounds( dimension->GetStart(),
978  dimension->GetEnd() - dimension->GetStart() );
979 
980  // Create a nice preview by measuring the longer dimension
981  bool vert = bounds.GetWidth() < bounds.GetHeight();
982 
983  ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
985  }
986 
987  dimension->Update();
988 
989  if( Is45Limited() || dimension->Type() == PCB_DIM_CENTER_T )
990  constrainDimension( dimension );
991 
992  break;
993 
994  case SET_HEIGHT:
995  {
996  if( dimension->Type() == PCB_DIM_ALIGNED_T )
997  {
998  PCB_DIM_ALIGNED* aligned = static_cast<PCB_DIM_ALIGNED*>( dimension );
999 
1000  // Calculating the direction of travel perpendicular to the selected axis
1001  double angle = aligned->GetAngle() + ( M_PI / 2 );
1002 
1003  wxPoint delta( (wxPoint) cursorPos - dimension->GetEnd() );
1004  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
1005  aligned->SetHeight( height );
1006  aligned->Update();
1007  }
1008  else if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
1009  {
1010  PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
1011 
1012  BOX2I bounds( dimension->GetStart(),
1013  dimension->GetEnd() - dimension->GetStart() );
1014  VECTOR2I direction( cursorPos - bounds.Centre() );
1015  bool vert;
1016 
1017  // Only change the orientation when we move outside the bounds
1018  if( !bounds.Contains( cursorPos ) )
1019  {
1020  // If the dimension is horizontal or vertical, set correct orientation
1021  // otherwise, test if we're left/right of the bounding box or above/below it
1022  if( bounds.GetWidth() == 0 )
1023  {
1024  vert = true;
1025  }
1026  else if( bounds.GetHeight() == 0 )
1027  {
1028  vert = false;
1029  }
1030  else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
1031  {
1032  vert = false;
1033  }
1034  else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
1035  {
1036  vert = true;
1037  }
1038  else
1039  {
1040  vert = std::abs( direction.y ) < std::abs( direction.x );
1041  }
1042  ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
1044  }
1045  else
1046  {
1047  vert = ortho->GetOrientation() == PCB_DIM_ORTHOGONAL::DIR::VERTICAL;
1048  }
1049 
1050  VECTOR2I heightVector( cursorPos - dimension->GetStart() );
1051  ortho->SetHeight( vert ? heightVector.x : heightVector.y );
1052  ortho->Update();
1053  }
1054  else if( dimension->Type() == PCB_DIM_LEADER_T )
1055  {
1056  // Leader: SET_HEIGHT actually sets the text position directly
1057  VECTOR2I lineVector( cursorPos - dimension->GetEnd() );
1058  dimension->Text().SetPosition( wxPoint( VECTOR2I( dimension->GetEnd() ) +
1059  GetVectorSnapped45( lineVector ) ) );
1060  dimension->Update();
1061  }
1062  }
1063  break;
1064  }
1065 
1066  // Show a preview of the item
1067  m_view->Update( &preview );
1068  }
1069  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1070  {
1071  if( dimension )
1072  {
1073  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1074 
1075  if( !m_view->IsLayerVisible( layer ) )
1076  {
1077  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
1078  m_frame->GetCanvas()->Refresh();
1079  }
1080 
1081  dimension->SetLayer( layer );
1082  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
1083  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
1084  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
1085  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
1086  dimension->Update();
1087 
1088  m_view->Update( &preview );
1089  frame()->SetMsgPanel( dimension );
1090  }
1091  else
1092  {
1093  evt->SetPassEvent();
1094  }
1095  }
1096  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1097  {
1098  if( step == SET_END || step == SET_HEIGHT )
1099  {
1100  frame()->OnEditItemRequest( dimension );
1101  dimension->Update();
1102  frame()->SetMsgPanel( dimension );
1103  break;
1104  }
1105  else
1106  {
1107  evt->SetPassEvent();
1108  }
1109  }
1110  else
1111  {
1112  evt->SetPassEvent();
1113  }
1114  }
1115 
1116  if( step != SET_ORIGIN )
1117  delete dimension;
1118 
1119  m_controls->SetAutoPan( false );
1120  m_controls->ForceCursorPosition( false );
1121  m_controls->CaptureCursor( false );
1123 
1124  m_view->Remove( &preview );
1125  m_frame->SetMsgPanel( board() );
1126 
1127  return 0;
1128 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
double GetAngle() const
Return the angle of the crossbar.
static TOOL_ACTION drawCenterDimension
Definition: pcb_actions.h:149
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:83
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
void SetHeight(int aHeight)
Set the distance from the feature points to the crossbar line.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
BOARD * board() const
BOARD * m_board
Definition: drawing_tool.h:266
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:167
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:81
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
PCB_TEXT & Text()
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:272
void SetItalic(bool isItalic)
Definition: eda_text.h:179
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:148
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:348
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
static TOOL_ACTION drawOrthogonalDimension
Definition: pcb_actions.h:150
void SetText(const wxString &aNewText)
Set the override text - has no effect if m_overrideValue == false.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void PrimeTool(const VECTOR2D &aPosition)
"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in posi...
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
Abstract dimension API.
Definition: pcb_dimension.h:95
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
APPEARANCE_CONTROLS * GetAppearancePanel()
void SetExtensionOffset(int aOffset)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:170
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
bool m_inDrawingTool
Definition: drawing_tool.h:269
void SetLineThickness(int aWidth)
KIGFX::VIEW * m_view
Definition: drawing_tool.h:264
For better understanding of the points that make a dimension:
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCB_SELECTION & selection() const
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void SetEnd(const wxPoint &aPoint)
coord_type GetWidth() const
Definition: box2.h:180
wxPoint GetPosition() const override
Generic, UI-independent tool event.
Definition: tool_event.h:152
Mark the center of a circle or arc with a cross shape.
unsigned int m_lineWidth
Definition: drawing_tool.h:271
void SetArrowLength(int aLength)
#define _(s)
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:265
bool Is45Limited() const
Should the tool use its 45° mode option?
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn 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:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
void constrainDimension(PCB_DIMENSION_BASE *aDim)
Force the dimension lime to be drawn on multiple of 45 degrees.
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:151
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:44
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual void SetStart(const wxPoint &aPoint)
void Activate()
Run the tool.
A leader is a dimension-like object pointing to a specific point.
constexpr int delta
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:159
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
bool HasPosition() const
Definition: tool_event.h:240
virtual const wxPoint & GetEnd() const
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
int GetLineThickness() const
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:263
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:106
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1512
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405
void Update()
Update the dimension's cached text and geometry.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), SELECTION::Add(), KIGFX::VIEW::Add(), PNS::angle(), ARROW, AUTOMATIC, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), PCB_ACTIONS::decWidth, delta, DIMENSION, PCB_ACTIONS::drawAlignedDimension, PCB_ACTIONS::drawCenterDimension, PCB_ACTIONS::drawLeader, PCB_ACTIONS::drawOrthogonalDimension, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_DIM_ALIGNED::GetAngle(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetDesignSettings(), PCB_DIMENSION_BASE::GetEnd(), PCB_DIMENSION_BASE::GetLineThickness(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), PCB_DIMENSION_BASE::GetPosition(), PCB_DIMENSION_BASE::GetStart(), EDA_BASE_FRAME::GetUserUnits(), GetVectorSnapped45(), TOOL_BASE::getView(), BOX2< Vec >::GetWidth(), grid, TOOL_EVENT::HasPosition(), PCB_DIM_ORTHOGONAL::HORIZONTAL, PCB_ACTIONS::incWidth, PCB_TOOL_BASE::Is45Limited(), TOOL_EVENT::IsAction(), KIGFX::VIEW::IsLayerVisible(), KI_FALLTHROUGH, PCB_ACTIONS::layerChanged, m_board, m_controls, m_frame, m_inDrawingTool, PCB_TOOL_BASE::m_isFootprintEditor, m_lineWidth, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MD_SHIFT, MEASURE, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), ortho, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, TOOLS_HOLDER::PopTool(), TOOL_EVENT::Position(), TOOL_MANAGER::PrimeTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), EDA_DRAW_PANEL_GAL::Refresh(), ACTIONS::refreshPreview, SELECTION::Remove(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, PCB_DIMENSION_BASE::SetArrowLength(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), PCB_DIMENSION_BASE::SetEnd(), PCB_DIMENSION_BASE::SetExtensionOffset(), PCB_DIM_ALIGNED::SetHeight(), EDA_TEXT::SetItalic(), PCB_DIMENSION_BASE::SetLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), PCB_DIMENSION_BASE::SetLineThickness(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_TEXT::SetPosition(), PCB_DIMENSION_BASE::SetStart(), PCB_DIMENSION_BASE::SetText(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), PCB_DIMENSION_BASE::Text(), EDA_ITEM::Type(), PCB_DIMENSION_BASE::Update(), KIGFX::VIEW::Update(), PCB_DIM_ORTHOGONAL::VERTICAL, TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

Referenced by setTransitions().

◆ DrawLine()

int DRAWING_TOOL::DrawLine ( const TOOL_EVENT aEvent)

Start 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 continuous polyline.

Definition at line 251 of file drawing_tool.cpp.

252 {
254  return 0;
255 
256  if( m_inDrawingTool )
257  return 0;
258 
260 
261  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
262  PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
263  BOARD_COMMIT commit( m_frame );
264  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
265  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
266 
267  line->SetShape( SHAPE_T::SEGMENT );
268  line->SetFlags( IS_NEW );
269 
270  if( aEvent.HasPosition() )
271  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
272 
273  std::string tool = aEvent.GetCommandStr().get();
274  m_frame->PushTool( tool );
275  Activate();
276 
277  while( drawSegment( tool, &line, startingPoint ) )
278  {
279  if( line )
280  {
281  if( m_isFootprintEditor )
282  static_cast<FP_SHAPE*>( line )->SetLocalCoord();
283 
284  commit.Add( line );
285  commit.Push( _( "Draw a line segment" ) );
286  startingPoint = VECTOR2D( line->GetEnd() );
287  }
288  else
289  {
290  startingPoint = NULLOPT;
291  }
292 
293  line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
294  line->SetShape( SHAPE_T::SEGMENT );
295  line->SetFlags( IS_NEW );
296  }
297 
298  return 0;
299 }
#define IS_NEW
New item, just created.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool m_inDrawingTool
Definition: drawing_tool.h:269
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:91
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:240
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), TOOL_EVENT::DisableGridSnapping(), drawSegment(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, LINE, m_frame, m_inDrawingTool, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), SEGMENT, and EDA_SHAPE::SetShape().

Referenced by setTransitions().

◆ DrawRectangle()

int DRAWING_TOOL::DrawRectangle ( const TOOL_EVENT aEvent)

Start interactively drawing a rectangle.

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

Definition at line 302 of file drawing_tool.cpp.

303 {
305  return 0;
306 
307  if( m_inDrawingTool )
308  return 0;
309 
311 
312  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
313  PCB_SHAPE* rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
314  BOARD_COMMIT commit( m_frame );
315  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
316  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
317 
318  rect->SetShape( SHAPE_T::RECT );
319  rect->SetFilled( false );
320  rect->SetFlags(IS_NEW );
321 
322  if( aEvent.HasPosition() )
323  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
324 
325  std::string tool = aEvent.GetCommandStr().get();
326  m_frame->PushTool( tool );
327  Activate();
328 
329  while( drawSegment( tool, &rect, startingPoint ) )
330  {
331  if( rect )
332  {
333  if( m_isFootprintEditor )
334  static_cast<FP_SHAPE*>( rect )->SetLocalCoord();
335 
336  commit.Add( rect );
337  commit.Push( _( "Draw a rectangle" ) );
338 
340  }
341 
342  rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
343  rect->SetShape( SHAPE_T::RECT );
344  rect->SetFilled( false );
345  rect->SetFlags(IS_NEW );
346  startingPoint = NULLOPT;
347  }
348 
349  return 0;
350 }
#define IS_NEW
New item, just created.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool m_inDrawingTool
Definition: drawing_tool.h:269
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:91
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:240
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), COMMIT::Add(), TOOL_EVENT::DisableGridSnapping(), drawSegment(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetModel(), TOOL_BASE::getViewControls(), TOOL_EVENT::HasPosition(), IS_NEW, m_frame, m_inDrawingTool, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, TOOL_BASE::m_toolMgr, NULLOPT, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), RECT, RECTANGLE, TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectItem, and EDA_SHAPE::SetShape().

Referenced by setTransitions().

◆ drawSegment()

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

Start drawing a selected shape (i.e.

PCB_SHAPE).

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

Definition at line 1402 of file drawing_tool.cpp.

1404 {
1405  SHAPE_T shape = ( *aGraphic )->GetShape();
1406 
1407  // Only three shapes are currently supported
1408  wxASSERT( shape == SHAPE_T::SEGMENT || shape == SHAPE_T::CIRCLE || shape == SHAPE_T::RECT );
1409 
1410  EDA_UNITS userUnits = m_frame->GetUserUnits();
1412  PCB_SHAPE*& graphic = *aGraphic;
1413  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1414 
1415  m_lineWidth = getSegmentWidth( drawingLayer );
1416 
1417  // geometric construction manager
1419 
1420  // drawing assistant overlay
1421  // TODO: workaround because EDA_SHAPE_TYPE_T is not visible from commons.
1422  KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
1423  KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, userUnits, geomShape );
1424 
1425  // Add a VIEW_GROUP that serves as a preview for the new item
1426  PCB_SELECTION preview;
1427  m_view->Add( &preview );
1428  m_view->Add( &twoPointAsst );
1429 
1430  bool started = false;
1431  bool cancelled = false;
1432  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
1433  VECTOR2I cursorPos = m_controls->GetMousePosition();
1434 
1435  auto setCursor =
1436  [&]()
1437  {
1439  };
1440 
1441  auto cleanup =
1442  [&]()
1443  {
1444  preview.Clear();
1445  m_view->Update( &preview );
1446  delete graphic;
1447  graphic = nullptr;
1448 
1449  if( !isLocalOriginSet )
1450  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1451  };
1452 
1453  m_controls->ShowCursor( true );
1454  // Set initial cursor
1455  setCursor();
1456 
1457  // Prime the pump
1459 
1460  if( aStartingPoint )
1462 
1463  // Main loop: keep receiving events
1464  while( TOOL_EVENT* evt = Wait() )
1465  {
1466  setCursor();
1467 
1468  if( started )
1469  m_frame->SetMsgPanel( graphic );
1470 
1471  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1472  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1473  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), drawingLayer );
1474  m_controls->ForceCursorPosition( true, cursorPos );
1475 
1476  if( evt->IsCancelInteractive() )
1477  {
1478  cleanup();
1479 
1480  if( !started )
1481  {
1482  // We've handled the cancel event. Don't cancel other tools
1483  evt->SetPassEvent( false );
1484  m_frame->PopTool( aTool );
1485  cancelled = true;
1486  }
1487 
1488  break;
1489  }
1490  else if( evt->IsActivate() )
1491  {
1492  if( evt->IsPointEditor() )
1493  {
1494  // don't exit (the point editor runs in the background)
1495  }
1496  else if( evt->IsMoveTool() )
1497  {
1498  cleanup();
1499  // leave ourselves on the stack so we come back after the move
1500  cancelled = true;
1501  break;
1502  }
1503  else
1504  {
1505  cleanup();
1506  m_frame->PopTool( aTool );
1507  cancelled = true;
1508  break;
1509  }
1510  }
1511  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1512  {
1513  drawingLayer = m_frame->GetActiveLayer();
1514  m_lineWidth = getSegmentWidth( drawingLayer );
1515 
1516  if( graphic )
1517  {
1518  if( !m_view->IsLayerVisible( drawingLayer ) )
1519  {
1520  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1521  m_frame->GetCanvas()->Refresh();
1522  }
1523 
1524  graphic->SetLayer( drawingLayer );
1525  graphic->SetWidth( m_lineWidth );
1526  m_view->Update( &preview );
1527  frame()->SetMsgPanel( graphic );
1528  }
1529  else
1530  {
1531  evt->SetPassEvent();
1532  }
1533  }
1534  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1535  {
1536  if( started )
1537  {
1538  frame()->OnEditItemRequest( graphic );
1539  m_view->Update( &preview );
1540  frame()->SetMsgPanel( graphic );
1541  break;
1542  }
1543  else
1544  {
1545  evt->SetPassEvent();
1546  }
1547  }
1548  else if( evt->IsClick( BUT_RIGHT ) )
1549  {
1551  }
1552  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1553  {
1554  if( !started )
1555  {
1557 
1558  if( aStartingPoint )
1559  {
1560  cursorPos = aStartingPoint.get();
1561  aStartingPoint = NULLOPT;
1562  }
1563 
1564  m_lineWidth = getSegmentWidth( drawingLayer );
1565 
1566  // Init the new item attributes
1567  graphic->SetShape( static_cast<SHAPE_T>( shape ) );
1568  graphic->SetFilled( false );
1569  graphic->SetWidth( m_lineWidth );
1570  graphic->SetLayer( drawingLayer );
1571  grid.SetSkipPoint( cursorPos );
1572 
1573  twoPointManager.SetOrigin( (wxPoint) cursorPos );
1574  twoPointManager.SetEnd( (wxPoint) cursorPos );
1575 
1576  if( !isLocalOriginSet )
1577  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1578 
1579  preview.Add( graphic );
1580  frame()->SetMsgPanel( graphic );
1581  m_controls->SetAutoPan( true );
1582  m_controls->CaptureCursor( true );
1583 
1584  if( !m_view->IsLayerVisible( drawingLayer ) )
1585  {
1586  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1587  m_frame->GetCanvas()->Refresh();
1588  }
1589 
1590  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1591 
1592  started = true;
1593  }
1594  else if( shape == SHAPE_T::CIRCLE )
1595  {
1596  // No clever logic if drawing a circle
1597  preview.Clear();
1598  twoPointManager.Reset();
1599  break;
1600  }
1601  else
1602  {
1603  PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
1604 
1605  if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
1606  || ( evt->IsDblClick( BUT_LEFT ) && shape == SHAPE_T::SEGMENT )
1607  || snapItem )
1608  // User has clicked twice in the same spot
1609  // or clicked on the end of an existing segment (closing a path)
1610  {
1611  BOARD_COMMIT commit( m_frame );
1612 
1613  // If the user clicks on an existing snap point from a drawsegment
1614  // we finish the segment as they are likely closing a path
1615  if( snapItem && ( shape == SHAPE_T::RECT || graphic->GetLength() > 0.0 ) )
1616  {
1617  commit.Add( graphic );
1618  commit.Push( _( "Draw a line segment" ) );
1619  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, graphic );
1620  }
1621  else
1622  {
1623  delete graphic;
1624  }
1625 
1626  graphic = nullptr;
1627  }
1628 
1629  preview.Clear();
1630  twoPointManager.Reset();
1631  break;
1632  }
1633 
1634  twoPointManager.SetEnd( cursorPos );
1635  }
1636  else if( evt->IsMotion() )
1637  {
1638  // 45 degree lines
1639  if( started && Is45Limited() )
1640  {
1641  const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
1642 
1643  // get a restricted 45/H/V line from the last fixed point to the cursor
1644  auto newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECT ) );
1645  m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
1646  twoPointManager.SetEnd( twoPointManager.GetOrigin() + (wxPoint) newEnd );
1647  twoPointManager.SetAngleSnap( true );
1648  }
1649  else
1650  {
1651  twoPointManager.SetEnd( (wxPoint) cursorPos );
1652  twoPointManager.SetAngleSnap( false );
1653  }
1654 
1655  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1656  m_view->Update( &preview );
1657  m_view->Update( &twoPointAsst );
1658  }
1659  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1660  {
1662  graphic->SetWidth( m_lineWidth );
1663  m_view->Update( &preview );
1664  frame()->SetMsgPanel( graphic );
1665  }
1666  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1667  {
1669  graphic->SetWidth( m_lineWidth );
1670  m_view->Update( &preview );
1671  frame()->SetMsgPanel( graphic );
1672  }
1673  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1674  {
1675  isLocalOriginSet = true;
1676  evt->SetPassEvent();
1677  }
1678  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1679  {
1680  if( frame()->GetUserUnits() != userUnits )
1681  {
1682  userUnits = frame()->GetUserUnits();
1683  twoPointAsst.SetUnits( userUnits );
1684  m_view->Update( &twoPointAsst );
1685  }
1686  evt->SetPassEvent();
1687  }
1688  else
1689  {
1690  evt->SetPassEvent();
1691  }
1692  }
1693 
1694  if( !isLocalOriginSet ) // reset the relative coordinate if it was not set before
1695  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1696 
1697  m_view->Remove( &twoPointAsst );
1698  m_view->Remove( &preview );
1699  m_frame->SetMsgPanel( board() );
1700 
1702  m_controls->SetAutoPan( false );
1703  m_controls->CaptureCursor( false );
1704  m_controls->ForceCursorPosition( false );
1705 
1706  return !cancelled;
1707 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:83
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:167
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
Represents an assistant draw when interactively drawing a line or circle on a canvas.
Represent a very simple geometry manager for items that have a start and end point.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:272
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:348
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void Reset()
Reset the manager to the initial state.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
APPEARANCE_CONTROLS * GetAppearancePanel()
static void updateSegmentFromGeometryMgr(const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER &aMgr, PCB_SHAPE *aGraphic)
Update a PCB_SHAPE from the current state of a #TWO_POINT_GEOMETRY_MANAGER.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:170
KIGFX::VIEW * m_view
Definition: drawing_tool.h:264
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
const PCB_SELECTION & selection() const
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void PopTool(const std::string &actionName)
SHAPE_T
Definition: eda_shape.h:40
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
unsigned int m_lineWidth
Definition: drawing_tool.h:271
void SetOrigin(const VECTOR2I &aOrigin)
< Set the origin of the ruler (the fixed end)
#define _(s)
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:265
bool Is45Limited() const
Should the tool use its 45° mode option?
int getSegmentWidth(PCB_LAYER_ID aLayer) const
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn 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:267
EDA_UNITS
Definition: eda_units.h:38
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
static TOOL_ACTION updateUnits
Definition: actions.h:147
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
static TOOL_ACTION resetLocalCoords
Definition: actions.h:150
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:106
static TOOL_ACTION cursorClick
Definition: actions.h:123
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1512
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:90
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405

References _, COMMIT::Add(), SELECTION::Add(), KIGFX::VIEW::Add(), ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), CIRCLE, SELECTION::Clear(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::GetEnd(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::GetOrigin(), PCB_BASE_FRAME::GetScreen(), getSegmentWidth(), EDA_BASE_FRAME::GetUserUnits(), GetVectorSnapped45(), TOOL_BASE::getView(), grid, PCB_ACTIONS::incWidth, PCB_TOOL_BASE::Is45Limited(), KIGFX::VIEW::IsLayerVisible(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, BASE_SCREEN::m_LocalOrigin, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, m_view, MD_SHIFT, NULLOPT, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PENCIL, TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), RECT, EDA_DRAW_PANEL_GAL::Refresh(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::Reset(), ACTIONS::resetLocalCoords, TOOL_MANAGER::RunAction(), SEGMENT, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetAngleSnap(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetEnd(), APPEARANCE_CONTROLS::SetLayerVisible(), EDA_DRAW_FRAME::SetMsgPanel(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetOrigin(), KIGFX::PREVIEW::TWO_POINT_ASSISTANT::SetUnits(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), updateSegmentFromGeometryMgr(), ACTIONS::updateUnits, TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

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

◆ DrawSpecificationStackup()

std::vector< BOARD_ITEM * > DRAWING_TOOL::DrawSpecificationStackup ( const wxPoint &  origin,
PCB_LAYER_ID  aLayer,
bool  aDrawNow,
wxPoint *  tablesize 
)

Definition at line 211 of file drawing_stackup_table_tool.cpp.

215 {
216  BOARD_COMMIT commit( m_frame );
217  std::vector<std::vector<PCB_TEXT*>> texts;
218 
219  // Style : Header
220  PCB_TEXT* headStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
221  headStyle->SetLayer( Eco1_User );
222  headStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
223  headStyle->SetTextThickness( Millimeter2iu( 0.3 ) );
224  headStyle->SetItalic( false );
225  headStyle->SetTextPos( wxPoint( 0, 0 ) );
226  headStyle->SetText( "Layer" );
228  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
229 
230  // Style : data
231  PCB_TEXT* dataStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
232  dataStyle->SetLayer( Eco1_User );
233  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
234  dataStyle->SetTextThickness( Millimeter2iu( 0.1 ) );
235  dataStyle->SetItalic( false );
236  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
237  dataStyle->SetText( "Layer" );
239  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
240 
241  //Get Layer names
243  BOARD_STACKUP& stackup = dsnSettings.GetStackupDescriptor();
244  stackup.SynchronizeWithBoard( &dsnSettings );
245 
246  std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
247 
248  std::vector<PCB_TEXT*> colLayer;
249  std::vector<PCB_TEXT*> colType;
250  std::vector<PCB_TEXT*> colMaterial;
251  std::vector<PCB_TEXT*> colThickness;
252  std::vector<PCB_TEXT*> colColor;
253  std::vector<PCB_TEXT*> colEpsilon;
254  std::vector<PCB_TEXT*> colTanD;
255  PCB_TEXT* t;
256 
257  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
258  t->SetText( _( "Layer Name" ) );
259  colLayer.push_back( t );
260 
261  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
262  t->SetText( _( "Type" ) );
263  colType.push_back( t );
264 
265  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
266  t->SetText( _( "Material" ) );
267  colMaterial.push_back( t );
268 
269  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
270 
271  switch( m_frame->GetUserUnits() )
272  {
273  case EDA_UNITS::MILLIMETRES: t->SetText( _( "Thickness (mm)" ) ); break;
274  case EDA_UNITS::INCHES: t->SetText( _( "Thickness (inches)" ) ); break;
275  case EDA_UNITS::MILS: t->SetText( _( "Thickness (mils)" ) ); break;
276  default: wxFAIL_MSG( "Unhandled unit type" );
277  }
278 
279  colThickness.push_back( t );
280 
281  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
282  t->SetText( _( "Color" ) );
283  colColor.push_back( t );
284 
285  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
286  t->SetText( _( "Epsilon R" ) );
287  colEpsilon.push_back( t );
288 
289  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
290  t->SetText( _( "Loss Tangent" ) );
291  colTanD.push_back( t );
292 
293  for( int i = 0; i < stackup.GetCount(); i++ )
294  {
295  BOARD_STACKUP_ITEM* stackup_item = layers.at( i );
296 
297  for( int j = 0; j < stackup_item->GetSublayersCount(); j++ )
298  {
299  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
300 
301  // Layer names are empty until we close at least once the board setup dialog.
302  // If the user did not open the dialog, then get the names from the board.
303  // But dielectric layer names will be missing.
304  // In this case, for dielectric, a dummy name will be used
305  if( stackup_item->GetLayerName().IsEmpty() )
306  {
307  wxString ly_name;
308 
309  if( IsValidLayer( stackup_item->GetBrdLayerId() ) )
310  ly_name = m_frame->GetBoard()->GetLayerName( stackup_item->GetBrdLayerId() );
311 
312  if( ly_name.IsEmpty() && stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
313  ly_name = _( "Dielectric" );
314 
315  t->SetText( ly_name );
316  }
317  else
318  t->SetText( stackup_item->GetLayerName() );
319 
320  colLayer.push_back( t );
321 
322  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
323  t->SetText( stackup_item->GetTypeName() );
324  colType.push_back( t );
325 
326  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
327  t->SetText( stackup_item->GetMaterial( j ) );
328  colMaterial.push_back( t );
329 
330  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
331  t->SetText( StringFromValue( m_frame->GetUserUnits(), stackup_item->GetThickness( j ),
332  true ) );
333  colThickness.push_back( t );
334 
335  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
336  t->SetText( stackup_item->GetColor() );
337  colColor.push_back( t );
338 
339  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
340  t->SetText( StringFromValue( EDA_UNITS::UNSCALED, stackup_item->GetEpsilonR( j ),
341  false ) );
342  colEpsilon.push_back( t );
343 
344  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
346  false ) );
347  colTanD.push_back( t );
348  }
349  }
350 
351  texts.push_back( colLayer );
352  texts.push_back( colType );
353  texts.push_back( colMaterial );
354  texts.push_back( colThickness );
355  texts.push_back( colColor );
356  texts.push_back( colEpsilon );
357  texts.push_back( colTanD );
358  std::vector<BOARD_ITEM*> table = initTextTable( texts, aOrigin, aLayer, tableSize, true );
359 
360  if( aDrawNow )
361  {
362  for( BOARD_ITEM* item : table )
363  commit.Add( item );
364 
365  commit.Push( _( "Insert board stackup table" ) );
366  }
367 
368  return table;
369 }
BOARD_STACKUP_ITEM_TYPE GetType() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:362
Manage layers needed to make a physical board.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
int GetSublayersCount() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void SetItalic(bool isItalic)
Definition: eda_text.h:179
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:246
wxString GetColor() const
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
static std::vector< BOARD_ITEM * > initTextTable(std::vector< std::vector< PCB_TEXT * >> aContent, wxPoint origin, PCB_LAYER_ID aLayer, wxPoint *aTableSize, bool aDrawFrame=true)
double GetLossTangent(int aDielectricSubLayer=0) const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
BOARD_STACKUP & GetStackupDescriptor()
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
int GetThickness(int aDielectricSubLayer=0) const
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:202
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetTypeName() const
#define _(s)
int GetCount() const
Manage one layer needed to make a physical board.
Definition: board_stackup.h:89
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
PCB_LAYER_ID GetBrdLayerId() const
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
wxString GetLayerName() const
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
bool IsValidLayer(LAYER_NUM aLayerId)
Test whether a given integer is a valid layer index, i.e.
Definition: layer_ids.h:774
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:169
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:159
BOARD * GetBoard() const
static constexpr int Millimeter2iu(double mm)
wxString GetMaterial(int aDielectricSubLayer=0) const
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Container for design settings for a BOARD object.

References _, COMMIT::Add(), BS_ITEM_TYPE_DIELECTRIC, BOARD_ITEM::Duplicate(), Eco1_User, PCB_BASE_FRAME::GetBoard(), BOARD_STACKUP_ITEM::GetBrdLayerId(), BOARD_STACKUP_ITEM::GetColor(), BOARD_STACKUP::GetCount(), PCB_BASE_FRAME::GetDesignSettings(), BOARD_STACKUP_ITEM::GetEpsilonR(), BOARD_STACKUP_ITEM::GetLayerName(), BOARD::GetLayerName(), BOARD_STACKUP::GetList(), BOARD_STACKUP_ITEM::GetLossTangent(), BOARD_STACKUP_ITEM::GetMaterial(), PCB_BASE_FRAME::GetModel(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_STACKUP_ITEM::GetSublayersCount(), BOARD_STACKUP_ITEM::GetThickness(), BOARD_STACKUP_ITEM::GetType(), BOARD_STACKUP_ITEM::GetTypeName(), EDA_BASE_FRAME::GetUserUnits(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, INCHES, initTextTable(), IsValidLayer(), m_frame, Millimeter2iu(), MILLIMETRES, MILS, BOARD_COMMIT::Push(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetText(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetVertJustify(), StringFromValue(), BOARD_STACKUP::SynchronizeWithBoard(), and UNSCALED.

Referenced by PlaceStackup().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 2262 of file drawing_tool.cpp.

2263 {
2264  if( m_isFootprintEditor )
2265  return 0;
2266 
2267  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
2268  {
2270  PCB_GRID_HELPER m_gridHelper;
2271  std::shared_ptr<DRC_ENGINE> m_drcEngine;
2272  int m_drcEpsilon;
2273  int m_worstClearance;
2274  bool m_allowDRCViolations;
2275 
2276  VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
2277  m_frame( aFrame ),
2278  m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ),
2279  m_drcEngine( aFrame->GetBoard()->GetDesignSettings().m_DRCEngine ),
2280  m_drcEpsilon( aFrame->GetBoard()->GetDesignSettings().GetDRCEpsilon() ),
2281  m_worstClearance( 0 )
2282  {
2284 
2285  m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations();
2286 
2287  try
2288  {
2289  m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() );
2290 
2291  DRC_CONSTRAINT constraint;
2292 
2293  if( m_drcEngine->QueryWorstConstraint( CLEARANCE_CONSTRAINT, constraint ) )
2294  m_worstClearance = constraint.GetValue().Min();
2295 
2296  if( m_drcEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, constraint ) )
2297  m_worstClearance = std::max( m_worstClearance, constraint.GetValue().Min() );
2298 
2299  for( FOOTPRINT* footprint : aFrame->GetBoard()->Footprints() )
2300  {
2301  for( PAD* pad : footprint->Pads() )
2302  m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
2303  }
2304  }
2305  catch( PARSE_ERROR& )
2306  {
2307  }
2308  }
2309 
2310  virtual ~VIA_PLACER()
2311  {
2312  }
2313 
2314  PCB_TRACK* findTrack( PCB_VIA* aVia )
2315  {
2316  const LSET lset = aVia->GetLayerSet();
2317  wxPoint position = aVia->GetPosition();
2318  BOX2I bbox = aVia->GetBoundingBox();
2319 
2320  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2321  auto view = m_frame->GetCanvas()->GetView();
2322  std::vector<PCB_TRACK*> possible_tracks;
2323 
2324  view->Query( bbox, items );
2325 
2326  for( auto it : items )
2327  {
2328  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
2329 
2330  if( !(item->GetLayerSet() & lset ).any() )
2331  continue;
2332 
2333  if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
2334  {
2335  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
2336  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
2337  possible_tracks.push_back( track );
2338  }
2339  }
2340 
2341  PCB_TRACK* return_track = nullptr;
2342  int min_d = std::numeric_limits<int>::max();
2343 
2344  for( PCB_TRACK* track : possible_tracks )
2345  {
2346  SEG test( track->GetStart(), track->GetEnd() );
2347  int dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
2348 
2349  if( dist < min_d )
2350  {
2351  min_d = dist;
2352  return_track = track;
2353  }
2354  }
2355 
2356  return return_track;
2357  }
2358 
2359  bool hasDRCViolation( PCB_VIA* aVia, BOARD_ITEM* aOther )
2360  {
2361  // It would really be better to know what particular nets a nettie should allow,
2362  // but for now it is what it is.
2363  if( DRC_ENGINE::IsNetTie( aOther ) )
2364  return false;
2365 
2366  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aOther );
2367 
2368  if( cItem && cItem->GetNetCode() == aVia->GetNetCode() )
2369  return false;
2370 
2371  DRC_CONSTRAINT constraint;
2372  int clearance;
2373 
2374  for( PCB_LAYER_ID layer : aOther->GetLayerSet().Seq() )
2375  {
2376  if( !IsCopperLayer( layer ) )
2377  continue;
2378 
2379  constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aVia, aOther, layer );
2380  clearance = constraint.GetValue().Min();
2381 
2382  if( clearance >= 0 )
2383  {
2384  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, layer );
2385  std::shared_ptr<SHAPE> otherShape = DRC_ENGINE::GetShape( aOther, layer );
2386 
2387  if( viaShape->Collide( otherShape.get(), clearance - m_drcEpsilon ) )
2388  return true;
2389  }
2390  }
2391 
2392  std::unique_ptr<SHAPE_SEGMENT> holeShape;
2393 
2394  if( aOther->Type() == PCB_VIA_T )
2395  {
2396  PCB_VIA* via = static_cast<PCB_VIA*>( aOther );
2397  wxPoint pos = via->GetPosition();
2398 
2399  holeShape.reset( new SHAPE_SEGMENT( pos, pos, via->GetDrill() ) );
2400  }
2401  else if( aOther->Type() == PCB_PAD_T )
2402  {
2403  PAD* pad = static_cast<PAD*>( aOther );
2404 
2405  if( pad->GetDrillSize().x )
2406  holeShape.reset( new SHAPE_SEGMENT( *pad->GetEffectiveHoleShape() ) );
2407  }
2408 
2409  if( holeShape )
2410  {
2411  constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, aVia, aOther,
2412  UNDEFINED_LAYER );
2413  clearance = constraint.GetValue().Min();
2414 
2415  if( clearance >= 0 )
2416  {
2417  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, UNDEFINED_LAYER );
2418 
2419  if( viaShape->Collide( holeShape.get(), clearance - m_drcEpsilon ) )
2420  return true;
2421  }
2422  }
2423 
2424  return false;
2425  }
2426 
2427  bool checkDRCViolation( PCB_VIA* aVia )
2428  {
2429  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2430  std::set<BOARD_ITEM*> checkedItems;
2431  BOX2I bbox = aVia->GetBoundingBox();
2432 
2433  bbox.Inflate( m_worstClearance );
2434  m_frame->GetCanvas()->GetView()->Query( bbox, items );
2435 
2436  for( std::pair<KIGFX::VIEW_ITEM*, int> it : items )
2437  {
2438  BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( it.first );
2439 
2440  if( !item )
2441  continue;
2442 
2443  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
2444  continue; // stitching vias bind to zones, so ignore them
2445 
2446  if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_GROUP_T )
2447  continue; // check against children, but not against footprint itself
2448 
2449  if( item->Type() == PCB_FP_TEXT_T && !static_cast<FP_TEXT*>( item )->IsVisible() )
2450  continue; // ignore hidden items
2451 
2452  if( checkedItems.count( item ) )
2453  continue;
2454 
2455  if( hasDRCViolation( aVia, item ) )
2456  return true;
2457 
2458  checkedItems.insert( item );
2459  }
2460 
2461  return false;
2462  }
2463 
2464  PAD* findPad( PCB_VIA* aVia )
2465  {
2466  const wxPoint position = aVia->GetPosition();
2467  const LSET lset = aVia->GetLayerSet();
2468 
2469  for( FOOTPRINT* fp : m_board->Footprints() )
2470  {
2471  for(PAD* pad : fp->Pads() )
2472  {
2473  if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
2474  if( pad->GetNetCode() > 0 )
2475  return pad;
2476  }
2477  }
2478 
2479  return nullptr;
2480  }
2481 
2482  int findStitchedZoneNet( PCB_VIA* aVia )
2483  {
2484  const wxPoint position = aVia->GetPosition();
2485  const LSET lset = aVia->GetLayerSet();
2486 
2487  std::vector<ZONE*> foundZones;
2488 
2489  for( ZONE* zone : m_board->Zones() )
2490  {
2491  for( PCB_LAYER_ID layer : LSET( zone->GetLayerSet() & lset ).Seq() )
2492  {
2493  if( zone->HitTestFilledArea( layer, position ) )
2494  foundZones.push_back( zone );
2495  }
2496  }
2497 
2498  std::sort( foundZones.begin(), foundZones.end(),
2499  [] ( const ZONE* a, const ZONE* b )
2500  {
2501  return a->GetLayer() < b->GetLayer();
2502  } );
2503 
2504  // first take the net of the active layer
2505  for( ZONE* z : foundZones )
2506  {
2507  if( m_frame->GetActiveLayer() == z->GetLayer() )
2508  return z->GetNetCode();
2509  }
2510 
2511  // none? take the topmost visible layer
2512  for( ZONE* z : foundZones )
2513  {
2514  if( m_board->IsLayerVisible( z->GetLayer() ) )
2515  return z->GetNetCode();
2516  }
2517 
2518  return -1;
2519  }
2520 
2521  void SnapItem( BOARD_ITEM *aItem ) override
2522  {
2523  // If you place a Via on a track but not on its centerline, the current
2524  // connectivity algorithm will require us to put a kink in the track when
2525  // we break it (so that each of the two segments ends on the via center).
2526  // That's not ideal, and is in fact probably worse than forcing snap in
2527  // this situation.
2528 
2529  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
2530  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
2531  wxPoint position = via->GetPosition();
2532  PCB_TRACK* track = findTrack( via );
2533 
2534  if( track )
2535  {
2536  SEG trackSeg( track->GetStart(), track->GetEnd() );
2537  VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
2538 
2539  aItem->SetPosition( (wxPoint) snap );
2540  }
2541  }
2542 
2543  bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
2544  {
2545  WX_INFOBAR* infobar = m_frame->GetInfoBar();
2546  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
2547  wxPoint viaPos = via->GetPosition();
2548  PCB_TRACK* track = findTrack( via );
2549  PAD* pad = findPad( via );
2550 
2551  if( track )
2552  via->SetNetCode( track->GetNetCode() );
2553  else if( pad )
2554  via->SetNetCode( pad->GetNetCode() );
2555  else
2556  via->SetNetCode( findStitchedZoneNet( via ) );
2557 
2558  if( !m_allowDRCViolations && checkDRCViolation( via ) )
2559  {
2560  m_frame->ShowInfoBarError( _( "Via location violates DRC." ), true,
2562  via->SetNetCode( 0 );
2563  return false;
2564  }
2565  else
2566  {
2568  infobar->Dismiss();
2569  }
2570 
2571  if( track )
2572  {
2573  if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
2574  {
2575  aCommit.Modify( track );
2576 
2577  PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
2578  const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
2579 
2580  track->SetEnd( viaPos );
2581  newTrack->SetStart( viaPos );
2582  aCommit.Add( newTrack );
2583  }
2584  }
2585  else if( !pad )
2586  {
2587  via->SetNetCode( findStitchedZoneNet( via ) );
2588  via->SetIsFree();
2589  }
2590 
2591  aCommit.Add( aItem );
2592  return true;
2593  }
2594 
2595  std::unique_ptr<BOARD_ITEM> CreateItem() override
2596  {
2598  PCB_VIA* via = new PCB_VIA( m_board );
2599 
2600  via->SetNetCode( 0 );
2601  via->SetViaType( bds.m_CurrentViaType );
2602 
2603  // for microvias, the size and hole will be changed later.
2604  via->SetWidth( bds.GetCurrentViaSize() );
2605  via->SetDrill( bds.GetCurrentViaDrill() );
2606 
2607  // Usual via is from copper to component.
2608  // layer pair is B_Cu and F_Cu.
2609  via->SetLayerPair( B_Cu, F_Cu );
2610 
2611  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
2612  PCB_LAYER_ID last_layer;
2613 
2614  // prepare switch to new active layer:
2615  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
2616  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
2617  else
2618  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
2619 
2620  // Adjust the actual via layer pair
2621  switch( via->GetViaType() )
2622  {
2623  case VIATYPE::BLIND_BURIED:
2624  via->SetLayerPair( first_layer, last_layer );
2625  break;
2626 
2627  case VIATYPE::MICROVIA: // from external to the near neighbor inner layer
2628  {
2629  PCB_LAYER_ID last_inner_layer =
2630  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
2631 
2632  if( first_layer == B_Cu )
2633  last_layer = last_inner_layer;
2634  else if( first_layer == F_Cu )
2635  last_layer = In1_Cu;
2636  else if( first_layer == last_inner_layer )
2637  last_layer = B_Cu;
2638  else if( first_layer == In1_Cu )
2639  last_layer = F_Cu;
2640 
2641  // else error: will be removed later
2642  via->SetLayerPair( first_layer, last_layer );
2643 
2644  // Update diameter and hole size, which where set previously for normal vias
2645  NETCLASS* netClass = via->GetNetClass();
2646 
2647  via->SetWidth( netClass->GetuViaDiameter() );
2648  via->SetDrill( netClass->GetuViaDrill() );
2649  }
2650  break;
2651 
2652  default:
2653  break;
2654  }
2655 
2656  return std::unique_ptr<BOARD_ITEM>( via );
2657  }
2658  };
2659 
2660  VIA_PLACER placer( frame() );
2661 
2662  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
2663 
2664  doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
2666 
2667  return 0;
2668 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_track.cpp:240
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
ZONES & Zones()
Definition: board.h:239
BOARD * m_board
Definition: drawing_tool.h:266
wxPoint GetPosition() const override
Definition: pcb_track.h:392
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
const wxPoint & GetEnd() const
Definition: pcb_track.h:105
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:57
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
static std::shared_ptr< SHAPE > GetShape(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
void SetEnd(const wxPoint &aEnd)
Definition: pcb_track.h:104
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:402
class PAD, a pad in a footprint
Definition: typeinfo.h:89
int GetWidth() const
Definition: pcb_track.h:102
T Min() const
Definition: minoptmax.h:33
static bool IsNetTie(BOARD_ITEM *aItem)
VIATYPE m_CurrentViaType
(VIA_BLIND_BURIED, VIA_THROUGH, VIA_MICROVIA)
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
PADS & Pads()
Definition: footprint.h:168
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
Definition: kiid.h:44
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:175
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
RAII class that sets an value at construction and resets it to the original value at destruction.
MESSAGE_TYPE GetMessageType() const
Definition: infobar.h:99
Allow repeat placement of the item.
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: zone.cpp:222
FOOTPRINTS & Footprints()
Definition: board.h:233
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
bool TestSegmentHit(const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
void SetStart(const wxPoint &aStart)
Definition: pcb_track.h:107
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:44
#define _(s)
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
int GetuViaDiameter() const
Definition: netclass.h:140
bool m_isFootprintEditor
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:796
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:267
void SetSnap(bool aSnap)
Definition: grid_helper.h:64
BOARD * GetBoard()
const KIID m_Uuid
Definition: eda_item.h:475
Definition: seg.h:40
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:473
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122
Common, abstract interface for edit frames.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
int GetCopperLayerCount() const
Definition: board.cpp:455
class ZONE, managed by a footprint
Definition: typeinfo.h:94
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
WX_INFOBAR * GetInfoBar()
int GetuViaDrill() const
Definition: netclass.h:144
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:424
void doInteractiveItemPlacement(const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
BOARD * GetBoard() const
ROUTER * Router() const
Definition: pad.h:57
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:181
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:43
const wxPoint & GetStart() const
Definition: pcb_track.h:108
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:145
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.

References _, COMMIT::Add(), PCB_GRID_HELPER::AlignToSegment(), PNS::ROUTING_SETTINGS::AllowDRCViolations(), B_Cu, BLIND_BURIED, CLEARANCE_CONSTRAINT, PCB_TRACK::Clone(), WX_INFOBAR::Dismiss(), PCB_TOOL_BASE::doInteractiveItemPlacement(), WX_INFOBAR::DRC_VIOLATION, EuclideanNorm(), F_Cu, PCB_TOOL_BASE::footprint(), BOARD::Footprints(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_FRAME::GetBoard(), PCB_TRACK::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetCopperLayerCount(), BOARD_DESIGN_SETTINGS::GetCurrentViaDrill(), BOARD_DESIGN_SETTINGS::GetCurrentViaSize(), PCB_BASE_EDIT_FRAME::GetDesignRulesPath(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetDRCEpsilon(), PCB_TRACK::GetEnd(), EDA_BASE_FRAME::GetInfoBar(), ZONE::GetLayer(), BOARD_ITEM::GetLayerSet(), PCB_VIA::GetLayerSet(), PCB_BASE_FRAME::GetMagneticItemsSettings(), WX_INFOBAR::GetMessageType(), BOARD_CONNECTED_ITEM::GetNetCode(), PCB_VIA::GetPosition(), PCB_BASE_FRAME::GetScreen(), DRC_ENGINE::GetShape(), PCB_TRACK::GetStart(), TOOL_MANAGER::GetTool(), TOOLS_HOLDER::GetToolManager(), NETCLASS::GetuViaDiameter(), NETCLASS::GetuViaDrill(), DRC_CONSTRAINT::GetValue(), PCB_DRAW_PANEL_GAL::GetView(), PCB_TRACK::GetWidth(), HOLE_CLEARANCE_CONSTRAINT, In1_Cu, BOX2< Vec >::Inflate(), PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_SINGLE_CLICK, IsCopperLayer(), BOARD::IsLayerVisible(), DRC_ENGINE::IsNetTie(), m_board, BOARD_DESIGN_SETTINGS::m_CurrentViaType, BOARD_DESIGN_SETTINGS::m_DRCEngine, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_mode, PCB_SCREEN::m_Route_Layer_BOTTOM, PCB_SCREEN::m_Route_Layer_TOP, EDA_ITEM::m_Uuid, MD_SHIFT, MICROVIA, MINOPTMAX< T >::Min(), COMMIT::Modify(), pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, KIGFX::VIEW::Query(), PNS::TOOL_BASE::Router(), LSET::Seq(), PCB_TRACK::SetEnd(), EDA_ITEM::SetPosition(), GRID_HELPER::SetSnap(), PCB_TRACK::SetStart(), PNS::ROUTER::Settings(), EDA_BASE_FRAME::ShowInfoBarError(), TestSegmentHit(), ToLAYER_ID(), EDA_ITEM::Type(), UNDEFINED_LAYER, VIA, via, PCB_TOOL_BASE::view(), and BOARD::Zones().

Referenced by setTransitions().

◆ DrawZone()

int DRAWING_TOOL::DrawZone ( const TOOL_EVENT aEvent)

Start interactively drawing a zone.

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

The event parameter indicates which type of zone to draw:

  • ADD add a new zone/keepout with fresh settings.
  • CUTOUT add a cutout to an existing zone.
  • SIMILAR add a new zone with the same settings as an existing one.

Definition at line 2008 of file drawing_tool.cpp.

2009 {
2010  if( m_isFootprintEditor && !m_frame->GetModel() )
2011  return 0;
2012 
2013  ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
2014  MODE drawMode = MODE::ZONE;
2015 
2016  if( aEvent.IsAction( &PCB_ACTIONS::drawRuleArea ) )
2017  drawMode = MODE::KEEPOUT;
2018 
2019  if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
2020  drawMode = MODE::GRAPHIC_POLYGON;
2021 
2022  SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
2023 
2024  // get a source zone, if we need one. We need it for:
2025  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
2026  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
2027  ZONE* sourceZone = nullptr;
2028 
2029  if( !getSourceZoneForAction( zoneMode, &sourceZone ) )
2030  return 0;
2031 
2032  // Turn zones on if they are off, so that the created object will be visible after completion
2034 
2036 
2037  params.m_keepout = drawMode == MODE::KEEPOUT;
2038  params.m_mode = zoneMode;
2039  params.m_sourceZone = sourceZone;
2040 
2041  if( zoneMode == ZONE_MODE::SIMILAR )
2042  params.m_layer = sourceZone->GetLayer();
2043  else
2044  params.m_layer = m_frame->GetActiveLayer();
2045 
2046  ZONE_CREATE_HELPER zoneTool( *this, params );
2047  // the geometry manager which handles the zone geometry, and hands the calculated points
2048  // over to the zone creator tool
2049  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
2050  bool constrainAngle = false;
2051  bool started = false;
2053  STATUS_TEXT_POPUP status( m_frame );
2054 
2055  status.SetTextColor( wxColour( 255, 0, 0 ) );
2056  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
2057 
2058  std::string tool = aEvent.GetCommandStr().get();
2059  m_frame->PushTool( tool );
2060 
2061  auto setCursor =
2062  [&]()
2063  {
2065  };
2066 
2067  auto cleanup =
2068  [&] ()
2069  {
2070  polyGeomMgr.Reset();
2071  started = false;
2072  grid.ClearSkipPoint();
2073  m_controls->SetAutoPan( false );
2074  m_controls->CaptureCursor( false );
2075  };
2076 
2077  Activate();
2078  // Must be done after Activate() so that it gets set into the correct context
2079  m_controls->ShowCursor( true );
2080  // Set initial cursor
2081  setCursor();
2082 
2083  // Prime the pump
2084  if( aEvent.HasPosition() )
2085  m_toolMgr->PrimeTool( aEvent.Position() );
2086 
2087  // Main loop: keep receiving events
2088  while( TOOL_EVENT* evt = Wait() )
2089  {
2090  setCursor();
2091 
2092  LSET layers( m_frame->GetActiveLayer() );
2093  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2094  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2095 
2096  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
2097  cursorPos = grid.BestSnapAnchor( cursorPos, layers );
2098 
2099  m_controls->ForceCursorPosition( true, cursorPos );
2100 
2101  if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || Is45Limited() )
2102  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2103  else
2104  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
2105 
2106  if( evt->IsCancelInteractive() )
2107  {
2108  if( polyGeomMgr.IsPolygonInProgress() )
2109  {
2110  cleanup();
2111  }
2112  else
2113  {
2114  // We've handled the cancel event. Don't cancel other tools
2115  evt->SetPassEvent( false );
2116  m_frame->PopTool( tool );
2117  break;
2118  }
2119  }
2120  else if( evt->IsActivate() )
2121  {
2122  if( polyGeomMgr.IsPolygonInProgress() )
2123  cleanup();
2124 
2125  if( evt->IsPointEditor() )
2126  {
2127  // don't exit (the point editor runs in the background)
2128  }
2129  else if( evt->IsMoveTool() )
2130  {
2131  // leave ourselves on the stack so we come back after the move
2132  break;
2133  }
2134  else
2135  {
2136  m_frame->PopTool( tool );
2137  break;
2138  }
2139  }
2140  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
2141  {
2142  if( zoneMode != ZONE_MODE::SIMILAR )
2143  params.m_layer = frame()->GetActiveLayer();
2144 
2145  if( !m_view->IsLayerVisible( params.m_layer ) )
2146  {
2147  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2148  m_frame->GetCanvas()->Refresh();
2149  }
2150  }
2151  else if( evt->IsClick( BUT_RIGHT ) )
2152  {
2154  }
2155  // events that lock in nodes
2156  else if( evt->IsClick( BUT_LEFT )
2157  || evt->IsDblClick( BUT_LEFT )
2158  || evt->IsAction( &PCB_ACTIONS::closeOutline ) )
2159  {
2160  // Check if it is double click / closing line (so we have to finish the zone)
2161  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
2162  || evt->IsAction( &PCB_ACTIONS::closeOutline )
2163  || polyGeomMgr.NewPointClosesOutline( cursorPos );
2164 
2165  if( endPolygon )
2166  {
2167  polyGeomMgr.SetFinished();
2168  polyGeomMgr.Reset();
2169 
2170  started = false;
2171  m_controls->SetAutoPan( false );
2172  m_controls->CaptureCursor( false );
2173  }
2174  // adding a corner
2175  else if( polyGeomMgr.AddPoint( cursorPos ) )
2176  {
2177  if( !started )
2178  {
2179  started = true;
2180 
2181  POLYGON_GEOM_MANAGER::LEADER_MODE leaderMode = polyGeomMgr.GetLeaderMode();
2182  constrainAngle = ( leaderMode == POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2183 
2184  m_controls->SetAutoPan( true );
2185  m_controls->CaptureCursor( true );
2186 
2187  if( !m_view->IsLayerVisible( params.m_layer ) )
2188  {
2189  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2190  m_frame->GetCanvas()->Refresh();
2191  }
2192  }
2193  }
2194  }
2195  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
2196  {
2197  polyGeomMgr.DeleteLastCorner();
2198 
2199  if( !polyGeomMgr.IsPolygonInProgress() )
2200  {
2201  // report finished as an empty shape
2202  polyGeomMgr.SetFinished();
2203 
2204  // start again
2205  started = false;
2206  m_controls->SetAutoPan( false );
2207  m_controls->CaptureCursor( false );
2208  }
2209  }
2210  else if( polyGeomMgr.IsPolygonInProgress()
2211  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
2212  {
2213  polyGeomMgr.SetCursorPosition( cursorPos );
2214 
2215  if( polyGeomMgr.IsSelfIntersecting( true ) )
2216  {
2217  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
2218  status.Move( p );
2219  status.PopupFor( 1500 );
2220  }
2221  else
2222  {
2223  status.Hide();
2224  }
2225  }
2226  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
2227  {
2228  if( started )
2229  {
2230  frame()->OnEditItemRequest( zoneTool.GetZone() );
2231  zoneTool.OnGeometryChange( polyGeomMgr );
2232  frame()->SetMsgPanel( zoneTool.GetZone() );
2233  }
2234  else
2235  {
2236  evt->SetPassEvent();
2237  }
2238  }
2239  /*else if( evt->IsAction( &ACTIONS::updateUnits ) )
2240  {
2241  // If we ever have an assistant here that reports dimensions, we'll want to
2242  // update its units here....
2243  // zoneAsst.SetUnits( frame()->GetUserUnits() );
2244  // m_view->Update( &zoneAsst );
2245  evt->SetPassEvent();
2246  }*/
2247  else
2248  {
2249  evt->SetPassEvent();
2250  }
2251 
2252  } // end while
2253 
2255  m_controls->ForceCursorPosition( false );
2256  controls()->SetAutoPan( false );
2257  m_controls->CaptureCursor( false );
2258  return 0;
2259 }
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
void SetObjectVisible(GAL_LAYER_ID aLayer, bool aVisible=true)
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
Add a new zone with the same settings as an existing one.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
LEADER_MODE
The kind of the leader line.
ZONE * m_sourceZone
Zone leader mode.
Extension of STATUS_POPUP for displaying a single line text.
Definition: status_popup.h:79
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
PCB_LAYER_ID m_layer
The zone mode to operate in.
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:143
void PrimeTool(const VECTOR2D &aPosition)
"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in posi...
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
Parameters used to fully describe a zone creation process.
APPEARANCE_CONTROLS * GetAppearancePanel()
Control for copper zone opacity/visibility (color ignored)
Definition: layer_ids.h:227
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
KIGFX::VIEW * m_view
Definition: drawing_tool.h:264
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
RAII class that sets an value at construction and resets it to the original value at destruction.
const PCB_SELECTION & selection() const
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: zone.cpp:222
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
Generic, UI-independent tool event.
Definition: tool_event.h:152
#define _(s)
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:265
Unconstrained point-to-point.
bool Is45Limited() const
Should the tool use its 45° mode option?
bool m_isFootprintEditor
bool GetHV45() const
Definition: zone.h:802
ZONE_MODE
Definition: pcb_actions.h:33
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn 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:267
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE **aZone)
Draw a polygon, that is added as a zone or a keepout area.
static TOOL_ACTION drawRuleArea
Definition: pcb_actions.h:154
KIGFX::VIEW_CONTROLS * controls() const
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
An adjunct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from ...
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:163
void Activate()
Run the tool.
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
bool HasPosition() const
Definition: tool_event.h:240
bool m_keepout
< Should create a keepout zone?
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:263
ZONE_MODE m_mode
Zone settings source (for similar and cutout zones)
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405
static TOOL_ACTION closeOutline
Definition: pcb_actions.h:164

References _, TOOL_INTERACTIVE::Activate(), POLYGON_GEOM_MANAGER::AddPoint(), ARROW, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_ACTIONS::closeOutline, PCB_TOOL_BASE::controls(), POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), PCB_ACTIONS::deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawRuleArea, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), ZONE::GetHV45(), ZONE::GetLayer(), POLYGON_GEOM_MANAGER::GetLeaderMode(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSourceZoneForAction(), TOOL_BASE::getView(), ZONE_CREATE_HELPER::GetZone(), GRAPHIC_POLYGON, grid, TOOL_EVENT::HasPosition(), PCB_TOOL_BASE::Is45Limited(), TOOL_EVENT::IsAction(), KIGFX::VIEW::IsLayerVisible(), POLYGON_GEOM_MANAGER::IsPolygonInProgress(), POLYGON_GEOM_MANAGER::IsSelfIntersecting(), KEEPOUT, LAYER_ZONES, PCB_ACTIONS::layerChanged, m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_layer, TOOL_INTERACTIVE::m_menu, ZONE_CREATE_HELPER::PARAMS::m_mode, m_mode, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, TOOL_BASE::m_toolMgr, m_view, MD_SHIFT, POLYGON_GEOM_MANAGER::NewPointClosesOutline(), PCB_BASE_EDIT_FRAME::OnEditItemRequest(), ZONE_CREATE_HELPER::OnGeometryChange(), TOOL_EVENT::Parameter(), PENCIL, TOOLS_HOLDER::PopTool(), TOOL_EVENT::Position(), TOOL_MANAGER::PrimeTool(), PCB_ACTIONS::properties, TOOLS_HOLDER::PushTool(), EDA_DRAW_PANEL_GAL::Refresh(), POLYGON_GEOM_MANAGER::Reset(), PCB_TOOL_BASE::selection(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), POLYGON_GEOM_MANAGER::SetCursorPosition(), POLYGON_GEOM_MANAGER::SetFinished(), APPEARANCE_CONTROLS::SetLayerVisible(), POLYGON_GEOM_MANAGER::SetLeaderMode(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_BASE_EDIT_FRAME::SetObjectVisible(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), SIMILAR, TOOL_INTERACTIVE::Wait(), and ZONE.

Referenced by setTransitions().

◆ footprint()

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 160 of file pcb_tool_base.h.

161  {
162  return getEditFrame<PCB_BASE_EDIT_FRAME>();
163  }

Referenced by PCB_POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_CONTROL::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), ROUTER_TOOL::DpDimensionsDialog(), EDIT_TOOL::DragArcTrack(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawVia(), DrawZone(), PAD_TOOL::EditPad(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::HighlightItem(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), BOARD_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_TOOL::Init(), SCRIPTING_TOOL::Init(), PCB_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), InteractivePlaceWithPreview(), PCB_TOOL_BASE::Is45Limited(), PCB_PICKER_TOOL::Main(), PCB_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MoveExact(), PCB_POINT_EDITOR::OnSelectionChange(), PCB_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), GROUP_TOOL::PickNewMember(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), BOARD_EDITOR_CONTROL::PlaceTarget(), PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), PAD_TOOL::recombinePad(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), SCRIPTING_TOOL::reloadPlugins(), EDIT_TOOL::Remove(), PCB_POINT_EDITOR::removeCorner(), PCB_SELECTION_TOOL::RequestSelection(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), PCB_POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), PCB_CONTROL::unfilledZoneCheck(), ROUTER_TOOL::updateMessagePanel(), EDIT_TOOL::updateModificationPoint(), BOARD_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ GetDrawingMode()

DRAWING_TOOL::MODE DRAWING_TOOL::GetDrawingMode ( ) const

Return the current drawing mode of the DRAWING_TOOL or #MODE::NONE if not currently in any drawing mode.

Definition at line 245 of file drawing_tool.cpp.

246 {
247  return m_mode;
248 }

References m_mode.

Referenced by BOARD_EDITOR_CONTROL::Init().

◆ getEditFrame()

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

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

Definition at line 184 of file tool_base.h.

185  {
186 #if !defined( QA_TEST ) // Dynamic casts give the linker a seizure in the test framework
187  wxASSERT( dynamic_cast<T*>( getToolHolderInt() ) );
188 #endif
189  return static_cast<T*>( getToolHolderInt() );
190  }
TOOLS_HOLDER * getToolHolderInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getToolHolderInt().

Referenced by ZONE_CREATE_HELPER::createNewZone().

◆ GetId()

TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Return the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 120 of file tool_base.h.

121  {
122  return m_toolId;
123  }
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209

References TOOL_BASE::m_toolId.

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

◆ GetManager()

TOOL_MANAGER* TOOL_BASE::GetManager ( ) const
inlineinherited

Return the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER or NULL if there is no associated tool manager.

Definition at line 143 of file tool_base.h.

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

References TOOL_BASE::m_toolMgr.

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

◆ getModel()

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

Return the model object if it matches the requested type.

Store the type of the tool.

Definition at line 196 of file tool_base.h.

References TOOL_BASE::getModelInt().

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

◆ GetName()

const std::string& TOOL_BASE::GetName ( void  ) const
inlineinherited

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

134  {
135  return m_toolName;
136  }
std::string m_toolName
Definition: tool_base.h:213

References TOOL_BASE::m_toolName.

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

◆ getSegmentWidth()

int DRAWING_TOOL::getSegmentWidth ( PCB_LAYER_ID  aLayer) const
private

Definition at line 2671 of file drawing_tool.cpp.

2672 {
2673  assert( m_board );
2674  return m_board->GetDesignSettings().GetLineThickness( aLayer );
2675 }
BOARD * m_board
Definition: drawing_tool.h:266
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.

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

Referenced by drawArc(), and drawSegment().

◆ getSourceZoneForAction()

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

Draw 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 oneGet 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 1974 of file drawing_tool.cpp.

1975 {
1976  bool clearSelection = false;
1977  *aZone = nullptr;
1978 
1979  // not an action that needs a source zone
1980  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1981  return true;
1982 
1984  const PCB_SELECTION& selection = selTool->GetSelection();
1985 
1986  if( selection.Empty() )
1987  {
1988  clearSelection = true;
1990  }
1991 
1992  // we want a single zone
1993  if( selection.Size() == 1 )
1994  *aZone = dyn_cast<ZONE*>( selection[0] );
1995 
1996  // expected a zone, but didn't get one
1997  if( !*aZone )
1998  {
1999  if( clearSelection )
2001 
2002  return false;
2003  }
2004 
2005  return true;
2006 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
const PCB_SELECTION & selection() const
Add a new zone/keepout with fresh settings.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
The selection tool: currently supports:
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:56

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

Referenced by DrawZone().

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Return the type of the tool.

Returns
The type of the tool.

Definition at line 108 of file tool_base.h.

109  {
110  return m_type;
111  }
TOOL_TYPE m_type
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:206

References TOOL_BASE::m_type.

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

◆ getView()

KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Returns the instance of #VIEW object used in the application.

It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 36 of file tool_base.cpp.

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

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

Referenced by EE_POINT_EDITOR::addCornerCondition(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), COMMON_TOOLS::CenterContents(), SCH_EDIT_TOOL::ChangeTextType(), EE_INSPECTION_TOOL::CheckSymbol(), GERBVIEW_CONTROL::ClearAllLayers(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::CollectHits(), SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint(), COMMON_TOOLS::CursorControl(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), PCB_SELECTION_TOOL::doSelectionMenu(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), EDIT_TOOL::DragArcTrack(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), PL_DRAWING_TOOLS::DrawShape(), DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), PCB_CONTROL::GridResetOrigin(), PCB_CONTROL::GridSetOrigin(), ROUTER_TOOL::handleCommonEvents(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), PCB_SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), BOARD_INSPECTION_TOOL::highlightNet(), PCB_SELECTION_TOOL::hitTestDistance(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), PL_EDIT_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), ROUTER_TOOL::performRouting(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PL_DRAWING_TOOLS::PlaceItem(), BOARD_EDITOR_CONTROL::PlaceTarget(), ROUTER_TOOL::prepareInteractive(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), BOARD_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), Reset(), EE_SELECTION_TOOL::Reset(), PCB_SELECTION_TOOL::Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::SelectAll(), EE_SELECTION_TOOL::SelectAll(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), SCH_DRAWING_TOOLS::TwoClickPlace(), PL_SELECTION_TOOL::unhighlight(), EE_SELECTION_TOOL::unhighlight(), PCB_SELECTION_TOOL::unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PL_POINT_EDITOR::updateItem(), PCB_POINT_EDITOR::updateItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), PCB_SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCB_VIEWER_TOOLS::view(), PCB_TOOL_BASE::view(), PCB_SELECTION_TOOL::zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and PCB_SELECTION_TOOL::~PCB_SELECTION_TOOL().

◆ getViewControls()

KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited

Return the instance of VIEW_CONTROLS object used in the application.

It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.).

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

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

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

Referenced by EE_POINT_EDITOR::addCorner(), PCB_POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDITOR_CONTROL::AssignNetclass(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), EDIT_TOOL::copyToClipboard(), SCH_DRAWING_TOOLS::createSheetPin(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), EDIT_TOOL::DragArcTrack(), DrawCircle(), DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DrawRectangle(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels(), BOARD_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), PCB_POINT_EDITOR::Reset(), Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), PCB_SELECTION_TOOL::selectCursor(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PCB_PICKER_TOOL::setControls(), PICKER_TOOL::setControls(), PL_POINT_EDITOR::setEditedPoint(), EE_POINT_EDITOR::setEditedPoint(), PCB_POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateItem(), PL_EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

◆ Go()

template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited

Define which state (aStateFunc) to go when a certain event arrives (aConditions).

No conditions means any event.

Definition at line 147 of file tool_interactive.h.

149 {
150  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
151 
152  goInternal( sptr, aConditions );
153 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by AUTOPLACE_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), BOARD_REANNOTATE_TOOL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), PCB_PICKER_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), SYMBOL_EDITOR_PIN_TOOL::setTransitions(), SYMBOL_EDITOR_MOVE_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), ROUTER_TOOL::setTransitions(), SCRIPTING_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), COMMON_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PAD_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), SCH_EDIT_TOOL::setTransitions(), FOOTPRINT_EDITOR_CONTROL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), DRC_TOOL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), PCB_CONTROL::setTransitions(), CVPCB_CONTROL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), PICKER_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), PCB_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ Init()

bool DRAWING_TOOL::Init ( )
overridevirtual

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

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

Reimplemented from PCB_TOOL_BASE.

Definition at line 176 of file drawing_tool.cpp.

177 {
178  auto activeToolFunctor = [this]( const SELECTION& aSel )
179  {
180  return m_mode != MODE::NONE;
181  };
182 
183  // some interactive drawing tools can undo the last point
184  auto canUndoPoint = [this]( const SELECTION& aSel )
185  {
186  return ( m_mode == MODE::ARC
187  || m_mode == MODE::ZONE
188  || m_mode == MODE::KEEPOUT
190  };
191 
192  // functor for tools that can automatically close the outline
193  auto canCloseOutline = [this]( const SELECTION& aSel )
194  {
195  return ( m_mode == MODE::ZONE