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

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

◆ MODE

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

Definition at line 63 of file drawing_tool.h.

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

◆ 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 78 of file tool_base.h.

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

Constructor & Destructor Documentation

◆ DRAWING_TOOL()

DRAWING_TOOL::DRAWING_TOOL ( )

Definition at line 151 of file drawing_tool.cpp.

151  :
152  PCB_TOOL_BASE( "pcbnew.InteractiveDrawing" ),
153  m_view( nullptr ),
154  m_controls( nullptr ),
155  m_board( nullptr ),
156  m_frame( nullptr ),
157  m_mode( MODE::NONE ),
158  m_lineWidth( 1 )
159 {
160 }
BOARD * m_board
Definition: drawing_tool.h:269
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
unsigned int m_lineWidth
Definition: drawing_tool.h:273
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:78

◆ ~DRAWING_TOOL()

DRAWING_TOOL::~DRAWING_TOOL ( )

Definition at line 163 of file drawing_tool.cpp.

164 {
165 }

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:215
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:210
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(), BOARD_INSPECTION_TOOL::HighlightNetTool(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), InteractivePlaceWithPreview(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), 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(), 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:215

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 160 of file pcb_tool_base.h.

160 { return getModel<BOARD>(); }

Referenced by 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(), 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(), 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 ( 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 644 of file drawing_tool.cpp.

645 {
646  const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() };
647 
648  aDim->SetEnd( wxPoint( VECTOR2I( aDim->GetStart() ) + GetVectorSnapped45( lineVector ) ) );
649  aDim->Update();
650 }
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition: dimension.h:121
void Update()
Updates the dimension's cached text and geometry.
Definition: dimension.h:146
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
virtual void SetEnd(const wxPoint &aPoint)
Definition: dimension.h:125
virtual const wxPoint & GetEnd() const
Definition: dimension.h:124

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

Referenced by DrawDimension().

◆ controls()

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

Definition at line 290 of file pcb_tool_base.cpp.

291 {
292  return frame()->GetDisplayOptions();
293 }
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  cleanup();
125  else
126  {
127  frame()->PopTool( aTool );
128  break;
129  }
130  }
131  else if( evt->IsActivate() )
132  {
133  if( newItem )
134  cleanup();
135 
136  if( evt->IsPointEditor() )
137  {
138  // don't exit (the point editor runs in the background)
139  }
140  else if( evt->IsMoveTool() )
141  {
142  // leave ourselves on the stack so we come back after the move
143  break;
144  }
145  else
146  {
147  frame()->PopTool( aTool );
148  break;
149  }
150  }
151  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
152  {
153  if( !newItem )
154  {
155  // create the item if possible
156  makeNewItem( cursorPos );
157 
158  // no item created, so wait for another click
159  if( !newItem )
160  continue;
161 
162  controls()->CaptureCursor( true );
163  controls()->SetAutoPan( true );
164  }
165  else
166  {
167  auto oldFlags = newItem->GetFlags();
168  newItem->ClearFlags();
169 
170  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
171  {
172  newItem->SetFlags( oldFlags );
173  continue;
174  }
175 
176  preview.Clear();
177  newItem.release();
178  commit.Push( aCommitMessage );
179 
180  controls()->CaptureCursor( false );
181  controls()->SetAutoPan( false );
182  controls()->ShowCursor( true );
183 
184  if( !( aOptions & IPO_REPEAT ) )
185  break;
186 
187  if( aOptions & IPO_SINGLE_CLICK )
188  makeNewItem( controls()->GetCursorPosition() );
189 
190  setCursor();
191  }
192  }
193  else if( evt->IsClick( BUT_RIGHT ) )
194  {
196  }
197  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
198  {
200  }
201  else if( newItem && evt->Category() == TC_COMMAND )
202  {
203  /*
204  * Handle any events that can affect the item as we move it around
205  */
206  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
207  {
208  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
209  newItem->Rotate( newItem->GetPosition(), rotationAngle );
210  view()->Update( &preview );
211  }
212  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
213  {
214  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
215  view()->Update( &preview );
216  }
217  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
218  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
219  {
220  // Refresh preview after event runs
222  }
223  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
224  {
225  frame()->OnEditItemRequest( newItem.get() );
226 
227  // Notify other tools of the changes
229  }
230  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
231  {
232  preview.Clear();
233  newItem.release();
234 
235  makeNewItem( (wxPoint) cursorPos );
236  aPlacer->SnapItem( newItem.get() );
237  view()->Update( &preview );
238  }
239  else
240  {
241  evt->SetPassEvent();
242  }
243  }
244  else if( newItem && evt->IsMotion() )
245  {
246  // track the cursor
247  newItem->SetPosition( (wxPoint) cursorPos );
248  aPlacer->SnapItem( newItem.get() );
249 
250  // Show a preview of the item
251  view()->Update( &preview );
252  }
253  else
254  {
255  evt->SetPassEvent();
256  }
257  }
258 
259  view()->Remove( &preview );
261 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
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:96
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
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:302
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:215
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:121
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:305
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:206
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:77
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:144
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:173
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:109
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:1175
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:65
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:303
static TOOL_ACTION refreshPreview
Definition: actions.h:109
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 380 of file drawing_tool.cpp.

381 {
383  return 0;
384 
385  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
386  PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
387  BOARD_COMMIT commit( m_frame );
388  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
389  bool immediateMode = aEvent.HasPosition();
390 
391  arc->SetShape( S_ARC );
392  arc->SetFlags( IS_NEW );
393 
394  std::string tool = aEvent.GetCommandStr().get();
395  m_frame->PushTool( tool );
396  Activate();
397 
398  while( drawArc( tool, &arc, immediateMode ) )
399  {
400  if( arc )
401  {
402  if( m_isFootprintEditor )
403  static_cast<FP_SHAPE*>( arc )->SetLocalCoord();
404 
405  commit.Add( arc );
406  commit.Push( _( "Draw an arc" ) );
407 
409  }
410 
411  arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
412  arc->SetShape( S_ARC );
413  arc->SetFlags( IS_NEW );
414  immediateMode = false;
415  }
416 
417  return 0;
418 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
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:141
Arcs (with rounded ends)
Definition: board_item.h:52
RAII class that sets an value at construction and resets it to the original value at destruction.
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
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:471
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:261
#define IS_NEW
New item, just created.
Definition: eda_item.h:107

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

Referenced by setTransitions().

◆ drawArc()

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

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

1673 {
1674  PCB_SHAPE*& graphic = *aGraphic;
1675  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1676 
1677  m_lineWidth = getSegmentWidth( drawingLayer );
1678 
1679  // Arc geometric construction manager
1681 
1682  // Arc drawing assistant overlay
1683  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1684 
1685  // Add a VIEW_GROUP that serves as a preview for the new item
1686  PCB_SELECTION preview;
1687  m_view->Add( &preview );
1688  m_view->Add( &arcAsst );
1690 
1691  m_controls->ShowCursor( true );
1692 
1693  bool firstPoint = false;
1694  bool cancelled = false;
1695 
1696  // Set initial cursor
1697  auto setCursor =
1698  [&]()
1699  {
1701  };
1702 
1703  auto cleanup =
1704  [&] ()
1705  {
1706  preview.Clear();
1707  delete *aGraphic;
1708  *aGraphic = nullptr;
1709  };
1710 
1711  // Prime the pump
1713 
1714  if( aImmediateMode )
1716 
1717  setCursor();
1718 
1719  // Main loop: keep receiving events
1720  while( TOOL_EVENT* evt = Wait() )
1721  {
1722  if( firstPoint )
1723  m_frame->SetMsgPanel( graphic );
1724 
1725  setCursor();
1726 
1727  graphic->SetLayer( drawingLayer );
1728 
1729  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1730  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
1731  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
1732  m_controls->ForceCursorPosition( true, cursorPos );
1733 
1734  if( evt->IsCancelInteractive() )
1735  {
1736  cleanup();
1737 
1738  if( !firstPoint )
1739  {
1740  m_frame->PopTool( aTool );
1741  cancelled = true;
1742  }
1743 
1744  break;
1745  }
1746  else if( evt->IsActivate() )
1747  {
1748  if( evt->IsPointEditor() )
1749  {
1750  // don't exit (the point editor runs in the background)
1751  }
1752  else if( evt->IsMoveTool() )
1753  {
1754  cleanup();
1755  // leave ourselves on the stack so we come back after the move
1756  cancelled = true;
1757  break;
1758  }
1759  else
1760  {
1761  cleanup();
1762  m_frame->PopTool( aTool );
1763  cancelled = true;
1764  break;
1765  }
1766  }
1767  else if( evt->IsClick( BUT_LEFT ) )
1768  {
1769  if( !firstPoint )
1770  {
1772 
1773  m_controls->SetAutoPan( true );
1774  m_controls->CaptureCursor( true );
1775 
1776  drawingLayer = m_frame->GetActiveLayer();
1777  m_lineWidth = getSegmentWidth( drawingLayer );
1778 
1779  // Init the new item attributes
1780  // (non-geometric, those are handled by the manager)
1781  graphic->SetShape( S_ARC );
1782  graphic->SetWidth( m_lineWidth );
1783 
1784  if( !m_view->IsLayerVisible( drawingLayer ) )
1785  {
1786  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1787  m_frame->GetCanvas()->Refresh();
1788  }
1789 
1790  preview.Add( graphic );
1791  frame()->SetMsgPanel( graphic );
1792  firstPoint = true;
1793  }
1794 
1795  arcManager.AddPoint( cursorPos, true );
1796  }
1797  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
1798  {
1799  arcManager.RemoveLastPoint();
1800  }
1801  else if( evt->IsMotion() )
1802  {
1803  // set angle snap
1804  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1805 
1806  // update, but don't step the manager state
1807  arcManager.AddPoint( cursorPos, false );
1808  }
1809  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1810  {
1811  drawingLayer = m_frame->GetActiveLayer();
1812  m_lineWidth = getSegmentWidth( drawingLayer );
1813 
1814  if( graphic )
1815  {
1816  if( !m_view->IsLayerVisible( drawingLayer ) )
1817  {
1818  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1819  m_frame->GetCanvas()->Refresh();
1820  }
1821 
1822  graphic->SetLayer( drawingLayer );
1823  graphic->SetWidth( m_lineWidth );
1824  m_view->Update( &preview );
1825  frame()->SetMsgPanel( graphic );
1826  }
1827  else
1828  {
1829  evt->SetPassEvent();
1830  }
1831  }
1832  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1833  {
1835  {
1836  graphic->SetAngle( 900, true );
1837  frame()->OnEditItemRequest( graphic );
1838  m_view->Update( &preview );
1839  frame()->SetMsgPanel( graphic );
1840  break;
1841  }
1842  else if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
1843  {
1844  frame()->OnEditItemRequest( graphic );
1845  m_view->Update( &preview );
1846  frame()->SetMsgPanel( graphic );
1847  break;
1848  }
1849  else
1850  {
1851  evt->SetPassEvent();
1852  }
1853  }
1854  else if( evt->IsClick( BUT_RIGHT ) )
1855  {
1857  }
1858  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1859  {
1861  graphic->SetWidth( m_lineWidth );
1862  m_view->Update( &preview );
1863  frame()->SetMsgPanel( graphic );
1864  }
1865  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1866  {
1868  graphic->SetWidth( m_lineWidth );
1869  m_view->Update( &preview );
1870  frame()->SetMsgPanel( graphic );
1871  }
1872  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1873  {
1874  arcManager.ToggleClockwise();
1875  }
1876  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1877  {
1878  arcAsst.SetUnits( frame()->GetUserUnits() );
1879  m_view->Update( &arcAsst );
1880  evt->SetPassEvent();
1881  }
1882  else
1883  {
1884  evt->SetPassEvent();
1885  }
1886 
1887  if( arcManager.IsComplete() )
1888  {
1889  break;
1890  }
1891  else if( arcManager.HasGeometryChanged() )
1892  {
1893  updateArcFromConstructionMgr( arcManager, *graphic );
1894  m_view->Update( &preview );
1895  m_view->Update( &arcAsst );
1896 
1897  if( firstPoint )
1898  frame()->SetMsgPanel( graphic );
1899  else
1900  frame()->SetMsgPanel( board() );
1901  }
1902  }
1903 
1904  preview.Remove( graphic );
1905  m_view->Remove( &arcAsst );
1906  m_view->Remove( &preview );
1907  m_frame->SetMsgPanel( board() );
1908 
1910  m_controls->SetAutoPan( false );
1911  m_controls->CaptureCursor( false );
1912  m_controls->ForceCursorPosition( false );
1913 
1914  return !cancelled;
1915 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
Manage the construction of a circular arc though sequential setting of critical points: center,...
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:174
int GetUserUnits()
Returns 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:194
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, PCB_SHAPE &aArc)
Update an arc PCB_SHAPE from the current state of an Arc Geometry Manager.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:274
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
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:352
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
Arcs (with rounded ends)
Definition: board_item.h:52
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:177
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 SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
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:173
unsigned int m_lineWidth
Definition: drawing_tool.h:273
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:180
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:295
static TOOL_ACTION updateUnits
Definition: actions.h:150
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)
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
Represents an assistant draw when interactively drawing an arc on a canvas.
Definition: arc_assistant.h:38
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:167
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:322
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: pcb_shape.cpp:466
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:109
static TOOL_ACTION cursorClick
Definition: actions.h:126
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(), 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_ALT, MD_CTRL, 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(), S_ARC, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE, KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_START, PCB_SHAPE::SetAngle(), KIGFX::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 338 of file drawing_stackup_table_tool.cpp.

