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
 
virtual 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
 
void updateStatusBar () 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:72
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 159 of file drawing_tool.cpp.

159  :
160  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
161  m_view( nullptr ),
162  m_controls( nullptr ),
163  m_board( nullptr ),
164  m_frame( nullptr ),
165  m_mode( MODE::NONE ),
166  m_inDrawingTool( false ),
167  m_lineWidth( 1 )
168 {
169 }
BOARD * m_board
Definition: drawing_tool.h:268
bool m_inDrawingTool
Definition: drawing_tool.h:271
KIGFX::VIEW * m_view
Definition: drawing_tool.h:266
unsigned int m_lineWidth
Definition: drawing_tool.h:273
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:267
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
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 172 of file drawing_tool.cpp.

173 {
174 }

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(), ROUTER_TOOL::InlineDrag(), 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 712 of file drawing_tool.cpp.

713 {
714  const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() };
715 
716  aDim->SetEnd( wxPoint( VECTOR2I( aDim->GetStart() ) + GetVectorSnapped45( lineVector ) ) );
717  aDim->Update();
718 }
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:622
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::properties ) )
228  {
229  frame()->OnEditItemRequest( newItem.get() );
230 
231  // Notify other tools of the changes
233  }
234  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
235  {
236  preview.Clear();
237  newItem.release();
238 
239  makeNewItem( (wxPoint) cursorPos );
240  aPlacer->SnapItem( newItem.get() );
241  view()->Update( &preview );
242  }
243  else
244  {
245  evt->SetPassEvent();
246  }
247  }
248  else if( newItem && evt->IsMotion() )
249  {
250  // track the cursor
251  newItem->SetPosition( (wxPoint) cursorPos );
252  aPlacer->SnapItem( newItem.get() );
253 
254  // Show a preview of the item
255  view()->Update( &preview );
256  }
257  else
258  {
259  evt->SetPassEvent();
260  }
261  }
262 
263  view()->Remove( &preview );
265  controls()->SetAutoPan( false );
266  controls()->CaptureCursor( false );
267 }
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
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:299
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:205
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:1299
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 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_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 424 of file drawing_tool.cpp.

425 {
427  return 0;
428 
429  if( m_inDrawingTool )
430  return 0;
431 
433 
434  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
435  PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
436  BOARD_COMMIT commit( m_frame );
437  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
438  bool immediateMode = aEvent.HasPosition();
439 
440  arc->SetShape( SHAPE_T::ARC );
441  arc->SetFlags( IS_NEW );
442 
443  std::string tool = aEvent.GetCommandStr().get();
444  m_frame->PushTool( tool );
445  Activate();
446 
447  while( drawArc( tool, &arc, immediateMode ) )
448  {
449  if( arc )
450  {
451  if( m_isFootprintEditor )
452  static_cast<FP_SHAPE*>( arc )->SetLocalCoord();
453 
454  commit.Add( arc );
455  commit.Push( _( "Draw an arc" ) );
456 
458  }
459 
460  arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
461  arc->SetShape( SHAPE_T::ARC );
462  arc->SetFlags( IS_NEW );
463  immediateMode = false;
464  }
465 
466  return 0;
467 }
#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:271
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:269
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:100
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 1758 of file drawing_tool.cpp.

