KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_dimension.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) 2012 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
7 * Copyright (C) 2023 CERN
8 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <bitmaps.h>
25#include <pcb_edit_frame.h>
26#include <base_units.h>
28#include <font/font.h>
29#include <board.h>
30#include <footprint.h>
31#include <pcb_dimension.h>
32#include <pcb_painter.h>
33#include <pcb_text.h>
34#include <view/view.h>
40#include <geometry/shape_rect.h>
44#include <trigo.h>
45#include <api/api_enums.h>
46#include <api/api_utils.h>
47#include <api/board/board_types.pb.h>
48#include <properties/property.h>
51
54
55
57
58static const EDA_ANGLE s_arrowAngle( 27.5, DEGREES_T );
59
60
69static OPT_VECTOR2I segPolyIntersection( const SHAPE_POLY_SET& aPoly, const SEG& aSeg,
70 bool aStart = true )
71{
72 VECTOR2I start( aStart ? aSeg.A : aSeg.B );
73 VECTOR2I endpoint( aStart ? aSeg.B : aSeg.A );
74
75 if( aPoly.Contains( start ) )
76 return std::nullopt;
77
78 for( SHAPE_POLY_SET::CONST_SEGMENT_ITERATOR seg = aPoly.CIterateSegments(); seg; ++seg )
79 {
80 if( OPT_VECTOR2I intersection = ( *seg ).Intersect( aSeg ) )
81 {
82 if( ( *intersection - start ).SquaredEuclideanNorm()
83 < ( endpoint - start ).SquaredEuclideanNorm() )
84 endpoint = *intersection;
85 }
86 }
87
88 if( start == endpoint )
89 return std::nullopt;
90
91 return OPT_VECTOR2I( endpoint );
92}
93
94
95static OPT_VECTOR2I segCircleIntersection( CIRCLE& aCircle, SEG& aSeg, bool aStart = true )
96{
97 VECTOR2I start( aStart ? aSeg.A : aSeg.B );
98 VECTOR2I endpoint( aStart ? aSeg.B : aSeg.A );
99
100 if( aCircle.Contains( start ) )
101 return std::nullopt;
102
103 std::vector<VECTOR2I> intersections = aCircle.Intersect( aSeg );
104
105 for( VECTOR2I& intersection : aCircle.Intersect( aSeg ) )
106 {
107 if( ( intersection - start ).SquaredEuclideanNorm()
108 < ( endpoint - start ).SquaredEuclideanNorm() )
109 endpoint = intersection;
110 }
111
112 if( start == endpoint )
113 return std::nullopt;
114
115 return OPT_VECTOR2I( endpoint );
116}
117
118
123static void CollectKnockedOutSegments( const SHAPE_POLY_SET& aPoly, const SEG& aSeg,
124 std::vector<std::shared_ptr<SHAPE>>& aSegmentsAfterKnockout )
125{
126 // Now we can draw 0, 1, or 2 crossbar lines depending on how the polygon collides
127 const bool containsA = aPoly.Contains( aSeg.A );
128 const bool containsB = aPoly.Contains( aSeg.B );
129
130 const OPT_VECTOR2I endpointA = segPolyIntersection( aPoly, aSeg );
131 const OPT_VECTOR2I endpointB = segPolyIntersection( aPoly, aSeg, false );
132
133 if( endpointA )
134 aSegmentsAfterKnockout.emplace_back( new SHAPE_SEGMENT( aSeg.A, *endpointA ) );
135
136 if( endpointB )
137 {
138 bool can_add = true;
139
140 if( endpointA )
141 {
142 if( ( *endpointB == aSeg.A && *endpointA == aSeg.B )
143 || ( *endpointA == *endpointB && aSeg.A == aSeg.B ) )
144 can_add = false;
145 }
146
147 if( can_add )
148 aSegmentsAfterKnockout.emplace_back( new SHAPE_SEGMENT( *endpointB, aSeg.B ) );
149 }
150
151 if( !containsA && !containsB && !endpointA && !endpointB )
152 aSegmentsAfterKnockout.emplace_back( new SHAPE_SEGMENT( aSeg ) );
153}
154
155
157 PCB_TEXT( aParent, aType ),
158 m_overrideTextEnabled( false ),
160 m_autoUnits( false ),
164 m_suppressZeroes( false ),
165 m_lineThickness( pcbIUScale.mmToIU( 0.2 ) ),
166 m_arrowLength( pcbIUScale.MilsToIU( 50 ) ),
169 m_keepTextAligned( true ),
170 m_measuredValue( 0 ),
171 m_start( 0, 0 ),
172 m_end( 0, 0 ),
173 m_inClearRenderCache( false )
174{
176 m_busy = false;
177}
178
179
181{
182 if( const FOOTPRINT* fp = GetParentFootprint() )
183 return fp->GetTransform().Apply( m_start );
184
185 return m_start;
186}
187
188
190{
191 if( const FOOTPRINT* fp = GetParentFootprint() )
192 return fp->GetTransform().Apply( m_end );
193
194 return m_end;
195}
196
197
199{
200 if( const FOOTPRINT* fp = GetParentFootprint() )
201 m_start = fp->GetTransform().InverseApply( aPoint );
202 else
203 m_start = aPoint;
204}
205
206
208{
209 if( const FOOTPRINT* fp = GetParentFootprint() )
210 m_end = fp->GetTransform().InverseApply( aPoint );
211 else
212 m_end = aPoint;
213}
214
215
216void PCB_DIMENSION_BASE::OnFootprintRescaled( double /* aRatioX */, double /* aRatioY */, double /* aLinearFactor */,
217 const VECTOR2I& /* aAnchor */, const EDA_ANGLE& /* aParentRotate */ )
218{
221}
222
223
231
232
234{
235 if( Type() != aOther.Type() )
236 return false;
237
238 const PCB_DIMENSION_BASE& other = static_cast<const PCB_DIMENSION_BASE&>( aOther );
239
240 return *this == other;
241}
242
243
245{
246 if( m_textPosition != aOther.m_textPosition )
247 return false;
248
250 return false;
251
252 if( m_units != aOther.m_units )
253 return false;
254
255 if( m_autoUnits != aOther.m_autoUnits )
256 return false;
257
258 if( m_unitsFormat != aOther.m_unitsFormat )
259 return false;
260
261 if( m_precision != aOther.m_precision )
262 return false;
263
264 if( m_suppressZeroes != aOther.m_suppressZeroes )
265 return false;
266
267 if( m_lineThickness != aOther.m_lineThickness )
268 return false;
269
270 if( m_arrowLength != aOther.m_arrowLength )
271 return false;
272
274 return false;
275
276 if( m_measuredValue != aOther.m_measuredValue )
277 return false;
278
279 return EDA_TEXT::operator==( aOther );
280}
281
282
283double PCB_DIMENSION_BASE::Similarity( const BOARD_ITEM& aOther ) const
284{
285 if( m_Uuid == aOther.m_Uuid )
286 return 1.0;
287
288 if( Type() != aOther.Type() )
289 return 0.0;
290
291 const PCB_DIMENSION_BASE& other = static_cast<const PCB_DIMENSION_BASE&>( aOther );
292
293 double similarity = 1.0;
294
295 if( m_textPosition != other.m_textPosition )
296 similarity *= 0.9;
297
299 similarity *= 0.9;
300
301 if( m_units != other.m_units )
302 similarity *= 0.9;
303
304 if( m_autoUnits != other.m_autoUnits )
305 similarity *= 0.9;
306
307 if( m_unitsFormat != other.m_unitsFormat )
308 similarity *= 0.9;
309
310 if( m_precision != other.m_precision )
311 similarity *= 0.9;
312
314 similarity *= 0.9;
315
316 if( m_lineThickness != other.m_lineThickness )
317 similarity *= 0.9;
318
319 if( m_arrowLength != other.m_arrowLength )
320 similarity *= 0.9;
321
323 similarity *= 0.9;
324
325 if( m_measuredValue != other.m_measuredValue )
326 similarity *= 0.9;
327
328 similarity *= EDA_TEXT::Similarity( other );
329
330 return similarity;
331}
332
333
334void PCB_DIMENSION_BASE::Serialize( google::protobuf::Any &aContainer ) const
335{
336 using namespace kiapi::common;
337 using namespace kiapi::board::types;
338 Dimension dimension;
339
340 dimension.mutable_id()->set_value( m_Uuid.AsStdString() );
341 dimension.set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( GetLayer() ) );
342 dimension.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
343 : types::LockedState::LS_UNLOCKED );
344
345 EDA_TEXT::Serialize( *dimension.mutable_text(), pcbIUScale );
346
347 types::Text* text = dimension.mutable_text();
348 text->set_text( GetValueText() );
349
350 dimension.set_override_text_enabled( m_overrideTextEnabled );
351 dimension.set_override_text( m_valueString.ToUTF8() );
352 dimension.set_prefix( m_prefix.ToUTF8() );
353 dimension.set_suffix( m_suffix.ToUTF8() );
354
356 dimension.set_unit_format(
358 dimension.set_arrow_direction(
361 dimension.set_suppress_trailing_zeroes( m_suppressZeroes );
362
363 if( FOOTPRINT* parent = GetParentFootprint() )
364 dimension.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
365 else if( const BOARD* board = GetBoard() )
366 dimension.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
367
368 dimension.mutable_line_thickness()->set_value_nm( m_lineThickness );
369 dimension.mutable_arrow_length()->set_value_nm( m_arrowLength );
370 dimension.mutable_extension_offset()->set_value_nm( m_extensionOffset );
371 dimension.set_text_position(
373 dimension.set_keep_text_aligned( m_keepTextAligned );
374
375 kiapi::common::PackCustomProperties( dimension.mutable_custom_properties(), *this );
376
377 if( !aContainer.PackFrom( dimension ) )
378 wxFAIL_MSG( wxT( "Failed to pack PCB_DIMENSION" ) );
379}
380
381
382bool PCB_DIMENSION_BASE::Deserialize( const google::protobuf::Any &aContainer )
383{
384 using namespace kiapi::common;
385 kiapi::board::types::Dimension dimension;
386
387 if( !aContainer.UnpackTo( &dimension ) )
388 return false;
389
391 SetUuidDirect( KIID( dimension.id().value() ) );
392 SetLocked( dimension.locked() == types::LockedState::LS_LOCKED );
393
394 // Setting text attributes triggers Update(), which must already see the text position mode
395 SetTextPositionMode( FromProtoEnum<DIM_TEXT_POSITION>( dimension.text_position() ) );
396 SetKeepTextAligned( dimension.keep_text_aligned() );
397
398 EDA_TEXT::Deserialize( dimension.text(), pcbIUScale );
399
400 SetOverrideTextEnabled( dimension.override_text_enabled() );
401 SetOverrideText( wxString::FromUTF8( dimension.override_text() ) );
402 SetPrefix( wxString::FromUTF8( dimension.prefix() ) );
403 SetSuffix( wxString::FromUTF8( dimension.suffix() ) );
404
405 SetUnitsMode( FromProtoEnum<DIM_UNITS_MODE>( dimension.unit() ) );
406 SetUnitsFormat( FromProtoEnum<DIM_UNITS_FORMAT>( dimension.unit_format() ) );
407 SetArrowDirection( FromProtoEnum<DIM_ARROW_DIRECTION>( dimension.arrow_direction() ) );
408 SetPrecision( FromProtoEnum<DIM_PRECISION>( dimension.precision() ) );
409 SetSuppressZeroes( dimension.suppress_trailing_zeroes() );
410
411 SetLineThickness( dimension.line_thickness().value_nm() );
412 SetArrowLength( dimension.arrow_length().value_nm() );
413 SetExtensionOffset( dimension.extension_offset().value_nm() );
414
415 kiapi::common::UnpackCustomProperties( dimension.custom_properties(), *this );
416
417 Update();
418
419 return true;
420}
421
422
423void PCB_DIMENSION_BASE::drawAnArrow( VECTOR2I startPoint, EDA_ANGLE anAngle, int aLength )
424{
425 if( aLength )
426 {
427 VECTOR2I tailEnd( aLength, 0 );
428 RotatePoint( tailEnd, -anAngle );
429 m_shapes.emplace_back( new SHAPE_SEGMENT( startPoint, startPoint + tailEnd ) );
430 }
431
432 VECTOR2I arrowEndPos( m_arrowLength, 0 );
433 VECTOR2I arrowEndNeg( m_arrowLength, 0 );
434
435 RotatePoint( arrowEndPos, -anAngle + s_arrowAngle );
436 RotatePoint( arrowEndNeg, -anAngle - s_arrowAngle );
437
438 m_shapes.emplace_back( new SHAPE_SEGMENT( startPoint, startPoint + arrowEndPos ) );
439 m_shapes.emplace_back( new SHAPE_SEGMENT( startPoint, startPoint + arrowEndNeg ) );
440}
441
442
444{
446
447 switch( m_unitsFormat )
448 {
449 case DIM_UNITS_FORMAT::NO_SUFFIX: // no units
450 break;
451
452 case DIM_UNITS_FORMAT::BARE_SUFFIX: // normal
454 break;
455
456 case DIM_UNITS_FORMAT::PAREN_SUFFIX: // parenthetical
457 text += wxT( " (" ) + EDA_UNIT_UTILS::GetText( m_units ).Trim( false ) + wxT( ")" );
458 break;
459 }
460
461 text.Prepend( m_prefix );
462 text.Append( m_suffix );
463
464 SetText( text );
465}
466
467
469{
471
472 // We use EDA_TEXT::ClearRenderCache() as a signal that the properties of the EDA_TEXT
473 // have changed and we may need to update the dimension text
474
476 {
478 Update();
479 m_inClearRenderCache = false;
480 }
481}
482
483
484template<typename ShapeType>
485void PCB_DIMENSION_BASE::addShape( const ShapeType& aShape )
486{
487 m_shapes.push_back( std::make_shared<ShapeType>( aShape ) );
488}
489
490
492{
493 struct lconv* lc = localeconv();
494 wxChar sep = lc->decimal_point[0];
495
496 int val = GetMeasuredValue();
497 int precision = static_cast<int>( m_precision );
498 wxString text;
499
500 if( precision >= 6 )
501 {
502 switch( m_units )
503 {
504 case EDA_UNITS::INCH: precision = precision - 4; break;
505 case EDA_UNITS::MILS: precision = std::max( 0, precision - 7 ); break;
506 case EDA_UNITS::MM: precision = precision - 5; break;
507 default: precision = precision - 4; break;
508 }
509 }
510
511 wxString format = wxT( "%." ) + wxString::Format( wxT( "%i" ), precision ) + wxT( "f" );
512
513 text.Printf( format, EDA_UNIT_UTILS::UI::ToUserUnit( pcbIUScale, m_units, val ) );
514
515 if( m_suppressZeroes && precision > 0 )
516 {
517 while( text.EndsWith( '0' ) )
518 {
519 text.RemoveLast();
520
521 if( text.EndsWith( '.' ) || text.EndsWith( sep ) )
522 {
523 text.RemoveLast();
524 break;
525 }
526 }
527 }
528
529 return text;
530}
531
532
537
538
544
545
547{
548 switch( GetValueMode() )
549 {
551 {
552 PCB_CONSTRAINT* lengthConstraint = FindDimensionLengthConstraint( GetBoard(), this );
553
554 if( lengthConstraint && lengthConstraint->GetValue() )
555 {
557 *lengthConstraint->GetValue() );
558 }
559
560 return GetValueText();
561 }
562
564 return GetOverrideText();
565
567 default:
568 return GetValueText();
569 }
570}
571
572
573void PCB_DIMENSION_BASE::ChangeValueFieldText( const wxString& aText )
574{
576 {
577 SetOverrideText( aText );
578 Update();
579 }
580}
581
582
583void PCB_DIMENSION_BASE::SetPrefix( const wxString& aPrefix )
584{
585 m_prefix = aPrefix;
586}
587
588
589void PCB_DIMENSION_BASE::SetSuffix( const wxString& aSuffix )
590{
591 m_suffix = aSuffix;
592}
593
594
596{
597 m_units = aUnits;
598}
599
600
602{
603 if( m_autoUnits )
604 {
606 }
607 else
608 {
609 switch( m_units )
610 {
611 default:
615 }
616 }
617}
618
619
621{
622 switch( aMode )
623 {
625 m_autoUnits = false;
627 break;
628
630 m_autoUnits = false;
632 break;
633
635 m_autoUnits = false;
637 break;
638
640 m_autoUnits = true;
642 break;
643 }
644}
645
646
648{
649 SetTextAngleDegrees( aDegrees );
650 // Create or repair any knockouts
651 Update();
652}
653
654
656{
657 SetKeepTextAligned( aKeepAligned );
658 // Re-align the text and repair any knockouts
659 Update();
660}
661
662
664{
665 PCB_TEXT::Offset( offset );
666
667 if( const FOOTPRINT* fp = GetParentFootprint() )
668 {
669 const TRANSFORM_TRS& xform = fp->GetTransform();
670 VECTOR2I libOffset = xform.InverseApply( offset ) - xform.InverseApply( VECTOR2I( 0, 0 ) );
671 m_start += libOffset;
672 m_end += libOffset;
673 }
674 else
675 {
676 m_start += offset;
677 m_end += offset;
678 }
679
680 Update();
681}
682
683
684void PCB_DIMENSION_BASE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
685{
686 EDA_ANGLE newAngle = GetTextAngle() + aAngle;
687 newAngle.Normalize();
688 SetTextAngle( newAngle );
689
690 VECTOR2I pt = GetTextPos();
691 RotatePoint( pt, aRotCentre, aAngle );
692 SetTextPos( pt );
693
694 VECTOR2I boardStart = GetStart();
695 VECTOR2I boardEnd = GetEnd();
696 RotatePoint( boardStart, aRotCentre, aAngle );
697 RotatePoint( boardEnd, aRotCentre, aAngle );
698
699 if( const FOOTPRINT* fp = GetParentFootprint() )
700 {
701 m_start = fp->GetTransform().InverseApply( boardStart );
702 m_end = fp->GetTransform().InverseApply( boardEnd );
703 }
704 else
705 {
706 m_start = boardStart;
707 m_end = boardEnd;
708 }
709
710 Update();
711}
712
713
714void PCB_DIMENSION_BASE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
715{
716 Mirror( aCentre, aFlipDirection );
717
719}
720
721
722void PCB_DIMENSION_BASE::Mirror( const VECTOR2I& axis_pos, FLIP_DIRECTION aFlipDirection )
723{
724 if( const FOOTPRINT* fp = GetParentFootprint() )
725 {
726 const VECTOR2I libAxis = fp->GetTransform().InverseApply( axis_pos );
727
728 auto mirrorPt = [&]( VECTOR2I& p )
729 {
730 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
731 p.x = 2 * libAxis.x - p.x;
732 else
733 p.y = 2 * libAxis.y - p.y;
734 };
735
736 mirrorPt( m_start );
737 mirrorPt( m_end );
738
739 VECTOR2I libTextPos = EDA_TEXT::GetTextPos();
740 mirrorPt( libTextPos );
741 SetLibTextPos( libTextPos );
742
743 EDA_ANGLE newLibAngle =
745 SetLibTextAngle( newLibAngle );
746
747 if( IsSideSpecific() )
749
751 Update();
752 return;
753 }
754
755 VECTOR2I newPos = GetTextPos();
756
757 MIRROR( newPos, axis_pos, aFlipDirection );
758
759 SetTextPos( newPos );
760
761 // invert angle
763
764 MIRROR( m_start, axis_pos, aFlipDirection );
765 MIRROR( m_end, axis_pos, aFlipDirection );
766
767 if( IsSideSpecific() )
769
770 Update();
771}
772
773
774void PCB_DIMENSION_BASE::StyleFromSettings( const BOARD_DESIGN_SETTINGS& aSettings, bool aCheckSide )
775{
776 PCB_TEXT::StyleFromSettings( aSettings, aCheckSide );
777
785
786 Update(); // refresh text & geometry
787
788}
789
790
792 std::vector<MSG_PANEL_ITEM>& aList )
793{
794 // for now, display only the text within the DIMENSION using class PCB_TEXT.
795 wxString msg;
796
797 wxCHECK_RET( m_parent != nullptr, wxT( "PCB_TEXT::GetMsgPanelInfo() m_Parent is NULL." ) );
798
799 // Don't use GetShownText(); we want to see the variable references here
800 aList.emplace_back( _( "Dimension" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
801
802 aList.emplace_back( _( "Prefix" ), GetPrefix() );
803
805 {
806 aList.emplace_back( _( "Override Text" ), GetOverrideText() );
807 }
808 else
809 {
810 aList.emplace_back( _( "Value" ), GetValueText() );
811
812 switch( GetPrecision() )
813 {
814 case DIM_PRECISION::V_VV: msg = wxT( "0.00 in / 0 mils / 0.0 mm" ); break;
815 case DIM_PRECISION::V_VVV: msg = wxT( "0.000 in / 0 mils / 0.00 mm" ); break;
816 case DIM_PRECISION::V_VVVV: msg = wxT( "0.0000 in / 0.0 mils / 0.000 mm" ); break;
817 case DIM_PRECISION::V_VVVVV: msg = wxT( "0.00000 in / 0.00 mils / 0.0000 mm" ); break;
818 default: msg = wxT( "%" ) + wxString::Format( wxT( "1.%df" ), GetPrecision() );
819 }
820
821 aList.emplace_back( _( "Precision" ), wxString::Format( msg, 0.0 ) );
822 }
823
824 aList.emplace_back( _( "Suffix" ), GetSuffix() );
825
826 // Use our own UNITS_PROVIDER to report dimension info in dimension's units rather than
827 // in frame's units.
828 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
829 unitsProvider.SetUserUnits( GetUnits() );
830
831 aList.emplace_back( _( "Units" ), EDA_UNIT_UTILS::GetLabel( GetUnits() ) );
832
833 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
834 aList.emplace_back( _( "Text Thickness" ), unitsProvider.MessageTextFromValue( GetTextThickness() ) );
835 aList.emplace_back( _( "Text Width" ), unitsProvider.MessageTextFromValue( GetTextWidth() ) );
836 aList.emplace_back( _( "Text Height" ), unitsProvider.MessageTextFromValue( GetTextHeight() ) );
837
838 ORIGIN_TRANSFORMS& originTransforms = aFrame->GetOriginTransforms();
839
840 if( Type() == PCB_DIM_CENTER_T )
841 {
842 VECTOR2I startCoord = originTransforms.ToDisplayAbs( GetStart() );
843 wxString start = wxString::Format( wxT( "@(%s, %s)" ),
844 aFrame->MessageTextFromValue( startCoord.x ),
845 aFrame->MessageTextFromValue( startCoord.y ) );
846
847 aList.emplace_back( start, wxEmptyString );
848 }
849 else
850 {
851 VECTOR2I startCoord = originTransforms.ToDisplayAbs( GetStart() );
852 wxString start = wxString::Format( wxT( "@(%s, %s)" ),
853 aFrame->MessageTextFromValue( startCoord.x ),
854 aFrame->MessageTextFromValue( startCoord.y ) );
855 VECTOR2I endCoord = originTransforms.ToDisplayAbs( GetEnd() );
856 wxString end = wxString::Format( wxT( "@(%s, %s)" ),
857 aFrame->MessageTextFromValue( endCoord.x ),
858 aFrame->MessageTextFromValue( endCoord.y ) );
859
860 aList.emplace_back( start, end );
861 }
862
863 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
864 aList.emplace_back( _( "Status" ), _( "Locked" ) );
865
866 aList.emplace_back( _( "Layer" ), GetLayerName() );
867}
868
869
871{
872 std::shared_ptr<SHAPE_COMPOUND> effectiveShape = std::make_shared<SHAPE_COMPOUND>();
873
874 effectiveShape->AddShape( GetEffectiveTextShape()->Clone() );
875
876 for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
877 effectiveShape->AddShape( shape->Clone() );
878
879 return effectiveShape;
880}
881
882
883bool PCB_DIMENSION_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
884{
885 if( TextHitTest( aPosition ) )
886 return true;
887
888 int dist_max = aAccuracy + ( m_lineThickness / 2 );
889
890 // Locate SEGMENTS
891
892 for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
893 {
894 if( shape->Collide( aPosition, dist_max ) )
895 return true;
896 }
897
898 return false;
899}
900
901
902bool PCB_DIMENSION_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
903{
904 BOX2I arect = aRect;
905 arect.Inflate( aAccuracy );
906
908
909 if( aAccuracy )
910 rect.Inflate( aAccuracy );
911
912 if( aContained )
913 return arect.Contains( rect );
914
915 return arect.Intersects( rect );
916}
917
918
919bool PCB_DIMENSION_BASE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
920{
921 // Note: Can't use GetEffectiveShape() because we want text as BoundingBox, not as graphics.
922 SHAPE_COMPOUND effShape;
923
924 // Add shapes
925 for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
926 effShape.AddShape( shape );
927
928 if( aContained )
929 return TextHitTest( aPoly, aContained ) && KIGEOM::ShapeHitTest( aPoly, effShape, aContained );
930 else
931 return TextHitTest( aPoly, aContained ) || KIGEOM::ShapeHitTest( aPoly, effShape, aContained );
932}
933
934
936{
937 BOX2I bBox;
938 int xmin, xmax, ymin, ymax;
939
940 bBox = GetTextBox( nullptr );
941 xmin = bBox.GetX();
942 xmax = bBox.GetRight();
943 ymin = bBox.GetY();
944 ymax = bBox.GetBottom();
945
946 for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
947 {
948 BOX2I shapeBox = shape->BBox();
949 shapeBox.Inflate( m_lineThickness / 2 );
950
951 xmin = std::min( xmin, shapeBox.GetOrigin().x );
952 xmax = std::max( xmax, shapeBox.GetEnd().x );
953 ymin = std::min( ymin, shapeBox.GetOrigin().y );
954 ymax = std::max( ymax, shapeBox.GetEnd().y );
955 }
956
957 bBox.SetX( xmin );
958 bBox.SetY( ymin );
959 bBox.SetWidth( xmax - xmin + 1 );
960 bBox.SetHeight( ymax - ymin + 1 );
961
962 bBox.Normalize();
963
964 return bBox;
965}
966
967
968wxString PCB_DIMENSION_BASE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
969{
970 return wxString::Format( _( "Dimension '%s' on %s" ),
972 GetLayerName() );
973}
974
975
976
978{
980 VECTOR2I( GetBoundingBox().GetSize() ) );
981 dimBBox.Merge( PCB_TEXT::ViewBBox() );
982
983 return dimBBox;
984}
985
986
987std::vector<int> PCB_DIMENSION_BASE::ViewGetLayers() const
988{
989 std::vector<int> layers = PCB_TEXT::ViewGetLayers();
990
991 // Always advertised while ViewGetLOD gates the draw on actual constraint reference
992 layers.push_back( LAYER_CONSTRAINT_SHADOW );
993
994 return layers;
995}
996
997
998double PCB_DIMENSION_BASE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
999{
1000 if( aLayer == LAYER_CONSTRAINT_SHADOW && aView )
1001 {
1002 KIGFX::PCB_RENDER_SETTINGS& renderSettings =
1003 *static_cast<KIGFX::PCB_PAINTER&>( *aView->GetPainter() ).GetSettings();
1004
1005 if( !renderSettings.GetConstrainedItems().count( m_Uuid ) )
1006 return LOD_HIDE;
1007
1008 if( !aView->IsLayerVisibleCached( GetLayer() ) )
1009 return LOD_HIDE;
1010
1011 if( renderSettings.GetHighContrast() && GetLayer() != renderSettings.GetPrimaryHighContrastLayer() )
1012 return LOD_HIDE;
1013
1014 return LOD_SHOW;
1015 }
1016
1017 return PCB_TEXT::ViewGetLOD( aLayer, aView );
1018}
1019
1020
1021double PCB_DIMENSION_BASE::GetCoverageArea( int aTextMargin ) const
1022{
1023 // A dimension covers its whole drawing, not only the value text it inherits from
1024 return BOARD_ITEM::GetCoverageArea( aTextMargin );
1025}
1026
1027
1029 int aClearance, int aError, ERROR_LOC aErrorLoc,
1030 bool aIgnoreLineWidth ) const
1031{
1032 wxASSERT_MSG( !aIgnoreLineWidth, wxT( "IgnoreLineWidth has no meaning for dimensions." ) );
1033
1034 for( const std::shared_ptr<SHAPE>& shape : m_shapes )
1035 {
1036 const SHAPE_CIRCLE* circle = dynamic_cast<const SHAPE_CIRCLE*>( shape.get() );
1037 const SHAPE_SEGMENT* seg = dynamic_cast<const SHAPE_SEGMENT*>( shape.get() );
1038
1039 if( circle )
1040 {
1041 TransformCircleToPolygon( aBuffer, circle->GetCenter(),
1042 circle->GetRadius() + m_lineThickness / 2 + aClearance,
1043 aError, aErrorLoc );
1044 }
1045 else if( seg )
1046 {
1047 TransformOvalToPolygon( aBuffer, seg->GetSeg().A, seg->GetSeg().B,
1048 m_lineThickness + 2 * aClearance, aError, aErrorLoc );
1049 }
1050 else
1051 {
1052 wxFAIL_MSG( wxT( "PCB_DIMENSION_BASE::TransformShapeToPolygon unknown shape type." ) );
1053 }
1054 }
1055}
1056
1057
1059 PCB_DIMENSION_BASE( aParent, aType ),
1060 m_height( 0 )
1061{
1062 // To preserve look of old dimensions, initialize extension height based on default arrow length
1063 m_extensionHeight = static_cast<int>( m_arrowLength * s_arrowAngle.Sin() );
1064}
1065
1066
1068{
1069 return new PCB_DIM_ALIGNED( *this );
1070}
1071
1072
1074{
1075 wxCHECK( aOther && aOther->Type() == PCB_DIM_ALIGNED_T, /* void */ );
1076 *this = *static_cast<const PCB_DIM_ALIGNED*>( aOther );
1077}
1078
1079void PCB_DIM_ALIGNED::Serialize( google::protobuf::Any &aContainer ) const
1080{
1081 using namespace kiapi::common;
1082 kiapi::board::types::Dimension dimension;
1083
1084 PCB_DIMENSION_BASE::Serialize( aContainer );
1085
1086 if( !aContainer.UnpackTo( &dimension ) )
1087 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1088
1089 PackVector2( *dimension.mutable_aligned()->mutable_start(), GetStart() );
1090 PackVector2( *dimension.mutable_aligned()->mutable_end(), GetEnd() );
1091 dimension.mutable_aligned()->mutable_height()->set_value_nm( m_height );
1092 dimension.mutable_aligned()->mutable_extension_height()->set_value_nm( m_extensionHeight );
1093
1094 if( !aContainer.PackFrom( dimension ) )
1095 wxFAIL_MSG( wxT( "Failed to pack PCB_DIM_ALIGNED" ) );
1096}
1097
1098
1099bool PCB_DIM_ALIGNED::Deserialize( const google::protobuf::Any &aContainer )
1100{
1101 using namespace kiapi::common;
1102
1103 if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
1104 return false;
1105
1106 kiapi::board::types::Dimension dimension;
1107
1108 if( !aContainer.UnpackTo( &dimension ) )
1109 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1110
1111 if( !dimension.has_aligned() )
1112 return false;
1113
1114 SetStart( UnpackVector2( dimension.aligned().start() ) );
1115 SetEnd( UnpackVector2( dimension.aligned().end() ) );
1116 SetHeight( (int) dimension.aligned().height().value_nm());
1117 SetExtensionHeight( (int) dimension.aligned().extension_height().value_nm() );
1118
1119 Update();
1120
1121 return true;
1122}
1123
1124
1126{
1127 wxASSERT( aImage->Type() == Type() );
1128
1129 m_shapes.clear();
1130 static_cast<PCB_DIM_ALIGNED*>( aImage )->m_shapes.clear();
1131
1132 std::swap( *static_cast<PCB_DIM_ALIGNED*>( this ), *static_cast<PCB_DIM_ALIGNED*>( aImage ) );
1133
1134 Update();
1135}
1136
1137
1138void PCB_DIM_ALIGNED::Mirror( const VECTOR2I& axis_pos, FLIP_DIRECTION aFlipDirection )
1139{
1140 m_height = -m_height;
1141 // Call this last for the Update()
1142 PCB_DIMENSION_BASE::Mirror( axis_pos, aFlipDirection );
1143}
1144
1145
1150
1151
1152void PCB_DIM_ALIGNED::UpdateHeight( const VECTOR2I& aCrossbarStart, const VECTOR2I& aCrossbarEnd )
1153{
1154 VECTOR2D height( aCrossbarStart - GetStart() );
1155 VECTOR2D crossBar( aCrossbarEnd - aCrossbarStart );
1156
1157 if( height.Cross( crossBar ) > 0 )
1158 m_height = -height.EuclideanNorm();
1159 else
1160 m_height = height.EuclideanNorm();
1161
1162 Update();
1163}
1164
1165
1167{
1168 if( m_busy ) // Skeep reentrance that happens sometimes after calling updateText()
1169 return;
1170
1171 m_busy = true;
1172
1173 m_shapes.clear();
1174
1175 const VECTOR2I start = GetStart();
1176 const VECTOR2I end = GetEnd();
1177 VECTOR2I dimension( end - start );
1178
1179 m_measuredValue = KiROUND( dimension.EuclideanNorm() );
1180
1181 VECTOR2I extension;
1182
1183 if( m_height > 0 )
1184 extension = VECTOR2I( -dimension.y, dimension.x );
1185 else
1186 extension = VECTOR2I( dimension.y, -dimension.x );
1187
1188 // Add extension lines
1189 int extensionHeight = std::abs( m_height ) - m_extensionOffset + m_extensionHeight;
1190
1191 VECTOR2I extStart( start );
1192 extStart += extension.Resize( m_extensionOffset );
1193
1194 addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
1195
1196 extStart = VECTOR2I( end );
1197 extStart += extension.Resize( m_extensionOffset );
1198
1199 addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
1200
1201 // Add crossbar
1202 VECTOR2I crossBarDistance = sign( m_height ) * extension.Resize( m_height );
1203 m_crossBarStart = start + crossBarDistance;
1204 m_crossBarEnd = end + crossBarDistance;
1205
1206 // Update text after calculating crossbar position but before adding crossbar lines
1207 updateText();
1208
1209 // Now that we have the text updated, we can determine how to draw the crossbar.
1210 // First we need to create an appropriate bounding polygon to collide with
1211 BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, - GetEffectiveTextPenWidth() );
1212
1213 SHAPE_POLY_SET polyBox;
1214 polyBox.NewOutline();
1215 polyBox.Append( textBox.GetOrigin() );
1216 polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
1217 polyBox.Append( textBox.GetEnd() );
1218 polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
1219 polyBox.Rotate( GetTextAngle(), textBox.GetCenter() );
1220
1221 // The ideal crossbar, if the text doesn't collide
1222 SEG crossbar( m_crossBarStart, m_crossBarEnd );
1223
1224 CollectKnockedOutSegments( polyBox, crossbar, m_shapes );
1225
1227 {
1228 drawAnArrow( m_crossBarStart, EDA_ANGLE( dimension ) + EDA_ANGLE( 180 ),
1230 drawAnArrow( m_crossBarEnd, EDA_ANGLE( dimension ),
1232 }
1233 else
1234 {
1235 drawAnArrow( m_crossBarStart, EDA_ANGLE( dimension ), 0 );
1236 drawAnArrow( m_crossBarEnd, EDA_ANGLE( dimension ) + EDA_ANGLE( 180 ), 0 );
1237 }
1238
1239 m_busy = false;
1240}
1241
1242
1244{
1245 VECTOR2I crossbarCenter( ( m_crossBarEnd - m_crossBarStart ) / 2 );
1246
1248 {
1249 int textOffsetDistance = GetEffectiveTextPenWidth() + GetTextHeight();
1250 EDA_ANGLE rotation;
1251
1252 if( crossbarCenter.x == 0 )
1253 rotation = ANGLE_90 * sign( -crossbarCenter.y );
1254 else if( crossbarCenter.x < 0 )
1255 rotation = -ANGLE_90;
1256 else
1257 rotation = ANGLE_90;
1258
1259 VECTOR2I textOffset = crossbarCenter;
1260 RotatePoint( textOffset, rotation );
1261 textOffset = crossbarCenter + textOffset.Resize( textOffsetDistance );
1262
1263 SetTextPos( m_crossBarStart + textOffset );
1264 }
1266 {
1267 SetTextPos( m_crossBarStart + crossbarCenter );
1268 }
1269
1270 if( m_keepTextAligned )
1271 {
1272 EDA_ANGLE textAngle = FULL_CIRCLE - EDA_ANGLE( crossbarCenter );
1273 textAngle.Normalize();
1274
1275 if( textAngle > ANGLE_90 && textAngle <= ANGLE_270 )
1276 textAngle -= ANGLE_180;
1277
1278 SetTextAngle( textAngle );
1279 }
1280
1282}
1283
1284
1285void PCB_DIM_ALIGNED::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1286{
1287 PCB_DIMENSION_BASE::GetMsgPanelInfo( aFrame, aList );
1288
1289 // Use our own UNITS_PROVIDER to report dimension info in dimension's units rather than
1290 // in frame's units.
1291 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
1292 unitsProvider.SetUserUnits( GetUnits() );
1293
1294 aList.emplace_back( _( "Height" ), unitsProvider.MessageTextFromValue( m_height ) );
1295}
1296
1297
1300{
1301 // To preserve look of old dimensions, initialize extension height based on default arrow length
1302 m_extensionHeight = static_cast<int>( m_arrowLength * s_arrowAngle.Sin() );
1304}
1305
1306
1308{
1309 return new PCB_DIM_ORTHOGONAL( *this );
1310}
1311
1312
1314{
1315 wxCHECK( aOther && aOther->Type() == PCB_DIM_ORTHOGONAL_T, /* void */ );
1316 *this = *static_cast<const PCB_DIM_ORTHOGONAL*>( aOther );
1317}
1318
1319void PCB_DIM_ORTHOGONAL::Serialize( google::protobuf::Any &aContainer ) const
1320{
1321 using namespace kiapi::common;
1322 kiapi::board::types::Dimension dimension;
1323
1324 PCB_DIMENSION_BASE::Serialize( aContainer );
1325
1326 if( !aContainer.UnpackTo( &dimension ) )
1327 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1328
1329 PackVector2( *dimension.mutable_orthogonal()->mutable_start(), GetStart() );
1330 PackVector2( *dimension.mutable_orthogonal()->mutable_end(), GetEnd() );
1331 dimension.mutable_orthogonal()->mutable_height()->set_value_nm( m_height );
1332 dimension.mutable_orthogonal()->mutable_extension_height()->set_value_nm( m_extensionHeight );
1333
1334 dimension.mutable_orthogonal()->set_alignment( m_orientation == DIR::VERTICAL
1335 ? types::AxisAlignment::AA_Y_AXIS
1336 : types::AxisAlignment::AA_X_AXIS );
1337 if( !aContainer.PackFrom( dimension ) )
1338 wxFAIL_MSG( wxT( "Failed to pack PCB_DIM_ORTHOGONAL" ) );
1339}
1340
1341
1342bool PCB_DIM_ORTHOGONAL::Deserialize( const google::protobuf::Any &aContainer )
1343{
1344 using namespace kiapi::common;
1345
1346 if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
1347 return false;
1348
1349 kiapi::board::types::Dimension dimension;
1350
1351 if( !aContainer.UnpackTo( &dimension ) )
1352 return false;
1353
1354 if( !dimension.has_orthogonal() )
1355 return false;
1356
1357 SetStart( UnpackVector2( dimension.orthogonal().start() ) );
1358 SetEnd( UnpackVector2( dimension.orthogonal().end() ) );
1359 SetHeight( (int) dimension.orthogonal().height().value_nm());
1360 SetExtensionHeight( (int) dimension.orthogonal().extension_height().value_nm() );
1361 SetOrientation( dimension.orthogonal().alignment() == types::AxisAlignment::AA_Y_AXIS ? DIR::VERTICAL
1362 : DIR::HORIZONTAL );
1363
1364 Update();
1365
1366 return true;
1367}
1368
1369
1371{
1372 wxASSERT( aImage->Type() == Type() );
1373
1374 m_shapes.clear();
1375 static_cast<PCB_DIM_ORTHOGONAL*>( aImage )->m_shapes.clear();
1376
1377 std::swap( *static_cast<PCB_DIM_ORTHOGONAL*>( this ),
1378 *static_cast<PCB_DIM_ORTHOGONAL*>( aImage ) );
1379
1380 Update();
1381}
1382
1383
1384void PCB_DIM_ORTHOGONAL::Mirror( const VECTOR2I& axis_pos, FLIP_DIRECTION aFlipDirection )
1385{
1386 // Only reverse the height if the height is aligned with the flip
1387 if( m_orientation == DIR::HORIZONTAL && aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
1388 m_height = -m_height;
1389 else if( m_orientation == DIR::VERTICAL && aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
1390 m_height = -m_height;
1391
1392 // Call this last, as we need the Update()
1393 PCB_DIMENSION_BASE::Mirror( axis_pos, aFlipDirection );
1394}
1395
1396
1401
1402
1404{
1405 if( m_busy ) // Skeep reentrance that happens sometimes after calling updateText()
1406 return;
1407
1408 m_busy = true;
1409 m_shapes.clear();
1410
1411 const VECTOR2I start = GetStart();
1412 const VECTOR2I end = GetEnd();
1413
1414 int measurement = ( m_orientation == DIR::HORIZONTAL ? end.x - start.x : end.y - start.y );
1416
1417 VECTOR2I extension;
1418
1420 extension = VECTOR2I( 0, m_height );
1421 else
1422 extension = VECTOR2I( m_height, 0 );
1423
1424 // Add first extension line
1425 int extensionHeight = std::abs( m_height ) - m_extensionOffset + m_extensionHeight;
1426
1427 VECTOR2I extStart( start );
1428 extStart += extension.Resize( m_extensionOffset );
1429
1430 addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
1431
1432 // Add crossbar
1433 VECTOR2I crossBarDistance = sign( m_height ) * extension.Resize( m_height );
1434 m_crossBarStart = start + crossBarDistance;
1435
1438 else
1440
1441 // Add second extension line (end to crossbar end)
1443 extension = VECTOR2I( 0, end.y - m_crossBarEnd.y );
1444 else
1445 extension = VECTOR2I( end.x - m_crossBarEnd.x, 0 );
1446
1447 extensionHeight = extension.EuclideanNorm() - m_extensionOffset + m_extensionHeight;
1448
1449 extStart = VECTOR2I( m_crossBarEnd );
1450 extStart -= extension.Resize( m_extensionHeight );
1451
1452 addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
1453
1454 // Update text after calculating crossbar position but before adding crossbar lines
1455 updateText();
1456
1457 // Now that we have the text updated, we can determine how to draw the crossbar.
1458 // First we need to create an appropriate bounding polygon to collide with
1459 BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() );
1460
1461 SHAPE_POLY_SET polyBox;
1462 polyBox.NewOutline();
1463 polyBox.Append( textBox.GetOrigin() );
1464 polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
1465 polyBox.Append( textBox.GetEnd() );
1466 polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
1467 polyBox.Rotate( GetTextAngle(), textBox.GetCenter() );
1468
1469 // The ideal crossbar, if the text doesn't collide
1470 SEG crossbar( m_crossBarStart, m_crossBarEnd );
1471
1472 CollectKnockedOutSegments( polyBox, crossbar, m_shapes );
1473
1474 EDA_ANGLE crossBarAngle( m_crossBarEnd - m_crossBarStart );
1475
1477 {
1478 // Arrows with fixed length.
1479 drawAnArrow( m_crossBarStart, crossBarAngle + EDA_ANGLE( 180 ),
1482 }
1483 else
1484 {
1485 drawAnArrow( m_crossBarStart, crossBarAngle, 0 );
1486 drawAnArrow( m_crossBarEnd, crossBarAngle + EDA_ANGLE( 180 ), 0 );
1487 }
1488
1489 m_busy = false;
1490}
1491
1492
1494{
1495 VECTOR2I crossbarCenter( ( m_crossBarEnd - m_crossBarStart ) / 2 );
1496
1498 {
1499 int textOffsetDistance = GetEffectiveTextPenWidth() + GetTextHeight();
1500
1501 VECTOR2I textOffset;
1502
1504 textOffset.y = -textOffsetDistance;
1505 else
1506 textOffset.x = -textOffsetDistance;
1507
1508 textOffset += crossbarCenter;
1509
1510 SetTextPos( m_crossBarStart + textOffset );
1511 }
1513 {
1514 SetTextPos( m_crossBarStart + crossbarCenter );
1515 }
1516
1517 if( m_keepTextAligned )
1518 {
1519 if( abs( crossbarCenter.x ) > abs( crossbarCenter.y ) )
1521 else
1523 }
1524
1526}
1527
1528
1529void PCB_DIM_ORTHOGONAL::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
1530{
1531 EDA_ANGLE angle( aAngle );
1532
1533 // restrict angle to -179.9 to 180.0 degrees
1534 angle.Normalize180();
1535
1536 // adjust orientation and height to new angle
1537 // we can only handle the cases of -90, 0, 90, 180 degrees exactly;
1538 // in the other cases we will use the nearest 90 degree angle to
1539 // choose at least an approximate axis for the target orientation
1540 // In case of exactly 45 or 135 degrees, we will round towards zero for consistency
1541 if( angle > ANGLE_45 && angle <= ANGLE_135 )
1542 {
1543 // about 90 degree
1545 {
1547 }
1548 else
1549 {
1551 m_height = -m_height;
1552 }
1553 }
1554 else if( angle < -ANGLE_45 && angle >= -ANGLE_135 )
1555 {
1556 // about -90 degree
1558 {
1560 m_height = -m_height;
1561 }
1562 else
1563 {
1565 }
1566 }
1567 else if( angle > ANGLE_135 || angle < -ANGLE_135 )
1568 {
1569 // about 180 degree
1570 m_height = -m_height;
1571 }
1572
1573 // this will update m_crossBarStart and m_crossbarEnd
1574 PCB_DIMENSION_BASE::Rotate( aRotCentre, angle );
1575}
1576
1577
1588
1589
1591{
1592 wxCHECK( aOther && aOther->Type() == PCB_DIM_LEADER_T, /* void */ );
1593 *this = *static_cast<const PCB_DIM_LEADER*>( aOther );
1594}
1595
1596void PCB_DIM_LEADER::Serialize( google::protobuf::Any &aContainer ) const
1597{
1598 using namespace kiapi::common;
1599 kiapi::board::types::Dimension dimension;
1600
1601 PCB_DIMENSION_BASE::Serialize( aContainer );
1602
1603 if( !aContainer.UnpackTo( &dimension ) )
1604 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1605
1606 PackVector2( *dimension.mutable_leader()->mutable_start(), GetStart() );
1607 PackVector2( *dimension.mutable_leader()->mutable_end(), GetEnd() );
1608 dimension.mutable_leader()->set_border_style(
1610 m_textBorder ) );
1611
1612 if( !aContainer.PackFrom( dimension ) )
1613 wxFAIL_MSG( wxT( "Failed to pack PCB_DIM_LEADER" ) );
1614}
1615
1616
1617bool PCB_DIM_LEADER::Deserialize( const google::protobuf::Any &aContainer )
1618{
1619 using namespace kiapi::common;
1620
1621 if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
1622 return false;
1623
1624 kiapi::board::types::Dimension dimension;
1625
1626 if( !aContainer.UnpackTo( &dimension ) )
1627 return false;
1628
1629 if( !dimension.has_leader() )
1630 return false;
1631
1632 SetStart( UnpackVector2( dimension.leader().start() ) );
1633 SetEnd( UnpackVector2( dimension.leader().end() ) );
1634 SetTextBorder( FromProtoEnum<DIM_TEXT_BORDER>( dimension.leader().border_style() ) );
1635
1636 Update();
1637
1638 return true;
1639}
1640
1641
1643{
1644 return new PCB_DIM_LEADER( *this );
1645}
1646
1647
1649{
1650 wxASSERT( aImage->Type() == Type() );
1651
1652 m_shapes.clear();
1653 static_cast<PCB_DIM_LEADER*>( aImage )->m_shapes.clear();
1654
1655 std::swap( *static_cast<PCB_DIM_LEADER*>( this ), *static_cast<PCB_DIM_LEADER*>( aImage ) );
1656
1657 Update();
1658}
1659
1660
1665
1666
1668{
1669 // Our geometry is dependent on the size of the text, so just update the whole shebang
1671}
1672
1673
1675{
1676 if( m_busy ) // Skeep reentrance that happens sometimes after calling updateText()
1677 return;
1678
1679 m_busy = true;
1680
1681 m_shapes.clear();
1682
1684
1685 // Now that we have the text updated, we can determine how to draw the second line
1686 // First we need to create an appropriate bounding polygon to collide with
1687 BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() * 2 );
1688
1689 SHAPE_POLY_SET polyBox;
1690 polyBox.NewOutline();
1691 polyBox.Append( textBox.GetOrigin() );
1692 polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
1693 polyBox.Append( textBox.GetEnd() );
1694 polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
1695 polyBox.Rotate( GetTextAngle(), textBox.GetCenter() );
1696
1697 const VECTOR2I boardStart = GetStart();
1698 const VECTOR2I boardEnd = GetEnd();
1699
1700 VECTOR2I firstLine( boardEnd - boardStart );
1701 VECTOR2I start( boardStart );
1702 start += firstLine.Resize( m_extensionOffset );
1703
1704 SEG arrowSeg( boardStart, boardEnd );
1705 SEG textSeg( boardEnd, GetTextPos() );
1706 OPT_VECTOR2I arrowSegEnd;
1707 OPT_VECTOR2I textSegEnd;
1708
1710 {
1711 double penWidth = GetEffectiveTextPenWidth() / 2.0;
1712 double radius = ( textBox.GetWidth() / 2.0 ) - penWidth;
1713 CIRCLE circle( textBox.GetCenter(), radius );
1714
1715 arrowSegEnd = segCircleIntersection( circle, arrowSeg );
1716 textSegEnd = segCircleIntersection( circle, textSeg );
1717 }
1718 else
1719 {
1720 arrowSegEnd = segPolyIntersection( polyBox, arrowSeg );
1721 textSegEnd = segPolyIntersection( polyBox, textSeg );
1722 }
1723
1724 if( !arrowSegEnd )
1725 arrowSegEnd = boardEnd;
1726
1727 m_shapes.emplace_back( new SHAPE_SEGMENT( start, *arrowSegEnd ) );
1728
1729 drawAnArrow( start, EDA_ANGLE( firstLine ), 0 );
1730
1731 if( !GetText().IsEmpty() )
1732 {
1733 switch( m_textBorder )
1734 {
1736 {
1737 for( SHAPE_POLY_SET::SEGMENT_ITERATOR seg = polyBox.IterateSegments(); seg; seg++ )
1738 m_shapes.emplace_back( new SHAPE_SEGMENT( *seg ) );
1739
1740 break;
1741 }
1742
1744 {
1745 double penWidth = GetEffectiveTextPenWidth() / 2.0;
1746 double radius = ( textBox.GetWidth() / 2.0 ) - penWidth;
1747 m_shapes.emplace_back( new SHAPE_CIRCLE( textBox.GetCenter(), radius ) );
1748
1749 break;
1750 }
1751
1752 default:
1753 break;
1754 }
1755 }
1756
1757 if( textSegEnd && *arrowSegEnd == boardEnd )
1758 m_shapes.emplace_back( new SHAPE_SEGMENT( boardEnd, *textSegEnd ) );
1759
1760 m_busy = false;
1761}
1762
1763
1764void PCB_DIM_LEADER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1765{
1766 // Don't use GetShownText(); we want to see the variable references here
1767 aList.emplace_back( _( "Leader" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
1768
1769 ORIGIN_TRANSFORMS& originTransforms = aFrame->GetOriginTransforms();
1770
1771 VECTOR2I startCoord = originTransforms.ToDisplayAbs( GetStart() );
1772 wxString start = wxString::Format( wxT( "@(%s, %s)" ),
1773 aFrame->MessageTextFromValue( startCoord.x ),
1774 aFrame->MessageTextFromValue( startCoord.y ) );
1775
1776 aList.emplace_back( start, wxEmptyString );
1777
1778 aList.emplace_back( _( "Layer" ), GetLayerName() );
1779}
1780
1781
1791
1793{
1794 wxCHECK( aOther && aOther->Type() == PCB_DIM_RADIAL_T, /* void */ );
1795 *this = *static_cast<const PCB_DIM_RADIAL*>( aOther );
1796}
1797
1798void PCB_DIM_RADIAL::Serialize( google::protobuf::Any &aContainer ) const
1799{
1800 using namespace kiapi::common;
1801 kiapi::board::types::Dimension dimension;
1802
1803 PCB_DIMENSION_BASE::Serialize( aContainer );
1804
1805 if( !aContainer.UnpackTo( &dimension ) )
1806 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1807
1808 PackVector2( *dimension.mutable_radial()->mutable_center(), GetStart() );
1809 PackVector2( *dimension.mutable_radial()->mutable_radius_point(), GetEnd() );
1810 dimension.mutable_radial()->mutable_leader_length()->set_value_nm( m_leaderLength );
1811
1812 if( !aContainer.PackFrom( dimension ) )
1813 wxFAIL_MSG( wxT( "Failed to pack PCB_DIM_RADIAL" ) );
1814}
1815
1816
1817bool PCB_DIM_RADIAL::Deserialize( const google::protobuf::Any &aContainer )
1818{
1819 using namespace kiapi::common;
1820
1821 if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
1822 return false;
1823
1824 kiapi::board::types::Dimension dimension;
1825
1826 if( !aContainer.UnpackTo( &dimension ) )
1827 return false;
1828
1829 if( !dimension.has_radial() )
1830 return false;
1831
1832 SetStart( UnpackVector2( dimension.radial().center() ) );
1833 SetEnd( UnpackVector2( dimension.radial().radius_point() ) );
1834 SetLeaderLength( (int) dimension.radial().leader_length().value_nm() );
1835
1836 Update();
1837
1838 return true;
1839}
1840
1841
1843{
1844 return new PCB_DIM_RADIAL( *this );
1845}
1846
1847
1849{
1850 wxASSERT( aImage->Type() == Type() );
1851
1852 m_shapes.clear();
1853 static_cast<PCB_DIM_RADIAL*>( aImage )->m_shapes.clear();
1854
1855 std::swap( *static_cast<PCB_DIM_RADIAL*>( this ), *static_cast<PCB_DIM_RADIAL*>( aImage ) );
1856
1857 Update();
1858}
1859
1860
1865
1866
1868{
1869 const VECTOR2I end = GetEnd();
1870 VECTOR2I radial( end - GetStart() );
1871
1872 return end + radial.Resize( m_leaderLength );
1873}
1874
1875
1877{
1878 if( m_keepTextAligned )
1879 {
1880 VECTOR2I textLine( GetTextPos() - GetKnee() );
1881 EDA_ANGLE textAngle = FULL_CIRCLE - EDA_ANGLE( textLine );
1882
1883 textAngle.Normalize();
1884
1885 if( textAngle > ANGLE_90 && textAngle <= ANGLE_270 )
1886 textAngle -= ANGLE_180;
1887
1888 // Round to nearest degree
1889 textAngle = EDA_ANGLE( KiROUND( textAngle.AsDegrees() ), DEGREES_T );
1890
1891 SetTextAngle( textAngle );
1892 }
1893
1895}
1896
1897
1899{
1900 if( m_busy ) // Skeep reentrance that happens sometimes after calling updateText()
1901 return;
1902
1903 m_busy = true;
1904
1905 m_shapes.clear();
1906
1907 const VECTOR2I boardStart = GetStart();
1908 const VECTOR2I boardEnd = GetEnd();
1909
1910 VECTOR2I center( boardStart );
1911 VECTOR2I centerArm( 0, m_arrowLength );
1912
1913 m_shapes.emplace_back( new SHAPE_SEGMENT( center - centerArm, center + centerArm ) );
1914
1915 RotatePoint( centerArm, -ANGLE_90 );
1916
1917 m_shapes.emplace_back( new SHAPE_SEGMENT( center - centerArm, center + centerArm ) );
1918
1919 VECTOR2I radius( boardEnd - boardStart );
1920
1921 m_measuredValue = KiROUND( radius.EuclideanNorm() );
1922
1923 updateText();
1924
1925 // Now that we have the text updated, we can determine how to draw the second line
1926 // First we need to create an appropriate bounding polygon to collide with
1927 BOX2I textBox = GetTextBox( nullptr ).Inflate( GetTextWidth() / 2, GetEffectiveTextPenWidth() );
1928
1929 SHAPE_POLY_SET polyBox;
1930 polyBox.NewOutline();
1931 polyBox.Append( textBox.GetOrigin() );
1932 polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
1933 polyBox.Append( textBox.GetEnd() );
1934 polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
1935 polyBox.Rotate( GetTextAngle(), textBox.GetCenter() );
1936
1937 VECTOR2I radial( boardEnd - boardStart );
1938 radial = radial.Resize( m_leaderLength );
1939
1940 SEG arrowSeg( boardEnd, boardEnd + radial );
1941 SEG textSeg( arrowSeg.B, GetTextPos() );
1942
1943 CollectKnockedOutSegments( polyBox, arrowSeg, m_shapes );
1944 CollectKnockedOutSegments( polyBox, textSeg, m_shapes );
1945
1946 drawAnArrow( boardEnd, EDA_ANGLE( radial ), 0 );
1947
1948 m_busy = false;
1949}
1950
1951
1958
1960{
1961 wxCHECK( aOther && aOther->Type() == PCB_DIM_CENTER_T, /* void */ );
1962 *this = *static_cast<const PCB_DIM_CENTER*>( aOther );
1963}
1964
1965void PCB_DIM_CENTER::Serialize( google::protobuf::Any &aContainer ) const
1966{
1967 using namespace kiapi::common;
1968 kiapi::board::types::Dimension dimension;
1969
1970 PCB_DIMENSION_BASE::Serialize( aContainer );
1971
1972 if( !aContainer.UnpackTo( &dimension ) )
1973 wxFAIL_MSG( wxT( "Failed to unpack dimension from internal serialization" ) );
1974
1975 PackVector2( *dimension.mutable_center()->mutable_center(), GetStart() );
1976 PackVector2( *dimension.mutable_center()->mutable_end(), GetEnd() );
1977
1978 if( !aContainer.PackFrom( dimension ) )
1979 wxFAIL_MSG( wxT( "Failed to pack PCB_DIM_CENTER" ) );
1980}
1981
1982
1983bool PCB_DIM_CENTER::Deserialize( const google::protobuf::Any &aContainer )
1984{
1985 using namespace kiapi::common;
1986
1987 if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
1988 return false;
1989
1990 kiapi::board::types::Dimension dimension;
1991
1992 if( !aContainer.UnpackTo( &dimension ) )
1993 return false;
1994
1995 if( !dimension.has_center() )
1996 return false;
1997
1998 SetStart( UnpackVector2( dimension.center().center() ) );
1999 SetEnd( UnpackVector2( dimension.center().end() ) );
2000
2001 Update();
2002
2003 return true;
2004}
2005
2006
2008{
2009 return new PCB_DIM_CENTER( *this );
2010}
2011
2012
2014{
2015 wxASSERT( aImage->Type() == Type() );
2016
2017 std::swap( *static_cast<PCB_DIM_CENTER*>( this ), *static_cast<PCB_DIM_CENTER*>( aImage ) );
2018}
2019
2020
2025
2026
2028{
2029 BOX2I bBox;
2030 int xmin, xmax, ymin, ymax;
2031
2032 const VECTOR2I start = GetStart();
2033 xmin = start.x;
2034 xmax = start.x;
2035 ymin = start.y;
2036 ymax = start.y;
2037
2038 for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
2039 {
2040 BOX2I shapeBox = shape->BBox();
2041 shapeBox.Inflate( m_lineThickness / 2 );
2042
2043 xmin = std::min( xmin, shapeBox.GetOrigin().x );
2044 xmax = std::max( xmax, shapeBox.GetEnd().x );
2045 ymin = std::min( ymin, shapeBox.GetOrigin().y );
2046 ymax = std::max( ymax, shapeBox.GetEnd().y );
2047 }
2048
2049 bBox.SetX( xmin );
2050 bBox.SetY( ymin );
2051 bBox.SetWidth( xmax - xmin + 1 );
2052 bBox.SetHeight( ymax - ymin + 1 );
2053
2054 bBox.Normalize();
2055
2056 return bBox;
2057}
2058
2059
2061{
2062 return GetBoundingBox();
2063}
2064
2065
2067{
2068 // Even if PCB_DIM_CENTER has no text, we still need to update its text position
2069 // so GetTextPos() users get a valid value. Required at least for lasso hit-testing.
2070 SetTextPos( GetStart() );
2071
2073}
2074
2075
2077{
2078 if( m_busy ) // Skeep reentrance that happens sometimes after calling updateText()
2079 return;
2080
2081 m_busy = true;
2082
2083 m_shapes.clear();
2084
2085 const VECTOR2I boardStart = GetStart();
2086 const VECTOR2I boardEnd = GetEnd();
2087 VECTOR2I center( boardStart );
2088 VECTOR2I arm( boardEnd - boardStart );
2089
2090 m_shapes.emplace_back( new SHAPE_SEGMENT( center - arm, center + arm ) );
2091
2092 RotatePoint( arm, -ANGLE_90 );
2093
2094 m_shapes.emplace_back( new SHAPE_SEGMENT( center - arm, center + arm ) );
2095
2096 updateText();
2097
2098 m_busy = false;
2099}
2100
2101
2102static struct DIMENSION_DESC
2103{
2105 {
2107 .Map( DIM_PRECISION::X, _HKI( "0" ) )
2108 .Map( DIM_PRECISION::X_X, _HKI( "0.0" ) )
2109 .Map( DIM_PRECISION::X_XX, _HKI( "0.00" ) )
2110 .Map( DIM_PRECISION::X_XXX, _HKI( "0.000" ) )
2111 .Map( DIM_PRECISION::X_XXXX, _HKI( "0.0000" ) )
2112 .Map( DIM_PRECISION::X_XXXXX, _HKI( "0.00000" ) )
2113 .Map( DIM_PRECISION::V_VV, _HKI( "0.00 in / 0 mils / 0.0 mm" ) )
2114 .Map( DIM_PRECISION::V_VVV, _HKI( "0.000 / 0 / 0.00" ) )
2115 .Map( DIM_PRECISION::V_VVVV, _HKI( "0.0000 / 0.0 / 0.000" ) )
2116 .Map( DIM_PRECISION::V_VVVVV, _HKI( "0.00000 / 0.00 / 0.0000" ) );
2117
2119 .Map( DIM_UNITS_FORMAT::NO_SUFFIX, _HKI( "1234.0" ) )
2120 .Map( DIM_UNITS_FORMAT::BARE_SUFFIX, _HKI( "1234.0 mm" ) )
2121 .Map( DIM_UNITS_FORMAT::PAREN_SUFFIX, _HKI( "1234.0 (mm)" ) );
2122
2124 .Map( DIM_UNITS_MODE::INCH, _HKI( "Inches" ) )
2125 .Map( DIM_UNITS_MODE::MILS, _HKI( "Mils" ) )
2126 .Map( DIM_UNITS_MODE::MM, _HKI( "Millimeters" ) )
2127 .Map( DIM_UNITS_MODE::AUTOMATIC, _HKI( "Automatic" ) );
2128
2130 .Map( DIM_ARROW_DIRECTION::INWARD, _HKI( "Inward" ) )
2131 .Map( DIM_ARROW_DIRECTION::OUTWARD, _HKI( "Outward" ) );
2132
2134 .Map( DIM_VALUE_MODE::DRIVEN, _HKI( "Driven" ) )
2135 .Map( DIM_VALUE_MODE::DRIVING, _HKI( "Driving" ) )
2136 .Map( DIM_VALUE_MODE::ARBITRARY, _HKI( "Arbitrary" ) );
2137
2139 .Map( DIM_TEXT_POSITION::OUTSIDE, _HKI( "Outside" ) )
2140 .Map( DIM_TEXT_POSITION::INLINE, _HKI( "Inline" ) )
2141 .Map( DIM_TEXT_POSITION::MANUAL, _HKI( "Manual" ) );
2142
2151
2152 propMgr.Mask( TYPE_HASH( PCB_DIMENSION_BASE ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
2153
2154 const wxString groupDimension = _HKI( "Dimension Properties" );
2155
2156 auto isLeader =
2157 []( INSPECTABLE* aItem ) -> bool
2158 {
2159 return dynamic_cast<PCB_DIM_LEADER*>( aItem ) != nullptr;
2160 };
2161
2162 auto isNotLeader =
2163 []( INSPECTABLE* aItem ) -> bool
2164 {
2165 return dynamic_cast<PCB_DIM_LEADER*>( aItem ) == nullptr;
2166 };
2167
2168 auto isNotCenter =
2169 []( INSPECTABLE* aItem ) -> bool
2170 {
2171 return dynamic_cast<PCB_DIM_CENTER*>( aItem ) == nullptr;
2172 };
2173
2174 auto isMultiArrowDirection =
2175 []( INSPECTABLE* aItem ) -> bool
2176 {
2177 return dynamic_cast<PCB_DIM_ALIGNED*>( aItem ) != nullptr;
2178 };
2179
2182 groupDimension )
2183 .SetAvailableFunc( isNotLeader );
2186 groupDimension )
2187 .SetAvailableFunc( isNotLeader );
2188
2189 auto hasValueMode =
2190 []( INSPECTABLE* aItem ) -> bool
2191 {
2192 return DimensionHasValueMode( dynamic_cast<PCB_DIMENSION_BASE*>( aItem ) );
2193 };
2194
2195 // Value bearing dims use Value row instead while leaders keep Text below
2196 // Override Text left for centre mark only
2197 auto usesOverrideText =
2198 [isLeader, hasValueMode]( INSPECTABLE* aItem ) -> bool
2199 {
2200 return aItem && !isLeader( aItem ) && !hasValueMode( aItem );
2201 };
2202
2203 // Driving needs both endpoints bound to movable geometry
2204 // Dropdown always offers it so gate the transition here
2205 auto valueModeValidator =
2206 []( const wxAny&& aValue, EDA_ITEM* aItem ) -> VALIDATOR_RESULT
2207 {
2208 PCB_DIMENSION_BASE* dim = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
2209
2210 if( !dim )
2211 return std::nullopt;
2212
2213 int mode = 0;
2214
2215 if( aValue.CheckType<DIM_VALUE_MODE>() )
2216 mode = static_cast<int>( aValue.As<DIM_VALUE_MODE>() );
2217 else if( !aValue.GetAs( &mode ) )
2218 return std::nullopt;
2219
2220 if( mode == static_cast<int>( DIM_VALUE_MODE::DRIVING )
2221 && !DimensionCanDrive( dim->GetBoard(), dim ) )
2222 {
2223 return std::make_unique<VALIDATION_ERROR_MSG>(
2224 _( "Driving requires both dimension endpoints bound to objects" ) );
2225 }
2226
2227 return std::nullopt;
2228 };
2229
2230 // Driving edits length constraint which must stay positive
2231 // Catches zero and negative and stale exprs parsing to zero
2232 auto drivingValueValidator =
2233 []( const wxAny&& aValue, EDA_ITEM* aItem ) -> VALIDATOR_RESULT
2234 {
2235 PCB_DIMENSION_BASE* dim = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
2236
2237 if( !dim || dim->GetValueMode() != DIM_VALUE_MODE::DRIVING )
2238 return std::nullopt;
2239
2240 wxString text;
2241
2242 if( !aValue.GetAs( &text ) )
2243 return std::nullopt;
2244
2246
2247 if( !( iu > 0.0 ) )
2248 {
2249 return std::make_unique<VALIDATION_ERROR_MSG>(
2250 _( "Enter a positive length for a driving dimension" ) );
2251 }
2252
2253 return std::nullopt;
2254 };
2255
2256 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, wxString>( _HKI( "Override Text" ),
2258 groupDimension )
2259 .SetAvailableFunc( usesOverrideText );
2260
2263 groupDimension )
2264 .SetAvailableFunc( hasValueMode )
2265 .SetValidator( std::move( valueModeValidator ) );
2266
2269 groupDimension )
2270 .SetAvailableFunc( hasValueMode )
2272 []( INSPECTABLE* aItem ) -> bool
2273 {
2274 // Driven mirrors measured geometry so grey it out since edit would not stick
2275 PCB_DIMENSION_BASE* dim = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
2276 return dim && dim->GetValueMode() != DIM_VALUE_MODE::DRIVEN;
2277 } )
2278 .SetValidator( std::move( drivingValueValidator ) );
2279
2282 groupDimension )
2283 .SetAvailableFunc( isLeader );
2284
2287 groupDimension )
2288 .SetAvailableFunc( isNotLeader )
2289 .SetIsCopyable();
2292 groupDimension )
2293 .SetAvailableFunc( isNotLeader )
2294 .SetIsCopyable();
2297 groupDimension )
2298 .SetAvailableFunc( isNotLeader )
2299 .SetIsCopyable();
2300 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, bool>( _HKI( "Suppress Trailing Zeroes" ),
2302 groupDimension )
2303 .SetAvailableFunc( isNotLeader )
2304 .SetIsCopyable();
2305
2308 groupDimension )
2309 .SetAvailableFunc( isMultiArrowDirection )
2310 .SetIsCopyable();
2311
2312 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, int>( _HKI( "Line Thickness" ),
2315 groupDimension )
2316 .SetIsCopyable();
2317
2318 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, int>( _HKI( "Arrow Length" ),
2321 groupDimension )
2322 .SetAvailableFunc( isNotCenter )
2323 .SetIsCopyable();
2324
2325 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, int>( _HKI( "Extension Line Offset" ),
2328 groupDimension )
2329 .SetAvailableFunc( isNotCenter )
2330 .SetIsCopyable();
2331
2332 const wxString groupText = _HKI( "Text Properties" );
2333
2336 groupText )
2337 .SetAvailableFunc( isNotLeader )
2338 .SetIsCopyable();
2339
2340 const auto isTextOrientationWriteable =
2341 []( INSPECTABLE* aItem ) -> bool
2342 {
2343 return !static_cast<PCB_DIMENSION_BASE*>( aItem )->GetKeepTextAligned();
2344 };
2345
2346 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, bool>( _HKI( "Keep Aligned with Dimension" ),
2349 groupText );
2350
2351 propMgr.AddProperty( new PROPERTY<PCB_DIMENSION_BASE, double>( _HKI( "Orientation" ),
2355 groupText )
2356 .SetWriteableFunc( isTextOrientationWriteable );
2357 }
2359
2366
2367
2369{
2371 {
2382
2383 const wxString groupDimension = _HKI( "Dimension Properties" );
2384
2385 propMgr.AddProperty( new PROPERTY<PCB_DIM_ALIGNED, int>( _HKI( "Crossbar Height" ),
2388 groupDimension );
2389 propMgr.AddProperty( new PROPERTY<PCB_DIM_ALIGNED, int>( _HKI( "Extension Line Overshoot" ),
2392 groupDimension );
2393
2395 _HKI( "Text" ),
2396 []( INSPECTABLE* aItem ) { return false; } );
2398 _HKI( "Vertical Justification" ),
2399 []( INSPECTABLE* aItem ) { return false; } );
2401 _HKI( "Hyperlink" ),
2402 []( INSPECTABLE* aItem ) { return false; } );
2404 _HKI( "Knockout" ),
2405 []( INSPECTABLE* aItem ) { return false; } );
2406 }
2408
2409
2411{
2413 {
2426
2428 _HKI( "Text" ),
2429 []( INSPECTABLE* aItem ) { return false; } );
2431 _HKI( "Vertical Justification" ),
2432 []( INSPECTABLE* aItem ) { return false; } );
2434 _HKI( "Hyperlink" ),
2435 []( INSPECTABLE* aItem ) { return false; } );
2437 _HKI( "Knockout" ),
2438 []( INSPECTABLE* aItem ) { return false; } );
2439 }
2441
2442
2444{
2446 {
2457
2458 const wxString groupDimension = _HKI( "Dimension Properties" );
2459
2460 propMgr.AddProperty( new PROPERTY<PCB_DIM_RADIAL, int>( _HKI( "Leader Length" ),
2463 groupDimension );
2464
2466 _HKI( "Text" ),
2467 []( INSPECTABLE* aItem ) { return false; } );
2469 _HKI( "Vertical Justification" ),
2470 []( INSPECTABLE* aItem ) { return false; } );
2472 _HKI( "Hyperlink" ),
2473 []( INSPECTABLE* aItem ) { return false; } );
2475 _HKI( "Knockout" ),
2476 []( INSPECTABLE* aItem ) { return false; } );
2477 }
2479
2480
2482{
2484 {
2486 .Map( DIM_TEXT_BORDER::NONE, _HKI( "None" ) )
2487 .Map( DIM_TEXT_BORDER::RECTANGLE, _HKI( "Rectangle" ) )
2488 .Map( DIM_TEXT_BORDER::CIRCLE, _HKI( "Circle" ) );
2489
2500
2501 const wxString groupDimension = _HKI( "Dimension Properties" );
2502
2505 groupDimension );
2506
2508 _HKI( "Text" ),
2509 []( INSPECTABLE* aItem ) { return false; } );
2511 _HKI( "Vertical Justification" ),
2512 []( INSPECTABLE* aItem ) { return false; } );
2514 _HKI( "Hyperlink" ),
2515 []( INSPECTABLE* aItem ) { return false; } );
2517 _HKI( "Knockout" ),
2518 []( INSPECTABLE* aItem ) { return false; } );
2519 }
2521
2523
2524
2526{
2528 {
2539
2540
2542 _HKI( "Text" ),
2543 []( INSPECTABLE* aItem ) { return false; } );
2545 _HKI( "Vertical Justification" ),
2546 []( INSPECTABLE* aItem ) { return false; } );
2548 _HKI( "Hyperlink" ),
2549 []( INSPECTABLE* aItem ) { return false; } );
2551 _HKI( "Knockout" ),
2552 []( INSPECTABLE* aItem ) { return false; } );
2553 }
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BITMAPS
A list of all bitmap identifiers.
@ add_radial_dimension
@ add_aligned_dimension
@ add_center_dimension
@ add_orthogonal_dimension
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
Container for design settings for a BOARD object.
DIM_PRECISION m_DimensionPrecision
Number of digits after the decimal.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
DIM_TEXT_POSITION m_DimensionTextPosition
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:101
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
Definition board_item.h:441
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
PCB_LAYER_ID m_layer
Definition board_item.h:625
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual double GetCoverageArea(int aTextMargin) const
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
bool IsSideSpecific() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
EDA_UNITS GetUserUnits()
Definition board.h:1041
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 void SetHeight(size_type val)
Definition box2.h:295
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr coord_type GetY() const
Definition box2.h:211
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr coord_type GetX() const
Definition box2.h:210
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 bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr void SetWidth(size_type val)
Definition box2.h:290
constexpr void SetX(coord_type val)
Definition box2.h:280
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr void SetY(coord_type val)
Definition box2.h:285
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:314
constexpr coord_type GetBottom() const
Definition box2.h:225
Represent basic circle geometry with utility geometry functions.
Definition circle.h:33
std::vector< VECTOR2I > Intersect(const CIRCLE &aCircle) const
Compute the intersection points between this circle and aCircle.
Definition circle.cpp:243
bool Contains(const VECTOR2I &aP) const
Return true if aP is on the circumference of this circle.
Definition circle.cpp:188
EDA_ANGLE Normalize()
Definition eda_angle.h:228
double AsDegrees() const
Definition eda_angle.h:115
EDA_ANGLE Normalize180()
Definition eda_angle.h:273
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:609
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition eda_text.cpp:170
virtual VECTOR2I GetTextPos() const
Definition eda_text.h:313
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
virtual int GetTextHeight() const
Definition eda_text.h:307
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition eda_text.cpp:201
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:355
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition eda_text.cpp:755
virtual int GetTextWidth() const
Definition eda_text.h:304
virtual void ClearBoundingBoxCache()
Definition eda_text.cpp:676
double Similarity(const EDA_TEXT &aOther) const
virtual void ClearRenderCache()
Definition eda_text.cpp:670
bool IsMirrored() const
Definition eda_text.h:229
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
Build a list of segments (SHAPE_SEGMENT) to describe a text shape.
void SetTextAngleDegrees(double aOrientation)
Definition eda_text.h:181
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:444
static ENUM_MAP< T > & Instance()
Definition property.h:811
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:94
const std::unordered_set< KIID > & GetConstrainedItems() const
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:176
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:181
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
bool IsLayerVisibleCached(int aLayer) const
Definition view.h:472
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
Definition kiid.h:46
A class to perform either relative or absolute display origin transforms for a single axis of a point...
T ToDisplayAbs(const T &aValue) const
A geometric constraint between board items (issue #2329).
std::optional< double > GetValue() const
Abstract dimension API.
EDA_UNITS GetUnits() const
bool m_autoUnits
If true, follow the currently selected UI units.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void Update()
Update the dimension's cached text and geometry.
void ChangeSuffix(const wxString &aSuffix)
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
wxString GetOverrideText() const
wxString GetSuffix() const
std::vector< std::shared_ptr< SHAPE > > m_shapes
Internal cache of drawn shapes.
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void ClearRenderCache() override
int m_lineThickness
Thickness used for all graphics in the dimension.
virtual void SetEnd(const VECTOR2I &aPoint)
void Move(const VECTOR2I &offset) override
Move this object.
void SetUnitsFormat(const DIM_UNITS_FORMAT aFormat)
bool m_suppressZeroes
Suppress trailing zeroes.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void ChangeLineThickness(int aWidth)
int GetLineThickness() const
void SetUnits(EDA_UNITS aUnits)
VECTOR2I m_start
Start, FP-relative when in a footprint, board absolute otherwise.
DIM_PRECISION m_precision
Number of digits to display after decimal.
virtual void SetStart(const VECTOR2I &aPoint)
void addShape(const ShapeType &aShape)
void SetPrefix(const wxString &aPrefix)
wxString m_suffix
String appended to the value.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void ChangeOverrideText(const wxString &aValue)
void SetExtensionOffset(int aOffset)
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void SetSuppressZeroes(bool aSuppress)
bool m_inClearRenderCache
re-entrancy guard
PCB_DIMENSION_BASE(BOARD_ITEM *aParent, KICAD_T aType=PCB_DIMENSION_T)
void ChangeExtensionOffset(int aOffset)
int m_extensionOffset
Distance from feature points to extension line start.
DIM_TEXT_POSITION GetTextPositionMode() const
void ChangeArrowDirection(const DIM_ARROW_DIRECTION &aDirection)
bool GetKeepTextAligned() const
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
void ChangeTextAngleDegrees(double aDegrees)
bool m_keepTextAligned
Calculate text orientation to match dimension.
DIM_PRECISION GetPrecision() const
wxString GetPrefix() const
void SetOverrideTextEnabled(bool aOverride)
void SetSuffix(const wxString &aSuffix)
bool operator==(const PCB_DIMENSION_BASE &aOther) const
void ChangeValueMode(DIM_VALUE_MODE aMode)
Property panel setter for value mode override text flag lives on dimension length constraint is board...
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
DIM_UNITS_MODE GetUnitsMode() const
void drawAnArrow(VECTOR2I aStartPoint, EDA_ANGLE anAngle, int aLength)
Draws an arrow and updates the shape container.
void SetTextPositionMode(DIM_TEXT_POSITION aMode)
virtual void updateText()
Update the text field value from the current geometry (called by updateGeometry normally).
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
EDA_UNITS m_units
0 = inches, 1 = mm
int m_measuredValue
value of PCB dimensions
DIM_VALUE_MODE GetValueMode() const
Value mode from board state via DimensionValueMode.
DIM_UNITS_FORMAT GetUnitsFormat() const
void SetLineThickness(int aWidth)
void SetArrowLength(int aLength)
DIM_ARROW_DIRECTION GetArrowDirection() const
wxString m_valueString
Displayed value when m_overrideValue = true.
void ChangeTextPositionMode(DIM_TEXT_POSITION aMode)
virtual VECTOR2I GetEnd() const
void ChangePrecision(DIM_PRECISION aPrecision)
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
void SetPrecision(DIM_PRECISION aPrecision)
bool m_overrideTextEnabled
Manually specify the displayed measurement value.
DIM_UNITS_FORMAT m_unitsFormat
How to render the units suffix.
int GetMeasuredValue() const
bool GetSuppressZeroes() const
void SetArrowDirection(const DIM_ARROW_DIRECTION &aDirection)
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
DIM_TEXT_POSITION m_textPosition
How to position the text.
void SetOverrideText(const wxString &aValue)
wxString GetValueText() const
int GetExtensionOffset() const
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void ChangePrefix(const wxString &aPrefix)
wxString m_prefix
String prepended to the value.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
virtual VECTOR2I GetStart() const
The dimension's origin is the first feature point for the dimension.
DIM_ARROW_DIRECTION m_arrowDirection
direction of dimension arrow.
void ChangeKeepTextAligned(bool aKeepAligned)
void ChangeUnitsFormat(const DIM_UNITS_FORMAT aFormat)
wxString GetValueFieldText() const
Mode aware value for panel driving shows constraint length arbitrary shows override text otherwise sh...
void ChangeArrowLength(int aLength)
void ChangeSuppressZeroes(bool aSuppress)
int GetArrowLength() const
double GetCoverageArea(int aTextMargin) const override
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void ChangeValueFieldText(const wxString &aText)
Property panel setter for value arbitrary text owned by dimension driving edits board level constrain...
double GetTextAngleDegreesProp() const
bool GetOverrideTextEnabled() const
void SetUnitsMode(DIM_UNITS_MODE aMode)
int m_arrowLength
Length of arrow shapes.
virtual void Mirror(const VECTOR2I &axis_pos, FLIP_DIRECTION aFlipDirection) override
Mirror the dimension relative to a given horizontal axis.
VECTOR2I m_end
End, FP-relative when in a footprint, board absolute otherwise.
void ChangeUnitsMode(DIM_UNITS_MODE aMode)
void SetKeepTextAligned(bool aKeepAligned)
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
VECTOR2I GetPosition() const override
For better understanding of the points that make a dimension:
int GetHeight() const
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
int m_height
Perpendicular distance from features to crossbar.
void ChangeExtensionHeight(int aHeight)
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
void SetExtensionHeight(int aHeight)
VECTOR2I m_crossBarStart
Crossbar start control point.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void Mirror(const VECTOR2I &axis_pos, FLIP_DIRECTION aFlipDirection) override
Mirror the dimension relative to a given horizontal axis.
void UpdateHeight(const VECTOR2I &aCrossbarStart, const VECTOR2I &aCrossbarEnd)
Update the stored height basing on points coordinates.
virtual void swapData(BOARD_ITEM *aImage) override
int m_extensionHeight
Length of extension lines past the crossbar.
void CopyFrom(const BOARD_ITEM *aOther) override
void SetHeight(int aHeight)
Set the distance from the feature points to the crossbar line.
VECTOR2I m_crossBarEnd
Crossbar end control point.
PCB_DIM_ALIGNED(BOARD_ITEM *aParent, KICAD_T aType=PCB_DIM_ALIGNED_T)
void ChangeHeight(int aHeight)
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
int GetExtensionHeight() const
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Mark the center of a circle or arc with a cross shape.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void CopyFrom(const BOARD_ITEM *aOther) override
virtual void swapData(BOARD_ITEM *aImage) override
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
PCB_DIM_CENTER(BOARD_ITEM *aParent)
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
A leader is a dimension-like object pointing to a specific point.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
DIM_TEXT_BORDER m_textBorder
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
DIM_TEXT_BORDER GetTextBorder() const
void CopyFrom(const BOARD_ITEM *aOther) override
virtual void swapData(BOARD_ITEM *aImage) override
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
void SetTextBorder(DIM_TEXT_BORDER aBorder)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
PCB_DIM_LEADER(BOARD_ITEM *aParent)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void ChangeTextBorder(DIM_TEXT_BORDER aBorder)
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
void swapData(BOARD_ITEM *aImage) override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
void CopyFrom(const BOARD_ITEM *aOther) override
void SetOrientation(DIR aOrientation)
Set the orientation of the dimension line (so, perpendicular to the feature lines).
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
DIR m_orientation
What axis to lock the dimension line to.
void Mirror(const VECTOR2I &axis_pos, FLIP_DIRECTION aFlipDirection) override
Mirror the dimension relative to a given horizontal axis.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
PCB_DIM_ORTHOGONAL(BOARD_ITEM *aParent)
A radial dimension indicates either the radius or diameter of an arc or circle.
int GetLeaderLength() const
PCB_DIM_RADIAL(BOARD_ITEM *aParent)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
virtual void swapData(BOARD_ITEM *aImage) override
void SetLeaderLength(int aLength)
void CopyFrom(const BOARD_ITEM *aOther) override
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
void ChangeLeaderLength(int aLength)
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
VECTOR2I GetKnee() const
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
EDA_ANGLE GetLibTextAngle() const
Text angle in the parent footprint's lib frame, or absolute when not in a footprint.
Definition pcb_text.h:128
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
Definition pcb_text.cpp:373
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition pcb_text.cpp:244
EDA_ANGLE GetTextAngle() const override
Definition pcb_text.cpp:562
void Offset(const VECTOR2I &aOffset) override
Definition pcb_text.cpp:527
void SetLibTextAngle(const EDA_ANGLE &aAngle)
Definition pcb_text.h:130
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition pcb_text.cpp:259
VECTOR2I GetTextPos() const override
Definition pcb_text.cpp:463
PCB_TEXT(BOARD_ITEM *parent, KICAD_T idtype=PCB_TEXT_T)
Definition pcb_text.cpp:49
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
Definition pcb_text.cpp:628
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition pcb_text.cpp:250
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition pcb_text.cpp:428
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_text.cpp:692
int GetTextThickness() const override
Definition pcb_text.cpp:499
void SetTextAngle(const EDA_ANGLE &aAngle) override
Definition pcb_text.cpp:574
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition pcb_text.cpp:180
void SetLibTextPos(const VECTOR2I &aPos)
Definition pcb_text.cpp:544
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:275
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:305
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition property.h:397
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
Definition property.h:388
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
void AddShape(SHAPE *aShape)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
SEGMENT_ITERATOR IterateSegments(int aFirst, int aLast, bool aIterateHoles=false)
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
CONST_SEGMENT_ITERATOR CIterateSegments(int aFirst, int aLast, bool aIterateHoles=false) const
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
SEGMENT_ITERATOR_TEMPLATE< const SEG > CONST_SEGMENT_ITERATOR
const SEG & GetSeg() const
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void SetUserUnits(EDA_UNITS aUnits)
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition vector2d.h:559
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:406
@ FOR_GUI
Definition common.h:93
bool DimensionHasValueMode(const PCB_DIMENSION_BASE *aDimension)
True for dimension types with a measured value aligned orthogonal or radial offering the Driven Drivi...
bool DimensionCanDrive(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
True when Driving mode may be offered for aDimension needs both endpoints bound via DimensionEndpoint...
DIM_VALUE_MODE DimensionValueMode(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
The value mode aDimension is in, derived from state: a self driving length means Driving,...
PCB_CONSTRAINT * FindDimensionLengthConstraint(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
Self FIXED_LENGTH constraint whose members are exactly aDimension START and END or nullptr the drivin...
DIM_VALUE_MODE
Mode a value bearing dimension value is in Driven mirrors measured geometry Driving forces geometry t...
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:469
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:468
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:473
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:477
static constexpr EDA_ANGLE FULL_CIRCLE
Definition eda_angle.h:470
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:476
static constexpr EDA_ANGLE ANGLE_135
Definition eda_angle.h:475
#define PCB_EDIT_FRAME_NAME
EDA_UNITS
Definition eda_units.h:45
a few functions useful in geometry calculations.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ LAYER_CONSTRAINT_SHADOW
Shadow layer for items bound to a constraint.
Definition layer_ids.h:320
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Dwgs_User
Definition layer_ids.h:103
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:44
FLIP_DIRECTION
Definition mirror.h:26
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:27
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:28
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Return the string from aValue according to aUnits (inch, mm ...) for display.
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Convert aValue in internal units to the appropriate user units defined by aUnit.
KICOMMON_API wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
bool ShapeHitTest(const SHAPE_LINE_CHAIN &aHitter, const SHAPE &aHittee, bool aHitteeContained)
Perform a shape-to-shape hit test.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
#define _HKI(x)
Definition page_info.cpp:40
static const int INWARD_ARROW_LENGTH_TO_HEAD_RATIO
static const EDA_ANGLE s_arrowAngle(27.5, DEGREES_T)
static struct DIMENSION_DESC _DIMENSION_DESC
static OPT_VECTOR2I segPolyIntersection(const SHAPE_POLY_SET &aPoly, const SEG &aSeg, bool aStart=true)
Find the intersection between a given segment and polygon outline.
static OPT_VECTOR2I segCircleIntersection(CIRCLE &aCircle, SEG &aSeg, bool aStart=true)
static void CollectKnockedOutSegments(const SHAPE_POLY_SET &aPoly, const SEG &aSeg, std::vector< std::shared_ptr< SHAPE > > &aSegmentsAfterKnockout)
Knockout a polygon from a segment.
DIM_TEXT_POSITION
Where to place the text on a dimension.
@ OUTSIDE
Text appears outside the dimension line (default)
@ MANUAL
Text placement is manually set by the user.
@ INLINE
Text appears in line with the dimension line.
DIM_UNITS_FORMAT
How to display the units in a dimension's text.
DIM_UNITS_MODE
Used for storing the units selection in the file because EDA_UNITS alone doesn't cut it.
DIM_ARROW_DIRECTION
Used for dimension's arrow.
DIM_TEXT_BORDER
Frame to show around dimension text.
DIM_PRECISION
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define ENUM_TO_WXANY(type)
Definition property.h:918
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
VECTOR2I center
int radius
VECTOR2I end
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
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_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_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
constexpr int sign(T val)
Definition util.h:167
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)