340 {
341  BOARD_COMMIT commit( m_frame );
342  std::vector<BOARD_ITEM*> objects;
344  BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
345 
346  wxPoint cursorPos = aOrigin;
347 
348  // Style : Section header
349  PCB_TEXT* headStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
350  headStyle->SetLayer( Eco1_User );
351  headStyle->SetTextSize( wxSize( Millimeter2iu( 2.0 ), Millimeter2iu( 2.0 ) ) );
352  headStyle->SetTextThickness( Millimeter2iu( 0.4 ) );
353  headStyle->SetItalic( false );
354  headStyle->SetTextPos( wxPoint( 0, 0 ) );
356  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
357 
358  // Style : Data
359  PCB_TEXT* dataStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
360  dataStyle->SetLayer( Eco1_User );
361  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
362  dataStyle->SetTextThickness( Millimeter2iu( 0.2 ) );
363  dataStyle->SetItalic( false );
364  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
366  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
367 
368  PCB_TEXT* t;
369 
370  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
371  t->SetText( _( "BOARD CHARACTERISTICS" ) );
372  t->SetPosition( cursorPos );
373  objects.push_back( t );
374 
375  cursorPos.y = cursorPos.y + t->GetBoundingBox().GetHeight()
377 
378  std::vector<std::vector<PCB_TEXT*>> texts;
379  std::vector<PCB_TEXT*> colLabel1;
380  std::vector<PCB_TEXT*> colData1;
381  std::vector<PCB_TEXT*> colbreak;
382  std::vector<PCB_TEXT*> colLabel2;
383  std::vector<PCB_TEXT*> colData2;
384  wxString text = wxString( "" );
385 
386  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
387  t->SetText( _( "Copper Layer Count: " ) );
388  colLabel1.push_back( t );
389 
390  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
392  colData1.push_back( t );
393 
394  EDA_RECT size = m_frame->GetBoard()->ComputeBoundingBox( true );
395  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
396  t->SetText( _( "Board overall dimensions: " ) );
397  colLabel1.push_back( t );
398 
399  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
400  t->SetText( wxString::Format( "%s x %s",
402  MessageTextFromValue( m_frame->GetUserUnits(), size.GetHeight(), true ) ) );
403  colData1.push_back( t );
404 
405  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
406  t->SetText( _( "Min track/spacing: " ) );
407  colLabel1.push_back( t );
408 
409  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
410  t->SetText( wxString::Format( "%s / %s",
412  MessageTextFromValue( m_frame->GetUserUnits(), settings.m_MinClearance, true ) ) );
413  colData1.push_back( t );
414 
415  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
416  t->SetText( _( "Copper Finish: " ) );
417  colLabel1.push_back( t );
418 
419  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
420  t->SetText( stackup.m_FinishType );
421  colData1.push_back( t );
422 
423  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
424  t->SetText( _( "Castellated pads: " ) );
425  colLabel1.push_back( t );
426 
427  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
428  t->SetText( stackup.m_CastellatedPads ? _( "Yes" ) : _( "No" ) );
429  colData1.push_back( t );
430 
431  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
432  t->SetText( _( "Board Thickness: " ) );
433  colLabel2.push_back( t );
434 
435  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
437 
438  t->SetText( text );
439  colData2.push_back( t );
440 
441  // some empty cells
442  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
443  colLabel2.push_back( t );
444  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
445  colData2.push_back( t );
446 
447  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
448  t->SetText( _( "Min hole diameter: " ) );
449  colLabel2.push_back( t );
450  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
451 
452  double holeSize = std::min( settings.m_MinThroughDrill, settings.m_ViasMinSize );
453  text = MessageTextFromValue( m_frame->GetUserUnits(), holeSize, true );
454  t->SetText( text );
455  colData2.push_back( t );
456 
457  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
458  t->SetText( _( "Impedance Control: " ) );
459  colLabel2.push_back( t );
460 
461  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
462  t->SetText( stackup.m_CastellatedPads ? _( "Yes" ) : _( "No" ) );
463  colData2.push_back( t );
464 
465  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
466  t->SetText( _( "Plated Board Edge: " ) );
467  colLabel2.push_back( t );
468  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
469  t->SetText( stackup.m_HasDielectricConstrains ? _( "Yes" ) : _( "No" ) );
470  colData2.push_back( t );
471 
472  texts.push_back( colLabel1 );
473  texts.push_back( colData1 );
474  texts.push_back( colbreak );
475  texts.push_back( colLabel2 );
476  texts.push_back( colData2 );
477  wxPoint tableSize2 = wxPoint();
478 
479  std::vector<BOARD_ITEM*> table = initTextTable( texts, cursorPos, Eco1_User, &tableSize2,
480  false );
481 
482  for( auto item : table )
483  objects.push_back( item );
484 
485  if( aDrawNow )
486  {
487  for( auto item : objects )
488  commit.Add( item );
489 
490  commit.Push( "Board Characteristics" );
491  }
492 
493  tableSize->x = tableSize2.x;
494  tableSize->y = cursorPos.y + tableSize2.y + From_User_Unit( EDA_UNITS::MILLIMETRES, 2.0 );
495 
496  return objects;
497 }
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:125
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:77
this class manage the layers needed to make a physical board they are solder mask,...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
wxString m_FinishType
The name of external copper finish.
void SetItalic(bool isItalic)
Definition: eda_text.h:186
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
int GetWidth() const
Definition: eda_rect.h:114
bool m_CastellatedPads
True if castellated pads exist.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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 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:121
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
int GetHeight() const
Definition: eda_rect.h:115
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:208
#define _(s)
Definition: 3d_actions.cpp:33
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:1029
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:225
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:202
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:130
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:303
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 334 of file drawing_tool.cpp.

335 {
337  return 0;
338 
339  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
340  PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
341  BOARD_COMMIT commit( m_frame );
342  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
343  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
344 
345  circle->SetShape( S_CIRCLE );
346  circle->SetFilled( false );
347  circle->SetFlags( IS_NEW );
348 
349  if( aEvent.HasPosition() )
350  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
351 
352  std::string tool = aEvent.GetCommandStr().get();
353  m_frame->PushTool( tool );
354  Activate();
355 
356  while( drawSegment( tool, &circle, startingPoint ) )
357  {
358  if( circle )
359  {
360  if( m_isFootprintEditor )
361  static_cast<FP_SHAPE*>( circle )->SetLocalCoord();
362 
363  commit.Add( circle );
364  commit.Push( _( "Draw a circle" ) );
365 
366  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle );
367  }
368 
369  circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
370  circle->SetShape( S_CIRCLE );
371  circle->SetFilled( false );
372  circle->SetFlags( IS_NEW );
373  startingPoint = NULLOPT;
374  }
375 
376  return 0;
377 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
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:141
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
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:352
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:471
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
boost::optional< T > OPT
Definition: optional.h:7
ring
Definition: board_item.h:53
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:261
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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

Referenced by setTransitions().

◆ DrawDimension()

int DRAWING_TOOL::DrawDimension ( const TOOL_EVENT aEvent)

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