1759 {
1760  PCB_SHAPE*& graphic = *aGraphic;
1761 
1762  wxCHECK( graphic, 0 );
1763 
1764  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1765 
1766  m_lineWidth = getSegmentWidth( drawingLayer );
1767 
1768  // Arc geometric construction manager
1770 
1771  // Arc drawing assistant overlay
1772  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1773 
1774  // Add a VIEW_GROUP that serves as a preview for the new item
1775  PCB_SELECTION preview;
1776  m_view->Add( &preview );
1777  m_view->Add( &arcAsst );
1779 
1780  auto setCursor =
1781  [&]()
1782  {
1784  };
1785 
1786  auto cleanup =
1787  [&] ()
1788  {
1789  preview.Clear();
1790  delete *aGraphic;
1791  *aGraphic = nullptr;
1792  };
1793 
1794  m_controls->ShowCursor( true );
1795  // Set initial cursor
1796  setCursor();
1797 
1798  bool firstPoint = false;
1799  bool cancelled = false;
1800 
1801  // Prime the pump
1803 
1804  if( aImmediateMode )
1806 
1807  // Main loop: keep receiving events
1808  while( TOOL_EVENT* evt = Wait() )
1809  {
1810  if( firstPoint )
1811  m_frame->SetMsgPanel( graphic );
1812 
1813  setCursor();
1814 
1815  graphic->SetLayer( drawingLayer );
1816 
1817  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1818  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1819  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
1820  m_controls->ForceCursorPosition( true, cursorPos );
1821 
1822  if( evt->IsCancelInteractive() )
1823  {
1824  cleanup();
1825 
1826  if( !firstPoint )
1827  {
1828  // We've handled the cancel event. Don't cancel other tools
1829  evt->SetPassEvent( false );
1830  m_frame->PopTool( aTool );
1831  cancelled = true;
1832  }
1833 
1834  break;
1835  }
1836  else if( evt->IsActivate() )
1837  {
1838  if( evt->IsPointEditor() )
1839  {
1840  // don't exit (the point editor runs in the background)
1841  }
1842  else if( evt->IsMoveTool() )
1843  {
1844  cleanup();
1845  // leave ourselves on the stack so we come back after the move
1846  cancelled = true;
1847  break;
1848  }
1849  else
1850  {
1851  cleanup();
1852  m_frame->PopTool( aTool );
1853  cancelled = true;
1854  break;
1855  }
1856  }
1857  else if( evt->IsClick( BUT_LEFT ) )
1858  {
1859  if( !firstPoint )
1860  {
1862 
1863  m_controls->SetAutoPan( true );
1864  m_controls->CaptureCursor( true );
1865 
1866  drawingLayer = m_frame->GetActiveLayer();
1867  m_lineWidth = getSegmentWidth( drawingLayer );
1868 
1869  // Init the new item attributes
1870  // (non-geometric, those are handled by the manager)
1871  graphic->SetShape( SHAPE_T::ARC );
1872  graphic->SetWidth( m_lineWidth );
1873 
1874  if( !m_view->IsLayerVisible( drawingLayer ) )
1875  {
1876  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1877  m_frame->GetCanvas()->Refresh();
1878  }
1879 
1880  preview.Add( graphic );
1881  frame()->SetMsgPanel( graphic );
1882  firstPoint = true;
1883  }
1884 
1885  arcManager.AddPoint( cursorPos, true );
1886  }
1887  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1888  {
1889  arcManager.RemoveLastPoint();
1890  }
1891  else if( evt->IsMotion() )
1892  {
1893  // set angle snap
1894  arcManager.SetAngleSnap( Is45Limited() );
1895 
1896  // update, but don't step the manager state
1897  arcManager.AddPoint( cursorPos, false );
1898  }
1899  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1900  {
1901  drawingLayer = m_frame->GetActiveLayer();
1902  m_lineWidth = getSegmentWidth( drawingLayer );
1903 
1904  if( graphic )
1905  {
1906  if( !m_view->IsLayerVisible( drawingLayer ) )
1907  {
1908  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1909  m_frame->GetCanvas()->Refresh();
1910  }
1911 
1912  graphic->SetLayer( drawingLayer );
1913  graphic->SetWidth( m_lineWidth );
1914  m_view->Update( &preview );
1915  frame()->SetMsgPanel( graphic );
1916  }
1917  else
1918  {
1919  evt->SetPassEvent();
1920  }
1921  }
1922  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1923  {
1925  {
1926  graphic->SetArcAngleAndEnd( 900 );
1927  frame()->OnEditItemRequest( graphic );
1928  m_view->Update( &preview );
1929  frame()->SetMsgPanel( graphic );
1930  break;
1931  }
1932  // Don't show the edit panel if we can't represent the arc with it
1933  else if( ( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
1934  && ( arcManager.GetStartRadiusEnd() != arcManager.GetEndRadiusEnd() ) )
1935  {
1936  frame()->OnEditItemRequest( graphic );
1937  m_view->Update( &preview );
1938  frame()->SetMsgPanel( graphic );
1939  break;
1940  }
1941  else
1942  {
1943  evt->SetPassEvent();
1944  }
1945  }
1946  else if( evt->IsClick( BUT_RIGHT ) )
1947  {
1949  }
1950  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1951  {
1953  graphic->SetWidth( m_lineWidth );
1954  m_view->Update( &preview );
1955  frame()->SetMsgPanel( graphic );
1956  }
1957  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1958  {
1960  graphic->SetWidth( m_lineWidth );
1961  m_view->Update( &preview );
1962  frame()->SetMsgPanel( graphic );
1963  }
1964  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1965  {
1966  arcManager.ToggleClockwise();
1967  }
1968  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1969  {
1970  arcAsst.SetUnits( frame()->GetUserUnits() );
1971  m_view->Update( &arcAsst );
1972  evt->SetPassEvent();
1973  }
1974  else
1975  {
1976  evt->SetPassEvent();
1977  }
1978 
1979  if( arcManager.IsComplete() )
1980  {
1981  break;
1982  }
1983  else if( arcManager.HasGeometryChanged() )
1984  {
1985  updateArcFromConstructionMgr( arcManager, *graphic );
1986  m_view->Update( &preview );
1987  m_view->Update( &arcAsst );
1988 
1989  if( firstPoint )
1990  frame()->SetMsgPanel( graphic );
1991  else
1992  frame()->SetMsgPanel( board() );
1993  }
1994  }
1995 
1996  preview.Remove( graphic );
1997  m_view->Remove( &arcAsst );
1998  m_view->Remove( &preview );
1999  m_frame->SetMsgPanel( board() );
2000 
2002  m_controls->SetAutoPan( false );
2003  m_controls->CaptureCursor( false );
2004  m_controls->ForceCursorPosition( false );
2005 
2006  return !cancelled;
2007 }
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.
VECTOR2I GetEndRadiusEnd() const
Get the radius of the arc (valid if step >= SET_START)
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:164
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:164
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:274
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:350
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
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc end point.
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:547
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:167
KIGFX::VIEW * m_view
Definition: drawing_tool.h:266
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:273
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:97
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:267
virtual 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:269
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:170
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
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:100
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:160
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:320
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:1570
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(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetEndRadiusEnd(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSegmentWidth(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetStartRadiusEnd(), 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 374 of file drawing_stackup_table_tool.cpp.

378 {
379  BOARD_COMMIT commit( m_frame );
380  std::vector<BOARD_ITEM*> objects;
382  BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
383 
384  wxPoint cursorPos = aOrigin;
385 
386  // Style : Section header
387  std::unique_ptr<PCB_TEXT> headStyle =
388  std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
389  headStyle->SetLayer( Eco1_User );
390  headStyle->SetTextSize( wxSize( Millimeter2iu( 2.0 ), Millimeter2iu( 2.0 ) ) );
391  headStyle->SetTextThickness( Millimeter2iu( 0.4 ) );
392  headStyle->SetItalic( false );
393  headStyle->SetTextPos( wxPoint( 0, 0 ) );
394  headStyle->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
395  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
396 
397  // Style : Data
398  std::unique_ptr<PCB_TEXT> dataStyle =
399  std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
400  dataStyle->SetLayer( Eco1_User );
401  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
402  dataStyle->SetTextThickness( Millimeter2iu( 0.2 ) );
403  dataStyle->SetItalic( false );
404  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
405  dataStyle->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
406  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
407 
408  PCB_TEXT* t;
409 
410  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
411  t->SetText( _( "BOARD CHARACTERISTICS" ) );
412  t->SetPosition( cursorPos );
413  objects.push_back( t );
414 
415  cursorPos.y = cursorPos.y + t->GetBoundingBox().GetHeight()
417 
418  std::vector<std::vector<PCB_TEXT*>> texts;
419  std::vector<PCB_TEXT*> colLabel1;
420  std::vector<PCB_TEXT*> colData1;
421  std::vector<PCB_TEXT*> colbreak;
422  std::vector<PCB_TEXT*> colLabel2;
423  std::vector<PCB_TEXT*> colData2;
424  wxString text;
425 
426  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
427  t->SetText( _( "Copper Layer Count: " ) );
428  colLabel1.push_back( t );
429 
430  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
432  colData1.push_back( t );
433 
434  SHAPE_POLY_SET outline;
436  BOX2I size = outline.BBox();
437  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
438  t->SetText( _( "Board overall dimensions: " ) );
439  colLabel1.push_back( t );
440 
441  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
442  t->SetText( wxString::Format( wxT( "%s x %s" ),
444  MessageTextFromValue( m_frame->GetUserUnits(), size.GetHeight(), true ) ) );
445  colData1.push_back( t );
446 
447  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
448  t->SetText( _( "Min track/spacing: " ) );
449  colLabel1.push_back( t );
450 
451  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
452  t->SetText( wxString::Format( wxT( "%s / %s" ),
454  MessageTextFromValue( m_frame->GetUserUnits(), settings.m_MinClearance, true ) ) );
455  colData1.push_back( t );
456 
457  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
458  t->SetText( _( "Copper Finish: " ) );
459  colLabel1.push_back( t );
460 
461  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
462  t->SetText( stackup.m_FinishType );
463  colData1.push_back( t );
464 
465  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
466  t->SetText( _( "Castellated pads: " ) );
467  colLabel1.push_back( t );
468 
469  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
470  t->SetText( stackup.m_CastellatedPads ? _( "Yes" ) : _( "No" ) );
471  colData1.push_back( t );
472 
473  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
474  t->SetText( _( "Board Thickness: " ) );
475  colLabel2.push_back( t );
476 
477  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
479 
480  t->SetText( text );
481  colData2.push_back( t );
482 
483  // some empty cells
484  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
485  colLabel2.push_back( t );
486  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
487  colData2.push_back( t );
488 
489  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
490  t->SetText( _( "Min hole diameter: " ) );
491  colLabel2.push_back( t );
492  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
493 
494  double holeSize = std::min( settings.m_MinThroughDrill, settings.m_ViasMinSize );
495  text = MessageTextFromValue( m_frame->GetUserUnits(), holeSize, true );
496  t->SetText( text );
497  colData2.push_back( t );
498 
499  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
500  t->SetText( _( "Impedance Control: " ) );
501  colLabel2.push_back( t );
502 
503  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
504  t->SetText( stackup.m_HasDielectricConstrains ? _( "Yes" ) : _( "No" ) );
505  colData2.push_back( t );
506 
507  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
508  t->SetText( _( "Plated Board Edge: " ) );
509  colLabel2.push_back( t );
510 
511  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
512  t->SetText( stackup.m_EdgePlating ? _( "Yes" ) : _( "No" ) );
513  colData2.push_back( t );
514 
515  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
516  t->SetText( _( "Edge card connectors: " ) );
517  colLabel1.push_back( t );
518 
519  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
520  switch( stackup.m_EdgeConnectorConstraints )
521  {
522  case BS_EDGE_CONNECTOR_NONE: t->SetText( _( "No" ) ); break;
523  case BS_EDGE_CONNECTOR_IN_USE: t->SetText( _( "Yes" ) ); break;
524  case BS_EDGE_CONNECTOR_BEVELLED: t->SetText( _( "Yes, Bevelled" ) ); break;
525  }
526  colData1.push_back( t );
527 
528  texts.push_back( colLabel1 );
529  texts.push_back( colData1 );
530  texts.push_back( colbreak );
531  texts.push_back( colLabel2 );
532  texts.push_back( colData2 );
533  wxPoint tableSize2 = wxPoint();
534 
535  std::vector<BOARD_ITEM*> table = initTextTable( texts, cursorPos, Eco1_User, &tableSize2,
536  false );
537 
538  for( BOARD_ITEM* item : table )
539  objects.push_back( item );
540 
541  if( aDrawNow )
542  {
543  for( auto item : objects )
544  commit.Add( item );
545 
546  commit.Push( wxT( "Board Characteristics" ) );
547  }
548 
549  tableSize->x = tableSize2.x;
550  tableSize->y = cursorPos.y + tableSize2.y + From_User_Unit( EDA_UNITS::MILLIMETRES, 2.0 );
551 
552  return objects;
553 }
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
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:1835
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:81
Manage layers needed to make a physical board.
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.
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specified in job file: BS_EDGE_CONNECTO...
bool m_CastellatedPads
True if castellated pads exist.
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:124
Represent a set of closed polygons.
coord_type GetWidth() const
Definition: box2.h:180
#define _(s)
int GetHeight() const
Definition: eda_rect.h:119
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
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
coord_type GetHeight() const
Definition: box2.h:181
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
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)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
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:277
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Container for design settings for a BOARD object.

References _, COMMIT::Add(), SHAPE_POLY_SET::BBox(), BS_EDGE_CONNECTOR_BEVELLED, BS_EDGE_CONNECTOR_IN_USE, BS_EDGE_CONNECTOR_NONE, Eco1_User, Format(), From_User_Unit(), PCB_BASE_FRAME::GetBoard(), BOARD::GetBoardPolygonOutlines(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), PCB_TEXT::GetBoundingBox(), BOARD_DESIGN_SETTINGS::GetCopperLayerCount(), BOARD::GetDesignSettings(), EDA_RECT::GetHeight(), BOX2< Vec >::GetHeight(), PCB_BASE_FRAME::GetModel(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), EDA_BASE_FRAME::GetUserUnits(), BOX2< Vec >::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(), PCB_TEXT::SetPosition(), EDA_TEXT::SetText(), 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 373 of file drawing_tool.cpp.

374 {
376  return 0;
377 
378  if( m_inDrawingTool )
379  return 0;
380 
382 
383  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
384  PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
385  BOARD_COMMIT commit( m_frame );
386  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
387  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
388 
389  circle->SetShape( SHAPE_T::CIRCLE );
390  circle->SetFilled( false );
391  circle->SetFlags( IS_NEW );
392 
393  if( aEvent.HasPosition() )
394  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
395 
396  std::string tool = aEvent.GetCommandStr().get();
397  m_frame->PushTool( tool );
398  Activate();
399 
400  while( drawSegment( tool, &circle, startingPoint ) )
401  {
402  if( circle )
403  {
404  if( m_isFootprintEditor )
405  static_cast<FP_SHAPE*>( circle )->SetLocalCoord();
406 
407  commit.Add( circle );
408  commit.Push( _( "Draw a circle" ) );
409 
410  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
411  }
412 
413  circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
414  circle->SetShape( SHAPE_T::CIRCLE );
415  circle->SetFilled( false );
416  circle->SetFlags( IS_NEW );
417  startingPoint = NULLOPT;
418  }
419 
420  return 0;
421 }
#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:271
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:621
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
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:100
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 721 of file drawing_tool.cpp.

722 {
724  return 0;
725 
726  if( m_inDrawingTool )
727  return 0;
728 
730 
731  enum DIMENSION_STEPS
732  {
733  SET_ORIGIN = 0,
734  SET_END,
735  SET_HEIGHT,
736  FINISHED
737  };
738 
739  TOOL_EVENT originalEvent = aEvent;
740  PCB_DIMENSION_BASE* dimension = nullptr;
741  BOARD_COMMIT commit( m_frame );
743  BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
744  PCB_SELECTION preview; // A VIEW_GROUP that serves as a preview for the new item(s)
745  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
746  int step = SET_ORIGIN;
747 
748  m_view->Add( &preview );
749 
750  auto cleanup =
751  [&]()
752  {
753  m_controls->SetAutoPan( false );
754  m_controls->CaptureCursor( false );
755 
756  preview.Clear();
757  m_view->Update( &preview );
758 
759  delete dimension;
760  dimension = nullptr;
761  step = SET_ORIGIN;
762  };
763 
764  auto setCursor =
765  [&]()
766  {
768  };
769 
771 
772  std::string tool = aEvent.GetCommandStr().get();
773  m_frame->PushTool( tool );
774 
775  Activate();
776  // Must be done after Activate() so that it gets set into the correct context
777  m_controls->ShowCursor( true );
778  // Set initial cursor
779  setCursor();
780 
781  // Prime the pump
783 
784  if( aEvent.HasPosition() )
785  m_toolMgr->PrimeTool( aEvent.Position() );
786 
787  // Main loop: keep receiving events
788  while( TOOL_EVENT* evt = Wait() )
789  {
790  if( step > SET_ORIGIN )
791  frame()->SetMsgPanel( dimension );
792 
793  setCursor();
794 
795  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
796  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
797 
798  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
799 
800  cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
801  m_controls->ForceCursorPosition( true, cursorPos );
802 
803  if( evt->IsCancelInteractive() )
804  {
805  m_controls->SetAutoPan( false );
806 
807  if( step != SET_ORIGIN ) // start from the beginning
808  {
809  cleanup();
810  }
811  else
812  {
813  m_frame->PopTool( tool );
814  break;
815  }
816  }
817  else if( evt->IsActivate() )
818  {
819  if( step != SET_ORIGIN )
820  cleanup();
821 
822  if( evt->IsPointEditor() )
823  {
824  // don't exit (the point editor runs in the background)
825  }
826  else if( evt->IsMoveTool() )
827  {
828  // leave ourselves on the stack so we come back after the move
829  break;
830  }
831  else
832  {
833  m_frame->PopTool( tool );
834  break;
835  }
836  }
837  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
838  {
840  dimension->SetLineThickness( m_lineWidth );
841  m_view->Update( &preview );
842  frame()->SetMsgPanel( dimension );
843  }
844  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
845  {
846  if( m_lineWidth > WIDTH_STEP )
847  {
849  dimension->SetLineThickness( m_lineWidth );
850  m_view->Update( &preview );
851  frame()->SetMsgPanel( dimension );
852  }
853  }
854  else if( evt->IsClick( BUT_RIGHT ) )
855  {
857  }
858  else if( evt->IsClick( BUT_LEFT ) )
859  {
860  switch( step )
861  {
862  case SET_ORIGIN:
863  {
865 
867 
868  // Init the new item attributes
869  auto setMeasurementAttributes =
870  [&]( PCB_DIMENSION_BASE* aDim )
871  {
872  aDim->SetUnitsMode( boardSettings.m_DimensionUnitsMode );
873  aDim->SetUnitsFormat( boardSettings.m_DimensionUnitsFormat );
874  aDim->SetPrecision( boardSettings.m_DimensionPrecision );
875  aDim->SetSuppressZeroes( boardSettings.m_DimensionSuppressZeroes );
876  aDim->SetTextPositionMode( boardSettings.m_DimensionTextPosition );
877  aDim->SetKeepTextAligned( boardSettings.m_DimensionKeepTextAligned );
878 
879  if( boardSettings.m_DimensionUnitsMode == DIM_UNITS_MODE::AUTOMATIC )
880  aDim->SetUnits( m_frame->GetUserUnits() );
881  };
882 
883  if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) )
884  {
885  dimension = new PCB_DIM_ALIGNED( m_board );
886  setMeasurementAttributes( dimension );
887  }
888  else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) )
889  {
890  dimension = new PCB_DIM_ORTHOGONAL( m_board );
891  setMeasurementAttributes( dimension );
892  }
893  else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) )
894  {
895  dimension = new PCB_DIM_CENTER( m_board );
896  }
897  else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) )
898  {
899  dimension = new PCB_DIM_LEADER( m_board );
900  dimension->Text().SetPosition( wxPoint( cursorPos ) );
901  }
902  else
903  {
904  wxFAIL_MSG( wxT( "Unhandled action in DRAWING_TOOL::DrawDimension" ) );
905  }
906 
907  dimension->SetLayer( layer );
908  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
909  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
910  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
911  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
912  dimension->SetArrowLength( boardSettings.m_DimensionArrowLength );
913  dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset );
914  dimension->SetStart( (wxPoint) cursorPos );
915  dimension->SetEnd( (wxPoint) cursorPos );
916  dimension->Update();
917 
918  if( !m_view->IsLayerVisible( layer ) )
919  {
920  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
921  m_frame->GetCanvas()->Refresh();
922  }
923 
924  preview.Add( dimension );
925  frame()->SetMsgPanel( dimension );
926 
927  m_controls->SetAutoPan( true );
928  m_controls->CaptureCursor( true );
929  break;
930  }
931 
932  case SET_END:
933  {
934  dimension->SetEnd( (wxPoint) cursorPos );
935  dimension->Update();
936 
937  if( Is45Limited() || dimension->Type() == PCB_DIM_CENTER_T )
938  constrainDimension( dimension );
939 
940  // Dimensions that have origin and end in the same spot are not valid
941  if( dimension->GetStart() == dimension->GetEnd() )
942  --step;
943  else if( dimension->Type() == PCB_DIM_LEADER_T )
944  dimension->SetText( wxT( "?" ) );
945 
946  if( dimension->Type() == PCB_DIM_CENTER_T )
947  {
948  // No separate height/text step
949  ++step;
951  }
952  else
953  {
954  break;
955  }
956  }
957 
958  case SET_HEIGHT:
959  if( dimension->Type() == PCB_DIM_LEADER_T )
960  {
961  assert( dimension->GetStart() != dimension->GetEnd() );
962  assert( dimension->GetLineThickness() > 0 );
963 
964  preview.Remove( dimension );
965 
966  commit.Add( dimension );
967  commit.Push( _( "Draw a leader" ) );
968 
969  // Run the edit immediately to set the leader text
970  m_toolMgr->RunAction( PCB_ACTIONS::properties, true, dimension );
971  }
972  else if( (wxPoint) cursorPos != dimension->GetPosition() )
973  {
974  assert( dimension->GetStart() != dimension->GetEnd() );
975  assert( dimension->GetLineThickness() > 0 );
976 
977  preview.Remove( dimension );
978 
979  commit.Add( dimension );
980  commit.Push( _( "Draw a dimension" ) );
981 
982  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
983  }
984 
985  break;
986  }
987 
988  if( ++step == FINISHED )
989  {
990  step = SET_ORIGIN;
991  m_controls->SetAutoPan( false );
992  m_controls->CaptureCursor( false );
993  }
994  }
995  else if( evt->IsMotion() )
996  {
997  switch( step )
998  {
999  case SET_END:
1000  dimension->SetEnd( (wxPoint) cursorPos );
1001 
1002  if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
1003  {
1004  PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
1005 
1006  BOX2I bounds( dimension->GetStart(),
1007  dimension->GetEnd() - dimension->GetStart() );
1008 
1009  // Create a nice preview by measuring the longer dimension
1010  bool vert = bounds.GetWidth() < bounds.GetHeight();
1011 
1012  ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
1014  }
1015 
1016  dimension->Update();
1017 
1018  if( Is45Limited() || dimension->Type() == PCB_DIM_CENTER_T )
1019  constrainDimension( dimension );
1020 
1021  break;
1022 
1023  case SET_HEIGHT:
1024  {
1025  if( dimension->Type() == PCB_DIM_ALIGNED_T )
1026  {
1027  PCB_DIM_ALIGNED* aligned = static_cast<PCB_DIM_ALIGNED*>( dimension );
1028 
1029  // Calculating the direction of travel perpendicular to the selected axis
1030  double angle = aligned->GetAngle() + ( M_PI / 2 );
1031 
1032  wxPoint delta( (wxPoint) cursorPos - dimension->GetEnd() );
1033  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
1034  aligned->SetHeight( height );
1035  aligned->Update();
1036  }
1037  else if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
1038  {
1039  PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
1040 
1041  BOX2I bounds( dimension->GetStart(),
1042  dimension->GetEnd() - dimension->GetStart() );
1043  VECTOR2I direction( cursorPos - bounds.Centre() );
1044  bool vert;
1045 
1046  // Only change the orientation when we move outside the bounds
1047  if( !bounds.Contains( cursorPos ) )
1048  {
1049  // If the dimension is horizontal or vertical, set correct orientation
1050  // otherwise, test if we're left/right of the bounding box or above/below it
1051  if( bounds.GetWidth() == 0 )
1052  {
1053  vert = true;
1054  }
1055  else if( bounds.GetHeight() == 0 )
1056  {
1057  vert = false;
1058  }
1059  else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
1060  {
1061  vert = false;
1062  }
1063  else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
1064  {
1065  vert = true;
1066  }
1067  else
1068  {
1069  vert = std::abs( direction.y ) < std::abs( direction.x );
1070  }
1071  ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
1073  }
1074  else
1075  {
1076  vert = ortho->GetOrientation() == PCB_DIM_ORTHOGONAL::DIR::VERTICAL;
1077  }
1078 
1079  VECTOR2I heightVector( cursorPos - dimension->GetStart() );
1080  ortho->SetHeight( vert ? heightVector.x : heightVector.y );
1081  ortho->Update();
1082  }
1083  else if( dimension->Type() == PCB_DIM_LEADER_T )
1084  {
1085  // Leader: SET_HEIGHT actually sets the text position directly
1086  VECTOR2I lineVector( cursorPos - dimension->GetEnd() );
1087  dimension->Text().SetPosition( wxPoint( VECTOR2I( dimension->GetEnd() ) +
1088  GetVectorSnapped45( lineVector ) ) );
1089  dimension->Update();
1090  }
1091  }
1092  break;
1093  }
1094 
1095  // Show a preview of the item
1096  m_view->Update( &preview );
1097  }
1098  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1099  {
1100  if( dimension )
1101  {
1102  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1103 
1104  if( !m_view->IsLayerVisible( layer ) )
1105  {
1106  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
1107  m_frame->GetCanvas()->Refresh();
1108  }
1109 
1110  dimension->SetLayer( layer );
1111  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
1112  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
1113  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
1114  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
1115  dimension->Update();
1116 
1117  m_view->Update( &preview );
1118  frame()->SetMsgPanel( dimension );
1119  }
1120  else
1121  {
1122  evt->SetPassEvent();
1123  }
1124  }
1125  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1126  {
1127  if( step == SET_END || step == SET_HEIGHT )
1128  {
1129  frame()->OnEditItemRequest( dimension );
1130  dimension->Update();
1131  frame()->SetMsgPanel( dimension );
1132  break;
1133  }
1134  else
1135  {
1136  evt->SetPassEvent();
1137  }
1138  }
1139  else
1140  {
1141  evt->SetPassEvent();
1142  }
1143  }
1144 
1145  if( step != SET_ORIGIN )
1146  delete dimension;
1147 
1148  m_controls->SetAutoPan( false );
1149  m_controls->ForceCursorPosition( false );
1150  m_controls->CaptureCursor( false );
1152 
1153  m_view->Remove( &preview );
1154  m_frame->SetMsgPanel( board() );
1155 
1156  return 0;
1157 }
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:146
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:268
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:164
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:274
void SetItalic(bool isItalic)
Definition: eda_text.h:200
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:145
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:350
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
static TOOL_ACTION drawOrthogonalDimension
Definition: pcb_actions.h:147
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:258
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
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:167
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:271
void SetLineThickness(int aWidth)
KIGFX::VIEW * m_view
Definition: drawing_tool.h:266
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:273
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:267
virtual 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:269
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:289
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:148
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:180
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:320
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:1570
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
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 271 of file drawing_tool.cpp.

