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) 2018 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>
36 
37 #include <view/view_group.h>
38 #include <view/view_controls.h>
39 #include <view/view.h>
41 #include <tool/tool_manager.h>
42 #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"
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",
71  _( "Draw Line" ), _( "Draw a line" ), NULL, AF_ACTIVATE );
72 
73 TOOL_ACTION PCB_ACTIONS::drawGraphicPolygon( "pcbnew.InteractiveDrawing.graphicPolygon",
75  _( "Draw Graphic Polygon" ), _( "Draw a graphic polygon" ), NULL, AF_ACTIVATE );
76 
77 TOOL_ACTION PCB_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle",
79  _( "Draw Circle" ), _( "Draw a circle" ), NULL, AF_ACTIVATE );
80 
81 TOOL_ACTION PCB_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
83  _( "Draw Arc" ), _( "Draw an arc" ), NULL, AF_ACTIVATE );
84 
85 TOOL_ACTION PCB_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text",
87  _( "Add Text" ), _( "Add a text" ), NULL, AF_ACTIVATE );
88 
89 TOOL_ACTION PCB_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
91  _( "Add Dimension" ), _( "Add a dimension" ), NULL, AF_ACTIVATE );
92 
93 TOOL_ACTION PCB_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone",
95  _( "Add Filled Zone" ), _( "Add a filled zone" ), NULL, AF_ACTIVATE );
96 
97 TOOL_ACTION PCB_ACTIONS::drawVia( "pcbnew.InteractiveDrawing.via",
99  _( "Add Vias" ), _( "Add free-standing vias" ), NULL, AF_ACTIVATE );
100 
101 TOOL_ACTION PCB_ACTIONS::drawZoneKeepout( "pcbnew.InteractiveDrawing.keepout",
103  _( "Add Keepout Area" ), _( "Add a keepout area" ), NULL, AF_ACTIVATE );
104 
105 TOOL_ACTION PCB_ACTIONS::drawZoneCutout( "pcbnew.InteractiveDrawing.zoneCutout",
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",
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",
117  "Place DXF", "", NULL, AF_ACTIVATE );
118 
119 TOOL_ACTION PCB_ACTIONS::setAnchor( "pcbnew.InteractiveDrawing.setAnchor",
121  _( "Place the Footprint Anchor" ), _( "Place the footprint anchor" ),
122  NULL, AF_ACTIVATE );
123 
124 TOOL_ACTION PCB_ACTIONS::incWidth( "pcbnew.InteractiveDrawing.incWidth",
126  _( "Increase Line Width" ), _( "Increase the line width" ) );
127 
128 TOOL_ACTION PCB_ACTIONS::decWidth( "pcbnew.InteractiveDrawing.decWidth",
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 {
157 }
158 
159 
161 {
162 }
163 
164 
166 {
167  auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
168  return m_mode != MODE::NONE;
169  };
170 
171  // some interactive drawing tools can undo the last point
172  auto canUndoPoint = [ this ] ( const SELECTION& aSel ) {
173  return m_mode == MODE::ARC || m_mode == MODE::ZONE;
174  };
175 
176  // functor for zone-only actions
177  auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) {
178  return m_mode == MODE::ZONE;
179  };
180 
181  auto& ctxMenu = m_menu.GetMenu();
182 
183  // cancel current tool goes in main context menu at the top if present
184  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
185  ctxMenu.AddSeparator( activeToolFunctor, 1 );
186 
187  // tool-specific actions
188  ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 200 );
189  ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 200 );
190 
191  ctxMenu.AddSeparator( canUndoPoint, 500 );
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 {
221  if( m_editModules && !m_frame->GetModel() )
222  return 0;
223 
225  DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
226 
227  OPT<VECTOR2D> startingPoint;
228  BOARD_COMMIT commit( m_frame );
229 
230  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
231 
233  wxCURSOR_PENCIL, _( "Add graphic line" ) );
234 
235  while( drawSegment( S_SEGMENT, line, startingPoint ) )
236  {
237  if( line )
238  {
239  commit.Add( line );
240  commit.Push( _( "Draw a line segment" ) );
241  startingPoint = VECTOR2D( line->GetEnd() );
242  }
243  else
244  {
245  startingPoint = NULLOPT;
246  }
247 
248  line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
249  }
250 
252 
253  return 0;
254 }
255 
256 
258 {
259  if( m_editModules && !m_frame->GetModel() )
260  return 0;
261 
263  DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
264  BOARD_COMMIT commit( m_frame );
265 
266  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
267 
269  wxCURSOR_PENCIL, _( "Add graphic circle" ) );
270 
271  while( drawSegment( S_CIRCLE, circle ) )
272  {
273  if( circle )
274  {
275  commit.Add( circle );
276  commit.Push( _( "Draw a circle" ) );
277  }
278 
279  circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
280  }
281 
283 
284  return 0;
285 }
286 
287 
288 int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
289 {
290  if( m_editModules && !m_frame->GetModel() )
291  return 0;
292 
294  DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
295  BOARD_COMMIT commit( m_frame );
296 
297  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
298 
300  wxCURSOR_PENCIL, _( "Add graphic arc" ) );
301 
302  while( drawArc( arc ) )
303  {
304  if( arc )
305  {
306  commit.Add( arc );
307  commit.Push( _( "Draw an arc" ) );
308  }
309 
310  arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
311  }
312 
314 
315  return 0;
316 }
317 
318 
320 {
321  if( m_editModules && !m_frame->GetModel() )
322  return 0;
323 
324  BOARD_ITEM* text = NULL;
325  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
327  SELECTION& selection = selTool->GetSelection();
328  BOARD_COMMIT commit( m_frame );
329 
331  m_controls->ShowCursor( true );
332  m_controls->SetSnapping( true );
333  // do not capture or auto-pan until we start placing some text
334 
335  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
336 
337  Activate();
339  wxCURSOR_PENCIL, _( "Add text" ) );
340 
341  bool reselect = false;
342 
343  // Main loop: keep receiving events
344  while( OPT_TOOL_EVENT evt = Wait() )
345  {
346  VECTOR2I cursorPos = m_controls->GetCursorPosition();
347 
348  if( reselect && text )
350 
352  {
353  if( text )
354  {
356 
357  // Delete the old text and have another try
358  delete text;
359  text = NULL;
360 
361  m_controls->SetAutoPan( false );
362  m_controls->CaptureCursor( false );
363  m_controls->ShowCursor( true );
364  }
365  else
366  break;
367 
368  if( evt->IsActivate() ) // now finish unconditionally
369  break;
370  }
371  else if( evt->IsClick( BUT_RIGHT ) )
372  {
374  }
375  else if( evt->IsClick( BUT_LEFT ) )
376  {
377  if( !text )
378  {
381 
382  // Init the new item attributes
383  if( m_editModules )
384  {
385  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) m_frame->GetModel() );
386 
387  textMod->SetLayer( layer );
388  textMod->SetTextSize( dsnSettings.GetTextSize( layer ) );
389  textMod->SetThickness( dsnSettings.GetTextThickness( layer ) );
390  textMod->SetItalic( dsnSettings.GetTextItalic( layer ) );
391  textMod->SetKeepUpright( dsnSettings.GetTextUpright( layer ) );
392  textMod->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
393 
394  DIALOG_TEXT_PROPERTIES textDialog( m_frame, textMod, NULL );
395  bool placing;
396 
397  RunMainStack([&]() {
398  placing = textDialog.ShowModal() && ( textMod->GetText().Length() > 0 );
399  } );
400 
401  if( placing )
402  text = textMod;
403  else
404  delete textMod;
405  }
406  else
407  {
408  TEXTE_PCB* textPcb = new TEXTE_PCB( m_frame->GetModel() );
409  // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
410  textPcb->SetFlags( IS_NEW );
411 
412  textPcb->SetLayer( layer );
413 
414  // Set the mirrored option for layers on the BACK side of the board
415  if( IsBackLayer( layer ) )
416  textPcb->SetMirrored( true );
417 
418  textPcb->SetTextSize( dsnSettings.GetTextSize( layer ) );
419  textPcb->SetThickness( dsnSettings.GetTextThickness( layer ) );
420  textPcb->SetItalic( dsnSettings.GetTextItalic( layer ) );
421  textPcb->SetTextPos( wxPoint( cursorPos.x, cursorPos.y ) );
422 
423  RunMainStack([&]() {
424  m_frame->InstallTextOptionsFrame( textPcb, NULL );
425  } );
426 
427  if( textPcb->GetText().IsEmpty() )
428  delete textPcb;
429  else
430  text = textPcb;
431  }
432 
433  if( text == NULL )
434  continue;
435 
436  m_controls->WarpCursor( text->GetPosition(), true );
438  m_controls->CaptureCursor( true );
439  m_controls->SetAutoPan( true );
440 
442  }
443  else
444  {
445  text->ClearFlags();
447 
448  commit.Add( text );
449  commit.Push( _( "Place a text" ) );
450 
451  m_controls->CaptureCursor( false );
452  m_controls->SetAutoPan( false );
453  m_controls->ShowCursor( true );
454 
455  text = NULL;
456  }
457  }
458  else if( text && evt->IsMotion() )
459  {
460  text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
461  selection.SetReferencePoint( cursorPos );
462  m_view->Update( &selection );
463  frame()->SetMsgPanel( text );
464  }
465 
466  else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
467  {
468  // Calling 'Properties' action clears the selection, so we need to restore it
469  reselect = true;
470  }
471  }
472 
473  frame()->SetMsgPanel( board() );
475 
476  return 0;
477 }
478 
479 
481 {
482  const VECTOR2I lineVector{ dimension->GetEnd() - dimension->GetOrigin() };
483 
484  dimension->SetEnd( wxPoint(
485  VECTOR2I( dimension->GetOrigin() ) + GetVectorSnapped45( lineVector ) ) );
486 }
487 
488 
490 {
491  if( m_editModules && !m_frame->GetModel() )
492  return 0;
493 
494  DIMENSION* dimension = NULL;
495  BOARD_COMMIT commit( m_frame );
496  GRID_HELPER grid( m_frame );
497 
498  // Add a VIEW_GROUP that serves as a preview for the new item
499  SELECTION preview;
500 
501  m_view->Add( &preview );
502 
504  m_controls->ShowCursor( true );
505  m_controls->SetSnapping( true );
506 
507  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
508 
509  Activate();
510  m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
511 
512  enum DIMENSION_STEPS
513  {
514  SET_ORIGIN = 0,
515  SET_END,
516  SET_HEIGHT,
517  FINISHED
518  };
519  int step = SET_ORIGIN;
520 
521  // Main loop: keep receiving events
522  while( OPT_TOOL_EVENT evt = Wait() )
523  {
524  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
525  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
526  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
527  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), nullptr );
528  m_controls->ForceCursorPosition( true, cursorPos );
529 
531  {
532  m_controls->SetAutoPan( false );
533 
534  if( step != SET_ORIGIN ) // start from the beginning
535  {
536  preview.Clear();
537 
538  delete dimension;
539  step = SET_ORIGIN;
540  }
541  else
542  break;
543 
544  if( evt->IsActivate() ) // now finish unconditionally
545  break;
546  }
547  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN )
548  {
550  dimension->SetWidth( m_lineWidth );
551  m_view->Update( &preview );
552  frame()->SetMsgPanel( dimension );
553  }
554  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && step != SET_ORIGIN )
555  {
556  if( m_lineWidth > WIDTH_STEP )
557  {
559  dimension->SetWidth( m_lineWidth );
560  m_view->Update( &preview );
561  frame()->SetMsgPanel( dimension );
562  }
563  }
564  else if( evt->IsClick( BUT_RIGHT ) )
565  {
567  }
568  else if( evt->IsClick( BUT_LEFT ) )
569  {
570  switch( step )
571  {
572  case SET_ORIGIN:
573  {
574  PCB_LAYER_ID layer = getDrawingLayer();
575  const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
576 
577  if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts
578  layer = Dwgs_User;
579 
580  // Init the new item attributes
581  dimension = new DIMENSION( m_board );
582  dimension->SetLayer( layer );
583  dimension->SetOrigin( wxPoint( cursorPos.x, cursorPos.y ) );
584  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
585  dimension->Text().SetTextSize( boardSettings.GetTextSize( layer ) );
586  dimension->Text().SetThickness( boardSettings.GetTextThickness( layer ) );
587  dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) );
588  dimension->SetWidth( boardSettings.GetLineThickness( layer ) );
589  dimension->SetUnits( m_frame->GetUserUnits(), false );
590  dimension->AdjustDimensionDetails();
591 
592  preview.Add( dimension );
593  frame()->SetMsgPanel( dimension );
594 
595  m_controls->SetAutoPan( true );
596  m_controls->CaptureCursor( true );
597  }
598  break;
599 
600  case SET_END:
601  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
602 
603  if( !!evt->Modifier( MD_CTRL ) )
604  constrainDimension( dimension );
605 
606  // Dimensions that have origin and end in the same spot are not valid
607  if( dimension->GetOrigin() == dimension->GetEnd() )
608  --step;
609 
610  break;
611 
612  case SET_HEIGHT:
613  {
614  if( wxPoint( cursorPos.x, cursorPos.y ) != dimension->GetPosition() )
615  {
616  assert( dimension->GetOrigin() != dimension->GetEnd() );
617  assert( dimension->GetWidth() > 0 );
618 
619  preview.Remove( dimension );
620 
621  commit.Add( dimension );
622  commit.Push( _( "Draw a dimension" ) );
623  }
624  }
625  break;
626  }
627 
628  if( ++step == FINISHED )
629  {
630  step = SET_ORIGIN;
631  m_controls->SetAutoPan( false );
632  m_controls->CaptureCursor( false );
633  }
634  }
635  else if( evt->IsMotion() )
636  {
637  switch( step )
638  {
639  case SET_END:
640  dimension->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
641 
642  if( !!evt->Modifier( MD_CTRL ) )
643  constrainDimension( dimension );
644 
645  break;
646 
647  case SET_HEIGHT:
648  {
649  // Calculating the direction of travel perpendicular to the selected axis
650  double angle = dimension->GetAngle() + ( M_PI / 2 );
651 
652  wxPoint pos( cursorPos.x, cursorPos.y );
653  wxPoint delta( pos - dimension->m_featureLineDO );
654  double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
655  dimension->SetHeight( height );
656  }
657  break;
658  }
659 
660  // Show a preview of the item
661  m_view->Update( &preview );
662  if( step )
663  frame()->SetMsgPanel( dimension );
664  else
665  frame()->SetMsgPanel( board() );
666  }
667  }
668 
669  if( step != SET_ORIGIN )
670  delete dimension;
671 
672  m_controls->SetAutoPan( false );
673 
674  m_view->Remove( &preview );
675  frame()->SetMsgPanel( board() );
677 
678  return 0;
679 }
680 
681 
682 int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
683 {
684  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
685 
686  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
687 
688  return drawZone( false, ZONE_MODE::ADD );
689 }
690 
691 
693 {
694  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::KEEPOUT );
695 
696  m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
697 
698  return drawZone( true, ZONE_MODE::ADD );
699 }
700 
701 
703 {
704  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
705 
706  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zone cutout" ) );
707 
708  return drawZone( false, ZONE_MODE::CUTOUT );
709 }
710 
711 
713 {
714  if( m_editModules && !m_frame->GetModel() )
715  return 0;
716 
717  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::GRAPHIC_POLYGON );
718 
720  wxCURSOR_PENCIL, _( "Add graphic polygon" ) );
721 
722  return drawZone( false, ZONE_MODE::GRAPHIC_POLYGON );
723 }
724 
725 
727 {
728  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE );
729 
730  m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add similar zone" ) );
731 
732  return drawZone( false, ZONE_MODE::SIMILAR );
733 }
734 
735 
736 int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
737 {
738  if( !m_frame->GetModel() )
739  return 0;
740 
741  DIALOG_DXF_IMPORT dlg( m_frame );
742  int dlgResult = dlg.ShowModal();
743 
744  const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
745 
746  if( dlgResult != wxID_OK || list.empty() )
747  return 0;
748 
749  VECTOR2I cursorPos = m_controls->GetCursorPosition();
750  VECTOR2I delta = cursorPos - list.front()->GetPosition();
751 
752  // Add a VIEW_GROUP that serves as a preview for the new item
753  SELECTION preview;
754  BOARD_COMMIT commit( m_frame );
755 
756  // Build the undo list & add items to the current view
757  for( auto item : list )
758  {
759  assert( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
760  preview.Add( item );
761  }
762 
763  BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
764  m_view->Add( &preview );
765 
767  m_controls->ShowCursor( true );
768  m_controls->SetSnapping( true );
770 
771  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
772 
773  // Now move the new items to the current cursor position:
774  cursorPos = m_controls->GetCursorPosition();
775  delta = cursorPos - firstItem->GetPosition();
776 
777  for( auto item : preview )
778  static_cast<BOARD_ITEM*>( item )->Move( wxPoint( delta.x, delta.y ) );
779 
780  m_view->Update( &preview );
781 
782  Activate();
783 
784  // Main loop: keep receiving events
785  while( OPT_TOOL_EVENT evt = Wait() )
786  {
787  cursorPos = m_controls->GetCursorPosition();
788 
789  if( evt->IsMotion() )
790  {
791  delta = cursorPos - firstItem->GetPosition();
792 
793  for( auto item : preview )
794  static_cast<BOARD_ITEM*>( item )->Move( wxPoint( delta.x, delta.y ) );
795 
796  m_view->Update( &preview );
797  }
798  else if( evt->Category() == TC_COMMAND )
799  {
800  // TODO it should be handled by EDIT_TOOL, so add items and select?
801  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
802  {
803  const auto rotationPoint = wxPoint( cursorPos.x, cursorPos.y );
804  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
805  *m_frame, *evt );
806 
807  for( auto item : preview )
808  {
809  static_cast<BOARD_ITEM*>( item )->Rotate( rotationPoint, rotationAngle );
810  }
811 
812  m_view->Update( &preview );
813  }
814  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
815  {
816  for( auto item : preview )
817  static_cast<BOARD_ITEM*>( item )->Flip( wxPoint( cursorPos.x, cursorPos.y ) );
818 
819  m_view->Update( &preview );
820  }
821  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
822  {
823  preview.FreeItems();
824  break;
825  }
826  }
827  else if( evt->IsClick( BUT_RIGHT ) )
828  {
830  }
831  else if( evt->IsClick( BUT_LEFT ) )
832  {
833  // Place the drawing
835 
836  for( auto item : preview )
837  {
838  if( m_editModules )
839  {
840  // Modules use different types for the same things,
841  // so we need to convert imported items to appropriate classes.
842  BOARD_ITEM* converted = NULL;
843 
844  switch( item->Type() )
845  {
846  case PCB_TEXT_T:
847  {
848  TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item );
849  TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent );
850 
851  // Assignment operator also copies the item PCB_TEXT_T type,
852  // so it cannot be added to a module which handles PCB_MODULE_TEXT_T
853  textMod->SetText( text->GetText() );
854 #if 0
855  textMod->SetTextSize( text->GetTextSize() );
856  textMod->SetThickness( text->GetThickness() );
857  textMod->SetOrientation( text->GetTextAngle() );
858  textMod->SetTextPos( text->GetTextPos() );
859  textMod->SetTextSize( text->GetTextSize() );
860  textMod->SetVisible( text->GetVisible() );
861  textMod->SetMirrored( text->IsMirrored() );
862  textMod->SetItalic( text->IsItalic() );
863  textMod->SetBold( text->IsBold() );
864  textMod->SetHorizJustify( text->GetHorizJustify() );
865  textMod->SetVertJustify( text->GetVertJustify() );
866  textMod->SetMultilineAllowed( text->IsMultilineAllowed() );
867 #else
868  textMod->EDA_TEXT::SetEffects( *text );
869  textMod->SetLocalCoord(); // using changed SetTexPos() via SetEffects()
870 #endif
871  converted = textMod;
872  break;
873  }
874 
875  case PCB_LINE_T:
876  {
877  DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item );
878  EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent );
879 
880  // Assignment operator also copies the item PCB_LINE_T type,
881  // so it cannot be added to a module which handles PCB_MODULE_EDGE_T
882  modSeg->SetWidth( seg->GetWidth() );
883  modSeg->SetStart( seg->GetStart() );
884  modSeg->SetEnd( seg->GetEnd() );
885  modSeg->SetAngle( seg->GetAngle() );
886  modSeg->SetShape( seg->GetShape() );
887  modSeg->SetType( seg->GetType() );
888  modSeg->SetBezControl1( seg->GetBezControl1() );
889  modSeg->SetBezControl2( seg->GetBezControl2() );
890  modSeg->SetBezierPoints( seg->GetBezierPoints() );
891  modSeg->SetPolyShape( seg->GetPolyShape() );
892  modSeg->SetLocalCoord();
893  converted = modSeg;
894  break;
895  }
896 
897  default:
898  assert( false );
899  break;
900  }
901 
902  if( converted )
903  converted->SetLayer( static_cast<BOARD_ITEM*>( item )->GetLayer() );
904 
905  delete item;
906  item = converted;
907  }
908 
909  if( item )
910  commit.Add( item );
911  }
912 
913  commit.Push( _( "Place a DXF drawing" ) );
914  break;
915  }
916  }
917 
918  preview.Clear();
919  m_view->Remove( &preview );
920 
921  return 0;
922 }
923 
924 
926 {
927  assert( m_editModules );
928 
929  if( !m_frame->GetModel() )
930  return 0;
931 
932  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
933 
934  Activate();
935  m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL,
936  _( "Place the footprint anchor" ) );
937 
938  m_controls->ShowCursor( true );
939  m_controls->SetSnapping( true );
940  m_controls->SetAutoPan( true );
941  m_controls->CaptureCursor( false );
942 
943  while( OPT_TOOL_EVENT evt = Wait() )
944  {
945  if( evt->IsClick( BUT_LEFT ) )
946  {
948  BOARD_COMMIT commit( m_frame );
949  commit.Modify( module );
950 
951  // set the new relative internal local coordinates of footprint items
952  VECTOR2I cursorPos = m_controls->GetCursorPosition();
953  wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
954  module->MoveAnchorPosition( moveVector );
955 
956  commit.Push( _( "Move the footprint reference anchor" ) );
957 
958  // Usually, we do not need to change twice the anchor position,
959  // so deselect the active tool
960  break;
961  }
962  else if( evt->IsClick( BUT_RIGHT ) )
963  {
965  }
966  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
967  break;
968  }
969 
971 
972  return 0;
973 }
974 
975 
976 bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
977  OPT<VECTOR2D> aStartingPoint )
978 {
979  // Only two shapes are currently supported
980  assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
981 
982  DRAWSEGMENT line45;
983  GRID_HELPER grid( m_frame );
984 
987 
988  // Add a VIEW_GROUP that serves as a preview for the new item
989  SELECTION preview;
990  m_view->Add( &preview );
991 
993  m_controls->ShowCursor( true );
994 
995  Activate();
996 
997  bool direction45 = false; // 45 degrees only mode
998  bool started = false;
999  bool IsOCurseurSet = ( m_frame->GetScreen()->m_O_Curseur != wxPoint( 0, 0 ) );
1000  VECTOR2I cursorPos = m_controls->GetMousePosition();
1001 
1002  if( aStartingPoint )
1003  {
1004  // Init the new item attributes
1005  aGraphic->SetShape( (STROKE_T) aShape );
1006  aGraphic->SetWidth( m_lineWidth );
1007  aGraphic->SetLayer( getDrawingLayer() );
1008  aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) );
1009 
1010  cursorPos = grid.BestSnapAnchor( cursorPos, aGraphic );
1011  m_controls->ForceCursorPosition( true, cursorPos );
1012  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1013 
1014  if( aShape == S_SEGMENT )
1015  line45 = *aGraphic; // used only for direction 45 mode with lines
1016 
1017  preview.Add( aGraphic );
1018  m_controls->SetAutoPan( true );
1019  m_controls->CaptureCursor( true );
1020 
1021  if( !IsOCurseurSet )
1022  m_frame->GetScreen()->m_O_Curseur = wxPoint( aStartingPoint->x, aStartingPoint->y );
1023 
1024  started = true;
1025  }
1026 
1027  // Main loop: keep receiving events
1028  while( OPT_TOOL_EVENT evt = Wait() )
1029  {
1030  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1031  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1032  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1033  cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), getDrawingLayer() );
1034  m_controls->ForceCursorPosition( true, cursorPos );
1035 
1036  // 45 degree angle constraint enabled with an option and toggled with Ctrl
1037  const bool limit45 = ( frame()->Settings().m_use45DegreeGraphicSegments != !!( evt->Modifier( MD_CTRL ) ) );
1038 
1039  if( direction45 != limit45 && started && aShape == S_SEGMENT )
1040  {
1041  direction45 = limit45;
1042 
1043  if( direction45 )
1044  {
1045  preview.Add( &line45 );
1046  make45DegLine( aGraphic, &line45, cursorPos );
1047  }
1048  else
1049  {
1050  preview.Remove( &line45 );
1051  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1052  }
1053 
1054  m_view->Update( &preview );
1055  frame()->SetMsgPanel( aGraphic );
1056  }
1057 
1059  {
1060  preview.Clear();
1061  m_view->Update( &preview );
1062  delete aGraphic;
1063  aGraphic = NULL;
1064  if( !IsOCurseurSet )
1065  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1066  break;
1067  }
1068  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1069  {
1071  aGraphic->SetLayer( getDrawingLayer() );
1072  aGraphic->SetWidth( m_lineWidth );
1073  m_view->Update( &preview );
1074  frame()->SetMsgPanel( aGraphic );
1075  }
1076  else if( evt->IsClick( BUT_RIGHT ) )
1077  {
1079  }
1080  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
1081  {
1082  if( !started )
1083  {
1085 
1086  // Init the new item attributes
1087  aGraphic->SetShape( (STROKE_T) aShape );
1088  aGraphic->SetWidth( m_lineWidth );
1089  aGraphic->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
1090  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1091  aGraphic->SetLayer( getDrawingLayer() );
1092 
1093  if( !IsOCurseurSet )
1094  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
1095 
1096  if( aShape == S_SEGMENT )
1097  line45 = *aGraphic; // used only for direction 45 mode with lines
1098 
1099  preview.Add( aGraphic );
1100  frame()->SetMsgPanel( aGraphic );
1101  m_controls->SetAutoPan( true );
1102  m_controls->CaptureCursor( true );
1103 
1104  started = true;
1105  }
1106  else
1107  {
1108  if( aGraphic->GetEnd() == aGraphic->GetStart()
1109  || ( evt->IsDblClick( BUT_LEFT ) && aShape == S_SEGMENT ) )
1110  // User has clicked twice in the same spot
1111  {
1112  // a clear sign that the current drawing is finished
1113  // Now we have to add the helper line as well, unless it is zero-length
1114  if( direction45 && line45.GetStart() != aGraphic->GetStart() )
1115  {
1116  BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
1117  DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( (MODULE*) parent )
1118  : new DRAWSEGMENT;
1119 
1120  // Copy coordinates, layer, etc.
1121  *static_cast<DRAWSEGMENT*>( l ) = line45;
1122  l->SetEnd( aGraphic->GetStart() );
1123 
1124  BOARD_COMMIT commit( m_frame );
1125  commit.Add( l );
1126  commit.Push( _( "Draw a line" ) );
1127  }
1128 
1129  delete aGraphic;
1130  aGraphic = NULL;
1131  }
1132 
1133  preview.Clear();
1134  break;
1135  }
1136  }
1137  else if( evt->IsMotion() )
1138  {
1139  // 45 degree lines
1140  if( direction45 && aShape == S_SEGMENT )
1141  make45DegLine( aGraphic, &line45, cursorPos );
1142  else
1143  aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
1144 
1145  m_view->Update( &preview );
1146 
1147  if( started )
1148  frame()->SetMsgPanel( aGraphic );
1149  else
1150  frame()->SetMsgPanel( board() );
1151  }
1152  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1153  {
1155  aGraphic->SetWidth( m_lineWidth );
1156  line45.SetWidth( m_lineWidth );
1157  m_view->Update( &preview );
1158  frame()->SetMsgPanel( aGraphic );
1159  }
1160  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && ( m_lineWidth > WIDTH_STEP ) )
1161  {
1163  aGraphic->SetWidth( m_lineWidth );
1164  line45.SetWidth( m_lineWidth );
1165  m_view->Update( &preview );
1166  frame()->SetMsgPanel( aGraphic );
1167  }
1168  else if( evt->IsAction( &PCB_ACTIONS::resetCoords ) )
1169  {
1170  IsOCurseurSet = true;
1171  }
1172  }
1173 
1174  if( !IsOCurseurSet ) // reset the relative coordinte if it was not set before
1175  m_frame->GetScreen()->m_O_Curseur = wxPoint( 0, 0 );
1176 
1177  m_view->Remove( &preview );
1178  frame()->SetMsgPanel( board() );
1179  m_controls->SetAutoPan( false );
1180  m_controls->CaptureCursor( false );
1181  m_controls->ForceCursorPosition( false );
1182 
1183  return started;
1184 }
1185 
1186 
1192  DRAWSEGMENT& aArc )
1193 {
1194  auto vec = aMgr.GetOrigin();
1195 
1196  aArc.SetCenter( { vec.x, vec.y } );
1197 
1198  vec = aMgr.GetStartRadiusEnd();
1199  aArc.SetArcStart( { vec.x, vec.y } );
1200 
1201  aArc.SetAngle( RAD2DECIDEG( -aMgr.GetSubtended() ) );
1202 }
1203 
1204 
1206 {
1208 
1210 
1211  // Arc geometric construction manager
1213 
1214  // Arc drawing assistant overlay
1215  KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() );
1216 
1217  // Add a VIEW_GROUP that serves as a preview for the new item
1218  SELECTION preview;
1219  m_view->Add( &preview );
1220  m_view->Add( &arcAsst );
1221  GRID_HELPER grid( m_frame );
1222 
1223  m_controls->ShowCursor( true );
1224  m_controls->SetSnapping( true );
1225 
1226  Activate();
1227 
1228  bool firstPoint = false;
1229 
1230  // Main loop: keep receiving events
1231  while( OPT_TOOL_EVENT evt = Wait() )
1232  {
1233  PCB_LAYER_ID layer = getDrawingLayer();
1234  aGraphic->SetLayer( layer );
1235 
1236  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1237  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1238  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1239  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), aGraphic );
1240  m_controls->ForceCursorPosition( true, cursorPos );
1241 
1242  if( evt->IsClick( BUT_LEFT ) )
1243  {
1244  if( !firstPoint )
1245  {
1246  m_controls->SetAutoPan( true );
1247  m_controls->CaptureCursor( true );
1248 
1250 
1251  // Init the new item attributes
1252  // (non-geometric, those are handled by the manager)
1253  aGraphic->SetShape( S_ARC );
1254  aGraphic->SetWidth( m_lineWidth );
1255 
1256  preview.Add( aGraphic );
1257  firstPoint = true;
1258  }
1259 
1260  arcManager.AddPoint( cursorPos, true );
1261  }
1262  else if( evt->IsAction( &deleteLastPoint ) )
1263  {
1264  arcManager.RemoveLastPoint();
1265  }
1266  else if( evt->IsMotion() )
1267  {
1268  // set angle snap
1269  arcManager.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1270 
1271  // update, but don't step the manager state
1272  arcManager.AddPoint( cursorPos, false );
1273  }
1274  else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
1275  {
1276  preview.Clear();
1277  delete aGraphic;
1278  aGraphic = nullptr;
1279  break;
1280  }
1281  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1282  {
1284  aGraphic->SetLayer( getDrawingLayer() );
1285  aGraphic->SetWidth( m_lineWidth );
1286  m_view->Update( &preview );
1287  frame()->SetMsgPanel( aGraphic );
1288  }
1289  else if( evt->IsClick( BUT_RIGHT ) )
1290  {
1292  }
1293  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1294  {
1296  aGraphic->SetWidth( m_lineWidth );
1297  m_view->Update( &preview );
1298  frame()->SetMsgPanel( aGraphic );
1299  }
1300  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) && m_lineWidth > WIDTH_STEP )
1301  {
1303  aGraphic->SetWidth( m_lineWidth );
1304  m_view->Update( &preview );
1305  frame()->SetMsgPanel( aGraphic );
1306  }
1307  else if( evt->IsAction( &PCB_ACTIONS::arcPosture ) )
1308  {
1309  arcManager.ToggleClockwise();
1310  }
1311 
1312  if( arcManager.IsComplete() )
1313  {
1314  break;
1315  }
1316  else if( arcManager.HasGeometryChanged() )
1317  {
1318  updateArcFromConstructionMgr( arcManager, *aGraphic );
1319  m_view->Update( &preview );
1320  m_view->Update( &arcAsst );
1321 
1322  if(firstPoint)
1323  frame()->SetMsgPanel( aGraphic );
1324  else
1325  frame()->SetMsgPanel( board() );
1326  }
1327  }
1328 
1329  preview.Remove( aGraphic );
1330  m_view->Remove( &arcAsst );
1331  m_view->Remove( &preview );
1332  frame()->SetMsgPanel( board() );
1333  m_controls->SetAutoPan( false );
1334  m_controls->CaptureCursor( false );
1335  m_controls->ForceCursorPosition( false );
1336 
1337  return !arcManager.IsReset();
1338 }
1339 
1340 
1342 {
1343  bool clearSelection = false;
1344  aZone = nullptr;
1345 
1346  // not an action that needs a source zone
1347  if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON )
1348  return true;
1349 
1351  const SELECTION& selection = selTool->GetSelection();
1352 
1353  if( selection.Empty() )
1354  {
1355  clearSelection = true;
1357  }
1358 
1359  // we want a single zone
1360  if( selection.Size() == 1 )
1361  aZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
1362 
1363  // expected a zone, but didn't get one
1364  if( !aZone )
1365  {
1366  if( clearSelection )
1368 
1369  return false;
1370  }
1371 
1372  return true;
1373 }
1374 
1375 int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
1376 {
1377  // get a source zone, if we need one. We need it for:
1378  // ZONE_MODE::CUTOUT (adding a hole to the source zone)
1379  // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone
1380  ZONE_CONTAINER* sourceZone = nullptr;
1381 
1382  if( !getSourceZoneForAction( aMode, sourceZone ) )
1383  {
1385  return 0;
1386  }
1387 
1389 
1390  params.m_keepout = aKeepout;
1391  params.m_mode = aMode;
1392  params.m_sourceZone = sourceZone;
1393 
1394  if( aMode == ZONE_MODE::GRAPHIC_POLYGON )
1395  params.m_layer = getDrawingLayer();
1396  else if( aMode == ZONE_MODE::SIMILAR )
1397  params.m_layer = sourceZone->GetLayer();
1398  else
1399  params.m_layer = m_frame->GetActiveLayer();
1400 
1401  ZONE_CREATE_HELPER zoneTool( *this, params );
1402 
1403  // the geometry manager which handles the zone geometry, and
1404  // hands the calculated points over to the zone creator tool
1405  POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
1406 
1407  Activate(); // register for events
1408 
1409  m_controls->ShowCursor( true );
1410  m_controls->SetSnapping( true );
1411 
1412  bool started = false;
1413  GRID_HELPER grid( m_frame );
1414  STATUS_TEXT_POPUP status( m_frame );
1415  status.SetTextColor( wxColour( 255, 0, 0 ) );
1416  status.SetText( _( "Self-intersecting polygons are not allowed" ) );
1417 
1418  while( OPT_TOOL_EVENT evt = Wait() )
1419  {
1420  LSET layers( m_frame->GetActiveLayer() );
1421  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1422  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1423  m_controls->SetSnapping( !evt->Modifier( MD_ALT ) );
1424  VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), layers );
1425  m_controls->ForceCursorPosition( true, cursorPos );
1426 
1428  {
1429  // pre-empted by another tool, give up
1430  // cancelled without an inprogress polygon, give up
1431  if( !polyGeomMgr.IsPolygonInProgress() || evt->IsActivate() )
1432  {
1433  break;
1434  }
1435 
1436  polyGeomMgr.Reset();
1437  // start again
1438  started = false;
1439 
1440  m_controls->SetAutoPan( false );
1441  m_controls->CaptureCursor( false );
1442  }
1443  else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
1444  {
1445  if( aMode == ZONE_MODE::GRAPHIC_POLYGON )
1446  params.m_layer = getDrawingLayer();
1447  else if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::CUTOUT )
1448  params.m_layer = frame()->GetActiveLayer();
1449  }
1450  else if( evt->IsClick( BUT_RIGHT ) )
1451  {
1453  }
1454  // events that lock in nodes
1455  else if( evt->IsClick( BUT_LEFT )
1456  || evt->IsDblClick( BUT_LEFT )
1457  || evt->IsAction( &closeZoneOutline ) )
1458  {
1459  // Check if it is double click / closing line (so we have to finish the zone)
1460  const bool endPolygon = evt->IsDblClick( BUT_LEFT )
1461  || evt->IsAction( &closeZoneOutline )
1462  || polyGeomMgr.NewPointClosesOutline( cursorPos );
1463 
1464  if( endPolygon )
1465  {
1466  polyGeomMgr.SetFinished();
1467  polyGeomMgr.Reset();
1468 
1469  // ready to start again
1470  started = false;
1471  m_controls->SetAutoPan( false );
1472  m_controls->CaptureCursor( false );
1473  }
1474 
1475  // adding a corner
1476  else if( polyGeomMgr.AddPoint( cursorPos ) )
1477  {
1478  if( !started )
1479  {
1480  started = true;
1481  m_controls->SetAutoPan( true );
1482  m_controls->CaptureCursor( true );
1483  }
1484  }
1485 
1486  }
1487  else if( evt->IsAction( &deleteLastPoint ) )
1488  {
1489  polyGeomMgr.DeleteLastCorner();
1490 
1491  if( !polyGeomMgr.IsPolygonInProgress() )
1492  {
1493  // report finished as an empty shape
1494  polyGeomMgr.SetFinished();
1495 
1496  // start again
1497  started = false;
1498  m_controls->SetAutoPan( false );
1499  m_controls->CaptureCursor( false );
1500  }
1501  }
1502  else if( polyGeomMgr.IsPolygonInProgress()
1503  && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1504  {
1505  polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
1508 
1509  if( polyGeomMgr.IsSelfIntersecting( true ) )
1510  {
1511  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
1512  status.Move( p );
1513  status.Popup( m_frame );
1514  status.Expire( 1500 );
1515  }
1516  else
1517  {
1518  status.Hide();
1519  }
1520  }
1521  } // end while
1522 
1525  m_controls->ForceCursorPosition( false );
1526 
1527  return 0;
1528 }
1529 
1530 
1532  VECTOR2I& aPos ) const
1533 {
1534  VECTOR2I origin( aSegment->GetStart() );
1535  DIRECTION_45 direction( origin - aPos );
1536  SHAPE_LINE_CHAIN newChain = direction.BuildInitialTrace( origin, aPos );
1537 
1538  if( newChain.PointCount() > 2 )
1539  {
1540  aSegment->SetEnd( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
1541  aHelper->SetStart( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) );
1542  aHelper->SetEnd( wxPoint( newChain.Point( -1 ).x, newChain.Point( -1 ).y ) );
1543  }
1544  else
1545  {
1546  aSegment->SetEnd( wxPoint( aPos.x, aPos.y ) );
1547  aHelper->SetStart( wxPoint( aPos.x, aPos.y ) );
1548  aHelper->SetEnd( wxPoint( aPos.x, aPos.y ) );
1549  }
1550 }
1551 
1552 
1553 int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
1554 {
1555  struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
1556  {
1557  GRID_HELPER m_gridHelper;
1558 
1559  VIA_PLACER( PCB_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame )
1560  {}
1561 
1562  TRACK* findTrack( VIA* aVia )
1563  {
1564  const LSET lset = aVia->GetLayerSet();
1565 
1566  for( TRACK* track : m_board->Tracks() )
1567  {
1568  if( !(track->GetLayerSet() & lset ).any() )
1569  continue;
1570 
1571  if( TestSegmentHit( aVia->GetPosition(), track->GetStart(), track->GetEnd(),
1572  ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
1573  return track;
1574  }
1575 
1576  return nullptr;
1577  }
1578 
1579  int findStitchedZoneNet( VIA* aVia )
1580  {
1581  const auto pos = aVia->GetPosition();
1582  const auto lset = aVia->GetLayerSet();
1583 
1584  for( auto mod : m_board->Modules() )
1585  {
1586  for( D_PAD* pad : mod->Pads() )
1587  {
1588  if( pad->HitTest( pos ) && ( pad->GetLayerSet() & lset ).any() )
1589  return -1;
1590  }
1591  }
1592 
1593  std::vector<ZONE_CONTAINER*> foundZones;
1594 
1595  for( auto zone : m_board->Zones() )
1596  {
1597  if( zone->HitTestFilledArea( pos ) )
1598  {
1599  foundZones.push_back( zone );
1600  }
1601  }
1602 
1603  std::sort( foundZones.begin(), foundZones.end(),
1604  [] ( const ZONE_CONTAINER* a, const ZONE_CONTAINER* b ) {
1605  return a->GetLayer() < b->GetLayer();
1606  } );
1607 
1608  // first take the net of the active layer
1609  for( auto z : foundZones )
1610  {
1611  if( m_frame->GetActiveLayer() == z->GetLayer() )
1612  return z->GetNetCode();
1613  }
1614 
1615  // none? take the topmost visible layer
1616  for( auto z : foundZones )
1617  {
1618  if( m_board->IsLayerVisible( z->GetLayer() ) )
1619  return z->GetNetCode();
1620  }
1621 
1622  return -1;
1623  }
1624 
1625  void SnapItem( BOARD_ITEM *aItem ) override
1626  {
1627  // If you place a Via on a track but not on its centerline, the current
1628  // connectivity algorithm will require us to put a kink in the track when
1629  // we break it (so that each of the two segments ends on the via center).
1630  // That's not ideal, and is in fact probably worse than forcing snap in
1631  // this situation.
1632 
1633 // bool do_snap = ( m_frame->Settings().m_magneticTracks == CAPTURE_CURSOR_IN_TRACK_TOOL
1634 // || m_frame->Settings().m_magneticTracks == CAPTURE_ALWAYS );
1635  m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
1636  auto via = static_cast<VIA*>( aItem );
1637  wxPoint pos = via->GetPosition();
1638  TRACK* track = findTrack( via );
1639 
1640  if( track )
1641  {
1642  SEG trackSeg( track->GetStart(), track->GetEnd() );
1643  VECTOR2I snap = m_gridHelper.AlignToSegment( pos, trackSeg );
1644 
1645  aItem->SetPosition( wxPoint( snap.x, snap.y ) );
1646  }
1647  }
1648 
1649  void PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
1650  {
1651  auto via = static_cast<VIA*>( aItem );
1652  int newNet;
1653  TRACK* track = findTrack( via );
1654 
1655  if( track )
1656  {
1657  aCommit.Modify( track );
1658  TRACK* newTrack = dynamic_cast<TRACK*>( track->Clone() );
1659  track->SetEnd( via->GetPosition() );
1660  newTrack->SetStart( via->GetPosition() );
1661  aCommit.Add( newTrack );
1662 
1663  newNet = track->GetNetCode();
1664  }
1665  else
1666  newNet = findStitchedZoneNet( via );
1667 
1668  if( newNet > 0 )
1669  via->SetNetCode( newNet );
1670 
1671  aCommit.Add( aItem );
1672  }
1673 
1674  std::unique_ptr<BOARD_ITEM> CreateItem() override
1675  {
1676  auto& ds = m_board->GetDesignSettings();
1677  VIA* via = new VIA( m_board );
1678 
1679  via->SetNetCode( 0 );
1680  via->SetViaType( ds.m_CurrentViaType );
1681 
1682  // for microvias, the size and hole will be changed later.
1683  via->SetWidth( ds.GetCurrentViaSize() );
1684  via->SetDrill( ds.GetCurrentViaDrill() );
1685 
1686  // Usual via is from copper to component.
1687  // layer pair is B_Cu and F_Cu.
1688  via->SetLayerPair( B_Cu, F_Cu );
1689 
1690  PCB_LAYER_ID first_layer = m_frame->GetActiveLayer();
1691  PCB_LAYER_ID last_layer;
1692 
1693  // prepare switch to new active layer:
1694  if( first_layer != m_frame->GetScreen()->m_Route_Layer_TOP )
1695  last_layer = m_frame->GetScreen()->m_Route_Layer_TOP;
1696  else
1697  last_layer = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
1698 
1699  // Adjust the actual via layer pair
1700  switch( via->GetViaType() )
1701  {
1702  case VIA_BLIND_BURIED:
1703  via->SetLayerPair( first_layer, last_layer );
1704  break;
1705 
1706  case VIA_MICROVIA: // from external to the near neighbor inner layer
1707  {
1708  PCB_LAYER_ID last_inner_layer =
1709  ToLAYER_ID( ( m_board->GetCopperLayerCount() - 2 ) );
1710 
1711  if( first_layer == B_Cu )
1712  last_layer = last_inner_layer;
1713  else if( first_layer == F_Cu )
1714  last_layer = In1_Cu;
1715  else if( first_layer == last_inner_layer )
1716  last_layer = B_Cu;
1717  else if( first_layer == In1_Cu )
1718  last_layer = F_Cu;
1719 
1720  // else error: will be removed later
1721  via->SetLayerPair( first_layer, last_layer );
1722 
1723  // Update diameter and hole size, which where set previously
1724  // for normal vias
1725  NETINFO_ITEM* net = via->GetNet();
1726 
1727  if( net )
1728  {
1729  via->SetWidth( net->GetMicroViaSize() );
1730  via->SetDrill( net->GetMicroViaDrillSize() );
1731  }
1732  }
1733  break;
1734 
1735  default:
1736  break;
1737  }
1738 
1739  return std::unique_ptr<BOARD_ITEM>( via );
1740  }
1741  };
1742 
1743  VIA_PLACER placer( frame() );
1744 
1745  SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
1746 
1747  frame()->SetToolID( ID_PCB_DRAW_VIA_BUTT, wxCURSOR_PENCIL, _( "Add vias" ) );
1748 
1749  doInteractiveItemPlacement( &placer, _( "Place via" ),
1751 
1752  frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
1753 
1754  return 0;
1755 }
1756 
1757 
1759 {
1773 }
1774 
1775 
1777 {
1778  assert( m_board );
1779  return m_board->GetDesignSettings().GetLineThickness( aLayer );
1780 }
1781 
1782 
1784 {
1785  PCB_LAYER_ID layer = m_frame->GetActiveLayer();
1786 
1787  if( IsCopperLayer( layer ) )
1788  {
1789  if( layer == F_Cu )
1790  layer = F_SilkS;
1791  else if( layer == B_Cu )
1792  layer = B_SilkS;
1793  else
1794  layer = Dwgs_User;
1795 
1796  m_frame->SetActiveLayer( layer );
1797  }
1798 
1799  return layer;
1800 }
1801 
1802 
1803 const unsigned int DRAWING_TOOL::WIDTH_STEP = 100000;
void SetMirrored(bool isMirrored)
Definition: eda_text.h:191
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:142
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.
void SetKeepUpright(bool aKeepUpright)
void SetShape(STROKE_T aShape)
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:90
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set 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:201
static TOOL_ACTION placeDXF
Activation of the drawing tool (placing a drawing from DXF file)
Definition: pcb_actions.h:181
void SetBezierPoints(const std::vector< wxPoint > &aPoints)
TEXTE_PCB class definition.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
int DrawVia(const TOOL_EVENT &aEvent)
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
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:273
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:458
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:187
bool IsItalic() const
Definition: eda_text.h:183
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:172
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
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.
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:151
void SetType(int aType)
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.
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:77
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:281
void SetItalic(bool isItalic)
Definition: eda_text.h:182
static TOOL_ACTION drawZoneKeepout
Activation of the drawing tool (drawing a keepout area)
Definition: pcb_actions.h:166
EDA_ITEM * Front() const
Definition: selection.h:152
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:374
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
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:111
void SetVisible(bool aVisible)
Definition: eda_text.h:188
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.
PCB_LAYER_ID m_layer
Layer to begin drawing
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.
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aDraggedItem)
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
Parameters used to fully describe a zone creation process.
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
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 InstallTextOptionsFrame(BOARD_ITEM *aText, wxDC *aDC)
Routine for main window class to launch text properties dialog.
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
static TOOL_ACTION setAnchor
Activation of the drawing tool (placing the footprint anchor)
Definition: pcb_actions.h:184
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:154
static const int delta[8][2]
Definition: solve.cpp:112
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:364
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
bool IsBold() const
Definition: eda_text.h:186
double GetTextAngle() const
Definition: eda_text.h:177
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:167
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:190
static TOOL_ACTION drawGraphicPolygon
Definition: pcb_actions.h:145
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:271
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
static bool m_use45DegreeGraphicSegments
DIMENSION class definition.
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
PCB_LAYER_ID
A quick note on layer IDs:
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets t...
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
STROKE_T GetShape() const
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:256
const auto NULLOPT
Definition: optional.h:9
static TOOL_ACTION drawDimension
Activation of the drawing tool (dimension)
Definition: pcb_actions.h:157
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:254
const wxPoint & GetEnd()
Function GetEnd.
VIATYPE_T GetViaType() const
Definition: class_track.h:457
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
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.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
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:143
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:207
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:139
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:278
SELECTION & GetSelection()
Function GetSelection()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
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:141
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void AdjustDimensionDetails()
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension...
a few functions useful in geometry calculations.
const wxPoint & GetBezControl1() const
static TOOL_ACTION drawVia
Activation of the drawing tool (drawing a VIA)
Definition: pcb_actions.h:163
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:272
SHAPE_POLY_SET & GetPolyShape()
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
int GetType() const
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
void SetUnits(EDA_UNITS_T aUnits, bool aUseMils)
virtual void Move(const wxPoint &aWhere)
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
All active tools
Definition: tool_event.h:144
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:1530
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:169
void Expire(int aMsecs)
Hides the popup after a specified time.
const wxPoint GetPosition() const override
Definition: class_track.h:429
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
void SetMultilineAllowed(bool aAllow)
Function SetMultiLineAllowed.
Definition: eda_text.h:200
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 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:274
bool m_editModules
Definition: pcb_tool.h:150
void SetSnap(bool aSnap)
Definition: grid_helper.h:63
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:148
Definition: seg.h:36
bool GetTextUpright(PCB_LAYER_ID aLayer) const
const std::vector< wxPoint > & GetBezierPoints() const
void SetLocalCoord()
Set relative coordinates from draw coordinates.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
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:193
void SetLocalCoord()
Set relative coordinates.
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:286
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:256
void constrainDimension(DIMENSION *dimension)
Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees...
double GetAngle() const
void ToggleClockwise()
Reverse the current are direction
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
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:192
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:465
This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry ...
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
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
Return 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:186
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
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:257
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()
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec)
Snap a vector onto the nearest 0, 45 or 90 degree line.
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:253
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
void SetUseGrid(bool aGrid=true)
Definition: grid_helper.h:68
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:228
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
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:166
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:185
void make45DegLine(DRAWSEGMENT *aSegment, DRAWSEGMENT *aHelper, VECTOR2I &aPos) const
Function make45DegLine() Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees.
wxPoint m_featureLineDO
void Flip(T &aValue)
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:184
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
#define mod(a, n)
Definition: greymap.cpp:24
static TOOL_ACTION drawZone
Activation of the drawing tool (drawing a ZONE)
Definition: pcb_actions.h:160
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.
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:161
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
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:457
void SetBezControl1(const wxPoint &aPoint)
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
BOARD * board() const
Definition: pcb_tool.h:140
void SetWidth(int aWidth)
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:82