654 {
656  return 0;
657 
658  enum DIMENSION_STEPS
659  {
660  SET_ORIGIN = 0,
661  SET_END,
662  SET_HEIGHT,
663  FINISHED
664  };
665 
666  TOOL_EVENT originalEvent = aEvent;
667  DIMENSION_BASE* dimension = nullptr;
668  BOARD_COMMIT commit( m_frame );
670  BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
671  PCB_SELECTION preview; // A VIEW_GROUP that serves as a preview for the new item(s)
672  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
673  int step = SET_ORIGIN;
674 
675  m_view->Add( &preview );
676 
677  auto cleanup =
678  [&]()
679  {
680  m_controls->SetAutoPan( false );
681  m_controls->CaptureCursor( false );
682 
683  preview.Clear();
684  m_view->Update( &preview );
685 
686  delete dimension;
687  dimension = nullptr;
688  step = SET_ORIGIN;
689  };
690 
691  auto setCursor =
692  [&]()
693  {
695  };
696 
698  m_controls->ShowCursor( true );
699 
700  std::string tool = aEvent.GetCommandStr().get();
701  m_frame->PushTool( tool );
702  Activate();
703 
704  // Prime the pump
706 
707  if( aEvent.HasPosition() )
708  m_toolMgr->PrimeTool( aEvent.Position() );
709 
710  // Set initial cursor
711  setCursor();
712 
713  // Main loop: keep receiving events
714  while( TOOL_EVENT* evt = Wait() )
715  {
716  if( step > SET_ORIGIN )
717  frame()->SetMsgPanel( dimension );
718 
719  setCursor();
720 
721  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
722  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
723 
724  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
725 
726  cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
727  m_controls->ForceCursorPosition( true, cursorPos );
728 
729  if( evt->IsCancelInteractive() )
730  {
731  m_controls->SetAutoPan( false );
732 
733  if( step != SET_ORIGIN ) // start from the beginning
734  {
735  cleanup();
736  }
737  else
738  {
739  m_frame->PopTool( tool );
740  break;
741  }
742  }
743  else if( evt->IsActivate() )
744  {
745  if( step != SET_ORIGIN )
746  cleanup();
747 
748  if( evt->IsPointEditor() )
749  {
750  // don't exit (the point editor runs in the background)
751  }
752  else if( evt->IsMoveTool() )
753  {
754  // leave ourselves on the stack so we come back after the move
755  break;
756  }
757  else
758  {
759  m_frame->PopTool( tool );
760  break;
761  }
762  }
763  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
764  {
766  dimension->SetLineThickness( m_lineWidth );
767  m_view->Update( &preview );
768  frame()->SetMsgPanel( dimension );
769  }
770  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
771  {
772  if( m_lineWidth > WIDTH_STEP )
773  {
775  dimension->SetLineThickness( m_lineWidth );
776  m_view->Update( &preview );
777  frame()->SetMsgPanel( dimension );
778  }
779  }
780  else if( evt->IsClick( BUT_RIGHT ) )
781  {
783  }
784  else if( evt->IsClick( BUT_LEFT ) )
785  {
786  switch( step )
787  {
788  case SET_ORIGIN:
789  {
791 
793 
794  // Init the new item attributes
795  auto setMeasurementAttributes =
796  [&]( DIMENSION_BASE* aDim )
797  {
798  aDim->SetUnitsMode( boardSettings.m_DimensionUnitsMode );
799  aDim->SetUnitsFormat( boardSettings.m_DimensionUnitsFormat );
800  aDim->SetPrecision( boardSettings.m_DimensionPrecision );
801  aDim->SetSuppressZeroes( boardSettings.m_DimensionSuppressZeroes );
802  aDim->SetTextPositionMode( boardSettings.m_DimensionTextPosition );
803  aDim->SetKeepTextAligned( boardSettings.m_DimensionKeepTextAligned );
804 
805  if( boardSettings.m_DimensionUnitsMode == DIM_UNITS_MODE::AUTOMATIC )
806  aDim->SetUnits( m_frame->GetUserUnits() );
807  };
808 
809  if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) )
810  {
811  dimension = new ALIGNED_DIMENSION( m_board );
812  setMeasurementAttributes( dimension );
813  }
814  else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) )
815  {
816  dimension = new ORTHOGONAL_DIMENSION( m_board );
817  setMeasurementAttributes( dimension );
818  }
819  else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) )
820  {
821  dimension = new CENTER_DIMENSION( m_board );
822  }
823  else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) )
824  {
825  dimension = new LEADER( m_board );
826  dimension->Text().SetPosition( wxPoint( cursorPos ) );
827  }
828  else
829  {
830  wxFAIL_MSG( "Unhandled action in DRAWING_TOOL::DrawDimension" );
831  }
832 
833  dimension->SetLayer( layer );
834  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
835  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
836  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
837  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
838  dimension->SetArrowLength( boardSettings.m_DimensionArrowLength );
839  dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset );
840  dimension->SetStart( (wxPoint) cursorPos );
841  dimension->SetEnd( (wxPoint) cursorPos );
842  dimension->Update();
843 
844  if( !m_view->IsLayerVisible( layer ) )
845  {
846  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
847  m_frame->GetCanvas()->Refresh();
848  }
849 
850  preview.Add( dimension );
851  frame()->SetMsgPanel( dimension );
852 
853  m_controls->SetAutoPan( true );
854  m_controls->CaptureCursor( true );
855  }
856  break;
857 
858  case SET_END:
859  {
860  dimension->SetEnd( (wxPoint) cursorPos );
861  dimension->Update();
862 
863  if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T )
864  constrainDimension( dimension );
865 
866  // Dimensions that have origin and end in the same spot are not valid
867  if( dimension->GetStart() == dimension->GetEnd() )
868  --step;
869  else if( dimension->Type() == PCB_DIM_LEADER_T )
870  dimension->SetText( wxT( "?" ) );
871 
872  if( dimension->Type() == PCB_DIM_CENTER_T )
873  {
874  // No separate height/text step
875  ++step;
877  }
878  else
879  {
880  break;
881  }
882  }
883 
884  case SET_HEIGHT:
885  if( dimension->Type() == PCB_DIM_LEADER_T )
886  {
887  assert( dimension->GetStart() != dimension->GetEnd() );
888  assert( dimension->GetLineThickness() > 0 );
889 
890  preview.Remove( dimension );
891 
892  commit.Add( dimension );
893  commit.Push( _( "Draw a leader" ) );
894 
895  // Run the edit immediately to set the leader text
896  m_toolMgr->RunAction( PCB_ACTIONS::properties, true, dimension );
897  }
898  else if( (wxPoint) cursorPos != dimension->GetPosition() )
899  {
900  assert( dimension->GetStart() != dimension->GetEnd() );
901  assert( dimension->GetLineThickness() > 0 );
902 
903  preview.Remove( dimension );
904 
905  commit.Add( dimension );
906  commit.Push( _( "Draw a dimension" ) );
907 
908  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, dimension );
909  }
910 
911  break;
912  }
913 
914  if( ++step == FINISHED )
915  {
916  step = SET_ORIGIN;
917  m_controls->SetAutoPan( false );
918  m_controls->CaptureCursor( false );
919  }
920  }
921  else if( evt->IsMotion() )
922  {
923  switch( step )
924  {
925  case SET_END:
926  dimension->SetEnd( (wxPoint) cursorPos );
927 
928  if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
929  {
930  ORTHOGONAL_DIMENSION* ortho = static_cast<ORTHOGONAL_DIMENSION*>( dimension );
931 
932  BOX2I bounds( dimension->GetStart(),
933  dimension->GetEnd() - dimension->GetStart() );
934 
935  // Create a nice preview by measuring the longer dimension
936  bool vert = bounds.GetWidth() < bounds.GetHeight();
937 
938  ortho->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL
940  }
941 
942  dimension->Update();
943 
944  if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T )
945  constrainDimension( dimension );
946 
947  break;
948 
949  case SET_HEIGHT:
950  {
951  if( dimension->Type() == PCB_DIM_ALIGNED_T )
952  {
953  ALIGNED_DIMENSION* aligned = static_cast<ALIGNED_DIMENSION*>( dimension );
954 
955  // Calculating the direction of travel perpendicular to the selected axis
956  double angle = aligned->GetAngle() + ( M_PI / 2 );
957 
958  wxPoint delta( (wxPoint) cursorPos - dimension->GetEnd() );
959  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
960  aligned->SetHeight( height );
961  aligned->Update();
962  }
963  else if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
964  {
965  ORTHOGONAL_DIMENSION* ortho = static_cast<ORTHOGONAL_DIMENSION*>( dimension );
966 
967  BOX2I bounds( dimension->GetStart(),
968  dimension->GetEnd() - dimension->GetStart() );
969  VECTOR2I direction( cursorPos - bounds.Centre() );
970  bool vert;
971 
972  // Only change the orientation when we move outside the bounds
973  if( !bounds.Contains( cursorPos ) )
974  {
975  // If the dimension is horizontal or vertical, set correct orientation
976  // otherwise, test if we're left/right of the bounding box or above/below it
977  if( bounds.GetWidth() == 0 )
978  {
979  vert = true;
980  }
981  else if( bounds.GetHeight() == 0 )
982  {
983  vert = false;
984  }
985  else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
986  {
987  vert = false;
988  }
989  else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
990  {
991  vert = true;
992  }
993  else
994  {
995  vert = std::abs( direction.y ) < std::abs( direction.x );
996  }
997  ortho->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL
999  }
1000  else
1001  {
1002  vert = ortho->GetOrientation() == ORTHOGONAL_DIMENSION::DIR::VERTICAL;
1003  }
1004 
1005  VECTOR2I heightVector( cursorPos - dimension->GetStart() );
1006  ortho->SetHeight( vert ? heightVector.x : heightVector.y );
1007  ortho->Update();
1008  }
1009  else if( dimension->Type() == PCB_DIM_LEADER_T )
1010  {
1011  // Leader: SET_HEIGHT actually sets the text position directly
1012  VECTOR2I lineVector( cursorPos - dimension->GetEnd() );
1013  dimension->Text().SetPosition( wxPoint( VECTOR2I( dimension->GetEnd() ) +
1014  GetVectorSnapped45( lineVector ) ) );
1015  dimension->Update();
1016  }
1017  }
1018  break;
1019  }
1020 
1021  // Show a preview of the item
1022  m_view->Update( &preview );
1023  }
1024  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1025  {
1026  if( dimension )
1027  {
1028  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1029 
1030  if( !m_view->IsLayerVisible( layer ) )
1031  {
1032  m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
1033  m_frame->GetCanvas()->Refresh();
1034  }
1035 
1036  dimension->SetLayer( layer );
1037  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
1038  dimension->Text().SetTextThickness( boardSettings.GetTextThickness( layer ) );
1039  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
1040  dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
1041  dimension->Update();
1042 
1043  m_view->Update( &preview );
1044  frame()->SetMsgPanel( dimension );
1045  }
1046  else
1047  {
1048  evt->SetPassEvent();
1049  }
1050  }
1051  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1052  {
1053  if( step == SET_END || step == SET_HEIGHT )
1054  {
1055  frame()->OnEditItemRequest( dimension );
1056  dimension->Update();
1057  frame()->SetMsgPanel( dimension );
1058  break;
1059  }
1060  else
1061  {
1062  evt->SetPassEvent();
1063  }
1064  }
1065  else
1066  {
1067  evt->SetPassEvent();
1068  }
1069  }
1070 
1071  if( step != SET_ORIGIN )
1072  delete dimension;
1073 
1074  m_controls->SetAutoPan( false );
1075  m_controls->ForceCursorPosition( false );
1076  m_controls->CaptureCursor( false );
1078 
1079  m_view->Remove( &preview );
1080  m_frame->SetMsgPanel( board() );
1081  return 0;
1082 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
static TOOL_ACTION drawCenterDimension
Definition: pcb_actions.h:153
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 ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:100
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:96
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
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
BOARD * m_board
Definition: drawing_tool.h:269
virtual void SetStart(const wxPoint &aPoint)
Definition: dimension.h:122
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:174
virtual void SetPosition(const wxPoint &aPos) override
Definition: pcb_text.h:77
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:102
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: dimension.cpp:212
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:274
void SetItalic(bool isItalic)
Definition: eda_text.h:186
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:152
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition: dimension.h:121
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:352
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
static TOOL_ACTION drawOrthogonalDimension
Definition: pcb_actions.h:154
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
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...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
void Update()
Updates the dimension's cached text and geometry.
Definition: dimension.h:146
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
APPEARANCE_CONTROLS * GetAppearancePanel()
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:177
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:77
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:70
int GetLineThickness() const
Definition: dimension.h:187
double GetAngle() const
Function GetAngle Returns angle of the crossbar.
Definition: dimension.h:388
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
PCB_BASE_EDIT_FRAME * frame() const
void constrainDimension(DIMENSION_BASE *aDim)
Force the dimension lime to be drawn on multiple of 45 degrees.
virtual PCB_LAYER_ID GetActiveLayer() const
void SetText(const wxString &aNewText)
Sets the override text - has no effect if m_overrideValue == false.
Definition: dimension.cpp:199
PCB_LAYER_ID
A quick note on layer IDs:
void SetHeight(int aHeight)
Sets the distance from the feature points to the crossbar line.
Definition: dimension.h:371
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.
coord_type GetWidth() const
Definition: box2.h:197
PCB_TEXT & Text()
Definition: dimension.h:209
Generic, UI-independent tool event.
Definition: tool_event.h:173
unsigned int m_lineWidth
Definition: drawing_tool.h:273
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
Definition: dimension.h:414
virtual void SetEnd(const wxPoint &aPoint)
Definition: dimension.h:125
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
void SetExtensionOffset(int aOffset)
Definition: dimension.h:184
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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:471
wxPoint GetPosition() const override
Definition: dimension.h:127
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:295
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:155
#define _(s)
Definition: 3d_actions.cpp:33
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
void SetArrowLength(int aLength)
Definition: dimension.h:182
void Activate()
Run the tool.
class ORTHOGONAL_DIMENSION, 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:166
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
bool HasPosition() const
Definition: tool_event.h:261
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:322
void SetLineThickness(int aWidth)
Definition: dimension.h:188
For better understanding of the points that make a dimension:
Definition: dimension.h:334
Abstract dimension API.
Definition: dimension.h:95
virtual const wxPoint & GetEnd() const
Definition: dimension.h:124
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
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:284
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION refreshPreview
Definition: actions.h:109
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:163
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
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:88
Marks the center of a circle or arc with a cross shape The size and orientation of the cross is adjus...
Definition: dimension.h:517