272 {
274  return 0;
275 
276  if( m_inDrawingTool )
277  return 0;
278 
280 
281  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
282  PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
283  BOARD_COMMIT commit( m_frame );
284  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
285  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
286 
287  line->SetShape( SHAPE_T::SEGMENT );
288  line->SetFlags( IS_NEW );
289 
290  if( aEvent.HasPosition() )
291  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
292 
293  std::string tool = aEvent.GetCommandStr().get();
294  m_frame->PushTool( tool );
295  Activate();
296 
297  while( drawSegment( tool, &line, startingPoint ) )
298  {
299  if( line )
300  {
301  if( m_isFootprintEditor )
302  static_cast<FP_SHAPE*>( line )->SetLocalCoord();
303 
304  commit.Add( line );
305  commit.Push( _( "Draw a line segment" ) );
306  startingPoint = VECTOR2D( line->GetEnd() );
307  }
308  else
309  {
310  startingPoint = NULLOPT;
311  }
312 
313  line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
314  line->SetShape( SHAPE_T::SEGMENT );
315  line->SetFlags( IS_NEW );
316  }
317 
318  return 0;
319 }
#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:271
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:621
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
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:100
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 322 of file drawing_tool.cpp.

323 {
325  return 0;
326 
327  if( m_inDrawingTool )
328  return 0;
329 
331 
332  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
333  PCB_SHAPE* rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
334  BOARD_COMMIT commit( m_frame );
335  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
336  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
337 
338  rect->SetShape( SHAPE_T::RECT );
339  rect->SetFilled( false );
340  rect->SetFlags(IS_NEW );
341 
342  if( aEvent.HasPosition() )
343  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
344 
345  std::string tool = aEvent.GetCommandStr().get();
346  m_frame->PushTool( tool );
347  Activate();
348 
349  while( drawSegment( tool, &rect, startingPoint ) )
350  {
351  if( rect )
352  {
353  if( m_isFootprintEditor )
354  static_cast<FP_SHAPE*>( rect )->SetLocalCoord();
355 
356  commit.Add( rect );
357  commit.Push( _( "Draw a rectangle" ) );
358 
360  }
361 
362  rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
363  rect->SetShape( SHAPE_T::RECT );
364  rect->SetFilled( false );
365  rect->SetFlags(IS_NEW );
366  startingPoint = NULLOPT;
367  }
368 
369  return 0;
370 }
#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:271
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:621
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:341
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
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:100
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 1433 of file drawing_tool.cpp.

