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 (wxPoint origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
 Function DrawBoardCharacteristics() More...
 
std::vector< BOARD_ITEM * > DrawSpecificationStackup (wxPoint origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
 Function DrawSpecificationStackup() More...
 
int PlaceCharacteristics (const TOOL_EVENT &aEvent)
 Function PlaceCharacteristics() More...
 
int PlaceStackup (const TOOL_EVENT &aEvent)
 Function PlaceStackup() More...
 
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
 
void Activate ()
 Run the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Assign a context menu and tells when it should be activated. More...
 
void RunMainStack (std::function< void()> aFunc)
 Call a function using the main stack. More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Define which state (aStateFunc) to go when a certain event arrives (aConditions). More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Suspend execution of the tool until an event specified in aEventList arrives. More...
 
TOOL_TYPE GetType () const
 Return the type of the tool. More...
 
TOOL_ID GetId () const
 Return the unique identifier of the tool. More...
 
const std::string & GetName () const
 Return the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Return the instance of TOOL_MANAGER that takes care of the tool. More...
 
bool IsToolActive () const
 

Protected Types

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

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static const unsigned int WIDTH_STEP = Millimeter2iu( 0.1 )
 

Friends

class ZONE_CREATE_HELPER
 

Detailed Description

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

Definition at line 50 of file drawing_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Options for placing items interactively.

Enumerator
IPO_ROTATE 

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

IPO_FLIP 

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

IPO_SINGLE_CLICK 

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

IPO_REPEAT 

Allow repeat placement of the item.

Definition at line 110 of file pcb_tool_base.h.

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

◆ MODE

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

Definition at line 63 of file drawing_tool.h.

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

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

153  :
154  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
155  m_view( nullptr ),
156  m_controls( nullptr ),
157  m_board( nullptr ),
158  m_frame( nullptr ),
159  m_mode( MODE::NONE ),
160  m_inDrawingTool( false ),
161  m_lineWidth( 1 )
162 {
163 }
BOARD * m_board
Definition: drawing_tool.h:269
bool m_inDrawingTool
Definition: drawing_tool.h:272
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
unsigned int m_lineWidth
Definition: drawing_tool.h:274
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:268
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
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 166 of file drawing_tool.cpp.

167 {
168 }

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 159 of file pcb_tool_base.h.

159 { return getModel<BOARD>(); }

Referenced by PCB_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), BOARD_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::DragArcTrack(), drawArc(), DrawDimension(), drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportNetlist(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), PCB_SELECTION_TOOL::filterSelection(), PCB_TOOL_BASE::footprint(), PCB_SELECTION_TOOL::GetBoard(), PCB_SELECTION_TOOL::getCollectorsGuide(), GROUP_TOOL::Group(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::highlightNet(), InteractivePlaceWithPreview(), PCB_CONTROL::LayerNext(), PCB_CONTROL::LayerPrev(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::MoveExact(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), PCB_CONTROL::Paste(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PAD_TOOL::PlacePad(), BOARD_EDITOR_CONTROL::PlaceTarget(), PlaceText(), PCB_SELECTION_TOOL::RebuildSelection(), PAD_TOOL::recombinePad(), BOARD_EDITOR_CONTROL::RepairBoard(), FOOTPRINT_EDITOR_CONTROL::RepairFootprint(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::selectAllItemsOnNet(), PCB_SELECTION_TOOL::selectAllItemsOnSheet(), PCB_SELECTION_TOOL::selectConnectedTracks(), PCB_SELECTION_TOOL::selectionContains(), PCB_SELECTION_TOOL::selectPoint(), PCB_CONTROL::TrackDisplayMode(), 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 681 of file drawing_tool.cpp.

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

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

Referenced by DrawDimension().

◆ controls()

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

Definition at line 294 of file pcb_tool_base.cpp.

295 {
296  return frame()->GetDisplayOptions();
297 }
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
PCB_BASE_EDIT_FRAME * frame() const

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

Referenced by BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), PCB_CONTROL::HighContrastMode(), PCB_CONTROL::HighContrastModeCycle(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), PNS::TOOL_BASE::pickSingleItem(), PCB_CONTROL::ToggleRatsnest(), PCB_CONTROL::TrackDisplayMode(), PCB_CONTROL::ViaDisplayMode(), and PCB_CONTROL::ZoneDisplayMode().

◆ 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 35 of file pcb_tool_base.cpp.

38 {
39  using namespace std::placeholders;
40  std::unique_ptr<BOARD_ITEM> newItem;
41 
42  frame()->PushTool( aTool );
43  Activate();
44 
45  BOARD_COMMIT commit( frame() );
46 
48 
49  // do not capture or auto-pan until we start placing an item
50  controls()->ShowCursor( true );
51 
52  // Add a VIEW_GROUP that serves as a preview for the new item
53  PCB_SELECTION preview;
54  view()->Add( &preview );
55 
56  aPlacer->m_board = board();
57  aPlacer->m_frame = frame();
58  aPlacer->m_modifiers = 0;
59 
60  auto makeNewItem =
61  [&]( VECTOR2I aPosition )
62  {
63  if( frame()->GetModel() )
64  newItem = aPlacer->CreateItem();
65 
66  if( newItem )
67  {
68  newItem->SetPosition( (wxPoint) aPosition );
69  preview.Add( newItem.get() );
70 
71  if( newItem->Type() == PCB_FOOTPRINT_T )
72  {
73  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
74 
75  // footprints have more drawable parts
76  fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
77  }
78  }
79  };
80 
81  if( aOptions & IPO_SINGLE_CLICK )
82  makeNewItem( controls()->GetCursorPosition() );
83 
84  auto setCursor =
85  [&]()
86  {
87  if( !newItem )
89  else
91  };
92 
93  // Set initial cursor
94  setCursor();
95 
96  // Main loop: keep receiving events
97  while( TOOL_EVENT* evt = Wait() )
98  {
99  setCursor();
100 
101  VECTOR2I cursorPos = controls()->GetCursorPosition();
102  aPlacer->m_modifiers = evt->Modifier();
103 
104  auto cleanup =
105  [&] ()
106  {
107  newItem = nullptr;
108  preview.Clear();
109  view()->Update( &preview );
110  controls()->SetAutoPan( false );
111  controls()->CaptureCursor( false );
112  controls()->ShowCursor( true );
113  };
114 
115  if( evt->IsCancelInteractive() )
116  {
117  if( aOptions & IPO_SINGLE_CLICK )
118  {
119  cleanup();
120  frame()->PopTool( aTool );
121  break;
122  }
123  else if( newItem )
124  {
125  cleanup();
126  }
127  else
128  {
129  frame()->PopTool( aTool );
130  break;
131  }
132  }
133  else if( evt->IsActivate() )
134  {
135  if( newItem )
136  cleanup();
137 
138  if( evt->IsPointEditor() )
139  {
140  // don't exit (the point editor runs in the background)
141  }
142  else if( evt->IsMoveTool() )
143  {
144  // leave ourselves on the stack so we come back after the move
145  break;
146  }
147  else
148  {
149  frame()->PopTool( aTool );
150  break;
151  }
152  }
153  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
154  {
155  if( !newItem )
156  {
157  // create the item if possible
158  makeNewItem( cursorPos );
159 
160  // no item created, so wait for another click
161  if( !newItem )
162  continue;
163 
164  controls()->CaptureCursor( true );
165  controls()->SetAutoPan( true );
166  }
167  else
168  {
169  auto oldFlags = newItem->GetFlags();
170  newItem->ClearFlags();
171 
172  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
173  {
174  newItem->SetFlags( oldFlags );
175  continue;
176  }
177 
178  preview.Clear();
179  newItem.release();
180  commit.Push( aCommitMessage );
181 
182  controls()->CaptureCursor( false );
183  controls()->SetAutoPan( false );
184  controls()->ShowCursor( true );
185 
186  if( !( aOptions & IPO_REPEAT ) )
187  break;
188 
189  if( aOptions & IPO_SINGLE_CLICK )
190  makeNewItem( controls()->GetCursorPosition() );
191 
192  setCursor();
193  }
194  }
195  else if( evt->IsClick( BUT_RIGHT ) )
196  {
198  }
199  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
200  {
202  }
203  else if( newItem && evt->Category() == TC_COMMAND )
204  {
205  /*
206  * Handle any events that can affect the item as we move it around
207  */
208  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
209  {
210  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
211  newItem->Rotate( newItem->GetPosition(), rotationAngle );
212  view()->Update( &preview );
213  }
214  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
215  {
216  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
217  view()->Update( &preview );
218  }
219  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
220  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
221  {
222  // Refresh preview after event runs
224  }
225  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
226  {
227  frame()->OnEditItemRequest( newItem.get() );
228 
229  // Notify other tools of the changes
231  }
232  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
233  {
234  preview.Clear();
235  newItem.release();
236 
237  makeNewItem( (wxPoint) cursorPos );
238  aPlacer->SnapItem( newItem.get() );
239  view()->Update( &preview );
240  }
241  else
242  {
243  evt->SetPassEvent();
244  }
245  }
246  else if( newItem && evt->IsMotion() )
247  {
248  // track the cursor
249  newItem->SetPosition( (wxPoint) cursorPos );
250  aPlacer->SnapItem( newItem.get() );
251 
252  // Show a preview of the item
253  view()->Update( &preview );
254  }
255  else
256  {
257  evt->SetPassEvent();
258  }
259  }
260 
261  view()->Remove( &preview );
263  controls()->SetAutoPan( false );
264  controls()->CaptureCursor( false );
265 }
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:82
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:31
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:299
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:302
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
const PCB_SELECTION & selection() const
Allow repeat placement of the item.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
KIGFX::PCB_VIEW * view() const
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:56
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:1189
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:300
static TOOL_ACTION refreshPreview
Definition: actions.h:106
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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

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

◆ DrawArc()

int DRAWING_TOOL::DrawArc ( const TOOL_EVENT aEvent)

Start interactively drawing an arc.

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

Definition at line 401 of file drawing_tool.cpp.

402 {
404  return 0;
405 
406  if( m_inDrawingTool )
407  return 0;
408  else
409  m_inDrawingTool = true;
410 
411  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
412  PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
413  BOARD_COMMIT commit( m_frame );
414  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
415  bool immediateMode = aEvent.HasPosition();
416 
417  arc->SetShape( SHAPE_T::ARC );
418  arc->SetFlags( IS_NEW );
419 
420  std::string tool = aEvent.GetCommandStr().get();
421  m_frame->PushTool( tool );
422  Activate();
423 
424  while( drawArc( tool, &arc, immediateMode ) )
425  {
426  if( arc )
427  {
428  if( m_isFootprintEditor )
429  static_cast<FP_SHAPE*>( arc )->SetLocalCoord();
430 
431  commit.Add( arc );
432  commit.Push( _( "Draw an arc" ) );
433 
435  }
436 
437  arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
438  arc->SetShape( SHAPE_T::ARC );
439  arc->SetFlags( IS_NEW );
440  immediateMode = false;
441  }
442 
443  m_inDrawingTool = false;
444  return 0;
445 }
Arcs (with rounded ends)
void SetShape(SHAPE_T aShape)
Definition: pcb_shape.h:109
#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:272
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:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
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 PCB_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 1741 of file drawing_tool.cpp.

1742 {
1743  PCB_SHAPE*& graphic = *aGraphic;
1744  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1745 
1746  m_lineWidth = getSegmentWidth( drawingLayer );
1747 
1748  // Arc geometric construction manager
1750 
1751  // Arc drawing assistant overlay
1752  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1753 
1754  // Add a VIEW_GROUP that serves as a preview for the new item
1755  PCB_SELECTION preview;
1756  m_view->Add( &preview );
1757  m_view->Add( &arcAsst );
1759 
1760  m_controls->ShowCursor( true );
1761 
1762  bool firstPoint = false;
1763  bool cancelled = false;
1764 
1765  // Set initial cursor
1766  auto setCursor =
1767  [&]()
1768  {
1770  };
1771 
1772  auto cleanup =
1773  [&] ()
1774  {
1775  preview.Clear();
1776  delete *aGraphic;
1777  *aGraphic = nullptr;
1778  };
1779 
1780  // Prime the pump
1782 
1783  if( aImmediateMode )
1785 
1786  setCursor();
1787 
1788  // Main loop: keep receiving events
1789  while( TOOL_EVENT* evt = Wait() )
1790  {
1791  if( firstPoint )
1792  m_frame->SetMsgPanel( graphic );
1793 
1794  setCursor();
1795 
1796  graphic->SetLayer( drawingLayer );
1797 
1798  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1799  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1800  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
1801  m_controls->ForceCursorPosition( true, cursorPos );
1802 
1803  if( evt->IsCancelInteractive() )
1804  {
1805  cleanup();
1806 
1807  if( !firstPoint )
1808  {
1809  // We've handled the cancel event. Don't cancel other tools
1810  evt->SetPassEvent( false );
1811  m_frame->PopTool( aTool );
1812  cancelled = true;
1813  }
1814 
1815  break;
1816  }
1817  else if( evt->IsActivate() )
1818  {
1819  if( evt->IsPointEditor() )
1820  {
1821  // don't exit (the point editor runs in the background)
1822  }
1823  else if( evt->IsMoveTool() )
1824  {
1825  cleanup();
1826  // leave ourselves on the stack so we come back after the move
1827  cancelled = true;
1828  break;
1829  }
1830  else
1831  {
1832  cleanup();
1833  m_frame->PopTool( aTool );
1834  cancelled = true;
1835  break;
1836  }
1837  }
1838  else if( evt->IsClick( BUT_LEFT ) )
1839  {
1840  if( !firstPoint )
1841  {
1843 
1844  m_controls->SetAutoPan( true );
1845  m_controls->CaptureCursor( true );
1846 
1847  drawingLayer = m_frame->GetActiveLayer();
1848  m_lineWidth = getSegmentWidth( drawingLayer );
1849 
1850  // Init the new item attributes
1851  // (non-geometric, those are handled by the manager)
1852  graphic->SetShape( SHAPE_T::ARC );
1853  graphic->SetWidth( m_lineWidth );
1854 
1855  if( !m_view->IsLayerVisible( drawingLayer ) )
1856  {
1857  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1858  m_frame->GetCanvas()->Refresh();
1859  }
1860 
1861  preview.Add( graphic );
1862  frame()->SetMsgPanel( graphic );
1863  firstPoint = true;
1864  }
1865 
1866  arcManager.AddPoint( cursorPos, true );
1867  }
1868  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1869  {
1870  arcManager.RemoveLastPoint();
1871  }
1872  else if( evt->IsMotion() )
1873  {
1874  // set angle snap
1875  arcManager.SetAngleSnap( evt->Modifier( MD_SHIFT ) );
1876 
1877  // update, but don't step the manager state
1878  arcManager.AddPoint( cursorPos, false );
1879  }
1880  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1881  {
1882  drawingLayer = m_frame->GetActiveLayer();
1883  m_lineWidth = getSegmentWidth( drawingLayer );
1884 
1885  if( graphic )
1886  {
1887  if( !m_view->IsLayerVisible( drawingLayer ) )
1888  {
1889  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1890  m_frame->GetCanvas()->Refresh();
1891  }
1892 
1893  graphic->SetLayer( drawingLayer );
1894  graphic->SetWidth( m_lineWidth );
1895  m_view->Update( &preview );
1896  frame()->SetMsgPanel( graphic );
1897  }
1898  else
1899  {
1900  evt->SetPassEvent();
1901  }
1902  }
1903  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1904  {
1906  {
1907  graphic->SetAngle( 900, true );
1908  frame()->OnEditItemRequest( graphic );
1909  m_view->Update( &preview );
1910  frame()->SetMsgPanel( graphic );
1911  break;
1912  }
1913  else if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
1914  {
1915  frame()->OnEditItemRequest( graphic );
1916  m_view->Update( &preview );
1917  frame()->SetMsgPanel( graphic );
1918  break;
1919  }
1920  else
1921  {
1922  evt->SetPassEvent();
1923  }
1924  }
1925  else if( evt->IsClick( BUT_RIGHT ) )
1926  {
1928  }
1929  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1930  {
1932  graphic->SetWidth( m_lineWidth );
1933  m_view->Update( &preview );
1934  frame()->SetMsgPanel( graphic );
1935  }
1936  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1937  {
1939  graphic->SetWidth( m_lineWidth );
1940  m_view->Update( &preview );
1941  frame()->SetMsgPanel( graphic );
1942  }
1943  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1944  {
1945  arcManager.ToggleClockwise();
1946  }
1947  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1948  {
1949  arcAsst.SetUnits( frame()->GetUserUnits() );
1950  m_view->Update( &arcAsst );
1951  evt->SetPassEvent();
1952  }
1953  else
1954  {
1955  evt->SetPassEvent();
1956  }
1957 
1958  if( arcManager.IsComplete() )
1959  {
1960  break;
1961  }
1962  else if( arcManager.HasGeometryChanged() )
1963  {
1964  updateArcFromConstructionMgr( arcManager, *graphic );
1965  m_view->Update( &preview );
1966  m_view->Update( &arcAsst );
1967 
1968  if( firstPoint )
1969  frame()->SetMsgPanel( graphic );
1970  else
1971  frame()->SetMsgPanel( board() );
1972  }
1973  }
1974 
1975  preview.Remove( graphic );
1976  m_view->Remove( &arcAsst );
1977  m_view->Remove( &preview );
1978  m_frame->SetMsgPanel( board() );
1979 
1981  m_controls->SetAutoPan( false );
1982  m_controls->CaptureCursor( false );
1983  m_controls->ForceCursorPosition( false );
1984 
1985  return !cancelled;
1986 }
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,...
Arcs (with rounded ends)
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.
void SetShape(SHAPE_T aShape)
Definition: pcb_shape.h:109
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:170
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:192
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:275
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:351
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
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:173
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_LAYER_ID
A quick note on layer IDs:
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:274
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:268
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:270
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:176
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:292
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)
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 SetWidth(int aWidth)
Definition: pcb_shape.h:96
Represents an assistant draw when interactively drawing an arc on a canvas.
Definition: arc_assistant.h:38
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:163
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:321
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Set the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: pcb_shape.cpp:519
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:1503
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:404

References KIGFX::VIEW::Add(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::AddPoint(), ARC, PCB_ACTIONS::arcPosture, ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), ACTIONS::cursorClick, PCB_ACTIONS::decWidth, PCB_ACTIONS::deleteLastPoint, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSegmentWidth(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetStep(), EDA_BASE_FRAME::GetUserUnits(), GetUserUnits(), TOOL_BASE::getView(), grid, KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::HasGeometryChanged(), PCB_ACTIONS::incWidth, 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, PCB_SHAPE::SetAngle(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::SetAngleSnap(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), BOARD_ITEM::SetLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_SHAPE::SetShape(), PCB_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 ( wxPoint  origin,
PCB_LAYER_ID  aLayer,
bool  aDrawNow,
wxPoint *  tablesize 
)

Function DrawBoardCharacteristics()

Definition at line 361 of file drawing_stackup_table_tool.cpp.

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

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

Referenced by PlaceCharacteristics().

◆ DrawCircle()

int DRAWING_TOOL::DrawCircle ( const TOOL_EVENT aEvent)

Start interactively drawing a circle.

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

Definition at line 349 of file drawing_tool.cpp.

350 {
352  return 0;
353 
354  if( m_inDrawingTool )
355  return 0;
356  else
357  m_inDrawingTool = true;
358 
359  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
360  PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
361  BOARD_COMMIT commit( m_frame );
362  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
363  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
364 
365  circle->SetShape( SHAPE_T::CIRCLE );
366  circle->SetFilled( false );
367  circle->SetFlags( IS_NEW );
368 
369  if( aEvent.HasPosition() )
370  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
371 
372  std::string tool = aEvent.GetCommandStr().get();
373  m_frame->PushTool( tool );
374  Activate();
375 
376  while( drawSegment( tool, &circle, startingPoint ) )
377  {
378  if( circle )
379  {
380  if( m_isFootprintEditor )
381  static_cast<FP_SHAPE*>( circle )->SetLocalCoord();
382 
383  commit.Add( circle );
384  commit.Push( _( "Draw a circle" ) );
385 
386  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
387  }
388 
389  circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
390  circle->SetShape( SHAPE_T::CIRCLE );
391  circle->SetFilled( false );
392  circle->SetFlags( IS_NEW );
393  startingPoint = NULLOPT;
394  }
395 
396  m_inDrawingTool = false;
397  return 0;
398 }
void SetShape(SHAPE_T aShape)
Definition: pcb_shape.h:109
#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:272
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:336
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
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 PCB_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 690 of file drawing_tool.cpp.

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

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), PNS::angle(), ARROW, AUTOMATIC, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), PCB_ACTIONS::decWidth, DIMENSION, PCB_ACTIONS::drawAlignedDimension, PCB_ACTIONS::drawCenterDimension, PCB_ACTIONS::drawLeader, PCB_ACTIONS::drawOrthogonalDimension, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), 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, 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 245 of file drawing_tool.cpp.

246 {
248  return 0;
249 
250  if( m_inDrawingTool )
251  return 0;
252  else
253  m_inDrawingTool = true;
254 
255  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
256  PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
257  BOARD_COMMIT commit( m_frame );
258  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
259  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
260 
261  line->SetShape( SHAPE_T::SEGMENT );
262  line->SetFlags( IS_NEW );
263 
264  if( aEvent.HasPosition() )
265  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
266 
267  std::string tool = aEvent.GetCommandStr().get();
268  m_frame->PushTool( tool );
269  Activate();
270 
271  while( drawSegment( tool, &line, startingPoint ) )
272  {
273  if( line )
274  {
275  if( m_isFootprintEditor )
276  static_cast<FP_SHAPE*>( line )->SetLocalCoord();
277 
278  commit.Add( line );
279  commit.Push( _( "Draw a line segment" ) );
280  startingPoint = VECTOR2D( line->GetEnd() );
281  }
282  else
283  {
284  startingPoint = NULLOPT;
285  }
286 
287  line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
288  line->SetShape( SHAPE_T::SEGMENT );
289  line->SetFlags( IS_NEW );
290  }
291 
292  m_inDrawingTool = false;
293  return 0;
294 }
void SetShape(SHAPE_T aShape)
Definition: pcb_shape.h:109
#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.
usual segment : line with rounded ends
bool m_inDrawingTool
Definition: drawing_tool.h:272
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:336
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
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 PCB_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 297 of file drawing_tool.cpp.

298 {
300  return 0;
301 
302  if( m_inDrawingTool )
303  return 0;
304  else
305  m_inDrawingTool = true;
306 
307  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
308  PCB_SHAPE* rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
309  BOARD_COMMIT commit( m_frame );
310  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
311  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
312 
313  rect->SetShape( SHAPE_T::RECT );
314  rect->SetFilled( false );
315  rect->SetFlags(IS_NEW );
316 
317  if( aEvent.HasPosition() )
318  startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
319 
320  std::string tool = aEvent.GetCommandStr().get();
321  m_frame->PushTool( tool );
322  Activate();
323 
324  while( drawSegment( tool, &rect, startingPoint ) )
325  {
326  if( rect )
327  {
328  if( m_isFootprintEditor )
329  static_cast<FP_SHAPE*>( rect )->SetLocalCoord();
330 
331  commit.Add( rect );
332  commit.Push( _( "Draw a rectangle" ) );
333 
335  }
336 
337  rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
338  rect->SetShape( SHAPE_T::RECT );
339  rect->SetFilled( false );
340  rect->SetFlags(IS_NEW );
341  startingPoint = NULLOPT;
342  }
343 
344  m_inDrawingTool = false;
345  return 0;
346 }
void SetShape(SHAPE_T aShape)
Definition: pcb_shape.h:109
#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:272
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
RAII class that sets an value at construction and resets it to the original value at destruction.
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
#define _(s)
bool DisableGridSnapping() const
Definition: tool_event.h:336
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
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
segment with non rounded ends
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 PCB_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 1403 of file drawing_tool.cpp.

1405 {
1406  SHAPE_T shape = ( *aGraphic )->GetShape();
1407 
1408  // Only three shapes are currently supported
1409  wxASSERT( shape == SHAPE_T::SEGMENT || shape == SHAPE_T::CIRCLE || shape == SHAPE_T::RECT );
1410 
1411  EDA_UNITS userUnits = m_frame->GetUserUnits();
1413  PCB_SHAPE*& graphic = *aGraphic;
1414  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1415 
1416  m_lineWidth = getSegmentWidth( drawingLayer );
1417 
1418  // geometric construction manager
1420 
1421  // drawing assistant overlay
1422  // TODO: workaround because PCB_SHAPE_TYPE_T is not visible from commons.
1423  KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
1424  KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, userUnits, geomShape );
1425 
1426  // Add a VIEW_GROUP that serves as a preview for the new item
1427  PCB_SELECTION preview;
1428  m_view->Add( &preview );
1429  m_view->Add( &twoPointAsst );
1430 
1431  m_controls->ShowCursor( true );
1432 
1433  bool started = false;
1434  bool cancelled = false;
1435  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
1436  VECTOR2I cursorPos = m_controls->GetMousePosition();
1437 
1438  auto setCursor =
1439  [&]()
1440  {
1442  };
1443 
1444  auto cleanup =
1445  [&]()
1446  {
1447  preview.Clear();
1448  m_view->Update( &preview );
1449  delete graphic;
1450  graphic = nullptr;
1451 
1452  if( !isLocalOriginSet )
1453  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1454  };
1455 
1456  // Prime the pump
1458 
1459  if( aStartingPoint )
1461 
1462  // Set initial cursor
1463  setCursor();
1464 
1465  // Main loop: keep receiving events
1466  while( TOOL_EVENT* evt = Wait() )
1467  {
1468  setCursor();
1469 
1470  if( started )
1471  m_frame->SetMsgPanel( graphic );
1472 
1473  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1474  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1475  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), drawingLayer );
1476  m_controls->ForceCursorPosition( true, cursorPos );
1477 
1478  // 45 degree angle constraint enabled with an option and toggled with Ctrl
1479  bool limit45 = frame()->Settings().m_Use45DegreeGraphicSegments;
1480 
1481  if( evt->Modifier( MD_SHIFT ) )
1482  limit45 = !limit45;
1483 
1484  if( evt->IsCancelInteractive() )
1485  {
1486  cleanup();
1487 
1488  if( !started )
1489  {
1490  // We've handled the cancel event. Don't cancel other tools
1491  evt->SetPassEvent( false );
1492  m_frame->PopTool( aTool );
1493  cancelled = true;
1494  }
1495 
1496  break;
1497  }
1498  else if( evt->IsActivate() )
1499  {
1500  if( evt->IsPointEditor() )
1501  {
1502  // don't exit (the point editor runs in the background)
1503  }
1504  else if( evt->IsMoveTool() )
1505  {
1506  cleanup();
1507  // leave ourselves on the stack so we come back after the move
1508  cancelled = true;
1509  break;
1510  }
1511  else
1512  {
1513  cleanup();
1514  m_frame->PopTool( aTool );
1515  cancelled = true;
1516  break;
1517  }
1518  }
1519  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1520  {
1521  drawingLayer = m_frame->GetActiveLayer();
1522  m_lineWidth = getSegmentWidth( drawingLayer );
1523 
1524  if( graphic )
1525  {
1526  if( !m_view->IsLayerVisible( drawingLayer ) )
1527  {
1528  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1529  m_frame->GetCanvas()->Refresh();
1530  }
1531 
1532  graphic->SetLayer( drawingLayer );
1533  graphic->SetWidth( m_lineWidth );
1534  m_view->Update( &preview );
1535  frame()->SetMsgPanel( graphic );
1536  }
1537  else
1538  {
1539  evt->SetPassEvent();
1540  }
1541  }
1542  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1543  {
1544  if( started )
1545  {
1546  frame()->OnEditItemRequest( graphic );
1547  m_view->Update( &preview );
1548  frame()->SetMsgPanel( graphic );
1549  break;
1550  }
1551  else
1552  {
1553  evt->SetPassEvent();
1554  }
1555  }
1556  else if( evt->IsClick( BUT_RIGHT ) )
1557  {
1559  }
1560  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1561  {
1562  if( !started )
1563  {
1565 
1566  if( aStartingPoint )
1567  {
1568  cursorPos = aStartingPoint.get();
1569  aStartingPoint = NULLOPT;
1570  }
1571 
1572  m_lineWidth = getSegmentWidth( drawingLayer );
1573 
1574  // Init the new item attributes
1575  graphic->SetShape( static_cast<SHAPE_T>( shape ) );
1576  graphic->SetFilled( false );
1577  graphic->SetWidth( m_lineWidth );
1578  graphic->SetLayer( drawingLayer );
1579  grid.SetSkipPoint( cursorPos );
1580 
1581  twoPointManager.SetOrigin( (wxPoint) cursorPos );
1582  twoPointManager.SetEnd( (wxPoint) cursorPos );
1583 
1584  if( !isLocalOriginSet )
1585  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1586 
1587  preview.Add( graphic );
1588  frame()->SetMsgPanel( graphic );
1589  m_controls->SetAutoPan( true );
1590  m_controls->CaptureCursor( true );
1591 
1592  if( !m_view->IsLayerVisible( drawingLayer ) )
1593  {
1594  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1595  m_frame->GetCanvas()->Refresh();
1596  }
1597 
1598  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1599 
1600  started = true;
1601  }
1602  else if( shape == SHAPE_T::CIRCLE )
1603  {
1604  // No clever logic if drawing a circle
1605  preview.Clear();
1606  twoPointManager.Reset();
1607  break;
1608  }
1609  else
1610  {
1611  PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
1612 
1613  if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
1614  || ( evt->IsDblClick( BUT_LEFT ) && shape == SHAPE_T::SEGMENT )
1615  || snapItem )
1616  // User has clicked twice in the same spot
1617  // or clicked on the end of an existing segment (closing a path)
1618  {
1619  BOARD_COMMIT commit( m_frame );
1620 
1621  // If the user clicks on an existing snap point from a drawsegment
1622  // we finish the segment as they are likely closing a path
1623  if( snapItem
1624  && ( shape == SHAPE_T::RECT || graphic->GetLength() > 0.0 ) )
1625  {
1626  commit.Add( graphic );
1627  commit.Push( _( "Draw a line segment" ) );
1628  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, graphic );
1629  }
1630  else
1631  {
1632  delete graphic;
1633  }
1634 
1635  graphic = nullptr;
1636  }
1637 
1638  preview.Clear();
1639  twoPointManager.Reset();
1640  break;
1641  }
1642 
1643  twoPointManager.SetEnd( cursorPos );
1644  }
1645  else if( evt->IsMotion() )
1646  {
1647  // 45 degree lines
1648  if( started
1649  && ( ( limit45 && shape == SHAPE_T::SEGMENT )
1650  || ( evt->Modifier( MD_SHIFT ) && shape == SHAPE_T::RECT ) ) )
1651  {
1652  const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
1653 
1654  // get a restricted 45/H/V line from the last fixed point to the cursor
1655  auto newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECT ) );
1656  m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
1657  twoPointManager.SetEnd( twoPointManager.GetOrigin() + (wxPoint) newEnd );
1658  twoPointManager.SetAngleSnap( true );
1659  }
1660  else
1661  {
1662  twoPointManager.SetEnd( (wxPoint) cursorPos );
1663  twoPointManager.SetAngleSnap( false );
1664  }
1665 
1666  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1667  m_view->Update( &preview );
1668  m_view->Update( &twoPointAsst );
1669  }
1670  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1671  {
1673  graphic->SetWidth( m_lineWidth );
1674  m_view->Update( &preview );
1675  frame()->SetMsgPanel( graphic );
1676  }
1677  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1678  {
1680  graphic->SetWidth( m_lineWidth );
1681  m_view->Update( &preview );
1682  frame()->SetMsgPanel( graphic );
1683  }
1684  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1685  {
1686  isLocalOriginSet = true;
1687  evt->SetPassEvent();
1688  }
1689  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1690  {
1691  if( frame()->GetUserUnits() != userUnits )
1692  {
1693  userUnits = frame()->GetUserUnits();
1694  twoPointAsst.SetUnits( userUnits );
1695  m_view->Update( &twoPointAsst );
1696  }
1697  evt->SetPassEvent();
1698  }
1699  else
1700  {
1701  evt->SetPassEvent();
1702  }
1703  }
1704 
1705  if( !isLocalOriginSet ) // reset the relative coordinate if it was not set before
1706  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1707 
1708  m_view->Remove( &twoPointAsst );
1709  m_view->Remove( &preview );
1710  m_frame->SetMsgPanel( board() );
1711 
1713  m_controls->SetAutoPan( false );
1714  m_controls->CaptureCursor( false );
1715  m_controls->ForceCursorPosition( false );
1716 
1717  return !cancelled;
1718 }
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:82
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:170
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:31
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:275
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:351
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
usual segment : line with rounded ends
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void Reset()
Reset the manager to the initial state.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
APPEARANCE_CONTROLS * GetAppearancePanel()
static void updateSegmentFromGeometryMgr(const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER &aMgr, PCB_SHAPE *aGraphic)
Update a PCB_SHAPE from the current state of a #TWO_POINT_GEOMETRY_MANAGER.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:173
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
SHAPE_T
The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member.
Definition: board_item.h:46
bool m_Use45DegreeGraphicSegments
PCB_LAYER_ID
A quick note on layer IDs:
const PCB_SELECTION & selection() const
const auto NULLOPT
Definition: optional.h:9
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void PopTool(const std::string &actionName)
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:274
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:268
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:270
EDA_UNITS
Definition: eda_units.h:38
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:292
static TOOL_ACTION updateUnits
Definition: actions.h:147
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...
PCBNEW_SETTINGS & Settings()
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:321
segment with non rounded ends
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:1503
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:404