References _, TOOL_INTERACTIVE::Activate(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), PNS::angle(), ARROW, AUTOMATIC, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), constrainDimension(), PCB_ACTIONS::decWidth, DIMENSION, PCB_ACTIONS::drawAlignedDimension, PCB_ACTIONS::drawCenterDimension, PCB_ACTIONS::drawLeader, PCB_ACTIONS::drawOrthogonalDimension, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), ALIGNED_DIMENSION::GetAngle(), PCB_BASE_EDIT_FRAME::GetAppearancePanel(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetDesignSettings(), DIMENSION_BASE::GetEnd(), DIMENSION_BASE::GetLineThickness(), PCB_BASE_FRAME::GetMagneticItemsSettings(), PCB_BASE_FRAME::GetModel(), KIGFX::VIEW_CONTROLS::GetMousePosition(), DIMENSION_BASE::GetPosition(), DIMENSION_BASE::GetStart(), EDA_BASE_FRAME::GetUserUnits(), GetVectorSnapped45(), TOOL_BASE::getView(), BOX2< Vec >::GetWidth(), grid, TOOL_EVENT::HasPosition(), ORTHOGONAL_DIMENSION::HORIZONTAL, PCB_ACTIONS::incWidth, TOOL_EVENT::IsAction(), KIGFX::VIEW::IsLayerVisible(), KI_FALLTHROUGH, PCB_ACTIONS::layerChanged, LEADER, m_board, m_controls, m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_lineWidth, TOOL_INTERACTIVE::m_menu, m_mode, TOOL_BASE::m_toolMgr, m_view, MD_ALT, MD_CTRL, 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, DIMENSION_BASE::SetArrowLength(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), DIMENSION_BASE::SetEnd(), DIMENSION_BASE::SetExtensionOffset(), ALIGNED_DIMENSION::SetHeight(), EDA_TEXT::SetItalic(), DIMENSION_BASE::SetLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), DIMENSION_BASE::SetLineThickness(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_TEXT::SetPosition(), DIMENSION_BASE::SetStart(), DIMENSION_BASE::SetText(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), DIMENSION_BASE::Text(), EDA_ITEM::Type(), DIMENSION_BASE::Update(), KIGFX::VIEW::Update(), ORTHOGONAL_DIMENSION::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 242 of file drawing_tool.cpp.

243 {
245  return 0;
246 
247  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
248  PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
249  BOARD_COMMIT commit( m_frame );
250  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
251  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
252 
253  line->SetShape( S_SEGMENT );
254  line->SetFlags( IS_NEW );
255 
256  if( aEvent.HasPosition() )
257  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
258 
259  std::string tool = aEvent.GetCommandStr().get();
260  m_frame->PushTool( tool );
261  Activate();
262 
263  while( drawSegment( tool, &line, startingPoint ) )
264  {
265  if( line )
266  {
267  if( m_isFootprintEditor )
268  static_cast<FP_SHAPE*>( line )->SetLocalCoord();
269 
270  commit.Add( line );
271  commit.Push( _( "Draw a line segment" ) );
272  startingPoint = VECTOR2D( line->GetEnd() );
273  }
274  else
275  {
276  startingPoint = NULLOPT;
277  }
278 
279  line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
280  line->SetShape( S_SEGMENT );
281  line->SetFlags( IS_NEW );
282  }
283 
284  return 0;
285 }
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
usual segment : line with rounded ends
Definition: board_item.h:50
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
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:352
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:471
#define _(s)
Definition: 3d_actions.cpp:33
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:261
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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

Referenced by setTransitions().

◆ DrawRectangle()

int DRAWING_TOOL::DrawRectangle ( const TOOL_EVENT aEvent)

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

289 {
291  return 0;
292 
293  FOOTPRINT* parentFootprint = dynamic_cast<FOOTPRINT*>( m_frame->GetModel() );
294  PCB_SHAPE* rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
295  BOARD_COMMIT commit( m_frame );
296  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
297  OPT<VECTOR2D> startingPoint = boost::make_optional<VECTOR2D>( false, VECTOR2D( 0, 0 ) );
298 
299  rect->SetShape( S_RECT );
300  rect->SetFilled( false );
301  rect->SetFlags(IS_NEW );
302 
303  if( aEvent.HasPosition() )
304  startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) );
305 
306  std::string tool = aEvent.GetCommandStr().get();
307  m_frame->PushTool( tool );
308  Activate();
309 
310  while( drawSegment( tool, &rect, startingPoint ) )
311  {
312  if( rect )
313  {
314  if( m_isFootprintEditor )
315  static_cast<FP_SHAPE*>( rect )->SetLocalCoord();
316 
317  commit.Add( rect );
318  commit.Push( _( "Draw a rectangle" ) );
319 
321  }
322 
323  rect = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE;
324  rect->SetShape( S_RECT );
325  rect->SetFilled( false );
326  rect->SetFlags(IS_NEW );
327  startingPoint = NULLOPT;
328  }
329 
330  return 0;
331 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
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:141
segment with non rounded ends
Definition: board_item.h:51
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
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:129
bool m_isFootprintEditor
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:352
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:471
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
boost::optional< T > OPT
Definition: optional.h:7
void Activate()
Run the tool.
bool HasPosition() const
Definition: tool_event.h:261
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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

Referenced by setTransitions().

◆ drawSegment()

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

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