1435 {
1436  SHAPE_T shape = ( *aGraphic )->GetShape();
1437 
1438  // Only three shapes are currently supported
1439  wxASSERT( shape == SHAPE_T::SEGMENT || shape == SHAPE_T::CIRCLE || shape == SHAPE_T::RECT );
1440 
1441  EDA_UNITS userUnits = m_frame->GetUserUnits();
1443  PCB_SHAPE*& graphic = *aGraphic;
1444  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1445 
1446  m_lineWidth = getSegmentWidth( drawingLayer );
1447 
1448  // geometric construction manager
1450 
1451  // drawing assistant overlay
1452  // TODO: workaround because EDA_SHAPE_TYPE_T is not visible from commons.
1453  KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
1454  KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, userUnits, geomShape );
1455 
1456  // Add a VIEW_GROUP that serves as a preview for the new item
1457  PCB_SELECTION preview;
1458  m_view->Add( &preview );
1459  m_view->Add( &twoPointAsst );
1460 
1461  bool started = false;
1462  bool cancelled = false;
1463  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
1464  VECTOR2I cursorPos = m_controls->GetMousePosition();
1465 
1466  auto setCursor =
1467  [&]()
1468  {
1470  };
1471 
1472  auto cleanup =
1473  [&]()
1474  {
1475  preview.Clear();
1476  m_view->Update( &preview );
1477  delete graphic;
1478  graphic = nullptr;
1479 
1480  if( !isLocalOriginSet )
1481  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1482  };
1483 
1484  m_controls->ShowCursor( true );
1485  // Set initial cursor
1486  setCursor();
1487 
1488  // Prime the pump
1490 
1491  if( aStartingPoint )
1493 
1494  // Main loop: keep receiving events
1495  while( TOOL_EVENT* evt = Wait() )
1496  {
1497  setCursor();
1498 
1499  if( started )
1500  m_frame->SetMsgPanel( graphic );
1501 
1502  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1503  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1504  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), drawingLayer );
1505  m_controls->ForceCursorPosition( true, cursorPos );
1506 
1507  if( evt->IsCancelInteractive() )
1508  {
1509  cleanup();
1510 
1511  if( !started )
1512  {
1513  // We've handled the cancel event. Don't cancel other tools
1514  evt->SetPassEvent( false );
1515  m_frame->PopTool( aTool );
1516  cancelled = true;
1517  }
1518 
1519  break;
1520  }
1521  else if( evt->IsActivate() )
1522  {
1523  if( evt->IsPointEditor() )
1524  {
1525  // don't exit (the point editor runs in the background)
1526  }
1527  else if( evt->IsMoveTool() )
1528  {
1529  cleanup();
1530  // leave ourselves on the stack so we come back after the move
1531  cancelled = true;
1532  break;
1533  }
1534  else
1535  {
1536  cleanup();
1537  m_frame->PopTool( aTool );
1538  cancelled = true;
1539  break;
1540  }
1541  }
1542  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1543  {
1544  drawingLayer = m_frame->GetActiveLayer();
1545  m_lineWidth = getSegmentWidth( drawingLayer );
1546 
1547  if( graphic )
1548  {
1549  if( !m_view->IsLayerVisible( drawingLayer ) )
1550  {
1551  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1552  m_frame->GetCanvas()->Refresh();
1553  }
1554 
1555  graphic->SetLayer( drawingLayer );
1556  graphic->SetWidth( m_lineWidth );
1557  m_view->Update( &preview );
1558  frame()->SetMsgPanel( graphic );
1559  }
1560  else
1561  {
1562  evt->SetPassEvent();
1563  }
1564  }
1565  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1566  {
1567  if( started )
1568  {
1569  frame()->OnEditItemRequest( graphic );
1570  m_view->Update( &preview );
1571  frame()->SetMsgPanel( graphic );
1572  break;
1573  }
1574  else
1575  {
1576  evt->SetPassEvent();
1577  }
1578  }
1579  else if( evt->IsClick( BUT_RIGHT ) )
1580  {
1582  }
1583  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1584  {
1585  if( !started )
1586  {
1588 
1589  if( aStartingPoint )
1590  {
1591  cursorPos = aStartingPoint.get();
1592  aStartingPoint = NULLOPT;
1593  }
1594 
1595  m_lineWidth = getSegmentWidth( drawingLayer );
1596 
1597  // Init the new item attributes
1598  graphic->SetShape( static_cast<SHAPE_T>( shape ) );
1599  graphic->SetFilled( false );
1600  graphic->SetWidth( m_lineWidth );
1601  graphic->SetLayer( drawingLayer );
1602  grid.SetSkipPoint( cursorPos );
1603 
1604  twoPointManager.SetOrigin( (wxPoint) cursorPos );
1605  twoPointManager.SetEnd( (wxPoint) cursorPos );
1606 
1607  if( !isLocalOriginSet )
1608  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1609 
1610  preview.Add( graphic );
1611  frame()->SetMsgPanel( graphic );
1612  m_controls->SetAutoPan( true );
1613  m_controls->CaptureCursor( true );
1614 
1615  if( !m_view->IsLayerVisible( drawingLayer ) )
1616  {
1617  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1618  m_frame->GetCanvas()->Refresh();
1619  }
1620 
1621  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1622 
1623  started = true;
1624  }
1625  else if( shape == SHAPE_T::CIRCLE )
1626  {
1627  // No clever logic if drawing a circle
1628  preview.Clear();
1629  twoPointManager.Reset();
1630  break;
1631  }
1632  else
1633  {
1634  PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
1635 
1636  if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
1637  || ( evt->IsDblClick( BUT_LEFT ) && shape == SHAPE_T::SEGMENT )
1638  || snapItem )
1639  // User has clicked twice in the same spot
1640  // or clicked on the end of an existing segment (closing a path)
1641  {
1642  BOARD_COMMIT commit( m_frame );
1643 
1644  // If the user clicks on an existing snap point from a drawsegment
1645  // we finish the segment as they are likely closing a path
1646  if( snapItem && ( shape == SHAPE_T::RECT || graphic->GetLength() > 0.0 ) )
1647  {
1648  commit.Add( graphic );
1649  commit.Push( _( "Draw a line segment" ) );
1650  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, graphic );
1651  }
1652  else
1653  {
1654  delete graphic;
1655  }
1656 
1657  graphic = nullptr;
1658  }
1659 
1660  preview.Clear();
1661  twoPointManager.Reset();
1662  break;
1663  }
1664 
1665  twoPointManager.SetEnd( cursorPos );
1666  }
1667  else if( evt->IsMotion() )
1668  {
1669  // 45 degree lines
1670  if( started && Is45Limited() )
1671  {
1672  const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
1673 
1674  // get a restricted 45/H/V line from the last fixed point to the cursor
1675  auto newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECT ) );
1676  m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
1677  twoPointManager.SetEnd( twoPointManager.GetOrigin() + (wxPoint) newEnd );
1678  twoPointManager.SetAngleSnap( true );
1679  }
1680  else
1681  {
1682  twoPointManager.SetEnd( (wxPoint) cursorPos );
1683  twoPointManager.SetAngleSnap( false );
1684  }
1685 
1686  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1687  m_view->Update( &preview );
1688  m_view->Update( &twoPointAsst );
1689  }
1690  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1691  {
1693  graphic->SetWidth( m_lineWidth );
1694  m_view->Update( &preview );
1695  frame()->SetMsgPanel( graphic );
1696  }
1697  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1698  {
1700  graphic->SetWidth( m_lineWidth );
1701  m_view->Update( &preview );
1702  frame()->SetMsgPanel( graphic );
1703  }
1704  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1705  {
1706  isLocalOriginSet = true;
1707  evt->SetPassEvent();
1708  }
1709  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1710  {
1711  if( frame()->GetUserUnits() != userUnits )
1712  {
1713  userUnits = frame()->GetUserUnits();
1714  twoPointAsst.SetUnits( userUnits );
1715  m_view->Update( &twoPointAsst );
1716  }
1717  evt->SetPassEvent();
1718  }
1719  else
1720  {
1721  evt->SetPassEvent();
1722  }
1723  }
1724 
1725  if( !isLocalOriginSet ) // reset the relative coordinate if it was not set before
1726  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1727 
1728  m_view->Remove( &twoPointAsst );
1729  m_view->Remove( &preview );
1730  m_frame->SetMsgPanel( board() );
1731 
1733  m_controls->SetAutoPan( false );
1734  m_controls->CaptureCursor( false );
1735  m_controls->ForceCursorPosition( false );
1736 
1737  return !cancelled;
1738 }
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:164
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:274
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:350
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:622
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:167
KIGFX::VIEW * m_view
Definition: drawing_tool.h:266
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:621
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:273
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:267
virtual 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:269
EDA_UNITS
Definition: eda_units.h:38
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
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:320
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:1570
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  std::unique_ptr<PCB_TEXT> headStyle =
221  std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
222  headStyle->SetLayer( Eco1_User );
223  headStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
224  headStyle->SetTextThickness( Millimeter2iu( 0.3 ) );
225  headStyle->SetItalic( false );
226  headStyle->SetTextPos( wxPoint( 0, 0 ) );
227  headStyle->SetText( _( "Layer" ) );
228  headStyle->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
229  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
230 
231  // Style : data
232  std::unique_ptr<PCB_TEXT> dataStyle =
233  std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
234  dataStyle->SetLayer( Eco1_User );
235  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
236  dataStyle->SetTextThickness( Millimeter2iu( 0.1 ) );
237  dataStyle->SetItalic( false );
238  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
239  dataStyle->SetText( _( "Layer" ) );
240  dataStyle->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
241  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
242 
243  //Get Layer names
245  BOARD_STACKUP& stackup = dsnSettings.GetStackupDescriptor();
246  stackup.SynchronizeWithBoard( &dsnSettings );
247 
248  std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
249 
250  std::vector<PCB_TEXT*> colLayer;
251  std::vector<PCB_TEXT*> colType;
252  std::vector<PCB_TEXT*> colMaterial;
253  std::vector<PCB_TEXT*> colThickness;
254  std::vector<PCB_TEXT*> colColor;
255  std::vector<PCB_TEXT*> colEpsilon;
256  std::vector<PCB_TEXT*> colTanD;
257  PCB_TEXT* t;
258 
259  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
260  t->SetText( _( "Layer Name" ) );
261  colLayer.push_back( t );
262 
263  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
264  t->SetText( _( "Type" ) );
265  colType.push_back( t );
266 
267  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
268  t->SetText( _( "Material" ) );
269  colMaterial.push_back( t );
270 
271  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
272 
273  switch( m_frame->GetUserUnits() )
274  {
275  case EDA_UNITS::MILLIMETRES: t->SetText( _( "Thickness (mm)" ) ); break;
276  case EDA_UNITS::INCHES: t->SetText( _( "Thickness (inches)" ) ); break;
277  case EDA_UNITS::MILS: t->SetText( _( "Thickness (mils)" ) ); break;
278  default: wxFAIL_MSG( wxT( "Unhandled unit type" ) );
279  }
280 
281  colThickness.push_back( t );
282 
283  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
284  t->SetText( _( "Color" ) );
285  colColor.push_back( t );
286 
287  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
288  t->SetText( _( "Epsilon R" ) );
289  colEpsilon.push_back( t );
290 
291  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
292  t->SetText( _( "Loss Tangent" ) );
293  colTanD.push_back( t );
294 
295  for( int i = 0; i < stackup.GetCount(); i++ )
296  {
297  BOARD_STACKUP_ITEM* stackup_item = layers.at( i );
298 
299  for( int j = 0; j < stackup_item->GetSublayersCount(); j++ )
300  {
301  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
302 
303  // Layer names are empty until we close at least once the board setup dialog.
304  // If the user did not open the dialog, then get the names from the board.
305  // But dielectric layer names will be missing.
306  // In this case, for dielectric, a dummy name will be used
307  if( stackup_item->GetLayerName().IsEmpty() )
308  {
309  wxString ly_name;
310 
311  if( IsValidLayer( stackup_item->GetBrdLayerId() ) )
312  ly_name = m_frame->GetBoard()->GetLayerName( stackup_item->GetBrdLayerId() );
313 
314  if( ly_name.IsEmpty() && stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
315  ly_name = _( "Dielectric" );
316 
317  t->SetText( ly_name );
318  }
319  else
320  t->SetText( stackup_item->GetLayerName() );
321 
322  colLayer.push_back( t );
323 
324  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
325  t->SetText( stackup_item->GetTypeName() );
326  colType.push_back( t );
327 
328  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
329  t->SetText( stackup_item->GetMaterial( j ) );
330  colMaterial.push_back( t );
331 
332  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
333  t->SetText( StringFromValue( m_frame->GetUserUnits(), stackup_item->GetThickness( j ),
334  true ) );
335  colThickness.push_back( t );
336 
337  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
338  t->SetText( stackup_item->GetColor() );
339  colColor.push_back( t );
340 
341  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
342  t->SetText( StringFromValue( EDA_UNITS::UNSCALED, stackup_item->GetEpsilonR( j ),
343  false ) );
344  colEpsilon.push_back( t );
345 
346  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
348  false ) );
349  colTanD.push_back( t );
350  }
351  }
352 
353  texts.push_back( colLayer );
354  texts.push_back( colType );
355  texts.push_back( colMaterial );
356  texts.push_back( colThickness );
357  texts.push_back( colColor );
358  texts.push_back( colEpsilon );
359  texts.push_back( colTanD );
360  std::vector<BOARD_ITEM*> table = initTextTable( texts, aOrigin, aLayer, tableSize, true );
361 
362  if( aDrawNow )
363  {
364  for( BOARD_ITEM* item : table )
365  commit.Add( item );
366 
367  commit.Push( _( "Insert board stackup table" ) );
368  }
369 
370  return table;
371 }
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.
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
wxString GetColor() const
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:124
int GetThickness(int aDielectricSubLayer=0) const
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:269
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
wxString GetLayerName() const
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:786
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, 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::SetText(), StringFromValue(), BOARD_STACKUP::SynchronizeWithBoard(), and UNSCALED.