References _, SELECTION::Add(), COMMIT::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, KIGFX::VIEW::IsLayerVisible(), PCB_ACTIONS::layerChanged, m_controls, m_frame, m_lineWidth, BASE_SCREEN::m_LocalOrigin, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, PCBNEW_SETTINGS::m_Use45DegreeGraphicSegments, m_view, MD_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(), PCB_BASE_FRAME::Settings(), KIGFX::PREVIEW::TWO_POINT_ASSISTANT::SetUnits(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), KIGFX::VIEW::Update(), updateSegmentFromGeometryMgr(), ACTIONS::updateUnits, TOOL_INTERACTIVE::Wait(), and WIDTH_STEP.

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

◆ DrawSpecificationStackup()

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

Function DrawSpecificationStackup()

Definition at line 211 of file drawing_stackup_table_tool.cpp.

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

References _, COMMIT::Add(), BOARD_ITEM::Duplicate(), Eco1_User, PCB_BASE_FRAME::GetBoard(), BOARD_STACKUP::GetCount(), PCB_BASE_FRAME::GetDesignSettings(), BOARD::GetLayerName(), BOARD_STACKUP::GetList(), PCB_BASE_FRAME::GetModel(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), EDA_BASE_FRAME::GetUserUnits(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, INCHES, initTextTable(), m_frame, Millimeter2iu(), MILLIMETRES, BOARD_COMMIT::Push(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetText(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetVertJustify(), StringFromValue(), BOARD_STACKUP::SynchronizeWithBoard(), and UNSCALED.

Referenced by PlaceStackup().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 2278 of file drawing_tool.cpp.

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

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

Referenced by setTransitions().

◆ DrawZone()

int DRAWING_TOOL::DrawZone ( const TOOL_EVENT aEvent)

Start interactively drawing a zone.

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

The event parameter indicates which type of zone to draw:

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

Definition at line 2023 of file drawing_tool.cpp.

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

References _, TOOL_INTERACTIVE::Activate(), POLYGON_GEOM_MANAGER::AddPoint(), ARROW, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_ACTIONS::closeOutline, PCB_TOOL_BASE::controls(), POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), PCB_ACTIONS::deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawRuleArea, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), ZONE::GetHV45(), ZONE::GetLayer(), POLYGON_GEOM_MANAGER::GetLeaderMode(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), getSourceZoneForAction(), TOOL_BASE::getView(), ZONE_CREATE_HELPER::GetZone(), GRAPHIC_POLYGON, grid, TOOL_EVENT::HasPosition(), 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 154 of file pcb_tool_base.h.

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

Referenced by PCB_POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_CONTROL::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), ROUTER_TOOL::DpDimensionsDialog(), EDIT_TOOL::DragArcTrack(), drawArc(), DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), drawSegment(), DrawVia(), DrawZone(), PAD_TOOL::EditPad(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::HighlightItem(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), BOARD_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_TOOL::Init(), SCRIPTING_TOOL::Init(), PCB_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), InteractivePlaceWithPreview(), PCB_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(), PCB_POINT_EDITOR::removeCorner(), PCB_SELECTION_TOOL::RequestSelection(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), PCB_POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), 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 239 of file drawing_tool.cpp.