1341 {
1342  int shape = (*aGraphic)->GetShape();
1343  // Only three shapes are currently supported
1344  assert( shape == S_SEGMENT || shape == S_CIRCLE || shape == S_RECT );
1345 
1346  EDA_UNITS userUnits = m_frame->GetUserUnits();
1348  PCB_SHAPE*& graphic = *aGraphic;
1349  PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer();
1350 
1351  m_lineWidth = getSegmentWidth( drawingLayer );
1352 
1353  // geometric construction manager
1355 
1356  // drawing assistant overlay
1357  // TODO: workaround because PCB_SHAPE_TYPE_T is not visible from commons.
1358  KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
1359  KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, userUnits, geomShape );
1360 
1361  // Add a VIEW_GROUP that serves as a preview for the new item
1362  PCB_SELECTION preview;
1363  m_view->Add( &preview );
1364  m_view->Add( &twoPointAsst );
1365 
1366  m_controls->ShowCursor( true );
1367 
1368  bool started = false;
1369  bool cancelled = false;
1370  bool isLocalOriginSet = ( m_frame->GetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) );
1371  VECTOR2I cursorPos = m_controls->GetMousePosition();
1372 
1373  auto setCursor =
1374  [&]()
1375  {
1377  };
1378 
1379  auto cleanup =
1380  [&]()
1381  {
1382  preview.Clear();
1383  m_view->Update( &preview );
1384  delete graphic;
1385  graphic = nullptr;
1386 
1387  if( !isLocalOriginSet )
1388  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1389  };
1390 
1391  // Prime the pump
1393 
1394  if( aStartingPoint )
1396 
1397  // Set initial cursor
1398  setCursor();
1399 
1400  // Main loop: keep receiving events
1401  while( TOOL_EVENT* evt = Wait() )
1402  {
1403  setCursor();
1404 
1405  if( started )
1406  m_frame->SetMsgPanel( graphic );
1407 
1408  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1409  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
1410  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), drawingLayer );
1411  m_controls->ForceCursorPosition( true, cursorPos );
1412 
1413  // 45 degree angle constraint enabled with an option and toggled with Ctrl
1414  bool limit45 = frame()->Settings().m_Use45DegreeGraphicSegments;
1415 
1416  if( evt->Modifier( MD_CTRL ) )
1417  limit45 = !limit45;
1418 
1419  if( evt->IsCancelInteractive() )
1420  {
1421  cleanup();
1422 
1423  if( !started )
1424  {
1425  m_frame->PopTool( aTool );
1426  cancelled = true;
1427  }
1428 
1429  break;
1430  }
1431  else if( evt->IsActivate() )
1432  {
1433  if( evt->IsPointEditor() )
1434  {
1435  // don't exit (the point editor runs in the background)
1436  }
1437  else if( evt->IsMoveTool() )
1438  {
1439  cleanup();
1440  // leave ourselves on the stack so we come back after the move
1441  cancelled = true;
1442  break;
1443  }
1444  else
1445  {
1446  cleanup();
1447  m_frame->PopTool( aTool );
1448  cancelled = true;
1449  break;
1450  }
1451  }
1452  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1453  {
1454  drawingLayer = m_frame->GetActiveLayer();
1455  m_lineWidth = getSegmentWidth( drawingLayer );
1456 
1457  if( graphic )
1458  {
1459  if( !m_view->IsLayerVisible( drawingLayer ) )
1460  {
1461  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1462  m_frame->GetCanvas()->Refresh();
1463  }
1464 
1465  graphic->SetLayer( drawingLayer );
1466  graphic->SetWidth( m_lineWidth );
1467  m_view->Update( &preview );
1468  frame()->SetMsgPanel( graphic );
1469  }
1470  else
1471  {
1472  evt->SetPassEvent();
1473  }
1474  }
1475  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
1476  {
1477  if( started )
1478  {
1479  frame()->OnEditItemRequest( graphic );
1480  m_view->Update( &preview );
1481  frame()->SetMsgPanel( graphic );
1482  break;
1483  }
1484  else
1485  {
1486  evt->SetPassEvent();
1487  }
1488  }
1489  else if( evt->IsClick( BUT_RIGHT ) )
1490  {
1492  }
1493  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1494  {
1495  if( !started )
1496  {
1498 
1499  if( aStartingPoint )
1500  {
1501  cursorPos = aStartingPoint.get();
1502  aStartingPoint = NULLOPT;
1503  }
1504 
1505  m_lineWidth = getSegmentWidth( drawingLayer );
1506 
1507  // Init the new item attributes
1508  graphic->SetShape( (PCB_SHAPE_TYPE_T) shape );
1509  graphic->SetFilled( false );
1510  graphic->SetWidth( m_lineWidth );
1511  graphic->SetLayer( drawingLayer );
1512  grid.SetSkipPoint( cursorPos );
1513 
1514  twoPointManager.SetOrigin( (wxPoint) cursorPos );
1515  twoPointManager.SetEnd( (wxPoint) cursorPos );
1516 
1517  if( !isLocalOriginSet )
1518  m_frame->GetScreen()->m_LocalOrigin = cursorPos;
1519 
1520  preview.Add( graphic );
1521  frame()->SetMsgPanel( graphic );
1522  m_controls->SetAutoPan( true );
1523  m_controls->CaptureCursor( true );
1524 
1525  if( !m_view->IsLayerVisible( drawingLayer ) )
1526  {
1527  m_frame->GetAppearancePanel()->SetLayerVisible( drawingLayer, true );
1528  m_frame->GetCanvas()->Refresh();
1529  }
1530 
1531  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1532 
1533  started = true;
1534  }
1535  else if( shape == S_CIRCLE )
1536  {
1537  // No clever logic if drawing a circle
1538  preview.Clear();
1539  twoPointManager.Reset();
1540  break;
1541  }
1542  else
1543  {
1544  PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
1545 
1546  if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
1547  || ( evt->IsDblClick( BUT_LEFT ) && shape == S_SEGMENT ) || snapItem )
1548  // User has clicked twice in the same spot
1549  // or clicked on the end of an existing segment (closing a path)
1550  {
1551  BOARD_COMMIT commit( m_frame );
1552 
1553  // If the user clicks on an existing snap point from a drawsegment
1554  // we finish the segment as they are likely closing a path
1555  if( snapItem && ( shape == S_RECT || graphic->GetLength() > 0.0 ) )
1556  {
1557  commit.Add( graphic );
1558  commit.Push( _( "Draw a line segment" ) );
1559  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, graphic );
1560  }
1561  else
1562  {
1563  delete graphic;
1564  }
1565 
1566  graphic = nullptr;
1567  }
1568 
1569  preview.Clear();
1570  twoPointManager.Reset();
1571  break;
1572  }
1573 
1574  twoPointManager.SetEnd( cursorPos );
1575  }
1576  else if( evt->IsMotion() )
1577  {
1578  // 45 degree lines
1579  if( started && ( ( limit45 && shape == S_SEGMENT )
1580  || ( evt->Modifier( MD_CTRL ) && shape == S_RECT ) ) )
1581  {
1582  const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
1583 
1584  // get a restricted 45/H/V line from the last fixed point to the cursor
1585  auto newEnd = GetVectorSnapped45( lineVector, ( shape == S_RECT ) );
1586  m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
1587  twoPointManager.SetEnd( twoPointManager.GetOrigin() + (wxPoint) newEnd );
1588  twoPointManager.SetAngleSnap( true );
1589  }
1590  else
1591  {
1592  twoPointManager.SetEnd( (wxPoint) cursorPos );
1593  twoPointManager.SetAngleSnap( false );
1594  }
1595 
1596  updateSegmentFromGeometryMgr( twoPointManager, graphic );
1597  m_view->Update( &preview );
1598  m_view->Update( &twoPointAsst );
1599  }
1600  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1601  {
1603  graphic->SetWidth( m_lineWidth );
1604  m_view->Update( &preview );
1605  frame()->SetMsgPanel( graphic );
1606  }
1607  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1608  {
1610  graphic->SetWidth( m_lineWidth );
1611  m_view->Update( &preview );
1612  frame()->SetMsgPanel( graphic );
1613  }
1614  else if( evt->IsAction( &ACTIONS::resetLocalCoords ) )
1615  {
1616  isLocalOriginSet = true;
1617  evt->SetPassEvent();
1618  }
1619  else if( evt->IsAction( &ACTIONS::updateUnits ) )
1620  {
1621  if( frame()->GetUserUnits() != userUnits )
1622  {
1623  userUnits = frame()->GetUserUnits();
1624  twoPointAsst.SetUnits( userUnits );
1625  m_view->Update( &twoPointAsst );
1626  }
1627  evt->SetPassEvent();
1628  }
1629  else
1630  {
1631  evt->SetPassEvent();
1632  }
1633  }
1634 
1635  if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before
1636  m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
1637 
1638  m_view->Remove( &twoPointAsst );
1639  m_view->Remove( &preview );
1640  m_frame->SetMsgPanel( board() );
1641 
1643  m_controls->SetAutoPan( false );
1644  m_controls->CaptureCursor( false );
1645  m_controls->ForceCursorPosition( false );
1646 
1647  return !cancelled;
1648 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
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:96
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:174
Represents an assistant draw when interactively drawing a line or circle on a canvas.
Represent a very simple geometry manager for items that have a start and end point.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:274
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
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:352
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
usual segment : line with rounded ends
Definition: board_item.h:50
void Reset()
Reset the manager to the initial state.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
segment with non rounded ends
Definition: board_item.h:51
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 an 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:177
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:77
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
PCB_BASE_EDIT_FRAME * frame() const
virtual PCB_LAYER_ID GetActiveLayer() const
bool m_Use45DegreeGraphicSegments
PCB_LAYER_ID
A quick note on layer IDs:
PCB_SHAPE_TYPE_T
The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member.
Definition: board_item.h:48
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:173
unsigned int m_lineWidth
Definition: drawing_tool.h:273
void SetOrigin(const VECTOR2I &aOrigin)
< Set the origin of the ruler (the fixed end)
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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:295
static TOOL_ACTION updateUnits
Definition: actions.h:150
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
PCBNEW_SETTINGS & Settings()
static TOOL_ACTION resetLocalCoords
Definition: actions.h:153
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
ring
Definition: board_item.h:53
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:322
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:109
static TOOL_ACTION cursorClick
Definition: actions.h:126
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:94
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(), 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_ALT, MD_CTRL, MD_SHIFT, NULLOPT, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PENCIL, TOOLS_HOLDER::PopTool(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), EDA_DRAW_PANEL_GAL::Refresh(), ACTIONS::refreshPreview, KIGFX::VIEW::Remove(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::Reset(), ACTIONS::resetLocalCoords, TOOL_MANAGER::RunAction(), S_CIRCLE, S_RECT, S_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 205 of file drawing_stackup_table_tool.cpp.

207 {
208  BOARD_COMMIT commit( m_frame );
209  std::vector<std::vector<PCB_TEXT*>> texts;
210 
211  // Style : Header
212  PCB_TEXT* headStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
213  headStyle->SetLayer( Eco1_User );
214  headStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
215  headStyle->SetTextThickness( Millimeter2iu( 0.3 ) );
216  headStyle->SetItalic( false );
217  headStyle->SetTextPos( wxPoint( 0, 0 ) );
218  headStyle->SetText( "Layer" );
220  headStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
221 
222  // Style : data
223  PCB_TEXT* dataStyle = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
224  dataStyle->SetLayer( Eco1_User );
225  dataStyle->SetTextSize( wxSize( Millimeter2iu( 1.5 ), Millimeter2iu( 1.5 ) ) );
226  dataStyle->SetTextThickness( Millimeter2iu( 0.1 ) );
227  dataStyle->SetItalic( false );
228  dataStyle->SetTextPos( wxPoint( 0, 0 ) );
229  dataStyle->SetText( "Layer" );
231  dataStyle->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
232 
233  //Get Layer names
235  BOARD_STACKUP& stackup = dsnSettings.GetStackupDescriptor();
236  std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
237 
238  std::vector<PCB_TEXT*> colLayer;
239  std::vector<PCB_TEXT*> colType;
240  std::vector<PCB_TEXT*> colMaterial;
241  std::vector<PCB_TEXT*> colThickness;
242  std::vector<PCB_TEXT*> colColor;
243  std::vector<PCB_TEXT*> colEpsilon;
244  std::vector<PCB_TEXT*> colTanD;
245  PCB_TEXT* t;
246 
247  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
248  t->SetText( _( "Layer Name" ) );
249  colLayer.push_back( t );
250 
251  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
252  t->SetText( _( "Type" ) );
253  colType.push_back( t );
254 
255  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
256  t->SetText( _( "Material" ) );
257  colMaterial.push_back( t );
258 
259  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
260 
262  t->SetText( _( "Thickness (mm)" ) );
263 
264  else if( m_frame->GetUserUnits() == EDA_UNITS::INCHES )
265  t->SetText( _( "Thickness (mils)" ) );
266 
267  colThickness.push_back( t );
268 
269  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
270  t->SetText( _( "Color" ) );
271  colColor.push_back( t );
272 
273  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
274  t->SetText( _( "Epsilon R" ) );
275  colEpsilon.push_back( t );
276 
277  t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
278  t->SetText( _( "Loss Tangent" ) );
279  colTanD.push_back( t );
280 
281  int i;
282 
283  for( i = 0; i < stackup.GetCount(); i++ )
284  {
285  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
286  t->SetText( layers.at( i )->GetLayerName() );
287  colLayer.push_back( t );
288 
289  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
290  t->SetText( layers.at( i )->GetTypeName() );
291  colType.push_back( t );
292 
293  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
294  t->SetText( layers.at( i )->GetMaterial() );
295  colMaterial.push_back( t );
296 
297  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
298  t->SetText(
299  StringFromValue( m_frame->GetUserUnits(), layers.at( i )->GetThickness(), true ) );
300  colThickness.push_back( t );
301 
302  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
303  t->SetText( layers.at( i )->GetColor() );
304  colColor.push_back( t );
305 
306  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
307  t->SetText( StringFromValue( EDA_UNITS::UNSCALED, layers.at( i )->GetEpsilonR(), false ) );
308  colEpsilon.push_back( t );
309 
310  t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
311  t->SetText(
312  StringFromValue( EDA_UNITS::UNSCALED, layers.at( i )->GetLossTangent(), false ) );
313  colTanD.push_back( t );
314  }
315 
316  texts.push_back( colLayer );
317  texts.push_back( colType );
318  texts.push_back( colMaterial );
319  texts.push_back( colThickness );
320  texts.push_back( colColor );
321  texts.push_back( colEpsilon );
322  texts.push_back( colTanD );
323  std::vector<BOARD_ITEM*> table =
324  initTextTable( texts, aOrigin, aLayer, tableSize, true );
325 
326  if( aDrawNow )
327  {
328 
329  for( auto item : table )
330  commit.Add( item );
331 
332  commit.Push( _( "Insert board stackup table" ) );
333  }
334 
335  return table;
336 }
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
this class manage the layers needed to make a physical board they are solder mask,...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetItalic(bool isItalic)
Definition: eda_text.h:186
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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_STACKUP & GetStackupDescriptor()
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
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:208
#define _(s)
Definition: 3d_actions.cpp:33
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:225
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:202
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
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, BOARD_STACKUP::GetCount(), PCB_BASE_FRAME::GetDesignSettings(), 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(), and UNSCALED.

Referenced by PlaceStackup().

◆ DrawVia()

int DRAWING_TOOL::DrawVia ( const TOOL_EVENT aEvent)

Definition at line 2201 of file drawing_tool.cpp.

2202 {
2203  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
2204  {
2206  PCB_GRID_HELPER m_gridHelper;
2207  std::shared_ptr<DRC_ENGINE> m_drcEngine;
2208  int m_drcEpsilon;
2209  int m_worstClearance;
2210  bool m_allowDRCViolations;
2211  bool m_flaggedDRC;
2212 
2213  VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
2214  m_frame( aFrame ),
2215  m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ),
2216  m_drcEngine( aFrame->GetBoard()->GetDesignSettings().m_DRCEngine ),
2217  m_drcEpsilon( aFrame->GetBoard()->GetDesignSettings().GetDRCEpsilon() ),
2218  m_worstClearance( 0 ),
2219  m_flaggedDRC( false )
2220  {
2222  PNS::ROUTING_SETTINGS& cfg = router->Router()->Settings();
2223 
2224  m_allowDRCViolations = cfg.Mode() == PNS::RM_MarkObstacles && cfg.CanViolateDRC();
2225 
2226  try
2227  {
2228  m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() );
2229 
2230  DRC_CONSTRAINT constraint;
2231 
2232  if( m_drcEngine->QueryWorstConstraint( CLEARANCE_CONSTRAINT, constraint ) )
2233  m_worstClearance = constraint.GetValue().Min();
2234 
2235  if( m_drcEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, constraint ) )
2236  m_worstClearance = std::max( m_worstClearance, constraint.GetValue().Min() );
2237 
2238  for( FOOTPRINT* footprint : aFrame->GetBoard()->Footprints() )
2239  {
2240  for( PAD* pad : footprint->Pads() )
2241  m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
2242  }
2243  }
2244  catch( PARSE_ERROR& )
2245  {
2246  }
2247  }
2248 
2249  virtual ~VIA_PLACER()
2250  {
2251  }
2252 
2253  TRACK* findTrack( VIA* aVia )
2254  {
2255  const LSET lset = aVia->GetLayerSet();
2256  wxPoint position = aVia->GetPosition();
2257  BOX2I bbox = aVia->GetBoundingBox();
2258 
2259  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2260  auto view = m_frame->GetCanvas()->GetView();
2261  std::vector<TRACK*> possible_tracks;
2262 
2263  view->Query( bbox, items );
2264 
2265  for( auto it : items )
2266  {
2267  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
2268 
2269  if( !(item->GetLayerSet() & lset ).any() )
2270  continue;
2271 
2272  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2273  {
2274  if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
2275  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
2276  possible_tracks.push_back( track );
2277  }
2278  }
2279 
2280  TRACK* return_track = nullptr;
2281  int min_d = std::numeric_limits<int>::max();
2282 
2283  for( TRACK* track : possible_tracks )
2284  {
2285  SEG test( track->GetStart(), track->GetEnd() );
2286  int dist = ( test.NearestPoint( position ) - position ).EuclideanNorm();
2287 
2288  if( dist < min_d )
2289  {
2290  min_d = dist;
2291  return_track = track;
2292  }
2293  }
2294 
2295  return return_track;
2296  }
2297 
2298  bool hasDRCViolation( VIA* aVia, BOARD_ITEM* aOther )
2299  {
2300  // It would really be better to know what particular nets a nettie should allow,
2301  // but for now it is what it is.
2302  if( DRC_ENGINE::IsNetTie( aOther ) )
2303  return false;
2304 
2305  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aOther );
2306 
2307  if( cItem && cItem->GetNetCode() == aVia->GetNetCode() )
2308  return false;
2309 
2310  DRC_CONSTRAINT constraint;
2311  int clearance;
2312 
2313  for( PCB_LAYER_ID layer : aOther->GetLayerSet().Seq() )
2314  {
2315  if( !IsCopperLayer( layer ) )
2316  continue;
2317 
2318  constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aVia, aOther, layer );
2319  clearance = constraint.GetValue().Min();
2320 
2321  if( clearance >= 0 )
2322  {
2323  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, layer );
2324  std::shared_ptr<SHAPE> otherShape = DRC_ENGINE::GetShape( aOther, layer );
2325 
2326  if( viaShape->Collide( otherShape.get(), clearance - m_drcEpsilon ) )
2327  return true;
2328  }
2329  }
2330 
2331  std::unique_ptr<SHAPE_SEGMENT> holeShape;
2332 
2333  if( aOther->Type() == PCB_VIA_T )
2334  {
2335  VIA* via = static_cast<VIA*>( aOther );
2336  wxPoint pos = via->GetPosition();
2337 
2338  holeShape.reset( new SHAPE_SEGMENT( pos, pos, via->GetDrill() ) );
2339  }
2340  else if( aOther->Type() == PCB_PAD_T )
2341  {
2342  PAD* pad = static_cast<PAD*>( aOther );
2343 
2344  if( pad->GetDrillSize().x )
2345  holeShape.reset( new SHAPE_SEGMENT( *pad->GetEffectiveHoleShape() ) );
2346  }
2347 
2348  if( holeShape )
2349  {
2350  constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, aVia, aOther,
2351  UNDEFINED_LAYER );
2352  clearance = constraint.GetValue().Min();
2353 
2354  if( clearance >= 0 )
2355  {
2356  std::shared_ptr<SHAPE> viaShape = DRC_ENGINE::GetShape( aVia, UNDEFINED_LAYER );
2357 
2358  if( viaShape->Collide( holeShape.get(), clearance - m_drcEpsilon ) )
2359  return true;
2360  }
2361  }
2362 
2363  return false;
2364  }
2365 
2366  bool checkDRCViolation( VIA* aVia )
2367  {
2368  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
2369  std::set<BOARD_ITEM*> checkedItems;
2370  BOX2I bbox = aVia->GetBoundingBox();
2371 
2372  bbox.Inflate( m_worstClearance );
2373  m_frame->GetCanvas()->GetView()->Query( bbox, items );
2374 
2375  for( std::pair<KIGFX::VIEW_ITEM*, int> it : items )
2376  {
2377  BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( it.first );
2378 
2379  if( !item )
2380  continue;
2381 
2382  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
2383  continue; // stitching vias bind to zones, so ignore them
2384 
2385  if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_GROUP_T )
2386  continue; // check against children, but not against footprint itself
2387 
2388  if( item->Type() == PCB_FP_TEXT_T && !static_cast<FP_TEXT*>( item )->IsVisible() )
2389  continue; // ignore hidden items
2390 
2391  if( checkedItems.count( item ) )
2392  continue;
2393 
2394  if( hasDRCViolation( aVia, item ) )
2395  return true;
2396 
2397  checkedItems.insert( item );
2398  }
2399 
2400  return false;
2401  }
2402 
2403  PAD* findPad( VIA* aVia )
2404  {
2405  const wxPoint position = aVia->GetPosition();
2406  const LSET lset = aVia->GetLayerSet();
2407 
2408  for( FOOTPRINT* fp : m_board->Footprints() )
2409  {
2410  for(PAD* pad : fp->Pads() )
2411  {
2412  if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
2413  if( pad->GetNetCode() > 0 )
2414  return pad;
2415  }
2416  }
2417 
2418  return nullptr;
2419  }
2420 
2421  int findStitchedZoneNet( VIA* aVia )
2422  {
2423  const wxPoint position = aVia->GetPosition();
2424  const LSET lset = aVia->GetLayerSet();
2425 
2426  std::vector<ZONE*> foundZones;
2427 
2428  for( ZONE* zone : m_board->Zones() )
2429  {
2430  for( PCB_LAYER_ID layer : LSET( zone->GetLayerSet() & lset ).Seq() )
2431  {
2432  if( zone->HitTestFilledArea( layer, position ) )
2433  foundZones.push_back( zone );
2434  }
2435  }
2436 
2437  std::sort( foundZones.begin(), foundZones.end(),
2438  [] ( const ZONE* a, const ZONE* b )
2439  {
2440  return a->GetLayer() < b->GetLayer();
2441  } );
2442 
2443  // first take the net of the active layer
2444  for( ZONE* z : foundZones )
2445  {
2446  if( m_frame->GetActiveLayer() == z->GetLayer() )
2447  return z->GetNetCode();
2448  }
2449 
2450  // none? take the topmost visible layer
2451  for( ZONE* z : foundZones )
2452  {
2453  if( m_board->IsLayerVisible( z->GetLayer() ) )
2454  return z->GetNetCode();
2455  }
2456 
2457  return -1;
2458  }
2459 
2460  void SnapItem( BOARD_ITEM *aItem ) override
2461  {
2462  // If you place a Via on a track but not on its centerline, the current
2463  // connectivity algorithm will require us to put a kink in the track when
2464  // we break it (so that each of the two segments ends on the via center).
2465  // That's not ideal, and is in fact probably worse than forcing snap in
2466  // this situation.
2467 
2468  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
2469  auto via = static_cast<VIA*>( aItem );
2470  wxPoint position = via->GetPosition();
2471  TRACK* track = findTrack( via );
2472 
2473  if( track )
2474  {
2475  SEG trackSeg( track->GetStart(), track->GetEnd() );
2476  VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
2477 
2478  aItem->SetPosition( (wxPoint) snap );
2479  }
2480  }
2481 
2482  bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
2483  {
2484  VIA* via = static_cast<VIA*>( aItem );
2485  wxPoint viaPos = via->GetPosition();
2486  TRACK* track = findTrack( via );
2487  PAD * pad = findPad( via );
2488 
2489  if( track )
2490  via->SetNetCode( track->GetNetCode() );
2491  else if( pad )
2492  via->SetNetCode( pad->GetNetCode() );
2493 
2494  if( !m_allowDRCViolations && checkDRCViolation( via ) )
2495  {
2496  m_frame->ShowInfoBarError( _( "Via location violates DRC." ) );
2497  via->SetNetCode( 0 );
2498  m_flaggedDRC = true;
2499  return false;
2500  }
2501  else if( m_flaggedDRC )
2502  {
2503  m_frame->GetInfoBar()->Dismiss();
2504  }
2505 
2506  if( track )
2507  {
2508  if( viaPos != track->GetStart() && viaPos != track->GetEnd() )
2509  {
2510  aCommit.Modify( track );
2511 
2512  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
2513  const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
2514 
2515  track->SetEnd( viaPos );
2516  newTrack->SetStart( viaPos );
2517  aCommit.Add( newTrack );
2518  }
2519  }
2520  else if( !pad )
2521  {
2522  via->SetNetCode( findStitchedZoneNet( via ) );
2523  via->SetIsFree();
2524  }
2525 
2526  aCommit.Add( aItem );
2527  return true;
2528  }
2529 
2530  std::unique_ptr<BOARD_ITEM> CreateItem() override
2531  {
2532  auto& ds = m_board->GetDesignSettings();
2533  VIA* via = new VIA( m_board );
2534 
2535  via->SetNetCode( 0 );
2536  via->SetViaType( ds.m_CurrentViaType );
2537 
2538  // for microvias, the size and hole will be changed later.
2539  via->SetWidth( ds.GetCurrentViaSize() );
2540  via->SetDrill( ds.GetCurrentViaDrill() );
2541 
2542  // Usual via is from copper to component.
2543  // layer pair is B_Cu and F_Cu.
2544  via->SetLayerPair( B_Cu, F_Cu );
2545 
2546  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
2547  PCB_LAYER_ID last_layer;
2548 
2549  // prepare switch to new active layer:
2550  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
2551  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
2552  else
2553  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
2554 
2555  // Adjust the actual via layer pair
2556  switch( via->GetViaType() )
2557  {
2558  case VIATYPE::BLIND_BURIED:
2559  via->SetLayerPair( first_layer, last_layer );
2560  break;
2561 
2562  case VIATYPE::MICROVIA: // from external to the near neighbor inner layer
2563  {
2564  PCB_LAYER_ID last_inner_layer =
2565  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
2566 
2567  if( first_layer == B_Cu )
2568  last_layer = last_inner_layer;
2569  else if( first_layer == F_Cu )
2570  last_layer = In1_Cu;
2571  else if( first_layer == last_inner_layer )
2572  last_layer = B_Cu;
2573  else if( first_layer == In1_Cu )
2574  last_layer = F_Cu;
2575 
2576  // else error: will be removed later
2577  via->SetLayerPair( first_layer, last_layer );
2578 
2579  // Update diameter and hole size, which where set previously for normal vias
2580  NETCLASS* netClass = via->GetNetClass();
2581 
2582  via->SetWidth( netClass->GetuViaDiameter() );
2583  via->SetDrill( netClass->GetuViaDrill() );
2584  }
2585  break;
2586 
2587  default:
2588  break;
2589  }
2590 
2591  return std::unique_ptr<BOARD_ITEM>( via );
2592  }
2593  };
2594 
2595  VIA_PLACER placer( frame() );
2596 
2597  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
2598 
2599  doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place via" ),
2601 
2602  return 0;
2603 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
Contain all persistent settings of the router, such as the mode, optimization effort,...
Definition: track.h:343
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:311
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: track.cpp:376
BOARD * m_board
Definition: drawing_tool.h:269
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:303
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
void SetEnd(const wxPoint &aEnd)
Definition: track.h:112
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)
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
const wxPoint & GetStart() const
Definition: track.h:116
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: track.cpp:220
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: track.cpp:54
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
class PAD, a pad in a footprint
Definition: typeinfo.h:89
T Min() const
Definition: minoptmax.h:33
static bool IsNetTie(BOARD_ITEM *aItem)
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,...
PADS & Pads()
Definition: footprint.h:164
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:171
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:216
FOOTPRINTS & Footprints()
Definition: board.h:305
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
PNS_MODE Mode() const
Set the routing mode.
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:44
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:525
Definition: seg.h:41
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:471
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302
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:453
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
Ignore collisions, mark obstacles.
int GetWidth() const
Definition: track.h:110
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:121
Common, abstract interface for edit frames.
#define _(s)
Definition: 3d_actions.cpp:33
int GetCopperLayerCount() const
Definition: board.cpp:435
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...
const wxPoint & GetEnd() const
Definition: track.h:113
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
WX_INFOBAR * GetInfoBar()
void SetStart(const wxPoint &aStart)
Definition: track.h:115
int GetuViaDrill() const
Definition: netclass.h:144
class 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:55
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:428
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:60
wxPoint GetPosition() const override
Definition: track.h:411
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:184
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
Definition: track.h:83
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:43
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