Referenced by PlaceStackup().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 2298 of file drawing_tool.cpp.

2299 {
2300  if( m_isFootprintEditor )
2301  return 0;
2302 
2303  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
2304  {
2306  PCB_GRID_HELPER m_gridHelper;
2307  std::shared_ptr<DRC_ENGINE> m_drcEngine;
2308  int m_drcEpsilon;
2309  int m_worstClearance;
2310  bool m_allowDRCViolations;
2311 
2312  VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
2313  m_frame( aFrame ),
2314  m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ),
2315  m_drcEngine( aFrame->GetBoard()->GetDesignSettings().m_DRCEngine ),
2316  m_drcEpsilon( aFrame->GetBoard()->GetDesignSettings().GetDRCEpsilon() ),
2317  m_worstClearance( 0 )
2318  {
2320 
2321  m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations();
2322 
2323  try
2324  {
2325  m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() );
2326 
2327  DRC_CONSTRAINT constraint;
2328 
2329  if( m_drcEngine->QueryWorstConstraint( CLEARANCE_CONSTRAINT, constraint ) )
2330  m_worstClearance = constraint.GetValue().Min();
2331 
2332  if( m_drcEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, constraint ) )
2333  m_worstClearance = std::max( m_worstClearance, constraint.GetValue().Min() );
2334 
2335  for( FOOTPRINT* footprint : aFrame->GetBoard()->Footprints() )
2336  {
2337  for( PAD* pad : footprint->Pads() )
2338  m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
2339  }
2340  }
2341  catch( PARSE_ERROR& )
2342  {
2343  }
2344  }
2345 
2346  virtual ~VIA_PLACER()
2347  {
2348  }
2349 
2350  PCB_TRACK* findTrack( PCB_VIA* aVia )
2351  {
2352  const LSET lset = aVia->GetLayerSet();
2353  wxPoint position = aVia->GetPosition();
2354  BOX2I bbox = aVia->GetBoundingBox();
2355 
2356  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2357  auto view = m_frame->GetCanvas()->GetView();
2358  std::vector<PCB_TRACK*> possible_tracks;
2359 
2360  view->Query( bbox, items );
2361 
2362  for( auto it : items )
2363  {
2364  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
2365 
2366  if( !(item->GetLayerSet() & lset ).any() )
2367  continue;
2368 
2369  if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
2370  {
2371  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
2372  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
2373  possible_tracks.push_back( track );
2374  }
2375  }
2376 
2377  PCB_TRACK* return_track = nullptr;
2378  int min_d = std::numeric_limits<int>::max();
2379 
2380  for( PCB_TRACK* track : possible_tracks )
2381  {
2382  SEG test( track->GetStart(), track->GetEnd() );
2383  int dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
2384 
2385  if( dist < min_d )
2386  {
2387  min_d = dist;
2388  return_track = track;
2389  }
2390  }
2391 
2392  return return_track;
2393  }
2394 
2395  bool hasDRCViolation( PCB_VIA* aVia, BOARD_ITEM* aOther )
2396  {
2397  // It would really be better to know what particular nets a nettie should allow,
2398  // but for now it is what it is.
2399  if( DRC_ENGINE::IsNetTie( aOther ) )
2400  return false;
2401 
2402  DRC_CONSTRAINT constraint;
2403 
2404  if( ( aOther->Type() == PCB_ZONE_T || aOther->Type() == PCB_FP_ZONE_T )
2405  && static_cast<ZONE*>( aOther )->GetIsRuleArea() )
2406  {
2407  ZONE* zone = static_cast<ZONE*>( aOther );
2408 
2409  if( zone->GetDoNotAllowVias() )
2410  return true;
2411 
2412  constraint = m_drcEngine->EvalRules( DISALLOW_CONSTRAINT, aVia, nullptr,
2413  UNDEFINED_LAYER );
2414 
2415  if( constraint.m_DisallowFlags )
2416  return true;
2417 
2418  return false;
2419  }
2420 
2421  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aOther );
2422 
2423  if( cItem && cItem->GetNetCode() == aVia->GetNetCode() )
2424  return false;
2425 
2426  int clearance;
2427 
2428  for( PCB_LAYER_ID layer : aOther->GetLayerSet().Seq() )
2429  {
2430  if( !IsCopperLayer( layer ) )
2431  continue;
2432 
2433  constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aVia, aOther, layer );
2434  clearance = constraint.GetValue().Min();
2435 
2436  if( clearance >= 0 )
2437  {
2438  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, layer );
2439  std::shared_ptr<SHAPE> otherShape = DRC_ENGINE::GetShape( aOther, layer );
2440 
2441  if( viaShape->Collide( otherShape.get(), clearance - m_drcEpsilon ) )
2442  return true;
2443  }
2444  }
2445 
2446  std::unique_ptr<SHAPE_SEGMENT> holeShape;
2447 
2448  if( aOther->Type() == PCB_VIA_T )
2449  {
2450  PCB_VIA* via = static_cast<PCB_VIA*>( aOther );
2451  wxPoint pos = via->GetPosition();
2452 
2453  holeShape.reset( new SHAPE_SEGMENT( pos, pos, via->GetDrill() ) );
2454  }
2455  else if( aOther->Type() == PCB_PAD_T )
2456  {
2457  PAD* pad = static_cast<PAD*>( aOther );
2458 
2459  if( pad->GetDrillSize().x )
2460  holeShape.reset( new SHAPE_SEGMENT( *pad->GetEffectiveHoleShape() ) );
2461  }
2462 
2463  if( holeShape )
2464  {
2465  constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, aVia, aOther,
2466  UNDEFINED_LAYER );
2467  clearance = constraint.GetValue().Min();
2468 
2469  if( clearance >= 0 )
2470  {
2471  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, UNDEFINED_LAYER );
2472 
2473  if( viaShape->Collide( holeShape.get(), clearance - m_drcEpsilon ) )
2474  return true;
2475  }
2476  }
2477 
2478  return false;
2479  }
2480 
2481  bool checkDRCViolation( PCB_VIA* aVia )
2482  {
2483  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2484  std::set<BOARD_ITEM*> checkedItems;
2485  BOX2I bbox = aVia->GetBoundingBox();
2486 
2487  bbox.Inflate( m_worstClearance );
2488  m_frame->GetCanvas()->GetView()->Query( bbox, items );
2489 
2490  for( std::pair<KIGFX::VIEW_ITEM*, int> it : items )
2491  {
2492  BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( it.first );
2493 
2494  if( !item )
2495  continue;
2496 
2497  if( ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
2498  && !static_cast<ZONE*>( item )->GetIsRuleArea() )
2499  {
2500  continue; // stitching vias bind to zones, so ignore them
2501  }
2502  else if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_GROUP_T )
2503  {
2504  continue; // check against children, but not against footprint itself
2505  }
2506  else if( item->Type() == PCB_FP_TEXT_T
2507  && !static_cast<FP_TEXT*>( item )->IsVisible() )
2508  {
2509  continue; // ignore hidden items
2510  }
2511  else if( checkedItems.count( item ) )
2512  {
2513  continue; // already checked
2514  }
2515 
2516  if( hasDRCViolation( aVia, item ) )
2517  return true;
2518 
2519  checkedItems.insert( item );
2520  }
2521 
2522  return false;
2523  }
2524 
2525  PAD* findPad( PCB_VIA* aVia )
2526  {
2527  const wxPoint position = aVia->GetPosition();
2528  const LSET lset = aVia->GetLayerSet();
2529 
2530  for( FOOTPRINT* fp : m_board->Footprints() )
2531  {
2532  for(PAD* pad : fp->Pads() )
2533  {
2534  if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
2535  if( pad->GetNetCode() > 0 )
2536  return pad;
2537  }
2538  }
2539 
2540  return nullptr;
2541  }
2542 
2543  int findStitchedZoneNet( PCB_VIA* aVia )
2544  {
2545  const wxPoint position = aVia->GetPosition();
2546  const LSET lset = aVia->GetLayerSet();
2547 
2548  // first take the net of the active layer
2549  if( lset.test( m_frame->GetActiveLayer() ) )
2550  {
2551  for( ZONE* z : m_board->Zones() )
2552  {
2553  if( z->IsOnLayer( m_frame->GetActiveLayer() ) )
2554  {
2555  if( z->HitTestFilledArea( m_frame->GetActiveLayer(), position ) )
2556  return z->GetNetCode();
2557  }
2558  }
2559  }
2560 
2561  // none? take the topmost visible layer
2562  for( PCB_LAYER_ID layer : LSET( m_board->GetVisibleLayers() & lset ).Seq() )
2563  {
2564  for( ZONE* z : m_board->Zones() )
2565  {
2566  if( z->IsOnLayer( m_frame->GetActiveLayer() ) )
2567  {
2568  if( z->HitTestFilledArea( layer, position ) )
2569  return z->GetNetCode();
2570  }
2571  }
2572  }
2573 
2574  return -1;
2575  }
2576 
2577  void SnapItem( BOARD_ITEM *aItem ) override
2578  {
2579  // If you place a Via on a track but not on its centerline, the current
2580  // connectivity algorithm will require us to put a kink in the track when
2581  // we break it (so that each of the two segments ends on the via center).
2582  // That's not ideal, and is in fact probably worse than forcing snap in
2583  // this situation.
2584 
2585  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
2586  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
2587  wxPoint position = via->GetPosition();
2588  PCB_TRACK* track = findTrack( via );
2589  PAD* pad = findPad( via );
2590 
2591  if( track )
2592  {
2593  SEG trackSeg( track->GetStart(), track->GetEnd() );
2594  VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
2595 
2596  aItem->SetPosition( (wxPoint) snap );
2597  }
2598  else if( pad && m_gridHelper.GetSnap()
2601  {
2602  aItem->SetPosition( pad->GetPosition() );
2603  }
2604  }
2605 
2606  bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
2607  {
2608  WX_INFOBAR* infobar = m_frame->GetInfoBar();
2609  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
2610  wxPoint viaPos = via->GetPosition();
2611  PCB_TRACK* track = findTrack( via );
2612  PAD* pad = findPad( via );
2613 
2614  if( track )
2615  via->SetNetCode( track->GetNetCode() );
2616  else if( pad )
2617  via->SetNetCode( pad->GetNetCode() );
2618  else
2619  via->SetNetCode( findStitchedZoneNet( via ) );
2620 
2621  if( !m_allowDRCViolations && checkDRCViolation( via ) )
2622  {
2623  m_frame->ShowInfoBarError( _( "Via location violates DRC." ), true,
2625  via->SetNetCode( 0 );
2626  return false;
2627  }
2628  else
2629  {
2631  infobar->Dismiss();
2632  }
2633 
2634  if( track )
2635  {
2636  if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
2637  {
2638  aCommit.Modify( track );
2639 
2640  PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
2641  const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
2642 
2643  track->SetEnd( viaPos );
2644  newTrack->SetStart( viaPos );
2645  aCommit.Add( newTrack );
2646  }
2647  }
2648  else if( !pad )
2649  {
2650  via->SetNetCode( findStitchedZoneNet( via ) );
2651  via->SetIsFree();
2652  }
2653 
2654  aCommit.Add( aItem );
2655  return true;
2656  }
2657 
2658  std::unique_ptr<BOARD_ITEM> CreateItem() override
2659  {
2661  PCB_VIA* via = new PCB_VIA( m_board );
2662 
2663  via->SetNetCode( 0 );
2664  via->SetViaType( bds.m_CurrentViaType );
2665 
2666  // for microvias, the size and hole will be changed later.
2667  via->SetWidth( bds.GetCurrentViaSize() );
2668  via->SetDrill( bds.GetCurrentViaDrill() );
2669 
2670  // Usual via is from copper to component.
2671  // layer pair is B_Cu and F_Cu.
2672  via->SetLayerPair( B_Cu, F_Cu );
2673 
2674  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
2675  PCB_LAYER_ID last_layer;
2676 
2677  // prepare switch to new active layer:
2678  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
2679  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
2680  else
2681  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
2682 
2683  // Adjust the actual via layer pair
2684  switch( via->GetViaType() )
2685  {
2686  case VIATYPE::BLIND_BURIED:
2687  via->SetLayerPair( first_layer, last_layer );
2688  break;
2689 
2690  case VIATYPE::MICROVIA: // from external to the near neighbor inner layer
2691  {
2692  PCB_LAYER_ID last_inner_layer =
2693  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
2694 
2695  if( first_layer == B_Cu )
2696  last_layer = last_inner_layer;
2697  else if( first_layer == F_Cu )
2698  last_layer = In1_Cu;
2699  else if( first_layer == last_inner_layer )
2700  last_layer = B_Cu;
2701  else if( first_layer == In1_Cu )
2702  last_layer = F_Cu;
2703 
2704  // else error: will be removed later
2705  via->SetLayerPair( first_layer, last_layer );
2706 
2707  // Update diameter and hole size, which where set previously for normal vias
2708  NETCLASS* netClass = via->GetNetClass();
2709 
2710  via->SetWidth( netClass->GetuViaDiameter() );
2711  via->SetDrill( netClass->GetuViaDrill() );
2712  }
2713  break;
2714 
2715  default:
2716  break;
2717  }
2718 
2719  return std::unique_ptr<BOARD_ITEM>( via );
2720  }
2721  };
2722 
2723  VIA_PLACER placer( frame() );
2724 
2725  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
2726 
2727  doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
2729 
2730  return 0;
2731 }
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:213
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
bool GetSnap() const
Definition: grid_helper.h:65
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
ZONES & Zones()
Definition: board.h:240
BOARD * m_board
Definition: drawing_tool.h:268
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:58
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:252
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
bool GetDoNotAllowVias() const
Definition: zone.h:737
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:481
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:375
class PAD, a pad in a footprint
Definition: typeinfo.h:89
int GetWidth() const
Definition: pcb_track.h:102
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
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:169
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:516
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.
FOOTPRINTS & Footprints()
Definition: board.h:234
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:808
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:269
void SetSnap(bool aSnap)
Definition: grid_helper.h:64
BOARD * GetBoard()
const KIID m_Uuid
Definition: eda_item.h:474
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
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
MAGNETIC_OPTIONS pads
int m_DisallowFlags
Definition: drc_rule.h:146
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:426
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:182
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914
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:148
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
Container for design settings for a BOARD object.

