KiCad PCB EDA Suite
drawing_tool.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014-2017 CERN
5  * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include "drawing_tool.h"
27 #include "pcb_actions.h"
28 
29 #include <pcb_edit_frame.h>
30 #include <class_draw_panel_gal.h>
31 #include <project.h>
32 #include <id.h>
33 #include <pcbnew_id.h>
34 #include <confirm.h>
37 
38 #include <view/view_group.h>
39 #include <view/view_controls.h>
40 #include <view/view.h>
42 #include <tool/tool_manager.h>
43 #include <geometry/direction45.h>
44 #include <ratsnest_data.h>
45 #include <board_commit.h>
46 #include <scoped_set_reset.h>
47 #include <bitmaps.h>
48 #include <hotkeys.h>
49 #include <painter.h>
50 #include <status_popup.h>
51 #include "grid_helper.h"
52 
54 
55 #include <class_board.h>
56 #include <class_edge_mod.h>
57 #include <class_pcb_text.h>
58 #include <class_dimension.h>
59 #include <class_zone.h>
60 #include <class_module.h>
61 
62 #include <tools/selection_tool.h>
63 #include <tools/tool_event_utils.h>
65 
67 
68 // Drawing tool actions
69 TOOL_ACTION PCB_ACTIONS::drawLine( "pcbnew.InteractiveDrawing.line",
70  AS_GLOBAL, 0,
71  _( "Draw Line" ), _( "Draw a line" ), NULL, AF_ACTIVATE );
72 
73 TOOL_ACTION PCB_ACTIONS::drawGraphicPolygon( "pcbnew.InteractiveDrawing.graphicPolygon",
74  AS_GLOBAL, 0,
75  _( "Draw Graphic Polygon" ), _( "Draw a graphic polygon" ), NULL, AF_ACTIVATE );
76 
77 TOOL_ACTION PCB_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle",
78  AS_GLOBAL, 0,
79  _( "Draw Circle" ), _( "Draw a circle" ), NULL, AF_ACTIVATE );
80 
81 TOOL_ACTION PCB_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
82  AS_GLOBAL, 0,
83  _( "Draw Arc" ), _( "Draw an arc" ), NULL, AF_ACTIVATE );
84 
85 TOOL_ACTION PCB_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text",
86  AS_GLOBAL, 0,
87  _( "Add Text" ), _( "Add a text" ), NULL, AF_ACTIVATE );
88 
89 TOOL_ACTION PCB_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
90  AS_GLOBAL, 0,
91  _( "Add Dimension" ), _( "Add a dimension" ), NULL, AF_ACTIVATE );
92 
93 TOOL_ACTION PCB_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone",
94  AS_GLOBAL, 0,
95  _( "Add Filled Zone" ), _( "Add a filled zone" ), NULL, AF_ACTIVATE );
96 
97 TOOL_ACTION PCB_ACTIONS::drawVia( "pcbnew.InteractiveDrawing.via",
98  AS_GLOBAL, 0,
99  _( "Add Vias" ), _( "Add free-standing vias" ), NULL, AF_ACTIVATE );
100 
101 TOOL_ACTION PCB_ACTIONS::drawZoneKeepout( "pcbnew.InteractiveDrawing.keepout",
102  AS_GLOBAL, 0,
103  _( "Add Keepout Area" ), _( "Add a keepout area" ), NULL, AF_ACTIVATE );
104 
105 TOOL_ACTION PCB_ACTIONS::drawZoneCutout( "pcbnew.InteractiveDrawing.zoneCutout",
106  AS_GLOBAL, 0,
107  _( "Add a Zone Cutout" ), _( "Add a cutout area of an existing zone" ),
108  add_zone_cutout_xpm, AF_ACTIVATE );
109 
110 TOOL_ACTION PCB_ACTIONS::drawSimilarZone( "pcbnew.InteractiveDrawing.similarZone",
111  AS_GLOBAL, 0,
112  _( "Add a Similar Zone" ), _( "Add a zone with the same settings as an existing zone" ),
113  add_zone_xpm, AF_ACTIVATE );
114 
115 TOOL_ACTION PCB_ACTIONS::placeDXF( "pcbnew.InteractiveDrawing.placeDXF",
116  AS_GLOBAL, 0,
117  "Place DXF", "", NULL, AF_ACTIVATE );
118 
119 TOOL_ACTION PCB_ACTIONS::setAnchor( "pcbnew.InteractiveDrawing.setAnchor",
120  AS_GLOBAL, 0,
121  _( "Place the Footprint Anchor" ), _( "Place the footprint anchor" ),
122  NULL, AF_ACTIVATE );
123 
124 TOOL_ACTION PCB_ACTIONS::incWidth( "pcbnew.InteractiveDrawing.incWidth",
125  AS_CONTEXT, '+',
126  _( "Increase Line Width" ), _( "Increase the line width" ) );
127 
128 TOOL_ACTION PCB_ACTIONS::decWidth( "pcbnew.InteractiveDrawing.decWidth",
129  AS_CONTEXT, '-',
130  _( "Decrease Line Width" ), _( "Decrease the line width" ) );
131 
132 TOOL_ACTION PCB_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture",
134  _( "Switch Arc Posture" ), _( "Switch the arc posture" ) );
135 
136 /*
137  * Contextual actions
138  */
139 
140 static TOOL_ACTION deleteLastPoint( "pcbnew.InteractiveDrawing.deleteLastPoint",
141  AS_CONTEXT, WXK_BACK,
142  _( "Delete Last Point" ), _( "Delete the last point added to the current item" ),
143  undo_xpm );
144 
145 static TOOL_ACTION closeZoneOutline( "pcbnew.InteractiveDrawing.closeZoneOutline",
146  AS_CONTEXT, 0,
147  _( "Close Zone Outline" ), _( "Close the outline of a zone in progress" ),
148  checked_ok_xpm );
149 
150 
152  PCB_TOOL( "pcbnew.InteractiveDrawing" ),
153  m_view( nullptr ), m_controls( nullptr ),
154  m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
155  m_lineWidth( 1 ),
156  m_menu( *this )
157 {
158 }
159 
160 
162 {
163 }
164 
165 
167 {
168  auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
169  return m_mode != MODE::NONE;
170  };
171 
172  // some interactive drawing tools can undo the last point
173  auto canUndoPoint = [ this ] ( const SELECTION& aSel ) {
174  return m_mode == MODE::ARC || m_mode == MODE::ZONE;
175  };
176 
177  // functor for zone-only actions
178  auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) {
179  return m_mode == MODE::ZONE;
180  };
181 
182  auto& ctxMenu = m_menu.GetMenu();
183 
184  // cancel current toool goes in main context menu at the top if present
185  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1000 );
186 
187  // tool-specific actions
188  ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 1000 );
189  ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 1000 );
190 
191  ctxMenu.AddSeparator( activeToolFunctor, 1000 );
192 
193  // Type-specific sub-menus will be added for us by other tools
194  // For example, zone fill/unfill is provided by the PCB control tool
195 
196  // Finally, add the standard zoom/grid items
197  m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
198 
199  return true;
200 }
201 
202 
204 {
205  // Init variables used by every drawing tool
206  m_view = getView();
208  m_board = getModel<BOARD>();
209  m_frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
210 }
211 
212 
214 {
215  return m_mode;
216 }
217 
218 
219 int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
220 {
222  DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
223 
224  OPT<VECTOR2D> startingPoint;
225  BOARD_COMMIT commit( m_frame );
226 
227  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
228 
230  wxCURSOR_PENCIL, _( "Add graphic line" ) );
232 
233  while( drawSegment( S_SEGMENT, line, startingPoint ) )
234  {
235  if( line )
236  {
237  commit.Add( line );
238  commit.Push( _( "Draw a line segment" ) );
239  startingPoint = VECTOR2D( line->GetEnd() );
240  }
241  else
242  {
243  startingPoint = NULLOPT;
244  }
245 
246  line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
247  }
248 
250 
251  return 0;
252 }
253 
254 
256 {
258  DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
259  BOARD_COMMIT commit( m_frame );
260 
261  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
262 
264  wxCURSOR_PENCIL, _( "Add graphic circle" ) );
266 
267  while( drawSegment( S_CIRCLE, circle ) )
268  {
269  if( circle )
270  {
271  commit.Add( circle );
272  commit.Push( _( "Draw a circle" ) );
273  }
274 
275  circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
276  }
277 
279 
280  return 0;
281 }
282 
283 
284 int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
285 {
287  DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
288  BOARD_COMMIT commit( m_frame );
289 
290  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
291 
293  wxCURSOR_PENCIL, _( "Add graphic arc" ) );
295 
296  while( drawArc( arc ) )
297  {
298  if( arc )
299  {
300  commit.Add( arc );
301  commit.Push( _( "Draw an arc" ) );
302  }
303 
304  arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
305  }
306 
308 
309  return 0;
310 }
311 
312 
314 {
315  BOARD_ITEM* text = NULL;
316  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
318  SELECTION& selection = selTool->GetSelection();
319  BOARD_COMMIT commit( m_frame );
320 
322  m_controls->ShowCursor( true );
323  m_controls->SetSnapping( true );
324  // do not capture or auto-pan until we start placing some text
325 
326  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
327 
328  Activate();
330  wxCURSOR_PENCIL, _( "Add text" ) );
331 
332  bool reselect = false;
333 
334  // Main loop: keep receiving events
335  while( OPT_TOOL_EVENT evt = Wait() )
336  {
337  VECTOR2I cursorPos = m_controls->GetCursorPosition();
338 
339  if( reselect && text )
341 
343  {
344  if( text )
345  {
347 
348  // Delete the old text and have another try
349  delete text;
350  text = NULL;
351 
352  m_controls->SetAutoPan( false );
353  m_controls->CaptureCursor( false );
354  m_controls->ShowCursor( true );
355  }
356  else
357  break;
358 
359  if( evt->IsActivate() ) // now finish unconditionally
360  break;
361  }
362  else if( evt->IsClick( BUT_RIGHT ) )
363  {
365  }
366  else if( evt->IsClick( BUT_LEFT ) )
367  {
368  if( !text )
369  {
370  // Init the new item attributes
371  if( m_editModules )
372  {
373  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() );
374 
375  textMod->SetLayer( m_frame->GetActiveLayer() );
376  textMod->SetTextSize( dsnSettings.m_ModuleTextSize );
377  textMod->SetThickness( dsnSettings.m_ModuleTextWidth );
378  textMod->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
379 
380  DIALOG_EDIT_FPTEXT textDialog( m_frame, m_frame, textMod, NULL );
381  bool placing;
382 
383  RunMainStack([&]() {
384  placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 );
385  } );
386 
387  if( placing )
388  text = textMod;
389  else
390  delete textMod;
391  }
392  else
393  {
394  TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() );
395  // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
396  textPcb->SetFlags( IS_NEW );
397 
399  textPcb->SetLayer( layer );
400 
401  // Set the mirrored option for layers on the BACK side of the board
402  if( IsBackLayer( layer ) )
403  textPcb->SetMirrored( true );
404 
405  textPcb->SetTextSize( dsnSettings.m_PcbTextSize );
406  textPcb->SetThickness( dsnSettings.m_PcbTextWidth );
407  textPcb->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
408 
409  RunMainStack([&]() {
410  getEditFrame<PCB_EDIT_FRAME>()->InstallTextPCBOptionsFrame( textPcb, NULL );
411  } );
412 
413  if( textPcb->GetText().IsEmpty() )
414  delete textPcb;
415  else
416  text = textPcb;
417  }
418 
419  if( text == NULL )
420  continue;
421 
422  m_controls->CaptureCursor( true );
423  m_controls->SetAutoPan( true );
424 
426  }
427  else
428  {
429  text->ClearFlags();
431 
432  commit.Add( text );
433  commit.Push( _( "Place a text" ) );
434 
435  m_controls->CaptureCursor( false );
436  m_controls->SetAutoPan( false );
437  m_controls->ShowCursor( true );
438 
439  text = NULL;
440  }
441  }
442  else if( text && evt->IsMotion() )
443  {
444  text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
445  selection.SetReferencePoint( cursorPos );
446  m_view->Update( &selection );
447  frame()->SetMsgPanel( text );
448  }
449 
450  else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
451  {
452  // Calling 'Properties' action clears the selection, so we need to restore it
453  reselect = true;
454  }
455  }
456 
457  frame()->SetMsgPanel( board() );
459 
460  return 0;
461 }
462 
463 
465 {
466  DIMENSION* dimension = NULL;
467  BOARD_COMMIT commit( m_frame );
468  int maxThickness;
469 
470  // Add a VIEW_GROUP that serves as a preview for the new item
471  SELECTION preview;
472 
473  m_view->Add( &preview );
474 
476  m_controls->ShowCursor( true );
477  m_controls->SetSnapping( true );
478 
479  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
480 
481  Activate();
482  m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
484 
485  enum DIMENSION_STEPS
486  {
487  SET_ORIGIN = 0,
488  SET_END,
489  SET_HEIGHT,
490  FINISHED
491  };
492  int step = SET_ORIGIN;
493 
494  // Main loop: keep receiving events
495  while( OPT_TOOL_EVENT evt = Wait() )
496  {
497  VECTOR2I cursorPos = m_controls->GetCursorPosition();
498 
500  {
501  if( step != SET_ORIGIN ) // start from the beginning
502  {
503  preview.Clear();
504 
505  delete dimension;
506  step = SET_ORIGIN;
507  }
508  else
509  break;
510 
511  if( evt->IsActivate() ) // now finish unconditionally
512  break;
513  }
514  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
515  {
517  dimension->SetWidth( m_lineWidth );
518  m_view->Update( &preview );
519  frame()->SetMsgPanel( dimension );
520  }
521  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
522  {
523  if( m_lineWidth > WIDTH_STEP )
524  {
526  dimension->SetWidth( m_lineWidth );
527  m_view->Update( &preview );
528  frame()->SetMsgPanel( dimension );
529  }
530  }
531  else if( evt->IsClick( BUT_RIGHT ) )
532  {
534  }
535  else if( evt->IsClick( BUT_LEFT ) )
536  {
537  switch( step )
538  {
539  case SET_ORIGIN:
540  {
541  PCB_LAYER_ID layer = getDrawingLayer();
542 
543  if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
544  layer = Dwgs_User;
545 
546  // Init the new item attributes
547  dimension = new DIMENSION( m_board );
548  dimension->SetLayer( layer );
549  dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
550  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
552 
554  maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetTextSize() );
555 
556  if( width > maxThickness )
557  width = maxThickness;
558 
559  dimension->Text().SetThickness( width );
560  dimension->SetWidth( width );
561  dimension->AdjustDimensionDetails();
562 
563  preview.Add( dimension );
564  frame()->SetMsgPanel( dimension );
565 
566  m_controls->SetAutoPan( true );
567  m_controls->CaptureCursor( true );
568  }
569  break;
570 
571  case SET_END:
572  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
573 
574  // Dimensions that have origin and end in the same spot are not valid
575  if( dimension->GetOrigin() == dimension->GetEnd() )
576  --step;
577 
578  break;
579 
580  case SET_HEIGHT:
581  {
582  if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
583  {
584  assert( dimension->GetOrigin() != dimension->GetEnd() );
585  assert( dimension->GetWidth() > 0 );
586 
587  preview.Remove( dimension );
588 
589  commit.Add( dimension );
590  commit.Push( _( "Draw a dimension" ) );
591  }
592  }
593  break;
594  }
595 
596  if( ++step == FINISHED )
597  {
598  step = SET_ORIGIN;
599  m_controls->SetAutoPan( false );
600  m_controls->CaptureCursor( false );
601  }
602  }
603  else if( evt->IsMotion() )
604  {
605  switch( step )
606  {
607  case SET_END:
608  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
609  break;
610 
611  case SET_HEIGHT:
612  {
613  // Calculating the direction of travel perpendicular to the selected axis
614  double angle = dimension->GetAngle() + ( M_PI / 2 );
615 
616  wxPoint pos( cursorPos.x, cursorPos.y );
617  wxPoint delta( pos - dimension->m_featureLineDO );
618  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
619  dimension->SetHeight( height );
620  }
621  break;
622  }
623 
624  // Show a preview of the item
625  m_view->Update( &preview );
626  if( step )
627  frame()->SetMsgPanel( dimension );
628  else
629  frame()->SetMsgPanel( board() );
630  }
631  }
632 
633  if( step != SET_ORIGIN )
634  delete dimension;
635 
636  m_view->Remove( &preview );
637  frame()->SetMsgPanel( board() );
639 
640  return 0;
641 }
642 
643 
644 int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
645 {
646  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
647 
648  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
649 
650  return drawZone( false, ZONE_MODE::ADD );
651 }
652 
653 
655 {
656  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::KEEPOUT );
657 
658  m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
659 
660  return drawZone( true, ZONE_MODE::ADD );
661 }
662 
663 
665 {
666  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
667 
668  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zone cutout" ) );
669 
670  return drawZone( false, ZONE_MODE::CUTOUT );
671 }
672 
673 
675 {
676  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::GRAPHIC_POLYGON );
677 
679  wxCURSOR_PENCIL, _( "Add graphic polygon" ) );
680 
681  return drawZone( false, ZONE_MODE::GRAPHIC_POLYGON );
682 }
683 
684 
686 {
687  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
688 
689  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add similar zone" ) );
690 
691  return drawZone( false, ZONE_MODE::SIMILAR );
692 }
693 
694 
695 int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
696 {
697  if( !m_frame->GetModel() )
698  return 0;
699 
700  DIALOG_DXF_IMPORT dlg( m_frame );
701  int dlgResult = dlg.ShowModal();
702 
703  const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
704 
705  if( dlgResult != wxID_OK || list.empty() )
706  return 0;
707 
708  VECTOR2I cursorPos = m_controls->GetCursorPosition();
709  VECTOR2I delta = cursorPos - list.front()->GetPosition();
710 
711  // Add a VIEW_GROUP that serves as a preview for the new item
712  SELECTION preview;
713  BOARD_COMMIT commit( m_frame );
714 
715  // Build the undo list & add items to the current view
716  for( auto item : list )
717  {
718  assert( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
719  preview.Add( item );
720  }
721 
722  BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
723  m_view->Add( &preview );
724 
726  m_controls->ShowCursor( true );
727  m_controls->SetSnapping( true );
728 
729  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
730 
731  Activate();
732 
733  // Main loop: keep receiving events
734  while( OPT_TOOL_EVENT evt = Wait() )
735  {
736  cursorPos = m_controls->GetCursorPosition();
737 
738  if( evt->IsMotion() )
739  {
740  delta = cursorPos - firstItem->GetPosition();
741 
742  for( auto item : preview )
743  static_cast<BOARD_ITEM*>( item )->Move( wxPoint( delta.x, delta.y ) );
744 
745  m_view->Update( &preview );
746  }
747  else if( evt->Category() == TC_COMMAND )
748  {
749  // TODO it should be handled by EDIT_TOOL, so add items and select?
750  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
751  {
752  const auto rotationPoint = wxPoint( cursorPos.x, cursorPos.y );
753  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
754  *m_frame, *evt );
755 
756  for( auto item : preview )
757  {
758  static_cast<BOARD_ITEM*>( item )->Rotate( rotationPoint, rotationAngle );
759  }
760 
761  m_view->Update( &preview );
762  }
763  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
764  {
765  for( auto item : preview )
766  static_cast<BOARD_ITEM*>( item )->Flip( wxPoint( cursorPos.x, cursorPos.y ) );
767 
768  m_view->Update( &preview );
769  }
770  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
771  {
772  preview.FreeItems();
773  break;
774  }
775  }
776  else if( evt->IsClick( BUT_RIGHT ) )
777  {
779  }
780  else if( evt->IsClick( BUT_LEFT ) )
781  {
782  // Place the drawing
784 
785  for( auto item : preview )
786  {
787  if( m_editModules )
788  {
789  // Modules use different types for the same things,
790  // so we need to convert imported items to appropriate classes.
791  BOARD_ITEM* converted = NULL;
792 
793  switch( item->Type() )
794  {
795  case PCB_TEXT_T:
796  {
797  TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item );
798  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent );
799 
800  // Assignment operator also copies the item PCB_TEXT_T type,
801  // so it cannot be added to a module which handles PCB_MODULE_TEXT_T
802  textMod->SetText( text->GetText() );
803 #if 0
804  textMod->SetTextSize( text->GetTextSize() );
805  textMod->SetThickness( text->GetThickness() );
806  textMod->SetOrientation( text->GetTextAngle() );
807  textMod->SetTextPos( text->GetTextPos() );
808  textMod->SetTextSize( text->GetTextSize() );
809  textMod->SetVisible( text->GetVisible() );
810  textMod->SetMirrored( text->IsMirrored() );
811  textMod->SetItalic( text->IsItalic() );
812  textMod->SetBold( text->IsBold() );
813  textMod->SetHorizJustify( text->GetHorizJustify() );
814  textMod->SetVertJustify( text->GetVertJustify() );
815  textMod->SetMultilineAllowed( text->IsMultilineAllowed() );
816 #else
817  textMod->EDA_TEXT::SetEffects( *text );
818  textMod->SetLocalCoord(); // using changed SetTexPos() via SetEffects()
819 #endif
820  converted = textMod;
821  break;
822  }
823 
824  case PCB_LINE_T:
825  {
826  DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item );
827  EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent );
828 
829  // Assignment operator also copies the item PCB_LINE_T type,
830  // so it cannot be added to a module which handles PCB_MODULE_EDGE_T
831  modSeg->SetWidth( seg->GetWidth() );
832  modSeg->SetStart( seg->GetStart() );
833  modSeg->SetEnd( seg->GetEnd() );
834  modSeg->SetAngle( seg->GetAngle() );
835  modSeg->SetShape( seg->GetShape() );
836  modSeg->SetType( seg->GetType() );
837  modSeg->SetBezControl1( seg->GetBezControl1() );
838  modSeg->SetBezControl2( seg->GetBezControl2() );
839  modSeg->SetBezierPoints( seg->GetBezierPoints() );
840  modSeg->SetPolyShape( seg->GetPolyShape() );
841  modSeg->SetLocalCoord();
842  converted = modSeg;
843  break;
844  }
845 
846  default:
847  assert( false );
848  break;
849  }
850 
851  if( converted )
852  converted->SetLayer( static_cast<BOARD_ITEM*>( item )->GetLayer() );
853 
854  delete item;
855  item = converted;
856  }
857 
858  if( item )
859  commit.Add( item );
860  }
861 
862  commit.Push( _( "Place a DXF drawing" ) );
863  break;
864  }
865  }
866 
867  preview.Clear();
868  m_view->Remove( &preview );
869 
870  return 0;
871 }
872 
873 
875 {
876  assert( m_editModules );
877 
878  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
879 
880  Activate();
881  m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL,
882  _( "Place the footprint anchor" ) );
883 
884  m_controls->ShowCursor( true );
885  m_controls->SetSnapping( true );
886  m_controls->SetAutoPan( true );
887  m_controls->CaptureCursor( false );
888 
889  while( OPT_TOOL_EVENT evt = Wait() )
890  {
891  if( evt->IsClick( BUT_LEFT ) )
892  {
894  BOARD_COMMIT commit( m_frame );
895  commit.Modify( module );
896 
897  // set the new relative internal local coordinates of footprint items
898  VECTOR2I cursorPos = m_controls->GetCursorPosition();
899  wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
900  module->MoveAnchorPosition( moveVector );
901 
902  commit.Push( _( "Move the footprint reference anchor" ) );
903 
904  // Usually, we do not need to change twice the anchor position,
905  // so deselect the active tool
906  break;
907  }
908  else if( evt->IsClick( BUT_RIGHT ) )
909  {
911  }
912  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
913  break;
914  }
915 
917 
918  return 0;
919 }
920 
921 
922 bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
923  OPT<VECTOR2D> aStartingPoint )
924 {
925  // Only two shapes are currently supported
926  assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
927 
928  DRAWSEGMENT line45;
929 
930  // Add a VIEW_GROUP that serves as a preview for the new item
931  SELECTION preview;
932  m_view->Add( &preview );
933 
935  m_controls->ShowCursor( true );
936  m_controls->SetSnapping( true );
937 
938  Activate();
939 
940  bool direction45 = false; // 45 degrees only mode
941  bool started = false;
942  bool IsOCurseurSet = ( m_frame->GetScreen()->m_O_Curseur != wxPoint( 0, 0 ) );
943  VECTOR2I cursorPos = m_controls->GetCursorPosition();
944 
945  if( aStartingPoint )
946  {
947  // Init the new item attributes
948  aGraphic->SetShape( (STROKE_T) aShape );
949  aGraphic->SetWidth( m_lineWidth );
950  aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) );
951  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
952  aGraphic->SetLayer( getDrawingLayer() );
953 
954  if( aShape == S_SEGMENT )
955  line45 = *aGraphic; // used only for direction 45 mode with lines
956 
957  preview.Add( aGraphic );
958  m_controls->SetAutoPan( true );
959  m_controls->CaptureCursor( true );
960 
961  if( !IsOCurseurSet )
962  m_frame->GetScreen()->m_O_Curseur = wxPoint( aStartingPoint->x, aStartingPoint->y );
963 
964  started = true;
965  }
966 
967  // Main loop: keep receiving events
968  while( OPT_TOOL_EVENT evt = Wait() )
969  {
970  cursorPos = m_controls->GetCursorPosition();
971 
972  // 45 degree angle constraint enabled with an option and toggled with Ctrl
973  const bool limit45 = ( frame()->Settings().m_use45DegreeGraphicSegments != !!( evt->Modifier( MD_CTRL ) ) );
974 
975  if( direction45 != limit45 && started && aShape == S_SEGMENT )
976  {
977  direction45 = limit45;
978 
979  if( direction45 )
980  {
981  preview.Add( &line45 );
982  make45DegLine( aGraphic, &line45 );
983  }
984  else
985  {
986  preview.Remove( &line45 );
987  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
988  }
989 
990  m_view->Update( &preview );
991  frame()->SetMsgPanel( aGraphic );
992  }
993 
995  {
996  preview.Clear();
997  m_view->Update( &preview );
998  delete aGraphic;
999  aGraphic = NULL;
1000  if( !IsOCurseurSet )
1001  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1002  break;
1003  }
1004  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1005  {
1006  aGraphic->SetLayer( getDrawingLayer() );
1007  m_view->Update( &preview );
1008  frame()->SetMsgPanel( aGraphic );
1009  }
1010  else if( evt->IsClick( BUT_RIGHT ) )
1011  {
1013  }
1014  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1015  {
1016  if( !started )
1017  {
1018  // Init the new item attributes
1019  aGraphic->SetShape( (STROKE_T) aShape );
1020  aGraphic->SetWidth( m_lineWidth );
1021  aGraphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
1022  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1023  aGraphic->SetLayer( getDrawingLayer() );
1024 
1025  if( !IsOCurseurSet )
1026  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
1027 
1028  if( aShape == S_SEGMENT )
1029  line45 = *aGraphic; // used only for direction 45 mode with lines
1030 
1031  preview.Add( aGraphic );
1032  frame()->SetMsgPanel( aGraphic );
1033  m_controls->SetAutoPan( true );
1034  m_controls->CaptureCursor( true );
1035 
1036  started = true;
1037  }
1038  else
1039  {
1040  if( aGraphic->GetEnd() == aGraphic->GetStart()
1041  || ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT ) )
1042  // User has clicked twice in the same spot
1043  {
1044  // a clear sign that the current drawing is finished
1045  // Now we have to add the helper line as well, unless it is zero-length
1046  if( direction45 && line45.GetStart() != aGraphic->GetStart() )
1047  {
1048  BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
1049  DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( (MODULE*) parent )
1050  : new DRAWSEGMENT;
1051 
1052  // Copy coordinates, layer, etc.
1053  *static_cast<DRAWSEGMENT*>( l ) = line45;
1054  l->SetEnd( aGraphic->GetStart() );
1055 
1056  BOARD_COMMIT commit( m_frame );
1057  commit.Add( l );
1058  commit.Push( _( "Draw a line" ) );
1059  }
1060 
1061  delete aGraphic;
1062  aGraphic = NULL;
1063  }
1064 
1065  preview.Clear();
1066  break;
1067  }
1068  }
1069  else if( evt->IsMotion() )
1070  {
1071  // 45 degree lines
1072  if( direction45 && aShape == S_SEGMENT )
1073  make45DegLine( aGraphic, &line45 );
1074  else
1075  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1076 
1077  m_view->Update( &preview );
1078 
1079  if( started )
1080  frame()->SetMsgPanel( aGraphic );
1081  else
1082  frame()->SetMsgPanel( board() );
1083  }
1084  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1085  {
1087  aGraphic->SetWidth( m_lineWidth );
1088  line45.SetWidth( m_lineWidth );
1089  m_view->Update( &preview );
1090  frame()->SetMsgPanel( aGraphic );
1091  }
1092  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1093  {
1095  aGraphic->SetWidth( m_lineWidth );
1096  line45.SetWidth( m_lineWidth );
1097  m_view->Update( &preview );
1098  frame()->SetMsgPanel( aGraphic );
1099  }
1100  else if( evt->IsAction( &PCB_ACTIONS::resetCoords ) )
1101  {
1102  IsOCurseurSet = true;
1103  }
1104  }
1105 
1106  if( !IsOCurseurSet ) // reset the relative coordinte if it was not set before
1107  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1108 
1109  m_view->Remove( &preview );
1110  frame()->SetMsgPanel( board() );
1111  m_controls->SetAutoPan( false );
1112  m_controls->CaptureCursor( false );
1113 
1114  return started;
1115 }
1116 
1117 
1123  DRAWSEGMENT& aArc )
1124 {
1125  auto vec = aMgr.GetOrigin();
1126 
1127  aArc.SetCenter( { vec.x, vec.y } );
1128 
1129  vec = aMgr.GetStartRadiusEnd();
1130  aArc.SetArcStart( { vec.x, vec.y } );
1131 
1132  aArc.SetAngle( RAD2DECIDEG( -aMgr.GetSubtended() ) );
1133 }
1134 
1135 
1137 {
1139 
1140  // Arc geometric construction manager
1142 
1143  // Arc drawing assistant overlay
1144  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager );
1145 
1146  // Add a VIEW_GROUP that serves as a preview for the new item
1147  SELECTION preview;
1148  m_view->Add( &preview );
1149  m_view->Add( &arcAsst );
1150 
1151  m_controls->ShowCursor( true );
1152  m_controls->SetSnapping( true );
1153 
1154  Activate();
1155 
1156  bool firstPoint = false;
1157 
1158  // Main loop: keep receiving events
1159  while( OPT_TOOL_EVENT evt = Wait() )
1160  {
1161  const VECTOR2I cursorPos = m_controls->GetCursorPosition();
1162 
1163  if( evt->IsClick( BUT_LEFT ) )
1164  {
1165  if( !firstPoint )
1166  {
1167  m_controls->SetAutoPan( true );
1168  m_controls->CaptureCursor( true );
1169 
1170  PCB_LAYER_ID layer = getDrawingLayer();
1171 
1172  // Init the new item attributes
1173  // (non-geometric, those are handled by the manager)
1174  aGraphic->SetShape( S_ARC );
1175  aGraphic->SetWidth( m_lineWidth );
1176  aGraphic->SetLayer( layer );
1177 
1178  preview.Add( aGraphic );
1179  firstPoint = true;
1180  }
1181 
1182  arcManager.AddPoint( cursorPos, true );
1183  }
1184  else if( evt->IsAction( &deleteLastPoint ) )
1185  {
1186  arcManager.RemoveLastPoint();
1187  }
1188  else if( evt->IsMotion() )
1189  {
1190  // set angle snap
1191  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1192 
1193  // update, but don't step the manager state
1194  arcManager.AddPoint( cursorPos, false );
1195  }
1196  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
1197  {
1198  preview.Clear();
1199  delete aGraphic;
1200  aGraphic = nullptr;
1201  break;
1202  }
1203  else if( evt->IsClick( BUT_RIGHT ) )
1204  {
1206  }
1207  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1208  {
1210  aGraphic->SetWidth( m_lineWidth );
1211  m_view->Update( &preview );
1212  frame()->SetMsgPanel( aGraphic );
1213  }
1214  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1215  {
1217  aGraphic->SetWidth( m_lineWidth );
1218  m_view->Update( &preview );
1219  frame()->SetMsgPanel( aGraphic );
1220  }
1221  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1222  {
1223  arcManager.ToggleClockwise();
1224  }
1225 
1226  if( arcManager.IsComplete() )
1227  {
1228  break;
1229  }
1230  else if( arcManager.HasGeometryChanged() )
1231  {
1232  updateArcFromConstructionMgr( arcManager, *aGraphic );
1233  m_view->Update( &preview );
1234  m_view->Update( &arcAsst );
1235 
1236  if(firstPoint)
1237  frame()->SetMsgPanel( aGraphic );
1238  else
1239  frame()->SetMsgPanel( board() );
1240  }
1241  }
1242 
1243  preview.Remove( aGraphic );
1244  m_view->Remove( &arcAsst );
1245  m_view->Remove( &preview );
1246  frame()->SetMsgPanel( board() );
1247  m_controls->SetAutoPan( false );
1248  m_controls->CaptureCursor( false );
1249 
1250  return !arcManager.IsReset();
1251 }
1252 
1253 
1255 {
1256  aZone = nullptr;
1257 
1258  // not an action that needs a source zone
1259  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1260  return true;
1261 
1263  const SELECTION& selection = selTool->GetSelection();
1264 
1265  if( selection.Empty() )
1267 
1268  // we want a single zone
1269  if( selection.Size() != 1 )
1270  return false;
1271 
1272  aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
1273 
1274  // expected a zone, but didn't get one
1275  if( !aZone )
1276  return false;
1277 
1278  return true;
1279 }
1280 
1281 
1283 {
1284  auto& controls = *getViewControls();
1285  bool started = false;
1286 
1287  STATUS_TEXT_POPUP status( m_frame );
1288  status.SetTextColor( wxColour( 255, 0, 0 ) );
1289  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
1290 
1291  while( OPT_TOOL_EVENT evt = Wait() )
1292  {
1293  VECTOR2I cursorPos = controls.GetCursorPosition();
1294 
1296  {
1297  // pre-empted by another tool, give up
1298  // cancelled without an inprogress polygon, give up
1299  if( !polyGeomMgr.IsPolygonInProgress() || evt->IsActivate() )
1300  {
1301  break;
1302  }
1303 
1304  polyGeomMgr.Reset();
1305  // start again
1306  started = false;
1307 
1308  controls.SetAutoPan( false );
1309  controls.CaptureCursor( false );
1310  }
1311  else if( evt->IsClick( BUT_RIGHT ) )
1312  {
1314  }
1315  // events that lock in nodes
1316  else if( evt->IsClick( BUT_LEFT )
1317  || evt->IsDblClick( BUT_LEFT )
1318  || evt->IsAction( &closeZoneOutline ) )
1319  {
1320  // Check if it is double click / closing line (so we have to finish the zone)
1321  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
1322  || evt->IsAction( &closeZoneOutline )
1323  || polyGeomMgr.NewPointClosesOutline( cursorPos );
1324 
1325  if( endPolygon )
1326  {
1327  polyGeomMgr.SetFinished();
1328  polyGeomMgr.Reset();
1329 
1330  // ready to start again
1331  started = false;
1332  controls.SetAutoPan( false );
1333  controls.CaptureCursor( false );
1334  }
1335 
1336  // adding a corner
1337  else if( polyGeomMgr.AddPoint( cursorPos ) )
1338  {
1339  if( !started )
1340  {
1341  started = true;
1342  controls.SetAutoPan( true );
1343  controls.CaptureCursor( true );
1344  }
1345  }
1346 
1347  }
1348  else if( evt->IsAction( &deleteLastPoint ) )
1349  {
1350  polyGeomMgr.DeleteLastCorner();
1351 
1352  if( !polyGeomMgr.IsPolygonInProgress() )
1353  {
1354  // report finished as an empty shape
1355  polyGeomMgr.SetFinished();
1356 
1357  // start again
1358  started = false;
1359  controls.SetAutoPan( false );
1360  controls.CaptureCursor( false );
1361  }
1362  }
1363  else if( polyGeomMgr.IsPolygonInProgress()
1364  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1365  {
1366  polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
1369 
1370  if( polyGeomMgr.IsSelfIntersecting( true ) )
1371  {
1372  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
1373  status.Move( p );
1374  status.Popup( m_frame );
1375  status.Expire( 1500 );
1376  }
1377  else
1378  {
1379  status.Hide();
1380  }
1381  }
1382  } // end while
1383 }
1384 
1385 
1386 int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
1387 {
1388  // get a source zone, if we need one. We need it for:
1389  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1390  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1391  ZONE_CONTAINER* sourceZone = nullptr;
1392 
1393  if( !getSourceZoneForAction( aMode, sourceZone ) )
1394  return 0;
1395 
1397 
1398  params.m_keepout = aKeepout;
1399  params.m_mode = aMode;
1400  params.m_sourceZone = sourceZone;
1401 
1402  ZONE_CREATE_HELPER zoneTool( *this, params );
1403 
1404  // the geometry manager which handles the zone geometry, and
1405  // hands the calculated points over to the zone creator tool
1406  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1407 
1408  Activate(); // register for events
1409 
1410  auto& controls = *getViewControls();
1411 
1413 
1414  controls.ShowCursor( true );
1415  controls.SetSnapping( true );
1416 
1417  runPolygonEventLoop( polyGeomMgr );
1418 
1420 
1421  return 0;
1422 }
1423 
1424 
1425 void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const
1426 {
1427  VECTOR2I cursorPos = m_controls->GetCursorPosition();
1428  VECTOR2I origin( aSegment->GetStart() );
1429  DIRECTION_45 direction( origin - cursorPos );
1430  SHAPE_LINE_CHAIN newChain = direction.BuildInitialTrace( origin, cursorPos );
1431 
1432  if( newChain.PointCount() > 2 )
1433  {
1434  aSegment->SetEnd( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
1435  aHelper->SetStart( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
1436  aHelper->SetEnd( wxPoint( newChain.Point( -1 ).x, newChain.Point( -1 ).y ) );
1437  }
1438  else
1439  {
1440  aSegment->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1441  aHelper->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
1442  aHelper->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1443  }
1444 }
1445 
1446 
1447 int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
1448 {
1449  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
1450  {
1451  GRID_HELPER m_gridHelper;
1452 
1453  VIA_PLACER( PCB_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame )
1454  {}
1455 
1456  TRACK* findTrack( VIA* aVia )
1457  {
1458  const LSET lset = aVia->GetLayerSet();
1459 
1460  for( TRACK* track : m_board->Tracks() )
1461  {
1462  if( !(track->GetLayerSet() & lset ).any() )
1463  continue;
1464 
1465  if( TestSegmentHit( aVia->GetPosition(), track->GetStart(), track->GetEnd(),
1466  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
1467  return track;
1468  }
1469 
1470  return nullptr;
1471  }
1472 
1473  int findStitchedZoneNet( VIA* aVia )
1474  {
1475  const auto pos = aVia->GetPosition();
1476  const auto lset = aVia->GetLayerSet();
1477 
1478  for( auto mod : m_board->Modules() )
1479  {
1480  for( D_PAD* pad : mod->Pads() )
1481  {
1482  if( pad->HitTest( pos ) && ( pad->GetLayerSet() & lset ).any() )
1483  return -1;
1484  }
1485  }
1486 
1487  std::vector<ZONE_CONTAINER*> foundZones;
1488 
1489  for( auto zone : m_board->Zones() )
1490  {
1491  if( zone->HitTestFilledArea( pos ) )
1492  {
1493  foundZones.push_back( zone );
1494  }
1495  }
1496 
1497  std::sort( foundZones.begin(), foundZones.end(),
1498  [] ( const ZONE_CONTAINER* a, const ZONE_CONTAINER* b ) {
1499  return a->GetLayer() < b->GetLayer();
1500  } );
1501 
1502  // first take the net of the active layer
1503  for( auto z : foundZones )
1504  {
1505  if( m_frame->GetActiveLayer() == z->GetLayer() )
1506  return z->GetNetCode();
1507  }
1508 
1509  // none? take the topmost visible layer
1510  for( auto z : foundZones )
1511  {
1512  if( m_board->IsLayerVisible( z->GetLayer() ) )
1513  return z->GetNetCode();
1514  }
1515 
1516  return -1;
1517  }
1518 
1519  void SnapItem( BOARD_ITEM *aItem ) override
1520  {
1521 #if 0
1522  // If you place a Via on a track but not on its centerline, the current
1523  // connectivity algorithm will require us to put a kink in the track when
1524  // we break it (so that each of the two segments ends on the via center).
1525  // That's not ideal, and is in fact probably worse than forcing snap in
1526  // this situation.
1529 #endif
1530  {
1531  auto via = static_cast<VIA*>( aItem );
1532  wxPoint pos = via->GetPosition();
1533  TRACK* track = findTrack( via );
1534 
1535  if( track )
1536  {
1537  SEG trackSeg( track->GetStart(), track->GetEnd() );
1538  VECTOR2I snap = m_gridHelper.AlignToSegment( pos, trackSeg );
1539 
1540  aItem->SetPosition( wxPoint( snap.x, snap.y ) );
1541  }
1542  }
1543  }
1544 
1545  void PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
1546  {
1547  auto via = static_cast<VIA*>( aItem );
1548  int newNet;
1549  TRACK* track = findTrack( via );
1550 
1551  if( track )
1552  {
1553  aCommit.Modify( track );
1554  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
1555  track->SetEnd( via->GetPosition() );
1556  newTrack->SetStart( via->GetPosition() );
1557  aCommit.Add( newTrack );
1558 
1559  newNet = track->GetNetCode();
1560  }
1561  else
1562  newNet = findStitchedZoneNet( via );
1563 
1564  if( newNet > 0 )
1565  via->SetNetCode( newNet );
1566 
1567  aCommit.Add( aItem );
1568  }
1569 
1570  std::unique_ptr<BOARD_ITEM> CreateItem() override
1571  {
1572  auto& ds = m_board->GetDesignSettings();
1573  VIA* via = new VIA( m_board );
1574 
1575  via->SetNetCode( 0 );
1576  via->SetViaType( ds.m_CurrentViaType );
1577 
1578  // for microvias, the size and hole will be changed later.
1579  via->SetWidth( ds.GetCurrentViaSize() );
1580  via->SetDrill( ds.GetCurrentViaDrill() );
1581 
1582  // Usual via is from copper to component.
1583  // layer pair is B_Cu and F_Cu.
1584  via->SetLayerPair( B_Cu, F_Cu );
1585 
1586  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
1587  PCB_LAYER_ID last_layer;
1588 
1589  // prepare switch to new active layer:
1590  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
1591  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
1592  else
1593  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
1594 
1595  // Adjust the actual via layer pair
1596  switch( via->GetViaType() )
1597  {
1598  case VIA_BLIND_BURIED:
1599  via->SetLayerPair( first_layer, last_layer );
1600  break;
1601 
1602  case VIA_MICROVIA: // from external to the near neighbor inner layer
1603  {
1604  PCB_LAYER_ID last_inner_layer =
1605  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
1606 
1607  if( first_layer == B_Cu )
1608  last_layer = last_inner_layer;
1609  else if( first_layer == F_Cu )
1610  last_layer = In1_Cu;
1611  else if( first_layer == last_inner_layer )
1612  last_layer = B_Cu;
1613  else if( first_layer == In1_Cu )
1614  last_layer = F_Cu;
1615 
1616  // else error: will be removed later
1617  via->SetLayerPair( first_layer, last_layer );
1618 
1619  // Update diameter and hole size, which where set previously
1620  // for normal vias
1621  NETINFO_ITEM* net = via->GetNet();
1622 
1623  if( net )
1624  {
1625  via->SetWidth( net->GetMicroViaSize() );
1626  via->SetDrill( net->GetMicroViaDrillSize() );
1627  }
1628  }
1629  break;
1630 
1631  default:
1632  break;
1633  }
1634 
1635  return std::unique_ptr<BOARD_ITEM>( via );
1636  }
1637  };
1638 
1639  VIA_PLACER placer( frame() );
1640 
1641  frame()->SetToolID( ID_PCB_DRAW_VIA_BUTT, wxCURSOR_PENCIL, _( "Add vias" ) );
1642 
1643  doInteractiveItemPlacement( &placer, _( "Place via" ),
1645 
1646  frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
1647 
1648  return 0;
1649 }
1650 
1651 
1653 {
1667 }
1668 
1669 
1670 int DRAWING_TOOL::getSegmentWidth( unsigned int aLayer ) const
1671 {
1672  assert( m_board );
1673 
1674  if( aLayer == Edge_Cuts )
1676  else if( m_editModules )
1678  else
1680 }
1681 
1682 
1684 {
1685  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1686 
1687  if( IsCopperLayer( layer ) )
1688  {
1689  if( layer == F_Cu )
1690  layer = F_SilkS;
1691  else if( layer == B_Cu )
1692  layer = B_SilkS;
1693  else
1694  layer = Dwgs_User;
1695 
1696  m_frame->SetActiveLayer( layer );
1697  }
1698 
1699  return layer;
1700 }
1701 
1702 
1703 const unsigned int DRAWING_TOOL::WIDTH_STEP = 100000;
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
void SetCursorPosition(const VECTOR2I &aPos, LEADER_MODE aModifier)
Set the current cursor position.
static TOOL_ACTION drawLine
Activation of the drawing tool (line)
Definition: pcb_actions.h:139
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
Class ARC_GEOM_MANAGER.
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int DrawCircle(const TOOL_EVENT &aEvent)
Function DrawCircle() Starts interactively drawing a circle.
void SetTextColor(const wxColour &aColor)
Change text color.
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
void SetShape(STROKE_T aShape)
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:84
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Function SetToolID sets the tool command ID to aId and sets the cursor to aCursor.
const wxPoint & GetBezControl2() const
void SetPolyShape(const SHAPE_POLY_SET &aShape)
bool IsMultilineAllowed() const
Definition: eda_text.h:186
static TOOL_ACTION placeDXF
Activation of the drawing tool (placing a drawing from DXF file)
Definition: pcb_actions.h:178
void SetBezierPoints(const std::vector< wxPoint > &aPoints)
TEXTE_PCB class definition.
int DrawVia(const TOOL_EVENT &aEvent)
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
static TOOL_ACTION closeZoneOutline("pcbnew.InteractiveDrawing.closeZoneOutline", AS_CONTEXT, 0, _("Close Zone Outline"), _("Close the outline of a zone in progress"), checked_ok_xpm)
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
int DrawZone(const TOOL_EVENT &aEvent)
Function DrawZone() Starts interactively drawing a zone.
BOARD * m_board
Definition: drawing_tool.h:269
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:456
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:184
bool IsItalic() const
Definition: eda_text.h:168
virtual void SetPosition(const wxPoint &aPos)=0
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
MODE GetDrawingMode() const
Function GetDrawingMode.
static TOOL_ACTION drawSimilarZone
Activation of the drawing tool (drawing a similar ZONE to another one)
Definition: pcb_actions.h:169
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
This file is part of the common library.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
int m_ModuleTextWidth
Default footprint texts thickness.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:118
static TOOL_ACTION drawArc
Activation of the drawing tool (arc)
Definition: pcb_actions.h:148
void SetType(int aType)
int m_ModuleSegmentWidth
Default width for all graphic lines.
int DrawLine(const TOOL_EVENT &aEvent)
Function DrawLine() Starts interactively drawing a line.
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
int PointCount() const
Function PointCount()
VIEW_CONTROLS class definition.
int m_PcbTextWidth
current Pcb (not module) Text width
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;s a back layer.
int GetWidth() const
static TOOL_ACTION deleteLastPoint("pcbnew.InteractiveDrawing.deleteLastPoint", AS_CONTEXT, WXK_BACK, _("Delete Last Point"), _("Delete the last point added to the current item"), undo_xpm)
Class SELECTION_TOOL.
Class BOARD to handle a board.
Class STATUS_TEXT_POPUP.
Definition: status_popup.h:74
Class that computes missing connections on a PCB.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:280
void SetItalic(bool isItalic)
Definition: eda_text.h:167
static TOOL_ACTION drawZoneKeepout
Activation of the drawing tool (drawing a keepout area)
Definition: pcb_actions.h:163
EDA_ITEM * Front() const
Definition: selection.h:147
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
static TOOL_ACTION cancelInteractive
Definition: actions.h:45
int GetCopperLayerCount() const
Function GetCopperLayerCount.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:364
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:108
void SetVisible(bool aVisible)
Definition: eda_text.h:173
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
bool drawSegment(int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint=NULLOPT)
Starts drawing a selected shape (i.e.
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
double RAD2DECIDEG(double rad)
Definition: trigo.h:204
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key...
Definition: tool_action.h:174
Classes to handle copper zones.
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
usual segment : line with rounded ends
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
Function getSourceZoneForAction()
static void updateArcFromConstructionMgr(const KIGFX::PREVIEW::ARC_GEOM_MANAGER &aMgr, DRAWSEGMENT &aArc)
Update an arc DRAWSEGMENT from the current state of an Arc Geometry Manager.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
Parameters used to fully describe a zone creation process.
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
wxSize m_ModuleTextSize
Default footprint texts size.
void MoveAnchorPosition(const wxPoint &aMoveVector)
Function MoveAnchorPosition Move the reference point of the footprint It looks like a move footprint:...
double GetAngle() const
Function GetAngle Returns angle of the crossbar.
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
static TOOL_ACTION setAnchor
Activation of the drawing tool (placing the footprint anchor)
Definition: pcb_actions.h:181
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
void SetBezControl2(const wxPoint &aPoint)
static TOOL_ACTION placeText
Activation of the drawing tool (text)
Definition: pcb_actions.h:151
static const int delta[8][2]
Definition: solve.cpp:112
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
const wxPoint & GetEnd() const
Definition: class_track.h:119
Add a new zone with the same settings as an existing one.
static TOOL_ACTION resetCoords
Definition: pcb_actions.h:380
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
void AddPoint(const VECTOR2I &aPt, bool aLockIn)
Add a point to the construction manager.
Pcbnew hotkeys.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:187
static TOOL_ACTION drawGraphicPolygon
Definition: pcb_actions.h:142
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
void SetWidth(int aWidth)
Definition: class_track.h:115
int PlaceDXF(const TOOL_EVENT &aEvent)
Function PlaceDXF() Places a drawing imported from a DXF file in module editor.
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
int getSegmentWidth(unsigned int aLayer) const
Returns the appropriate width for a segment depending on the settings.
#define IS_NEW
New item, just created.
Definition: base_struct.h:109
static bool m_use45DegreeGraphicSegments
DIMENSION class definition.
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:134
MAGNETIC_PAD_OPTION_VALUES m_magneticTracks
PCB_LAYER_ID
A quick note on layer IDs:
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows to input text and its settings and then lets the u...
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
STROKE_T GetShape() const
void FreeItems()
Function FreeItems() Frees all the items that were added to the group.
Definition: view_group.cpp:167
Unconstrained point-to-point
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
Class LSET is a set of PCB_LAYER_IDs.
RAII class that sets an value at construction and resets it to the original value at destruction...
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:264
const auto NULLOPT
Definition: optional.h:9
static TOOL_ACTION drawDimension
Activation of the drawing tool (dimension)
Definition: pcb_actions.h:154
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:250
const wxPoint & GetEnd()
Function GetEnd.
VIATYPE_T GetViaType() const
Definition: class_track.h:455
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:832
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
wxSize m_PcbTextSize
current Pcb (not module) Text size
int DrawZoneKeepout(const TOOL_EVENT &aEvent)
Function DrawZoneKeepout() Starts interactively drawing a keepout area.
PCB_GENERAL_SETTINGS & Settings()
Class DIRECTION_45.
Definition: direction45.h:36
const wxPoint & GetOrigin() const
Function GetOrigin.
const wxPoint & GetStart() const
Definition: class_track.h:122
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
Arcs (with rounded ends)
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:135
Class TOOL_EVENT.
Definition: tool_event.h:162
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:274
int m_DrawSegmentWidth
current graphic line width (not EDGE layer)
SELECTION & GetSelection()
Function GetSelection()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:46
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
virtual void Popup(wxWindow *aFocus=nullptr)
MODULE * module() const
Definition: pcb_tool.h:137
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
const wxPoint & GetBezControl1() const
static TOOL_ACTION drawVia
Activation of the drawing tool (drawing a VIA)
Definition: pcb_actions.h:160
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:268
SHAPE_POLY_SET & GetPolyShape()
const SELECTION & selection() const
Definition: pcb_tool.cpp:219
int GetType() const
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
virtual void Move(const wxPoint &aWhere)
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
All active tools
Definition: tool_event.h:138
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1499
double GetSubtended() const
Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE) ...
static TOOL_ACTION drawZoneCutout
Activation of the drawing tool (drawing a ZONE cutout)
Definition: pcb_actions.h:166
void Expire(int aMsecs)
Hides the popup after a specified time.
const wxPoint GetPosition() const override
Definition: class_track.h:427
void SetMultilineAllowed(bool aAllow)
Function SetMultiLineAllowed.
Definition: eda_text.h:185
int DrawZoneCutout(const TOOL_EVENT &aEvent)
Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone...
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
void AdjustDimensionDetails(bool aDoNotChangeText=false)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
void SetStart(const wxPoint &aStart)
DRAWING_TOOL::ZONE_MODE m_mode
The zone mode to operate in
virtual const wxPoint GetPosition() const =0
void setTransitions() override
Sets up handlers for various events.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
bool m_editModules
Definition: pcb_tool.h:143
void DeleteLastCorner()
Remove the last-added point from the polygon.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
int GetNetCode() const
Function GetNetCode.
static TOOL_ACTION drawCircle
Activation of the drawing tool (circle)
Definition: pcb_actions.h:145
Definition: seg.h:36
const std::vector< wxPoint > & GetBezierPoints() const
void SetLocalCoord()
Set relative coordinates from draw coordinates.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:102
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
Definition: draw_frame.cpp:616
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:68
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
static TOOL_ACTION arcPosture
Switch posture when drawing arc.
Definition: pcb_actions.h:190
void SetLocalCoord()
Set relative coordinates.
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:283
const std::list< BOARD_ITEM * > & GetImportedItems() const
Function GetImportedItems()
bool IsSelfIntersecting(bool aIncludeLeaderPts) const
Checks whether the locked points constitute a self-intersecting outline.
int SetAnchor(const TOOL_EVENT &aEvent)
Function SetAnchor() Places the footprint anchor (only in module editor).
ZONE_CONTAINERS & Zones()
Definition: class_board.h:252
double GetAngle() const
void ToggleClockwise()
Reverse the current are direction
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
bool IsMirrored() const
Definition: eda_text.h:177
Class SHAPE_LINE_CHAIN.
int GetWidth() const
Definition: class_track.h:116
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
bool NewPointClosesOutline(const VECTOR2I &aPt) const
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
TEXTE_PCB & Text()
Class TOOL_ACTION.
Definition: tool_action.h:46
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:463
This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry ...
Class SELECTION_AREA.
Definition: arc_assistant.h:38
void Reset()
Clear the manager state and start again.
int GetWidth() const
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:182
boost::optional< T > OPT
Definition: optional.h:7
void SetEnd(const wxPoint &aEnd)
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
int DrawGraphicPolygon(const TOOL_EVENT &aEvent)
const wxPoint GetPosition() const override
void SetStart(const wxPoint &aStart)
Definition: class_track.h:121
VECTOR2I & Point(int aIndex)
Function Point()
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:334
VECTOR2I GetOrigin() const
Get the centre point of the arc (valid when state > SET_ORIGIN)
Module description (excepted pads)
const wxSize & GetTextSize() const
Definition: eda_text.h:213
Abstract interface for BOARD_ITEMs capable of storing other items inside.
bool drawArc(DRAWSEGMENT *&aGraphic)
Starts drawing an arc.
void doInteractiveItemPlacement(INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
Definition: pcb_tool.cpp:39
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
int m_EdgeSegmentWidth
current graphic line width (EDGE layer only)
bool m_keepout
Should create a keepout zone?
void SetWidth(int aWidth)
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
Add a new zone/keepout with fresh settings.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:162
bool AddPoint(const VECTOR2I &aPt)
Lock in a polygon point.
int DrawSimilarZone(const TOOL_EVENT &aEvent)
Function DrawSimilarZone() Starts interactively drawing a zone with same settings as an existing zone...
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void SetBold(bool aBold)
Definition: eda_text.h:170
wxPoint m_featureLineDO
void Flip(T &aValue)
void runPolygonEventLoop(POLYGON_GEOM_MANAGER &aPolyGeomMgr)
Run the event loop for polygon creation, sending user input on to the given POLYGON_GEOM_MANAGER for ...
void SetFinished()
Mark the polygon finished and update the client.
int DrawArc(const TOOL_EVENT &aEvent)
Function DrawArc() Starts interactively drawing an arc.
Make a cutout to an existing zone.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
const wxPoint GetPosition() const override
Definition: class_module.h:182
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
#define mod(a, n)
Definition: greymap.cpp:24
static TOOL_ACTION drawZone
Activation of the drawing tool (drawing a ZONE)
Definition: pcb_actions.h:157
Class DIMENSION.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc start
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
void SetText(const wxString &aText)
Display a text.
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: drawing_tool.h:277
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:45
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
void make45DegLine(DRAWSEGMENT *aSegment, DRAWSEGMENT *aHelper) const
Function make45DegLine() Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:465
int DrawDimension(const TOOL_EVENT &aEvent)
Function DrawDimension() Starts interactively drawing a dimension.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:451
void SetBezControl1(const wxPoint &aPoint)
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
BOARD * board() const
Definition: pcb_tool.h:136
void SetWidth(int aWidth)
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:79