References _, COMMIT::Add(), PCB_GRID_HELPER::AlignToSegment(), B_Cu, BLIND_BURIED, CLEARANCE_CONSTRAINT, 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(), TRACK::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), BOARD::GetCopperLayerCount(), PCB_BASE_EDIT_FRAME::GetDesignRulesPath(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetDRCEpsilon(), TRACK::GetEnd(), EDA_BASE_FRAME::GetInfoBar(), ZONE::GetLayer(), BOARD_ITEM::GetLayerSet(), VIA::GetLayerSet(), PCB_BASE_FRAME::GetMagneticItemsSettings(), BOARD_CONNECTED_ITEM::GetNetCode(), VIA::GetPosition(), PCB_BASE_FRAME::GetScreen(), DRC_ENGINE::GetShape(), TRACK::GetStart(), TOOL_MANAGER::GetTool(), TOOLS_HOLDER::GetToolManager(), NETCLASS::GetuViaDiameter(), NETCLASS::GetuViaDrill(), DRC_CONSTRAINT::GetValue(), PCB_DRAW_PANEL_GAL::GetView(), 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_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(), PNS::ROUTING_SETTINGS::Mode(), 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::RM_MarkObstacles, PNS::TOOL_BASE::Router(), LSET::Seq(), TRACK::SetEnd(), EDA_ITEM::SetPosition(), GRID_HELPER::SetSnap(), 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 1952 of file drawing_tool.cpp.

1953 {
1954  if( m_isFootprintEditor && !m_frame->GetModel() )
1955  return 0;
1956 
1957  ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
1958  MODE drawMode = MODE::ZONE;
1959 
1960  if( aEvent.IsAction( &PCB_ACTIONS::drawRuleArea ) )
1961  drawMode = MODE::KEEPOUT;
1962 
1963  if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) )
1964  drawMode = MODE::GRAPHIC_POLYGON;
1965 
1966  SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode );
1967 
1968  // get a source zone, if we need one. We need it for:
1969  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1970  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1971  ZONE* sourceZone = nullptr;
1972 
1973  if( !getSourceZoneForAction( zoneMode, &sourceZone ) )
1974  return 0;
1975 
1976  // Turn zones on if they are off, so that the created object will be visible after completion
1978 
1980 
1981  params.m_keepout = drawMode == MODE::KEEPOUT;
1982  params.m_mode = zoneMode;
1983  params.m_sourceZone = sourceZone;
1984 
1985  if( zoneMode == ZONE_MODE::SIMILAR )
1986  params.m_layer = sourceZone->GetLayer();
1987  else
1988  params.m_layer = m_frame->GetActiveLayer();
1989 
1990  ZONE_CREATE_HELPER zoneTool( *this, params );
1991 
1992  // the geometry manager which handles the zone geometry, and
1993  // hands the calculated points over to the zone creator tool
1994  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1995  bool constrainAngle = false;
1996 
1997  std::string tool = aEvent.GetCommandStr().get();
1998  m_frame->PushTool( tool );
1999  Activate(); // register for events
2000 
2001  m_controls->ShowCursor( true );
2002 
2003  bool started = false;
2005  STATUS_TEXT_POPUP status( m_frame );
2006  status.SetTextColor( wxColour( 255, 0, 0 ) );
2007  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
2008 
2009  auto setCursor =
2010  [&]()
2011  {
2013  };
2014 
2015  auto cleanup =
2016  [&] ()
2017  {
2018  polyGeomMgr.Reset();
2019  started = false;
2020  grid.ClearSkipPoint();
2021  m_controls->SetAutoPan( false );
2022  m_controls->CaptureCursor( false );
2023  };
2024 
2025  // Prime the pump
2026  if( aEvent.HasPosition() )
2027  m_toolMgr->PrimeTool( aEvent.Position() );
2028 
2029  // Set initial cursor
2030  setCursor();
2031 
2032  // Main loop: keep receiving events
2033  while( TOOL_EVENT* evt = Wait() )
2034  {
2035  setCursor();
2036 
2037  LSET layers( m_frame->GetActiveLayer() );
2038  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2039  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
2040 
2041  VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
2042  cursorPos = grid.BestSnapAnchor( cursorPos, layers );
2043 
2044  m_controls->ForceCursorPosition( true, cursorPos );
2045 
2046  if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || evt->Modifier( MD_CTRL ) )
2047  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2048  else
2049  polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
2050 
2051  if( evt->IsCancelInteractive() )
2052  {
2053  if( polyGeomMgr.IsPolygonInProgress() )
2054  cleanup();
2055  else
2056  {
2057  m_frame->PopTool( tool );
2058  break;
2059  }
2060  }
2061  else if( evt->IsActivate() )
2062  {
2063  if( polyGeomMgr.IsPolygonInProgress() )
2064  cleanup();
2065 
2066  if( evt->IsPointEditor() )
2067  {
2068  // don't exit (the point editor runs in the background)
2069  }
2070  else if( evt->IsMoveTool() )
2071  {
2072  // leave ourselves on the stack so we come back after the move
2073  break;
2074  }
2075  else
2076  {
2077  m_frame->PopTool( tool );
2078  break;
2079  }
2080  }
2081  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
2082  {
2083  if( zoneMode != ZONE_MODE::SIMILAR )
2084  params.m_layer = frame()->GetActiveLayer();
2085 
2086  if( !m_view->IsLayerVisible( params.m_layer ) )
2087  {
2088  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2089  m_frame->GetCanvas()->Refresh();
2090  }
2091  }
2092  else if( evt->IsClick( BUT_RIGHT ) )
2093  {
2095  }
2096  // events that lock in nodes
2097  else if( evt->IsClick( BUT_LEFT )
2098  || evt->IsDblClick( BUT_LEFT )
2099  || evt->IsAction( &PCB_ACTIONS::closeOutline ) )
2100  {
2101  // Check if it is double click / closing line (so we have to finish the zone)
2102  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
2103  || evt->IsAction( &PCB_ACTIONS::closeOutline )
2104  || polyGeomMgr.NewPointClosesOutline( cursorPos );
2105 
2106  if( endPolygon )
2107  {
2108  polyGeomMgr.SetFinished();
2109  polyGeomMgr.Reset();
2110 
2111  started = false;
2112  m_controls->SetAutoPan( false );
2113  m_controls->CaptureCursor( false );
2114  }
2115  // adding a corner
2116  else if( polyGeomMgr.AddPoint( cursorPos ) )
2117  {
2118  if( !started )
2119  {
2120  started = true;
2121 
2122  POLYGON_GEOM_MANAGER::LEADER_MODE leaderMode = polyGeomMgr.GetLeaderMode();
2123  constrainAngle = ( leaderMode == POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
2124 
2125  m_controls->SetAutoPan( true );
2126  m_controls->CaptureCursor( true );
2127 
2128  if( !m_view->IsLayerVisible( params.m_layer ) )
2129  {
2130  m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
2131  m_frame->GetCanvas()->Refresh();
2132  }
2133  }
2134  }
2135  }
2136  else if( evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) )
2137  {
2138  polyGeomMgr.DeleteLastCorner();
2139 
2140  if( !polyGeomMgr.IsPolygonInProgress() )
2141  {
2142  // report finished as an empty shape
2143  polyGeomMgr.SetFinished();
2144 
2145  // start again
2146  started = false;
2147  m_controls->SetAutoPan( false );
2148  m_controls->CaptureCursor( false );
2149  }
2150  }
2151  else if( polyGeomMgr.IsPolygonInProgress()
2152  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
2153  {
2154  polyGeomMgr.SetCursorPosition( cursorPos );
2155 
2156  if( polyGeomMgr.IsSelfIntersecting( true ) )
2157  {
2158  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
2159  status.Move( p );
2160  status.PopupFor( 1500 );
2161  }
2162  else
2163  {
2164  status.Hide();
2165  }
2166  }
2167  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
2168  {
2169  if( started )
2170  {
2171  frame()->OnEditItemRequest( zoneTool.GetZone() );
2172  zoneTool.OnGeometryChange( polyGeomMgr );
2173  frame()->SetMsgPanel( zoneTool.GetZone() );
2174  }
2175  else
2176  {
2177  evt->SetPassEvent();
2178  }
2179  }
2180  /*else if( evt->IsAction( &ACTIONS::updateUnits ) )
2181  {
2182  // If we ever have an assistant here that reports dimensions, we'll want to
2183  // update its units here....
2184  // zoneAsst.SetUnits( frame()->GetUserUnits() );
2185  // m_view->Update( &zoneAsst );
2186  evt->SetPassEvent();
2187  }*/
2188  else
2189  {
2190  evt->SetPassEvent();
2191  }
2192 
2193  } // end while
2194 
2196  m_controls->ForceCursorPosition( false );
2197  return 0;
2198 }
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:215
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:121
PCB_LAYER_ID m_layer
The zone mode to operate in.
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:147
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:70
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:216
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:443
Generic, UI-independent tool event.
Definition: tool_event.h:173
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:37
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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:471
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:295
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:158
#define _(s)
Definition: 3d_actions.cpp:33
An adjunct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from ...
static TOOL_ACTION deleteLastPoint
Definition: pcb_actions.h:167
void Activate()
Run the tool.
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
bool HasPosition() const
Definition: tool_event.h:261
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:284
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:168