References _, COMMIT::Add(), PCB_GRID_HELPER::AlignToSegment(), PNS::ROUTING_SETTINGS::AllowDRCViolations(), B_Cu, BLIND_BURIED, CAPTURE_ALWAYS, CLEARANCE_CONSTRAINT, PCB_TRACK::Clone(), DISALLOW_CONSTRAINT, 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(), ZONE::GetDoNotAllowVias(), BOARD_DESIGN_SETTINGS::GetDRCEpsilon(), PCB_TRACK::GetEnd(), EDA_BASE_FRAME::GetInfoBar(), 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(), GRID_HELPER::GetSnap(), PCB_TRACK::GetStart(), TOOL_MANAGER::GetTool(), TOOLS_HOLDER::GetToolManager(), NETCLASS::GetuViaDiameter(), NETCLASS::GetuViaDrill(), DRC_CONSTRAINT::GetValue(), PCB_DRAW_PANEL_GAL::GetView(), BOARD::GetVisibleLayers(), PCB_TRACK::GetWidth(), HOLE_CLEARANCE_CONSTRAINT, In1_Cu, BOX2< Vec >::Inflate(), PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_SINGLE_CLICK, IsCopperLayer(), DRC_ENGINE::IsNetTie(), m_board, BOARD_DESIGN_SETTINGS::m_CurrentViaType, DRC_CONSTRAINT::m_DisallowFlags, 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, MAGNETIC_SETTINGS::pads, 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 2044 of file drawing_tool.cpp.

