KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_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-2021 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <functional>
23#include <memory>
24#include <algorithm>
25#include <limits>
26
27using namespace std::placeholders;
28#include <advanced_config.h>
29#include <kiplatform/ui.h>
30#include <view/view_controls.h>
34#include <geometry/seg.h>
36#include <math/util.h>
37#include <confirm.h>
38#include <tool/tool_manager.h>
43#include <gal/painter.h>
44#include <tools/pcb_actions.h>
55#include <router/router_tool.h>
56#include <router/pns_router.h>
62#include <board_commit.h>
63#include <pcb_edit_frame.h>
64#include <pcb_reference_image.h>
65#include <pcb_generator.h>
66#include <pcb_group.h>
67#include <pcb_dimension.h>
68#include <pcb_barcode.h>
69#include <pcb_grid_item.h>
70#include <pcb_textbox.h>
71#include <pcb_tablecell.h>
72#include <pcb_table.h>
73#include <pad.h>
74#include <zone.h>
75#include <zone_filler.h>
76#include <footprint.h>
77#include <board.h>
83#include <progress_reporter.h>
84#include <layer_ids.h>
86
87const unsigned int PCB_POINT_EDITOR::COORDS_PADDING = pcbIUScale.mmToIU( 20 );
88
89static void appendDirection( std::vector<VECTOR2I>& aDirections, const VECTOR2I& aDirection )
90{
91 if( aDirection.x != 0 || aDirection.y != 0 )
92 aDirections.push_back( aDirection );
93}
94
95static std::vector<VECTOR2I> getConstraintDirections( EDIT_RELATION* aRelation )
96{
97 std::vector<VECTOR2I> directions;
98
99 if( !aRelation )
100 return directions;
101
102 switch( aRelation->Kind() )
103 {
105 appendDirection( directions, VECTOR2I( 1, 0 ) );
106 appendDirection( directions, VECTOR2I( 0, 1 ) );
107 break;
108
110 appendDirection( directions, VECTOR2I( 1, 0 ) );
111 appendDirection( directions, VECTOR2I( 0, 1 ) );
112 appendDirection( directions, VECTOR2I( 1, 1 ) );
113 appendDirection( directions, VECTOR2I( 1, -1 ) );
114 break;
115
117 appendDirection( directions, VECTOR2I( 0, 1 ) );
118 break;
119
121 appendDirection( directions, VECTOR2I( 1, 0 ) );
122 break;
123
125 appendDirection( directions, aRelation->Direction() );
126 break;
127
128 default:
129 break;
130 }
131
132 return directions;
133}
134
135// Few constants to avoid using bare numbers for point indices
147
148
153
154
155static std::optional<CONSTRAINT_MEMBER> constraintMemberForEditPoint(
156 PCB_SHAPE* aShape, EDIT_POINTS* aPoints, EDIT_POINT* aEditedPoint )
157{
158 if( !aShape || !aPoints || !aEditedPoint )
159 return std::nullopt;
160
161 SHAPE_T type = aShape->GetShape();
162 VECTOR2I position = aEditedPoint->GetPosition();
163
164 if( type == SHAPE_T::SEGMENT || type == SHAPE_T::ARC || type == SHAPE_T::BEZIER )
165 {
166 if( position == aShape->GetStart() )
168
169 if( position == aShape->GetEnd() )
171
172 if( type == SHAPE_T::ARC && position == aShape->GetCenter() )
174 }
175 else if( type == SHAPE_T::CIRCLE && position == aShape->GetCenter() )
176 {
178 }
179 else if( type == SHAPE_T::RECTANGLE && aPoints->PointsSize() >= RECT_MAX_POINTS )
180 {
181 for( unsigned i = RECT_TOP_LEFT; i <= RECT_BOT_LEFT; ++i )
182 {
183 if( aEditedPoint == &aPoints->Point( i ) )
185 }
186
187 for( unsigned i = 0; i < aPoints->LinesSize() && i < 4; ++i )
188 {
189 if( aEditedPoint == &aPoints->Line( i ) )
191 }
192 }
193 else if( type == SHAPE_T::POLY && ConstraintPolygonIsModelable( aShape ) )
194 {
195 for( unsigned i = 0; i < aPoints->PointsSize(); ++i )
196 {
197 if( aEditedPoint == &aPoints->Point( i ) )
199 }
200
201 for( unsigned i = 0; i < aPoints->LinesSize(); ++i )
202 {
203 if( aEditedPoint == &aPoints->Line( i ) )
205 }
206 }
207
208 return std::nullopt;
209}
210
211
226
227
234
235
237{
238public:
239 RECT_RADIUS_TEXT_ITEM( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
241 m_iuScale( aIuScale ),
242 m_units( aUnits ),
243 m_radius( 0 ),
244 m_corner(),
245 m_quadrant( -1, 1 ),
246 m_visible( false )
247 {
248 }
249
250 const BOX2I ViewBBox() const override
251 {
252 BOX2I tmp;
253 tmp.SetMaximum();
254 return tmp;
255 }
256
257 std::vector<int> ViewGetLayers() const override
258 {
260 }
261
262 void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override
263 {
264 if( !m_visible )
265 return;
266
267 wxArrayString strings;
268 strings.push_back( KIGFX::PREVIEW::DimensionLabel( "r", m_radius, m_iuScale, m_units ) );
270 aLayer == LAYER_SELECT_OVERLAY );
271 }
272
273 void Set( int aRadius, const VECTOR2I& aCorner, const VECTOR2I& aQuadrant, EDA_UNITS aUnits )
274 {
275 m_radius = aRadius;
276 m_corner = aCorner;
277 m_quadrant = aQuadrant;
278 m_units = aUnits;
279 m_visible = true;
280 }
281
282 void Hide()
283 {
284 m_visible = false;
285 }
286
287 wxString GetClass() const override
288 {
289 return wxT( "RECT_RADIUS_TEXT_ITEM" );
290 }
291
292private:
299};
300
301
303{
304public:
306 m_rectangle( aRectangle )
307 {
308 wxASSERT( m_rectangle.GetShape() == SHAPE_T::RECTANGLE );
309 }
310
315 static void MakePoints( const PCB_SHAPE& aRectangle, EDIT_POINTS& aPoints )
316 {
317 wxCHECK( aRectangle.GetShape() == SHAPE_T::RECTANGLE, /* void */ );
318
319 VECTOR2I topLeft = aRectangle.GetTopLeft();
320 VECTOR2I botRight = aRectangle.GetBotRight();
321
322 aPoints.SetSwapX( topLeft.x > botRight.x );
323 aPoints.SetSwapY( topLeft.y > botRight.y );
324
325 if( aPoints.SwapX() )
326 std::swap( topLeft.x, botRight.x );
327
328 if( aPoints.SwapY() )
329 std::swap( topLeft.y, botRight.y );
330
331 aPoints.AddPoint( topLeft );
332 aPoints.AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
333 aPoints.AddPoint( botRight );
334 aPoints.AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
335 aPoints.AddPoint( aRectangle.GetCenter() );
336 aPoints.AddPoint( VECTOR2I( botRight.x - aRectangle.GetCornerRadius(), topLeft.y ) );
337 aPoints.Point( RECT_RADIUS ).SetDrawCircle();
338
339 // Neither is a corner the caller can place. The centre moves the whole rectangle and
340 // the radius rounds it, both read from the shape as it stands
343
344 aPoints.AddLine( aPoints.Point( RECT_TOP_LEFT ), aPoints.Point( RECT_TOP_RIGHT ) );
345 aPoints.Line( RECT_TOP ).SetRelation(
347 aPoints.AddLine( aPoints.Point( RECT_TOP_RIGHT ), aPoints.Point( RECT_BOT_RIGHT ) );
348 aPoints.Line( RECT_RIGHT ).SetRelation(
350 aPoints.AddLine( aPoints.Point( RECT_BOT_RIGHT ), aPoints.Point( RECT_BOT_LEFT ) );
351 aPoints.Line( RECT_BOT ).SetRelation(
353 aPoints.AddLine( aPoints.Point( RECT_BOT_LEFT ), aPoints.Point( RECT_TOP_LEFT ) );
354 aPoints.Line( RECT_LEFT ).SetRelation(
356 }
357
358 static void UpdateItem( PCB_SHAPE& aRectangle, const EDIT_POINT& aEditedPoint,
359 EDIT_POINTS& aPoints, const VECTOR2I& aMinSize = { 0, 0 } )
360 {
361 // You can have more points if your item wants to have more points
362 // (this class assumes the rect points come first, but that can be changed)
364
365 auto setLeft =
366 [&]( int left )
367 {
368 aPoints.SwapX() ? aRectangle.SetRight( left ) : aRectangle.SetLeft( left );
369 };
370 auto setRight =
371 [&]( int right )
372 {
373 aPoints.SwapX() ? aRectangle.SetLeft( right ) : aRectangle.SetRight( right );
374 };
375 auto setTop =
376 [&]( int top )
377 {
378 aPoints.SwapY() ? aRectangle.SetBottom( top ) : aRectangle.SetTop( top );
379 };
380 auto setBottom =
381 [&]( int bottom )
382 {
383 aPoints.SwapY() ? aRectangle.SetTop( bottom ) : aRectangle.SetBottom( bottom );
384 };
385
386 VECTOR2I topLeft = aPoints.Point( RECT_TOP_LEFT ).GetPosition();
387 VECTOR2I topRight = aPoints.Point( RECT_TOP_RIGHT ).GetPosition();
388 VECTOR2I botLeft = aPoints.Point( RECT_BOT_LEFT ).GetPosition();
389 VECTOR2I botRight = aPoints.Point( RECT_BOT_RIGHT ).GetPosition();
390
391 PinEditedCorner( aEditedPoint, aPoints, topLeft, topRight, botLeft, botRight,
392 { 0, 0 }, { 0, 0 }, aMinSize );
393
394 if( isModified( aEditedPoint, aPoints.Point( RECT_TOP_LEFT ) )
395 || isModified( aEditedPoint, aPoints.Point( RECT_TOP_RIGHT ) )
396 || isModified( aEditedPoint, aPoints.Point( RECT_BOT_RIGHT ) )
397 || isModified( aEditedPoint, aPoints.Point( RECT_BOT_LEFT ) ) )
398 {
399 setTop( topLeft.y );
400 setLeft( topLeft.x );
401 setRight( botRight.x );
402 setBottom( botRight.y );
403 }
404 else if( isModified( aEditedPoint, aPoints.Point( RECT_CENTER ) ) )
405 {
406 const VECTOR2I moveVector = aPoints.Point( RECT_CENTER ).GetPosition() - aRectangle.GetCenter();
407 aRectangle.Move( moveVector );
408 }
409 else if( isModified( aEditedPoint, aPoints.Point( RECT_RADIUS ) ) )
410 {
411 int width = std::abs( botRight.x - topLeft.x );
412 int height = std::abs( botRight.y - topLeft.y );
413 int maxRadius = std::min( width, height ) / 2;
414 int x = aPoints.Point( RECT_RADIUS ).GetX();
415 x = std::clamp( x, botRight.x - maxRadius, botRight.x );
416 aPoints.Point( RECT_RADIUS ).SetPosition( x, topLeft.y );
417 aRectangle.SetCornerRadius( botRight.x - x );
418 }
419 else if( isModified( aEditedPoint, aPoints.Line( RECT_TOP ) ) )
420 {
421 // Only top changes; keep others from previous full-local bbox
422 setTop( topLeft.y );
423 }
424 else if( isModified( aEditedPoint, aPoints.Line( RECT_LEFT ) ) )
425 {
426 // Only left changes; keep others from previous full-local bbox
427 setLeft( topLeft.x );
428 }
429 else if( isModified( aEditedPoint, aPoints.Line( RECT_BOT ) ) )
430 {
431 // Only bottom changes; keep others from previous full-local bbox
432 setBottom( botRight.y );
433 }
434 else if( isModified( aEditedPoint, aPoints.Line( RECT_RIGHT ) ) )
435 {
436 // Only right changes; keep others from previous full-local bbox
437 setRight( botRight.x );
438 }
439
440 for( unsigned i = 0; i < aPoints.LinesSize(); ++i )
441 {
442 if( !isModified( aEditedPoint, aPoints.Line( i ) ) )
443 aPoints.Line( i ).SetRelation(
445 }
446 }
447
448 static void UpdatePoints( const PCB_SHAPE& aRectangle, EDIT_POINTS& aPoints )
449 {
450 wxCHECK( aPoints.PointsSize() >= RECT_MAX_POINTS, /* void */ );
451
452 VECTOR2I topLeft = aRectangle.GetTopLeft();
453 VECTOR2I botRight = aRectangle.GetBotRight();
454
455 aPoints.SetSwapX( topLeft.x > botRight.x );
456 aPoints.SetSwapY( topLeft.y > botRight.y );
457
458 if( aPoints.SwapX() )
459 std::swap( topLeft.x, botRight.x );
460
461 if( aPoints.SwapY() )
462 std::swap( topLeft.y, botRight.y );
463
464 aPoints.Point( RECT_TOP_LEFT ).SetPosition( topLeft );
465 aPoints.Point( RECT_RADIUS ).SetPosition( botRight.x - aRectangle.GetCornerRadius(), topLeft.y );
466 aPoints.Point( RECT_TOP_RIGHT ).SetPosition( botRight.x, topLeft.y );
467 aPoints.Point( RECT_BOT_RIGHT ).SetPosition( botRight );
468 aPoints.Point( RECT_BOT_LEFT ).SetPosition( topLeft.x, botRight.y );
469 aPoints.Point( RECT_CENTER ).SetPosition( aRectangle.GetCenter() );
470 }
471
472 void MakePoints( EDIT_POINTS& aPoints ) override
473 {
474 // Just call the static helper
475 MakePoints( m_rectangle, aPoints );
476 }
477
478 bool UpdatePoints( EDIT_POINTS& aPoints ) override
479 {
480 // Careful; rectangle shape is mutable between cardinal and non-cardinal rotations...
481 if( m_rectangle.GetShape() != SHAPE_T::RECTANGLE || aPoints.PointsSize() == 0 )
482 return false;
483
484 UpdatePoints( m_rectangle, aPoints );
485 return true;
486 }
487
488 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
489 std::vector<EDA_ITEM*>& aUpdatedItems ) override
490 {
491 UpdateItem( m_rectangle, aEditedPoint, aPoints );
492 }
493
508 static void PinEditedCorner( const EDIT_POINT& aEditedPoint, const EDIT_POINTS& aEditPoints,
509 VECTOR2I& aTopLeft, VECTOR2I& aTopRight, VECTOR2I& aBotLeft, VECTOR2I& aBotRight,
510 const VECTOR2I& aHole = { 0, 0 }, const VECTOR2I& aHoleSize = { 0, 0 },
511 const VECTOR2I& aMinSize = { 0, 0 } )
512 {
513 int minWidth = std::max( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 ), aMinSize.x );
514 int minHeight = std::max( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 ), aMinSize.y );
515
516 if( isModified( aEditedPoint, aEditPoints.Point( RECT_TOP_LEFT ) ) )
517 {
518 if( aHoleSize.x )
519 {
520 // pin edited point to the top/left of the hole
521 aTopLeft.x = std::min( aTopLeft.x, aHole.x - aHoleSize.x / 2 - minWidth );
522 aTopLeft.y = std::min( aTopLeft.y, aHole.y - aHoleSize.y / 2 - minHeight );
523 }
524 else
525 {
526 // pin edited point within opposite corner
527 aTopLeft.x = std::min( aTopLeft.x, aBotRight.x - minWidth );
528 aTopLeft.y = std::min( aTopLeft.y, aBotRight.y - minHeight );
529 }
530
531 // push edited point edges to adjacent corners
532 aTopRight.y = aTopLeft.y;
533 aBotLeft.x = aTopLeft.x;
534 }
535 else if( isModified( aEditedPoint, aEditPoints.Point( RECT_TOP_RIGHT ) ) )
536 {
537 if( aHoleSize.x )
538 {
539 // pin edited point to the top/right of the hole
540 aTopRight.x = std::max( aTopRight.x, aHole.x + aHoleSize.x / 2 + minWidth );
541 aTopRight.y = std::min( aTopRight.y, aHole.y - aHoleSize.y / 2 - minHeight );
542 }
543 else
544 {
545 // pin edited point within opposite corner
546 aTopRight.x = std::max( aTopRight.x, aBotLeft.x + minWidth );
547 aTopRight.y = std::min( aTopRight.y, aBotLeft.y - minHeight );
548 }
549
550 // push edited point edges to adjacent corners
551 aTopLeft.y = aTopRight.y;
552 aBotRight.x = aTopRight.x;
553 }
554 else if( isModified( aEditedPoint, aEditPoints.Point( RECT_BOT_LEFT ) ) )
555 {
556 if( aHoleSize.x )
557 {
558 // pin edited point to the bottom/left of the hole
559 aBotLeft.x = std::min( aBotLeft.x, aHole.x - aHoleSize.x / 2 - minWidth );
560 aBotLeft.y = std::max( aBotLeft.y, aHole.y + aHoleSize.y / 2 + minHeight );
561 }
562 else
563 {
564 // pin edited point within opposite corner
565 aBotLeft.x = std::min( aBotLeft.x, aTopRight.x - minWidth );
566 aBotLeft.y = std::max( aBotLeft.y, aTopRight.y + minHeight );
567 }
568
569 // push edited point edges to adjacent corners
570 aBotRight.y = aBotLeft.y;
571 aTopLeft.x = aBotLeft.x;
572 }
573 else if( isModified( aEditedPoint, aEditPoints.Point( RECT_BOT_RIGHT ) ) )
574 {
575 if( aHoleSize.x )
576 {
577 // pin edited point to the bottom/right of the hole
578 aBotRight.x = std::max( aBotRight.x, aHole.x + aHoleSize.x / 2 + minWidth );
579 aBotRight.y = std::max( aBotRight.y, aHole.y + aHoleSize.y / 2 + minHeight );
580 }
581 else
582 {
583 // pin edited point within opposite corner
584 aBotRight.x = std::max( aBotRight.x, aTopLeft.x + minWidth );
585 aBotRight.y = std::max( aBotRight.y, aTopLeft.y + minHeight );
586 }
587
588 // push edited point edges to adjacent corners
589 aBotLeft.y = aBotRight.y;
590 aTopRight.x = aBotRight.x;
591 }
592 else if( isModified( aEditedPoint, aEditPoints.Line( RECT_TOP ) ) )
593 {
594 aTopLeft.y = std::min( aTopLeft.y, aBotRight.y - minHeight );
595 }
596 else if( isModified( aEditedPoint, aEditPoints.Line( RECT_LEFT ) ) )
597 {
598 aTopLeft.x = std::min( aTopLeft.x, aBotRight.x - minWidth );
599 }
600 else if( isModified( aEditedPoint, aEditPoints.Line( RECT_BOT ) ) )
601 {
602 aBotRight.y = std::max( aBotRight.y, aTopLeft.y + minHeight );
603 }
604 else if( isModified( aEditedPoint, aEditPoints.Line( RECT_RIGHT ) ) )
605 {
606 aBotRight.x = std::max( aBotRight.x, aTopLeft.x + minWidth );
607 }
608 }
609
610private:
612};
613
614
620{
621public:
623 m_zone( aZone )
624 {}
625
626 void MakePoints( EDIT_POINTS& aPoints ) override
627 {
629 }
630
631 bool UpdatePoints( EDIT_POINTS& aPoints ) override
632 {
634 return true;
635 }
636
637 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
638 std::vector<EDA_ITEM*>& aUpdatedItems ) override
639 {
640 m_zone.UnFill();
641 POLYGON_POINT_EDIT_BEHAVIOR::UpdateOutlineFromPoints( *m_zone.Outline(), aEditedPoint, aPoints );
642 m_zone.HatchBorder();
643 }
644
645 bool UpdateItemAppliesAllPoints() const override { return true; }
646
647 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override
648 {
650 }
651
652private:
654};
655
656
658{
659public:
661 POLYGON_POINT_EDIT_BEHAVIOR( aGen.Outline() ),
662 m_gen( aGen )
663 {
664 }
665
666 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
667 std::vector<EDA_ITEM*>& aUpdatedItems ) override
668 {
669 // Defer to the base class to update the polygon
670 POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
671
672 // Flag the generator has to be updated based on potential outline change
673 m_gen.MarkDirty();
674 }
675
676private:
678};
679
680
682{
683public:
685 m_barcode( aBarcode )
686 {}
687
689 {
691 dummy.SetStart( m_barcode.GetCenter() - VECTOR2I( m_barcode.GetWidth() / 2, m_barcode.GetHeight() / 2 ) );
692 dummy.SetEnd( dummy.GetStart() + VECTOR2I( m_barcode.GetWidth(), m_barcode.GetHeight() ) );
693 dummy.Rotate( m_barcode.GetPosition(), m_barcode.GetAngle() );
694 return dummy;
695 }
696
697 void MakePoints( EDIT_POINTS& aPoints ) override
698 {
699 if( !m_barcode.GetAngle().IsCardinal() )
700 {
701 // Non-cardinal barcode point-editing isn't useful enough to support.
702 return;
703 }
704
705 auto set45Constraint =
706 [&]( int a, int b )
707 {
708 aPoints.Point( a ).SetRelation( EDIT_RELATION::Angle45( aPoints.Point( b ) ) );
709 };
710
712
713 if( m_barcode.KeepSquare() )
714 {
715 set45Constraint( RECT_TOP_LEFT, RECT_BOT_RIGHT );
716 set45Constraint( RECT_TOP_RIGHT, RECT_BOT_LEFT );
717 set45Constraint( RECT_BOT_RIGHT, RECT_TOP_LEFT );
718 set45Constraint( RECT_BOT_LEFT, RECT_TOP_RIGHT );
719 }
720 }
721
722 bool UpdatePoints( EDIT_POINTS& aPoints ) override
723 {
724 const unsigned target = m_barcode.GetAngle().IsCardinal() ? RECT_MAX_POINTS : 0;
725
726 if( aPoints.PointsSize() != target )
727 return false;
728
730 return true;
731 }
732
733 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
734 std::vector<EDA_ITEM*>& aUpdatedItems ) override
735 {
736 if( m_barcode.GetAngle().IsCardinal() )
737 {
739 RECTANGLE_POINT_EDIT_BEHAVIOR::UpdateItem( dummy, aEditedPoint, aPoints );
740 dummy.Rotate( dummy.GetCenter(), -m_barcode.GetAngle() );
741
742 m_barcode.SetPosition( dummy.GetCenter() );
743 m_barcode.SetWidth( dummy.GetRectangleWidth() );
744 m_barcode.SetHeight( dummy.GetRectangleHeight() );
745 m_barcode.AssembleBarcode();
746 }
747 }
748
749private:
751};
752
753
755{
756public:
758 m_gridItem( aGridItem )
759 {
760 }
761
762 void MakePoints( EDIT_POINTS& aPoints ) override
763 {
764 // Index 0: centre (drag = translate).
765 aPoints.AddPoint( m_gridItem.GetPosition() );
766
767 switch( m_gridItem.GetGridItemType() )
768 {
770 aPoints.AddPoint( toWorld( radiusEndLocal() ) );
771 aPoints.AddPoint( toWorld( arcEndLocal() ) );
772 aPoints.AddPoint( toWorld( arcMidLocal() ) );
773 break;
774
776 aPoints.AddPoint( toWorld( cornerLocal( 0, 0 ) ) );
777 aPoints.AddPoint( toWorld( cornerLocal( 1, 0 ) ) );
778 aPoints.AddPoint( toWorld( cornerLocal( 1, 1 ) ) );
779 aPoints.AddPoint( toWorld( cornerLocal( 0, 1 ) ) );
780 break;
781
782 default:
783 wxFAIL_MSG( wxT( "MakePoints: unhandled PCB_GRID_TYPE" ) );
784 break;
785 }
786 }
787
788 bool UpdatePoints( EDIT_POINTS& aPoints ) override
789 {
790 switch( m_gridItem.GetGridItemType() )
791 {
793 if( aPoints.PointsSize() != 4 )
794 return false;
795
796 aPoints.Point( 0 ).SetPosition( m_gridItem.GetPosition() );
797 aPoints.Point( 1 ).SetPosition( toWorld( radiusEndLocal() ) );
798 aPoints.Point( 2 ).SetPosition( toWorld( arcEndLocal() ) );
799 aPoints.Point( 3 ).SetPosition( toWorld( arcMidLocal() ) );
800 return true;
801
803 if( aPoints.PointsSize() != 5 )
804 return false;
805
806 aPoints.Point( 0 ).SetPosition( m_gridItem.GetPosition() );
807 aPoints.Point( 1 ).SetPosition( toWorld( cornerLocal( 0, 0 ) ) );
808 aPoints.Point( 2 ).SetPosition( toWorld( cornerLocal( 1, 0 ) ) );
809 aPoints.Point( 3 ).SetPosition( toWorld( cornerLocal( 1, 1 ) ) );
810 aPoints.Point( 4 ).SetPosition( toWorld( cornerLocal( 0, 1 ) ) );
811 return true;
812
813 default:
814 wxFAIL_MSG( wxT( "UpdatePoints: unhandled PCB_GRID_TYPE" ) );
815 return false;
816 }
817 }
818
819 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
820 std::vector<EDA_ITEM*>& aUpdatedItems ) override
821 {
822 // Centre handle: translate the whole grid.
823 if( isModified( aEditedPoint, aPoints.Point( 0 ) ) )
824 {
825 m_gridItem.SetPosition( aEditedPoint.GetPosition() );
826 return;
827 }
828
829 const VECTOR2I local = toLocal( aEditedPoint.GetPosition() );
830
831 switch( m_gridItem.GetGridItemType() )
832 {
834 {
835 // World offset from grid centre.
836 const VECTOR2I worldOff = aEditedPoint.GetPosition() - m_gridItem.GetPosition();
837 const double dragAngle = std::atan2( worldOff.y, worldOff.x );
838 const int newRadius = std::max( 1, KiROUND( std::hypot( worldOff.x, worldOff.y ) ) );
839 const double orientOld = m_gridItem.GetOrientation().AsRadians();
840 const double phiMaxOld = m_gridItem.GetPhiExtent().AsRadians();
841
842 // KiCad screen rotation: a local point at phi lands at world math-angle
843 // (phi - orient). Each handle drag pins exactly one endpoint and follows
844 // the (already-snapped) cursor; the unmoved endpoint stays put.
845 const auto wrap2pi = []( double a )
846 {
847 while( a < 0 )
848 a += 2 * M_PI;
849 while( a >= 2 * M_PI )
850 a -= 2 * M_PI;
851 return a;
852 };
853
854 if( isModified( aEditedPoint, aPoints.Point( 1 ) ) ) // radius end (phi=0)
855 {
856 // phi=0 follows the cursor; the phi=phiMax end stays at world angle
857 // (phiMaxOld - orientOld).
858 const double newOrient = -dragAngle;
859 const double newPhiMax = wrap2pi( phiMaxOld - orientOld - dragAngle );
860
861 m_gridItem.SetOrientation( EDA_ANGLE( newOrient, RADIANS_T ) );
862 m_gridItem.SetPhiExtentDegrees( newPhiMax * 180.0 / M_PI );
863 }
864 else if( isModified( aEditedPoint, aPoints.Point( 2 ) ) ) // arc end (phi=phiMax)
865 {
866 // phi=phiMax follows the cursor; the phi=0 end (orient direction) stays.
867 const double newPhiMax = wrap2pi( dragAngle + orientOld );
868
869 m_gridItem.SetPhiExtentDegrees( newPhiMax * 180.0 / M_PI );
870 }
871 else if( isModified( aEditedPoint, aPoints.Point( 3 ) ) ) // arc mid (bisector)
872 {
873 // Bisector follows the cursor; phiMax unchanged (whole wedge rotates).
874 const double newOrient = phiMaxOld / 2.0 - dragAngle;
875
876 m_gridItem.SetOrientation( EDA_ANGLE( newOrient, RADIANS_T ) );
877 }
878
879 m_gridItem.SetRadiusExtent( newRadius );
880 break;
881 }
882
884 {
885 // Dragging a corner resizes symmetrically about the centre.
886 const int newHalfX = std::max( 1, std::abs( local.x ) );
887 const int newHalfY = std::max( 1, std::abs( local.y ) );
888
889 // SetExtent takes size/2 directly, bypassing the property panel's
890 // total-width 2x / /2 accessor dance.
891 m_gridItem.SetExtent( VECTOR2I( newHalfX, newHalfY ) );
892 break;
893 }
894
895 default:
896 wxFAIL_MSG( wxT( "UpdateItem: unhandled PCB_GRID_TYPE" ) );
897 break;
898 }
899 }
900
901private:
902 VECTOR2I toLocal( const VECTOR2I& aWorld ) const
903 {
904 VECTOR2I local = aWorld - m_gridItem.GetPosition();
905 RotatePoint( local, -m_gridItem.GetOrientation() );
906 return local;
907 }
908
909 VECTOR2I toWorld( const VECTOR2I& aLocal ) const
910 {
911 VECTOR2I world = aLocal;
912 RotatePoint( world, m_gridItem.GetOrientation() );
913 return m_gridItem.GetPosition() + world;
914 }
915
916 // aX / aY in {0, 1}: 0 = negative half, 1 = positive half.
917 VECTOR2I cornerLocal( int aX, int aY ) const
918 {
919 const int sx = ( aX == 0 ) ? -1 : +1;
920 const int sy = ( aY == 0 ) ? -1 : +1;
921 return VECTOR2I( sx * m_gridItem.GetExtent().x, sy * m_gridItem.GetExtent().y );
922 }
923
924 VECTOR2I radiusEndLocal() const { return VECTOR2I( m_gridItem.GetRadiusExtent(), 0 ); }
925
927 {
928 const double phi = m_gridItem.GetPhiExtent().AsRadians();
929 const int r = m_gridItem.GetRadiusExtent();
930 return VECTOR2I( KiROUND( r * std::cos( phi ) ), KiROUND( r * std::sin( phi ) ) );
931 }
932
934 {
935 const double phi = m_gridItem.GetPhiExtent().AsRadians() / 2.0;
936 const int r = m_gridItem.GetRadiusExtent();
937 return VECTOR2I( KiROUND( r * std::cos( phi ) ), KiROUND( r * std::sin( phi ) ) );
938 }
939
941};
942
943
945{
946public:
951
952 void MakePoints( EDIT_POINTS& aPoints ) override
953 {
954 aPoints.AddPoint( edgeMidpoint( COL_WIDTH ) );
955 aPoints.AddPoint( edgeMidpoint( ROW_HEIGHT ) );
956 }
957
958 bool UpdatePoints( EDIT_POINTS& aPoints ) override
959 {
960 wxCHECK( aPoints.PointsSize() == TABLECELL_MAX_POINTS, false );
961
964
965 return true;
966 }
967
968 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
969 std::vector<EDA_ITEM*>& aUpdatedItems ) override
970 {
972
973 PCB_TABLE& table = static_cast<PCB_TABLE&>( *m_cell.GetParent() );
974 aCommit.Modify( &table );
975 aUpdatedItems.push_back( &table );
976
977 if( isModified( aEditedPoint, aPoints.Point( COL_WIDTH ) ) )
978 {
979 m_cell.SetEnd( VECTOR2I( unturned( aPoints.Point( COL_WIDTH ).GetPosition() ).x, m_cell.GetEndY() ) );
980
981 int colWidth = m_cell.GetRectangleWidth();
982
983 for( int ii = 0; ii < m_cell.GetColSpan() - 1; ++ii )
984 colWidth -= table.GetColWidth( m_cell.GetColumn() + ii );
985
986 table.SetColWidth( m_cell.GetColumn() + m_cell.GetColSpan() - 1, colWidth );
987 }
988 else if( isModified( aEditedPoint, aPoints.Point( ROW_HEIGHT ) ) )
989 {
990 m_cell.SetEnd( VECTOR2I( m_cell.GetEndX(), unturned( aPoints.Point( ROW_HEIGHT ).GetPosition() ).y ) );
991
992 int rowHeight = m_cell.GetRectangleHeight();
993
994 for( int ii = 0; ii < m_cell.GetRowSpan() - 1; ++ii )
995 rowHeight -= table.GetRowHeight( m_cell.GetRow() + ii );
996
997 table.SetRowHeight( m_cell.GetRow() + m_cell.GetRowSpan() - 1, rowHeight );
998 }
999
1000 table.Normalize();
1001 }
1002
1003private:
1004 // A cell keeps its rectangle square to the board and carries the turn in its text angle, so
1005 // the handles belong on the edges it is drawn with, not on the stored rectangle.
1007 {
1008 std::vector<VECTOR2I> corners = m_cell.GetCorners();
1009
1010 return aPoint == COL_WIDTH ? ( corners[1] + corners[2] ) / 2 : ( corners[2] + corners[3] ) / 2;
1011 }
1012
1013 // Bring a dragged handle back into the frame the rectangle is stored in.
1014 VECTOR2I unturned( const VECTOR2I& aPoint ) const
1015 {
1016 BOX2I box;
1017 box.Merge( m_cell.GetStart() );
1018 box.Merge( m_cell.GetEnd() );
1019
1020 VECTOR2I pt = aPoint;
1021 RotatePoint( pt, box.GetCenter(), -m_cell.GetDrawRotation() );
1022
1023 return pt;
1024 }
1025
1027};
1028
1029
1031{
1032public:
1034 m_pad( aPad ),
1035 m_layer( aLayer )
1036 {}
1037
1038 void MakePoints( EDIT_POINTS& aPoints ) override
1039 {
1040 VECTOR2I shapePos = m_pad.ShapePos( m_layer );
1041 VECTOR2I halfSize( m_pad.GetSize( m_layer ).x / 2, m_pad.GetSize( m_layer ).y / 2 );
1042
1043 if( m_pad.IsLocked() )
1044 return;
1045
1046 switch( m_pad.GetShape( m_layer ) )
1047 {
1048 case PAD_SHAPE::CIRCLE:
1049 aPoints.AddPoint( VECTOR2I( shapePos.x + halfSize.x, shapePos.y ) );
1050 break;
1051
1052 case PAD_SHAPE::OVAL:
1057 {
1058 if( !m_pad.GetOrientation().IsCardinal() )
1059 break;
1060
1061 if( m_pad.GetOrientation().IsVertical() )
1062 std::swap( halfSize.x, halfSize.y );
1063
1064 // It's important to fill these according to the RECT indices
1065 aPoints.AddPoint( shapePos - halfSize );
1066 aPoints.AddPoint( VECTOR2I( shapePos.x + halfSize.x, shapePos.y - halfSize.y ) );
1067 aPoints.AddPoint( shapePos + halfSize );
1068 aPoints.AddPoint( VECTOR2I( shapePos.x - halfSize.x, shapePos.y + halfSize.y ) );
1069 }
1070 break;
1071
1072 default: // suppress warnings
1073 break;
1074 }
1075 }
1076
1077 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1078 {
1079 bool locked = m_pad.GetParent() && m_pad.IsLocked();
1080 VECTOR2I shapePos = m_pad.ShapePos( m_layer );
1081 VECTOR2I halfSize( m_pad.GetSize( m_layer ).x / 2, m_pad.GetSize( m_layer ).y / 2 );
1082
1083 switch( m_pad.GetShape( m_layer ) )
1084 {
1085 case PAD_SHAPE::CIRCLE:
1086 {
1087 int target = locked ? 0 : 1;
1088
1089 // Careful; pad shape is mutable...
1090 if( int( aPoints.PointsSize() ) != target )
1091 {
1092 aPoints.Clear();
1093 MakePoints( aPoints );
1094 }
1095 else if( target == 1 )
1096 {
1097 shapePos.x += halfSize.x;
1098 aPoints.Point( 0 ).SetPosition( shapePos );
1099 }
1100 }
1101 break;
1102
1103 case PAD_SHAPE::OVAL:
1108 {
1109 // Careful; pad shape and orientation are mutable...
1110 int target = locked || !m_pad.GetOrientation().IsCardinal() ? 0 : 4;
1111
1112 if( int( aPoints.PointsSize() ) != target )
1113 {
1114 aPoints.Clear();
1115 MakePoints( aPoints );
1116 }
1117 else if( target == 4 )
1118 {
1119 if( m_pad.GetOrientation().IsVertical() )
1120 std::swap( halfSize.x, halfSize.y );
1121
1122 aPoints.Point( RECT_TOP_LEFT ).SetPosition( shapePos - halfSize );
1123 aPoints.Point( RECT_TOP_RIGHT ).SetPosition( VECTOR2I( shapePos.x + halfSize.x,
1124 shapePos.y - halfSize.y ) );
1125 aPoints.Point( RECT_BOT_RIGHT ).SetPosition( shapePos + halfSize );
1126 aPoints.Point( RECT_BOT_LEFT ).SetPosition( VECTOR2I( shapePos.x - halfSize.x,
1127 shapePos.y + halfSize.y ) );
1128 }
1129
1130 break;
1131 }
1132
1133 default: // suppress warnings
1134 break;
1135 }
1136
1137 return true;
1138 }
1139
1140 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1141 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1142 {
1143 switch( m_pad.GetShape( m_layer ) )
1144 {
1145 case PAD_SHAPE::CIRCLE:
1146 {
1147 VECTOR2I end = aPoints.Point( 0 ).GetPosition();
1148 int diameter = 2 * ( end - m_pad.GetPosition() ).EuclideanNorm();
1149
1150 m_pad.SetSize( m_layer, VECTOR2I( diameter, diameter ) );
1151 break;
1152 }
1153
1154 case PAD_SHAPE::OVAL:
1159 {
1160 VECTOR2I topLeft = aPoints.Point( RECT_TOP_LEFT ).GetPosition();
1161 VECTOR2I topRight = aPoints.Point( RECT_TOP_RIGHT ).GetPosition();
1162 VECTOR2I botLeft = aPoints.Point( RECT_BOT_LEFT ).GetPosition();
1163 VECTOR2I botRight = aPoints.Point( RECT_BOT_RIGHT ).GetPosition();
1164 VECTOR2I holeCenter = m_pad.GetPosition();
1165 VECTOR2I holeSize = m_pad.GetDrillSize();
1166
1167 RECTANGLE_POINT_EDIT_BEHAVIOR::PinEditedCorner( aEditedPoint, aPoints, topLeft, topRight,
1168 botLeft, botRight, holeCenter, holeSize );
1169
1170 if( ( m_pad.GetOffset( m_layer ).x || m_pad.GetOffset( m_layer ).y )
1171 || ( m_pad.GetDrillSize().x && m_pad.GetDrillSize().y ) )
1172 {
1173 // Keep hole pinned at the current location; adjust the pad around the hole
1174
1175 VECTOR2I center = m_pad.GetPosition();
1176 int dist[4];
1177
1178 if( isModified( aEditedPoint, aPoints.Point( RECT_TOP_LEFT ) )
1179 || isModified( aEditedPoint, aPoints.Point( RECT_BOT_RIGHT ) ) )
1180 {
1181 dist[0] = center.x - topLeft.x;
1182 dist[1] = center.y - topLeft.y;
1183 dist[2] = botRight.x - center.x;
1184 dist[3] = botRight.y - center.y;
1185 }
1186 else
1187 {
1188 dist[0] = center.x - botLeft.x;
1189 dist[1] = center.y - topRight.y;
1190 dist[2] = topRight.x - center.x;
1191 dist[3] = botLeft.y - center.y;
1192 }
1193
1194 VECTOR2I padSize( dist[0] + dist[2], dist[1] + dist[3] );
1195 VECTOR2I deltaOffset( padSize.x / 2 - dist[2], padSize.y / 2 - dist[3] );
1196
1197 if( m_pad.GetOrientation().IsVertical() )
1198 std::swap( padSize.x, padSize.y );
1199
1200 RotatePoint( deltaOffset, -m_pad.GetOrientation() );
1201
1202 m_pad.SetSize( m_layer, padSize );
1203 m_pad.SetOffset( m_layer, -deltaOffset );
1204 }
1205 else
1206 {
1207 // Keep pad position at the center of the pad shape
1208
1209 int left, top, right, bottom;
1210
1211 if( isModified( aEditedPoint, aPoints.Point( RECT_TOP_LEFT ) )
1212 || isModified( aEditedPoint, aPoints.Point( RECT_BOT_RIGHT ) ) )
1213 {
1214 left = topLeft.x;
1215 top = topLeft.y;
1216 right = botRight.x;
1217 bottom = botRight.y;
1218 }
1219 else
1220 {
1221 left = botLeft.x;
1222 top = topRight.y;
1223 right = topRight.x;
1224 bottom = botLeft.y;
1225 }
1226
1227 VECTOR2I padSize( abs( right - left ), abs( bottom - top ) );
1228
1229 if( m_pad.GetOrientation().IsVertical() )
1230 std::swap( padSize.x, padSize.y );
1231
1232 m_pad.SetSize( m_layer, padSize );
1233 m_pad.SetPosition( VECTOR2I( ( left + right ) / 2, ( top + bottom ) / 2 ) );
1234 }
1235 break;
1236 }
1237 default: // suppress warnings
1238 break;
1239 }
1240 }
1241
1242private:
1245};
1246
1247
1254{
1255public:
1257 m_generator( aGenerator )
1258 {}
1259
1260 void MakePoints( EDIT_POINTS& aPoints ) override
1261 {
1262 m_generator.MakeEditPoints( aPoints );
1263 }
1264
1265 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1266 {
1267 m_generator.UpdateEditPoints( aPoints );
1268 return true;
1269 }
1270
1271 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1272 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1273 {
1274 m_generator.UpdateFromEditPoints( aPoints );
1275 }
1276
1277private:
1279};
1280
1281
1291{
1292public:
1294 m_dimension( aDimension ),
1295 m_originalTextPos( aDimension.GetTextPos() ),
1296 m_oldCrossBar( SEG{ aDimension.GetCrossbarStart(), aDimension.GetCrossbarEnd() } )
1297 {}
1298
1300 {
1301 const SEG newCrossBar{ m_dimension.GetCrossbarStart(), m_dimension.GetCrossbarEnd() };
1302
1303 if( newCrossBar == m_oldCrossBar )
1304 {
1305 // Crossbar didn't change, text doesn't need to change
1306 return;
1307 }
1308
1309 const VECTOR2I newTextPos = getDimensionNewTextPosition();
1310 m_dimension.SetTextPos( newTextPos );
1311
1312 const GR_TEXT_H_ALIGN_T oldJustify = m_dimension.GetHorizJustify();
1313
1314 // We may need to update the justification if we go past vertical.
1317 {
1318 const VECTOR2I oldProject = m_oldCrossBar.LineProject( m_originalTextPos );
1319 const VECTOR2I newProject = newCrossBar.LineProject( newTextPos );
1320
1321 const VECTOR2I oldProjectedOffset =
1322 oldProject - m_oldCrossBar.NearestPoint( oldProject );
1323 const VECTOR2I newProjectedOffset = newProject - newCrossBar.NearestPoint( newProject );
1324
1325 const bool textWasLeftOf = oldProjectedOffset.x < 0
1326 || ( oldProjectedOffset.x == 0 && oldProjectedOffset.y > 0 );
1327 const bool textIsLeftOf = newProjectedOffset.x < 0
1328 || ( newProjectedOffset.x == 0 && newProjectedOffset.y > 0 );
1329
1330 if( textWasLeftOf != textIsLeftOf )
1331 {
1332 // Flip whatever the user had set
1333 m_dimension.SetHorizJustify( ( oldJustify == GR_TEXT_H_ALIGN_T::GR_TEXT_H_ALIGN_LEFT )
1336 }
1337 }
1338
1339 // Update the dimension (again) to ensure the text knockouts are correct
1340 m_dimension.Update();
1341 }
1342
1343private:
1345 {
1346 const SEG newCrossBar{ m_dimension.GetCrossbarStart(), m_dimension.GetCrossbarEnd() };
1347
1348 const EDA_ANGLE oldAngle = EDA_ANGLE( m_oldCrossBar.B - m_oldCrossBar.A );
1349 const EDA_ANGLE newAngle = EDA_ANGLE( newCrossBar.B - newCrossBar.A );
1350 const EDA_ANGLE rotation = oldAngle - newAngle;
1351
1352 // There are two modes - when the text is between the crossbar points, and when it's not.
1354 {
1356 const VECTOR2I rotTextOffsetFromCbCenter = GetRotated( m_originalTextPos - m_oldCrossBar.Center(),
1357 rotation );
1358 const VECTOR2I rotTextOffsetFromCbEnd = GetRotated( m_originalTextPos - cbNearestEndToText, rotation );
1359
1360 // Which of the two crossbar points is now in the right direction? They could be swapped over now.
1361 // If zero-length, doesn't matter, they're the same thing
1362 const bool startIsInOffsetDirection = KIGEOM::PointIsInDirection( m_dimension.GetCrossbarStart(),
1363 rotTextOffsetFromCbCenter,
1364 newCrossBar.Center() );
1365
1366 const VECTOR2I& newCbRefPt = startIsInOffsetDirection ? m_dimension.GetCrossbarStart()
1367 : m_dimension.GetCrossbarEnd();
1368
1369 // Apply the new offset to the correct crossbar point
1370 return newCbRefPt + rotTextOffsetFromCbEnd;
1371 }
1372
1373 // If the text was between the crossbar points, it should stay there, but we need to find a
1374 // good place for it. Keep it the same distance from the crossbar line, but rotated as needed.
1375
1376 const VECTOR2I origTextPointProjected = m_oldCrossBar.NearestPoint( m_originalTextPos );
1377 const double oldRatio = KIGEOM::GetLengthRatioFromStart( origTextPointProjected, m_oldCrossBar );
1378
1379 // Perpendicular from the crossbar line to the text position
1380 // We need to keep this length constant
1381 const VECTOR2I rotCbNormalToText = GetRotated( m_originalTextPos - origTextPointProjected, rotation );
1382
1383 const VECTOR2I newProjected = newCrossBar.A + ( newCrossBar.B - newCrossBar.A ) * oldRatio;
1384 return newProjected + rotCbNormalToText;
1385 }
1386
1390};
1391
1392
1397{
1398public:
1400 m_dimension( aDimension )
1401 {}
1402
1403 void MakePoints( EDIT_POINTS& aPoints ) override
1404 {
1405 aPoints.AddPoint( m_dimension.GetStart() );
1406 aPoints.AddPoint( m_dimension.GetEnd() );
1407 aPoints.AddPoint( m_dimension.GetTextPos() );
1408 aPoints.AddPoint( m_dimension.GetCrossbarStart() );
1409 aPoints.AddPoint( m_dimension.GetCrossbarEnd() );
1410
1413
1414 if( m_dimension.Type() == PCB_DIM_ALIGNED_T )
1415 {
1416 // Dimension height setting - edit points should move only along the feature lines
1417 aPoints.Point( DIM_CROSSBARSTART )
1419 aPoints.Point( DIM_CROSSBARSTART ), aPoints.Point( DIM_START ) ) );
1420 aPoints.Point( DIM_CROSSBAREND )
1422 aPoints.Point( DIM_CROSSBAREND ), aPoints.Point( DIM_END ) ) );
1423 }
1424 }
1425
1426 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1427 {
1428 wxCHECK( aPoints.PointsSize() == DIM_ALIGNED_MAX, false );
1429
1430 aPoints.Point( DIM_START ).SetPosition( m_dimension.GetStart() );
1431 aPoints.Point( DIM_END ).SetPosition( m_dimension.GetEnd() );
1432 aPoints.Point( DIM_TEXT ).SetPosition( m_dimension.GetTextPos() );
1433 aPoints.Point( DIM_CROSSBARSTART ).SetPosition( m_dimension.GetCrossbarStart() );
1434 aPoints.Point( DIM_CROSSBAREND ).SetPosition( m_dimension.GetCrossbarEnd() );
1435 return true;
1436 }
1437
1438 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1439 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1440 {
1442
1443 if( m_dimension.Type() == PCB_DIM_ALIGNED_T )
1444 updateAlignedDimension( aEditedPoint, aPoints );
1445 else
1446 updateOrthogonalDimension( aEditedPoint, aPoints );
1447 }
1448
1449 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override
1450 {
1451 // Constraint for crossbar
1452 if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1453 return aPoints.Point( DIM_END ).GetPosition();
1454
1455 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1456 return aPoints.Point( DIM_START ).GetPosition();
1457
1458 // No constraint
1459 return aEditedPoint.GetPosition();
1460 }
1461
1462private:
1466 void updateAlignedDimension( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints )
1467 {
1468 DIM_ALIGNED_TEXT_UPDATER textPositionUpdater( m_dimension );
1469
1470 // Check which point is currently modified and updated dimension's points respectively
1471 if( isModified( aEditedPoint, aPoints.Point( DIM_CROSSBARSTART ) ) )
1472 {
1473 VECTOR2D featureLine( aEditedPoint.GetPosition() - m_dimension.GetStart() );
1474 VECTOR2D crossBar( m_dimension.GetEnd() - m_dimension.GetStart() );
1475
1476 if( featureLine.Cross( crossBar ) > 0 )
1477 m_dimension.SetHeight( -featureLine.EuclideanNorm() );
1478 else
1479 m_dimension.SetHeight( featureLine.EuclideanNorm() );
1480
1481 m_dimension.Update();
1482 }
1483 else if( isModified( aEditedPoint, aPoints.Point( DIM_CROSSBAREND ) ) )
1484 {
1485 VECTOR2D featureLine( aEditedPoint.GetPosition() - m_dimension.GetEnd() );
1486 VECTOR2D crossBar( m_dimension.GetEnd() - m_dimension.GetStart() );
1487
1488 if( featureLine.Cross( crossBar ) > 0 )
1489 m_dimension.SetHeight( -featureLine.EuclideanNorm() );
1490 else
1491 m_dimension.SetHeight( featureLine.EuclideanNorm() );
1492
1493 m_dimension.Update();
1494 }
1495 else if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1496 {
1497 m_dimension.SetStart( aEditedPoint.GetPosition() );
1498 m_dimension.Update();
1499
1500 aPoints.Point( DIM_CROSSBARSTART )
1502 aPoints.Point( DIM_CROSSBARSTART ), aPoints.Point( DIM_START ) ) );
1503 aPoints.Point( DIM_CROSSBAREND )
1505 aPoints.Point( DIM_CROSSBAREND ), aPoints.Point( DIM_END ) ) );
1506 }
1507 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1508 {
1509 m_dimension.SetEnd( aEditedPoint.GetPosition() );
1510 m_dimension.Update();
1511
1512 aPoints.Point( DIM_CROSSBARSTART )
1514 aPoints.Point( DIM_CROSSBARSTART ), aPoints.Point( DIM_START ) ) );
1515 aPoints.Point( DIM_CROSSBAREND )
1517 aPoints.Point( DIM_CROSSBAREND ), aPoints.Point( DIM_END ) ) );
1518 }
1519 else if( isModified( aEditedPoint, aPoints.Point( DIM_TEXT ) ) )
1520 {
1521 // Force manual mode if we weren't already in it
1522 m_dimension.SetTextPositionMode( DIM_TEXT_POSITION::MANUAL );
1523 m_dimension.SetTextPos( aEditedPoint.GetPosition() );
1524 m_dimension.Update();
1525 }
1526
1527 textPositionUpdater.UpdateTextAfterChange();
1528 }
1529
1533 void updateOrthogonalDimension( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints )
1534 {
1535 DIM_ALIGNED_TEXT_UPDATER textPositionUpdater( m_dimension );
1536 PCB_DIM_ORTHOGONAL& orthDimension = static_cast<PCB_DIM_ORTHOGONAL&>( m_dimension );
1537
1538 if( isModified( aEditedPoint, aPoints.Point( DIM_CROSSBARSTART ) )
1539 || isModified( aEditedPoint, aPoints.Point( DIM_CROSSBAREND ) ) )
1540 {
1541 BOX2I bounds( m_dimension.GetStart(), m_dimension.GetEnd() - m_dimension.GetStart() );
1542
1543 const VECTOR2I& cursorPos = aEditedPoint.GetPosition();
1544
1545 // Find vector from nearest dimension point to edit position
1546 VECTOR2I directionA( cursorPos - m_dimension.GetStart() );
1547 VECTOR2I directionB( cursorPos - m_dimension.GetEnd() );
1548 VECTOR2I direction = directionA.SquaredEuclideanNorm() < directionB.SquaredEuclideanNorm() ? directionA
1549 : directionB;
1550
1551 bool vert;
1552 VECTOR2D featureLine( cursorPos - m_dimension.GetStart() );
1553
1554 // Only change the orientation when we move outside the bounds
1555 if( !bounds.Contains( cursorPos ) )
1556 {
1557 // If the dimension is horizontal or vertical, set correct orientation
1558 // otherwise, test if we're left/right of the bounding box or above/below it
1559 if( bounds.GetWidth() == 0 )
1560 vert = true;
1561 else if( bounds.GetHeight() == 0 )
1562 vert = false;
1563 else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
1564 vert = false;
1565 else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
1566 vert = true;
1567 else
1568 vert = std::abs( direction.y ) < std::abs( direction.x );
1569
1572 }
1573 else
1574 {
1575 vert = orthDimension.GetOrientation() == PCB_DIM_ORTHOGONAL::DIR::VERTICAL;
1576 }
1577
1578 m_dimension.SetHeight( vert ? featureLine.x : featureLine.y );
1579 }
1580 else if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1581 {
1582 m_dimension.SetStart( aEditedPoint.GetPosition() );
1583 }
1584 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1585 {
1586 m_dimension.SetEnd( aEditedPoint.GetPosition() );
1587 }
1588 else if( isModified( aEditedPoint, aPoints.Point( DIM_TEXT ) ) )
1589 {
1590 // Force manual mode if we weren't already in it
1591 m_dimension.SetTextPositionMode( DIM_TEXT_POSITION::MANUAL );
1592 m_dimension.SetTextPos( VECTOR2I( aEditedPoint.GetPosition() ) );
1593 }
1594
1595 m_dimension.Update();
1596
1597 // After recompute, find the new text position
1598 textPositionUpdater.UpdateTextAfterChange();
1599 }
1600
1602};
1603
1604
1606{
1607public:
1609 m_dimension( aDimension )
1610 {}
1611
1612 void MakePoints( EDIT_POINTS& aPoints ) override
1613 {
1614 aPoints.AddPoint( m_dimension.GetStart() );
1615 aPoints.AddPoint( m_dimension.GetEnd() );
1616
1618
1619 aPoints.Point( DIM_END ).SetRelation( EDIT_RELATION::Angle45( aPoints.Point( DIM_START ) ) );
1621 }
1622
1623 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1624 {
1625 wxCHECK( aPoints.PointsSize() == DIM_CENTER_MAX, false );
1626
1627 aPoints.Point( DIM_START ).SetPosition( m_dimension.GetStart() );
1628 aPoints.Point( DIM_END ).SetPosition( m_dimension.GetEnd() );
1629 return true;
1630 }
1631
1632 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1633 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1634 {
1636
1637 if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1638 m_dimension.SetStart( aEditedPoint.GetPosition() );
1639 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1640 m_dimension.SetEnd( aEditedPoint.GetPosition() );
1641
1642 m_dimension.Update();
1643 }
1644
1645 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override
1646 {
1647 if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1648 return aPoints.Point( DIM_START ).GetPosition();
1649
1650 return std::nullopt;
1651 }
1652
1653private:
1655};
1656
1657
1659{
1660public:
1662 m_dimension( aDimension )
1663 {}
1664
1665 void MakePoints( EDIT_POINTS& aPoints ) override
1666 {
1667 aPoints.AddPoint( m_dimension.GetStart() );
1668 aPoints.AddPoint( m_dimension.GetEnd() );
1669 aPoints.AddPoint( m_dimension.GetTextPos() );
1670 aPoints.AddPoint( m_dimension.GetKnee() );
1671
1674
1675 aPoints.Point( DIM_KNEE )
1677 aPoints.Point( DIM_END ) ) );
1679
1680 aPoints.Point( DIM_TEXT ).SetRelation( EDIT_RELATION::Angle45( aPoints.Point( DIM_KNEE ) ) );
1682 }
1683
1684 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1685 {
1686 wxCHECK( aPoints.PointsSize() == DIM_RADIAL_MAX, false );
1687
1688 aPoints.Point( DIM_START ).SetPosition( m_dimension.GetStart() );
1689 aPoints.Point( DIM_END ).SetPosition( m_dimension.GetEnd() );
1690 aPoints.Point( DIM_TEXT ).SetPosition( m_dimension.GetTextPos() );
1691 aPoints.Point( DIM_KNEE ).SetPosition( m_dimension.GetKnee() );
1692 return true;
1693 }
1694
1695 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1696 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1697 {
1699
1700 if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1701 {
1702 m_dimension.SetStart( aEditedPoint.GetPosition() );
1703 m_dimension.Update();
1704
1705 aPoints.Point( DIM_KNEE )
1707 aPoints.Point( DIM_END ) ) );
1708 }
1709 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1710 {
1711 VECTOR2I oldKnee = m_dimension.GetKnee();
1712
1713 m_dimension.SetEnd( aEditedPoint.GetPosition() );
1714 m_dimension.Update();
1715
1716 VECTOR2I kneeDelta = m_dimension.GetKnee() - oldKnee;
1717 m_dimension.SetTextPos( m_dimension.GetTextPos() + kneeDelta );
1718 m_dimension.Update();
1719
1720 aPoints.Point( DIM_KNEE )
1722 aPoints.Point( DIM_END ) ) );
1723 }
1724 else if( isModified( aEditedPoint, aPoints.Point( DIM_KNEE ) ) )
1725 {
1726 VECTOR2I oldKnee = m_dimension.GetKnee();
1727 VECTOR2I arrowVec = aPoints.Point( DIM_KNEE ).GetPosition() - aPoints.Point( DIM_END ).GetPosition();
1728
1729 m_dimension.SetLeaderLength( arrowVec.EuclideanNorm() );
1730 m_dimension.Update();
1731
1732 VECTOR2I kneeDelta = m_dimension.GetKnee() - oldKnee;
1733 m_dimension.SetTextPos( m_dimension.GetTextPos() + kneeDelta );
1734 m_dimension.Update();
1735 }
1736 else if( isModified( aEditedPoint, aPoints.Point( DIM_TEXT ) ) )
1737 {
1738 m_dimension.SetTextPos( aEditedPoint.GetPosition() );
1739 m_dimension.Update();
1740 }
1741 }
1742
1743 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override
1744 {
1745 if( isModified( aEditedPoint, aPoints.Point( DIM_TEXT ) ) )
1746 return aPoints.Point( DIM_KNEE ).GetPosition();
1747
1748 return std::nullopt;
1749 }
1750
1751private:
1753};
1754
1755
1757{
1758public:
1760 m_dimension( aDimension )
1761 {}
1762
1763 void MakePoints( EDIT_POINTS& aPoints ) override
1764 {
1765 aPoints.AddPoint( m_dimension.GetStart() );
1766 aPoints.AddPoint( m_dimension.GetEnd() );
1767 aPoints.AddPoint( m_dimension.GetTextPos() );
1768
1771
1772 aPoints.Point( DIM_TEXT ).SetRelation( EDIT_RELATION::Angle45( aPoints.Point( DIM_END ) ) );
1774 }
1775
1776 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1777 {
1778 wxCHECK( aPoints.PointsSize() == DIM_LEADER_MAX, false );
1779
1780 aPoints.Point( DIM_START ).SetPosition( m_dimension.GetStart() );
1781 aPoints.Point( DIM_END ).SetPosition( m_dimension.GetEnd() );
1782 aPoints.Point( DIM_TEXT ).SetPosition( m_dimension.GetTextPos() );
1783 return true;
1784 }
1785
1786 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1787 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1788 {
1790
1791 if( isModified( aEditedPoint, aPoints.Point( DIM_START ) ) )
1792 {
1793 m_dimension.SetStart( aEditedPoint.GetPosition() );
1794 }
1795 else if( isModified( aEditedPoint, aPoints.Point( DIM_END ) ) )
1796 {
1797 const VECTOR2I newPoint( aEditedPoint.GetPosition() );
1798 const VECTOR2I delta = newPoint - m_dimension.GetEnd();
1799
1800 m_dimension.SetEnd( newPoint );
1801 m_dimension.SetTextPos( m_dimension.GetTextPos() + delta );
1802 }
1803 else if( isModified( aEditedPoint, aPoints.Point( DIM_TEXT ) ) )
1804 {
1805 m_dimension.SetTextPos( aEditedPoint.GetPosition() );
1806 }
1807
1808 m_dimension.Update();
1809 }
1810
1811private:
1813};
1814
1815
1820{
1821public:
1823 m_textbox( aTextbox )
1824 {}
1825
1826 void MakePoints( EDIT_POINTS& aPoints ) override
1827 {
1828 if( m_textbox.GetShape() == SHAPE_T::RECTANGLE )
1830
1831 // Rotated textboxes are implemented as polygons and these aren't currently editable.
1832 }
1833
1834 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1835 {
1836 // Careful; textbox shape is mutable between cardinal and non-cardinal rotations...
1837 const unsigned target = m_textbox.GetShape() == SHAPE_T::RECTANGLE ? RECT_MAX_POINTS : 0;
1838
1839 if( aPoints.PointsSize() != target )
1840 return false;
1841
1843 return true;
1844 }
1845
1846 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1847 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1848 {
1849 if( m_textbox.GetShape() == SHAPE_T::RECTANGLE )
1850 {
1851 m_textbox.ClearBoundingBoxCache();
1852 VECTOR2I minSize = m_textbox.GetMinSize();
1854 }
1855 }
1856
1857private:
1859};
1860
1862{
1863public:
1865 m_group( &aGroup ),
1866 m_parent( &aGroup ),
1867 m_pinned( std::nullopt )
1868 {
1869 for( BOARD_ITEM* item : aGroup.GetBoardItems() )
1870 {
1871 if( item->Type() == PCB_SHAPE_T )
1872 {
1873 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1874 m_shapes.push_back( shape );
1875 m_originalWidths[shape] = static_cast<double>( shape->GetWidth() );
1876 }
1877 }
1878 }
1879
1880 SHAPE_GROUP_POINT_EDIT_BEHAVIOR( std::vector<PCB_SHAPE*> aShapes, BOARD_ITEM* aParent,
1881 const std::optional<VECTOR2I>& aPinned ) :
1882 m_group( nullptr ),
1883 m_shapes( std::move( aShapes ) ),
1884 m_parent( aParent ),
1885 m_pinned( aPinned )
1886 {
1887 for( PCB_SHAPE* shape : m_shapes )
1888 m_originalWidths[shape] = static_cast<double>( shape->GetWidth() );
1889 }
1890
1891 // Gap in board units that keeps the box handles clear of the shapes' own handles
1892 void SetInflation( int aInflation ) { m_inflation = aInflation; }
1893
1894 void MakePoints( EDIT_POINTS& aPoints ) override
1895 {
1896 BOX2I bbox = getBoundingBox();
1897 bbox.Inflate( m_inflation );
1898 VECTOR2I tl = bbox.GetOrigin();
1899 VECTOR2I br = bbox.GetEnd();
1900
1901 aPoints.AddPoint( tl );
1902 aPoints.AddPoint( VECTOR2I( br.x, tl.y ) );
1903 aPoints.AddPoint( br );
1904 aPoints.AddPoint( VECTOR2I( tl.x, br.y ) );
1905 aPoints.AddPoint( bbox.Centre() );
1906
1907 aPoints.AddIndicatorLine( aPoints.Point( RECT_TOP_LEFT ), aPoints.Point( RECT_TOP_RIGHT ) );
1908 aPoints.AddIndicatorLine( aPoints.Point( RECT_TOP_RIGHT ), aPoints.Point( RECT_BOT_RIGHT ) );
1909 aPoints.AddIndicatorLine( aPoints.Point( RECT_BOT_RIGHT ), aPoints.Point( RECT_BOT_LEFT ) );
1910 aPoints.AddIndicatorLine( aPoints.Point( RECT_BOT_LEFT ), aPoints.Point( RECT_TOP_LEFT ) );
1911 }
1912
1913 bool UpdatePoints( EDIT_POINTS& aPoints ) override
1914 {
1915 BOX2I bbox = getBoundingBox();
1916 bbox.Inflate( m_inflation );
1917 VECTOR2I tl = bbox.GetOrigin();
1918 VECTOR2I br = bbox.GetEnd();
1919
1920 aPoints.Point( RECT_TOP_LEFT ).SetPosition( tl );
1921 aPoints.Point( RECT_TOP_RIGHT ).SetPosition( br.x, tl.y );
1922 aPoints.Point( RECT_BOT_RIGHT ).SetPosition( br );
1923 aPoints.Point( RECT_BOT_LEFT ).SetPosition( tl.x, br.y );
1924 aPoints.Point( RECT_CENTER ).SetPosition( bbox.Centre() );
1925 return true;
1926 }
1927
1928 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
1929 std::vector<EDA_ITEM*>& aUpdatedItems ) override
1930 {
1931 BOX2I oldBox = getBoundingBox();
1932 VECTOR2I oldCenter = oldBox.Centre();
1933
1934 if( isModified( aEditedPoint, aPoints.Point( RECT_CENTER ) ) )
1935 {
1936 if( m_pinned )
1937 {
1938 UpdatePoints( aPoints );
1939 return;
1940 }
1941
1942 VECTOR2I delta = aPoints.Point( RECT_CENTER ).GetPosition() - oldCenter;
1943
1944 if( m_group )
1945 {
1946 aCommit.Modify( m_group, nullptr, RECURSE_MODE::RECURSE );
1947 m_group->Move( delta );
1948 }
1949 else
1950 {
1951 for( PCB_SHAPE* shape : m_shapes )
1952 {
1953 aCommit.Modify( shape );
1954 shape->Move( delta );
1955 }
1956 }
1957
1958 for( PCB_SHAPE* shape : m_shapes )
1959 aUpdatedItems.push_back( shape );
1960
1961 UpdatePoints( aPoints );
1962 return;
1963 }
1964
1965 VECTOR2I tl = aPoints.Point( RECT_TOP_LEFT ).GetPosition();
1966 VECTOR2I tr = aPoints.Point( RECT_TOP_RIGHT ).GetPosition();
1967 VECTOR2I bl = aPoints.Point( RECT_BOT_LEFT ).GetPosition();
1968 VECTOR2I br = aPoints.Point( RECT_BOT_RIGHT ).GetPosition();
1969
1970 // Take the gap back out before pinning, so the minimum size is measured on the
1971 // real box and a corner the user did not touch scales by exactly one
1973 tr += VECTOR2I( -m_inflation, m_inflation );
1974 bl += VECTOR2I( m_inflation, -m_inflation );
1976
1977 RECTANGLE_POINT_EDIT_BEHAVIOR::PinEditedCorner( aEditedPoint, aPoints, tl, tr, bl, br );
1978
1979 VECTOR2I origin = oldCenter;
1980 double scale;
1981
1982 // A scale holds exactly one point still, so a pinned selection has to scale about the pin
1983 if( m_pinned )
1984 {
1985 VECTOR2I oldCorner( oldBox.GetLeft(), oldBox.GetTop() );
1986 VECTOR2I newCorner = tl;
1987
1988 if( isModified( aEditedPoint, aPoints.Point( RECT_TOP_RIGHT ) ) )
1989 {
1990 oldCorner = VECTOR2I( oldBox.GetRight(), oldBox.GetTop() );
1991 newCorner = tr;
1992 }
1993 else if( isModified( aEditedPoint, aPoints.Point( RECT_BOT_RIGHT ) ) )
1994 {
1995 oldCorner = VECTOR2I( oldBox.GetRight(), oldBox.GetBottom() );
1996 newCorner = br;
1997 }
1998 else if( isModified( aEditedPoint, aPoints.Point( RECT_BOT_LEFT ) ) )
1999 {
2000 oldCorner = VECTOR2I( oldBox.GetLeft(), oldBox.GetBottom() );
2001 newCorner = bl;
2002 }
2003
2004 // Below this share of the selection diagonal a corner is too near the pin to scale by
2005 const double MIN_ARM_RATIO = 0.1;
2006
2007 VECTOR2I oldArm = oldCorner - *m_pinned;
2008 VECTOR2I newArm = newCorner - *m_pinned;
2009 VECTOR2I diagonal( oldBox.GetWidth(), oldBox.GetHeight() );
2010 double span = static_cast<double>( oldArm.SquaredEuclideanNorm() );
2011 double floor = static_cast<double>( diagonal.SquaredEuclideanNorm() ) * MIN_ARM_RATIO * MIN_ARM_RATIO;
2012
2013 // A corner on the pin has no leverage, so any drag of it would scale wildly
2014 if( span < floor )
2015 {
2016 UpdatePoints( aPoints );
2017 return;
2018 }
2019
2020 // Measured along the arm, so a corner level with the pin stays controllable
2021 origin = *m_pinned;
2022 scale = static_cast<double>( oldArm.Dot( newArm ) ) / span;
2023 }
2024 else
2025 {
2026 double sx = static_cast<double>( br.x - tl.x ) / static_cast<double>( oldBox.GetWidth() );
2027 double sy = static_cast<double>( br.y - tl.y ) / static_cast<double>( oldBox.GetHeight() );
2028
2029 scale = ( sx + sy ) / 2.0;
2030 }
2031
2032 // Prevent scaling below a minimum threshold to avoid precision loss when shapes
2033 // are scaled to near-zero size. Also prevent negative scaling which would flip
2034 // shapes when dragging past the center point.
2035 const double MIN_SCALE = 0.01;
2036
2037 if( scale < MIN_SCALE )
2038 scale = MIN_SCALE;
2039
2040 for( PCB_SHAPE* shape : m_shapes )
2041 {
2042 aCommit.Modify( shape );
2043 shape->Move( -origin );
2044 shape->Scale( scale );
2045 shape->Move( origin );
2046
2047 if( auto shapeIt = m_originalWidths.find( shape ); shapeIt != m_originalWidths.end() )
2048 {
2049 shapeIt->second = shapeIt->second * scale;
2050 shape->SetWidth( KiROUND( shapeIt->second ) );
2051 }
2052 else
2053 {
2054 shape->SetWidth( KiROUND( shape->GetWidth() * scale ) );
2055 }
2056
2057 aUpdatedItems.push_back( shape );
2058 }
2059
2060 UpdatePoints( aPoints );
2061 }
2062
2063 BOARD_ITEM* GetParent() const { return m_parent; }
2064
2065 const std::vector<PCB_SHAPE*>& GetShapes() const { return m_shapes; }
2066
2067private:
2069 {
2070 BOX2I bbox;
2071
2072 for( const PCB_SHAPE* shape : m_shapes )
2073 bbox.Merge( shape->GetBoundingBox() );
2074
2075 return bbox;
2076 }
2077
2078private:
2080 std::vector<PCB_SHAPE*> m_shapes;
2082 std::optional<VECTOR2I> m_pinned;
2083 std::unordered_map<PCB_SHAPE*, double> m_originalWidths;
2085};
2086
2087
2089 PCB_TOOL_BASE( "pcbnew.PointEditor" ),
2090 m_frame( nullptr ),
2091 m_selectionTool( nullptr ),
2092 m_editedPoint( nullptr ),
2093 m_hoveredPoint( nullptr ),
2094 m_original( VECTOR2I( 0, 0 ) ),
2096 m_radiusHelper( nullptr ),
2097 m_altConstrainer( VECTOR2I( 0, 0 ) ),
2098 m_inPointEditorTool( false ),
2099 m_angleSnapPos( VECTOR2I( 0, 0 ) ),
2100 m_stickyDisplacement( VECTOR2I( 0, 0 ) ),
2101 m_angleSnapActive( false ),
2102 m_blockHoveredPoint( nullptr ),
2103 m_blockHoveredOwner( nullptr )
2104{}
2105
2106
2108{
2110
2111 // Undo a running gesture first. ResetTools runs before a board reload deletes the
2112 // old board, so the items are still here. Move the callback out before calling it,
2113 // so a second reset during the undo cannot call it again
2114 if( m_blockDragAbort )
2115 {
2116 std::function<void()> abort = std::move( m_blockDragAbort );
2117 m_blockDragAbort = nullptr;
2118 abort();
2119 }
2120
2121 if( KIGFX::VIEW* view = getView() )
2122 {
2123 if( m_angleItem && view->HasItem( m_angleItem.get() ) )
2124 view->Remove( m_angleItem.get() );
2125
2126 if( m_editPoints && view->HasItem( m_editPoints.get() ) )
2127 view->Remove( m_editPoints.get() );
2128
2129 if( view->HasItem( &m_preview ) )
2130 view->Remove( &m_preview );
2131 }
2132
2133 m_editedPoint = nullptr;
2134 m_hoveredPoint = nullptr;
2136
2137 m_angleItem.reset();
2138 m_editPoints.reset();
2139 m_altConstraint.reset();
2140 getViewControls()->SetAutoPan( false );
2141 m_angleSnapActive = false;
2143}
2144
2145
2147{
2148 const KICAD_T type = aItem.Type();
2149
2150 if( type == PCB_ZONE_T )
2151 return true;
2152
2153 if( type == PCB_SHAPE_T )
2154 {
2155 const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
2156 const SHAPE_T shapeType = shape.GetShape();
2157 return shapeType == SHAPE_T::SEGMENT || shapeType == SHAPE_T::POLY || shapeType == SHAPE_T::ARC;
2158 }
2159
2160 return false;
2161}
2162
2163
2165{
2166 const auto type = aItem.Type();
2167
2168 if( type == PCB_ZONE_T )
2169 return true;
2170
2171 if( type == PCB_SHAPE_T )
2172 {
2173 const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
2174 const SHAPE_T shapeType = shape.GetShape();
2175 return shapeType == SHAPE_T::POLY;
2176 }
2177
2178 return false;
2179}
2180
2181
2182static VECTOR2I snapCorner( const VECTOR2I& aPrev, const VECTOR2I& aNext, const VECTOR2I& aGuess,
2183 double aAngleDeg )
2184{
2185 double angleRad = aAngleDeg * M_PI / 180.0;
2186 VECTOR2D prev( aPrev );
2187 VECTOR2D next( aNext );
2188 double chord = ( next - prev ).EuclideanNorm();
2189 double sinA = sin( angleRad );
2190
2191 if( chord == 0.0 || fabs( sinA ) < 1e-9 )
2192 return aGuess;
2193
2194 double radius = chord / ( 2.0 * sinA );
2195 VECTOR2D mid = ( prev + next ) / 2.0;
2196 VECTOR2D dir = next - prev;
2197 VECTOR2D normal( -dir.y, dir.x );
2198 normal = normal.Resize( 1 );
2199 double h_sq = radius * radius - ( chord * chord ) / 4.0;
2200 double h = h_sq > 0.0 ? sqrt( h_sq ) : 0.0;
2201
2202 VECTOR2D center1 = mid + normal * h;
2203 VECTOR2D center2 = mid - normal * h;
2204
2205 auto project =
2206 [&]( const VECTOR2D& center )
2207 {
2208 VECTOR2D v = VECTOR2D( aGuess ) - center;
2209
2210 if( v.EuclideanNorm() == 0.0 )
2211 v = prev - center;
2212
2213 v = v.Resize( 1 );
2214 VECTOR2D p = center + v * radius;
2215 return KiROUND( p );
2216 };
2217
2218 VECTOR2I p1 = project( center1 );
2219 VECTOR2I p2 = project( center2 );
2220
2221 double d1 = ( VECTOR2D( aGuess ) - VECTOR2D( p1 ) ).EuclideanNorm();
2222 double d2 = ( VECTOR2D( aGuess ) - VECTOR2D( p2 ) ).EuclideanNorm();
2223
2224 return d1 < d2 ? p1 : p2;
2225}
2226
2227
2229{
2230 // Find the selection tool, so they can cooperate
2232
2233 wxASSERT_MSG( m_selectionTool, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
2234
2235 const auto arcIsEdited =
2236 []( const SELECTION& aSelection ) -> bool
2237 {
2238 const EDA_ITEM* item = aSelection.Front();
2239 return ( item != nullptr ) && ( item->Type() == PCB_SHAPE_T )
2240 && static_cast<const PCB_SHAPE*>( item )->GetShape() == SHAPE_T::ARC;
2241 };
2242
2243 using S_C = SELECTION_CONDITIONS;
2244
2245 auto& menu = m_selectionTool->GetToolMenu().GetMenu();
2246
2247 menu.AddItem( PCB_ACTIONS::cycleArcEditMode, S_C::Count( 1 ) && arcIsEdited );
2248
2249 return true;
2250}
2251
2252
2253std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
2254{
2255 std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
2256
2257 // An edge handle is only pickable in its own right with the feature on, so only then does
2258 // it show that it is under the cursor or picked
2259 points->SetLineStateVisible( blockAnchorEditingEnabled() );
2260
2261 if( !aItem )
2262 return points;
2263
2264 bool rejected = false;
2265 m_editorBehavior = makeBehavior( aItem, rejected );
2266
2267 if( rejected )
2268 points.reset();
2269
2270 if( m_editorBehavior && points )
2271 m_editorBehavior->MakePoints( *points );
2272
2273 return points;
2274}
2275
2276
2277std::unique_ptr<POINT_EDIT_BEHAVIOR> PCB_POINT_EDITOR::makeBehavior( EDA_ITEM* aItem, bool& aRejected )
2278{
2279 std::unique_ptr<POINT_EDIT_BEHAVIOR> behavior;
2280
2281 switch( aItem->Type() )
2282 {
2284 {
2285 PCB_REFERENCE_IMAGE& refImage = static_cast<PCB_REFERENCE_IMAGE&>( *aItem );
2286 behavior = std::make_unique<REFERENCE_IMAGE_POINT_EDIT_BEHAVIOR>( refImage.GetReferenceImage(),
2287 pcbIUScale.mmToIU( 1.0 ) );
2288 break;
2289 }
2290 case PCB_BARCODE_T:
2291 {
2292 PCB_BARCODE& barcode = static_cast<PCB_BARCODE&>( *aItem );
2293 behavior = std::make_unique<BARCODE_POINT_EDIT_BEHAVIOR>( barcode );
2294 break;
2295 }
2296 case PCB_GRID_ITEM_T:
2297 {
2298 PCB_GRID_ITEM& grid = static_cast<PCB_GRID_ITEM&>( *aItem );
2299 behavior = std::make_unique<GRID_POINT_EDIT_BEHAVIOR>( grid );
2300 break;
2301 }
2302 case PCB_TEXTBOX_T:
2303 {
2304 PCB_TEXTBOX& textbox = static_cast<PCB_TEXTBOX&>( *aItem );
2305 behavior = std::make_unique<TEXTBOX_POINT_EDIT_BEHAVIOR>( textbox );
2306 break;
2307 }
2308 case PCB_SHAPE_T:
2309 {
2310 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
2311
2312 switch( shape->GetShape() )
2313 {
2314 case SHAPE_T::SEGMENT: behavior = std::make_unique<EDA_SEGMENT_POINT_EDIT_BEHAVIOR>( *shape ); break;
2315
2316 case SHAPE_T::RECTANGLE: behavior = std::make_unique<RECTANGLE_POINT_EDIT_BEHAVIOR>( *shape ); break;
2317
2318 case SHAPE_T::ARC:
2319 behavior = std::make_unique<EDA_ARC_POINT_EDIT_BEHAVIOR>( *shape, m_arcEditMode, *getViewControls(),
2320 pcbIUScale );
2321 break;
2322
2323 case SHAPE_T::CIRCLE: behavior = std::make_unique<EDA_CIRCLE_POINT_EDIT_BEHAVIOR>( *shape ); break;
2324
2325 case SHAPE_T::POLY: behavior = std::make_unique<EDA_POLYGON_POINT_EDIT_BEHAVIOR>( *shape ); break;
2326
2327 case SHAPE_T::BEZIER:
2328 behavior = std::make_unique<EDA_BEZIER_POINT_EDIT_BEHAVIOR>( *shape, shape->GetMaxError() );
2329 break;
2330
2331 case SHAPE_T::ELLIPSE:
2332 case SHAPE_T::ELLIPSE_ARC: behavior = std::make_unique<EDA_ELLIPSE_POINT_EDIT_BEHAVIOR>( *shape ); break;
2333
2334 default: // suppress warnings
2335 break;
2336 }
2337
2338 break;
2339 }
2340
2341 case PCB_GROUP_T:
2342 {
2343 PCB_GROUP* group = static_cast<PCB_GROUP*>( aItem );
2344 bool shapesOnly = true;
2345
2346 for( BOARD_ITEM* child : group->GetBoardItems() )
2347 {
2348 if( child->Type() != PCB_SHAPE_T )
2349 {
2350 shapesOnly = false;
2351 break;
2352 }
2353 }
2354
2355 if( shapesOnly )
2356 {
2357 std::unique_ptr<SHAPE_GROUP_POINT_EDIT_BEHAVIOR> groupBehavior =
2358 std::make_unique<SHAPE_GROUP_POINT_EDIT_BEHAVIOR>( *group );
2359 groupBehavior->SetInflation( bboxHandleInflation() );
2360 behavior = std::move( groupBehavior );
2361 }
2362 else
2363 {
2364 aRejected = true;
2365 }
2366
2367 break;
2368 }
2369
2370 case PCB_TABLECELL_T:
2371 {
2372 PCB_TABLECELL* cell = static_cast<PCB_TABLECELL*>( aItem );
2373
2374 // No support for point-editing of a rotated table
2375 if( cell->GetShape() == SHAPE_T::RECTANGLE )
2376 behavior = std::make_unique<PCB_TABLECELL_POINT_EDIT_BEHAVIOR>( *cell );
2377
2378 break;
2379 }
2380
2381 case PCB_PAD_T:
2382 {
2383 // Pad edit only for the footprint editor
2385 {
2386 PAD& pad = static_cast<PAD&>( *aItem );
2387 PCB_LAYER_ID activeLayer = m_frame ? m_frame->GetActiveLayer() : PADSTACK::TEMP_ALL_LAYERS;
2388
2389 // Point editor only handles copper shape changes
2390 if( !IsCopperLayer( activeLayer ) )
2391 activeLayer = IsFrontLayer( activeLayer ) ? F_Cu : B_Cu;
2392
2393 behavior = std::make_unique<PAD_POINT_EDIT_BEHAVIOR>( pad, activeLayer );
2394 }
2395 break;
2396 }
2397
2398 case PCB_ZONE_T:
2399 {
2400 ZONE& zone = static_cast<ZONE&>( *aItem );
2401 behavior = std::make_unique<ZONE_POINT_EDIT_BEHAVIOR>( zone );
2402 break;
2403 }
2404
2405 case PCB_GENERATOR_T:
2406 {
2407 if( dynamic_cast<PCB_GENERATOR_POLY*>( aItem ) )
2408 {
2409 PCB_GENERATOR_POLY* generator = static_cast<PCB_GENERATOR_POLY*>( aItem );
2410 behavior = std::make_unique<GENERATOR_POLY_POINT_EDIT_BEHAVIOR>( *generator );
2411 break;
2412 }
2413 else
2414 {
2415 PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( aItem );
2416 behavior = std::make_unique<GENERATOR_POINT_EDIT_BEHAVIOR>( *generator );
2417 }
2418 break;
2419 }
2420
2421 case PCB_DIM_ALIGNED_T:
2423 {
2424 PCB_DIM_ALIGNED& dimension = static_cast<PCB_DIM_ALIGNED&>( *aItem );
2425 behavior = std::make_unique<ALIGNED_DIMENSION_POINT_EDIT_BEHAVIOR>( dimension );
2426 break;
2427 }
2428
2429 case PCB_DIM_CENTER_T:
2430 {
2431 PCB_DIM_CENTER& dimension = static_cast<PCB_DIM_CENTER&>( *aItem );
2432 behavior = std::make_unique<DIM_CENTER_POINT_EDIT_BEHAVIOR>( dimension );
2433 break;
2434 }
2435
2436 case PCB_DIM_RADIAL_T:
2437 {
2438 PCB_DIM_RADIAL& dimension = static_cast<PCB_DIM_RADIAL&>( *aItem );
2439 behavior = std::make_unique<DIM_RADIAL_POINT_EDIT_BEHAVIOR>( dimension );
2440 break;
2441 }
2442
2443 case PCB_DIM_LEADER_T:
2444 {
2445 PCB_DIM_LEADER& dimension = static_cast<PCB_DIM_LEADER&>( *aItem );
2446 behavior = std::make_unique<DIM_LEADER_POINT_EDIT_BEHAVIOR>( dimension );
2447 break;
2448 }
2449
2450 default: aRejected = true; break;
2451 }
2452
2453 return behavior;
2454}
2455
2456
2458{
2459 // The gap only matters when the shapes show their own handles next to the box
2461 return 0;
2462
2463 // About 10 screen pixels of clearance at any zoom
2464 return KiROUND( getView()->ToWorld( 10.0 ) );
2465}
2466
2467
2472
2473
2475{
2477
2478 std::vector<BOARD_ITEM*> items;
2479
2480 for( EDA_ITEM* selItem : aSelection )
2481 {
2482 if( selItem->IsBOARD_ITEM() )
2483 items.push_back( static_cast<BOARD_ITEM*>( selItem ) );
2484 }
2485
2486 std::vector<BOARD_ITEM*> expanded = BlockDragExpandSelection( items );
2487
2488 m_expandedSelection = expanded;
2489
2490 // A lone object that is not a group already shows its handles through m_editPoints
2491 if( aSelection.Size() == 1 && aSelection.Front()->Type() != PCB_GROUP_T )
2492 return;
2493
2494 for( BOARD_ITEM* item : expanded )
2495 {
2497 continue;
2498
2499 bool rejected = false;
2500 std::unique_ptr<POINT_EDIT_BEHAVIOR> behavior = makeBehavior( item, rejected );
2501
2502 if( !behavior )
2503 continue;
2504
2505 BLOCK_HANDLE_ENTRY entry;
2506 entry.behavior = std::move( behavior );
2507 entry.points = std::make_shared<EDIT_POINTS>( item );
2508 entry.points->SetLineStateVisible( true );
2509 entry.behavior->MakePoints( *entry.points );
2510 getView()->Add( entry.points.get() );
2511 m_blockHandles.push_back( std::move( entry ) );
2512 }
2513}
2514
2515
2517{
2518 if( KIGFX::VIEW* view = getView() )
2519 {
2520 for( BLOCK_HANDLE_ENTRY& entry : m_blockHandles )
2521 {
2522 if( view->HasItem( entry.points.get() ) )
2523 view->Remove( entry.points.get() );
2524 }
2525 }
2526
2527 m_blockHandles.clear();
2528 m_blockHoveredPoint = nullptr;
2529 m_blockHoveredOwner = nullptr;
2530
2531 // No repaint, the collections these keys point at are already gone
2532 m_pickedHandles.clear();
2533 m_expandedSelection.clear();
2534}
2535
2536
2542
2543
2544std::vector<EDIT_POINTS*> PCB_POINT_EDITOR::pickableCollections()
2545{
2546 std::vector<EDIT_POINTS*> collections;
2547
2548 for( BLOCK_HANDLE_ENTRY& entry : m_blockHandles )
2549 collections.push_back( entry.points.get() );
2550
2551 // The scaling box borrows a member shape as its parent, so it is not pickable
2552 if( m_editPoints && m_editPoints->GetParent()
2553 && !dynamic_cast<SHAPE_GROUP_POINT_EDIT_BEHAVIOR*>( m_editorBehavior.get() ) )
2554 {
2555 collections.push_back( m_editPoints.get() );
2556 }
2557
2558 return collections;
2559}
2560
2561
2562bool PCB_POINT_EDITOR::pickHandleAt( const VECTOR2I& aPosition, bool aAccumulate )
2563{
2564 for( EDIT_POINTS* points : pickableCollections() )
2565 {
2566 EDIT_POINT* point = points->FindPoint( aPosition, getView() );
2567
2568 if( !point )
2569 continue;
2570
2571 // A pickable handle at the same spot always wins
2572 if( !BlockDragHandlePickable( *points, *point ) )
2573 continue;
2574
2575 std::optional<PCB_HANDLE_KEY> key = PCB_HANDLE_KEY::Make( *points, point );
2576
2577 if( !key )
2578 return false;
2579
2580 std::set<PCB_HANDLE_KEY> picked = m_pickedHandles;
2581
2582 BlockDragApplyPick( picked, *key, aAccumulate );
2583 setPickedHandles( std::move( picked ) );
2584 return true;
2585 }
2586
2587 return false;
2588}
2589
2590
2592{
2593 if( m_pickedHandles.empty() )
2594 return;
2595
2596 setPickedHandles( {} );
2597}
2598
2599
2600void PCB_POINT_EDITOR::setPickedHandles( std::set<PCB_HANDLE_KEY> aPicked )
2601{
2602 m_pickedHandles = std::move( aPicked );
2604}
2605
2606
2608{
2609 // Nothing can be picked with the feature off, so leave the plain point editor alone
2610 if( m_pickedHandles.empty() && !blockAnchorEditingEnabled() )
2611 return;
2612
2613 std::vector<EDIT_POINTS*> collections = pickableCollections();
2614
2615 for( EDIT_POINTS* points : collections )
2616 {
2617 for( unsigned ii = 0; ii < points->PointsSize(); ++ii )
2618 points->Point( ii ).SetSelected( false );
2619
2620 for( unsigned ii = 0; ii < points->LinesSize(); ++ii )
2621 points->Line( ii ).SetSelected( false );
2622 }
2623
2624 for( auto it = m_pickedHandles.begin(); it != m_pickedHandles.end(); )
2625 {
2626 EDIT_POINT* resolved = nullptr;
2627
2628 for( EDIT_POINTS* points : collections )
2629 {
2630 resolved = it->Resolve( *points );
2631
2632 if( resolved )
2633 break;
2634 }
2635
2636 if( resolved )
2637 {
2638 resolved->SetSelected();
2639 ++it;
2640 }
2641 else
2642 {
2643 it = m_pickedHandles.erase( it );
2644 }
2645 }
2646
2647 for( EDIT_POINTS* points : collections )
2648 getView()->Update( points );
2649}
2650
2651
2653{
2654 for( BLOCK_HANDLE_ENTRY& entry : m_blockHandles )
2655 {
2656 // A collection can be rebuilt in place, so a stored hover pointer goes stale
2657 if( m_blockHoveredOwner == entry.points.get() )
2658 {
2660 m_blockHoveredPoint->SetHover( false );
2661
2662 m_blockHoveredPoint = nullptr;
2663 m_blockHoveredOwner = nullptr;
2664 }
2665
2666 if( !entry.behavior->UpdatePoints( *entry.points ) )
2667 {
2668 EDA_ITEM* parent = entry.points->GetParent();
2669
2670 if( getView()->HasItem( entry.points.get() ) )
2671 getView()->Remove( entry.points.get() );
2672
2673 entry.points = std::make_shared<EDIT_POINTS>( parent );
2674 entry.points->SetLineStateVisible( true );
2675 entry.behavior->MakePoints( *entry.points );
2676 getView()->Add( entry.points.get() );
2677 }
2678 else
2679 {
2680 getView()->Update( entry.points.get() );
2681 }
2682 }
2683}
2684
2685
2687{
2688 EDIT_POINT* hovered = nullptr;
2689 EDIT_POINTS* owner = nullptr;
2690
2691 for( BLOCK_HANDLE_ENTRY& entry : m_blockHandles )
2692 {
2693 EDIT_POINT* point = entry.points->FindPoint( aPosition, getView() );
2694
2695 // Light only what a click would pick, the same test pickHandleAt() makes
2696 if( point && BlockDragHandlePickable( *entry.points, *point ) )
2697 {
2698 hovered = point;
2699 owner = entry.points.get();
2700 break;
2701 }
2702 }
2703
2704 if( hovered == m_blockHoveredPoint )
2705 return;
2706
2708 {
2709 m_blockHoveredPoint->SetHover( false );
2710
2713 }
2714
2715 m_blockHoveredPoint = hovered;
2716 m_blockHoveredOwner = owner;
2717
2719 {
2720 m_blockHoveredPoint->SetHover();
2722 }
2723}
2724
2725
2727{
2728 if( aEvent.IsMotion() )
2729 updateBlockHandleHover( aEvent.Position() );
2730
2731 if( !m_editPoints )
2732 return;
2733
2734 EDIT_POINT* point;
2735 EDIT_POINT* hovered = nullptr;
2736
2737 if( aEvent.IsMotion() )
2738 {
2739 point = m_editPoints->FindPoint( aEvent.Position(), getView() );
2740 hovered = point;
2741 }
2742 else if( aEvent.IsDrag( BUT_LEFT ) )
2743 {
2744 point = m_editPoints->FindPoint( aEvent.DragOrigin(), getView() );
2745 }
2746 else
2747 {
2748 point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() );
2749 }
2750
2751 if( hovered )
2752 {
2753 if( m_hoveredPoint != hovered )
2754 {
2755 if( m_hoveredPoint )
2756 m_hoveredPoint->SetHover( false );
2757
2758 m_hoveredPoint = hovered;
2759 m_hoveredPoint->SetHover();
2760 }
2761 }
2762 else if( m_hoveredPoint )
2763 {
2764 m_hoveredPoint->SetHover( false );
2765 m_hoveredPoint = nullptr;
2766 }
2767
2768 if( m_editedPoint != point )
2769 setEditedPoint( point );
2770}
2771
2772
2773// Pass on only navigation, the way the selection tool's own band loops do
2781
2782
2784{
2785 for( int ii = 0; blockDragNavigationActions[ii]; ++ii )
2786 {
2787 if( aEvent->IsAction( blockDragNavigationActions[ii] ) )
2788 {
2789 aEvent->SetPassEvent();
2790 return;
2791 }
2792 }
2793}
2794
2795
2796// Commands that leave the board alone and so may run while a gesture holds its staged commit
2805
2806
2807static bool blockDragAllowsCommand( const TOOL_EVENT& aEvent )
2808{
2809 if( aEvent.IsCancelInteractive() || aEvent.IsActivate() )
2810 return true;
2811
2812 for( const TOOL_ACTION* const* list : { blockDragNavigationActions, blockDragSafeActions } )
2813 {
2814 for( int ii = 0; list[ii]; ++ii )
2815 {
2816 if( aEvent.IsAction( list[ii] ) )
2817 return true;
2818 }
2819 }
2820
2821 return false;
2822}
2823
2824
2825namespace
2826{
2827
2828// Draw the band in the handle highlight color, so it reads as a handle gesture
2829class HANDLE_PICK_AREA : public KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM
2830{
2831public:
2832 void SetPoly( const SHAPE_LINE_CHAIN& aPoly ) { m_poly = aPoly; }
2833 SHAPE_LINE_CHAIN& GetPoly() { return m_poly; }
2834
2835 const BOX2I ViewBBox() const override { return m_poly.BBox(); }
2836
2837private:
2838 void drawPreviewShape( KIGFX::VIEW* aView ) const override
2839 {
2840 if( m_poly.PointCount() < 2 )
2841 return;
2842
2843 KIGFX::GAL& gal = *aView->GetGAL();
2844
2845 gal.SetIsFill( false );
2846 gal.SetIsStroke( true );
2847 gal.SetLineWidth( 0.0 );
2848 gal.DrawPolygon( m_poly );
2849
2850 gal.SetIsFill( true );
2851 gal.SetIsStroke( false );
2852 gal.DrawPolygon( m_poly );
2853 }
2854
2855 SHAPE_LINE_CHAIN m_poly;
2856};
2857
2858} // namespace
2859
2860
2861// The solver can move shapes that share a constraint with the block but were never dragged
2862static void blockDragAppendConstraintCoMembers( BOARD* aBoard, std::vector<BOARD_ITEM*>& aItems )
2863{
2864 std::set<KIID> known;
2865 bool grew = true;
2866
2867 for( BOARD_ITEM* item : aItems )
2868 {
2869 known.insert( item->m_Uuid );
2870
2871 // A carried footprint's pads reach further clusters
2872 if( item->Type() == PCB_FOOTPRINT_T )
2873 {
2874 item->RunOnChildren( [&]( BOARD_ITEM* aChild )
2875 {
2876 known.insert( aChild->m_Uuid );
2877 },
2879 }
2880 }
2881
2882 auto include = [&]( BOARD_ITEM* aItem )
2883 {
2884 if( known.insert( aItem->m_Uuid ).second )
2885 {
2886 aItems.push_back( aItem );
2887 grew = true;
2888 }
2889 };
2890
2891 const std::vector<PCB_CONSTRAINT*> constraints = CollectResolvedConstraints( aBoard );
2892
2893 while( grew )
2894 {
2895 grew = false;
2896
2897 for( const PCB_CONSTRAINT* constraint : constraints )
2898 {
2899 bool touches = false;
2900
2901 for( const CONSTRAINT_MEMBER& member : constraint->GetMembers() )
2902 {
2903 if( known.count( member.m_item ) )
2904 {
2905 touches = true;
2906 break;
2907 }
2908 }
2909
2910 if( !touches )
2911 continue;
2912
2913 for( const CONSTRAINT_MEMBER& member : constraint->GetMembers() )
2914 {
2915 if( known.count( member.m_item ) )
2916 continue;
2917
2918 BOARD_ITEM* item = aBoard->ResolveItem( member.m_item, true );
2919
2920 if( !item )
2921 continue;
2922
2923 include( item );
2924
2925 // On a board the solver moves a constrained child's whole footprint
2926 if( FOOTPRINT* footprint = item->GetParentFootprint(); footprint && !aBoard->IsFootprintHolder() )
2927 {
2928 include( footprint );
2929 footprint->RunOnChildren( include, RECURSE_MODE::RECURSE );
2930 }
2931 }
2932 }
2933 }
2934}
2935
2936
2939static wxString blockDragDrcRefusal()
2940{
2941 return wxString::Format( _( "The move violates DRC. (%s to commit anyway.)" ),
2943}
2944
2945
2958{
2959public:
2961 BOARD_COMMIT& aCommit ) :
2962 m_editor( aEditor ),
2963 m_editFrame( aEditFrame ),
2964 m_grid( aGrid ),
2965 m_commit( aCommit )
2966 {
2967 }
2968
2970 bool IsActive() const { return m_active; }
2971
2975 bool Begin( const VECTOR2I& aOrigin, bool aPressInFlight );
2976
2978 bool KeyboardDrag() const { return m_keyboardDrag; }
2979
2981 bool ApplyCursor( const TOOL_EVENT& aEvent );
2982
2984 bool Release( const TOOL_EVENT& aEvent );
2985
2987 bool Cancel( TOOL_EVENT& aEvent );
2988
2991 void Abort();
2992
2995 bool AreaPickStarts( const TOOL_EVENT& aEvent );
2996
2999 bool RunAreaPick( const TOOL_EVENT& aEvent );
3000
3002 bool Refused() const { return m_refused; }
3003 void ClearRefused() { m_refused = false; }
3004
3006 bool PressConsumed() const { return m_pressConsumed; }
3008
3009private:
3017
3021 FRAME_RESULT applyFrame( const VECTOR2I& aDelta, std::vector<EDA_ITEM*>& aUpdated );
3022
3025 bool collectTargets();
3026
3028 void releaseState();
3029
3035 bool revert( bool aPushed );
3036
3038 void endDrag( bool aKeepPicks );
3039
3042 bool refuseRelease( const wxString& aMessage );
3043
3045 KIGFX::COLOR4D bandColor() const;
3046
3048 void showBand( HANDLE_PICK_AREA& aArea );
3049 void hideBand( HANDLE_PICK_AREA& aArea );
3050
3053 bool runLasso( const TOOL_EVENT& aEvent );
3054
3057 bool runBox( const TOOL_EVENT& aEvent );
3058
3059 // Borrowed from the editor's call for as long as the gesture runs, never owned
3064
3065 bool m_active = false;
3066 bool m_keyboardDrag = false;
3067 bool m_pressConsumed = false;
3068 bool m_refused = false;
3069 bool m_revertRestarts = false;
3071 bool m_routerActive = false;
3072
3075 std::map<PCB_HANDLE_KEY, VECTOR2I> m_origins;
3076
3078 std::vector<std::pair<EDIT_POINTS*, POINT_EDIT_BEHAVIOR*>> m_targets;
3079
3082 std::vector<BLOCK_DRAG_ENDPOINT> m_dependents;
3083 std::vector<std::shared_ptr<EDIT_POINTS>> m_dependentDisplays;
3084
3086 std::vector<BOARD_ITEM*> m_rigidItems;
3087
3090 std::vector<BOARD_ITEM*> m_moving;
3091
3094 std::vector<KIID> m_overlayHidden;
3095
3098 std::vector<std::pair<PCB_SHAPE*, CONSTRAINT_MEMBER>> m_constraintAnchors;
3100
3101 std::optional<BOARD_CONSTRAINT_BLOCK_SESSION> m_constraintSession;
3102 bool m_constraintWarned = false;
3103
3105 std::set<PCB_SHAPE*> m_solverBrightened;
3106
3108 std::optional<BLOCK_DRAG_VALIDATION> m_validation;
3109
3112
3118};
3119
3120
3122{
3123 SELECTION_MODE mode = m_editor.m_selectionTool->GetSelectionMode();
3124
3126 return runLasso( aEvent );
3127
3128 return runBox( aEvent );
3129}
3130
3131
3133{
3134 // The DRC status lives in the view's preview, which nothing else in this editor
3135 // uses, so every exit from the gesture clears it
3136 m_editor.getView()->ClearPreview();
3137
3138 for( BOARD_ITEM* moving : m_moving )
3139 {
3140 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( moving ) )
3141 {
3142 shape->ClearFlags( IS_MOVING );
3143 shape->UpdateHatching();
3144 }
3145 }
3146
3147 for( std::shared_ptr<EDIT_POINTS>& display : m_dependentDisplays )
3148 {
3149 if( m_editor.getView()->HasItem( display.get() ) )
3150 m_editor.getView()->Remove( display.get() );
3151 }
3152
3153 for( PCB_SHAPE* neighbor : m_solverBrightened )
3154 {
3155 neighbor->ClearBrightened();
3156 m_editor.getView()->Update( neighbor );
3157 }
3158
3159 m_solverBrightened.clear();
3160
3161 if( m_editor.m_editedPoint )
3162 m_editor.m_editedPoint->SetActive( false );
3163
3164 if( m_routerActive )
3165 {
3166 ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>();
3167
3168 if( routerTool && routerTool->Router() )
3169 {
3170 if( routerTool->Router()->RoutingInProgress() )
3171 routerTool->Router()->StopRouting();
3172
3173 routerTool->GetInterface()->SetIndependentPads( {} );
3174 }
3175
3176 m_routerActive = false;
3177 }
3178
3179 // Look items up by id, because fixing the route can replace a carried segment.
3180 // The selection tool hides a selected item from the board pass so the overlay can
3181 // draw it alone, and clearing the overlay flag clears that hiding too, so put it back
3182 for( const KIID& hidden : m_overlayHidden )
3183 {
3184 if( BOARD_ITEM* item = m_editor.board()->ResolveItem( hidden, true ) )
3185 {
3186 m_editor.getView()->Hide( item, false );
3187
3188 if( item->IsSelected() )
3189 m_editor.getView()->Hide( item, true );
3190 }
3191 }
3192
3193 m_overlayHidden.clear();
3194
3195 m_dependentDisplays.clear();
3196 m_dependents.clear();
3197 m_targets.clear();
3198 m_origins.clear();
3199 m_rigidItems.clear();
3200 m_moving.clear();
3201 m_constraintAnchors.clear();
3202 m_constraintTranslated.clear();
3203 m_constraintSession.reset();
3204 m_constraintWarned = false;
3205 m_validation.reset();
3206 m_appliedDelta = VECTOR2I( 0, 0 );
3207 m_revertRestarts = false;
3208 m_active = false;
3209 m_keyboardDrag = false;
3210 m_editor.m_blockDragAbort = nullptr;
3211 m_grid.SetPointEditProfile( true );
3212 m_editor.getViewControls()->ForceCursorPosition( false );
3213 m_editor.getViewControls()->SetAutoPan( false );
3214 m_editor.frame()->UndoRedoBlock( false );
3215}
3216
3217
3219{
3220 if( !m_active )
3221 return;
3222
3223 // Release the items before undoing, because the undo can replace them
3224 releaseState();
3225 m_commit.Revert();
3226
3227 // No repaint, the undo can replace the items these keys point at
3228 m_editor.m_pickedHandles.clear();
3229}
3230
3231
3232bool BLOCK_DRAG_SESSION::revert( bool aPushed )
3233{
3234 bool restart = m_revertRestarts;
3235
3236 releaseState();
3237
3238 if( aPushed )
3239 m_editFrame->RollbackFromUndo();
3240 else
3241 m_commit.Revert();
3242
3243 if( restart )
3244 m_editor.m_toolMgr->PostEvent( EVENTS::SelectedEvent );
3245
3246 return restart;
3247}
3248
3249
3250void BLOCK_DRAG_SESSION::endDrag( bool aKeepPicks )
3251{
3252 if( m_active )
3253 releaseState();
3254
3255 if( !aKeepPicks )
3256 m_editor.clearPickedHandles();
3257
3258 m_editor.updatePoints();
3259}
3260
3261
3263{
3264 m_targets.clear();
3265
3266 for( EDIT_POINTS* candidate : m_editor.pickableCollections() )
3267 {
3268 EDA_ITEM* parent = candidate->GetParent();
3269
3270 if( !parent )
3271 continue;
3272
3273 bool hasMovedPoint = false;
3274
3275 for( const auto& [key, origin] : m_origins )
3276 {
3277 if( key.Parent() == parent->m_Uuid )
3278 {
3279 hasMovedPoint = true;
3280 break;
3281 }
3282 }
3283
3284 if( !hasMovedPoint )
3285 continue;
3286
3287 POINT_EDIT_BEHAVIOR* behavior = nullptr;
3288
3289 if( candidate == m_editor.m_editPoints.get() )
3290 {
3291 behavior = m_editor.m_editorBehavior.get();
3292 }
3293 else
3294 {
3295 for( PCB_POINT_EDITOR::BLOCK_HANDLE_ENTRY& entry : m_editor.m_blockHandles )
3296 {
3297 if( entry.points.get() == candidate )
3298 {
3299 behavior = entry.behavior.get();
3300 break;
3301 }
3302 }
3303 }
3304
3305 if( !behavior )
3306 return false;
3307
3308 m_targets.push_back( { candidate, behavior } );
3309 }
3310
3311 return true;
3312}
3313
3314
3315// Write one frame. First the reshaped items, then the ones that travel whole, then the
3316// joined endpoints that follow, then the constraint solve over all of them. Undoing a
3317// frame is this same call with the last offset the gesture accepted
3319 std::vector<EDA_ITEM*>& aUpdated )
3320{
3321 if( !BlockDragApplyDisplacement( m_editor.pickableCollections(), m_origins, aDelta, m_grid ) || !collectTargets() )
3323
3324 for( auto& [targetPoints, behavior] : m_targets )
3325 {
3326 EDA_ITEM* parent = targetPoints->GetParent();
3327 aUpdated.push_back( parent );
3328
3329 for( const auto& [key, origin] : m_origins )
3330 {
3331 if( key.Parent() != parent->m_Uuid )
3332 continue;
3333
3334 if( EDIT_POINT* moved = key.Resolve( *targetPoints ) )
3335 {
3336 behavior->UpdateItem( *moved, *targetPoints, m_commit, aUpdated );
3337
3338 // A polygon rebuilds its whole outline from the point list, so it has just
3339 // taken every picked handle with it. Calling it again per handle repeats
3340 // the same work, which is quadratic in the number of points picked
3341 if( behavior->UpdateItemAppliesAllPoints() )
3342 break;
3343 }
3344 }
3345 }
3346
3347 VECTOR2I frameStep = aDelta - m_appliedDelta;
3348
3349 if( frameStep != VECTOR2I( 0, 0 ) )
3350 {
3351 for( BOARD_ITEM* rigidItem : m_rigidItems )
3352 {
3353 rigidItem->Move( frameStep );
3354 aUpdated.push_back( rigidItem );
3355 }
3356 }
3357
3358 m_appliedDelta = aDelta;
3359
3360 for( size_t ii = 0; ii < m_dependents.size(); ++ii )
3361 {
3362 const BLOCK_DRAG_ENDPOINT& dep = m_dependents[ii];
3363 VECTOR2I target = dep.position + aDelta;
3364
3365 if( dep.follow == BLOCK_DRAG_FOLLOW::WHOLE )
3366 {
3367 // Move it by the distance its joint has left to go, so a long drag cannot
3368 // drift. Setting one endpoint instead would leave an arc's centre behind
3369 VECTOR2I at = dep.isStart ? dep.shape->GetStart() : dep.shape->GetEnd();
3370
3371 dep.shape->Move( target - at );
3372 }
3373 else if( dep.isStart )
3374 {
3375 dep.shape->SetStart( target );
3376 }
3377 else
3378 {
3379 dep.shape->SetEnd( target );
3380 }
3381
3382 aUpdated.push_back( dep.shape );
3383
3384 // The two vectors line up index by index, so they are always filtered together
3385 m_dependentDisplays[ii]->Point( 0 ).SetPosition( target );
3386 m_editor.getView()->Update( m_dependentDisplays[ii].get() );
3387 }
3388
3389 // The picked handles and the carried offset are fixed. Everything else in their
3390 // constraint clusters moves as little as the relations allow
3391 if( m_constraintSession && frameStep != VECTOR2I( 0, 0 ) )
3392 {
3393 std::vector<std::pair<CONSTRAINT_MEMBER, VECTOR2I>> pins;
3394 pins.reserve( m_constraintAnchors.size() );
3395
3396 const PCB_SHAPE* anchorShape = nullptr;
3397 std::vector<CONSTRAINT_ANCHOR_POINT> anchors;
3398
3399 // Take the position the behavior actually used, not the one the cursor asked
3400 // for, so a drag the behavior clamped stays clamped through the solve
3401 for( const auto& [shape, member] : m_constraintAnchors )
3402 {
3403 if( shape != anchorShape )
3404 {
3405 anchors = ConstraintShapeAnchors( shape );
3406 anchorShape = shape;
3407 }
3408
3409 for( const CONSTRAINT_ANCHOR_POINT& anchor : anchors )
3410 {
3411 if( anchor.anchor == member.m_anchor && anchor.index == member.m_index )
3412 {
3413 pins.emplace_back( member, anchor.pos );
3414 break;
3415 }
3416 }
3417 }
3418
3419 std::vector<PCB_SHAPE*> solverMoved;
3420
3421 auto stageNeighbor = [&]( BOARD_ITEM* aItem )
3422 {
3423 m_commit.Modify( aItem );
3424
3425 // A dimension that only re-measured is not reported as moved, so refresh
3426 // it here or it looks frozen until the drag ends
3427 if( aItem->Type() != PCB_SHAPE_T )
3428 aUpdated.push_back( aItem );
3429 };
3430
3431 CONSTRAINT_BLOCK_RESULT solveResult =
3432 m_constraintSession->Solve( pins, m_constraintTranslated, aDelta, &solverMoved, stageNeighbor );
3433
3434 if( solveResult == CONSTRAINT_BLOCK_RESULT::REFUSED )
3436
3437 for( PCB_SHAPE* neighbor : solverMoved )
3438 {
3439 aUpdated.push_back( neighbor );
3440
3441 // A shape the gesture carries or reshapes is already drawn with the block,
3442 // so only mark the ones the solve pulled along
3443 if( !neighbor->IsMoving() && !neighbor->IsBrightened() )
3444 {
3445 neighbor->SetBrightened();
3446 m_solverBrightened.insert( neighbor );
3447 }
3448 }
3449 }
3450
3451 return FRAME_RESULT::APPLIED;
3452}
3453
3454
3455bool BLOCK_DRAG_SESSION::Begin( const VECTOR2I& aOrigin, bool aPressInFlight )
3456{
3457 EDIT_POINTS* grabCollection = nullptr;
3458 EDIT_POINT* grabPoint = nullptr;
3459
3460 for( EDIT_POINTS* candidate : m_editor.pickableCollections() )
3461 {
3462 if( EDIT_POINT* found = candidate->FindPoint( aOrigin, m_editor.getView() ) )
3463 {
3464 if( !BlockDragHandlePickable( *candidate, *found ) )
3465 continue;
3466
3467 grabCollection = candidate;
3468 grabPoint = found;
3469 break;
3470 }
3471 }
3472
3473 if( !grabPoint )
3474 return false;
3475
3476 std::optional<PCB_HANDLE_KEY> grabKey = PCB_HANDLE_KEY::Make( *grabCollection, grabPoint );
3477
3478 if( !grabKey )
3479 return false;
3480
3481 std::set<PCB_HANDLE_KEY> priorPicks = m_editor.m_pickedHandles;
3482 bool grabPicked = m_editor.m_pickedHandles.count( *grabKey ) > 0;
3483
3484 // Put the picks back if the start is declined
3485 auto restorePicks = [&]() -> bool
3486 {
3487 m_editor.setPickedHandles( priorPicks );
3488 return false;
3489 };
3490
3491 auto refuse = [&]( const wxString& aMessage ) -> bool
3492 {
3493 m_editor.frame()->ShowInfoBarError( aMessage );
3494 m_refused = true;
3495
3496 // Only a mouse press has the rest of a button press left to ignore. A
3497 // keyboard start sets no flag here, so a refusal cannot eat the next click
3498 if( aPressInFlight )
3499 m_pressConsumed = true;
3500
3501 return restorePicks();
3502 };
3503
3504 if( grabCollection == m_editor.m_editPoints.get() )
3505 {
3506 // A lone object's handles keep the normal drag, unless the handle grabbed is
3507 // part of a bigger picked set
3508 if( !grabPicked || m_editor.m_pickedHandles.size() < 2 )
3509 return false;
3510 }
3511 else if( !grabPicked )
3512 {
3513 // Dragging a handle that is not picked picks just that one first
3514 std::set<PCB_HANDLE_KEY> picked = m_editor.m_pickedHandles;
3515
3516 BlockDragApplyPick( picked, *grabKey, false );
3517 m_editor.setPickedHandles( std::move( picked ) );
3518 }
3519
3520 // From here on the selection tool sees none of this drag, whether the gesture
3521 // starts or is refused, so stop its long press timer here
3522 m_editor.m_selectionTool->StopDisambiguation();
3523
3524 // Refuse the whole gesture, so no selected item is left out without the user knowing
3525 std::vector<BOARD_ITEM*> routerItems;
3526
3527 for( BOARD_ITEM* selectedItem : m_editor.m_expandedSelection )
3528 {
3529 BLOCK_DRAG_CAPABILITY capability = BlockDragCapability( *selectedItem );
3530
3531 if( capability == BLOCK_DRAG_CAPABILITY::UNSUPPORTED )
3532 {
3533 return refuse( wxString::Format( _( "%s cannot be dragged." ),
3534 selectedItem->GetItemDescription( m_editor.frame(), false ) ) );
3535 }
3536
3537 if( capability == BLOCK_DRAG_CAPABILITY::ROUTER )
3538 routerItems.push_back( selectedItem );
3539 }
3540
3541 m_origins = BlockDragMoveOrigins( m_editor.pickableCollections(), m_editor.m_pickedHandles );
3542
3543 if( m_origins.empty() || !collectTargets() )
3544 return restorePicks();
3545
3546 bool overrideLocksNow = m_editFrame->GetOverrideLocks();
3547
3548 for( auto& [targetPoints, behavior] : m_targets )
3549 {
3550 BOARD_ITEM* parent = static_cast<BOARD_ITEM*>( targetPoints->GetParent() );
3551
3552 if( ConstraintItemIsLocked( parent ) && !overrideLocksNow )
3553 return refuse( wxString::Format( _( "%s is locked. Enable 'Override locks' to move it." ),
3554 parent->GetItemDescription( m_editor.frame(), false ) ) );
3555 }
3556
3557 // A selected item with no picked handle travels whole, as it would under the move
3558 // tool. Picking says which handles stay with the cursor, selecting says what moves
3559 m_rigidItems.clear();
3560
3561 // The items taking part in the gesture. The dependent search skips these
3562 std::unordered_set<const BOARD_ITEM*> blockParticipants;
3563
3564 for( auto& [targetPoints, behavior] : m_targets )
3565 blockParticipants.insert( static_cast<BOARD_ITEM*>( targetPoints->GetParent() ) );
3566
3567 for( BOARD_ITEM* selectedItem : m_editor.m_expandedSelection )
3568 {
3569 // An item with a picked handle reshapes instead, and its lock was checked above
3570 if( blockParticipants.count( selectedItem ) )
3571 continue;
3572
3573 if( ConstraintItemIsLocked( selectedItem ) && !overrideLocksNow )
3574 {
3575 return refuse( wxString::Format( _( "%s is locked. Enable 'Override locks' to move it." ),
3576 selectedItem->GetItemDescription( m_editor.frame(), false ) ) );
3577 }
3578
3579 blockParticipants.insert( selectedItem );
3580
3581 // Copper travels in the router session. A footprint also travels whole on
3582 // the board side, and only its copper becomes router solids
3583 if( BlockDragCapability( *selectedItem ) == BLOCK_DRAG_CAPABILITY::ROUTER )
3584 {
3585 if( selectedItem->Type() == PCB_FOOTPRINT_T )
3586 m_rigidItems.push_back( selectedItem );
3587
3588 continue;
3589 }
3590
3591 m_rigidItems.push_back( selectedItem );
3592 }
3593
3594 // The ends of everything the block moves are the starting points for finding
3595 // graphics that should follow. A carried arc seeds from both of its ends
3596 std::vector<BLOCK_DRAG_ENDPOINT> movedEndpoints;
3597
3598 for( auto& [targetPoints, behavior] : m_targets )
3599 {
3600 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( targetPoints->GetParent() );
3601
3602 if( !shape || shape->GetShape() != SHAPE_T::SEGMENT )
3603 continue;
3604
3605 for( const auto& [key, origin] : m_origins )
3606 {
3607 if( key.Parent() != shape->m_Uuid || key.IsLine() )
3608 continue;
3609
3610 if( key.Index() == 0 || key.Index() == 1 )
3611 movedEndpoints.push_back( { shape, key.Index() == 0, origin } );
3612 }
3613 }
3614
3615 for( BOARD_ITEM* rigidItem : m_rigidItems )
3616 {
3617 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( rigidItem );
3618
3619 if( !shape )
3620 continue;
3621
3622 // A carried arc joins the chain at both of its ends, so selecting the arc of
3623 // a filleted corner keeps its far joint together
3624 if( shape->GetShape() != SHAPE_T::SEGMENT && shape->GetShape() != SHAPE_T::ARC )
3625 continue;
3626
3627 movedEndpoints.push_back( { shape, true, shape->GetStart(), BLOCK_DRAG_FOLLOW::WHOLE } );
3628 movedEndpoints.push_back( { shape, false, shape->GetEnd(), BLOCK_DRAG_FOLLOW::WHOLE } );
3629 }
3630
3631 m_dependents.clear();
3632
3633 if( !movedEndpoints.empty() )
3634 {
3635 std::vector<PCB_SHAPE*> candidates;
3636
3637 // An item the gesture already moves must not also be pulled by one endpoint
3638 auto addCandidate = [&]( BOARD_ITEM* aItem )
3639 {
3640 if( aItem->Type() != PCB_SHAPE_T )
3641 return;
3642
3643 if( blockParticipants.count( aItem ) )
3644 return;
3645
3646 candidates.push_back( static_cast<PCB_SHAPE*>( aItem ) );
3647 };
3648
3649 if( m_editor.m_isFootprintEditor )
3650 {
3651 if( FOOTPRINT* footprint = m_editor.board()->GetFirstFootprint() )
3652 {
3653 for( BOARD_ITEM* drawing : footprint->GraphicalItems() )
3654 addCandidate( drawing );
3655 }
3656 }
3657 else
3658 {
3659 for( BOARD_ITEM* drawing : m_editor.board()->Drawings() )
3660 addCandidate( drawing );
3661 }
3662
3663 if( BlockDragFindDependents( candidates, movedEndpoints, overrideLocksNow, m_dependents )
3665 {
3666 return refuse( _( "A locked connected item prevents the drag. Enable 'Override locks' to move it." ) );
3667 }
3668 }
3669
3670 // Undoing swaps in fresh footprint children, so a pad selected together with
3671 // its footprint gets a new object
3672 bool padOfCarriedFootprint = false;
3673
3674 // Start the router session after every refusal, so no refusal has to unwind it
3675 if( !routerItems.empty() )
3676 {
3677 ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>();
3678
3679 if( !routerTool || !routerTool->Router() || routerTool->IsToolActive()
3680 || routerTool->Router()->RoutingInProgress() )
3681 {
3682 return refuse( _( "The router is busy." ) );
3683 }
3684
3685 // The router tool only rebinds its interface when it is reset to run, so after
3686 // a board reload the borrowed interface still points at the old board
3687 routerTool->GetInterface()->SetBoard( m_editor.board() );
3688 routerTool->GetInterface()->SetView( m_editor.getView() );
3689
3690 PNS::ROUTER* router = routerTool->Router();
3691 router->SyncWorld();
3692
3693 PNS::NODE* world = router->GetWorld();
3694 PNS::ITEM_SET routerSet;
3695 std::set<PAD*> independentPads;
3696 std::unordered_set<FOOTPRINT*> carriedFootprints;
3697
3698 for( BOARD_ITEM* routerItem : routerItems )
3699 {
3700 if( routerItem->Type() == PCB_FOOTPRINT_T )
3701 carriedFootprints.insert( static_cast<FOOTPRINT*>( routerItem ) );
3702 }
3703
3704 for( BOARD_ITEM* routerItem : routerItems )
3705 {
3706 if( routerItem->Type() == PCB_FOOTPRINT_T )
3707 {
3708 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( routerItem );
3709
3710 // A footprint with no copper is not in the router world, so it
3711 // travels on the board side only
3712 for( PAD* pad : footprint->Pads() )
3713 {
3714 for( PNS::ITEM* solid : world->FindItemsByParent( pad ) )
3715 routerSet.Add( solid );
3716 }
3717
3718 for( ZONE* zone : footprint->Zones() )
3719 {
3720 for( PNS::ITEM* solid : world->FindItemsByParent( zone ) )
3721 routerSet.Add( solid );
3722 }
3723
3724 for( BOARD_ITEM* graphic : footprint->GraphicalItems() )
3725 {
3726 if( graphic->GetLayer() == Edge_Cuts || graphic->GetLayer() == Margin
3727 || IsCopperLayer( graphic->GetLayer() ) )
3728 {
3729 for( PNS::ITEM* solid : world->FindItemsByParent( graphic ) )
3730 routerSet.Add( solid );
3731 }
3732 }
3733
3734 continue;
3735 }
3736
3737 if( routerItem->Type() == PCB_PAD_T )
3738 {
3739 PAD* pad = static_cast<PAD*>( routerItem );
3740
3741 if( carriedFootprints.count( pad->GetParentFootprint() ) )
3742 {
3743 padOfCarriedFootprint = true;
3744 continue;
3745 }
3746
3747 // A normal move turns a lone pad into its whole footprint unless free
3748 // pads are allowed, and a block cannot carry an unselected footprint
3749 if( !m_editor.frame()->GetPcbNewSettings()->m_AllowFreePads )
3750 {
3751 return refuse( wxString::Format( _( "%s cannot be dragged." ),
3752 pad->GetItemDescription( m_editor.frame(), false ) ) );
3753 }
3754
3755 // The solver only moves a pad with its footprint, so it cannot follow one the router moves alone
3757 {
3758 return refuse( wxString::Format( _( "%s cannot be dragged." ),
3759 pad->GetItemDescription( m_editor.frame(), false ) ) );
3760 }
3761
3762 // Keeps the router from moving the pad's whole footprint
3763 independentPads.insert( pad );
3764 }
3765
3766 std::vector<PNS::ITEM*> pnsItems = world->FindItemsByParent( routerItem );
3767
3768 if( pnsItems.empty() )
3769 {
3770 return refuse( wxString::Format( _( "%s cannot be dragged." ),
3771 routerItem->GetItemDescription( m_editor.frame(), false ) ) );
3772 }
3773
3774 for( PNS::ITEM* pnsItem : pnsItems )
3775 routerSet.Add( pnsItem );
3776 }
3777
3778 // A generator moves its copper on the board side, so the router world has to
3779 // move the same copper. Otherwise the router reroutes stale copies over it
3780 for( BOARD_ITEM* rigidItem : m_rigidItems )
3781 {
3782 if( rigidItem->Type() != PCB_GENERATOR_T )
3783 continue;
3784
3785 for( BOARD_ITEM* member : static_cast<PCB_GENERATOR*>( rigidItem )->GetBoardItems() )
3786 {
3787 for( PNS::ITEM* pnsItem : world->FindItemsByParent( member ) )
3788 routerSet.Add( pnsItem );
3789 }
3790 }
3791
3792 if( routerSet.Size() > 0 )
3793 {
3794 routerTool->GetInterface()->SetIndependentPads( independentPads );
3795
3796 if( !router->StartDragging( grabPoint->GetPosition(), routerSet, PNS::DM_BLOCK ) )
3797 {
3798 routerTool->GetInterface()->SetIndependentPads( {} );
3799 return refuse( _( "The copper in the selection cannot be dragged." ) );
3800 }
3801
3802 m_routerActive = true;
3803
3804 // The dragger leaves an arc with both ends pinned where it is. Name those for
3805 // the user, the way the router tool's own drag does, and keep them for the
3806 // hiding below
3807 std::set<KIID> blockAnchoredCopper;
3808
3809 if( auto* blockDragger = dynamic_cast<PNS::BLOCK_DRAGGER*>( router->GetDragger() ) )
3810 {
3811 const std::vector<PNS::LINE>& held = blockDragger->AnchoredLines();
3812
3813 if( !held.empty() )
3814 {
3815 m_editor.frame()->ShowInfoBarWarning( wxString::Format(
3816 wxPLURAL( "%zu selected arc cannot move because both ends are fixed.",
3817 "%zu selected arcs cannot move because both ends are fixed.", held.size() ),
3818 held.size() ) );
3819 }
3820
3821 for( const PNS::LINE& line : held )
3822 {
3823 for( const PNS::LINKED_ITEM* link : line.Links() )
3824 {
3825 if( const BOARD_ITEM* parent = link->Parent() )
3826 blockAnchoredCopper.insert( parent->m_Uuid );
3827 }
3828 }
3829 }
3830
3831 // The router keeps carried copper at its board position until the route is
3832 // fixed, and the selection overlay paints a selected item from that position.
3833 // Hide the overlay copy while the router preview stands in for it. The overlay
3834 // flag only takes effect while the item is still visible, and the first move
3835 // below hides it
3836 for( BOARD_ITEM* routerItem : routerItems )
3837 {
3838 if( routerItem->Type() == PCB_FOOTPRINT_T )
3839 continue;
3840
3841 // An arc the dragger anchored gets no preview, so hiding it would leave
3842 // it drawn by nobody until the gesture ends
3843 if( blockAnchoredCopper.count( routerItem->m_Uuid ) )
3844 continue;
3845
3846 m_editor.getView()->Hide( routerItem, true, true );
3847 m_overlayHidden.push_back( routerItem->m_Uuid );
3848 }
3849
3850 // The first move hands the carried copper over to the router preview, so
3851 // the first snap cannot land on copper that is about to move
3852 router->Move( grabPoint->GetPosition(), nullptr );
3853 }
3854 }
3855
3856 m_refParent = static_cast<BOARD_ITEM*>( grabCollection->GetParent() );
3857 m_refGrid = m_grid.GetItemGrid( m_refParent );
3858 m_snapConstraint = grabPoint->GetSnapConstraint();
3859 m_grabStart = grabPoint->GetPosition();
3860
3861 // Keep everything that moves with the cursor out of the snap targets, the
3862 // way the move tool does, or the block chases its own geometry
3864
3865 for( auto& [targetPoints, behavior] : m_targets )
3866 {
3867 EDA_ITEM* parent = targetPoints->GetParent();
3868 m_moving.push_back( static_cast<BOARD_ITEM*>( parent ) );
3869 m_commit.Modify( parent );
3870 }
3871
3872 for( BOARD_ITEM* rigidItem : m_rigidItems )
3873 {
3874 // A generator moves its members with it, so each member needs its own undo copy
3875 m_commit.Modify( rigidItem, nullptr, RECURSE_MODE::RECURSE );
3876 }
3877
3878 m_dependentDisplays.clear();
3879
3880 for( const BLOCK_DRAG_ENDPOINT& dep : m_dependents )
3881 {
3882 m_commit.Modify( dep.shape );
3883
3884 // A segment joined to the block at both ends shows up twice
3885 if( std::find( m_moving.begin(), m_moving.end(), dep.shape ) == m_moving.end() )
3886 m_moving.push_back( dep.shape );
3887
3888 std::shared_ptr<EDIT_POINTS> display = std::make_shared<EDIT_POINTS>( dep.shape );
3889 display->AddPoint( dep.position );
3890 display->Point( 0 ).SetDependent();
3891 m_editor.getView()->Add( display.get() );
3892 m_dependentDisplays.push_back( std::move( display ) );
3893 }
3894
3895 // Flag them from the same list the release clears, so the two always match
3896 for( BOARD_ITEM* moving : m_moving )
3897 {
3898 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( moving ) )
3899 {
3900 shape->SetFlags( IS_MOVING );
3901 shape->UpdateHatching();
3902 }
3903 }
3904
3905 // The solver can move an item that shares a constraint but was never dragged, so
3906 // validation has to watch it. Keep it out of the moving set, which is what lets it
3907 // stay a snap target
3908 std::vector<BOARD_ITEM*> validationScope = m_moving;
3909
3910 // Everything the gesture writes is fixed for the solver. A picked handle ends where
3911 // the user put it and a carried item ends at its own offset, while the rest of their
3912 // constraint clusters is free to move
3913 if( BoardHasConstraints( m_editor.board() ) )
3914 {
3915 std::vector<BOARD_ITEM*> blockConstrainedItems;
3916 std::unordered_set<const BOARD_ITEM*> seeded;
3917
3918 auto seedConstrained = [&]( BOARD_ITEM* aItem )
3919 {
3920 if( !IsConstrainableItem( aItem ) || !seeded.insert( aItem ).second )
3921 return;
3922
3923 if( BlockDragIsConstraintMember( *aItem ) )
3924 blockConstrainedItems.push_back( aItem );
3925 };
3926
3927 for( auto& [targetPoints, behavior] : m_targets )
3928 {
3929 PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( targetPoints->GetParent() );
3930
3931 if( !shape )
3932 continue;
3933
3934 for( const auto& [key, origin] : m_origins )
3935 {
3936 if( key.Parent() != shape->m_Uuid )
3937 continue;
3938
3939 EDIT_POINT* picked = key.Resolve( *targetPoints );
3940
3941 if( !picked )
3942 continue;
3943
3944 if( std::optional<CONSTRAINT_MEMBER> member =
3945 constraintMemberForEditPoint( shape, targetPoints, picked ) )
3946 {
3947 m_constraintAnchors.emplace_back( shape, *member );
3948 }
3949 }
3950
3951 seedConstrained( shape );
3952 }
3953
3954 // A carried container moves its graphics with it, so pin their offset too, or
3955 // the solve pulls them back out of the container
3956 std::unordered_set<BOARD_ITEM*> walked;
3957
3958 std::function<void( BOARD_ITEM* )> carryWhole = [&]( BOARD_ITEM* aItem )
3959 {
3960 if( !aItem || !walked.insert( aItem ).second )
3961 return;
3962
3963 m_constraintTranslated.insert( aItem->m_Uuid );
3964 seedConstrained( aItem );
3965 aItem->RunOnChildren( carryWhole, RECURSE_MODE::NO_RECURSE );
3966 };
3967
3968 for( BOARD_ITEM* rigidItem : m_rigidItems )
3969 carryWhole( rigidItem );
3970
3971 for( const BLOCK_DRAG_ENDPOINT& dep : m_dependents )
3972 {
3973 // The gesture moves a whole arc by the block offset, so the solver must carry all of it
3974 if( dep.follow == BLOCK_DRAG_FOLLOW::WHOLE )
3975 {
3976 carryWhole( dep.shape );
3977 continue;
3978 }
3979
3980 // The gesture already placed it, so it pins its joint and does not move again
3982
3983 m_constraintAnchors.emplace_back( dep.shape, CONSTRAINT_MEMBER( dep.shape->m_Uuid, anchor ) );
3984 seedConstrained( dep.shape );
3985 }
3986
3987 if( !blockConstrainedItems.empty() )
3988 {
3989 m_constraintSession.emplace();
3990
3991 if( !m_constraintSession->Build( m_editor.board(), blockConstrainedItems ) )
3992 m_constraintSession.reset();
3993 }
3994 }
3995
3996 blockDragAppendConstraintCoMembers( m_editor.board(), validationScope );
3997
3998 m_validation.emplace( *m_editor.board() );
3999 m_validation->CaptureBaseline( validationScope );
4000
4001 m_appliedDelta = VECTOR2I( 0, 0 );
4002 m_revertRestarts = padOfCarriedFootprint;
4003
4004 if( !m_editor.m_isFootprintEditor )
4005 {
4006 // Use the wider scope, because the solver reaches items the gesture never
4007 // touched, and undoing a footprint child gives that footprint all new
4008 // children, which leaves every pointer held here dead
4009 for( BOARD_ITEM* moving : validationScope )
4010 {
4011 if( moving->GetParentFootprint() )
4012 m_revertRestarts = true;
4013 }
4014 }
4015
4016 // The block is not a single point edit, so the grabbed item's own geometry
4017 // must not act as a snap target
4018 m_grid.SetPointEditProfile( false );
4019 m_editor.frame()->UndoRedoBlock( true );
4020 m_editor.getViewControls()->SetAutoPan( true );
4021 m_active = true;
4022
4023 // A start with no button down is the keyboard one, which the cursor then follows freely
4024 m_keyboardDrag = !aPressInFlight;
4025 m_editor.m_blockDragAbort = [this]()
4026 {
4027 Abort();
4028 };
4029 return true;
4030}
4031
4032
4034{
4035 if( !m_editor.blockAnchorEditingEnabled() )
4036 return false;
4037
4038 int modifiers = aEvent.Modifier( MD_SHIFT | MD_CTRL | MD_ALT );
4039
4040 if( modifiers != 0 && modifiers != MD_SHIFT )
4041 return false;
4042
4043 bool anyPickable = false;
4044
4045 for( EDIT_POINTS* candidate : m_editor.pickableCollections() )
4046 {
4047 if( candidate->FindPoint( aEvent.DragOrigin(), m_editor.getView() ) )
4048 return false;
4049
4050 if( anyPickable )
4051 continue;
4052
4053 for( unsigned ii = 0; ii < candidate->PointsSize(); ++ii )
4054 {
4055 if( BlockDragHandlePickable( *candidate, candidate->Point( ii ) ) )
4056 {
4057 anyPickable = true;
4058 break;
4059 }
4060 }
4061 }
4062
4063 if( !anyPickable )
4064 return false;
4065
4066 // Only empty canvas starts the gesture. A drag on an item still moves it
4067 return !m_editor.m_selectionTool->SelectionContains( aEvent.DragOrigin() );
4068}
4069
4070
4072{
4073 KIGFX::RENDER_SETTINGS* settings = m_editor.getView()->GetPainter()->GetSettings();
4074 KIGFX::COLOR4D color = settings->GetLayerColor( LAYER_AUX_ITEMS );
4075
4076 if( m_editor.getView()->GetGAL()->GetClearColor().Distance( color ) < 0.5 )
4077 color.Invert();
4078
4079 return color;
4080}
4081
4082
4083void BLOCK_DRAG_SESSION::showBand( HANDLE_PICK_AREA& aArea )
4084{
4085 // The selection tool never sees this drag, so stop its long press timer here
4086 m_editor.m_selectionTool->StopDisambiguation();
4087
4088 KIGFX::COLOR4D color = bandColor();
4089
4090 aArea.SetStrokeColor( color.WithAlpha( 0.9 ) );
4091 aArea.SetFillColor( color.WithAlpha( 0.15 ) );
4092 m_editor.getView()->Add( &aArea );
4093 m_editor.getView()->SetVisible( &aArea, true );
4094 m_editor.getViewControls()->SetAutoPan( true );
4095}
4096
4097
4098void BLOCK_DRAG_SESSION::hideBand( HANDLE_PICK_AREA& aArea )
4099{
4100 m_editor.getViewControls()->SetAutoPan( false );
4101 m_editor.getView()->SetVisible( &aArea, false );
4102 m_editor.getView()->Remove( &aArea );
4103}
4104
4105
4107{
4108 KIGFX::VIEW* view = m_editor.getView();
4109 HANDLE_PICK_AREA area;
4110
4111 showBand( area );
4112
4113 // aEvent points at the tool's one event slot, which every Wait() below overwrites
4114 bool accumulate = aEvent.Modifier( MD_SHIFT ) != 0;
4115 bool finished = false;
4116 bool exitLoop = false;
4117
4118 SHAPE_LINE_CHAIN points;
4119 points.SetClosed( true );
4120 points.Append( aEvent.DragOrigin() );
4121
4122 while( TOOL_EVENT* lassoEvt = m_editor.Wait() )
4123 {
4124 if( lassoEvt->IsCancelInteractive() )
4125 {
4126 lassoEvt->SetPassEvent( false );
4127 break;
4128 }
4129 else if( lassoEvt->IsActivate() )
4130 {
4131 // Pass it on so the new tool starts, as a normal handle drag does
4132 exitLoop = !lassoEvt->IsMoveTool();
4133 break;
4134 }
4135 else if( lassoEvt->IsSelectionEvent() || lassoEvt->Matches( EVENTS::InhibitSelectionEditing ) )
4136 {
4137 exitLoop = true;
4138 break;
4139 }
4140 else if( lassoEvt->IsDrag( BUT_LEFT ) || lassoEvt->IsClick( BUT_LEFT )
4141 || lassoEvt->IsAction( &ACTIONS::cursorClick ) )
4142 {
4143 points.Append( lassoEvt->Position() );
4144 }
4145 else if( lassoEvt->IsDblClick( BUT_LEFT ) || lassoEvt->IsAction( &ACTIONS::cursorDblClick )
4146 || lassoEvt->IsAction( &ACTIONS::finishInteractive ) )
4147 {
4148 finished = true;
4149 lassoEvt->SetPassEvent( false );
4150 break;
4151 }
4152 else if( lassoEvt->IsAction( &ACTIONS::deleteLastPoint ) || lassoEvt->IsAction( &ACTIONS::doDelete )
4153 || lassoEvt->IsAction( &ACTIONS::undo ) )
4154 {
4155 if( points.GetPointCount() > 0 )
4156 {
4157 m_editor.getViewControls()->SetCursorPosition( points.CLastPoint() );
4158 points.Remove( points.GetPointCount() - 1 );
4159 }
4160 }
4161 else
4162 {
4163 // Never pass a mouse down on, it would arm the long press timer again
4164 blockDragPassNavigation( lassoEvt );
4165 }
4166
4167 area.SetPoly( points );
4168 area.GetPoly().Append( m_editor.m_toolMgr->GetMousePosition() );
4169 view->Update( &area );
4170 }
4171
4172 hideBand( area );
4173
4174 if( finished )
4175 {
4176 std::set<PCB_HANDLE_KEY> picked = m_editor.m_pickedHandles;
4177
4178 BlockDragLassoPick( m_editor.pickableCollections(), points, accumulate, picked );
4179 m_editor.setPickedHandles( std::move( picked ) );
4180 }
4181
4182 return exitLoop;
4183}
4184
4185
4187{
4188 KIGFX::VIEW* view = m_editor.getView();
4189
4190 // aEvent points at the tool's one event slot, which every Wait() below
4191 // overwrites, so copy out everything needed from it now
4192 VECTOR2I origin = aEvent.DragOrigin();
4193 VECTOR2I end = aEvent.Position();
4194 bool accumulate = aEvent.Modifier( MD_SHIFT ) != 0;
4195 bool released = false;
4196 bool exitLoop = false;
4197
4198 HANDLE_PICK_AREA area;
4199 area.SetPoly( BlockDragPickRect( origin, end ) );
4200
4201 showBand( area );
4202
4203 while( TOOL_EVENT* boxEvt = m_editor.Wait() )
4204 {
4205 if( boxEvt->IsCancelInteractive() )
4206 {
4207 boxEvt->SetPassEvent( false );
4208 break;
4209 }
4210 else if( boxEvt->IsActivate() )
4211 {
4212 exitLoop = !boxEvt->IsMoveTool();
4213 break;
4214 }
4215 else if( boxEvt->IsSelectionEvent() || boxEvt->Matches( EVENTS::InhibitSelectionEditing ) )
4216 {
4217 exitLoop = true;
4218 break;
4219 }
4220 else if( boxEvt->IsDrag( BUT_LEFT ) )
4221 {
4222 end = boxEvt->Position();
4223 area.SetPoly( BlockDragPickRect( origin, end ) );
4224 view->Update( &area );
4225 }
4226 else if( boxEvt->IsMouseUp( BUT_LEFT ) )
4227 {
4228 released = true;
4229 break;
4230 }
4231 else
4232 {
4233 // Never pass a mouse down on, it would arm the long press timer again
4234 blockDragPassNavigation( boxEvt );
4235 }
4236 }
4237
4238 hideBand( area );
4239
4240 if( released )
4241 {
4242 std::set<PCB_HANDLE_KEY> picked = m_editor.m_pickedHandles;
4243
4244 BlockDragLassoPick( m_editor.pickableCollections(), BlockDragPickRect( origin, end ), accumulate, picked );
4245 m_editor.setPickedHandles( std::move( picked ) );
4246 }
4247
4248 return exitLoop;
4249}
4250
4251
4253{
4255 LSET snapLayers;
4256
4257 switch( m_snapConstraint )
4258 {
4259 case IGNORE_SNAPS: break;
4260 case OBJECT_LAYERS: snapLayers = m_refParent->GetLayerSet(); break;
4261 case ALL_LAYERS: snapLayers = LSET::AllLayersMask(); break;
4262 }
4263
4264 VECTOR2I snapped =
4265 m_grid.ResolveSnap( pos, snapLayers, m_refGrid, m_moving, m_grabStart + m_appliedDelta ).position;
4266 VECTOR2I delta = snapped - m_grabStart;
4267 VECTOR2I accepted = m_appliedDelta;
4268
4269 // Ctrl while moving does what it does in a single point drag, which is to
4270 // change how a polygon or zone edge behaves. Ctrl at the release is the
4271 // router's force placement, so the two are read at different times
4272 POLYGON_LINE_MODE edgeMode =
4274
4275 for( const auto& [key, origin] : m_origins )
4276 {
4277 if( !key.IsLine() )
4278 continue;
4279
4280 for( EDIT_POINTS* collection : m_editor.pickableCollections() )
4281 {
4282 EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( key.Resolve( *collection ) );
4283
4284 if( !line )
4285 continue;
4286
4287 if( POLYGON_EDGE_DRAG_POLICY* policy = line->GetDragPolicy() )
4288 {
4289 if( policy->GetMode() != edgeMode )
4290 policy->SetMode( edgeMode );
4291 }
4292
4293 break;
4294 }
4295 }
4296
4297 std::vector<EDA_ITEM*> updatedItems;
4298 FRAME_RESULT frameResult = applyFrame( delta, updatedItems );
4299
4300 if( frameResult == FRAME_RESULT::CONSTRAINED )
4301 {
4302 // Say it once, not once per frame, because the block keeps resisting for as
4303 // long as the cursor stays somewhere with no solution
4304 if( !m_constraintWarned )
4305 {
4306 m_editor.frame()->ShowInfoBarError( _( "The move would break a geometric constraint." ) );
4307 m_constraintWarned = true;
4308 }
4309
4310 m_grid.ClearSnapFeedback();
4311
4312 frameResult = applyFrame( accepted, updatedItems ) == FRAME_RESULT::LOST_IDENTITY ? FRAME_RESULT::LOST_IDENTITY
4314 }
4315
4316 if( frameResult == FRAME_RESULT::LOST_IDENTITY )
4317 {
4318 // A picked handle has gone mid gesture. Put the geometry back and let the
4319 // rest of this button press pass, so the user does not start a new gesture
4320 // from an empty pick set. Read the flag before the teardown clears it
4321 bool pressInFlight = !m_keyboardDrag;
4322
4323 if( revert( false ) )
4324 return true;
4325
4326 endDrag( false );
4327 m_pressConsumed = pressInFlight;
4328 }
4329 else
4330 {
4331 for( EDA_ITEM* updatedItem : updatedItems )
4332 m_editor.getView()->Update( updatedItem );
4333
4334 if( m_routerActive && m_appliedDelta != accepted )
4335 {
4336 if( ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>() )
4337 routerTool->Router()->Move( m_grabStart + m_appliedDelta, nullptr );
4338 }
4339
4340 // Say it while the cursor is still down, so the user hears why before the
4341 // release throws the gesture away
4342 if( m_routerActive )
4343 {
4344 ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>();
4345 PNS::DRAG_ALGO* dragger = routerTool ? routerTool->Router()->GetDragger() : nullptr;
4346 bool dragStatus = true;
4347
4348 // When the router is set to allow violations the release takes them anyway,
4349 // so a DRC warning here would ask the user for a Ctrl they do not need
4350 bool allowed = routerTool && routerTool->Router()->Settings().AllowDRCViolations();
4351
4352 m_editor.getView()->ClearPreview();
4353
4354 if( !allowed && dragger && dragger->GetForceMarkObstaclesMode( &dragStatus ) && !dragStatus )
4355 {
4356 wxString hint;
4357 hint.Printf( _( "(%s to commit anyway.)" ), KeyNameFromKeyCode( MD_CTRL + PSEUDO_WXK_CLICK ) );
4358
4360 statusItem->SetMessage( _( "The move violates DRC." ) );
4361 statusItem->SetHint( hint );
4362 statusItem->SetPosition( m_editor.m_toolMgr->GetMousePosition() );
4363 m_editor.getView()->AddToPreview( statusItem );
4364 }
4365 }
4366
4367 m_editor.getViewControls()->ForceCursorPosition( true, m_grabStart + m_appliedDelta );
4368 m_editor.updatePoints();
4369 }
4370
4371 return false;
4372}
4373
4374
4375bool BLOCK_DRAG_SESSION::refuseRelease( const wxString& aMessage )
4376{
4377 m_editor.frame()->ShowInfoBarError( aMessage );
4378
4379 if( revert( false ) )
4380 return true;
4381
4382 endDrag( true );
4383 return false;
4384}
4385
4386
4388{
4389 // This click stops here, so the selection tool only ever sees the press that
4390 // armed its long press timer
4391 m_editor.m_selectionTool->StopDisambiguation();
4392
4393 if( m_appliedDelta == VECTOR2I( 0, 0 ) )
4394 {
4395 // A gesture that changed nothing leaves no undo entry
4396 if( revert( false ) )
4397 return true;
4398
4399 endDrag( true );
4400 }
4401 else
4402 {
4403 auto originResolves = [&]( const std::pair<const PCB_HANDLE_KEY, VECTOR2I>& aOrigin )
4404 {
4405 return std::ranges::any_of( m_targets,
4406 [&]( const auto& aTarget )
4407 {
4408 return aOrigin.first.Resolve( *aTarget.first ) != nullptr;
4409 } );
4410 };
4411
4412 // A picked handle gone by now would leave part of the block unfinalized
4413 if( !collectTargets() || !std::ranges::all_of( m_origins, originResolves ) )
4414 {
4415 if( revert( false ) )
4416 return true;
4417
4418 endDrag( false );
4419 return false;
4420 }
4421
4422 // Finalize first, so the geometry that was checked is the geometry that goes in
4423 for( auto& [targetPoints, behavior] : m_targets )
4424 behavior->FinalizeItem( *targetPoints, m_commit );
4425
4426 BLOCK_DRAG_VALIDATION_RESULT validationResult = m_validation->Validate();
4427
4428 std::vector<ZONE*> zonesToFill;
4429
4430 auto appendFillZone = [&]( EDA_ITEM* aItem )
4431 {
4432 if( aItem->Type() != PCB_ZONE_T )
4433 return;
4434
4435 // A rule area has no fill, and filling nothing still rebuilds connectivity
4436 // and every zone's caches
4437 if( !static_cast<ZONE*>( aItem )->GetIsRuleArea() )
4438 zonesToFill.push_back( static_cast<ZONE*>( aItem ) );
4439 };
4440
4441 // The collections were just resolved, and the footprint editor does no zone filling
4442 if( !m_editor.m_isFootprintEditor )
4443 {
4444 for( auto& [targetPoints, behavior] : m_targets )
4445 appendFillZone( targetPoints->GetParent() );
4446
4447 for( BOARD_ITEM* rigidItem : m_rigidItems )
4448 appendFillZone( rigidItem );
4449 }
4450
4451 bool routerSessionOk = true;
4452 bool routerStatusOk = true;
4453 bool forceCommit = aEvent.Modifier( MD_CTRL );
4454
4455 if( m_routerActive )
4456 {
4457 ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>();
4458 PNS::DRAG_ALGO* dragger = routerTool ? routerTool->Router()->GetDragger() : nullptr;
4459
4460 if( !dragger )
4461 routerSessionOk = false;
4462 else if( routerTool->Router()->Settings().AllowDRCViolations() )
4463 routerStatusOk = true;
4464 else
4465 dragger->GetForceMarkObstaclesMode( &routerStatusOk );
4466 }
4467
4468 if( validationResult != BLOCK_DRAG_VALIDATION_RESULT::OK )
4469 {
4471 ? _( "The move would break a zone outline." )
4472 : _( "The move would break the board outline." ) ) )
4473 {
4474 return true;
4475 }
4476 }
4477 else if( !routerSessionOk || ( !routerStatusOk && !forceCommit ) )
4478 {
4479 // Forced placement skips the collision refusal and nothing else
4481 return true;
4482 }
4483 else
4484 {
4485 wxString label;
4486
4487 if( m_routerActive || !m_rigidItems.empty() || !m_dependents.empty() || m_targets.size() > 1 )
4488 label = _( "Drag block" );
4489 else
4490 label = m_origins.size() > 1 ? _( "Move Points" ) : _( "Move Point" );
4491
4492 // The carried changes name the undo entry, and the router and the fill add to
4493 // it. Only the gesture's last push may arm the refill scheduler. An earlier one
4494 // would run a fill, a connectivity rebuild and maybe a progress dialog inside
4495 // that push, while the router drag is still live
4496 m_commit.Push( label, m_routerActive ? ZONE_FILL_OP : 0 );
4497
4498 bool routerCommitted = true;
4499
4500 if( m_routerActive )
4501 {
4502 ROUTER_TOOL* routerTool = m_editor.m_toolMgr->GetTool<ROUTER_TOOL>();
4503 routerCommitted = false;
4504
4505 if( routerTool )
4506 {
4507 routerTool->GetInterface()->SetCommitFlags( APPEND_UNDO );
4508 routerCommitted = routerTool->Router()->FixRoute( VECTOR2I(), nullptr, false, forceCommit );
4509 routerTool->GetInterface()->SetCommitFlags( 0 );
4510 }
4511 }
4512
4513 if( !routerCommitted )
4514 {
4515 m_editor.frame()->ShowInfoBarError( blockDragDrcRefusal() );
4516
4517 if( revert( true ) )
4518 return true;
4519 }
4520 else if( !zonesToFill.empty() && m_routerActive && m_editFrame->GetPcbNewSettings()->m_AutoRefillZones )
4521 {
4522 // Dragging an outline leaves its zone unfilled. The router suppresses the
4523 // automatic refill, so do it here instead. With the refill off, nothing refills
4524 BOARD_COMMIT fillCommit( m_editFrame );
4525 ZONE_FILLER filler( m_editor.board(), &fillCommit );
4526
4527 if( filler.Fill( zonesToFill ) )
4528 {
4529 m_editor.board()->OnZonesFilled( zonesToFill );
4530
4531 if( ZONE_FILLER_TOOL* zoneFillerTool = m_editor.m_toolMgr->GetTool<ZONE_FILLER_TOOL>() )
4532 zoneFillerTool->RegenerateDirtyGenerators( fillCommit );
4533
4534 fillCommit.Push( label, APPEND_UNDO | ZONE_FILL_OP );
4535 }
4536 else
4537 {
4538 // The gesture's undo entry holds a copy of every zone the fill touched from
4539 // before the drag, so one undo takes the fill out along with the move
4540 m_editor.frame()->ShowInfoBarError( _( "Zone fill failed, the move was undone." ) );
4541
4542 if( revert( true ) )
4543 return true;
4544 }
4545 }
4546
4547 // A reshaped generator keeps its members where they were while the drag
4548 // runs and re-places them once the outline is final, as Move() leaves them
4549 // for the next Update(). It comes after the router's push, so the router
4550 // never meets a via this replaces, and joins the same undo entry. A revert
4551 // above has already ended the gesture
4552 if( GENERATOR_TOOL* genTool = m_active ? m_editor.m_toolMgr->GetTool<GENERATOR_TOOL>() : nullptr )
4553 {
4554 BOARD_COMMIT genCommit( m_editFrame );
4555 bool regenerated = false;
4556
4557 // A reshaped one is dirty from its handles, a carried one from Move()
4558 for( BOARD_ITEM* moving : m_moving )
4559 {
4560 if( moving->Type() != PCB_GENERATOR_T )
4561 continue;
4562
4563 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( moving );
4564
4565 if( !gen->IsDirty() )
4566 continue;
4567
4568 gen->EditStart( genTool, m_editor.board(), &genCommit );
4569 gen->Update( genTool, m_editor.board(), &genCommit );
4570 gen->EditFinish( genTool, m_editor.board(), &genCommit );
4571 regenerated = true;
4572 }
4573
4574 if( regenerated )
4575 genCommit.Push( label, APPEND_UNDO | ZONE_FILL_OP );
4576 }
4577
4578 endDrag( true );
4579 }
4580 }
4581
4582 return false;
4583}
4584
4585
4587{
4588 // Escape cancels the gesture and nothing else. The picks and the object
4589 // selection stay, and the rest of this button press is ignored. A tool
4590 // switch and the other ways of cancelling keep their usual effect
4591 bool escape = aEvent.IsCancel() && aEvent.GetCommandId() == (int) WXK_ESCAPE;
4592
4593 // Read the flag before the teardown clears it
4594 bool pressInFlight = !m_keyboardDrag;
4595
4596 if( escape )
4597 aEvent.SetPassEvent( false );
4598
4599 if( revert( false ) )
4600 return true;
4601
4602 endDrag( escape );
4603
4604 if( escape )
4605 m_pressConsumed = pressInFlight;
4606
4607 return false;
4608}
4609
4610
4612{
4614 return 0;
4615
4617 return 0;
4618
4620
4622 const PCB_SELECTION& selection = m_selectionTool->GetSelection();
4623
4624 if( selection.Size() == 0 )
4625 return 0;
4626
4627 for( EDA_ITEM* selItem : selection )
4628 {
4629 if( selItem->GetEditFlags() || !selItem->IsBOARD_ITEM() )
4630 return 0;
4631 }
4632
4633 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
4634 bool overrideLocks = editFrame->GetOverrideLocks();
4635
4636 // A locked item at the front of the selection would hide the handles of everything
4637 // else. With block handles the per item test refuses the drag by name, which tells
4638 // the user which item is in the way
4639 bool blockHandlesPossible = selection.Size() > 1 && blockAnchorEditingEnabled();
4640
4641 if( !item || ( item->IsLocked() && !overrideLocks && !blockHandlesPossible ) )
4642 return 0;
4643
4644 Activate();
4645 // Must be done after Activate() so that it gets set into the correct context
4646 getViewControls()->ShowCursor( true );
4647
4649 grid.SetPointEditProfile( true );
4651
4652 // Use the original object as a construction item
4653 std::vector<std::unique_ptr<BOARD_ITEM>> clones;
4654
4655 m_editorBehavior.reset();
4656
4657 if( selection.Size() > 1 )
4658 {
4659 // Multi-selection: check if all items are shapes
4660 std::vector<PCB_SHAPE*> shapes;
4661 std::set<KIID> shapeIds;
4662 bool allShapes = true;
4663 bool anyLocked = false;
4664
4665 for( EDA_ITEM* selItem : selection )
4666 {
4667 if( selItem->Type() == PCB_SHAPE_T )
4668 {
4669 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( selItem );
4670 shapes.push_back( shape );
4671 shapeIds.insert( shape->m_Uuid );
4672
4673 if( shape->IsLocked() )
4674 anyLocked = true;
4675 }
4676 else
4677 {
4678 allShapes = false;
4679 }
4680 }
4681
4682 std::vector<VECTOR2I> pinned;
4683
4684 if( allShapes && shapes.size() > 1 )
4685 pinned = ConstraintPinnedPositions( board(), shapeIds );
4686
4687 // Two pins in different places leave a scale no fixed point to work from
4688 if( allShapes && shapes.size() > 1 && ( !anyLocked || overrideLocks ) && pinned.size() < 2 )
4689 {
4690 std::optional<VECTOR2I> pin;
4691
4692 if( !pinned.empty() )
4693 pin = pinned.front();
4694
4695 std::unique_ptr<SHAPE_GROUP_POINT_EDIT_BEHAVIOR> groupBehavior =
4696 std::make_unique<SHAPE_GROUP_POINT_EDIT_BEHAVIOR>( std::move( shapes ), item, pin );
4697 groupBehavior->SetInflation( bboxHandleInflation() );
4698 m_editorBehavior = std::move( groupBehavior );
4699 m_editPoints = std::make_shared<EDIT_POINTS>( item );
4700 m_editPoints->SetLineStateVisible( blockAnchorEditingEnabled() );
4701 m_editorBehavior->MakePoints( *m_editPoints );
4702 }
4703 }
4704 else
4705 {
4706 // Single selection: use existing makePoints logic
4707 m_editPoints = makePoints( item );
4708 }
4709
4712
4713 if( !m_editPoints && m_blockHandles.empty() )
4714 return 0;
4715
4716 PCB_SHAPE* graphicItem = dynamic_cast<PCB_SHAPE*>( item );
4717
4718 // Only add the angle_item if we are editing a polygon or zone
4719 if( m_editPoints && ( item->Type() == PCB_ZONE_T || ( graphicItem && graphicItem->GetShape() == SHAPE_T::POLY ) ) )
4720 {
4721 m_angleItem = std::make_unique<KIGFX::PREVIEW::ANGLE_ITEM>( m_editPoints );
4722 }
4723
4724 m_preview.FreeItems();
4725 m_radiusHelper = nullptr;
4726 getView()->Add( &m_preview );
4727
4730
4731 if( m_editPoints )
4732 getView()->Add( m_editPoints.get() );
4733
4734 if( m_angleItem )
4735 getView()->Add( m_angleItem.get() );
4736
4737 setEditedPoint( nullptr );
4738 updateEditedPoint( aEvent );
4739 bool inDrag = false;
4740 bool isConstrained = false;
4741 bool haveSnapLineDirections = false;
4742
4743 auto updateSnapLineDirections = [&]()
4744 {
4745 std::vector<VECTOR2I> directions;
4746
4747 if( inDrag && m_editedPoint )
4748 {
4749 EDIT_RELATION* relation = nullptr;
4750
4751 if( m_altConstraint )
4752 relation = m_altConstraint.get();
4753 else if( m_editedPoint->IsConstrained() )
4754 relation = m_editedPoint->GetRelation();
4755
4756 directions = getConstraintDirections( relation );
4757 }
4758
4759 if( directions.empty() )
4760 {
4761 grid.SetSnapLineDirections( {} );
4762 grid.SetSnapLineEnd( std::nullopt );
4763 haveSnapLineDirections = false;
4764 }
4765 else
4766 {
4767 VECTOR2I origin = m_altConstraint ? m_altConstrainer.GetPosition() : m_original.GetPosition();
4768
4769 grid.SetSnapLineDirections( directions );
4770 grid.SetSnapLineOrigin( origin );
4771 grid.SetSnapLineEnd( std::nullopt );
4772 haveSnapLineDirections = true;
4773 }
4774 };
4775
4776 BOARD_COMMIT commit( editFrame );
4777
4778 auto installFeasibilityCallback = [&]()
4779 {
4780 grid.SetFeasibilityCallback( {} );
4781
4782 if( !m_constraintDragSession || dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
4783 return;
4784
4785 std::shared_ptr<BOARD_CONSTRAINT_DRAG_SESSION> session = m_constraintDragSession;
4786
4787 grid.SetFeasibilityCallback(
4788 [session]( const SNAP_SOURCE_CONTEXT& aContext, const std::vector<SNAP_CANDIDATE>& aCandidates )
4789 {
4790 return session->ResolveCandidates( aContext, aCandidates );
4791 } );
4792 };
4793
4794 BLOCK_DRAG_SESSION block( *this, editFrame, grid, commit );
4795
4796
4797 // Main loop: keep receiving events
4798 while( TOOL_EVENT* evt = Wait() )
4799 {
4800 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
4801 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
4802 installFeasibilityCallback();
4803
4804 if( editFrame->IsType( FRAME_PCB_EDITOR ) )
4806 else
4808
4809 if( ( !m_editPoints && m_blockHandles.empty() ) || evt->IsSelectionEvent()
4810 || evt->Matches( EVENTS::InhibitSelectionEditing ) )
4811 {
4812 break;
4813 }
4814
4815 EDIT_POINT* prevHover = m_hoveredPoint;
4816
4817 if( !inDrag && !block.IsActive() )
4818 updateEditedPoint( *evt );
4819
4820 if( prevHover != m_hoveredPoint && m_editPoints )
4821 {
4822 getView()->Update( m_editPoints.get() );
4823
4824 if( m_angleItem )
4825 getView()->Update( m_angleItem.get() );
4826 }
4827
4828 // A running gesture holds a staged commit, and with copper in it a live router
4829 // session. Refuse any command that could edit the board underneath it, because a
4830 // commit pushed now would record the gesture's half-dragged geometry as the state
4831 // its own undo returns to. Undo is already held off while the gesture runs
4832 if( block.IsActive() && evt->Category() == TC_COMMAND && !blockDragAllowsCommand( *evt ) )
4833 {
4834 wxBell();
4835 continue;
4836 }
4837
4838 // D over a picked handle starts the gesture from the keyboard, with the cursor
4839 // free instead of held down. Every other use of D belongs to the edit tool
4840 if( evt->IsAction( &PCB_ACTIONS::drag45Degree ) || evt->IsAction( &PCB_ACTIONS::dragFreeAngle ) )
4841 {
4842 // An edit already running owns D. Passing it on would start the edit tool's own
4843 // drag of the same selection on top of this one, and that tool refilters the
4844 // selection, which ends this gesture through its selection event. With the
4845 // feature off the key is not ours to swallow
4846 if( blockAnchorEditingEnabled() && ( inDrag || block.IsActive() ) )
4847 continue;
4848
4849 block.ClearRefused();
4850
4851 if( blockAnchorEditingEnabled() && block.Begin( getViewControls()->GetCursorPosition( false ), false ) )
4852 {
4853 // Handled here, so the loop's catch-all does not pass it on as well
4854 continue;
4855 }
4856
4857 // The gesture already said why it refused, so keep the key here. Passed on, the
4858 // edit tool would replace that message with one of its own
4859 if( block.Refused() )
4860 continue;
4861
4862 evt->SetPassEvent();
4863 }
4864
4865 if( evt->IsDrag( BUT_LEFT ) && !inDrag && !block.PressConsumed() && !block.IsActive()
4867 {
4868 block.Begin( evt->DragOrigin(), true );
4869 }
4870
4871 if( ( ( evt->IsDrag( BUT_LEFT ) && !block.PressConsumed() ) || ( block.KeyboardDrag() && evt->IsMotion() ) )
4872 && !inDrag && block.IsActive() )
4873 {
4874 if( block.ApplyCursor( *evt ) )
4875 break;
4876 }
4877 else if( block.IsActive()
4878 && ( evt->IsMouseUp( BUT_LEFT ) || ( block.KeyboardDrag() && evt->IsClick( BUT_LEFT ) ) ) )
4879 {
4880 if( block.Release( *evt ) )
4881 break;
4882 }
4883 // Comes before the click pick and the catch-all, which do not test this flag
4884 else if( block.PressConsumed() && evt->IsDrag( BUT_LEFT ) )
4885 {
4886 // The press we swallowed keeps the pointer until the release
4887 }
4888 else if( block.PressConsumed() && ( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
4889 {
4890 // The swallowed press ends here, and a later drag may try again
4891 block.ClearPressConsumed();
4892 }
4893 else if( evt->IsDrag( BUT_LEFT ) && !inDrag && !block.PressConsumed() && !m_editedPoint )
4894 {
4895 if( block.AreaPickStarts( *evt ) )
4896 {
4897 if( block.RunAreaPick( *evt ) )
4898 break;
4899 }
4900 else
4901 {
4902 // A refused start goes to the selection tool, which selects as usual
4903 evt->SetPassEvent();
4904 }
4905 }
4906 else if( evt->IsDrag( BUT_LEFT ) && m_editedPoint && !block.PressConsumed() )
4907 {
4908 if( !inDrag )
4909 {
4910 frame()->UndoRedoBlock( true );
4911
4912 if( item->Type() == PCB_GENERATOR_T )
4913 {
4914 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genStartEdit, &commit,
4915 static_cast<PCB_GENERATOR*>( item ) );
4916 }
4917
4919 m_original = *m_editedPoint; // Save the original position
4920 getViewControls()->SetAutoPan( true );
4921 inDrag = true;
4922
4923 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item ) )
4924 {
4925 if( std::optional<CONSTRAINT_MEMBER> member =
4927 {
4928 m_constraintDragSession = std::make_shared<BOARD_CONSTRAINT_DRAG_SESSION>();
4929
4930 if( !m_constraintDragSession->Build( board(), *member ) )
4932
4933 installFeasibilityCallback();
4934 }
4935 }
4936
4937 if( m_editedPoint->GetGridConstraint() != SNAP_BY_GRID )
4938 grid.SetAuxAxes( true, m_original.GetPosition() );
4939
4940 m_editedPoint->SetActive();
4941
4942 for( size_t ii = 0; ii < m_editPoints->PointsSize(); ++ii )
4943 {
4944 EDIT_POINT& point = m_editPoints->Point( ii );
4945
4946 if( &point != m_editedPoint )
4947 point.SetActive( false );
4948 }
4949
4950 // When we start dragging, create a clone of the item to use as the original
4951 // reference geometry (e.g. for intersections and extensions)
4952 BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( item->Clone() );
4953 clone->SetParent( nullptr );
4954
4955 if( PCB_SHAPE* shape= dynamic_cast<PCB_SHAPE*>( item ) )
4956 {
4957 shape->SetFlags( IS_MOVING );
4958 shape->UpdateHatching();
4959
4960 static_cast<PCB_SHAPE*>( clone )->SetFillMode( FILL_T::NO_FILL );
4961 }
4962
4963 clones.emplace_back( clone );
4964 grid.AddConstructionItems( { clone }, false, true );
4965
4966 updateSnapLineDirections();
4967 }
4968
4969 EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
4970 bool ctrlHeld = evt->Modifier( MD_CTRL );
4971
4972 bool need_constraint = ( Is45Limited() || Is90Limited() ) && !ctrlHeld;
4973
4974 if( isConstrained != need_constraint )
4975 {
4976 setAltConstraint( need_constraint );
4977 isConstrained = need_constraint;
4978 updateSnapLineDirections();
4979 }
4980
4981 if( need_constraint )
4982 {
4983 VECTOR2I origin = m_altConstraint ? m_altConstrainer.GetPosition()
4984 : m_original.GetPosition();
4985 grid.SetAngleRestriction( origin, Is45Limited() ? 45.0 : 90.0 );
4986 }
4987 else
4988 {
4989 grid.SetAngleRestriction( std::nullopt, 0.0 );
4990 }
4991
4992 // For polygon lines, Ctrl temporarily toggles between CONVERGING and FIXED_LENGTH modes
4993
4994 if( line )
4995 {
4996 bool isPoly = false;
4997
4998 switch( item->Type() )
4999 {
5000 case PCB_ZONE_T:
5001 isPoly = true;
5002 break;
5003
5004 case PCB_SHAPE_T:
5005 isPoly = static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY;
5006 break;
5007
5008 default:
5009 break;
5010 }
5011
5012 if( isPoly )
5013 {
5014 POLYGON_EDGE_DRAG_POLICY* policy = line->GetDragPolicy();
5015
5016 if( policy )
5017 {
5020
5021 if( policy->GetMode() != targetMode )
5022 policy->SetMode( targetMode );
5023 }
5024 }
5025 }
5026
5027 // Keep point inside of limits with some padding
5028 VECTOR2I pos = GetClampedCoords<double, int>( evt->Position(), COORDS_PADDING );
5029 LSET snapLayers;
5030
5031 switch( m_editedPoint->GetSnapConstraint() )
5032 {
5033 case IGNORE_SNAPS: break;
5034 case OBJECT_LAYERS: snapLayers = item->GetLayerSet(); break;
5035 case ALL_LAYERS: snapLayers = LSET::AllLayersMask(); break;
5036 }
5037
5038 if( m_editedPoint->GetGridConstraint() == SNAP_BY_GRID )
5039 {
5040 if( grid.GetUseGrid() )
5041 {
5042 POLYGON_EDGE_DRAG_POLICY* dragPolicy =
5043 line ? line->GetDragPolicy() : nullptr;
5044
5045 bool snappedAlongPerp = false;
5046
5047 if( dragPolicy )
5048 {
5049 // For a polygon edge, the line moves only perpendicular to itself.
5050 // Snapping pos.x and pos.y independently to the axis-aligned grid
5051 // produces inconsistent perpendicular displacements when the edge is
5052 // tilted (different magnitudes depending on which axis crossed the
5053 // half-grid threshold first), causing the rendered edge to flicker
5054 // between two positions. Quantize the perpendicular displacement
5055 // directly so each grid step produces one stable line position.
5056 const VECTOR2I& origCenter = dragPolicy->GetOriginalCenter();
5057 const VECTOR2I& perpVec = dragPolicy->GetPerpVector();
5058 double perpLen = VECTOR2D( perpVec ).EuclideanNorm();
5059
5060 if( perpLen > 0 )
5061 {
5062 VECTOR2D perpUnit = VECTOR2D( perpVec ) / perpLen;
5063 VECTOR2D gridSize = grid.GetGridSize( grid.GetItemGrid( item ) );
5064
5065 // Effective grid spacing along the perpendicular direction. For an
5066 // axis-aligned edge this reduces to the grid pitch on that axis.
5067 double step = std::hypot( gridSize.x * perpUnit.x,
5068 gridSize.y * perpUnit.y );
5069
5070 if( step > 0 )
5071 {
5072 double offset = VECTOR2D( pos - origCenter ).Dot( perpUnit );
5073 double snapped = std::round( offset / step ) * step;
5074 VECTOR2D snappedPt = VECTOR2D( origCenter ) + perpUnit * snapped;
5075 pos = VECTOR2I( KiROUND( snappedPt.x ), KiROUND( snappedPt.y ) );
5076 snappedAlongPerp = true;
5077 }
5078 }
5079 }
5080
5081 if( !snappedAlongPerp )
5082 {
5083 VECTOR2I gridPt =
5084 grid.ResolveSnap( pos, {}, grid.GetItemGrid( item ), { item } )
5085 .position;
5086
5087 VECTOR2I last = m_editedPoint->GetPosition();
5088 VECTOR2I delta = pos - last;
5089 VECTOR2I deltaGrid =
5090 gridPt
5091 - grid.ResolveSnap( last, {}, grid.GetItemGrid( item ), { item } )
5092 .position;
5093
5094 if( abs( delta.x ) > grid.GetGrid().x / 2 )
5095 pos.x = last.x + deltaGrid.x;
5096 else
5097 pos.x = last.x;
5098
5099 if( abs( delta.y ) > grid.GetGrid().y / 2 )
5100 pos.y = last.y + deltaGrid.y;
5101 else
5102 pos.y = last.y;
5103 }
5104 }
5105 }
5106
5107 if( m_angleSnapActive )
5108 {
5109 m_stickyDisplacement = evt->Position() - m_angleSnapPos;
5110 int stickyLimit = KiROUND( getView()->ToWorld( 5 ) );
5111
5112 if( m_stickyDisplacement.EuclideanNorm() > stickyLimit || evt->Modifier( MD_SHIFT ) )
5113 {
5114 m_angleSnapActive = false;
5115 }
5116 else
5117 {
5118 pos = m_angleSnapPos;
5119 }
5120 }
5121
5122 bool isFreePolygon =
5123 item->Type() == PCB_ZONE_T
5124 || ( item->Type() == PCB_SHAPE_T && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY );
5125
5126 if( isFreePolygon && !m_angleSnapActive && m_editPoints->PointsSize() > 2 && !evt->Modifier( MD_SHIFT ) )
5127 {
5128 int idx = getEditedPointIndex();
5129
5130 if( idx != wxNOT_FOUND )
5131 {
5132 int prevIdx = ( idx + m_editPoints->PointsSize() - 1 ) % m_editPoints->PointsSize();
5133 int nextIdx = ( idx + 1 ) % m_editPoints->PointsSize();
5134 VECTOR2I prev = m_editPoints->Point( prevIdx ).GetPosition();
5135 VECTOR2I next = m_editPoints->Point( nextIdx ).GetPosition();
5136 SEG segA( pos, prev );
5137 SEG segB( pos, next );
5138 double ang = segA.Angle( segB ).AsDegrees();
5139 double snapAng = 45.0 * std::round( ang / 45.0 );
5140
5141 if( std::abs( ang - snapAng ) < 2.0 )
5142 {
5143 VECTOR2I snapped = snapCorner( prev, next, pos, snapAng );
5144
5145 if( m_editedPoint->GetGridConstraint() == SNAP_TO_GRID && grid.GetSnap() )
5146 {
5147 VECTOR2I gridded =
5148 grid.ResolveSnap( snapped, {}, grid.GetItemGrid( item ), { item } )
5149 .position;
5150 double griddedAng = SEG( gridded, prev ).Angle( SEG( gridded, next ) ).AsDegrees();
5151
5152 snapped = std::abs( griddedAng - snapAng ) < 2.0 ? gridded : pos;
5153 }
5154
5155 if( snapped != pos )
5156 {
5157 m_angleSnapPos = snapped;
5158 m_angleSnapActive = true;
5159 m_stickyDisplacement = evt->Position() - m_angleSnapPos;
5160 pos = m_angleSnapPos;
5161 }
5162 }
5163 }
5164 }
5165
5166 bool constraintSnapped = false;
5167 std::vector<VECTOR2I> stationarySelfPoints;
5168 std::vector<SEG> stationarySelfSegments;
5169
5170 if( item->Type() == PCB_ZONE_T
5171 || ( item->Type() == PCB_SHAPE_T
5172 && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY ) )
5173 {
5174 const EDIT_LINE* editedLine = dynamic_cast<const EDIT_LINE*>( m_editedPoint );
5175
5176 for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
5177 {
5178 const EDIT_POINT& point = m_editPoints->Point( i );
5179
5180 if( &point != m_editedPoint
5181 && ( !editedLine
5182 || ( &point != &editedLine->GetOrigin()
5183 && &point != &editedLine->GetEnd() ) ) )
5184 {
5185 stationarySelfPoints.push_back( point.GetPosition() );
5186 }
5187 }
5188
5189 for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
5190 {
5191 const EDIT_LINE& stationaryLine = m_editPoints->Line( i );
5192
5193 if( &stationaryLine != editedLine
5194 && &stationaryLine.GetOrigin() != m_editedPoint
5195 && &stationaryLine.GetEnd() != m_editedPoint
5196 && ( !editedLine
5197 || ( &stationaryLine.GetOrigin() != &editedLine->GetOrigin()
5198 && &stationaryLine.GetOrigin() != &editedLine->GetEnd()
5199 && &stationaryLine.GetEnd() != &editedLine->GetOrigin()
5200 && &stationaryLine.GetEnd() != &editedLine->GetEnd() ) ) )
5201 {
5202 stationarySelfSegments.emplace_back(
5203 stationaryLine.GetOrigin().GetPosition(),
5204 stationaryLine.GetEnd().GetPosition() );
5205 }
5206 }
5207 }
5208 else if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item ) )
5209 {
5210 int editedIndex = getEditedPointIndex();
5211
5212 if( shape->GetShape() == SHAPE_T::RECTANGLE && m_editPoints->PointsSize() >= RECT_MAX_POINTS
5213 && editedIndex >= RECT_TOP_LEFT && editedIndex <= RECT_BOT_LEFT )
5214 {
5215 int opposite = ( editedIndex + 2 ) % 4;
5216 stationarySelfPoints.push_back( m_editPoints->Point( opposite ).GetPosition() );
5217 }
5218 else if( shape->GetShape() == SHAPE_T::RECTANGLE && m_editPoints->LinesSize() >= 4 )
5219 {
5220 for( unsigned i = 0; i < m_editPoints->LinesSize() && i < 4; ++i )
5221 {
5222 if( m_editedPoint != &m_editPoints->Line( i ) )
5223 continue;
5224
5225 const EDIT_LINE& opposite = m_editPoints->Line( ( i + 2 ) % 4 );
5226 stationarySelfPoints.push_back( opposite.GetOrigin().GetPosition() );
5227 stationarySelfPoints.push_back( opposite.GetEnd().GetPosition() );
5228 stationarySelfSegments.emplace_back( opposite.GetOrigin().GetPosition(),
5229 opposite.GetEnd().GetPosition() );
5230 break;
5231 }
5232 }
5233 else if( shape->GetShape() == SHAPE_T::ARC )
5234 {
5235 constexpr int arcStart = 0;
5236 constexpr int arcMid = 1;
5237 constexpr int arcEnd = 2;
5238 constexpr int arcCenter = 3;
5239
5241 {
5242 if( editedIndex != arcStart )
5243 stationarySelfPoints.push_back( m_editPoints->Point( arcStart ).GetPosition() );
5244
5245 if( editedIndex != arcEnd )
5246 stationarySelfPoints.push_back( m_editPoints->Point( arcEnd ).GetPosition() );
5247 }
5248 else if( editedIndex == arcStart || editedIndex == arcMid || editedIndex == arcEnd )
5249 {
5250 stationarySelfPoints.push_back( m_editPoints->Point( arcCenter ).GetPosition() );
5251 }
5252 }
5253 }
5254
5255 grid.SetStationarySelfGeometry( std::move( stationarySelfPoints ),
5256 std::move( stationarySelfSegments ) );
5257
5258 // Apply 45 degree or other constraints
5260 {
5261 m_editedPoint->SetPosition(
5262 grid.ResolveSnap( pos, snapLayers, grid.GetItemGrid( item ), { item } )
5263 .position );
5264 constraintSnapped = true;
5265 }
5266 else if( !m_angleSnapActive && m_editedPoint->IsConstrained() )
5267 {
5268 m_editedPoint->SetPosition( pos );
5269 m_editedPoint->ApplyRelation( grid );
5270 constraintSnapped = true;
5271
5272 // For constrained lines (like zone edges), try to snap to nearby anchors
5273 // that lie on the constraint line. First get the constrained position, then
5274 // look for snap anchors and verify they're on the constraint line.
5275 if( grid.GetSnap() && !snapLayers.empty() )
5276 {
5277 VECTOR2I constrainedPos = m_editedPoint->GetPosition();
5278 VECTOR2I snapPos =
5279 grid.ResolveSnap( constrainedPos, snapLayers, grid.GetItemGrid( item ),
5280 { item } )
5281 .position;
5282
5283 // Require the relation to preserve the discrete anchor exactly.
5284 if( snapPos != constrainedPos )
5285 {
5286 m_editedPoint->SetPosition( snapPos );
5287 m_editedPoint->ApplyRelation( grid );
5288 VECTOR2I projectedPos = m_editedPoint->GetPosition();
5289
5290 if( projectedPos != snapPos )
5291 m_editedPoint->SetPosition( constrainedPos );
5292 }
5293 }
5294 }
5295 else if( !m_angleSnapActive && m_editedPoint->GetGridConstraint() == SNAP_TO_GRID )
5296 {
5297 m_editedPoint->SetPosition(
5298 grid.ResolveSnap( pos, snapLayers, grid.GetItemGrid( item ), { item } )
5299 .position );
5300 }
5301 else
5302 {
5303 m_editedPoint->SetPosition( pos );
5304 }
5305
5306 if( haveSnapLineDirections )
5307 {
5308 VECTOR2I snapOrigin = m_altConstraint ? m_altConstrainer.GetPosition() : m_original.GetPosition();
5309 grid.SetSnapLineOrigin( snapOrigin );
5310
5311 if( constraintSnapped )
5312 grid.SetSnapLineEnd( m_editedPoint->GetPosition() );
5313 else
5314 grid.SetSnapLineEnd( std::nullopt );
5315 }
5316
5317 updateItem( commit );
5318 getViewControls()->ForceCursorPosition( true, m_editedPoint->GetPosition() );
5319 updatePoints();
5320
5321 if( m_radiusHelper )
5322 {
5323 if( m_editPoints->PointsSize() > RECT_RADIUS
5324 && m_editedPoint == &m_editPoints->Point( RECT_RADIUS ) )
5325 {
5326 if( PCB_SHAPE* rect = dynamic_cast<PCB_SHAPE*>( item ) )
5327 {
5328 int radius = rect->GetCornerRadius();
5329 int offset = radius - M_SQRT1_2 * radius;
5330 VECTOR2I topLeft = rect->GetTopLeft();
5331 VECTOR2I botRight = rect->GetBotRight();
5332 VECTOR2I topRight( botRight.x, topLeft.y );
5333 VECTOR2I center( topRight.x - offset, topRight.y + offset );
5334 m_radiusHelper->Set( radius, center, VECTOR2I( 1, -1 ), editFrame->GetUserUnits() );
5335 }
5336 }
5337 else
5338 {
5339 m_radiusHelper->Hide();
5340 }
5341 }
5342
5343 getView()->Update( &m_preview );
5344 }
5345 else if( m_editedPoint && evt->Action() == TA_MOUSE_DOWN && evt->Buttons() == BUT_LEFT )
5346 {
5347 m_editedPoint->SetActive();
5348
5349 for( size_t ii = 0; ii < m_editPoints->PointsSize(); ++ii )
5350 {
5351 EDIT_POINT& point = m_editPoints->Point( ii );
5352
5353 if( &point != m_editedPoint )
5354 point.SetActive( false );
5355 }
5356
5357 getView()->Update( m_editPoints.get() );
5358
5359 if( m_angleItem )
5360 getView()->Update( m_angleItem.get() );
5361 }
5362 else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
5363 {
5364 if( m_editedPoint )
5365 {
5366 m_editedPoint->SetActive( false );
5367 getView()->Update( m_editPoints.get() );
5368
5369 if( m_angleItem )
5370 getView()->Update( m_angleItem.get() );
5371 }
5372
5373 if( m_radiusHelper )
5374 m_radiusHelper->Hide();
5375
5376 getView()->Update( &m_preview );
5377
5378 getViewControls()->SetAutoPan( false );
5379 setAltConstraint( false );
5380 updateSnapLineDirections();
5381
5382 if( m_editorBehavior )
5383 m_editorBehavior->FinalizeItem( *m_editPoints, commit );
5384
5385 if( item->Type() == PCB_GENERATOR_T )
5386 {
5387 PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( item );
5388
5389 m_preview.FreeItems();
5390 m_radiusHelper = nullptr;
5391 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genFinishEdit, &commit, generator );
5392
5393 commit.Push( generator->GetCommitMessage() );
5394 }
5395 else if( item->Type() == PCB_TABLECELL_T )
5396 {
5397 commit.Push( _( "Resize Table Cells" ) );
5398 }
5399 else
5400 {
5401 commit.Push( _( "Move Point" ) );
5402 }
5403
5404 if( PCB_SHAPE* shape= dynamic_cast<PCB_SHAPE*>( item ) )
5405 {
5406 shape->ClearFlags( IS_MOVING );
5407 shape->UpdateHatching();
5408 }
5409
5410 inDrag = false;
5412 frame()->UndoRedoBlock( false );
5413 updateSnapLineDirections();
5414
5415 m_toolMgr->PostAction<EDA_ITEM*>( ACTIONS::reselectItem, item ); // FIXME: Needed for generators
5416 }
5417 else if( !inDrag && !block.IsActive() && evt->IsClick( BUT_LEFT ) && blockAnchorEditingEnabled() )
5418 {
5419 bool accumulate = evt->Modifier( MD_SHIFT ) != 0;
5420 bool consumed = pickHandleAt( evt->Position(), accumulate );
5421
5422 // A plain click on nothing just clears the picks. A Shift click on nothing
5423 // keeps them and goes to the selection tool, which adds to the selection
5424 if( !consumed && !accumulate && !m_pickedHandles.empty() )
5425 {
5427 consumed = true;
5428 }
5429
5430 if( consumed )
5431 {
5432 // The selection tool never sees a click we swallow, so stop its long press
5433 // timer here
5434 m_selectionTool->StopDisambiguation();
5435 }
5436 else
5437 {
5438 evt->SetPassEvent();
5439 }
5440 }
5441 else if( evt->IsCancelInteractive() || evt->IsActivate() )
5442 {
5443 if( block.IsActive() )
5444 {
5445 if( block.Cancel( *evt ) )
5446 break;
5447 }
5448 else if( inDrag ) // Restore the last change
5449 {
5450 if( item->Type() == PCB_GENERATOR_T )
5451 {
5452 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genCancelEdit, &commit,
5453 static_cast<PCB_GENERATOR*>( item ) );
5454 }
5455
5456 commit.Revert();
5457
5458 if( PCB_SHAPE* shape= dynamic_cast<PCB_SHAPE*>( item ) )
5459 {
5460 shape->ClearFlags( IS_MOVING );
5461 shape->UpdateHatching();
5462 }
5463
5464 inDrag = false;
5466 frame()->UndoRedoBlock( false );
5467 updateSnapLineDirections();
5468 }
5469 else if( evt->IsCancelInteractive() && !m_pickedHandles.empty() )
5470 {
5472
5473 // Cancel events go to every tool by default. The first Escape only drops
5474 // the picks, so stop it before it clears the selection too. A tool switch
5475 // and the other ways of cancelling keep their usual effect
5476 if( evt->IsCancel() && evt->GetCommandId() == (int) WXK_ESCAPE )
5477 evt->SetPassEvent( false );
5478 }
5479
5480 // Only cancel point editor when activating a new tool
5481 // Otherwise, allow the points to persist when moving up the
5482 // tool stack
5483 if( evt->IsActivate() && !evt->IsMoveTool() )
5484 break;
5485 }
5486 else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
5487 {
5488 // Re-create the points for items which can have different behavior on different layers
5489 if( m_editPoints && item->Type() == PCB_PAD_T && m_isFootprintEditor )
5490 {
5491 if( getView()->HasItem( m_editPoints.get() ) )
5492 getView()->Remove( m_editPoints.get() );
5493
5494 if( m_angleItem && getView()->HasItem( m_angleItem.get() ) )
5495 getView()->Remove( m_angleItem.get() );
5496
5497 m_editedPoint = nullptr;
5498 m_hoveredPoint = nullptr;
5499 m_editPoints = makePoints( item );
5500
5501 if( m_angleItem )
5502 {
5503 m_angleItem->SetEditPoints( m_editPoints );
5504 getView()->Add( m_angleItem.get() );
5505 }
5506
5507 getView()->Add( m_editPoints.get() );
5508 }
5509 }
5510 else if( evt->Action() == TA_UNDO_REDO_POST )
5511 {
5512 break;
5513 }
5514 else
5515 {
5516 evt->SetPassEvent();
5517 }
5518 }
5519
5520 // IS_MOVING is only still set if the loop broke mid-drag, and a null m_editPoints means
5521 // Reset() ran while we were suspended, so the board and item have already been destroyed
5522 if( inDrag && m_editPoints )
5523 {
5524 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( m_editPoints->GetParent() ) )
5525 {
5526 shape->ClearFlags( IS_MOVING );
5527 shape->UpdateHatching();
5528 }
5529 }
5530
5531 // Leaving the loop without going through the cancel branch undoes the drag
5532 // the same way Escape does. Reset() does this before the collections clear,
5533 // while the items are still here.
5534 block.Abort();
5535 m_blockDragAbort = nullptr;
5536
5537 m_preview.FreeItems();
5538 m_radiusHelper = nullptr;
5540
5542
5543 if( getView()->HasItem( &m_preview ) )
5544 getView()->Remove( &m_preview );
5545
5546 if( m_editPoints )
5547 {
5548 if( getView()->HasItem( m_editPoints.get() ) )
5549 getView()->Remove( m_editPoints.get() );
5550
5551 if( m_angleItem && getView()->HasItem( m_angleItem.get() ) )
5552 getView()->Remove( m_angleItem.get() );
5553
5554 m_hoveredPoint = nullptr;
5555 m_editPoints.reset();
5556 m_angleItem.reset();
5557 }
5558
5559 m_editedPoint = nullptr;
5560 grid.SetSnapLineDirections( {} );
5561
5562 return 0;
5563}
5564
5565
5567{
5568 if( !m_editPoints || !m_editPoints->GetParent() || !HasPoint() )
5569 return 0;
5570
5572
5573 BOARD_COMMIT commit( editFrame );
5574 commit.Stage( m_editPoints->GetParent(), CHT_MODIFY );
5575
5576 VECTOR2I pt = m_editedPoint->GetPosition();
5577 wxString title;
5578 wxString msg;
5579
5580 if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
5581 {
5582 title = _( "Move Midpoint to Location" );
5583 msg = _( "Move Midpoint" );
5584 }
5585 else
5586 {
5587 title = _( "Move Corner to Location" );
5588 msg = _( "Move Corner" );
5589 }
5590
5591 WX_PT_ENTRY_DIALOG dlg( editFrame, title, _( "X:" ), _( "Y:" ), pt, false );
5592
5593 if( dlg.ShowModal() == wxID_OK )
5594 {
5595 m_editedPoint->SetPosition( dlg.GetValue() );
5596 updateItem( commit );
5597 commit.Push( msg );
5598 }
5599
5600 return 0;
5601}
5602
5603
5605{
5606 wxCHECK( m_editPoints, /* void */ );
5607 EDA_ITEM* item = m_editPoints->GetParent();
5608
5609 if( !item )
5610 return;
5611
5612 // item is always updated
5613 std::vector<EDA_ITEM*> updatedItems = { item };
5614 aCommit.Modify( item );
5615
5616 if( m_editorBehavior )
5617 {
5618 wxCHECK( m_editedPoint, /* void */ );
5619 m_editorBehavior->UpdateItem( *m_editedPoint, *m_editPoints, aCommit, updatedItems );
5620 }
5621
5622 // Re-derive any geometry constrained to the dragged segment endpoint (issue #2329). The
5623 // behavior above has already moved the dragged point to the cursor, so its current endpoint
5624 // position is the pin target for the solver.
5625 if( auto* groupBehavior = dynamic_cast<SHAPE_GROUP_POINT_EDIT_BEHAVIOR*>( m_editorBehavior.get() );
5626 groupBehavior && BoardHasConstraints( board() ) )
5627 {
5628 // A group edit writes its own shapes, so the neighbours still need re-solving
5629 std::vector<PCB_SHAPE*> modified;
5630
5631 ReSolveShapeClustersHoldingEdited( board(), groupBehavior->GetShapes(), &modified,
5632 [&]( BOARD_ITEM* aNeighbor )
5633 {
5634 aCommit.Modify( aNeighbor );
5635 } );
5636
5637 for( PCB_SHAPE* neighbor : modified )
5638 updatedItems.push_back( neighbor );
5639 }
5640 else if( item->Type() == PCB_SHAPE_T && m_editedPoint && BoardHasConstraints( board() ) )
5641 {
5642 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
5643 SHAPE_T type = shape->GetShape();
5644 VECTOR2I cursor = m_editedPoint->GetPosition();
5645
5646 std::optional<CONSTRAINT_MEMBER> member;
5647 std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>> coDragged;
5648
5649 // Match dragged point to a constraint anchor segment bezier and arc expose endpoints
5650 // arc and circle also expose a centre bezier has none so centre test stays arc only
5651 if( type == SHAPE_T::SEGMENT || type == SHAPE_T::ARC || type == SHAPE_T::BEZIER )
5652 {
5653 if( cursor == shape->GetStart() )
5655 else if( cursor == shape->GetEnd() )
5657 else if( type == SHAPE_T::ARC && cursor == shape->GetCenter() )
5659 }
5660 else if( type == SHAPE_T::CIRCLE )
5661 {
5662 if( cursor == shape->GetCenter() )
5664 }
5665 else if( type == SHAPE_T::RECTANGLE && m_editPoints->PointsSize() >= RECT_MAX_POINTS )
5666 {
5667 // Only corner handles map to vertex anchors centre radius and side handles reshape whole rect
5668 // corners kept in min max order so ordinal equals vertex index solve target reads post clamp position
5669 for( unsigned i = RECT_TOP_LEFT; i <= RECT_BOT_LEFT; ++i )
5670 {
5671 if( isModified( m_editPoints->Point( i ) ) )
5672 {
5673 if( std::optional<CONSTRAINT_ANCHOR_POINT> corner = ConstraintShapeVertex( shape, (int) i ) )
5674 {
5675 member = CONSTRAINT_MEMBER( shape->m_Uuid, corner->anchor, corner->index );
5676 cursor = corner->pos;
5677 }
5678
5679 break;
5680 }
5681 }
5682
5683 // Side handle drags one edge param aliased by both corners side i runs corner i to i plus 1 mod 4
5684 // pinning corner i covers dragged plus one perpendicular param opposite corner hold covers the rest
5685 if( !member.has_value() )
5686 {
5687 for( unsigned i = 0; i < m_editPoints->LinesSize() && i < 4; ++i )
5688 {
5689 if( isModified( m_editPoints->Line( i ) ) )
5690 {
5691 if( std::optional<CONSTRAINT_ANCHOR_POINT> corner = ConstraintShapeVertex( shape, (int) i ) )
5692 {
5693 member = CONSTRAINT_MEMBER( shape->m_Uuid, corner->anchor, corner->index );
5694 cursor = corner->pos;
5695 }
5696
5697 break;
5698 }
5699 }
5700 }
5701 }
5702 else if( type == SHAPE_T::POLY && ConstraintPolygonIsModelable( shape ) )
5703 {
5704 // Editor builds one edit point per outline vertex in order so dragged ordinal is vertex index
5705 // holds even when a drag lands a vertex on top of another where position match would be ambiguous
5706 for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
5707 {
5708 if( isModified( m_editPoints->Point( i ) ) )
5709 {
5710 if( std::optional<CONSTRAINT_ANCHOR_POINT> vertex = ConstraintShapeVertex( shape, (int) i ) )
5711 {
5712 member = CONSTRAINT_MEMBER( shape->m_Uuid, vertex->anchor, vertex->index );
5713 cursor = vertex->pos;
5714 }
5715
5716 break;
5717 }
5718 }
5719
5720 // Edge handle moves two adjacent vertices one member cannot express both so second vertex
5721 // rides as a co dragged pin line i runs vertex i to i plus 1 mod count positions read back post move
5722 if( !member.has_value() )
5723 {
5724 for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
5725 {
5726 if( isModified( m_editPoints->Line( i ) ) )
5727 {
5728 int next = ( (int) i + 1 ) % (int) m_editPoints->PointsSize();
5729
5730 std::optional<CONSTRAINT_ANCHOR_POINT> v0 = ConstraintShapeVertex( shape, (int) i );
5731 std::optional<CONSTRAINT_ANCHOR_POINT> v1 = ConstraintShapeVertex( shape, next );
5732
5733 if( v0 && v1 )
5734 {
5735 member = CONSTRAINT_MEMBER( shape->m_Uuid, v0->anchor, v0->index );
5736 cursor = v0->pos;
5737 coDragged = { CONSTRAINT_MEMBER( shape->m_Uuid, v1->anchor, v1->index ), v1->pos };
5738 }
5739
5740 break;
5741 }
5742 }
5743 }
5744 }
5745
5746 bool isCurve = type == SHAPE_T::CIRCLE || type == SHAPE_T::ARC || type == SHAPE_T::ELLIPSE
5747 || type == SHAPE_T::ELLIPSE_ARC;
5748
5749 std::vector<PCB_SHAPE*> modified;
5750
5751 // Failed or diverged solve leaves neighbors untouched below so nothing is half moved this frame
5752 // moved shapes report in modified moved dimensions do not so refresh view here or they freeze
5753 auto stageNeighbor = [&]( BOARD_ITEM* aItem )
5754 {
5755 aCommit.Modify( aItem );
5756
5757 if( aItem->Type() != PCB_SHAPE_T )
5758 updatedItems.push_back( aItem );
5759 };
5760
5761 if( member.has_value() )
5762 {
5763 if( !m_constraintDragSession || !m_constraintDragSession->Matches( *member ) )
5764 {
5765 m_constraintDragSession = std::make_shared<BOARD_CONSTRAINT_DRAG_SESSION>();
5766
5767 if( !m_constraintDragSession->Build( board(), *member ) )
5769 }
5770
5772 {
5773 m_constraintDragSession->Solve( cursor, &modified, stageNeighbor,
5774 /* aIncludeDragged */ false,
5775 /* aStabilize */ false, {}, coDragged );
5776 }
5777 else
5778 {
5779 SolveCluster( board(), member.value(), cursor, &modified, stageNeighbor,
5780 /* aIncludeDragged */ false, /* aStabilize */ false, {}, coDragged );
5781 }
5782 }
5783 else if( isCurve )
5784 {
5785 // Radius or axis handle not a constrained point resize hold keeps new radius but yields
5786 // to a real radius constraint full dof hold below would fight it so curves use this instead
5787 ReSolveAfterShapeResize( board(), shape, &modified, stageNeighbor );
5788 }
5789 else if( type == SHAPE_T::RECTANGLE || ( type == SHAPE_T::POLY && ConstraintPolygonIsModelable( shape ) ) )
5790 {
5791 // Only whole shape handles centre and corner radius grips land here side corner and edge
5792 // drags pinned members above already treated like a properties edit new geometry wins neighbors follow
5793 ReSolveShapeClustersHoldingEdited( board(), { shape }, &modified, stageNeighbor );
5794 }
5795
5796 for( PCB_SHAPE* neighbor : modified )
5797 updatedItems.push_back( neighbor );
5798 }
5799
5800 // Perform any post-edit actions that the item may require
5801
5802 switch( item->Type() )
5803 {
5804 case PCB_TEXTBOX_T:
5805 case PCB_SHAPE_T:
5806 {
5807 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
5808
5809 if( shape->IsProxyItem() )
5810 {
5811 for( PAD* pad : shape->GetParentFootprint()->Pads() )
5812 {
5813 if( pad->IsEntered() )
5814 view()->Update( pad );
5815 }
5816 }
5817
5818 // Nuke outline font render caches
5819 if( PCB_TEXTBOX* textBox = dynamic_cast<PCB_TEXTBOX*>( item ) )
5820 textBox->ClearRenderCache();
5821
5822 break;
5823 }
5824 case PCB_GENERATOR_T:
5825 {
5826 GENERATOR_TOOL* generatorTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
5827 PCB_GENERATOR* generatorItem = static_cast<PCB_GENERATOR*>( item );
5828
5829 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genUpdateEdit, &aCommit, generatorItem );
5830
5831 // Note: POINT_EDITOR::m_preview holds only the canvas-draw status "popup"; the meanders
5832 // themselves (ROUTER_PREVIEW_ITEMs) are owned by the router.
5833
5834 m_preview.FreeItems();
5835 m_radiusHelper = nullptr;
5836
5837 for( EDA_ITEM* previewItem : generatorItem->GetPreviewItems( generatorTool, frame(), STATUS_ITEMS_ONLY ) )
5838 m_preview.Add( previewItem );
5839
5840 getView()->Update( &m_preview );
5841 break;
5842 }
5843 default:
5844 break;
5845 }
5846
5847 // Update the item and any affected items
5848 for( EDA_ITEM* updatedItem : updatedItems )
5849 getView()->Update( updatedItem );
5850
5851 frame()->SetMsgPanel( item );
5852}
5853
5854
5856{
5858
5859 // Done here too, because the three early returns below skip the refresh at the end
5861
5862 if( !m_editPoints )
5863 return;
5864
5865 EDA_ITEM* item = m_editPoints->GetParent();
5866
5867 if( !item )
5868 return;
5869
5870 if( !m_editorBehavior )
5871 return;
5872
5873 int editedIndex = -1;
5874 bool editingLine = false;
5875
5876 if( m_editedPoint )
5877 {
5878 // Check if we're editing a point (vertex)
5879 for( unsigned ii = 0; ii < m_editPoints->PointsSize(); ++ii )
5880 {
5881 if( &m_editPoints->Point( ii ) == m_editedPoint )
5882 {
5883 editedIndex = ii;
5884 break;
5885 }
5886 }
5887
5888 // If not found in points, check if we're editing a line (midpoint)
5889 if( editedIndex == -1 )
5890 {
5891 for( unsigned ii = 0; ii < m_editPoints->LinesSize(); ++ii )
5892 {
5893 if( &m_editPoints->Line( ii ) == m_editedPoint )
5894 {
5895 editedIndex = ii;
5896 editingLine = true;
5897 break;
5898 }
5899 }
5900 }
5901 }
5902
5903 if( SHAPE_GROUP_POINT_EDIT_BEHAVIOR* groupBehavior =
5904 dynamic_cast<SHAPE_GROUP_POINT_EDIT_BEHAVIOR*>( m_editorBehavior.get() ) )
5905 {
5906 groupBehavior->SetInflation( bboxHandleInflation() );
5907 }
5908
5909 if( !m_editorBehavior->UpdatePoints( *m_editPoints ) )
5910 {
5911 if( getView()->HasItem( m_editPoints.get() ) )
5912 getView()->Remove( m_editPoints.get() );
5913
5914 m_hoveredPoint = nullptr;
5915 m_editPoints = makePoints( item );
5916 getView()->Add( m_editPoints.get() );
5917 }
5918
5919 if( editedIndex >= 0 )
5920 {
5921 if( editingLine && editedIndex < (int) m_editPoints->LinesSize() )
5922 m_editedPoint = &m_editPoints->Line( editedIndex );
5923 else if( !editingLine && editedIndex < (int) m_editPoints->PointsSize() )
5924 m_editedPoint = &m_editPoints->Point( editedIndex );
5925 else
5926 m_editedPoint = nullptr;
5927 }
5928 else
5929 {
5930 m_editedPoint = nullptr;
5931 }
5932
5934
5935 getView()->Update( m_editPoints.get() );
5936
5937 if( m_angleItem )
5938 getView()->Update( m_angleItem.get() );
5939}
5940
5941
5943{
5945
5946 if( aPoint )
5947 {
5948 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
5949 controls->ForceCursorPosition( true, aPoint->GetPosition() );
5950 controls->ShowCursor( true );
5951 }
5952 else
5953 {
5954 if( frame()->ToolStackIsEmpty() )
5955 controls->ShowCursor( false );
5956
5957 controls->ForceCursorPosition( false );
5958 }
5959
5960 m_editedPoint = aPoint;
5961}
5962
5963
5965{
5966 EDA_ITEM* parent = m_editPoints ? m_editPoints->GetParent() : nullptr;
5967 EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
5968 bool isPoly = false;
5969
5970 if( parent )
5971 {
5972 switch( parent->Type() )
5973 {
5974 case PCB_ZONE_T:
5975 isPoly = true;
5976 break;
5977
5978 case PCB_SHAPE_T:
5979 isPoly = static_cast<PCB_SHAPE*>( parent )->GetShape() == SHAPE_T::POLY;
5980 break;
5981
5982 default:
5983 break;
5984 }
5985 }
5986
5987 if( aEnabled )
5988 {
5989 if( line && isPoly )
5990 {
5991 // For polygon lines, toggle the mode on the existing constraint rather than
5992 // creating a new one. This preserves the original reference positions.
5993 POLYGON_EDGE_DRAG_POLICY* policy = line->GetDragPolicy();
5994
5995 if( policy )
5997
5998 // Don't set m_altConstraint - we're modifying the line's own constraint
5999 }
6000 else
6001 {
6002 // Find a proper constraining point for angle snapping mode
6004
6005 if( Is90Limited() )
6007 else
6009 }
6010 }
6011 else
6012 {
6013 if( line && isPoly )
6014 {
6015 // Restore the line's constraint to CONVERGING mode
6016 POLYGON_EDGE_DRAG_POLICY* policy = line->GetDragPolicy();
6017
6018 if( policy )
6020 }
6021
6022 m_altConstraint.reset();
6023 }
6024}
6025
6026
6028{
6029 // If there's a behaviour and it provides a constrainer, use that
6030 if( m_editorBehavior )
6031 {
6032 const OPT_VECTOR2I constrainer = m_editorBehavior->Get45DegreeConstrainer( *m_editedPoint, *m_editPoints );
6033
6034 if( constrainer )
6035 return EDIT_POINT( *constrainer );
6036 }
6037
6038 // In any other case we may align item to its original position
6039 return m_original;
6040}
6041
6042
6043// Finds a corresponding vertex in a polygon set
6044static std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX> findVertex( SHAPE_POLY_SET& aPolySet, const EDIT_POINT& aPoint )
6045{
6046 for( auto it = aPolySet.IterateWithHoles(); it; ++it )
6047 {
6048 auto vertexIdx = it.GetIndex();
6049
6050 if( aPolySet.CVertex( vertexIdx ) == aPoint.GetPosition() )
6051 return std::make_pair( true, vertexIdx );
6052 }
6053
6054 return std::make_pair( false, SHAPE_POLY_SET::VERTEX_INDEX() );
6055}
6056
6057
6059{
6060 if( !m_editPoints || !m_editedPoint )
6061 return false;
6062
6063 EDA_ITEM* item = m_editPoints->GetParent();
6064 SHAPE_POLY_SET* polyset = nullptr;
6065
6066 if( !item )
6067 return false;
6068
6069 switch( item->Type() )
6070 {
6071 case PCB_ZONE_T:
6072 polyset = static_cast<ZONE*>( item )->Outline();
6073 break;
6074
6075 case PCB_SHAPE_T:
6076 if( static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY )
6077 polyset = &static_cast<PCB_SHAPE*>( item )->GetPolyShape();
6078 else
6079 return false;
6080
6081 break;
6082
6083 default:
6084 return false;
6085 }
6086
6087 std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX> vertex = findVertex( *polyset, *m_editedPoint );
6088
6089 if( !vertex.first )
6090 return false;
6091
6092 const SHAPE_POLY_SET::VERTEX_INDEX& vertexIdx = vertex.second;
6093
6094 // Check if there are enough vertices so one can be removed without
6095 // degenerating the polygon.
6096 // The first condition allows one to remove all corners from holes (when
6097 // there are only 2 vertices left, a hole is removed).
6098 if( vertexIdx.m_contour == 0
6099 && polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
6100 {
6101 return false;
6102 }
6103
6104 // Remove corner does not work with lines
6105 if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
6106 return false;
6107
6108 return m_editedPoint != nullptr;
6109}
6110
6111
6113{
6114 if( !m_editPoints )
6115 return 0;
6116
6117 EDA_ITEM* item = m_editPoints->GetParent();
6119 const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
6120
6121 // called without an active edited polygon
6122 if( !item || !CanAddCorner( *item ) )
6123 return 0;
6124
6125 PCB_SHAPE* graphicItem = dynamic_cast<PCB_SHAPE*>( item );
6126 BOARD_COMMIT commit( frame );
6127
6128 if( item->Type() == PCB_ZONE_T || ( graphicItem && graphicItem->GetShape() == SHAPE_T::POLY ) )
6129 {
6130 unsigned int nearestIdx = 0;
6131 unsigned int nextNearestIdx = 0;
6132 unsigned int nearestDist = INT_MAX;
6133 unsigned int firstPointInContour = 0;
6134 SHAPE_POLY_SET* zoneOutline;
6135
6136 if( item->Type() == PCB_ZONE_T )
6137 {
6138 ZONE* zone = static_cast<ZONE*>( item );
6139 zoneOutline = zone->Outline();
6140 zone->SetNeedRefill( true );
6141 }
6142 else
6143 {
6144 zoneOutline = &( graphicItem->GetPolyShape() );
6145 }
6146
6147 commit.Modify( item );
6148
6149 // Search the best outline segment to add a new corner
6150 // and therefore break this segment into two segments
6151
6152 // Object to iterate through the corners of the outlines (main contour and its holes)
6153 SHAPE_POLY_SET::ITERATOR iterator = zoneOutline->Iterate( 0, zoneOutline->OutlineCount()-1,
6154 /* IterateHoles */ true );
6155 int curr_idx = 0;
6156
6157 // Iterate through all the corners of the outlines and search the best segment
6158 for( ; iterator; iterator++, curr_idx++ )
6159 {
6160 int jj = curr_idx+1;
6161
6162 if( iterator.IsEndContour() )
6163 { // We reach the last point of the current contour (main or hole)
6164 jj = firstPointInContour;
6165 firstPointInContour = curr_idx+1; // Prepare next contour analysis
6166 }
6167
6168 SEG curr_segment( zoneOutline->CVertex( curr_idx ), zoneOutline->CVertex( jj ) );
6169
6170 unsigned int distance = curr_segment.Distance( cursorPos );
6171
6172 if( distance < nearestDist )
6173 {
6174 nearestDist = distance;
6175 nearestIdx = curr_idx;
6176 nextNearestIdx = jj;
6177 }
6178 }
6179
6180 // Find the point on the closest segment
6181 const VECTOR2I& sideOrigin = zoneOutline->CVertex( nearestIdx );
6182 const VECTOR2I& sideEnd = zoneOutline->CVertex( nextNearestIdx );
6183 SEG nearestSide( sideOrigin, sideEnd );
6184 VECTOR2I nearestPoint = nearestSide.NearestPoint( cursorPos );
6185
6186 // Do not add points that have the same coordinates as ones that already belong to polygon
6187 // instead, add a point in the middle of the side
6188 if( nearestPoint == sideOrigin || nearestPoint == sideEnd )
6189 nearestPoint = ( sideOrigin + sideEnd ) / 2;
6190
6191 zoneOutline->InsertVertex( nextNearestIdx, nearestPoint );
6192
6193 // Zones cannot carry constraint members but shape polygons can insertion shifts ordinals at or
6194 // past new vertex issue 2329 members only exist on hole free polys index past outline count is a hole vertex
6195 if( graphicItem && nextNearestIdx < (unsigned) zoneOutline->COutline( 0 ).PointCount() )
6196 {
6197 RemapPolygonVertexMembers( frame->GetBoard(), graphicItem->m_Uuid, (int) nextNearestIdx, 1,
6198 [&]( BOARD_ITEM* aConstraint ) { commit.Modify( aConstraint ); },
6199 [&]( BOARD_ITEM* aConstraint ) { commit.Remove( aConstraint ); } );
6200 }
6201
6202 if( item->Type() == PCB_ZONE_T )
6203 static_cast<ZONE*>( item )->HatchBorder();
6204
6205 commit.Push( _( "Add Zone Corner" ) );
6206 }
6207 else if( graphicItem )
6208 {
6209 switch( graphicItem->GetShape() )
6210 {
6211 case SHAPE_T::SEGMENT:
6212 {
6213 commit.Modify( graphicItem );
6214
6215 SEG seg( graphicItem->GetStart(), graphicItem->GetEnd() );
6216 VECTOR2I nearestPoint = seg.NearestPoint( cursorPos );
6217
6218 // Move the end of the line to the break point..
6219 graphicItem->SetEnd( nearestPoint );
6220
6221 // and add another one starting from the break point
6222 PCB_SHAPE* newSegment = static_cast<PCB_SHAPE*>( graphicItem->Duplicate( true, &commit ) );
6223 newSegment->ClearSelected();
6224 newSegment->SetStart( nearestPoint );
6225 newSegment->SetEnd( VECTOR2I( seg.B.x, seg.B.y ) );
6226
6227 commit.Add( newSegment );
6228 commit.Push( _( "Split Segment" ) );
6229 break;
6230 }
6231 case SHAPE_T::ARC:
6232 {
6233 commit.Modify( graphicItem );
6234
6235 const SHAPE_ARC arc( graphicItem->GetStart(), graphicItem->GetArcMid(), graphicItem->GetEnd(), 0 );
6236 const VECTOR2I nearestPoint = arc.NearestPoint( cursorPos );
6237
6238 // Move the end of the arc to the break point..
6239 graphicItem->SetEnd( nearestPoint );
6240
6241 // and add another one starting from the break point
6242 PCB_SHAPE* newArc = static_cast<PCB_SHAPE*>( graphicItem->Duplicate( true, &commit ) );
6243
6244 newArc->ClearSelected();
6245 newArc->SetEnd( arc.GetP1() );
6246 newArc->SetStart( nearestPoint );
6247
6248 commit.Add( newArc );
6249 commit.Push( _( "Split Arc" ) );
6250 break;
6251 }
6252 default:
6253 // No split implemented for other shapes
6254 break;
6255 }
6256 }
6257
6258 updatePoints();
6259 return 0;
6260}
6261
6262
6264{
6265 if( !m_editPoints || !m_editedPoint )
6266 return 0;
6267
6268 EDA_ITEM* item = m_editPoints->GetParent();
6269
6270 if( !item )
6271 return 0;
6272
6273 SHAPE_POLY_SET* polygon = nullptr;
6274
6275 if( item->Type() == PCB_ZONE_T )
6276 {
6277 ZONE* zone = static_cast<ZONE*>( item );
6278 polygon = zone->Outline();
6279 zone->SetNeedRefill( true );
6280 }
6281 else if( item->Type() == PCB_SHAPE_T )
6282 {
6283 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
6284
6285 if( shape->GetShape() == SHAPE_T::POLY )
6286 polygon = &shape->GetPolyShape();
6287 }
6288
6289 if( !polygon )
6290 return 0;
6291
6293 BOARD_COMMIT commit( frame );
6294 auto vertex = findVertex( *polygon, *m_editedPoint );
6295
6296 if( vertex.first )
6297 {
6298 const auto& vertexIdx = vertex.second;
6299 auto& outline = polygon->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour];
6300
6301 if( outline.PointCount() > 3 )
6302 {
6303 // the usual case: remove just the corner when there are >3 vertices
6304 commit.Modify( item );
6305 polygon->RemoveVertex( vertexIdx );
6306
6307 // Members only exist on hole free shape polygons where contour relative ordinal is member
6308 // index removed vertex member retires its constraint later ordinals shift down issue 2329
6309 if( item->Type() == PCB_SHAPE_T && vertexIdx.m_contour == 0 )
6310 {
6311 RemapPolygonVertexMembers( frame->GetBoard(), item->m_Uuid, vertexIdx.m_vertex, -1,
6312 [&]( BOARD_ITEM* aConstraint ) { commit.Modify( aConstraint ); },
6313 [&]( BOARD_ITEM* aConstraint ) { commit.Remove( aConstraint ); } );
6314 }
6315 }
6316 else
6317 {
6318 // either remove a hole or the polygon when there are <= 3 corners
6319 if( vertexIdx.m_contour > 0 )
6320 {
6321 // remove hole
6322 commit.Modify( item );
6323 polygon->RemoveContour( vertexIdx.m_contour );
6324 }
6325 else
6326 {
6327 m_toolMgr->RunAction( ACTIONS::selectionClear );
6328 commit.Remove( item );
6329 }
6330 }
6331
6332 setEditedPoint( nullptr );
6333
6334 if( item->Type() == PCB_ZONE_T )
6335 commit.Push( _( "Remove Zone Corner" ) );
6336 else
6337 commit.Push( _( "Remove Polygon Corner" ) );
6338
6339 if( item->Type() == PCB_ZONE_T )
6340 static_cast<ZONE*>( item )->HatchBorder();
6341
6342 updatePoints();
6343 }
6344
6345 return 0;
6346}
6347
6348
6350{
6351 if( !m_editPoints || !m_editedPoint )
6352 return 0;
6353
6354 EDA_ITEM* item = m_editPoints->GetParent();
6355
6356 if( !item )
6357 return 0;
6358
6359 SHAPE_POLY_SET* polygon = nullptr;
6360
6361 if( item->Type() == PCB_ZONE_T )
6362 {
6363 ZONE* zone = static_cast<ZONE*>( item );
6364 polygon = zone->Outline();
6365 zone->SetNeedRefill( true );
6366 }
6367 else if( item->Type() == PCB_SHAPE_T )
6368 {
6369 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
6370
6371 if( shape->GetShape() == SHAPE_T::POLY )
6372 polygon = &shape->GetPolyShape();
6373 }
6374
6375 if( !polygon )
6376 return 0;
6377
6378 // Search the best outline corner to break
6379
6381 BOARD_COMMIT commit( frame );
6382 const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
6383
6384 unsigned int nearestIdx = 0;
6385 unsigned int nearestDist = INT_MAX;
6386
6387 int curr_idx = 0;
6388 // Object to iterate through the corners of the outlines (main contour and its holes)
6389 SHAPE_POLY_SET::ITERATOR iterator = polygon->Iterate( 0, polygon->OutlineCount() - 1,
6390 /* IterateHoles */ true );
6391
6392 // Iterate through all the corners of the outlines and search the best segment
6393 for( ; iterator; iterator++, curr_idx++ )
6394 {
6395 unsigned int distance = polygon->CVertex( curr_idx ).Distance( cursorPos );
6396
6397 if( distance < nearestDist )
6398 {
6399 nearestDist = distance;
6400 nearestIdx = curr_idx;
6401 }
6402 }
6403
6404 int prevIdx, nextIdx;
6405 if( polygon->GetNeighbourIndexes( nearestIdx, &prevIdx, &nextIdx ) )
6406 {
6407 const SEG segA{ polygon->CVertex( prevIdx ), polygon->CVertex( nearestIdx ) };
6408 const SEG segB{ polygon->CVertex( nextIdx ), polygon->CVertex( nearestIdx ) };
6409
6410 // A plausible setback that won't consume a whole edge
6411 int setback = pcbIUScale.mmToIU( 5 );
6412 setback = std::min( setback, (int) ( segA.Length() * 0.25 ) );
6413 setback = std::min( setback, (int) ( segB.Length() * 0.25 ) );
6414
6415 CHAMFER_PARAMS chamferParams{ setback, setback };
6416
6417 std::optional<CHAMFER_RESULT> chamferResult = ComputeChamferPoints( segA, segB, chamferParams );
6418
6419 if( chamferResult && chamferResult->m_updated_seg_a && chamferResult->m_updated_seg_b )
6420 {
6421 commit.Modify( item );
6422 polygon->RemoveVertex( nearestIdx );
6423
6424 // The two end points of the chamfer are the new corners
6425 polygon->InsertVertex( nearestIdx, chamferResult->m_updated_seg_b->B );
6426 polygon->InsertVertex( nearestIdx, chamferResult->m_updated_seg_a->B );
6427
6428 // Chamfered corner constraints retire members past it net one higher insert pass must run
6429 // first threshold nearestIdx plus 1 deleting first nets negative one instead issue 2329
6430 if( item->Type() == PCB_SHAPE_T && nearestIdx < (unsigned) polygon->COutline( 0 ).PointCount() )
6431 {
6432 auto modify = [&]( BOARD_ITEM* aConstraint ) { commit.Modify( aConstraint ); };
6433 auto remove = [&]( BOARD_ITEM* aConstraint ) { commit.Remove( aConstraint ); };
6434
6435 RemapPolygonVertexMembers( frame->GetBoard(), item->m_Uuid, (int) nearestIdx + 1, 2, modify, remove );
6436 RemapPolygonVertexMembers( frame->GetBoard(), item->m_Uuid, (int) nearestIdx, -1, modify, remove );
6437 }
6438 }
6439 }
6440
6441 setEditedPoint( nullptr );
6442
6443 if( item->Type() == PCB_ZONE_T )
6444 commit.Push( _( "Break Zone Corner" ) );
6445 else
6446 commit.Push( _( "Break Polygon Corner" ) );
6447
6448 if( item->Type() == PCB_ZONE_T )
6449 static_cast<ZONE*>( item )->HatchBorder();
6450
6451 updatePoints();
6452
6453 return 0;
6454}
6455
6456
6458{
6459 updatePoints();
6460 return 0;
6461}
6462
6463
6465{
6467
6468 if( aEvent.Matches( ACTIONS::cycleArcEditMode.MakeEvent() ) )
6469 {
6470 if( editFrame->IsType( FRAME_PCB_EDITOR ) )
6472 else
6474
6476 }
6477 else
6478 {
6480 }
6481
6482 if( editFrame->IsType( FRAME_PCB_EDITOR ) )
6484 else
6486
6487 return 0;
6488}
6489
6490
6492{
6510}
BOX2I getBoundingBox(BOARD_ITEM *aItem)
ARC_EDIT_MODE
Settings for arc editing.
@ KEEP_ENDPOINTS_OR_START_DIRECTION
Whe editing endpoints, the other end remains in place.
@ KEEP_CENTER_ADJUST_ANGLE_RADIUS
When editing endpoints, the angle and radius are adjusted.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
bool BlockDragIsConstraintMember(const BOARD_ITEM &aItem)
True when the item belongs to any geometric constraint on its board or inside one of its footprints.
BLOCK_DRAG_CAPABILITY BlockDragCapability(const BOARD_ITEM &aItem)
Classify one board item for a block drag.
std::vector< BOARD_ITEM * > BlockDragExpandSelection(const std::vector< BOARD_ITEM * > &aSelection)
Replace group containers with their members, through nested groups, and drop duplicates.
bool BlockDragAnchorEditingEnabled(const PCB_BASE_FRAME *aFrame)
Whether the user has turned on editing anchor points on a multi-selection.
BLOCK_DRAG_CAPABILITY
How one selected item takes part in a block drag.
@ UNSUPPORTED
Stops the drag with a message before anything moves.
@ DEFORMABLE
Shows handles, and reshapes as the user drags the ones they picked.
@ ROUTER
Moves with the block through the router, which repairs the copper at the edge of the block.
BLOCK_DRAG_DEPENDENT_RESULT BlockDragFindDependents(const std::vector< PCB_SHAPE * > &aCandidates, const std::vector< BLOCK_DRAG_ENDPOINT > &aMovedEndpoints, bool aOverrideLocks, std::vector< BLOCK_DRAG_ENDPOINT > &aDependents)
Find the joined endpoints that have to follow the ones the drag moves.
@ LOCKED
A shape that would have to follow is locked and Override Locks is off, so the drag has to stop.
@ WHOLE
The whole shape moves, for a shape that moving one end alone would distort.
bool BlockDragApplyDisplacement(const std::vector< EDIT_POINTS * > &aCollections, const std::map< PCB_HANDLE_KEY, VECTOR2I > &aOrigins, const VECTOR2I &aDelta, const GRID_HELPER &aGrid)
Put every handle at its starting position plus the drag's offset.
std::map< PCB_HANDLE_KEY, VECTOR2I > BlockDragMoveOrigins(const std::vector< EDIT_POINTS * > &aCollections, const std::set< PCB_HANDLE_KEY > &aPicked)
Note every handle the drag will move, and where each one started.
SHAPE_LINE_CHAIN BlockDragPickRect(const VECTOR2I &aFirst, const VECTOR2I &aSecond)
The closed rectangle a box pick covers, built from two opposite corners.
bool BlockDragHandlePickable(const EDIT_POINTS &aCollection, const EDIT_POINT &aPoint)
True when the user is allowed to pick this handle.
void BlockDragApplyPick(std::set< PCB_HANDLE_KEY > &aPicked, const PCB_HANDLE_KEY &aKey, bool aAccumulate)
Add one clicked handle to the picked set.
void BlockDragLassoPick(const std::vector< EDIT_POINTS * > &aCollections, const SHAPE_LINE_CHAIN &aLasso, bool aAccumulate, std::set< PCB_HANDLE_KEY > &aPicked)
Add the handles a lasso surrounds to the picked set.
BLOCK_DRAG_VALIDATION_RESULT
@ INVALID_ZONE
A zone that came along lost its valid outline.
#define ZONE_FILL_OP
std::vector< VECTOR2I > ConstraintPinnedPositions(BOARD *aBoard, const std::set< KIID > &aItems)
The distinct board positions that fixed positions pin on aItems.
void ReSolveAfterShapeResize(BOARD *aBoard, PCB_SHAPE *aShape, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Re-solve after a resize, e.g. a circle radius edit. Holds aShape fixed so its neighbors adjust.
bool BoardHasConstraints(BOARD *aBoard)
True if aBoard resolves at least one geometric constraint (see CollectResolvedConstraints()).
CONSTRAINT_DIAGNOSIS SolveCluster(BOARD *aBoard, const CONSTRAINT_MEMBER &aDragged, const VECTOR2I &aCursor, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify, bool aIncludeDragged, bool aStabilize, const std::set< KIID > &aEdited, const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aCoDragged, const std::set< KIID > &aFixedShapes, bool aHoldDraggedRigid)
Gather the cluster of shapes transitively constrained with the dragged shape, solve with the dragged ...
bool ReSolveShapeClustersHoldingEdited(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aEditedShapes, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Re-solve clusters whose new geometry is authoritative holding every edited shape fully fixed so only ...
bool ConstraintItemIsLocked(const BOARD_ITEM *aItem)
True when the solver must treat aItem as immovable, either locked itself or living inside a locked fo...
CONSTRAINT_BLOCK_RESULT
How a block edit solve turned out.
@ REFUSED
No arrangement fits the pinned points, and the geometry is untouched.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static TOOL_ACTION gridFastCycle
Definition actions.h:189
static TOOL_ACTION toggleGrid
Definition actions.h:195
static TOOL_ACTION zoomRedraw
Definition actions.h:129
static TOOL_ACTION gridFast1
Definition actions.h:187
static TOOL_ACTION gridPrev
Definition actions.h:191
static TOOL_ACTION cursorLeft
Definition actions.h:169
static TOOL_ACTION zoomOutCenter
Definition actions.h:133
static TOOL_ACTION togglePolarCoords
Definition actions.h:206
static TOOL_ACTION zoomIn
Definition actions.h:130
static TOOL_ACTION cursorLeftFast
Definition actions.h:174
static TOOL_ACTION cycleArcEditMode
Definition actions.h:273
static TOOL_ACTION gridPreset
Definition actions.h:194
static TOOL_ACTION cursorDown
Definition actions.h:168
static TOOL_ACTION zoomOut
Definition actions.h:131
static TOOL_ACTION pointEditorArcKeepCenter
Definition actions.h:274
static TOOL_ACTION cursorRightFast
Definition actions.h:175
static TOOL_ACTION deleteLastPoint
Definition actions.h:272
static TOOL_ACTION toggleCursor
Definition actions.h:148
static TOOL_ACTION pointEditorArcKeepRadius
Definition actions.h:276
static TOOL_ACTION zoomCenter
Definition actions.h:138
static TOOL_ACTION panDown
Definition actions.h:182
static TOOL_ACTION cursorDblClick
Definition actions.h:178
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION cursorDownFast
Definition actions.h:173
static TOOL_ACTION reselectItem
Definition actions.h:226
static TOOL_ACTION cursorUpFast
Definition actions.h:172
static TOOL_ACTION panLeft
Definition actions.h:183
static TOOL_ACTION updateMenu
Definition actions.h:268
static TOOL_ACTION activatePointEditor
Definition actions.h:269
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION cursorClick
Definition actions.h:177
static TOOL_ACTION zoomFitScreen
Definition actions.h:139
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION panUp
Definition actions.h:181
static TOOL_ACTION zoomFitObjects
Definition actions.h:140
static TOOL_ACTION zoomInCenter
Definition actions.h:132
static TOOL_ACTION panRight
Definition actions.h:184
static TOOL_ACTION gridFast2
Definition actions.h:188
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition actions.h:167
static TOOL_ACTION refreshPreview
Definition actions.h:156
static TOOL_ACTION toggleGridOverrides
Definition actions.h:196
static TOOL_ACTION finishInteractive
Definition actions.h:70
static TOOL_ACTION gridNext
Definition actions.h:190
static TOOL_ACTION cursorRight
Definition actions.h:170
static TOOL_ACTION pointEditorArcKeepEndpoint
Definition actions.h:275
void updateOrthogonalDimension(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints)
Update orthogonal dimension points.
ALIGNED_DIMENSION_POINT_EDIT_BEHAVIOR(PCB_DIM_ALIGNED &aDimension)
void updateAlignedDimension(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints)
Update non-orthogonal dimension points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
BARCODE_POINT_EDIT_BEHAVIOR(PCB_BARCODE &aBarcode)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool collectTargets()
Pair every collection that holds a moved point with its behavior.
KIGFX::COLOR4D bandColor() const
Band colour for the area picks, kept clear of the canvas colour.
PCB_GRID_HELPER & m_grid
PCB_POINT_EDITOR & m_editor
bool KeyboardDrag() const
Whether this drag runs from the keyboard, so motion moves it and a click places it.
void releaseState()
Put the view, the flags and the router back, and drop the gesture's state.
bool Refused() const
Whether the last start was refused, in which case the gesture has already said why.
bool IsActive() const
Whether a drag is running.
bool runLasso(const TOOL_EVENT &aEvent)
Pick handles with a lasso, the way the object lasso works.
std::vector< BOARD_ITEM * > m_moving
Everything that moves with the cursor, kept out of the snap targets so the block cannot chase its own...
std::vector< std::shared_ptr< EDIT_POINTS > > m_dependentDisplays
bool m_keyboardDrag
Started with D, so motion moves it and a click places it.
std::set< KIID > m_constraintTranslated
bool m_refused
The last start was declined and said why itself.
BOARD_ITEM * m_refParent
The grabbed handle's snapping context, taken once at the start.
bool runBox(const TOOL_EVENT &aEvent)
Pick handles with a box, which finishes on release like normal box selection.
SNAP_CONSTRAINT_TYPE m_snapConstraint
bool m_pressConsumed
The rest of a swallowed button press is still to be ignored.
FRAME_RESULT applyFrame(const VECTOR2I &aDelta, std::vector< EDA_ITEM * > &aUpdated)
Write one frame.
std::optional< BLOCK_DRAG_VALIDATION > m_validation
The baseline the zone and board outline checks compare the released geometry against.
bool m_active
A drag is running.
void hideBand(HANDLE_PICK_AREA &aArea)
bool Begin(const VECTOR2I &aOrigin, bool aPressInFlight)
Start a drag from the handle at aOrigin.
FRAME_RESULT
How one frame of the gesture turned out.
@ LOST_IDENTITY
A picked handle has gone, so the gesture has to stop.
@ CONSTRAINED
A constraint blocks this frame, and the board is untouched.
@ APPLIED
The frame's geometry went onto the board.
bool ApplyCursor(const TOOL_EVENT &aEvent)
Place one frame of the drag. True when the editor has to leave its loop.
std::vector< BLOCK_DRAG_ENDPOINT > m_dependents
Unselected ends that sit on a moved joint and follow it, with the handle drawn at each one.
bool m_routerActive
A router drag session is carrying the block's copper.
bool RunAreaPick(const TOOL_EVENT &aEvent)
Run the lasso or the box, whichever the selection mode asks for.
bool m_revertRestarts
Undo will hand out fresh objects, so the editor has to start again from the live selection.
std::optional< BOARD_CONSTRAINT_BLOCK_SESSION > m_constraintSession
std::map< PCB_HANDLE_KEY, VECTOR2I > m_origins
Where each picked handle stood when the gesture began.
void endDrag(bool aKeepPicks)
End the gesture and rebuild the handles.
std::vector< std::pair< PCB_SHAPE *, CONSTRAINT_MEMBER > > m_constraintAnchors
What the solve holds fixed: the anchors the gesture placed itself, and the items it carried whole,...
std::set< PCB_SHAPE * > m_solverBrightened
Neighbours the solve pulled along, brightened so the user can see what moved with the block.
BLOCK_DRAG_SESSION(PCB_POINT_EDITOR &aEditor, PCB_BASE_EDIT_FRAME *aEditFrame, PCB_GRID_HELPER &aGrid, BOARD_COMMIT &aCommit)
bool m_constraintWarned
Said once, not per frame.
VECTOR2I m_appliedDelta
The last offset written to the board, which is what a refused frame is undone with.
bool revert(bool aPushed)
Undo the gesture.
bool Release(const TOOL_EVENT &aEvent)
Finish the drag and push what it changed. True when the editor has to leave its loop.
std::vector< std::pair< EDIT_POINTS *, POINT_EDIT_BEHAVIOR * > > m_targets
Each collection holding a picked handle, with the behavior that rebuilds its item.
bool refuseRelease(const wxString &aMessage)
Say why the release was refused and put the board back, keeping the picks so the user can try again f...
std::vector< KIID > m_overlayHidden
Copper whose selection overlay is hidden while the router preview stands in for it,...
GRID_HELPER_GRIDS m_refGrid
void Abort()
Undo a drag that is still running, for the exits that miss the release and cancel paths.
bool Cancel(TOOL_EVENT &aEvent)
Undo the drag, keeping the picks. True when the editor has to leave its loop.
PCB_BASE_EDIT_FRAME * m_editFrame
std::vector< BOARD_ITEM * > m_rigidItems
Selected items with no picked handle, which travel whole as they would under the move tool.
bool AreaPickStarts(const TOOL_EVENT &aEvent)
Whether a drag starting on empty canvas should pick handles by area.
void showBand(HANDLE_PICK_AREA &aArea)
Put the pick band on the view and take the cursor for it, and take it off again.
bool PressConsumed() const
Whether the rest of a swallowed button press is still to be ignored.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE) override
Add a change of the item aItem of type aChangeType to the change list.
void Revert() override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
bool IsLocked() const override
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:369
int GetMaxError() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
Definition board.h:441
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2176
constexpr void SetMaximum()
Definition box2.h:77
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr Vec Centre() const
Definition box2.h:100
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
int ShowModal() override
Class to help update the text position of a dimension when the crossbar changes.
DIM_ALIGNED_TEXT_UPDATER(PCB_DIM_ALIGNED &aDimension)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
DIM_CENTER_POINT_EDIT_BEHAVIOR(PCB_DIM_CENTER &aDimension)
DIM_LEADER_POINT_EDIT_BEHAVIOR(PCB_DIM_LEADER &aDimension)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
DIM_RADIAL_POINT_EDIT_BEHAVIOR(PCB_DIM_RADIAL &aDimension)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
double AsDegrees() const
Definition eda_angle.h:115
bool IsType(FRAME_T aType) const
bool GetOverrideLocks() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:314
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearSelected()
Definition eda_item.h:153
EDA_ITEM * GetParent() const
Definition eda_item.h:112
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:288
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
virtual VECTOR2I GetTopLeft() const
Definition eda_shape.h:365
SHAPE_POLY_SET & GetPolyShape()
SHAPE_T GetShape() const
Definition eda_shape.h:178
virtual VECTOR2I GetBotRight() const
Definition eda_shape.h:366
virtual void SetBottom(int val)
Definition eda_shape.h:371
virtual void SetTop(int val)
Definition eda_shape.h:368
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
virtual void SetLeft(int val)
Definition eda_shape.h:369
virtual void SetRight(int val)
Definition eda_shape.h:370
int GetCornerRadius() const
VECTOR2I GetArcMid() const
Represent a line connecting two EDIT_POINTs.
POLYGON_EDGE_DRAG_POLICY * GetDragPolicy() const
void SetRelation(std::unique_ptr< EDIT_RELATION > aRelation)
Set a relation for an EDIT_LINE.
EDIT_POINT & GetEnd()
Return the end EDIT_POINT.
EDIT_POINT & GetOrigin()
Return the origin EDIT_POINT.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
unsigned int PointsSize() const
Return number of stored EDIT_POINTs.
void AddPoint(const EDIT_POINT &aPoint)
Add an EDIT_POINT.
void SetSwapY(bool aSwap)
void Clear()
Clear all stored EDIT_POINTs and EDIT_LINEs.
EDIT_LINE & Line(unsigned int aIndex)
void AddIndicatorLine(EDIT_POINT &aOrigin, EDIT_POINT &aEnd)
Adds an EDIT_LINE that is shown as an indicator, rather than an editable line (no center point drag,...
void SetLineStateVisible(bool aShow)
bool SwapX() const
bool SwapY() const
void SetSwapX(bool aSwap)
EDA_ITEM * GetParent() const
Return parent of the EDIT_POINTS.
unsigned int LinesSize() const
Return number of stored EDIT_LINEs.
EDIT_POINT & Point(unsigned int aIndex)
void AddLine(const EDIT_LINE &aLine)
Adds an EDIT_LINE.
Represent a single point that can be used for modifying items.
Definition edit_points.h:44
void SetDrivesWholeShape(bool aDrives=true)
SNAP_CONSTRAINT_TYPE GetSnapConstraint() const
virtual void SetPosition(const VECTOR2I &aPosition)
Set new coordinates for an EDIT_POINT.
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
Definition edit_points.h:72
void SetSnapConstraint(SNAP_CONSTRAINT_TYPE aConstraint)
void SetSelected(bool aSelected=true)
int GetX() const
Return X coordinate of an EDIT_POINT.
Definition edit_points.h:88
void SetRelation(std::unique_ptr< EDIT_RELATION > aRelation)
Set a relation for an EDIT_POINT.
void SetActive(bool aActive=true)
void SetDrawCircle(bool aDrawCircle=true)
static std::unique_ptr< EDIT_RELATION > Angle90(const EDIT_POINT &aReference)
static std::unique_ptr< EDIT_RELATION > Angle45(const EDIT_POINT &aReference)
static std::unique_ptr< EDIT_RELATION > PerpendicularTranslation(const EDIT_LINE &aLine)
const VECTOR2I & Direction() const
static std::unique_ptr< EDIT_RELATION > PointOnLine(const EDIT_POINT &aConstrained, const EDIT_POINT &aReference)
EDIT_RELATION_KIND Kind() const
static const TOOL_EVENT InhibitSelectionEditing
Used to inform tools that the selection should temporarily be non-editable.
Definition actions.h:360
static const TOOL_EVENT SelectedEvent
Definition actions.h:347
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:354
static const TOOL_EVENT UninhibitSelectionEditing
Definition actions.h:361
static const TOOL_EVENT PointSelectedEvent
Definition actions.h:346
static const TOOL_EVENT SelectedItemsMoved
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:357
static const TOOL_EVENT UnselectedEvent
Definition actions.h:348
ZONES & Zones()
Definition footprint.h:361
std::deque< PAD * > & Pads()
Definition footprint.h:355
DRAWINGS & GraphicalItems()
Definition footprint.h:358
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
GENERATOR_POINT_EDIT_BEHAVIOR(PCB_GENERATOR &aGenerator)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
GENERATOR_POLY_POINT_EDIT_BEHAVIOR(PCB_GENERATOR_POLY &aGen)
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
Handle actions specific to filling copper zones.
VECTOR2I toLocal(const VECTOR2I &aWorld) const
GRID_POINT_EDIT_BEHAVIOR(PCB_GRID_ITEM &aGridItem)
VECTOR2I cornerLocal(int aX, int aY) const
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
VECTOR2I toWorld(const VECTOR2I &aLocal) const
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition color4d.h:309
COLOR4D & Invert()
Makes the color inverted, alpha remains the same.
Definition color4d.h:239
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:87
SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily dem...
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:365
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition view.cpp:488
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllLayersMask()
Definition lset.cpp:637
static constexpr PCB_LAYER_ID TEMP_ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:181
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
PAD_POINT_EDIT_BEHAVIOR(PAD &aPad, PCB_LAYER_ID aLayer)
Definition pad.h:61
ARC_EDIT_MODE m_ArcEditMode
static TOOL_ACTION drag45Degree
static TOOL_ACTION layerChanged
static TOOL_ACTION pointEditorMoveMidpoint
static TOOL_ACTION genFinishEdit
static TOOL_ACTION genStartEdit
static TOOL_ACTION pointEditorMoveCorner
static TOOL_ACTION genCancelEdit
static TOOL_ACTION dragFreeAngle
static TOOL_ACTION genUpdateEdit
static TOOL_ACTION pointEditorChamferCorner
static TOOL_ACTION pointEditorRemoveCorner
static TOOL_ACTION pointEditorAddCorner
Common, abstract interface for edit frames.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
A geometric constraint between board items (issue #2329).
For better understanding of the points that make a dimension:
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
void SetOrientation(DIR aOrientation)
Set the orientation of the dimension line (so, perpendicular to the feature lines).
DIR GetOrientation() const
A radial dimension indicates either the radius or diameter of an arc or circle.
virtual wxString GetCommitMessage() const =0
virtual void EditStart(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
bool IsDirty() const
Dirty flag system to for determining if generator output is not up to date It is up to each generator...
virtual bool Update(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
virtual void EditFinish(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
static std::optional< PCB_HANDLE_KEY > Make(const EDIT_POINTS &aPoints, const EDIT_POINT *aPoint)
Build the key for a handle in a collection.
Tool that displays edit points allowing to modify items by dragging the points.
friend class BLOCK_DRAG_SESSION
int changeArcEditMode(const TOOL_EVENT &aEvent)
Change the edit method for arcs.
void updateBlockHandlePoints()
Move those handles back onto their items after the geometry changed.
bool CanRemoveCorner(const SELECTION &aSelection)
Condition to display "Remove Corner" context menu entry.
void updateItem(BOARD_COMMIT &aCommit)
Update item's points with edit points.
void setPickedHandles(std::set< PCB_HANDLE_KEY > aPicked)
Replace the picked set and repaint the handles to match it.
VECTOR2I m_stickyDisplacement
void updateBlockHandleHover(const VECTOR2I &aPosition)
Highlight the handle under the cursor, if there is one.
int OnSelectionChange(const TOOL_EVENT &aEvent)
Change selection event handler.
void applyPickedFlags()
Paint the picked handles, dropping keys whose handle has gone.
void setAltConstraint(bool aEnabled)
Set up an alternative constraint (typically enabled upon a modifier key being pressed).
static const unsigned int COORDS_PADDING
bool HasBlockHandle() const
True when the cursor sits on a handle the user can pick.
EDIT_POINT * m_hoveredPoint
bool blockAnchorEditingEnabled() const
Whether the user has turned on anchor point handles for multi-selections.
int addCorner(const TOOL_EVENT &aEvent)
EDIT_POINTS * m_blockHoveredOwner
bool HasPoint()
Indicate the cursor is over an edit point.
EDIT_POINT m_original
Original pos for the current drag point.
static bool CanChamferCorner(const EDA_ITEM &aItem)
Check if a corner of the given item can be chamfered (zones, polys only).
EDIT_POINT get45DegConstrainer() const
Return a point that should be used as a constrainer for 45 degrees mode.
int modifiedSelection(const TOOL_EVENT &aEvent)
EDIT_POINT * m_blockHoveredPoint
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
std::unique_ptr< POINT_EDIT_BEHAVIOR > makeBehavior(EDA_ITEM *aItem, bool &aRejected)
Create the point edit behavior for an item.
void clearPickedHandles()
Unpick everything and redraw.
std::unique_ptr< POINT_EDIT_BEHAVIOR > m_editorBehavior
int removeCorner(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
std::shared_ptr< BOARD_CONSTRAINT_DRAG_SESSION > m_constraintDragSession
std::unique_ptr< EDIT_RELATION > m_altConstraint
RECT_RADIUS_TEXT_ITEM * m_radiusHelper
std::set< PCB_HANDLE_KEY > m_pickedHandles
int bboxHandleInflation() const
Gap to leave between the scaling box handles and the shapes' own handles, in board units for the curr...
std::vector< BLOCK_HANDLE_ENTRY > m_blockHandles
PCB_SELECTION m_preview
int movePoint(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
static bool CanAddCorner(const EDA_ITEM &aItem)
Check if a corner can be added to the given item (zones, polys, segments, arcs).
void setEditedPoint(EDIT_POINT *aPoint)
Set the current point being edited. NULL means none.
bool pickHandleAt(const VECTOR2I &aPosition, bool aAccumulate)
Pick the handle under aPosition. Returns false when there is no handle to pick.
EDIT_POINT m_altConstrainer
bool isModified(const EDIT_POINT &aPoint) const
Return true if aPoint is the currently modified point.
std::vector< EDIT_POINTS * > pickableCollections()
The handle collections the user can pick from.
ARC_EDIT_MODE m_arcEditMode
std::unique_ptr< KIGFX::PREVIEW::ANGLE_ITEM > m_angleItem
EDIT_POINT * m_editedPoint
void updateEditedPoint(const TOOL_EVENT &aEvent)
Update which point is being edited.
int getEditedPointIndex() const
void updatePoints()
Update edit points with item's points.
int chamferCorner(const TOOL_EVENT &aEvent)
void clearBlockHandles()
Take those handles off the view and throw them away.
std::vector< BOARD_ITEM * > m_expandedSelection
void setTransitions() override
Set up handlers for various events.
std::shared_ptr< EDIT_POINTS > m_editPoints
PCB_BASE_FRAME * m_frame
std::shared_ptr< EDIT_POINTS > makePoints(EDA_ITEM *aItem)
void buildBlockHandles(const PCB_SELECTION &aSelection)
Build the handles shown for every reshapeable item in a multi-selection or group.
std::function< void()> m_blockDragAbort
PCB_SELECTION_TOOL * m_selectionTool
Object to handle a bitmap image that can be inserted in a PCB.
REFERENCE_IMAGE & GetReferenceImage()
The selection tool: currently supports:
void SetCornerRadius(int aCornerRadius) override
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:80
void SetEnd(const VECTOR2I &aEnd) override
bool IsProxyItem() const override
Definition pcb_shape.h:155
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetStart(const VECTOR2I &aStart) override
VECTOR2I unturned(const VECTOR2I &aPoint) const
VECTOR2I edgeMidpoint(TABLECELL_POINTS aPoint) const
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
PCB_TABLECELL_POINT_EDIT_BEHAVIOR(PCB_TABLECELL &aCell)
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
T * frame() const
KIGFX::PCB_VIEW * view() const
virtual bool Is45Limited() const
Should the tool use its 45° mode option?
KIGFX::VIEW_CONTROLS * controls() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
virtual bool Is90Limited() const
Should the tool limit drawing to horizontal and vertical only?
const PCB_SELECTION & selection() const
virtual bool GetForceMarkObstaclesMode(bool *aDragStatus) const =0
int Size() const
void Add(const LINE &aLine)
Base class for PNS router board items.
Definition pns_item.h:98
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
Keep the router "world" - i.e.
Definition pns_node.h:274
std::vector< ITEM * > FindItemsByParent(const BOARD_ITEM *aParent)
void StopRouting()
void SyncWorld()
ROUTING_SETTINGS & Settings()
Definition pns_router.h:240
DRAG_ALGO * GetDragger()
Definition pns_router.h:187
bool RoutingInProgress() const
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish, bool aForceCommit)
NODE * GetWorld() const
Definition pns_router.h:212
bool Move(const VECTOR2I &aP, ITEM *aItem)
ROUTER * Router() const
PNS_KICAD_IFACE * GetInterface() const
void SetBoard(BOARD *aBoard)
void SetView(KIGFX::VIEW *aView)
void SetIndependentPads(const std::set< PAD * > &aPads)
Pads that move on their own. A moved pad otherwise carries its footprint.
void SetCommitFlags(int aCommitFlags)
A helper class interface to manage the edit points for a single item.
virtual void MakePoints(EDIT_POINTS &aPoints)=0
Construct the initial set of edit points for the item and append to the given list.
static bool isModified(const EDIT_POINT &aEditedPoint, const EDIT_POINT &aPoint)
Checks if two points are the same instance - which means the point is being edited.
void SetMode(POLYGON_LINE_MODE aMode)
POLYGON_LINE_MODE GetMode() const
const VECTOR2I & GetOriginalCenter() const
const VECTOR2I & GetPerpVector() const
static void UpdateOutlineFromPoints(SHAPE_POLY_SET &aOutline, const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints)
Update the polygon outline with the new positions of the edit points.
static void UpdatePointsFromOutline(const SHAPE_POLY_SET &aOutline, EDIT_POINTS &aPoints)
Update the edit points with the current polygon outline.
POLYGON_POINT_EDIT_BEHAVIOR(SHAPE_POLY_SET &aPolygon)
static void BuildForPolyOutline(EDIT_POINTS &aPoints, const SHAPE_POLY_SET &aOutline)
Build the edit points for the given polygon outline.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
static void RemoveNullSegmentsIfPolygonSurvives(SHAPE_POLY_SET &aOutline)
Remove the zero length segments left by an edit, unless that would strip the outline down to somethin...
static void UpdateItem(SCH_SHAPE &aRect, const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, const VECTOR2I &aMinSize={ 0, 0 })
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
static void UpdateItem(PCB_SHAPE &aRectangle, const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, const VECTOR2I &aMinSize={ 0, 0 })
static void UpdatePoints(SCH_SHAPE &aRect, EDIT_POINTS &aPoints)
static void PinEditedCorner(const EDIT_POINT &aEditedPoint, const EDIT_POINTS &aPoints, int minWidth, int minHeight, VECTOR2I &topLeft, VECTOR2I &topRight, VECTOR2I &botLeft, VECTOR2I &botRight)
Update the coordinates of 4 corners of a rectangle, according to constraints and the moved corner.
static void PinEditedCorner(const EDIT_POINT &aEditedPoint, const EDIT_POINTS &aEditPoints, VECTOR2I &aTopLeft, VECTOR2I &aTopRight, VECTOR2I &aBotLeft, VECTOR2I &aBotRight, const VECTOR2I &aHole={ 0, 0 }, const VECTOR2I &aHoleSize={ 0, 0 }, const VECTOR2I &aMinSize={ 0, 0 })
Update the coordinates of 4 corners of a rectangle, according to constraints and the moved corner.
static void MakePoints(SCH_SHAPE &aRect, EDIT_POINTS &aPoints)
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
static void MakePoints(const PCB_SHAPE &aRectangle, EDIT_POINTS &aPoints)
Standard rectangle points construction utility (other shapes may use this as well)
static void UpdatePoints(const PCB_SHAPE &aRectangle, EDIT_POINTS &aPoints)
RECTANGLE_POINT_EDIT_BEHAVIOR(PCB_SHAPE &aRectangle)
const EDA_IU_SCALE & m_iuScale
wxString GetClass() const override
Return the class name.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void Set(int aRadius, const VECTOR2I &aCorner, const VECTOR2I &aQuadrant, EDA_UNITS aUnits)
RECT_RADIUS_TEXT_ITEM(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
void SetMessage(const wxString &aStatus)
void SetHint(const wxString &aHint)
void SetPosition(const VECTOR2I &aPos) override
Definition seg.h:38
VECTOR2I B
Definition seg.h:46
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition seg.cpp:599
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition seg.cpp:668
EDA_ANGLE Angle(const SEG &aOther) const
Determine the smallest angle between two segments.
Definition seg.cpp:66
Class that groups generic conditions for selected items.
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
EDA_ITEM * Front() const
Definition selection.h:176
int Size() const
Returns the number of selected parts.
Definition selection.h:120
VECTOR2I NearestPoint(const VECTOR2I &aP) const
const VECTOR2I & GetP1() const
Definition shape_arc.h:115
std::optional< VECTOR2I > m_pinned
const std::vector< PCB_SHAPE * > & GetShapes() const
SHAPE_GROUP_POINT_EDIT_BEHAVIOR(PCB_GROUP &aGroup)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
std::unordered_map< PCB_SHAPE *, double > m_originalWidths
std::vector< PCB_SHAPE * > m_shapes
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
SHAPE_GROUP_POINT_EDIT_BEHAVIOR(std::vector< PCB_SHAPE * > aShapes, BOARD_ITEM *aParent, const std::optional< VECTOR2I > &aPinned)
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual size_t GetPointCount() const override
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
Represent a set of closed polygons.
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR IterateWithHoles(int aOutline)
void InsertVertex(int aGlobalIndex, const VECTOR2I &aNewVertex)
Adds a vertex in the globally indexed position aGlobalIndex.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
ITERATOR Iterate(int aFirst, int aLast, bool aIterateHoles=false)
Return an object to iterate through the points of the polygons between aFirst and aLast.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
A textbox is edited as a rectnagle when it is orthogonally aligned.
TEXTBOX_POINT_EDIT_BEHAVIOR(PCB_TEXTBOX &aTextbox)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
Represent a single user action.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
bool IsToolActive() const
Definition tool_base.cpp:28
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
bool IsCancelInteractive() const
Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc key,...
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition tool_event.h:388
bool IsActivate() const
Definition tool_event.h:341
const VECTOR2D Position() const
Return mouse cursor position in world coordinates.
Definition tool_event.h:289
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition tool_event.h:311
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition tool_event.h:362
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
const VECTOR2D DragOrigin() const
Return the point where dragging has started.
Definition tool_event.h:295
bool IsCancel() const
Definition tool_event.h:336
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
std::optional< int > GetCommandId() const
Definition tool_event.h:544
void SetPassEvent(bool aPass=true)
Definition tool_event.h:252
bool IsMotion() const
Definition tool_event.h:326
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
EDA_UNITS GetUserUnits() const
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition vector2d.h:559
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition vector2d.h:312
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition vector2d.h:567
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:406
VECTOR2I GetValue()
Return the value in internal units.
Handle actions specific to filling copper zones.
bool Fill(const std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
void FinalizeItem(EDIT_POINTS &aPoints, COMMIT &aCommit) override
Finalize the edit operation.
bool UpdateItemAppliesAllPoints() const override
Whether UpdateItem() writes every point back, so one call applies all of them.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetNeedRefill(bool aNeedRefill)
Definition zone.h:310
SHAPE_POLY_SET * Outline()
Definition zone.h:421
@ CHT_MODIFY
Definition commit.h:40
This file is part of the common library.
bool IsConstrainableItem(const BOARD_ITEM *aItem)
True when aItem is one ResolveConstrainableItem() accepts: a PCB_SHAPE, a dimension or a pad.
void RemapPolygonVertexMembers(BOARD *aBoard, const KIID &aPoly, int aChangedIndex, int aDelta, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::function< void(BOARD_ITEM *)> &aBeforeRemove)
Repoint persisted VERTEX constraint members after an outline edit of polygon aPoly inserts or removes...
std::optional< CONSTRAINT_ANCHOR_POINT > ConstraintShapeVertex(const PCB_SHAPE *aShape, int aIndex)
VERTEX anchor at ordinal aIndex of a rectangle or eligible polygon or std::nullopt if the shape has n...
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintShapeAnchors(const PCB_SHAPE *aShape)
Enumerate a shape constraint anchors with positions segment and arc endpoints arc centre circle centr...
bool ConstraintPolygonIsModelable(const PCB_SHAPE *aShape)
True when polygon has one non empty hole free arc free outline making it solver eligible Shared by ad...
std::vector< PCB_CONSTRAINT * > CollectResolvedConstraints(const BOARD *aBoard)
The constraints the editor resolves on aBoard.
std::optional< CHAMFER_RESULT > ComputeChamferPoints(const SEG &aSegA, const SEG &aSegB, const CHAMFER_PARAMS &aChamferParams)
Compute the chamfer points for a given line pair and chamfer parameters.
@ ARROW
Definition cursors.h:43
static constexpr double MIN_SCALE
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
@ RADIANS_T
Definition eda_angle.h:31
@ NO_FILL
Definition eda_fill.h:30
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
#define IS_MOVING
Item being moved.
SHAPE_T
Definition eda_shape.h:55
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
EDA_UNITS
Definition eda_units.h:45
SNAP_CONSTRAINT_TYPE
@ ALL_LAYERS
@ OBJECT_LAYERS
@ IGNORE_SNAPS
POLYGON_LINE_MODE
@ SNAP_BY_GRID
@ SNAP_TO_GRID
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
a few functions useful in geometry calculations.
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamp a vector to values that can be negated, respecting numeric limits of coordinates data type with...
GRID_HELPER_GRIDS
Definition grid_helper.h:55
@ GRID_CURRENT
Definition grid_helper.h:57
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
#define PSEUDO_WXK_CLICK
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
Definition layer_ids.h:279
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:276
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ Margin
Definition layer_ids.h:109
@ F_Cu
Definition layer_ids.h:60
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
Definition eda_units.h:169
bool PointProjectsOntoSegment(const VECTOR2I &aPoint, const SEG &aSeg)
Determine if a point projects onto a segment.
double GetLengthRatioFromStart(const VECTOR2I &aPoint, const SEG &aSeg)
Get the ratio of the vector to a point from the segment's start, compared to the segment's length.
const VECTOR2I & GetNearestEndpoint(const SEG &aSeg, const VECTOR2I &aPoint)
Get the nearest end of a segment to a point.
bool PointIsInDirection(const VECTOR2< T > &aPoint, const VECTOR2< T > &aDirection, const VECTOR2< T > &aFrom)
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const wxArrayString &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.
wxString DimensionLabel(const wxString &prefix, double aVal, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, bool aIncludeUnits=true)
Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffi...
@ DM_BLOCK
Definition pns_router.h:86
STL namespace.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ CHAMFERED_RECT
Definition padstack.h:61
@ ROUNDRECT
Definition padstack.h:58
@ TRAPEZOID
Definition padstack.h:57
@ RECTANGLE
Definition padstack.h:55
BARCODE class definition.
CONSTRAINT_ANCHOR
Which feature of a referenced board item participates in a constraint.
@ VERTEX
An indexed rectangle corner or polygon outline vertex; pairs with CONSTRAINT_MEMBER::m_index.
@ START
First endpoint of a segment or arc.
@ END
Second endpoint of a segment or arc.
@ CENTER
Center of an arc or circle.
@ MANUAL
Text placement is manually set by the user.
#define STATUS_ITEMS_ONLY
Class to handle a set of BOARD_ITEMs.
static VECTOR2I snapCorner(const VECTOR2I &aPrev, const VECTOR2I &aNext, const VECTOR2I &aGuess, double aAngleDeg)
static const TOOL_ACTION *const blockDragNavigationActions[]
@ RECT_RIGHT
@ RECT_LEFT
static std::optional< CONSTRAINT_MEMBER > constraintMemberForEditPoint(PCB_SHAPE *aShape, EDIT_POINTS *aPoints, EDIT_POINT *aEditedPoint)
static bool blockDragAllowsCommand(const TOOL_EVENT &aEvent)
static std::pair< bool, SHAPE_POLY_SET::VERTEX_INDEX > findVertex(SHAPE_POLY_SET &aPolySet, const EDIT_POINT &aPoint)
static const TOOL_ACTION *const blockDragSafeActions[]
static std::vector< VECTOR2I > getConstraintDirections(EDIT_RELATION *aRelation)
TEXTBOX_POINT_COUNT
Text boxes have different point counts depending on their orientation.
@ WHEN_POLYGON
@ WHEN_RECTANGLE
static void blockDragAppendConstraintCoMembers(BOARD *aBoard, std::vector< BOARD_ITEM * > &aItems)
@ RECT_MAX_POINTS
@ RECT_BOT_LEFT
@ RECT_BOT_RIGHT
@ RECT_CENTER
@ RECT_TOP_RIGHT
@ RECT_RADIUS
@ RECT_TOP_LEFT
DIMENSION_POINTS
@ DIM_LEADER_MAX
@ DIM_RADIAL_MAX
@ DIM_CROSSBAREND
@ DIM_START
@ DIM_ALIGNED_MAX
@ DIM_CENTER_MAX
@ DIM_CROSSBARSTART
static void appendDirection(std::vector< VECTOR2I > &aDirections, const VECTOR2I &aDirection)
static void blockDragPassNavigation(TOOL_EVENT *aEvent)
static wxString blockDragDrcRefusal()
The release refuses a DRC violation unless the user forces it, and says so the same way wherever it i...
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
#define CHECK_POINT_COUNT(aPoints, aExpected)
#define CHECK_POINT_COUNT_GE(aPoints, aExpected)
CITER next(CITER it)
Definition ptree.cpp:120
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
#define APPEND_UNDO
Definition sch_commit.h:39
SCH_CONDITIONS S_C
@ RECT_CENTER
@ RECT_RADIUS
@ RECT_RIGHT
@ RECT_LEFT
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
SELECTION_MODE
const int scale
std::vector< FAB_LAYER_COLOR > dummy
One end of a graphic shape, used both for the ends that moved and for the ones found to follow them.
Parameters that define a simple chamfer operation.
A selectable feature of a shape (a segment endpoint, arc centre, ...) and its location.
One participant in a constraint: a referenced board item plus the feature of that item that participa...
std::unique_ptr< POINT_EDIT_BEHAVIOR > behavior
std::shared_ptr< EDIT_POINTS > points
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
const std::string table
bool moved
KIBIS top(path, &reporter)
KIBIS_PIN * pin
VECTOR3I v1(5, 5, 5)
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
VECTOR2I center
int radius
VECTOR2I end
int delta
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
#define M_PI
@ TA_MOUSE_DOWN
Definition tool_event.h:66
@ TA_UNDO_REDO_POST
This event is sent after undo/redo command is performed.
Definition tool_event.h:105
@ MD_ALT
Definition tool_event.h:141
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ TC_COMMAND
Definition tool_event.h:53
@ BUT_LEFT
Definition tool_event.h:128
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
Definition trigo.h:73
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:71
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
Supplemental functions for working with vectors and simple objects that interact with vectors.
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
static PIECE polygon(std::vector< VIA_CROSS_SECTION_GEOMETRY::POINT > aPoints, bool aMixed=false)