References _, TOOL_INTERACTIVE::Activate(), POLYGON_GEOM_MANAGER::AddPoint(), ARROW, BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), PCB_ACTIONS::closeOutline, POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DeleteLastCorner(), PCB_ACTIONS::deleteLastPoint, POLYGON_GEOM_MANAGER::DIRECT, PCB_ACTIONS::drawPolygon, PCB_ACTIONS::drawRuleArea, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetActiveLayer(), PCB_BASE_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_ALT, MD_CTRL, MD_SHIFT, POLYGON_GEOM_MANAGER::NewPointClosesOutline(), PCB_BASE_EDIT_FRAME::OnEditItemRequest(), ZONE_CREATE_HELPER::OnGeometryChange(), TOOL_EVENT::Parameter(), PENCIL, TOOLS_HOLDER::PopTool(), TOOL_EVENT::Position(), TOOL_MANAGER::PrimeTool(), PCB_ACTIONS::properties, TOOLS_HOLDER::PushTool(), 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 155 of file pcb_tool_base.h.

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

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(), 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(), 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(), 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 236 of file drawing_tool.cpp.

237 {
238  return m_mode;
239 }

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

186  {
187 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
188  wxASSERT( dynamic_cast<T*>( getToolHolderInt() ) );
189 #endif
190  return static_cast<T*>( getToolHolderInt() );
191  }
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 121 of file tool_base.h.

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

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