2045 {
2046  if( m_isFootprintEditor && !m_frame->GetModel() )
2047  return 0;
2048 
2049  ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
2050  MODE drawMode = MODE::ZONE;
2051 
2052  if( aEvent.IsAction( &PCB_ACTIONS::drawRuleArea ) )
2053  drawMode = MODE::KEEPOUT;
2054 
2055  if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
2056  drawMode = MODE::GRAPHIC_POLYGON;
2057 
2058  SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
2059 
2060  // get a source zone, if we need one. We need it for:
2061  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
2062  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
2063  ZONE* sourceZone = nullptr;
2064 
2065  if( !getSourceZoneForAction( zoneMode, &sourceZone ) )
2066  return 0;
2067 
2068  // Turn zones on if they are off, so that the created object will be visible after completion
2070 
2072 
2073  params.m_keepout = drawMode == MODE::KEEPOUT;
2074  params.m_mode = zoneMode;
2075  params.m_sourceZone = sourceZone;
2076 
2077  if( zoneMode == ZONE_MODE::SIMILAR )
2078  params.m_layer = sourceZone->GetLayer();
2079  else
2080  params.m_layer = m_frame->GetActiveLayer();
2081 
2082  ZONE_CREATE_HELPER zoneTool( *this, params );
2083  // the geometry manager which handles the zone geometry, and hands the calculated points
2084  // over to the zone creator tool
2085  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
2086  bool constrainAngle = false;
2087  bool started = false;
2089  STATUS_TEXT_POPUP status( m_frame );
2090 
2091  status.SetTextColor( wxColour( 255, 0, 0 ) );
2092  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
2093 
2094  std::string tool = aEvent.GetCommandStr().get();
2095  m_frame->PushTool( tool );
2096 
2097  auto setCursor =
2098  [&]()
2099  {
2101  };
2102 
2103  auto cleanup =
2104  [&] ()
2105  {
2106  polyGeomMgr.Reset();
2107  started = false;
2108  grid.ClearSkipPoint();
2109  m_controls->SetAutoPan( false );
2110  m_controls->CaptureCursor( false );
2111  };
2112 
2113  Activate();
2114  // Must be done after Activate() so that it gets set into the correct context
2115  m_controls->ShowCursor( true );
2116  // Set initial cursor
2117  setCursor();
2118 
2119  // Prime the pump
2120  if( aEvent.HasPosition() )
2121  m_toolMgr->PrimeTool( aEvent.Position() );
2122 
2123  // Main loop: keep receiving events
2124  while( TOOL_EVENT* evt = Wait() )
2125  {
2126  setCursor();
2127 
2128  LSET layers( m_frame->GetActiveLayer() );
2129  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2130  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2131 
2132  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
2133  cursorPos = grid.BestSnapAnchor( cursorPos, layers );
2134 
2135  m_controls->ForceCursorPosition( true, cursorPos );
2136 
2137  if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || Is45Limited() )
2138  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2139  else
2140  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
2141 
2142  if( evt->IsCancelInteractive() )
2143  {
2144  if( polyGeomMgr.IsPolygonInProgress() )
2145  {
2146  cleanup();
2147  }
2148  else
2149  {
2150  // We've handled the cancel event. Don't cancel other tools
2151  evt->SetPassEvent( false );
2152  m_frame->PopTool( tool );
2153  break;
2154  }
2155  }
2156  else if( evt->IsActivate() )
2157  {
2158  if( polyGeomMgr.IsPolygonInProgress() )
2159  cleanup();
2160 
2161  if( evt->IsPointEditor() )
2162  {
2163  // don't exit (the point editor runs in the background)
2164  }
2165  else if( evt->IsMoveTool() )
2166  {
2167  // leave ourselves on the stack so we come back after the move
2168  break;
2169  }
2170  else
2171  {
2172  m_frame->PopTool( tool );
2173  break;
2174  }
2175  }
2176  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
2177  {
2178  if( zoneMode != ZONE_MODE::SIMILAR )
2179  params.m_layer = frame()->GetActiveLayer();
2180 
2181  if( !m_view->IsLayerVisible( params.m_layer ) )
2182  {
2183  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2184  m_frame->GetCanvas()->Refresh();
2185  }
2186  }
2187  else if( evt->IsClick( BUT_RIGHT ) )
2188  {
2190  }
2191  // events that lock in nodes
2192  else if( evt->IsClick( BUT_LEFT )
2193  || evt->IsDblClick( BUT_LEFT )
2194  || evt->IsAction( &PCB_ACTIONS::closeOutline ) )
2195  {
2196  // Check if it is double click / closing line (so we have to finish the zone)
2197  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
2198  || evt->IsAction( &PCB_ACTIONS::closeOutline )
2199  || polyGeomMgr.NewPointClosesOutline( cursorPos );
2200 
2201  if( endPolygon )
2202  {
2203  polyGeomMgr.SetFinished();
2204  polyGeomMgr.Reset();
2205 
2206  started = false;
2207  m_controls->SetAutoPan( false );
2208  m_controls->CaptureCursor( false );
2209  }
2210  // adding a corner
2211  else if( polyGeomMgr.AddPoint( cursorPos ) )
2212  {
2213  if( !started )
2214  {
2215  started = true;
2216 
2217  POLYGON_GEOM_MANAGER::LEADER_MODE leaderMode = polyGeomMgr.GetLeaderMode();
2218  constrainAngle = ( leaderMode == POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2219 
2220  m_controls->SetAutoPan( true );
2221  m_controls->CaptureCursor( true );
2222 
2223  if( !m_view->IsLayerVisible( params.m_layer ) )
2224  {
2225  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2226  m_frame->GetCanvas()->Refresh();
2227  }
2228  }
2229  }
2230  }
2231  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
2232  {
2233  polyGeomMgr.DeleteLastCorner();
2234 
2235  if( !polyGeomMgr.IsPolygonInProgress() )
2236  {
2237  // report finished as an empty shape
2238  polyGeomMgr.SetFinished();
2239 
2240  // start again
2241  started = false;
2242  m_controls->SetAutoPan( false );
2243  m_controls->CaptureCursor( false );
2244  }
2245  }
2246  else if( polyGeomMgr.IsPolygonInProgress()
2247  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
2248  {
2249  polyGeomMgr.SetCursorPosition( cursorPos );
2250 
2251  if( polyGeomMgr.IsSelfIntersecting( true ) )
2252  {
2253  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
2254  status.Move( p );
2255  status.PopupFor( 1500 );
2256  }
2257  else
2258  {
2259  status.Hide();
2260  }
2261  }
2262  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
2263  {
2264  if( started )
2265  {
2266  frame()->OnEditItemRequest( zoneTool.GetZone() );
2267  zoneTool.OnGeometryChange( polyGeomMgr );
2268  frame()->SetMsgPanel( zoneTool.GetZone() );
2269  }
2270  else
2271  {
2272  evt->SetPassEvent();
2273  }
2274  }
2275  /*else if( evt->IsAction( &ACTIONS::updateUnits ) )
2276  {
2277  // If we ever have an assistant here that reports dimensions, we'll want to
2278  // update its units here....
2279  // zoneAsst.SetUnits( frame()->GetUserUnits() );
2280  // m_view->Update( &zoneAsst );
2281  evt->SetPassEvent();
2282  }*/
2283  else
2284  {
2285  evt->SetPassEvent();
2286  }
2287 
2288  } // end while
2289 
2291  m_controls->ForceCursorPosition( false );
2292  controls()->SetAutoPan( false );
2293  m_controls->CaptureCursor( false );
2294  return 0;
2295 }
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:140
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:238
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:266
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
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:267
Unconstrained point-to-point.
virtual bool Is45Limited() const
Should the tool use its 45° mode option?
bool m_isFootprintEditor
bool GetHV45() const
Definition: zone.h:803
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:269
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:289
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:151
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:160
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:161

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(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), 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(), PAD_TOOL::Reset(), PNS::TOOL_BASE::Reset(), EDIT_TOOL::Rotate(), 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 248 of file drawing_tool.cpp.

249 {
250  return m_mode;
251 }

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

2735 {
2736  assert( m_board );
2737  return m_board->GetDesignSettings().GetLineThickness( aLayer );
2738 }
BOARD * m_board
Definition: drawing_tool.h:268
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 2010 of file drawing_tool.cpp.

2011 {
2012  bool clearSelection = false;
2013  *aZone = nullptr;
2014 
2015  // not an action that needs a source zone
2016  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
2017  return true;
2018 
2020  const PCB_SELECTION& selection = selTool->GetSelection();
2021 
2022  if( selection.Empty() )
2023  {
2024  clearSelection = true;
2026  }
2027 
2028  // we want a single zone
2029  if( selection.Size() == 1 )
2030  *aZone = dyn_cast<ZONE*>( selection[0] );
2031 
2032  // expected a zone, but didn't get one
2033  if( !*aZone )
2034  {
2035  if( clearSelection )
2037 
2038  return false;
2039  }
2040 
2041  return true;
2042 }
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(), PL_EDIT_TOOL::moveItem(), SCH_MOVE_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(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), 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::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(), COMMON_CONTROL::setTransitions(), KICAD_MANAGER_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(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), PAD_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), SCH_MOVE_TOOL::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_ASSOCIATION_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), PICKER_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), PCB_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), setTransitions(), SCH_EDITOR_CONTROL::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 177 of file drawing_tool.cpp.