240 {
241  return m_mode;
242 }

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

2683 {
2684  assert( m_board );
2685  return m_board->GetDesignSettings().GetLineThickness( aLayer );
2686 }
BOARD * m_board
Definition: drawing_tool.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:588
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 1989 of file drawing_tool.cpp.

1990 {
1991  bool clearSelection = false;
1992  *aZone = nullptr;
1993 
1994  // not an action that needs a source zone
1995  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1996  return true;
1997 
1999  const PCB_SELECTION& selection = selTool->GetSelection();
2000 
2001  if( selection.Empty() )
2002  {
2003  clearSelection = true;
2005  }
2006 
2007  // we want a single zone
2008  if( selection.Size() == 1 )
2009  *aZone = dyn_cast<ZONE*>( selection[0] );
2010 
2011  // expected a zone, but didn't get one
2012  if( !*aZone )
2013  {
2014  if( clearSelection )
2016 
2017  return false;
2018  }
2019 
2020  return true;
2021 }
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:97
int Size() const
Returns the number of selected parts.
Definition: selection.h:103
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(), 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(), 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(), ROUTER_TOOL::getStartLayer(), PCB_CONTROL::GridResetOrigin(), PCB_CONTROL::GridSetOrigin(), ROUTER_TOOL::handleCommonEvents(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), PCB_SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), BOARD_INSPECTION_TOOL::highlightNet(), PCB_SELECTION_TOOL::hitTestDistance(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), PL_EDIT_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), PL_EDIT_TOOL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), ROUTER_TOOL::performRouting(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PL_DRAWING_TOOLS::PlaceItem(), BOARD_EDITOR_CONTROL::PlaceTarget(), ROUTER_TOOL::prepareInteractive(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), BOARD_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), Reset(), EE_SELECTION_TOOL::Reset(), PCB_SELECTION_TOOL::Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::SelectAll(), EE_SELECTION_TOOL::SelectAll(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), SCH_DRAWING_TOOLS::TwoClickPlace(), PL_SELECTION_TOOL::unhighlight(), EE_SELECTION_TOOL::unhighlight(), PCB_SELECTION_TOOL::unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PL_POINT_EDITOR::updateItem(), PCB_POINT_EDITOR::updateItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), PCB_SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCB_VIEWER_TOOLS::view(), PCB_TOOL_BASE::view(), PCB_SELECTION_TOOL::zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and PCB_SELECTION_TOOL::~PCB_SELECTION_TOOL().