145  {
146  return m_toolMgr;
147  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215

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 197 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 134 of file tool_base.h.

135  {
136  return m_toolName;
137  }
std::string m_toolName
Definition: tool_base.h:214

References TOOL_BASE::m_toolName.

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

◆ getSegmentWidth()

int DRAWING_TOOL::getSegmentWidth ( PCB_LAYER_ID  aLayer) const
private

Definition at line 2606 of file drawing_tool.cpp.

2607 {
2608  assert( m_board );
2609  return m_board->GetDesignSettings().GetLineThickness( aLayer );
2610 }
BOARD * m_board
Definition: drawing_tool.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
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 1918 of file drawing_tool.cpp.

1919 {
1920  bool clearSelection = false;
1921  *aZone = nullptr;
1922 
1923  // not an action that needs a source zone
1924  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1925  return true;
1926 
1928  const PCB_SELECTION& selection = selTool->GetSelection();
1929 
1930  if( selection.Empty() )
1931  {
1932  clearSelection = true;
1934  }
1935 
1936  // we want a single zone
1937  if( selection.Size() == 1 )
1938  *aZone = dyn_cast<ZONE*>( selection[0] );
1939 
1940  // expected a zone, but didn't get one
1941  if( !*aZone )
1942  {
1943  if( clearSelection )
1945 
1946  return false;
1947  }
1948 
1949  return true;
1950 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
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:122
int Size() const
Returns the number of selected parts.
Definition: selection.h:128
The selection tool: currently supports:
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:60

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

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

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:289
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215

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::FindComponentAndItem(), 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(), 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(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PL_DRAWING_TOOLS::PlaceItem(), BOARD_EDITOR_CONTROL::PlaceTarget(), 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:215
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:291

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(), BOARD_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), BOARD_INSPECTION_TOOL::HighlightNetTool(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), 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(), 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:59
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(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), CONVERT_TOOL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::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(), BOARD_INSPECTION_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), PCB_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ Init()

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

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

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

504 {
506  return -1;
507 
508  bool cancelled = false;
509 
510  BOARD_COMMIT commit( m_frame );
511 
513  m_controls->ShowCursor( true );
514  // do not capture or auto-pan until we start placing the table
515 
516  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
517 
518  std::string tool = aEvent.GetCommandStr().get();
519  m_frame->PushTool( tool );
520  Activate();
521 
522  // Prime the pump
523  if( aEvent.HasPosition() )
525 
526  // Main loop: keep receiving events
527  wxPoint wxCursorPosition = wxPoint();
528  wxPoint wxPreviousCursorPosition = wxPoint( 0, 0 );
529 
530  view()->ClearPreview();
531  view()->InitPreview();
532 
533  for( auto item : aPreview )
534  {
535  item->Move( wxCursorPosition - wxPreviousCursorPosition );
536  view()->AddToPreview( item );
537  }
538 
539  while( TOOL_EVENT* evt = Wait() )
540  {
543  wxCursorPosition.x = pos.x;
544  wxCursorPosition.y = pos.y;
545 
546  if( evt->IsCancelInteractive() )
547  {
548  m_frame->PopTool( tool );
549  cancelled = true;
550  break;
551  }
552 
553  if( evt->IsMotion() )
554  {
555  view()->ShowPreview( false );
556 
557  for( auto item : aPreview )
558  {
559  item->Move( wxCursorPosition - wxPreviousCursorPosition );
560  }
561 
562  view()->ShowPreview( true );
563 
564  wxPreviousCursorPosition.x = wxCursorPosition.x;
565  wxPreviousCursorPosition.y = wxCursorPosition.y;
566 
567  }
568  else if( evt->IsActivate() )
569  {
570 
571  if( evt->IsMoveTool() )
572  {
573  // leave ourselves on the stack so we come back after the move
574  cancelled = true;
575  break;
576  }
577  else
578  {
579  m_frame->PopTool( tool );
580  cancelled = true;
581  break;
582  }
583  }
584  else if( evt->IsClick( BUT_RIGHT ) )
585  {
587  }
588  else if( evt->IsClick( BUT_LEFT ) )
589  {
590  if( aLayers != NULL )
591  {
592  PCB_LAYER_ID targetLayer = frame()->SelectOneLayer(
594  *aLayers, wxGetMousePosition() );
595 
596  view()->ClearPreview();
597 
598  if( targetLayer == PCB_LAYER_ID::UNDEFINED_LAYER )
599  {
600  // The user did not pick any layer.
601  m_frame->PopTool( tool );
602  cancelled = true;
603  break;
604  }
605 
606  for( auto item : aItems )
607  {
608  if( item->Type() == PCB_GROUP_T )
609  {
610  static_cast<PCB_GROUP*>( item )->SetLayerRecursive( targetLayer, 200 );
611  }