KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_line.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <base_units.h>
26#include <bitmaps.h>
27#include <string_utils.h>
28#include <core/mirror.h>
29#include <sch_painter.h>
30#include <sch_plotter.h>
33#include <sch_line.h>
34#include <sch_edit_frame.h>
36#include <connection_graph.h>
39#include <trigo.h>
40#include <board_item.h>
41#include <api/api_enums.h>
42#include <api/api_utils.h>
43#include <api/schematic/schematic_types.pb.h>
44#include <properties/property.h>
45#include <origin_transforms.h>
46#include <math/util.h>
47
48
49SCH_LINE::SCH_LINE( const VECTOR2I& pos, int layer ) :
50 SCH_ITEM( nullptr, SCH_LINE_T )
51{
52 m_start = pos;
53 m_end = pos;
54 m_stroke.SetWidth( 0 );
55 m_stroke.SetLineStyle( LINE_STYLE::DEFAULT );
57
58 switch( layer )
59 {
60 default: m_layer = LAYER_NOTES; break;
61 case LAYER_WIRE: m_layer = LAYER_WIRE; break;
62 case LAYER_BUS: m_layer = LAYER_BUS; break;
63 }
64
65 if( layer == LAYER_NOTES )
67 else
69
70 if( layer == LAYER_WIRE )
72 else if( layer == LAYER_BUS )
74 else
76
79}
80
81
83 SCH_ITEM( aLine )
84{
85 m_start = aLine.m_start;
86 m_end = aLine.m_end;
87 m_stroke = aLine.m_stroke;
90
94
96
97 // Don't apply groups to cloned lines. We have too many areas where we clone them
98 // temporarily, then modify/split/join them in the line movement routines after the
99 // segments are committed. Rely on the commit framework to add the lines to the
100 // entered group as appropriate.
101 m_group = nullptr;
102}
103
104
105void SCH_LINE::Serialize( google::protobuf::Any &aContainer ) const
106{
107 kiapi::schematic::types::Line line;
108
109 line.mutable_id()->set_value( m_Uuid.AsStdString() );
110 kiapi::common::PackVector2( *line.mutable_start(), GetStartPoint() );
111 kiapi::common::PackVector2( *line.mutable_end(), GetEndPoint() );
112 line.set_layer(
114
115 aContainer.PackFrom( line );
116}
117
118
119bool SCH_LINE::Deserialize( const google::protobuf::Any &aContainer )
120{
121 kiapi::schematic::types::Line line;
122
123 if( !aContainer.UnpackTo( &line ) )
124 return false;
125
126 const_cast<KIID&>( m_Uuid ) = KIID( line.id().value() );
129 SCH_LAYER_ID layer =
131
132 switch( layer )
133 {
134 case LAYER_WIRE:
135 case LAYER_BUS:
136 case LAYER_NOTES:
137 SetLayer( layer );
138 break;
139
140 default:
141 break;
142 }
143
144 return true;
145}
146
147
149{
150 switch( GetLayer() )
151 {
152 case LAYER_WIRE: return _( "Wire" );
153 case LAYER_BUS: return _( "Bus" );
154 default: return _( "Graphic Line" );
155 }
156}
157
158
160{
161 return new SCH_LINE( *this );
162}
163
164
165void SCH_LINE::Move( const VECTOR2I& aOffset )
166{
167 m_start += aOffset;
168 m_end += aOffset;
169}
170
171
172void SCH_LINE::MoveStart( const VECTOR2I& aOffset )
173{
174 m_start += aOffset;
175}
176
177
178void SCH_LINE::MoveEnd( const VECTOR2I& aOffset )
179{
180 m_end += aOffset;
181}
182
183
184#if defined(DEBUG)
185
186void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
187{
188 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
189 << " layer=\"" << m_layer << '"'
190 << " startIsDangling=\"" << m_startIsDangling
191 << '"' << " endIsDangling=\""
192 << m_endIsDangling << '"' << ">"
193 << " <start" << m_start << "/>"
194 << " <end" << m_end << "/>" << "</"
195 << GetClass().Lower().mb_str() << ">\n";
196}
197
198#endif
199
200
209
210
211double SCH_LINE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
212{
213 if( aLayer == LAYER_OP_VOLTAGES )
214 {
215 if( m_start == m_end )
216 return LOD_HIDE;
217
218 const int height = std::abs( m_end.y - m_start.y );
219
220 // Operating points will be shown only if zoom is appropriate
221 if( height > 0 )
222 return lodScaleForThreshold( aView, height, schIUScale.mmToIU( 5 ) );
223
224 const int width = std::abs( m_end.x - m_start.x );
225 return lodScaleForThreshold( aView, width, schIUScale.mmToIU( 15 ) );
226 }
227
228 // Other layers are always drawn.
229 return LOD_SHOW;
230}
231
232
234{
235 int width = GetPenWidth() / 2;
236
237 int xmin = std::min( m_start.x, m_end.x ) - width;
238 int ymin = std::min( m_start.y, m_end.y ) - width;
239
240 int xmax = std::max( m_start.x, m_end.x ) + width + 1;
241 int ymax = std::max( m_start.y, m_end.y ) + width + 1;
242
243 BOX2I ret( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin, ymax - ymin ) );
244
245 return ret;
246}
247
248
250{
251 return m_start.Distance( m_end );
252}
253
254
255void SCH_LINE::SetLength( double aLength )
256{
257 if( aLength < 0.0 )
258 aLength = 0.0;
259
260 double currentLength = GetLength();
261 VECTOR2I start = GetStartPoint();
263
264 if( currentLength <= 0.0 )
265 {
266 end = start + KiROUND( aLength, 0.0 );
267 }
268 else
269 {
270 VECTOR2I delta = GetEndPoint() - start;
271 double scale = aLength / currentLength;
272
273 end = start + KiROUND( delta * scale );
274 }
275
276 SetEndPoint( end );
277}
278
279
280void SCH_LINE::SetLineColor( const COLOR4D& aColor )
281{
282 m_stroke.SetColor( aColor );
284}
285
286
287void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
288{
289 COLOR4D newColor(r, g, b, a);
290
291 if( newColor == COLOR4D::UNSPECIFIED )
292 {
293 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
294 }
295 else
296 {
297 // Eeschema does not allow alpha channel in colors
298 newColor.a = 1.0;
299 m_stroke.SetColor( newColor );
300 }
301}
302
303
315
316
318{
319 m_stroke.SetLineStyle( aStyle );
321}
322
323
325{
326 if( IsGraphicLine() && m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
327 return LINE_STYLE::SOLID;
328 else
329 return m_stroke.GetLineStyle();
330}
331
332
344
345
346void SCH_LINE::SetLineWidth( const int aSize )
347{
348 m_stroke.SetWidth( aSize );
350}
351
352
354{
355 SCHEMATIC* schematic = Schematic();
356
357 switch ( m_layer )
358 {
359 default:
360 if( m_stroke.GetWidth() > 0 )
361 return m_stroke.GetWidth();
362
363 if( schematic )
364 return schematic->Settings().m_DefaultLineWidth;
365
366 return schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
367
368 case LAYER_WIRE:
369 if( m_stroke.GetWidth() > 0 )
370 m_lastResolvedWidth = m_stroke.GetWidth();
371 else if( !IsConnectivityDirty() )
373
374 return m_lastResolvedWidth;
375
376 case LAYER_BUS:
377 if( m_stroke.GetWidth() > 0 )
378 m_lastResolvedWidth = m_stroke.GetWidth();
379 else if( !IsConnectivityDirty() )
381
382 return m_lastResolvedWidth;
383 }
384}
385
386
387void SCH_LINE::MirrorVertically( int aCenter )
388{
389 if( m_flags & STARTPOINT )
390 MIRROR( m_start.y, aCenter );
391
392 if( m_flags & ENDPOINT )
393 MIRROR( m_end.y, aCenter );
394}
395
396
398{
399 if( m_flags & STARTPOINT )
400 MIRROR( m_start.x, aCenter );
401
402 if( m_flags & ENDPOINT )
403 MIRROR( m_end.x, aCenter );
404}
405
406
407void SCH_LINE::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
408{
409 if( m_flags & STARTPOINT )
410 RotatePoint( m_start, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
411
412 if( m_flags & ENDPOINT )
413 RotatePoint( m_end, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
414}
415
416
417int SCH_LINE::GetAngleFrom( const VECTOR2I& aPoint ) const
418{
419 VECTOR2I vec;
420
421 if( aPoint == m_start )
422 vec = m_end - aPoint;
423 else
424 vec = m_start - aPoint;
425
426 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
427}
428
429
430int SCH_LINE::GetReverseAngleFrom( const VECTOR2I& aPoint ) const
431{
432 VECTOR2I vec;
433
434 if( aPoint == m_end )
435 vec = m_start - aPoint;
436 else
437 vec = m_end - aPoint;
438
439 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
440}
441
442
443bool SCH_LINE::IsParallel( const SCH_LINE* aLine ) const
444{
445 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, false,
446 wxT( "Cannot test line segment for overlap." ) );
447
448 VECTOR2I firstSeg = m_end - m_start;
449 VECTOR2I secondSeg = aLine->m_end - aLine->m_start;
450
451 // Use long long here to avoid overflow in calculations
452 return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
453}
454
455
456SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions )
457{
458 auto less =
459 []( const VECTOR2I& lhs, const VECTOR2I& rhs ) -> bool
460 {
461 if( lhs.x == rhs.x )
462 return lhs.y < rhs.y;
463
464 return lhs.x < rhs.x;
465 };
466
467 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, nullptr,
468 wxT( "Cannot test line segment for overlap." ) );
469
470 if( this == aLine || GetLayer() != aLine->GetLayer() )
471 return nullptr;
472
473 VECTOR2I leftmost_start = aLine->m_start;
474 VECTOR2I leftmost_end = aLine->m_end;
475
476 VECTOR2I rightmost_start = m_start;
477 VECTOR2I rightmost_end = m_end;
478
479 // We place the start to the left and below the end of both lines
480 if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
481 std::swap( leftmost_start, leftmost_end );
482 if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
483 std::swap( rightmost_start, rightmost_end );
484
485 // - leftmost is the line that starts farthest to the left
486 // - other is the line that is _not_ leftmost
487 // - rightmost is the line that ends farthest to the right. This may or may not be 'other'
488 // as the second line may be completely covered by the first.
489 if( less( rightmost_start, leftmost_start ) )
490 {
491 std::swap( leftmost_start, rightmost_start );
492 std::swap( leftmost_end, rightmost_end );
493 }
494
495 VECTOR2I other_start = rightmost_start;
496 VECTOR2I other_end = rightmost_end;
497
498 if( less( rightmost_end, leftmost_end ) )
499 {
500 rightmost_start = leftmost_start;
501 rightmost_end = leftmost_end;
502 }
503
504 // If we end one before the beginning of the other, no overlap is possible
505 if( less( leftmost_end, other_start ) )
506 {
507 return nullptr;
508 }
509
510 // Search for a common end:
511 if( ( leftmost_start == other_start ) && ( leftmost_end == other_end ) ) // Trivial case
512 {
513 SCH_LINE* ret = new SCH_LINE( *aLine );
514 ret->SetStartPoint( leftmost_start );
515 ret->SetEndPoint( leftmost_end );
516 ret->SetConnectivityDirty( true );
517
518 if( IsSelected() || aLine->IsSelected() )
519 ret->SetSelected();
520
521 return ret;
522 }
523
524 bool colinear = false;
525
526 /* Test alignment: */
527 if( ( leftmost_start.y == leftmost_end.y ) &&
528 ( other_start.y == other_end.y ) ) // Horizontal segment
529 {
530 colinear = ( leftmost_start.y == other_start.y );
531 }
532 else if( ( leftmost_start.x == leftmost_end.x ) &&
533 ( other_start.x == other_end.x ) ) // Vertical segment
534 {
535 colinear = ( leftmost_start.x == other_start.x );
536 }
537 else
538 {
539 // We use long long here to avoid overflow -- it enforces promotion
540 // The slope of the left-most line is dy/dx. Then we check that the slope from the
541 // left most start to the right most start is the same as well as the slope from the
542 // left most start to right most end.
543 long long dx = leftmost_end.x - leftmost_start.x;
544 long long dy = leftmost_end.y - leftmost_start.y;
545 colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
546 ( other_start.x - leftmost_start.x ) * dy ) &&
547 ( ( other_end.y - leftmost_start.y ) * dx ==
548 ( other_end.x - leftmost_start.x ) * dy ) );
549 }
550
551 if( !colinear )
552 return nullptr;
553
554 // We either have a true overlap or colinear touching segments. We always want to merge
555 // the former, but the later only get merged if there no junction at the touch point.
556
557 bool touching = leftmost_end == rightmost_start;
558
559 if( touching && aCheckJunctions && aScreen->IsJunction( leftmost_end ) )
560 return nullptr;
561
562 // Make a new segment that merges the 2 segments
563 leftmost_end = rightmost_end;
564
565 SCH_LINE* ret = new SCH_LINE( *aLine );
566 ret->SetStartPoint( leftmost_start );
567 ret->SetEndPoint( leftmost_end );
568 ret->SetConnectivityDirty( true );
569
570 if( IsSelected() || aLine->IsSelected() )
571 ret->SetSelected();
572
573 return ret;
574}
575
576
578{
579 SCH_LINE* newSegment = static_cast<SCH_LINE*>( Duplicate( true /* addToParentGroup */, aCommit ) );
580
581 newSegment->SetStartPoint( aPoint );
582 newSegment->SetConnectivityDirty( true );
583 SetEndPoint( aPoint );
584
585 return newSegment;
586}
587
588
590{
591 SCH_LINE* newSegment = static_cast<SCH_LINE*>( Duplicate( false /* addToParentGroup */, nullptr ) );
592
593 newSegment->SetStartPoint( aPoint );
594 newSegment->SetConnectivityDirty( true );
595 SetEndPoint( aPoint );
596
597 return newSegment;
598}
599
600
601void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
602{
603 if( IsConnectable() )
604 {
605 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_start );
606 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_end );
607 }
608}
609
610
611bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
612 std::vector<DANGLING_END_ITEM>& aItemListByPos,
613 const SCH_SHEET_PATH* aPath )
614{
615 if( !IsConnectable() )
616 return false;
617
618 bool previousStartState = m_startIsDangling;
619 bool previousEndState = m_endIsDangling;
620
622
623 for( auto it = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, m_start );
624 it < aItemListByPos.end() && it->GetPosition() == m_start; it++ )
625 {
626 DANGLING_END_ITEM& item = *it;
627
628 if( item.GetItem() == this )
629 continue;
630
631 if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
632 || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
633 {
634 m_startIsDangling = false;
635 break;
636 }
637 }
638
639 for( auto it = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, m_end );
640 it < aItemListByPos.end() && it->GetPosition() == m_end; it++ )
641 {
642 DANGLING_END_ITEM& item = *it;
643
644 if( item.GetItem() == this )
645 continue;
646
647 if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
648 || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
649 {
650 m_endIsDangling = false;
651 break;
652 }
653 }
654
655 // We only use the bus dangling state for automatic line starting, so we don't care if it
656 // has changed or not (and returning true will result in extra work)
657 if( IsBus() )
658 return false;
659
660 return previousStartState != m_startIsDangling || previousEndState != m_endIsDangling;
661}
662
663
665{
666 if( m_layer == LAYER_WIRE || m_layer == LAYER_BUS )
667 return true;
668
669 return false;
670}
671
672
673bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
674{
675 switch( aItem->Type() )
676 {
677 case SCH_NO_CONNECT_T:
678 case SCH_SYMBOL_T:
679 return IsWire();
680
681 case SCH_JUNCTION_T:
682 case SCH_LABEL_T:
684 case SCH_HIER_LABEL_T:
687 case SCH_SHEET_T:
688 case SCH_SHEET_PIN_T:
689 return IsWire() || IsBus();
690
691 default:
692 return m_layer == aItem->GetLayer();
693 }
694}
695
696
698 const SCH_SHEET_PATH* aInstance ) const
699{
700 // Do not compare to ourself.
701 if( aItem == this || !IsConnectable() )
702 return false;
703
704 const SCH_LINE* line = dynamic_cast<const SCH_LINE*>( aItem );
705
706 // Don't compare against a different SCH_ITEM.
707 wxCHECK( line, false );
708
709 if( GetStartPoint() != line->GetStartPoint() )
710 return true;
711
712 return GetEndPoint() != line->GetEndPoint();
713}
714
715
716std::vector<VECTOR2I> SCH_LINE::GetConnectionPoints() const
717{
718 return { m_start, m_end };
719}
720
721
723{
724 switch( aItem->Type() )
725 {
726 case SCH_LINE_T:
727 return IsBus() == static_cast<const SCH_LINE*>( aItem )->IsBus();
728
729 default:
730 return true;
731 }
732}
733
734
735void SCH_LINE::GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const
736{
737 if( m_flags & STARTPOINT )
738 aPoints.push_back( m_start );
739
740 if( m_flags & ENDPOINT )
741 aPoints.push_back( m_end );
742}
743
744
745wxString SCH_LINE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
746{
747 wxString txtfmt;
748
749 if( m_start.x == m_end.x )
750 {
751 switch( m_layer )
752 {
753 case LAYER_WIRE: txtfmt = _( "Vertical Wire, length %s" ); break;
754 case LAYER_BUS: txtfmt = _( "Vertical Bus, length %s" ); break;
755 default: txtfmt = _( "Vertical Graphic Line, length %s" ); break;
756 }
757 }
758 else if( m_start.y == m_end.y )
759 {
760 switch( m_layer )
761 {
762 case LAYER_WIRE: txtfmt = _( "Horizontal Wire, length %s" ); break;
763 case LAYER_BUS: txtfmt = _( "Horizontal Bus, length %s" ); break;
764 default: txtfmt = _( "Horizontal Graphic Line, length %s" ); break;
765 }
766 }
767 else
768 {
769 switch( m_layer )
770 {
771 case LAYER_WIRE: txtfmt = _( "Wire, length %s" ); break;
772 case LAYER_BUS: txtfmt = _( "Bus, length %s" ); break;
773 default: txtfmt = _( "Graphic Line, length %s" ); break;
774 }
775 }
776
777 return wxString::Format( txtfmt,
778 aUnitsProvider->MessageTextFromValue( m_start.Distance( m_end ) ) );
779}
780
781
783{
784 if( m_layer == LAYER_NOTES )
786 else if( m_layer == LAYER_WIRE )
787 return BITMAPS::add_line;
788
789 return BITMAPS::add_bus;
790}
791
792
793bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
794{
795 if( Type() != aItem.Type() )
796 return Type() < aItem.Type();
797
798 const SCH_LINE* line = static_cast<const SCH_LINE*>( &aItem );
799
800 if( GetLayer() != line->GetLayer() )
801 return GetLayer() < line->GetLayer();
802
803 if( GetStartPoint().x != line->GetStartPoint().x )
804 return GetStartPoint().x < line->GetStartPoint().x;
805
806 if( GetStartPoint().y != line->GetStartPoint().y )
807 return GetStartPoint().y < line->GetStartPoint().y;
808
809 if( GetEndPoint().x != line->GetEndPoint().x )
810 return GetEndPoint().x < line->GetEndPoint().x;
811
812 return GetEndPoint().y < line->GetEndPoint().y;
813}
814
815
816bool SCH_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
817{
818 // Performance enhancement for connection-building
819 if( aPosition == m_start || aPosition == m_end )
820 return true;
821
822 if( aAccuracy >= 0 )
823 aAccuracy += GetPenWidth() / 2;
824 else
825 aAccuracy = abs( aAccuracy );
826
827 return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
828}
829
830
831bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
832{
834 return false;
835
836 BOX2I rect = aRect;
837
838 if ( aAccuracy )
839 rect.Inflate( aAccuracy );
840
841 if( aContained )
842 return rect.Contains( m_start ) && rect.Contains( m_end );
843
844 return rect.Intersects( m_start, m_end );
845}
846
847
848bool SCH_LINE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
849{
851 return false;
852
854 return KIGEOM::ShapeHitTest( aPoly, line, aContained );
855}
856
857
859{
860 SCH_LINE* item = (SCH_LINE*) aItem;
861
862 std::swap( m_start, item->m_start );
863 std::swap( m_end, item->m_end );
864 std::swap( m_startIsDangling, item->m_startIsDangling );
865 std::swap( m_endIsDangling, item->m_endIsDangling );
866 std::swap( m_stroke, item->m_stroke );
867}
868
869
870bool SCH_LINE::doIsConnected( const VECTOR2I& aPosition ) const
871{
872 if( m_layer != LAYER_WIRE && m_layer != LAYER_BUS )
873 return false;
874
875 return IsEndPoint( aPosition );
876}
877
878
879void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
880 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
881{
882 if( aBackground )
883 return;
884
885 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
886 int penWidth = GetEffectivePenWidth( renderSettings );
887 COLOR4D color = GetLineColor();
888
889 if( color == COLOR4D::UNSPECIFIED )
890 color = renderSettings->GetLayerColor( GetLayer() );
891
892 aPlotter->SetColor( color );
893
894 aPlotter->SetCurrentLineWidth( penWidth );
895 aPlotter->SetDash( penWidth, GetEffectiveLineStyle() );
896
897 aPlotter->MoveTo( m_start );
898 aPlotter->FinishTo( m_end );
899
900 aPlotter->SetDash( penWidth, LINE_STYLE::SOLID );
901
902 // Plot attributes to a hypertext menu
903 std::vector<wxString> properties;
904 BOX2I bbox = GetBoundingBox();
905 bbox.Inflate( penWidth * 3 );
906
907 if( aPlotOpts.m_PDFPropertyPopups )
908 {
909 if( GetLayer() == LAYER_WIRE )
910 {
911 if( SCH_CONNECTION* connection = Connection() )
912 {
913 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
914 _( "Net" ),
915 connection->Name() ) );
916
917 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
918 _( "Resolved netclass" ),
919 GetEffectiveNetClass()->GetHumanReadableName() ) );
920 }
921 }
922 else if( GetLayer() == LAYER_BUS )
923 {
924 if( SCH_CONNECTION* connection = Connection() )
925 {
926 for( const std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
927 properties.emplace_back( wxT( "!" ) + member->Name() );
928 }
929 }
930
931 if( !properties.empty() )
932 aPlotter->HyperlinkMenu( bbox, properties );
933 }
934}
935
936
937void SCH_LINE::SetPosition( const VECTOR2I& aPosition )
938{
939 m_end = m_end - ( m_start - aPosition );
940 m_start = aPosition;
941}
942
943
944void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
945{
946 wxString msg;
947
948 switch( GetLayer() )
949 {
950 case LAYER_WIRE: msg = _( "Wire" ); break;
951 case LAYER_BUS: msg = _( "Bus" ); break;
952 default: msg = _( "Graphical" ); break;
953 }
954
955 aList.emplace_back( _( "Line Type" ), msg );
956
957 LINE_STYLE lineStyle = GetStroke().GetLineStyle();
958
959 if( GetEffectiveLineStyle() != lineStyle )
960 aList.emplace_back( _( "Line Style" ), _( "from netclass" ) );
961 else
962 m_stroke.GetMsgPanelInfo( aFrame, aList, true, false );
963
964 SCH_CONNECTION* conn = nullptr;
965
966 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
967 conn = Connection();
968
969 if( conn )
970 {
971 conn->AppendInfoToMsgPanel( aList );
972
973 if( !conn->IsBus() )
974 {
975 aList.emplace_back( _( "Resolved Netclass" ),
976 UnescapeString( GetEffectiveNetClass()->GetHumanReadableName() ) );
977 }
978 }
979}
980
981
983{
984 return ( GetLayer() == LAYER_NOTES );
985}
986
987
989{
990 return ( GetLayer() == LAYER_WIRE );
991}
992
993
994bool SCH_LINE::IsBus() const
995{
996 return ( GetLayer() == LAYER_BUS );
997}
998
999
1000bool SCH_LINE::operator==( const SCH_ITEM& aOther ) const
1001{
1002 if( Type() != aOther.Type() )
1003 return false;
1004
1005 const SCH_LINE& other = static_cast<const SCH_LINE&>( aOther );
1006
1007 if( GetLayer() != other.GetLayer() )
1008 return false;
1009
1010 if( m_start != other.m_start )
1011 return false;
1012
1013 if( m_end != other.m_end )
1014 return false;
1015
1016 if( m_stroke.GetWidth() != other.m_stroke.GetWidth() )
1017 return false;
1018
1019 if( m_stroke.GetColor() != other.m_stroke.GetColor() )
1020 return false;
1021
1022 if( m_stroke.GetLineStyle() != other.m_stroke.GetLineStyle() )
1023 return false;
1024
1025 return true;
1026}
1027
1028
1029double SCH_LINE::Similarity( const SCH_ITEM& aOther ) const
1030{
1031 if( m_Uuid == aOther.m_Uuid )
1032 return 1.0;
1033
1034 if( Type() != aOther.Type() )
1035 return 0.0;
1036
1037 const SCH_LINE& other = static_cast<const SCH_LINE&>( aOther );
1038
1039 if( GetLayer() != other.GetLayer() )
1040 return 0.0;
1041
1042 double similarity = 1.0;
1043
1044 if( m_start != other.m_start )
1045 similarity *= 0.9;
1046
1047 if( m_end != other.m_end )
1048 similarity *= 0.9;
1049
1050 if( m_stroke.GetWidth() != other.m_stroke.GetWidth() )
1051 similarity *= 0.9;
1052
1053 if( m_stroke.GetColor() != other.m_stroke.GetColor() )
1054 similarity *= 0.9;
1055
1056 if( m_stroke.GetLineStyle() != other.m_stroke.GetLineStyle() )
1057 similarity *= 0.9;
1058
1059 return similarity;
1060}
1061
1062
1063bool SCH_LINE::ShouldHopOver( const SCH_LINE* aLine ) const
1064{
1065 // try to find if this should hop over aLine. Horizontal wires have preference for hop.
1066 bool isMeVertical = ( m_end.x == m_start.x );
1067 bool isCandidateVertical = ( aLine->GetEndPoint().x == aLine->GetStartPoint().x );
1068
1069 // Vertical vs. Horizontal: Horizontal should hop
1070 if( isMeVertical && !isCandidateVertical )
1071 return false;
1072
1073 if( isCandidateVertical && !isMeVertical )
1074 return true;
1075
1076 // Both this and aLine have a slope. Try to find the best candidate
1077 double slopeMe = ( m_end.y - m_start.y ) / (double) ( m_end.x - m_start.x );
1078 double slopeCandidate = ( aLine->GetEndPoint().y - aLine->GetStartPoint().y )
1079 / (double) ( aLine->GetEndPoint().x - aLine->GetStartPoint().x );
1080
1081 if( fabs( slopeMe ) == fabs( slopeCandidate ) ) // Can easily happen with 45 deg wires
1082 return slopeMe < slopeCandidate; // signs are certainly different
1083
1084 return fabs( slopeMe ) < fabs( slopeCandidate ); // The shallower line should hop
1085}
1086
1087
1088std::vector<VECTOR3I> SCH_LINE::BuildWireWithHopShape( const SCH_SCREEN* aScreen,
1089 double aArcRadius ) const
1090{
1091 // Note: Points are VECTOR3D, with Z coord used as flag
1092 // for segments: start point and end point have the Z coord = 0
1093 // for arcs: start point middle point and end point have the Z coord = 1
1094
1095 std::vector<VECTOR3I> wire_shape; // List of coordinates:
1096 // 2 points for a segment, 3 points for an arc
1097
1098 if( !IsWire() )
1099 {
1100 wire_shape.emplace_back( GetStartPoint().x,GetStartPoint().y, 0 );
1101 wire_shape.emplace_back( GetEndPoint().x, GetEndPoint().y, 0 );
1102 return wire_shape;
1103 }
1104
1105 std::vector<SCH_LINE*> existingWires; // wires to test (candidates)
1106 std::vector<VECTOR2I> intersections;
1107
1108 for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, GetBoundingBox() ) )
1109 {
1110 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1111
1112 if( line->IsWire() )
1113 existingWires.push_back( line );
1114 }
1115
1116 VECTOR2I currentLineStartPoint = GetStartPoint();
1117 VECTOR2I currentLineEndPoint = GetEndPoint();
1118
1119 for( SCH_LINE* existingLine : existingWires )
1120 {
1121 VECTOR2I extLineStartPoint = existingLine->GetStartPoint();
1122 VECTOR2I extLineEndPoint = existingLine->GetEndPoint();
1123
1124 if( extLineStartPoint == currentLineStartPoint && extLineEndPoint == currentLineEndPoint )
1125 continue;
1126
1127 if( !ShouldHopOver( existingLine ) )
1128 continue;
1129
1130 SEG currentSegment = SEG( currentLineStartPoint, currentLineEndPoint );
1131 SEG existingSegment = SEG( extLineStartPoint, extLineEndPoint );
1132
1133 if( OPT_VECTOR2I intersect = currentSegment.Intersect( existingSegment, true, false ) )
1134 {
1135 if( IsEndPoint( *intersect ) || existingLine->IsEndPoint( *intersect ) )
1136 continue;
1137
1138 // Ensure intersecting point is not yet entered. it can be already just entered
1139 // if more than two wires are intersecting at the same point,
1140 // creating bad hop over shapes for the current wire
1141 if( intersections.size() == 0 || intersections.back() != *intersect )
1142 intersections.push_back( *intersect );
1143 }
1144 }
1145
1146 if( intersections.empty() )
1147 {
1148 wire_shape.emplace_back( currentLineStartPoint.x, currentLineStartPoint.y, 0 );
1149 wire_shape.emplace_back( currentLineEndPoint.x, currentLineEndPoint.y, 0 );
1150 }
1151 else
1152 {
1153 auto getDistance =
1154 []( const VECTOR2I& a, const VECTOR2I& b ) -> double
1155 {
1156 return std::sqrt( std::pow( a.x - b.x, 2 ) + std::pow( a.y - b.y, 2 ) );
1157 };
1158
1159 std::sort( intersections.begin(), intersections.end(),
1160 [&]( const VECTOR2I& a, const VECTOR2I& b )
1161 {
1162 return getDistance( GetStartPoint(), a ) < getDistance( GetStartPoint(), b );
1163 } );
1164
1165 VECTOR2I currentStart = GetStartPoint();
1166 double R = aArcRadius;
1167
1168 for( const VECTOR2I& hopMid : intersections )
1169 {
1170 // Calculate the angle of the line from start point to end point in radians
1171 double lineAngle = std::atan2( GetEndPoint().y - GetStartPoint().y,
1172 GetEndPoint().x - GetStartPoint().x );
1173
1174 // Convert the angle from radians to degrees
1175 double lineAngleDeg = lineAngle * ( 180.0f / M_PI );
1176
1177 // Normalize the angle to be between 0 and 360 degrees
1178 if( lineAngleDeg < 0 )
1179 lineAngleDeg += 360;
1180
1181 double startAngle = lineAngleDeg;
1182 double endAngle = startAngle + 180.0f;
1183
1184 // Adjust the end angle if it exceeds 360 degrees
1185 if( endAngle >= 360.0 )
1186 endAngle -= 360.0;
1187
1188 // Convert start and end angles from degrees to radians
1189 double startAngleRad = startAngle * ( M_PI / 180.0f );
1190 double endAngleRad = endAngle * ( M_PI / 180.0f );
1191
1192 VECTOR2I arcMidPoint = {
1193 hopMid.x + static_cast<int>( R * cos( ( startAngleRad + endAngleRad ) / 2.0f ) ),
1194 hopMid.y - static_cast<int>( R * sin( ( startAngleRad + endAngleRad ) / 2.0f ) )
1195 };
1196
1197 VECTOR2I beforeHop = hopMid - KiROUND( R * std::cos( lineAngle ), R * std::sin( lineAngle ) );
1198 VECTOR2I afterHop = hopMid + KiROUND( R * std::cos( lineAngle ), R * std::sin( lineAngle ) );
1199
1200 // Draw the line from the current start point to the before-hop point
1201 wire_shape.emplace_back( currentStart.x, currentStart.y, 0 );
1202 wire_shape.emplace_back( beforeHop.x, beforeHop.y, 0 );
1203
1204 // Create an arc object
1205 SHAPE_ARC arc( beforeHop, arcMidPoint, afterHop, 0 );
1206 wire_shape.emplace_back( beforeHop.x, beforeHop.y, 1 );
1207 wire_shape.emplace_back( arcMidPoint.x, arcMidPoint.y, 1 );
1208 wire_shape.emplace_back( afterHop.x, afterHop.y, 1 );
1209
1210 currentStart = afterHop;
1211 }
1212
1213 // Draw the final line from the current start point to the end point of the original line
1214 wire_shape.emplace_back( currentStart. x,currentStart.y, 0 );
1215 wire_shape.emplace_back( GetEndPoint().x, GetEndPoint().y, 0 );
1216 }
1217
1218 return wire_shape;
1219}
1220
1221
1222static struct SCH_LINE_DESC
1223{
1225 {
1227
1228 if( lineStyleEnum.Choices().GetCount() == 0 )
1229 {
1230 lineStyleEnum.Map( LINE_STYLE::SOLID, _HKI( "Solid" ) )
1231 .Map( LINE_STYLE::DASH, _HKI( "Dashed" ) )
1232 .Map( LINE_STYLE::DOT, _HKI( "Dotted" ) )
1233 .Map( LINE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
1234 .Map( LINE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
1235 }
1236
1238
1239 if( wireLineStyleEnum.Choices().GetCount() == 0 )
1240 {
1241 wireLineStyleEnum.Map( WIRE_STYLE::DEFAULT, _HKI( "Default" ) )
1242 .Map( WIRE_STYLE::SOLID, _HKI( "Solid" ) )
1243 .Map( WIRE_STYLE::DASH, _HKI( "Dashed" ) )
1244 .Map( WIRE_STYLE::DOT, _HKI( "Dotted" ) )
1245 .Map( WIRE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
1246 .Map( WIRE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
1247 }
1248
1252
1253 auto isGraphicLine =
1254 []( INSPECTABLE* aItem ) -> bool
1255 {
1256 if( SCH_LINE* line = dynamic_cast<SCH_LINE*>( aItem ) )
1257 return line->IsGraphicLine();
1258
1259 return false;
1260 };
1261
1262 auto isWireOrBus =
1263 []( INSPECTABLE* aItem ) -> bool
1264 {
1265 if( SCH_LINE* line = dynamic_cast<SCH_LINE*>( aItem ) )
1266 return line->IsWire() || line->IsBus();
1267
1268 return false;
1269 };
1270
1271 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Start X" ),
1274
1275 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Start Y" ),
1278
1279 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "End X" ),
1282
1283 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "End Y" ),
1286
1287 propMgr.AddProperty( new PROPERTY<SCH_LINE, double>( _HKI( "Length" ),
1289
1290 propMgr.AddProperty( new PROPERTY_ENUM<SCH_LINE, LINE_STYLE>( _HKI( "Line Style" ),
1292 .SetAvailableFunc( isGraphicLine );
1293
1294 propMgr.AddProperty( new PROPERTY_ENUM<SCH_LINE, WIRE_STYLE>( _HKI( "Line Style" ),
1296 .SetAvailableFunc( isWireOrBus );
1297
1298 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Line Width" ),
1300
1301 propMgr.AddProperty( new PROPERTY<SCH_LINE, COLOR4D>( _HKI( "Color" ),
1303 }
1305
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
Definition api_enums.cpp:97
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:36
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BITMAPS
A list of all bitmap identifiers.
@ add_dashed_line
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:399
static std::vector< DANGLING_END_ITEM >::iterator get_lower_pos(std::vector< DANGLING_END_ITEM > &aItemListByPos, const VECTOR2I &aPos)
Definition sch_item.cpp:820
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:96
DANGLING_END_T GetType() const
Definition sch_item.h:132
EDA_ITEM * GetItem() const
Definition sch_item.h:130
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:527
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition eda_item.h:529
bool IsSelected() const
Definition eda_item.h:127
void SetSelected()
Definition eda_item.h:134
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:246
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:727
static ENUM_MAP< T > & Instance()
Definition property.h:721
wxPGChoices & Choices()
Definition property.h:770
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:37
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
double a
Alpha component.
Definition color4d.h:396
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
static double lodScaleForThreshold(const KIGFX::VIEW *aView, int aWhatIu, int aThresholdIu)
Get the scale at which aWhatIu would be drawn at the same size as aThresholdIu on screen.
Definition view_item.cpp:39
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:180
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:185
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:66
Definition kiid.h:49
int GetLineStyle() const
Definition netclass.h:234
int GetWireWidth() const
Definition netclass.h:204
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:219
int GetBusWidth() const
Definition netclass.h:212
Base plotter engine class.
Definition plotter.h:136
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:308
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle)=0
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:318
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition plotter.h:517
virtual void SetColor(const COLOR4D &color)=0
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:262
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Holds all the data relating to one schematic.
Definition schematic.h:88
SCHEMATIC_SETTINGS & Settings() const
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition sch_item.cpp:137
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:702
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:244
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:388
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:322
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:321
void SetConnectivityDirty(bool aDirty=true)
Definition sch_item.h:570
bool IsConnectivityDirty() const
Definition sch_item.h:568
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:51
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:352
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:647
SCH_LAYER_ID m_layer
Definition sch_item.h:753
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
int GetPenWidth() const override
Definition sch_line.cpp:353
void SetStartY(int aY)
Definition sch_line.h:144
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition sch_line.cpp:870
int GetEndY() const
Definition sch_line.h:152
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Definition sch_line.cpp:601
void SetStartPoint(const VECTOR2I &aPosition)
Definition sch_line.h:140
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_line.cpp:159
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_line.cpp:782
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition sch_line.cpp:611
bool m_startIsDangling
True if start point is not connected.
Definition sch_line.h:386
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition sch_line.cpp:816
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_line.cpp:937
std::vector< VECTOR3I > BuildWireWithHopShape(const SCH_SCREEN *aScreen, double aArcRadius) const
For wires only: build the list of points to draw the shape using segments and 180 deg arcs Points are...
int GetStartX() const
Definition sch_line.h:141
SCH_LINE * NonGroupAware_BreakAt(const VECTOR2I &aPoint)
This version should only be used when importing files.
Definition sch_line.cpp:589
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition sch_line.cpp:716
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition sch_line.cpp:430
SCH_LINE(const VECTOR2I &pos=VECTOR2I(0, 0), int layer=LAYER_NOTES)
Definition sch_line.cpp:49
bool IsWire() const
Return true if the line is a wire.
Definition sch_line.cpp:988
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_line.cpp:233
void SetWireStyle(const WIRE_STYLE aStyle)
Definition sch_line.h:186
void SetLineColor(const COLOR4D &aColor)
Definition sch_line.cpp:280
bool CanConnect(const SCH_ITEM *aItem) const override
Definition sch_line.cpp:673
bool IsParallel(const SCH_LINE *aLine) const
Definition sch_line.cpp:443
int GetStartY() const
Definition sch_line.h:143
void SetLineWidth(const int aSize)
Definition sch_line.cpp:346
bool ShouldHopOver(const SCH_LINE *aLine) const
For wires only:
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition sch_line.cpp:397
virtual STROKE_PARAMS GetStroke() const override
Definition sch_line.h:201
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition sch_line.cpp:417
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition sch_line.cpp:735
COLOR4D m_lastResolvedColor
Definition sch_line.h:398
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_line.cpp:333
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.
Definition sch_line.cpp:944
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition sch_line.cpp:879
wxString m_operatingPoint
Definition sch_line.h:400
void SetLength(double aLength)
Definition sch_line.cpp:255
wxString GetClass() const override
Return the class name.
Definition sch_line.h:64
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_line.cpp:407
VECTOR2I GetEndPoint() const
Definition sch_line.h:148
VECTOR2I GetStartPoint() const
Definition sch_line.h:139
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition sch_line.cpp:722
LINE_STYLE m_lastResolvedLineStyle
Definition sch_line.h:396
SCH_LINE * MergeOverlap(SCH_SCREEN *aScreen, SCH_LINE *aLine, bool aCheckJunctions)
Check line against aLine to see if it overlaps and merge if it does.
Definition sch_line.cpp:456
void SetEndY(int aY)
Definition sch_line.h:153
VECTOR2I m_start
Line start point.
Definition sch_line.h:388
bool IsBus() const
Return true if the line is a bus.
Definition sch_line.cpp:994
int m_lastResolvedWidth
Definition sch_line.h:397
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition sch_line.cpp:697
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_line.cpp:105
void SetLineStyle(const LINE_STYLE aStyle)
Definition sch_line.cpp:317
VECTOR2I m_end
Line end point.
Definition sch_line.h:389
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition sch_line.cpp:165
int GetEndX() const
Definition sch_line.h:150
LINE_STYLE GetLineStyle() const
Definition sch_line.cpp:324
void MoveEnd(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:178
STROKE_PARAMS m_stroke
Line stroke properties.
Definition sch_line.h:391
SCH_LINE * BreakAt(SCH_COMMIT *aCommit, const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition sch_line.cpp:577
bool m_endIsDangling
True if end point is not connected.
Definition sch_line.h:387
bool IsConnectable() const override
Definition sch_line.cpp:664
wxString GetFriendlyName() const override
Definition sch_line.cpp:148
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition sch_line.cpp:211
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_line.cpp:387
bool operator==(const SCH_ITEM &aOther) const override
bool operator<(const SCH_ITEM &aItem) const override
Definition sch_line.cpp:793
WIRE_STYLE GetWireStyle() const
Definition sch_line.h:187
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition sch_line.cpp:745
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
Definition sch_line.h:91
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition sch_line.cpp:982
int GetLineWidth() const
Definition sch_line.h:198
COLOR4D GetLineColor() const
Return COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition sch_line.cpp:304
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_line.cpp:201
void MoveStart(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:172
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_line.cpp:119
double GetLength() const
Definition sch_line.cpp:249
void SetEndX(int aX)
Definition sch_line.h:151
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:149
void SetStartX(int aX)
Definition sch_line.h:142
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_line.cpp:858
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:117
bool IsJunction(const VECTOR2I &aPosition) const
Test if a junction is required for the items at aPosition on the screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Definition seg.h:42
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition seg.cpp:437
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
#define DEFAULT_BUS_WIDTH_MILS
The default noconnect size in mils.
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
#define STRUCT_DELETED
flag indication structures to be erased
#define ENDPOINT
ends. (Used to support dragging.)
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define STARTPOINT
When a line is selected, these flags indicate which.
a few functions useful in geometry calculations.
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ LAYER_DANGLING
Definition layer_ids.h:477
@ LAYER_WIRE
Definition layer_ids.h:452
@ LAYER_NOTES
Definition layer_ids.h:467
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:493
@ LAYER_BUS
Definition layer_ids.h:453
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:495
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:501
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:45
bool ShapeHitTest(const SHAPE_LINE_CHAIN &aHitter, const SHAPE &aHittee, bool aHitteeContained)
Perform a shape-to-shape hit test.
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
Definition api_utils.cpp:86
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
Definition api_utils.cpp:79
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
#define _HKI(x)
Definition page_info.cpp:44
static bool intersect(const SEGMENT_WITH_NORMALS &aSeg, const SFVEC2F &aStart, const SFVEC2F &aEnd)
#define TYPE_HASH(x)
Definition property.h:74
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:821
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
@ BUS_END
Definition sch_item.h:80
@ PIN_END
Definition sch_item.h:82
@ BUS_ENTRY_END
Definition sch_item.h:84
@ WIRE_END
Definition sch_item.h:79
static struct SCH_LINE_DESC _SCH_LINE_DESC
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39
const int scale
wxString UnescapeString(const wxString &aSource)
LINE_STYLE
Dashed line types.
WIRE_STYLE
bool m_PDFPropertyPopups
Definition sch_plotter.h:64
VECTOR2I end
int delta
#define M_PI
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition trigo.cpp:175
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:229
@ SCH_LINE_T
Definition typeinfo.h:167
@ SCH_NO_CONNECT_T
Definition typeinfo.h:164
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:175
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_SHEET_PIN_T
Definition typeinfo.h:178
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:165
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
@ SCH_JUNCTION_T
Definition typeinfo.h:163
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695