◆ getViewControls()

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

Return the instance of VIEW_CONTROLS object used in the application.

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

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

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

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

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

130 {
131  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
132 
133  goInternal( sptr, aConditions );
134 }
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(), ROUTER_TOOL::setTransitions(), PCB_PICKER_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), SYMBOL_EDITOR_PIN_TOOL::setTransitions(), SYMBOL_EDITOR_MOVE_TOOL::setTransitions(), SCRIPTING_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), COMMON_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), PAD_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), FOOTPRINT_EDITOR_CONTROL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), PCB_CONTROL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), DRC_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), PICKER_TOOL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), PCB_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ Init()

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

172 {
173  auto activeToolFunctor = [this]( const SELECTION& aSel )
174  {
175  return m_mode != MODE::NONE;
176  };
177 
178  // some interactive drawing tools can undo the last point
179  auto canUndoPoint = [this]( const SELECTION& aSel )
180  {
181  return ( m_mode == MODE::ARC
182  || m_mode == MODE::ZONE
183  || m_mode == MODE::KEEPOUT
185  };
186 
187  // functor for tools that can automatically close the outline
188  auto canCloseOutline = [this]( const SELECTION& aSel )
189  {
190  return ( m_mode == MODE::ZONE
191  || m_mode == MODE::KEEPOUT
193  };
194 
195  auto viaToolActive = [this]( const SELECTION& aSel )
196  {
197  return m_mode == MODE::VIA;
198  };
199 
200  auto& ctxMenu = m_menu.GetMenu();
201 
202  // cancel current tool goes in main context menu at the top if present
203  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
204  ctxMenu.AddSeparator( 1 );
205 
206  // tool-specific actions
207  ctxMenu.AddItem( PCB_ACTIONS::closeOutline, canCloseOutline, 200 );
208  ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
209 
210  ctxMenu.AddSeparator( 500 );
211 
212  std::shared_ptr<VIA_SIZE_MENU> viaSizeMenu = std::make_shared<VIA_SIZE_MENU>();
213  viaSizeMenu->SetTool( this );
214  m_menu.AddSubMenu( viaSizeMenu );
215  ctxMenu.AddMenu( viaSizeMenu.get(), viaToolActive, 500 );
216 
217  ctxMenu.AddSeparator( 500 );
218 
219  // Type-specific sub-menus will be added for us by other tools
220  // For example, zone fill/unfill is provided by the PCB control tool
221 
222  // Finally, add the standard zoom/grid items
223  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
224 
225  return true;
226 }
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:163
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 closeOutline
Definition: pcb_actions.h:164

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

◆ 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 523 of file drawing_stackup_table_tool.cpp.

527 {
529  return -1;
530 
531  bool cancelled = false;
532 
533  BOARD_COMMIT commit( m_frame );
534 
536  m_controls->ShowCursor( true );
537 
538  // do not capture or auto-pan until we start placing the table
539  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
540 
541  std::string tool = aEvent.GetCommandStr().get();
542  m_frame->PushTool( tool );
543  Activate();
544 
545  // Prime the pump
546  if( aEvent.