KiCad PCB EDA Suite
point_editor.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) 2013-2019 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <functional>
26 using namespace std::placeholders;
27 #include <tool/tool_manager.h>
28 #include <view/view_controls.h>
30 #include <geometry/seg.h>
31 #include <confirm.h>
32 #include "pcb_actions.h"
33 #include "selection_tool.h"
34 #include "point_editor.h"
35 #include "grid_helper.h"
36 #include <board_commit.h>
37 #include <bitmaps.h>
38 #include <status_popup.h>
39 #include <pcb_edit_frame.h>
40 #include <class_edge_mod.h>
41 #include <class_dimension.h>
42 #include <class_zone.h>
45 
46 // Few constants to avoid using bare numbers for point indices
48 {
50 };
51 
53 {
55 };
56 
58 {
60 };
61 
63 {
68 };
69 
71 {
76 };
77 
79 {
80 private:
81 
82  static void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
83  const SHAPE_POLY_SET* aOutline, KIGFX::GAL* aGal )
84  {
85 
86  int cornersCount = aOutline->TotalVertices();
87 
88  for( auto iterator = aOutline->CIterateWithHoles(); iterator; iterator++ )
89  {
90  points->AddPoint( *iterator );
91 
92  if( iterator.IsEndContour() )
93  points->AddBreak();
94  }
95 
96  // Lines have to be added after creating edit points,
97  // as they use EDIT_POINT references
98  for( int i = 0; i < cornersCount - 1; ++i )
99  {
100  if( points->IsContourEnd( i ) )
101  {
102  points->AddLine( points->Point( i ),
103  points->Point( points->GetContourStartIdx( i ) ) );
104  }
105  else
106  {
107  points->AddLine( points->Point( i ), points->Point( i + 1 ) );
108  }
109 
110  points->Line( i ).SetConstraint( new EC_SNAPLINE( points->Line( i ),
111  std::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
112  }
113 
114  // The last missing line, connecting the last and the first polygon point
115  points->AddLine( points->Point( cornersCount - 1 ),
116  points->Point( points->GetContourStartIdx( cornersCount - 1 ) ) );
117 
118  points->Line( points->LinesSize() - 1 ).SetConstraint(
119  new EC_SNAPLINE( points->Line( points->LinesSize() - 1 ),
120  std::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
121  }
122 
123 public:
124  static std::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem, KIGFX::GAL* aGal )
125  {
126  std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
127 
128  if( !aItem )
129  return points;
130 
131  // Generate list of edit points basing on the item type
132  switch( aItem->Type() )
133  {
134  case PCB_LINE_T:
135  case PCB_MODULE_EDGE_T:
136  {
137  const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem );
138 
139  switch( segment->GetShape() )
140  {
141  case S_SEGMENT:
142  points->AddPoint( segment->GetStart() );
143  points->AddPoint( segment->GetEnd() );
144  break;
145 
146  case S_ARC:
147  points->AddPoint( segment->GetCenter() );
148  points->AddPoint( segment->GetArcStart() );
149  points->AddPoint( segment->GetArcMid() );
150  points->AddPoint( segment->GetArcEnd() );
151 
152  // Set constraints
153  // Arc end has to stay at the same radius as the start
154  points->Point( ARC_END ).SetConstraint( new EC_CIRCLE( points->Point( ARC_END ),
155  points->Point( ARC_CENTER ),
156  points->Point( ARC_START ) ) );
157 
158  points->Point( ARC_MID ).SetConstraint( new EC_LINE( points->Point( ARC_MID ),
159  points->Point( ARC_CENTER ) ) );
160  break;
161 
162  case S_CIRCLE:
163  points->AddPoint( segment->GetCenter() );
164  points->AddPoint( segment->GetEnd() );
165 
166  break;
167 
168  case S_POLYGON:
169  buildForPolyOutline( points, &segment->GetPolyShape(), aGal );
170  break;
171 
172  case S_CURVE:
173  points->AddPoint( segment->GetStart() );
174  points->AddPoint( segment->GetBezControl1() );
175  points->AddPoint( segment->GetBezControl2() );
176  points->AddPoint( segment->GetEnd() );
177  break;
178 
179  default: // suppress warnings
180  break;
181  }
182 
183  break;
184  }
185 
186  case PCB_ZONE_AREA_T:
187  {
188  auto zone = static_cast<const ZONE_CONTAINER*>( aItem );
189  buildForPolyOutline( points, zone->Outline(), aGal );
190  break;
191  }
192 
193  case PCB_DIMENSION_T:
194  {
195  const DIMENSION* dimension = static_cast<const DIMENSION*>( aItem );
196 
197  points->AddPoint( dimension->m_crossBarO );
198  points->AddPoint( dimension->m_crossBarF );
199  points->AddPoint( dimension->m_featureLineGO );
200  points->AddPoint( dimension->m_featureLineDO );
201 
202  // Dimension height setting - edit points should move only along the feature lines
203  points->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( points->Point( DIM_CROSSBARO ),
204  points->Point( DIM_FEATUREGO ) ) );
205  points->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( points->Point( DIM_CROSSBARF ),
206  points->Point( DIM_FEATUREDO ) ) );
207 
208  break;
209  }
210 
211  default:
212  points.reset();
213  break;
214  }
215 
216  return points;
217  }
218 
219 private:
221 };
222 
223 
225  PCB_TOOL_BASE( "pcbnew.PointEditor" ),
226  m_selectionTool( NULL ),
227  m_editedPoint( NULL ),
228  m_original( VECTOR2I( 0, 0 ) ),
229  m_altConstrainer( VECTOR2I( 0, 0 ) ),
230  m_refill( false )
231 {
232 }
233 
234 
236 {
237  m_refill = false;
238  m_editPoints.reset();
239  m_altConstraint.reset();
240  getViewControls()->SetAutoPan( false );
241 
242  m_statusPopup.reset( new STATUS_TEXT_POPUP( getEditFrame<PCB_BASE_EDIT_FRAME>() ) );
243  m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) );
244  m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) );
245 }
246 
247 
249 {
250  // Find the selection tool, so they can cooperate
252 
253  wxASSERT_MSG( m_selectionTool, _( "pcbnew.InteractiveSelection tool is not available" ) );
254 
255  auto& menu = m_selectionTool->GetToolMenu().GetMenu();
258  std::bind( &POINT_EDITOR::removeCornerCondition, this, _1 ) );
259 
260  return true;
261 }
262 
263 
265 {
266  EDIT_POINT* point;
267 
268  if( aEvent.IsMotion() )
269  {
270  point = m_editPoints->FindPoint( aEvent.Position(), getView() );
271  }
272  else if( aEvent.IsDrag( BUT_LEFT ) )
273  {
274  point = m_editPoints->FindPoint( aEvent.DragOrigin(), getView() );
275  }
276  else
277  {
278  point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() );
279  }
280 
281  if( m_editedPoint != point )
282  setEditedPoint( point );
283 }
284 
285 
287 {
288  if( !m_selectionTool )
289  return 0;
290 
292 
293  if( selection.Size() != 1 || selection.Front()->GetEditFlags() )
294  return 0;
295 
296  Activate();
297 
299  KIGFX::VIEW* view = getView();
300  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
301 
302  controls->ShowCursor( true );
303 
304  GRID_HELPER grid( editFrame );
305  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
306 
307  if( !item )
308  return 0;
309 
310  m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
311 
312  if( !m_editPoints )
313  return 0;
314 
315  view->Add( m_editPoints.get() );
316  setEditedPoint( nullptr );
317  updateEditedPoint( aEvent );
318  m_refill = false;
319  bool inDrag = false;
320 
321  BOARD_COMMIT commit( editFrame );
322  LSET snapLayers = item->GetLayerSet();
323 
324  if( item->Type() == PCB_DIMENSION_T )
325  snapLayers = LSET::AllLayersMask();
326 
327  // Main loop: keep receiving events
328  while( TOOL_EVENT* evt = Wait() )
329  {
330  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
331  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
332  controls->SetSnapping( !evt->Modifier( MD_ALT ) );
333 
334  if( !m_editPoints || evt->IsSelectionEvent() )
335  break;
336 
337  if ( !inDrag )
338  updateEditedPoint( *evt );
339 
340  if( evt->IsDrag( BUT_LEFT ) && m_editedPoint )
341  {
342  if( !inDrag )
343  {
344  commit.StageItems( selection, CHT_MODIFY );
345 
346  controls->ForceCursorPosition( false );
347  m_original = *m_editedPoint; // Save the original position
348  controls->SetAutoPan( true );
349  inDrag = true;
350  grid.SetAuxAxes( true, m_original.GetPosition() );
351  }
352 
353  //TODO: unify the constraints to solve simultaneously instead of sequentially
354  m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(),
355  snapLayers, { item } ) );
356  bool enableAltConstraint = !!evt->Modifier( MD_CTRL );
357 
358  if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint
359  setAltConstraint( enableAltConstraint );
360 
361  if( m_altConstraint )
362  m_altConstraint->Apply();
363  else
365 
367  snapLayers, { item } ) );
368 
369  updateItem();
370  updatePoints();
371  }
372 
373  else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
374  {
375  controls->SetAutoPan( false );
376  setAltConstraint( false );
377 
378  commit.Push( _( "Drag a corner" ) );
379  inDrag = false;
380  m_refill = true;
381  }
382 
383  else if( evt->IsCancelInteractive() || evt->IsActivate() )
384  {
385  if( inDrag ) // Restore the last change
386  commit.Revert();
387  else if( evt->IsCancelInteractive() )
388  break;
389 
390  if( evt->IsActivate() && !evt->IsMoveTool() )
391  break;
392  }
393 
394  else
395  evt->SetPassEvent();
396  }
397 
398  if( m_editPoints )
399  {
400  view->Remove( m_editPoints.get() );
401 
402  finishItem();
403  m_editPoints.reset();
404  }
405 
406  frame()->UpdateMsgPanel();
407 
408  return 0;
409 }
410 
411 
413 {
414  EDA_ITEM* item = m_editPoints->GetParent();
415 
416  if( !item )
417  return;
418 
419  switch( item->Type() )
420  {
421  case PCB_LINE_T:
422  case PCB_MODULE_EDGE_T:
423  {
424  DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item );
425  switch( segment->GetShape() )
426  {
427  case S_SEGMENT:
428  if( isModified( m_editPoints->Point( SEG_START ) ) )
429  segment->SetStart( wxPoint( m_editPoints->Point( SEG_START ).GetPosition().x,
430  m_editPoints->Point( SEG_START ).GetPosition().y ) );
431 
432  else if( isModified( m_editPoints->Point( SEG_END ) ) )
433  segment->SetEnd( wxPoint( m_editPoints->Point( SEG_END ).GetPosition().x,
434  m_editPoints->Point( SEG_END ).GetPosition().y ) );
435 
436  break;
437 
438  case S_ARC:
439  {
440  VECTOR2I center = m_editPoints->Point( ARC_CENTER ).GetPosition();
441  VECTOR2I mid = m_editPoints->Point( ARC_MID ).GetPosition();
442  VECTOR2I start = m_editPoints->Point( ARC_START ).GetPosition();
443  VECTOR2I end = m_editPoints->Point( ARC_END ).GetPosition();
444 
445  if( center != segment->GetCenter() )
446  {
447  wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
448  segment->Move( moveVector );
449 
450  m_editPoints->Point( ARC_START ).SetPosition( segment->GetArcStart() );
451  m_editPoints->Point( ARC_END ).SetPosition( segment->GetArcEnd() );
452  m_editPoints->Point( ARC_MID ).SetPosition( segment->GetArcMid() );
453  }
454  else
455  {
456  if( mid != segment->GetArcMid() )
457  {
458  center = GetArcCenter( start, mid, end );
459  segment->SetCenter( wxPoint( center.x, center.y ) );
460  m_editPoints->Point( ARC_CENTER ).SetPosition( center );
461  }
462 
463  segment->SetArcStart( wxPoint( start.x, start.y ) );
464 
465  VECTOR2D startLine = start - center;
466  VECTOR2D endLine = end - center;
467  double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
468 
469  // Adjust the new angle to (counter)clockwise setting
470  bool clockwise = ( segment->GetAngle() > 0 );
471 
472  if( clockwise && newAngle < 0.0 )
473  newAngle += 3600.0;
474  else if( !clockwise && newAngle > 0.0 )
475  newAngle -= 3600.0;
476 
477  segment->SetAngle( newAngle );
478  }
479 
480  break;
481  }
482 
483  case S_CIRCLE:
484  {
485  const VECTOR2I& center = m_editPoints->Point( CIRC_CENTER ).GetPosition();
486  const VECTOR2I& end = m_editPoints->Point( CIRC_END ).GetPosition();
487 
488  if( isModified( m_editPoints->Point( CIRC_CENTER ) ) )
489  {
490  wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
491  segment->Move( moveVector );
492  }
493  else
494  {
495  segment->SetEnd( wxPoint( end.x, end.y ) );
496  }
497 
498  break;
499  }
500 
501  case S_POLYGON:
502  {
503  SHAPE_POLY_SET& outline = segment->GetPolyShape();
504 
505  for( int i = 0; i < outline.TotalVertices(); ++i )
506  outline.Vertex( i ) = m_editPoints->Point( i ).GetPosition();
507 
508  validatePolygon( outline );
509  break;
510  }
511 
512  case S_CURVE:
513  if( isModified( m_editPoints->Point( BEZIER_CURVE_START ) ) )
514  segment->SetStart( wxPoint( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().x,
515  m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().y ) );
516  else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ) ) )
517  segment->SetBezControl1( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().x,
518  m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().y ) );
519  else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ) ) )
520  segment->SetBezControl2( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().x,
521  m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().y ) );
522  else if( isModified( m_editPoints->Point( BEZIER_CURVE_END ) ) )
523  segment->SetEnd( wxPoint( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().x,
524  m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().y ) );
525 
526  segment->RebuildBezierToSegmentsPointsList( segment->GetWidth() );
527  break;
528 
529  default: // suppress warnings
530  break;
531  }
532 
533  // Update relative coordinates for module edges
534  if( EDGE_MODULE* edge = dyn_cast<EDGE_MODULE*>( item ) )
535  edge->SetLocalCoord();
536 
537  break;
538  }
539 
540  case PCB_ZONE_AREA_T:
541  {
542  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
543  zone->ClearFilledPolysList();
544  SHAPE_POLY_SET& outline = *zone->Outline();
545 
546  for( int i = 0; i < outline.TotalVertices(); ++i )
547  {
548  if( outline.Vertex( i ) != m_editPoints->Point( i ).GetPosition() )
549  zone->SetNeedRefill( true );
550 
551  outline.Vertex( i ) = m_editPoints->Point( i ).GetPosition();
552  }
553 
554  validatePolygon( outline );
555  zone->Hatch();
556  break;
557  }
558 
559  case PCB_DIMENSION_T:
560  {
561  DIMENSION* dimension = static_cast<DIMENSION*>( item );
562 
563  // Check which point is currently modified and updated dimension's points respectively
564  if( isModified( m_editPoints->Point( DIM_CROSSBARO ) ) )
565  {
566  VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetOrigin() );
567  VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
568 
569  if( featureLine.Cross( crossBar ) > 0 )
570  dimension->SetHeight( -featureLine.EuclideanNorm() );
571  else
572  dimension->SetHeight( featureLine.EuclideanNorm() );
573  }
574 
575  else if( isModified( m_editPoints->Point( DIM_CROSSBARF ) ) )
576  {
577  VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetEnd() );
578  VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
579 
580  if( featureLine.Cross( crossBar ) > 0 )
581  dimension->SetHeight( -featureLine.EuclideanNorm() );
582  else
583  dimension->SetHeight( featureLine.EuclideanNorm() );
584  }
585 
586  else if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) )
587  {
588  dimension->SetOrigin( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) );
589  m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ),
590  m_editPoints->Point( DIM_FEATUREGO ) ) );
591  m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ),
592  m_editPoints->Point( DIM_FEATUREDO ) ) );
593  }
594 
595  else if( isModified( m_editPoints->Point( DIM_FEATUREDO ) ) )
596  {
597  dimension->SetEnd( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) );
598  m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ),
599  m_editPoints->Point( DIM_FEATUREGO ) ) );
600  m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ),
601  m_editPoints->Point( DIM_FEATUREDO ) ) );
602  }
603 
604  break;
605  }
606 
607  default:
608  break;
609  }
610 
611  if( frame() )
612  frame()->SetMsgPanel( item );
613 }
614 
615 
617 {
618  auto item = m_editPoints->GetParent();
619 
620  if( !item )
621  return;
622 
623  if( item->Type() == PCB_ZONE_AREA_T )
624  {
625  auto zone = static_cast<ZONE_CONTAINER*>( item );
626 
627  if( zone->IsFilled() && m_refill && zone->NeedRefill() )
628  m_toolMgr->RunAction( PCB_ACTIONS::zoneFill, true, zone );
629  }
630 }
631 
632 
634 {
635  bool valid = !aPoly.IsSelfIntersecting();
636 
637  if( m_statusPopup )
638  {
639  if( valid )
640  {
641  m_statusPopup->Hide();
642  }
643  else
644  {
645  wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
646  m_statusPopup->Move( p );
647  m_statusPopup->PopupFor( 1500 );
648  }
649  }
650 
651  return valid;
652 }
653 
654 
656 {
657  if( !m_editPoints )
658  return;
659 
660  EDA_ITEM* item = m_editPoints->GetParent();
661 
662  if( !item )
663  return;
664 
665  switch( item->Type() )
666  {
667  case PCB_LINE_T:
668  case PCB_MODULE_EDGE_T:
669  {
670  const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item );
671 
672  switch( segment->GetShape() )
673  {
674  case S_SEGMENT:
675  m_editPoints->Point( SEG_START ).SetPosition( segment->GetStart() );
676  m_editPoints->Point( SEG_END ).SetPosition( segment->GetEnd() );
677  break;
678 
679  case S_ARC:
680  m_editPoints->Point( ARC_CENTER ).SetPosition( segment->GetCenter() );
681  m_editPoints->Point( ARC_START ).SetPosition( segment->GetArcStart() );
682  m_editPoints->Point( ARC_MID ).SetPosition( segment->GetArcMid() );
683  m_editPoints->Point( ARC_END ).SetPosition( segment->GetArcEnd() );
684  break;
685 
686  case S_CIRCLE:
687  m_editPoints->Point( CIRC_CENTER ).SetPosition( segment->GetCenter() );
688  m_editPoints->Point( CIRC_END ).SetPosition( segment->GetEnd() );
689  break;
690 
691  case S_POLYGON:
692  {
693  const auto& points = segment->BuildPolyPointsList();
694 
695  if( m_editPoints->PointsSize() != (unsigned) points.size() )
696  {
697  getView()->Remove( m_editPoints.get() );
698  m_editedPoint = nullptr;
699  m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
700  getView()->Add( m_editPoints.get() );
701  }
702  else
703  {
704  for( unsigned i = 0; i < points.size(); i++ )
705  m_editPoints->Point( i ).SetPosition( points[i] );
706  }
707  break;
708  }
709 
710  case S_CURVE:
711  m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( segment->GetStart() );
712  m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( segment->GetBezControl1() );
713  m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( segment->GetBezControl2() );
714  m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( segment->GetEnd() );
715  break;
716 
717  default: // suppress warnings
718  break;
719  }
720 
721  break;
722  }
723 
724  case PCB_ZONE_AREA_T:
725  {
726  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
727  const SHAPE_POLY_SET* outline = zone->Outline();
728 
729  if( m_editPoints->PointsSize() != (unsigned) outline->TotalVertices() )
730  {
731  getView()->Remove( m_editPoints.get() );
732  m_editedPoint = nullptr;
733  m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
734  getView()->Add( m_editPoints.get() );
735  }
736  else
737  {
738  for( int i = 0; i < outline->TotalVertices(); ++i )
739  m_editPoints->Point( i ).SetPosition( outline->CVertex( i ) );
740  }
741 
742  break;
743  }
744 
745  case PCB_DIMENSION_T:
746  {
747  const DIMENSION* dimension = static_cast<const DIMENSION*>( item );
748 
749  m_editPoints->Point( DIM_CROSSBARO ).SetPosition( dimension->m_crossBarO );
750  m_editPoints->Point( DIM_CROSSBARF ).SetPosition( dimension->m_crossBarF );
751  m_editPoints->Point( DIM_FEATUREGO ).SetPosition( dimension->m_featureLineGO );
752  m_editPoints->Point( DIM_FEATUREDO ).SetPosition( dimension->m_featureLineDO );
753  break;
754  }
755 
756  default:
757  break;
758  }
759 
760  getView()->Update( m_editPoints.get() );
761 }
762 
763 
765 {
767 
768  if( aPoint )
769  {
770  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
771  controls->ForceCursorPosition( true, aPoint->GetPosition() );
772  controls->ShowCursor( true );
773  }
774  else
775  {
776  if( frame()->ToolStackIsEmpty() )
777  controls->ShowCursor( false );
778 
779  controls->ForceCursorPosition( false );
780  }
781 
782  m_editedPoint = aPoint;
783 }
784 
785 
786 void POINT_EDITOR::setAltConstraint( bool aEnabled )
787 {
788  if( aEnabled )
789  {
790  EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
791 
792  if( line && m_editPoints->GetParent()->Type() == PCB_ZONE_AREA_T )
793  {
795  }
796  else
797  {
798  // Find a proper constraining point for 45 degrees mode
801  }
802  }
803  else
804  {
805  m_altConstraint.reset();
806  }
807 }
808 
809 
811 {
812  EDA_ITEM* item = m_editPoints->GetParent();
813 
814  switch( item->Type() )
815  {
816  case PCB_LINE_T:
817  case PCB_MODULE_EDGE_T:
818  {
819  const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item );
820  {
821  switch( segment->GetShape() )
822  {
823  case S_SEGMENT:
824  return *( m_editPoints->Next( *m_editedPoint ) ); // select the other end of line
825 
826  case S_ARC:
827  case S_CIRCLE:
828  return m_editPoints->Point( CIRC_CENTER );
829 
830  default: // suppress warnings
831  break;
832  }
833  }
834 
835  break;
836  }
837 
838  case PCB_DIMENSION_T:
839  {
840  // Constraint for crossbar
841  if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) )
842  return m_editPoints->Point( DIM_FEATUREDO );
843 
844  else if( isModified( m_editPoints->Point( DIM_FEATUREDO ) ) )
845  return m_editPoints->Point( DIM_FEATUREGO );
846 
847  else
848  return EDIT_POINT( m_editedPoint->GetPosition() ); // no constraint
849 
850  break;
851  }
852 
853  default:
854  break;
855  }
856 
857  // In any other case we may align item to its original position
858  return m_original;
859 }
860 
861 
863 {
864  const auto type = aItem.Type();
865 
866  // Works only for zones and line segments
867  return type == PCB_ZONE_AREA_T ||
868  ( ( type == PCB_LINE_T || type == PCB_MODULE_EDGE_T ) &&
869  ( static_cast<const DRAWSEGMENT&>( aItem ).GetShape() == S_SEGMENT ||
870  static_cast<const DRAWSEGMENT&>( aItem ).GetShape() == S_POLYGON ) );
871 }
872 
873 
875 {
876  if( aSelection.Size() != 1 )
877  return false;
878 
879  const EDA_ITEM* item = aSelection.Front();
880 
881  return ( item != nullptr ) && canAddCorner( *item );
882 }
883 
884 
885 // Finds a corresponding vertex in a polygon set
886 static std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX>
887 findVertex( SHAPE_POLY_SET& aPolySet, const EDIT_POINT& aPoint )
888 {
889  for( auto it = aPolySet.IterateWithHoles(); it; ++it )
890  {
891  auto vertexIdx = it.GetIndex();
892 
893  if( aPolySet.Vertex( vertexIdx ) == aPoint.GetPosition() )
894  return std::make_pair( true, vertexIdx );
895  }
896 
897  return std::make_pair( false, SHAPE_POLY_SET::VERTEX_INDEX() );
898 }
899 
900 
902 {
903  if( !m_editPoints || !m_editedPoint )
904  return false;
905 
906  EDA_ITEM* item = m_editPoints->GetParent();
907 
908  if( !item || !( item->Type() == PCB_ZONE_AREA_T ||
909  ( ( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_LINE_T ) &&
910  static_cast<DRAWSEGMENT*>( item )->GetShape() == S_POLYGON ) ) )
911  return false;
912 
913  SHAPE_POLY_SET *polyset;
914 
915  if( item->Type() == PCB_ZONE_AREA_T )
916  polyset = static_cast<ZONE_CONTAINER*>( item )->Outline();
917  else
918  polyset = &static_cast<DRAWSEGMENT*>( item )->GetPolyShape();
919 
920  auto vertex = findVertex( *polyset, *m_editedPoint );
921 
922  if( !vertex.first )
923  return false;
924 
925  const auto& vertexIdx = vertex.second;
926 
927  // Check if there are enough vertices so one can be removed without
928  // degenerating the polygon.
929  // The first condition allows one to remove all corners from holes (when
930  // there are only 2 vertices left, a hole is removed).
931  if( vertexIdx.m_contour == 0 && polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
932  return false;
933 
934  // Remove corner does not work with lines
935  if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
936  return false;
937 
938  return m_editedPoint != NULL;
939 }
940 
941 
943 {
944  if( !m_editPoints )
945  return 0;
946 
947  EDA_ITEM* item = m_editPoints->GetParent();
948  PCB_BASE_EDIT_FRAME* frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
949  const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
950 
951  // called without an active edited polygon
952  if( !item || !canAddCorner( *item ) )
953  return 0;
954 
955  DRAWSEGMENT* graphicItem = dynamic_cast<DRAWSEGMENT*>( item );
956  BOARD_COMMIT commit( frame );
957 
958  if( item->Type() == PCB_ZONE_AREA_T ||
959  ( graphicItem && graphicItem->GetShape() == S_POLYGON ) )
960  {
961  unsigned int nearestIdx = 0;
962  unsigned int nextNearestIdx = 0;
963  unsigned int nearestDist = INT_MAX;
964  unsigned int firstPointInContour = 0;
965  SHAPE_POLY_SET* zoneOutline;
966 
967  if( item->Type() == PCB_ZONE_AREA_T )
968  {
969  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
970  zoneOutline = zone->Outline();
971  zone->SetNeedRefill( true );
972  }
973  else
974  zoneOutline = &( graphicItem->GetPolyShape() );
975 
976  commit.Modify( item );
977 
978  // Search the best outline segment to add a new corner
979  // and therefore break this segment into two segments
980 
981  // Object to iterate through the corners of the outlines (main contour and its holes)
982  SHAPE_POLY_SET::ITERATOR iterator = zoneOutline->Iterate( 0,
983  zoneOutline->OutlineCount()-1, /* IterateHoles */ true );
984  int curr_idx = 0;
985 
986  // Iterate through all the corners of the outlines and search the best segment
987  for( ; iterator; iterator++, curr_idx++ )
988  {
989  int jj = curr_idx+1;
990 
991  if( iterator.IsEndContour() )
992  { // We reach the last point of the current contour (main or hole)
993  jj = firstPointInContour;
994  firstPointInContour = curr_idx+1; // Prepare next contour analysis
995  }
996 
997  SEG curr_segment( zoneOutline->Vertex( curr_idx ), zoneOutline->Vertex( jj ) );
998 
999  unsigned int distance = curr_segment.Distance( cursorPos );
1000 
1001  if( distance < nearestDist )
1002  {
1003  nearestDist = distance;
1004  nearestIdx = curr_idx;
1005  nextNearestIdx = jj;
1006  }
1007  }
1008 
1009  // Find the point on the closest segment
1010  VECTOR2I sideOrigin = zoneOutline->Vertex( nearestIdx );
1011  VECTOR2I sideEnd = zoneOutline->Vertex( nextNearestIdx );
1012  SEG nearestSide( sideOrigin, sideEnd );
1013  VECTOR2I nearestPoint = nearestSide.NearestPoint( cursorPos );
1014 
1015  // Do not add points that have the same coordinates as ones that already belong to polygon
1016  // instead, add a point in the middle of the side
1017  if( nearestPoint == sideOrigin || nearestPoint == sideEnd )
1018  nearestPoint = ( sideOrigin + sideEnd ) / 2;
1019 
1020  zoneOutline->InsertVertex( nextNearestIdx, nearestPoint );
1021 
1022  // We re-hatch the filled zones but not polygons
1023  if( item->Type() == PCB_ZONE_AREA_T )
1024  static_cast<ZONE_CONTAINER*>( item )->Hatch();
1025 
1026 
1027  commit.Push( _( "Add a zone corner" ) );
1028  }
1029 
1030  else if( graphicItem && graphicItem->GetShape() == S_SEGMENT )
1031  {
1032  commit.Modify( graphicItem );
1033 
1034  SEG seg( graphicItem->GetStart(), graphicItem->GetEnd() );
1035  VECTOR2I nearestPoint = seg.NearestPoint( cursorPos );
1036 
1037  // Move the end of the line to the break point..
1038  graphicItem->SetEnd( wxPoint( nearestPoint.x, nearestPoint.y ) );
1039 
1040  // and add another one starting from the break point
1041  DRAWSEGMENT* newSegment;
1042 
1043  if( item->Type() == PCB_MODULE_EDGE_T )
1044  {
1045  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( graphicItem );
1046  assert( edge->GetParent()->Type() == PCB_MODULE_T );
1047  newSegment = new EDGE_MODULE( *edge );
1048  }
1049  else
1050  {
1051  newSegment = new DRAWSEGMENT( *graphicItem );
1052  }
1053 
1054  newSegment->ClearSelected();
1055  newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) );
1056  newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) );
1057 
1058  commit.Add( newSegment );
1059  commit.Push( _( "Split segment" ) );
1060  }
1061 
1062  updatePoints();
1063  return 0;
1064 }
1065 
1066 
1068 {
1069  if( !m_editPoints || !m_editedPoint )
1070  return 0;
1071 
1072  EDA_ITEM* item = m_editPoints->GetParent();
1073 
1074  if( !item )
1075  return 0;
1076 
1077  SHAPE_POLY_SET* polygon = nullptr;
1078 
1079  if( item->Type() == PCB_ZONE_AREA_T)
1080  {
1081  auto zone = static_cast<ZONE_CONTAINER*>( item );
1082  polygon = zone->Outline();
1083  zone->SetNeedRefill( true );
1084  }
1085  else if( (item->Type() == PCB_MODULE_EDGE_T ) || ( item->Type() == PCB_LINE_T ) )
1086  {
1087  auto ds = static_cast<DRAWSEGMENT*>( item );
1088 
1089  if( ds->GetShape() == S_POLYGON )
1090  polygon = &ds->GetPolyShape();
1091  }
1092 
1093  if( !polygon )
1094  return 0;
1095 
1096  PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
1097  BOARD_COMMIT commit( frame );
1098  auto vertex = findVertex( *polygon, *m_editedPoint );
1099 
1100  if( vertex.first )
1101  {
1102  const auto& vertexIdx = vertex.second;
1103  auto& outline = polygon->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour];
1104 
1105  if( outline.PointCount() > 3 )
1106  {
1107  // the usual case: remove just the corner when there are >3 vertices
1108  commit.Modify( item );
1109  polygon->RemoveVertex( vertexIdx );
1110  validatePolygon( *polygon );
1111  }
1112  else
1113  {
1114  // either remove a hole or the polygon when there are <= 3 corners
1115  if( vertexIdx.m_contour > 0 )
1116  {
1117  // remove hole
1118  commit.Modify( item );
1119  polygon->RemoveContour( vertexIdx.m_contour );
1120  }
1121  else
1122  {
1124  commit.Remove( item );
1125  }
1126  }
1127 
1128  setEditedPoint( nullptr );
1129 
1130  commit.Push( _( "Remove a zone/polygon corner" ) );
1131 
1132  // Refresh zone hatching
1133  if( item->Type() == PCB_ZONE_AREA_T)
1134  static_cast<ZONE_CONTAINER*>( item )->Hatch();
1135 
1136  updatePoints();
1137  }
1138 
1139  return 0;
1140 }
1141 
1142 
1144 {
1145  updatePoints();
1146  return 0;
1147 }
1148 
1149 
1151 {
1158 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
const wxPoint GetArcMid() const
int TotalVertices() const
Returns total number of vertices stored in the set.
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
Class EC_CONVERGING.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
int OnSelectionChange(const TOOL_EVENT &aEvent)
Function OnSelected()
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
void setTransitions() override
Sets up handlers for various events.
int OutlineCount() const
Returns the number of outlines in the set
bool IsEndContour() const
Function IsEndContour.
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
static TOOL_ACTION activatePointEditor
Definition: actions.h:158
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
This file is part of the common library.
wxPoint m_crossBarF
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
const wxPoint GetCenter() const override
Function GetCenter()
void ClearSelected()
Definition: base_struct.h:243
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
VIEW_CONTROLS class definition.
STROKE_T GetShape() const
const wxPoint GetArcEnd() const
void updateEditedPoint(const TOOL_EVENT &aEvent)
Updates which point is being edited.
Class SELECTION_TOOL.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Returns the index-th vertex in a given hole outline within a given outline
Class STATUS_TEXT_POPUP.
Definition: status_popup.h:79
virtual void Revert() override
Revertes the commit by restoring the modifed items state.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
polygon (not yet used for tracks, but could be in microwave apps)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
Class EDIT_LINE.
Definition: edit_points.h:207
int removeCorner(const TOOL_EVENT &aEvent)
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments Has me...
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:237
CONST_ITERATOR CIterateWithHoles(int aOutline) const
TOOL_MENU & GetToolMenu()
bool IsMotion() const
Definition: tool_event.h:303
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:109
double RAD2DECIDEG(double rad)
Definition: trigo.h:215
Struct VERTEX_INDEX.
void setAltConstraint(bool aEnabled)
Sets up an alternative constraint (typically enabled upon a modifier key being pressed).
usual segment : line with rounded ends
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aDraggedItem)
bool isModified(const EDIT_POINT &aPoint) const
Returns true if aPoint is the currently modified point.
Definition: point_editor.h:117
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: point_editor.h:92
ITERATOR Iterate(int aFirst, int aLast, bool aIterateHoles=false)
Function Iterate returns an object to iterate through the points of the polygons between aFirst and a...
CIRCLE_POINTS
const std::vector< wxPoint > BuildPolyPointsList() const
Build and return the list of corners in a std::vector<wxPoint> It must be used only to convert the SH...
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void SetBezControl2(const wxPoint &aPoint)
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:289
Class EC_LINE.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
Class EC_45DEGREE.
void updateItem() const
Updates item's points with edit points.
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:200
bool removeCornerCondition(const SELECTION &aSelection)
Condition to display "Remove corner" context menu entry.
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
Class EC_CIRCLE.
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
wxPoint m_featureLineGO
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world...
PCB_BASE_EDIT_FRAME * frame() const
DIMENSION class definition.
std::shared_ptr< EDIT_POINTS > m_editPoints
Currently available edit points.
Definition: point_editor.h:81
void finishItem()
Applies the last changes to the edited item.
class MODULE, a footprint
Definition: typeinfo.h:89
void SetAuxAxes(bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
Definition: grid_helper.cpp:92
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:293
void SetOrigin(const wxPoint &aOrigin)
Function SetOrigin Sets a new origin of the crossbar line.
Class LSET is a set of PCB_LAYER_IDs.
const PCBNEW_SELECTION & selection() const
virtual VECTOR2I GetPosition() const
Function GetPosition()
Definition: edit_points.h:68
const wxPoint & GetEnd()
Function GetEnd.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:269
ITERATOR IterateWithHoles(int aOutline)
Function IterateWithHoles.
Class SHAPE_POLY_SET.
SEG_POINTS
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
static TOOL_ACTION pointEditorAddCorner
Break outline (insert additional points to an edge)
Definition: pcb_actions.h:203
static TOOL_ACTION pointEditorRemoveCorner
Removes a corner.
Definition: pcb_actions.h:206
void SetEnd(const wxPoint &aEnd)
Function SetEnd Sets a new end of the crossbar line.
Arcs (with rounded ends)
Class TOOL_EVENT.
Definition: tool_event.h:168
std::shared_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_altConstraint
Definition: point_editor.h:84
COMMIT & StageItems(const Range &aRange, CHANGE_TYPE aChangeType)
Definition: commit.h:116
KIGFX::PCB_VIEW * view() const
DIMENSION_POINTS
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:374
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
const VECTOR2D DragOrigin() const
Returns the point where dragging has started.
Definition: tool_event.h:277
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
static LSET AllLayersMask()
Definition: lset.cpp:713
const wxPoint & GetArcStart() const
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
SHAPE_POLY_SET & GetPolyShape()
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: point_editor.h:72
Bezier Curve.
const wxPoint & GetOrigin() const
Function GetOrigin.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:306
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:1540
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:98
#define _(s)
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
int GetWidth() const
void SetStart(const wxPoint &aStart)
void SetSnap(bool aSnap)
Definition: grid_helper.h:66
Definition: seg.h:36
EDIT_POINT get45DegConstrainer() const
Returns a point that should be used as a constrainer for 45 degrees mode.
double GetAngle() const
bool validatePolygon(SHAPE_POLY_SET &aModified) const
Validates a polygon and displays a popup warning if invalid.
KIGFX::VIEW_CONTROLS * controls() const
Common, abstract interface for edit frames.
void SetHeight(int aHeight)
Function SetHeight Sets the length of feature lines.
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
Class ITERATOR_TEMPLATE.
size_t i
Definition: json11.cpp:597
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
static bool canAddCorner(const EDA_ITEM &aItem)
Determine if the tool can currently add a corner to the given item
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
void Hatch()
Function Hatch computes the hatch lines depending on the hatch parameters and stores it in the zone's...
Definition: class_zone.cpp:973
const wxPoint & GetBezControl2() const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
void updatePoints()
Updates edit points with item's points.
void SetEnd(const wxPoint &aEnd)
static std::pair< bool, SHAPE_POLY_SET::VERTEX_INDEX > findVertex(SHAPE_POLY_SET &aPolySet, const EDIT_POINT &aPoint)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
EDIT_POINT m_original
Original position for the current drag point.
Definition: point_editor.h:78
void Activate()
Function Activate() Runs the tool.
void InsertVertex(int aGlobalIndex, VECTOR2I aNewVertex)
Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex.
wxPoint m_crossBarO
BEZIER_CURVE_POINTS
const wxPoint & GetBezControl1() const
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void SetUseGrid(bool aGrid=true)
Definition: grid_helper.h:71
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Class EDIT_POINT.
Definition: edit_points.h:46
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
Class VIEW.
Definition: view.h:61
EDIT_POINT m_altConstrainer
Definition: point_editor.h:87
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
EDIT_POINT * m_editedPoint
Currently edited point, NULL if there is none.
Definition: point_editor.h:75
BOARD_ITEM_CONTAINER * GetParent() const
wxPoint m_featureLineDO
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
const VECTOR2I GetArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc/circle, given three points on its circumference.
Definition: trigo.cpp:362
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Class EC_SNAPLINE.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void setEditedPoint(EDIT_POINT *aPoint)
Sets the current point being edited. NULL means none.
static void buildForPolyOutline(std::shared_ptr< EDIT_POINTS > points, const SHAPE_POLY_SET *aOutline, KIGFX::GAL *aGal)
Class DIMENSION.
const VECTOR2D Position() const
Returns mouse cursor position in world coordinates.
Definition: tool_event.h:271
virtual void ApplyConstraint()
Function ApplyConstraint()
Definition: edit_points.h:173
int addCorner(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
int modifiedSelection(const TOOL_EVENT &aEvent)
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
ARC_POINTS
EDA_ITEM * Front() const
Definition: selection.h:182
void ClearFilledPolysList()
Function ClearFilledPolysList clears the list of filled polygons.
Definition: class_zone.h:533
static bool addCornerCondition(const SELECTION &aSelection)
Condition to display "Create corner" context menu entry.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
Class GAL is the abstract interface for drawing on a 2D-surface.
virtual void UpdateMsgPanel()
Redraw the message panel.
bool IsSelfIntersecting() const
Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting.
void SetBezControl1(const wxPoint &aPoint)
static std::shared_ptr< EDIT_POINTS > Make(EDA_ITEM *aItem, KIGFX::GAL *aGal)
void RemoveContour(int aContourIdx, int aPolygonIdx=-1)
Function RemoveContour deletes the aContourIdx-th contour of the aPolygonIdx-th polygon in the set.
virtual void SetPosition(const VECTOR2I &aPosition)
Function SetPosition()
Definition: edit_points.h:105
void SetNeedRefill(bool aNeedRefill)
Definition: class_zone.h:168