178 {
179  auto activeToolFunctor = [this]( const SELECTION& aSel )
180  {
181  return m_mode != MODE::NONE;
182  };
183 
184  // some interactive drawing tools can undo the last point
185  auto canUndoPoint = [this]( const SELECTION& aSel )
186  {
187  return ( m_mode == MODE::ARC
188  || m_mode == MODE::ZONE
189  || m_mode == MODE::KEEPOUT
191  };
192 
193  // functor for tools that can automatically close the outline
194  auto canCloseOutline = [this]( const SELECTION& aSel )
195  {
196  return ( m_mode == MODE::ZONE
197  || m_mode == MODE::KEEPOUT
199  };
200 
201  auto viaToolActive = [this]( const SELECTION& aSel )
202  {
203  return m_mode == MODE::VIA;
204  };
205 
206  auto& ctxMenu = m_menu.GetMenu();
207 
208  // cancel current tool goes in main context menu at the top if present
209  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
210  ctxMenu.AddSeparator( 1 );
211 
212  // tool-specific actions
213  ctxMenu.AddItem( PCB_ACTIONS::closeOutline, canCloseOutline, 200 );
214  ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
215 
216  ctxMenu.AddCheckItem( PCB_ACTIONS::toggle45, SELECTION_CONDITIONS::ShowAlways, 250 );
217  ctxMenu.AddSeparator( 500 );
218 
219  std::shared_ptr<VIA_SIZE_MENU> viaSizeMenu = std::make_shared<VIA_SIZE_MENU>();
220  viaSizeMenu->SetTool( this );
221  m_menu.AddSubMenu( viaSizeMenu );
222  ctxMenu.AddMenu( viaSizeMenu.get(), viaToolActive, 500 );
223 
224  ctxMenu.AddSeparator( 500 );
225 
226  // Type-specific sub-menus will be added for us by other tools
227  // For example, zone fill/unfill is provided by the PCB control tool
228 
229  // Finally, add the standard zoom/grid items
230  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
231 
232  return true;
233 }
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Store a submenu of this menu model.
Definition: tool_menu.cpp:52
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:160
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
static TOOL_ACTION toggle45
Definition: pcb_actions.h:420
static TOOL_ACTION closeOutline
Definition: pcb_actions.h:161

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

◆ InteractivePlaceWithPreview()

int DRAWING_TOOL::InteractivePlaceWithPreview ( const TOOL_EVENT aEvent,
std::vector< BOARD_ITEM * > &  aItems,
std::vector< BOARD_ITEM * > &  aPreview,
LSET aLayers 
)

Interactively place a set of BOARD_ITEM.

As a list of BOARD_ITEMs can be resource intesive to move around, we can use a reduced set of BOARD_ITEMs for preview purpose only.

Parameters
aEvent
aItemsBOARD_ITEMs to add to the board.
aPreviewBOARD_ITEMs only used during placement / preview.
aLayersSet of allowed destination when asking the user. If set to NULL, the user is not asked and all BOARD_ITEMs remain on their layers.

Definition at line 556 of file drawing_stackup_table_tool.cpp.

560 {
562  return -1;
563 
564  bool cancelled = false;
565 
566  BOARD_COMMIT commit( m_frame );
567 
569 
570  // do not capture or auto-pan until we start placing the table
571  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
572 
573  std::string tool = aEvent.GetCommandStr().get();
574  m_frame->PushTool( tool );
575 
576  Activate();
577  // Must be done after Activate() so that it gets set into the correct context
578  m_controls->ShowCursor( true );
579 
580  // Prime the pump
581  if( aEvent.HasPosition() )
583 
584  // Main loop: keep receiving events
585  wxPoint wxCursorPosition = wxPoint();
586  wxPoint wxPreviousCursorPosition = wxPoint( 0, 0 );
587 
588  view()->ClearPreview();
589  view()->InitPreview();
590 
591  for( BOARD_ITEM* item : aPreview )
592  {
593  item->Move( wxCursorPosition - wxPreviousCursorPosition );
594  view()->AddToPreview( item );
595  }
596 
597  while( TOOL_EVENT* evt = Wait() )
598  {
601  wxCursorPosition.x = pos.x;
602  wxCursorPosition.y = pos.y;
603 
604  if( evt->IsCancelInteractive() )
605  {
606  m_frame->PopTool( tool );
607  cancelled = true;
608  break;
609  }
610 
611  if( evt->IsMotion() )
612  {
613  view()->ShowPreview( false );
614 
615  for( auto item : aPreview )
616  {
617  item->Move( wxCursorPosition - wxPreviousCursorPosition );
618  }
619 
620  view()->ShowPreview( true );
621 
622  wxPreviousCursorPosition.x = wxCursorPosition.x;
623  wxPreviousCursorPosition.y = wxCursorPosition.y;
624 
625  }
626  else if( evt->IsActivate() )
627  {
628 
629  if( evt->IsMoveTool() )
630  {
631  // leave ourselves on the stack so we come back after the move
632  cancelled = true;
633  break;
634  }
635  else
636  {
637  m_frame->PopTool( tool );
638  cancelled = true;
639  break;
640  }
641  }
642  else if( evt->IsClick( BUT_RIGHT ) )
643  {
645  }
646  else if( evt->IsClick( BUT_LEFT ) )
647  {
648  if( aLayers != nullptr )
649  {
650  <