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>
37#include <sch_netchain.h>
38#include <schematic.h>
41#include <trigo.h>
42#include <board_item.h>
43#include <api/api_enums.h>
44#include <api/api_utils.h>
45#include <api/schematic/schematic_types.pb.h>
46#include <properties/property.h>
48#include <origin_transforms.h>
49#include <math/util.h>
50
51
52SCH_LINE::SCH_LINE( const VECTOR2I& pos, int layer ) :
53 SCH_ITEM( nullptr, SCH_LINE_T )
54{
55 m_start = pos;
56 m_end = pos;
57 m_stroke.SetWidth( 0 );
58 m_stroke.SetLineStyle( LINE_STYLE::DEFAULT );
60
61 switch( layer )
62 {
63 default: m_layer = LAYER_NOTES; break;
64 case LAYER_WIRE: m_layer = LAYER_WIRE; break;
65 case LAYER_BUS: m_layer = LAYER_BUS; break;
66 }
67
68 if( layer == LAYER_NOTES )
70 else
72
73 if( layer == LAYER_WIRE )
75 else if( layer == LAYER_BUS )
77 else
79
82}
83
84
86 SCH_ITEM( aLine )
87{
88 m_start = aLine.m_start;
89 m_end = aLine.m_end;
90 m_stroke = aLine.m_stroke;
93
97
99
100 // Don't apply groups to cloned lines. We have too many areas where we clone them
101 // temporarily, then modify/split/join them in the line movement routines after the
102 // segments are committed. Rely on the commit framework to add the lines to the
103 // entered group as appropriate.
104 m_group = nullptr;
105}
106
107
108void SCH_LINE::Serialize( google::protobuf::Any &aContainer ) const
109{
110 using namespace kiapi::common;
111
112 kiapi::schematic::types::SchematicLine line;
113 types::StrokeAttributes* stroke = line.mutable_stroke();
114
115 line.mutable_id()->set_value( m_Uuid.AsStdString() );
116 PackVector2( *line.mutable_start(), GetStartPoint(), schIUScale );
117 PackVector2( *line.mutable_end(), GetEndPoint(), schIUScale );
118 line.set_locked( IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
119
120 PackDistance( *stroke->mutable_width(), m_stroke.GetWidth(), schIUScale );
121 stroke->set_style( ToProtoEnum<LINE_STYLE, types::StrokeLineStyle>( m_stroke.GetLineStyle() ) );
122
123 if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED )
124 PackColor( *stroke->mutable_color(), m_stroke.GetColor() );
125
126 switch( GetLayer() )
127 {
128 case LAYER_WIRE:
129 line.set_type( kiapi::schematic::types::SLT_WIRE );
130 break;
131
132 case LAYER_BUS:
133 line.set_type( kiapi::schematic::types::SLT_BUS );
134 break;
135
136 case LAYER_NOTES:
137 line.set_type( kiapi::schematic::types::SLT_GRAPHIC );
138 break;
139
140 default:
141 line.set_type( kiapi::schematic::types::SLT_UNKNOWN );
142 break;
143 }
144
145 aContainer.PackFrom( line );
146}
147
148
149bool SCH_LINE::Deserialize( const google::protobuf::Any &aContainer )
150{
151 using namespace kiapi::common;
152
153 kiapi::schematic::types::SchematicLine line;
154
155 if( !aContainer.UnpackTo( &line ) )
156 return false;
157
158 const_cast<KIID&>( m_Uuid ) = KIID( line.id().value() );
159 SetStartPoint( UnpackVector2( line.start(), schIUScale ) );
160 SetEndPoint( UnpackVector2( line.end(), schIUScale ) );
161 SetLocked( line.locked() == types::LockedState::LS_LOCKED );
162
163 m_stroke.SetWidth( UnpackDistance( line.stroke().width(), schIUScale ) );
164 m_stroke.SetLineStyle( FromProtoEnum<LINE_STYLE, types::StrokeLineStyle>( line.stroke().style() ) );
165
166 if( line.stroke().has_color() )
167 m_stroke.SetColor( UnpackColor( line.stroke().color() ) );
168 else
169 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
170
171 switch( line.type() )
172 {
173 case kiapi::schematic::types::SLT_WIRE:
175 break;
176
177 case kiapi::schematic::types::SLT_BUS:
179 break;
180
181 default:
182 case kiapi::schematic::types::SLT_GRAPHIC:
184 break;
185 }
186
187 return true;
188}
189
190
192{
193 switch( GetLayer() )
194 {
195 case LAYER_WIRE: return _( "Wire" );
196 case LAYER_BUS: return _( "Bus" );
197 default: return _( "Graphic Line" );
198 }
199}
200
201
203{
204 return new SCH_LINE( *this );
205}
206
207
208void SCH_LINE::Move( const VECTOR2I& aOffset )
209{
210 m_start += aOffset;
211 m_end += aOffset;
212}
213
214
215void SCH_LINE::MoveStart( const VECTOR2I& aOffset )
216{
217 m_start += aOffset;
218}
219
220
221void SCH_LINE::MoveEnd( const VECTOR2I& aOffset )
222{
223 m_end += aOffset;
224}
225
226
227#if defined(DEBUG)
228
229void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
230{
231 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
232 << " layer=\"" << m_layer << '"'
233 << " startIsDangling=\"" << m_startIsDangling
234 << '"' << " endIsDangling=\""
235 << m_endIsDangling << '"' << ">"
236 << " <start" << m_start << "/>"
237 << " <end" << m_end << "/>" << "</"
238 << GetClass().Lower().mb_str() << ">\n";
239}
240
241#endif
242
243
252
253
254double SCH_LINE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
255{
256 if( aLayer == LAYER_OP_VOLTAGES )
257 {
258 if( m_start == m_end )
259 return LOD_HIDE;
260
261 const int height = std::abs( m_end.y - m_start.y );
262
263 // Operating points will be shown only if zoom is appropriate
264 if( height > 0 )
265 return lodScaleForThreshold( aView, height, schIUScale.mmToIU( 5 ) );
266
267 const int width = std::abs( m_end.x - m_start.x );
268 return lodScaleForThreshold( aView, width, schIUScale.mmToIU( 15 ) );
269 }
270
271 // Other layers are always drawn.
272 return LOD_SHOW;
273}
274
275
277{
278 int width = GetPenWidth() / 2;
279
280 int xmin = std::min( m_start.x, m_end.x ) - width;
281 int ymin = std::min( m_start.y, m_end.y ) - width;
282
283 int xmax = std::max( m_start.x, m_end.x ) + width + 1;
284 int ymax = std::max( m_start.y, m_end.y ) + width + 1;
285
286 BOX2I ret( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin, ymax - ymin ) );
287
288 return ret;
289}
290
291
293{
294 return m_start.Distance( m_end );
295}
296
297
298void SCH_LINE::SetLength( double aLength )
299{
300 if( aLength < 0.0 )
301 aLength = 0.0;
302
303 double currentLength = GetLength();
304 VECTOR2I start = GetStartPoint();
306
307 if( currentLength <= 0.0 )
308 {
309 end = start + KiROUND( aLength, 0.0 );
310 }
311 else
312 {
313 VECTOR2I delta = GetEndPoint() - start;
314 double scale = aLength / currentLength;
315
316 end = start + KiROUND( delta * scale );
317 }
318
319 SetEndPoint( end );
320}
321
322
323void SCH_LINE::SetLineColor( const COLOR4D& aColor )
324{
325 m_stroke.SetColor( aColor );
327}
328
329
330void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
331{
332 COLOR4D newColor(r, g, b, a);
333
334 if( newColor == COLOR4D::UNSPECIFIED )
335 {
336 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
337 }
338 else
339 {
340 // Eeschema does not allow alpha channel in colors
341 newColor.a = 1.0;
342 m_stroke.SetColor( newColor );
343 }
344}
345
346
358
359
361{
362 m_stroke.SetLineStyle( aStyle );
364}
365
366
368{
369 if( IsGraphicLine() && m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
370 return LINE_STYLE::SOLID;
371 else
372 return m_stroke.GetLineStyle();
373}
374
375
387
388
389void SCH_LINE::SetLineWidth( const int aSize )
390{
391 m_stroke.SetWidth( aSize );
393}
394
395
397{
398 SCHEMATIC* schematic = Schematic();
399
400 switch ( m_layer )
401 {
402 default:
403 if( m_stroke.GetWidth() > 0 )
404 return m_stroke.GetWidth();
405
406 if( schematic )
407 return schematic->Settings().m_DefaultLineWidth;
408
409 return schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
410
411 case LAYER_WIRE:
412 if( m_stroke.GetWidth() > 0 )
413 m_lastResolvedWidth = m_stroke.GetWidth();
414 else if( !IsConnectivityDirty() )
416
417 return m_lastResolvedWidth;
418
419 case LAYER_BUS:
420 if( m_stroke.GetWidth() > 0 )
421 m_lastResolvedWidth = m_stroke.GetWidth();
422 else if( !IsConnectivityDirty() )
424
425 return m_lastResolvedWidth;
426 }
427}
428
429
430void SCH_LINE::MirrorVertically( int aCenter )
431{
432 if( m_flags & STARTPOINT )
433 MIRROR( m_start.y, aCenter );
434
435 if( m_flags & ENDPOINT )
436 MIRROR( m_end.y, aCenter );
437}
438
439
441{
442 if( m_flags & STARTPOINT )
443 MIRROR( m_start.x, aCenter );
444
445 if( m_flags & ENDPOINT )
446 MIRROR( m_end.x, aCenter );
447}
448
449
450void SCH_LINE::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
451{
452 if( m_flags & STARTPOINT )
453 RotatePoint( m_start, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
454
455 if( m_flags & ENDPOINT )
456 RotatePoint( m_end, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
457}
458
459
460int SCH_LINE::GetAngleFrom( const VECTOR2I& aPoint ) const
461{
462 VECTOR2I vec;
463
464 if( aPoint == m_start )
465 vec = m_end - aPoint;
466 else
467 vec = m_start - aPoint;
468
469 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
470}
471
472
473int SCH_LINE::GetReverseAngleFrom( const VECTOR2I& aPoint ) const
474{
475 VECTOR2I vec;
476
477 if( aPoint == m_end )
478 vec = m_start - aPoint;
479 else
480 vec = m_end - aPoint;
481
482 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
483}
484
485
486bool SCH_LINE::IsParallel( const SCH_LINE* aLine ) const
487{
488 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, false,
489 wxT( "Cannot test line segment for overlap." ) );
490
491 VECTOR2I firstSeg = m_end - m_start;
492 VECTOR2I secondSeg = aLine->m_end - aLine->m_start;
493
494 // Use long long here to avoid overflow in calculations
495 return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
496}
497
498
499SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions )
500{
501 auto less =
502 []( const VECTOR2I& lhs, const VECTOR2I& rhs ) -> bool
503 {
504 if( lhs.x == rhs.x )
505 return lhs.y < rhs.y;
506
507 return lhs.x < rhs.x;
508 };
509
510 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, nullptr,
511 wxT( "Cannot test line segment for overlap." ) );
512
513 if( this == aLine || GetLayer() != aLine->GetLayer() )
514 return nullptr;
515
516 VECTOR2I leftmost_start = aLine->m_start;
517 VECTOR2I leftmost_end = aLine->m_end;
518
519 VECTOR2I rightmost_start = m_start;
520 VECTOR2I rightmost_end = m_end;
521
522 // We place the start to the left and below the end of both lines
523 if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
524 std::swap( leftmost_start, leftmost_end );
525 if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
526 std::swap( rightmost_start, rightmost_end );
527
528 // - leftmost is the line that starts farthest to the left
529 // - other is the line that is _not_ leftmost
530 // - rightmost is the line that ends farthest to the right. This may or may not be 'other'
531 // as the second line may be completely covered by the first.
532 if( less( rightmost_start, leftmost_start ) )
533 {
534 std::swap( leftmost_start, rightmost_start );
535 std::swap( leftmost_end, rightmost_end );
536 }
537
538 VECTOR2I other_start = rightmost_start;
539 VECTOR2I other_end = rightmost_end;
540
541 if( less( rightmost_end, leftmost_end ) )
542 {
543 rightmost_start = leftmost_start;
544 rightmost_end = leftmost_end;
545 }
546
547 // If we end one before the beginning of the other, no overlap is possible
548 if( less( leftmost_end, other_start ) )
549 {
550 return nullptr;
551 }
552
553 // Search for a common end:
554 if( ( leftmost_start == other_start ) && ( leftmost_end == other_end ) ) // Trivial case
555 {
556 SCH_LINE* ret = new SCH_LINE( *aLine );
557 ret->SetStartPoint( leftmost_start );
558 ret->SetEndPoint( leftmost_end );
559 ret->SetConnectivityDirty( true );
560
561 if( IsSelected() || aLine->IsSelected() )
562 ret->SetSelected();
563
564 return ret;
565 }
566
567 bool colinear = false;
568
569 /* Test alignment: */
570 if( ( leftmost_start.y == leftmost_end.y ) &&
571 ( other_start.y == other_end.y ) ) // Horizontal segment
572 {
573 colinear = ( leftmost_start.y == other_start.y );
574 }
575 else if( ( leftmost_start.x == leftmost_end.x ) &&
576 ( other_start.x == other_end.x ) ) // Vertical segment
577 {
578 colinear = ( leftmost_start.x == other_start.x );
579 }
580 else
581 {
582 // We use long long here to avoid overflow -- it enforces promotion
583 // The slope of the left-most line is dy/dx. Then we check that the slope from the
584 // left most start to the right most start is the same as well as the slope from the
585 // left most start to right most end.
586 long long dx = leftmost_end.x - leftmost_start.x;
587 long long dy = leftmost_end.y - leftmost_start.y;
588 colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
589 ( other_start.x - leftmost_start.x ) * dy ) &&
590 ( ( other_end.y - leftmost_start.y ) * dx ==
591 ( other_end.x - leftmost_start.x ) * dy ) );
592 }
593
594 if( !colinear )
595 return nullptr;
596
597 // We either have a true overlap or colinear touching segments. We always want to merge
598 // the former, but the later only get merged if there no junction at the touch point.
599
600 bool touching = leftmost_end == rightmost_start;
601
602 if( touching && aCheckJunctions && aScreen->IsJunction( leftmost_end ) )
603 return nullptr;
604
605 // Make a new segment that merges the 2 segments
606 leftmost_end = rightmost_end;
607
608 SCH_LINE* ret = new SCH_LINE( *aLine );
609 ret->SetStartPoint( leftmost_start );
610 ret->SetEndPoint( leftmost_end );
611 ret->SetConnectivityDirty( true );
612
613 if( IsSelected() || aLine->IsSelected() )
614 ret->SetSelected();
615
616 return ret;
617}
618
619
621{
622 SCH_LINE* newSegment = static_cast<SCH_LINE*>( Duplicate( true /* addToParentGroup */, aCommit ) );
623
624 newSegment->SetStartPoint( aPoint );
625 newSegment->SetConnectivityDirty( true );
626 SetEndPoint( aPoint );
627
628 return newSegment;
629}
630
631
633{
634 SCH_LINE* newSegment = static_cast<SCH_LINE*>( Duplicate( false /* addToParentGroup */, nullptr ) );
635
636 newSegment->SetStartPoint( aPoint );
637 newSegment->SetConnectivityDirty( true );
638 SetEndPoint( aPoint );
639
640 return newSegment;
641}
642
643
644void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
645{
646 if( IsConnectable() )
647 {
648 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_start );
649 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_end );
650 }
651}
652
653
654bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
655 std::vector<DANGLING_END_ITEM>& aItemListByPos,
656 const SCH_SHEET_PATH* aPath )
657{
658 if( !IsConnectable() )
659 return false;
660
661 bool previousStartState = m_startIsDangling;
662 bool previousEndState = m_endIsDangling;
663
665
666 for( auto it = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, m_start );
667 it < aItemListByPos.end() && it->GetPosition() == m_start; it++ )
668 {
669 DANGLING_END_ITEM& item = *it;
670
671 if( item.GetItem() == this )
672 continue;
673
674 if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
675 || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
676 {
677 m_startIsDangling = false;
678 break;
679 }
680 }
681
682 for( auto it = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, m_end );
683 it < aItemListByPos.end() && it->GetPosition() == m_end; it++ )
684 {
685 DANGLING_END_ITEM& item = *it;
686
687 if( item.GetItem() == this )
688 continue;
689
690 if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
691 || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
692 {
693 m_endIsDangling = false;
694 break;
695 }
696 }
697
698 // We only use the bus dangling state for automatic line starting, so we don't care if it
699 // has changed or not (and returning true will result in extra work)
700 if( IsBus() )
701 return false;
702
703 return previousStartState != m_startIsDangling || previousEndState != m_endIsDangling;
704}
705
706
708{
709 if( m_layer == LAYER_WIRE || m_layer == LAYER_BUS )
710 return true;
711
712 return false;
713}
714
715
716bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
717{
718 switch( aItem->Type() )
719 {
720 case SCH_NO_CONNECT_T:
721 case SCH_SYMBOL_T:
722 return IsWire();
723
724 case SCH_JUNCTION_T:
725 case SCH_LABEL_T:
727 case SCH_HIER_LABEL_T:
730 case SCH_SHEET_T:
731 case SCH_SHEET_PIN_T:
732 return IsWire() || IsBus();
733
734 default:
735 return m_layer == aItem->GetLayer();
736 }
737}
738
739
741 const SCH_SHEET_PATH* aInstance ) const
742{
743 // Do not compare to ourself.
744 if( aItem == this || !IsConnectable() )
745 return false;
746
747 const SCH_LINE* line = dynamic_cast<const SCH_LINE*>( aItem );
748
749 // Don't compare against a different SCH_ITEM.
750 wxCHECK( line, false );
751
752 if( GetStartPoint() != line->GetStartPoint() )
753 return true;
754
755 return GetEndPoint() != line->GetEndPoint();
756}
757
758
759std::vector<VECTOR2I> SCH_LINE::GetConnectionPoints() const
760{
761 return { m_start, m_end };
762}
763
764
766{
767 switch( aItem->Type() )
768 {
769 case SCH_LINE_T:
770 return IsBus() == static_cast<const SCH_LINE*>( aItem )->IsBus();
771
772 default:
773 return true;
774 }
775}
776
777
778void SCH_LINE::GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const
779{
780 if( m_flags & STARTPOINT )
781 aPoints.push_back( m_start );
782
783 if( m_flags & ENDPOINT )
784 aPoints.push_back( m_end );
785}
786
787
788wxString SCH_LINE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
789{
790 wxString txtfmt;
791
792 if( m_start.x == m_end.x )
793 {
794 switch( m_layer )
795 {
796 case LAYER_WIRE: txtfmt = _( "Vertical Wire, length %s" ); break;
797 case LAYER_BUS: txtfmt = _( "Vertical Bus, length %s" ); break;
798 default: txtfmt = _( "Vertical Graphic Line, length %s" ); break;
799 }
800 }
801 else if( m_start.y == m_end.y )
802 {
803 switch( m_layer )
804 {
805 case LAYER_WIRE: txtfmt = _( "Horizontal Wire, length %s" ); break;
806 case LAYER_BUS: txtfmt = _( "Horizontal Bus, length %s" ); break;
807 default: txtfmt = _( "Horizontal Graphic Line, length %s" ); break;
808 }
809 }
810 else
811 {
812 switch( m_layer )
813 {
814 case LAYER_WIRE: txtfmt = _( "Wire, length %s" ); break;
815 case LAYER_BUS: txtfmt = _( "Bus, length %s" ); break;
816 default: txtfmt = _( "Graphic Line, length %s" ); break;
817 }
818 }
819
820 return wxString::Format( txtfmt,
821 aUnitsProvider->MessageTextFromValue( m_start.Distance( m_end ) ) );
822}
823
824
826{
827 if( m_layer == LAYER_NOTES )
829 else if( m_layer == LAYER_WIRE )
830 return BITMAPS::add_line;
831
832 return BITMAPS::add_bus;
833}
834
835
836bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
837{
838 if( Type() != aItem.Type() )
839 return Type() < aItem.Type();
840
841 const SCH_LINE* line = static_cast<const SCH_LINE*>( &aItem );
842
843 if( GetLayer() != line->GetLayer() )
844 return GetLayer() < line->GetLayer();
845
846 if( GetStartPoint().x != line->GetStartPoint().x )
847 return GetStartPoint().x < line->GetStartPoint().x;
848
849 if( GetStartPoint().y != line->GetStartPoint().y )
850 return GetStartPoint().y < line->GetStartPoint().y;
851
852 if( GetEndPoint().x != line->GetEndPoint().x )
853 return GetEndPoint().x < line->GetEndPoint().x;
854
855 return GetEndPoint().y < line->GetEndPoint().y;
856}
857
858
859bool SCH_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
860{
861 // Performance enhancement for connection-building
862 if( aPosition == m_start || aPosition == m_end )
863 return true;
864
865 if( aAccuracy >= 0 )
866 aAccuracy += GetPenWidth() / 2;
867 else
868 aAccuracy = abs( aAccuracy );
869
870 return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
871}
872
873
874bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
875{
877 return false;
878
879 BOX2I rect = aRect;
880
881 if ( aAccuracy )
882 rect.Inflate( aAccuracy );
883
884 if( aContained )
885 return rect.Contains( m_start ) && rect.Contains( m_end );
886
887 return rect.Intersects( m_start, m_end );
888}
889
890
891bool SCH_LINE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
892{
894 return false;
895
897 return KIGEOM::ShapeHitTest( aPoly, line, aContained );
898}
899
900
902{
903 SCH_LINE* item = (SCH_LINE*) aItem;
904
905 std::swap( m_start, item->m_start );
906 std::swap( m_end, item->m_end );
907 std::swap( m_startIsDangling, item->m_startIsDangling );
908 std::swap( m_endIsDangling, item->m_endIsDangling );
909 std::swap( m_stroke, item->m_stroke );
910}
911
912
913bool SCH_LINE::doIsConnected( const VECTOR2I& aPosition ) const
914{
915 if( m_layer != LAYER_WIRE && m_layer != LAYER_BUS )
916 return false;
917
918 return IsEndPoint( aPosition );
919}
920
921
922void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
923 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
924{
925 if( aBackground )
926 return;
927
928 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
929 int penWidth = GetEffectivePenWidth( renderSettings );
930 COLOR4D color = GetLineColor();
931
932 if( color == COLOR4D::UNSPECIFIED )
933 color = renderSettings->GetLayerColor( GetLayer() );
934
935 if( color.m_text && Schematic() )
936 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
937
938 aPlotter->SetColor( color );
939
940 aPlotter->SetCurrentLineWidth( penWidth );
941 aPlotter->SetDash( penWidth, GetEffectiveLineStyle() );
942
943 aPlotter->MoveTo( m_start );
944 aPlotter->FinishTo( m_end );
945
946 aPlotter->SetDash( penWidth, LINE_STYLE::SOLID );
947
948 // Plot attributes to a hypertext menu
949 std::vector<wxString> properties;
950 BOX2I bbox = GetBoundingBox();
951 bbox.Inflate( penWidth * 3 );
952
953 if( aPlotOpts.m_PDFPropertyPopups )
954 {
955 if( GetLayer() == LAYER_WIRE )
956 {
957 if( SCH_CONNECTION* connection = Connection() )
958 {
959 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
960 _( "Net" ),
961 connection->Name() ) );
962
963 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
964 _( "Resolved netclass" ),
965 GetEffectiveNetClass()->GetHumanReadableName() ) );
966 }
967 }
968 else if( GetLayer() == LAYER_BUS )
969 {
970 if( SCH_CONNECTION* connection = Connection() )
971 {
972 for( const std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
973 properties.emplace_back( wxT( "!" ) + member->Name() );
974 }
975 }
976
977 if( !properties.empty() )
978 aPlotter->HyperlinkMenu( bbox, properties );
979 }
980}
981
982
983void SCH_LINE::SetPosition( const VECTOR2I& aPosition )
984{
985 m_end = m_end - ( m_start - aPosition );
986 m_start = aPosition;
987}
988
989
990void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
991{
992 wxString msg;
993
994 switch( GetLayer() )
995 {
996 case LAYER_WIRE: msg = _( "Wire" ); break;
997 case LAYER_BUS: msg = _( "Bus" ); break;
998 default: msg = _( "Graphical" ); break;
999 }
1000
1001 aList.emplace_back( _( "Line Type" ), msg );
1002
1003 LINE_STYLE lineStyle = GetStroke().GetLineStyle();
1004
1005 if( GetEffectiveLineStyle() != lineStyle )
1006 aList.emplace_back( _( "Line Style" ), _( "from netclass" ) );
1007 else
1008 m_stroke.GetMsgPanelInfo( aFrame, aList, true, false );
1009
1010 SCH_CONNECTION* conn = nullptr;
1011
1012 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1013 conn = Connection();
1014
1015 if( conn )
1016 {
1017 conn->AppendInfoToMsgPanel( aList );
1018
1019 if( !conn->IsBus() )
1020 {
1021 aList.emplace_back( _( "Resolved Netclass" ),
1022 UnescapeString( GetEffectiveNetClass()->GetHumanReadableName() ) );
1023
1024 if( SCHEMATIC* schematic = Schematic() )
1025 {
1026 if( SCH_NETCHAIN* chain = schematic->ConnectionGraph()->GetNetChainForNet( conn->Name() ) )
1027 aList.emplace_back( _( "Net Chain" ), UnescapeString( chain->GetName() ) );
1028 }
1029 }
1030 }
1031}
1032
1033
1035{
1036 return ( GetLayer() == LAYER_NOTES );
1037}
1038
1039
1041{
1042 return ( GetLayer() == LAYER_WIRE );
1043}
1044
1045
1047{
1048 return ( GetLayer() == LAYER_BUS );
1049}
1050
1051
1052bool SCH_LINE::operator==( const SCH_ITEM& aOther ) const
1053{
1054 if( Type() != aOther.Type() )
1055 return false;
1056
1057 const SCH_LINE& other = static_cast<const SCH_LINE&>( aOther );
1058
1059 if( GetLayer() != other.GetLayer() )
1060 return false;
1061
1062 if( m_start != other.m_start )
1063 return false;
1064
1065 if( m_end != other.m_end )
1066 return false;
1067
1068 if( m_stroke.GetWidth() != other.m_stroke.GetWidth() )
1069 return false;
1070
1071 if( m_stroke.GetColor() != other.m_stroke.GetColor() )
1072 return false;
1073
1074 if( m_stroke.GetLineStyle() != other.m_stroke.GetLineStyle() )
1075 return false;
1076
1077 return true;
1078}
1079
1080
1081double SCH_LINE::Similarity( const SCH_ITEM& aOther ) const
1082{
1083 if( m_Uuid == aOther.m_Uuid )
1084 return 1.0;
1085
1086 if( Type() != aOther.Type() )
1087 return 0.0;
1088
1089 const SCH_LINE& other = static_cast<const SCH_LINE&>( aOther );
1090
1091 if( GetLayer() != other.GetLayer() )
1092 return 0.0;
1093
1094 double similarity = 1.0;
1095
1096 if( m_start != other.m_start )
1097 similarity *= 0.9;
1098
1099 if( m_end != other.m_end )
1100 similarity *= 0.9;
1101
1102 if( m_stroke.GetWidth() != other.m_stroke.GetWidth() )
1103 similarity *= 0.9;
1104
1105 if( m_stroke.GetColor() != other.m_stroke.GetColor() )
1106 similarity *= 0.9;
1107
1108 if( m_stroke.GetLineStyle() != other.m_stroke.GetLineStyle() )
1109 similarity *= 0.9;
1110
1111 return similarity;
1112}
1113
1114
1115bool SCH_LINE::ShouldHopOver( const SCH_LINE* aLine ) const
1116{
1117 // try to find if this should hop over aLine. Horizontal wires have preference for hop.
1118 bool isMeVertical = ( m_end.x == m_start.x );
1119 bool isCandidateVertical = ( aLine->GetEndPoint().x == aLine->GetStartPoint().x );
1120
1121 // Vertical vs. Horizontal: Horizontal should hop
1122 if( isMeVertical && !isCandidateVertical )
1123 return false;
1124
1125 if( isCandidateVertical && !isMeVertical )
1126 return true;
1127
1128 // Both this and aLine have a slope. Try to find the best candidate
1129 double slopeMe = ( m_end.y - m_start.y ) / (double) ( m_end.x - m_start.x );
1130 double slopeCandidate = ( aLine->GetEndPoint().y - aLine->GetStartPoint().y )
1131 / (double) ( aLine->GetEndPoint().x - aLine->GetStartPoint().x );
1132
1133 if( fabs( slopeMe ) == fabs( slopeCandidate ) ) // Can easily happen with 45 deg wires
1134 return slopeMe < slopeCandidate; // signs are certainly different
1135
1136 return fabs( slopeMe ) < fabs( slopeCandidate ); // The shallower line should hop
1137}
1138
1139
1140std::vector<VECTOR3I> SCH_LINE::BuildWireWithHopShape( const SCH_SCREEN* aScreen,
1141 double aArcRadius ) const
1142{
1143 // Note: Points are VECTOR3D, with Z coord used as flag
1144 // for segments: start point and end point have the Z coord = 0
1145 // for arcs: start point middle point and end point have the Z coord = 1
1146
1147 std::vector<VECTOR3I> wire_shape; // List of coordinates:
1148 // 2 points for a segment, 3 points for an arc
1149
1150 if( !IsWire() && !IsBus() )
1151 {
1152 wire_shape.emplace_back( GetStartPoint().x,GetStartPoint().y, 0 );
1153 wire_shape.emplace_back( GetEndPoint().x, GetEndPoint().y, 0 );
1154 return wire_shape;
1155 }
1156
1157 std::vector<SCH_LINE*> existingWires; // wires to test (candidates)
1158 std::vector<VECTOR2I> intersections;
1159
1160 for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, GetBoundingBox() ) )
1161 {
1162 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1163
1164 if( line->IsWire() || line->IsBus() )
1165 existingWires.push_back( line );
1166 }
1167
1168 VECTOR2I currentLineStartPoint = GetStartPoint();
1169 VECTOR2I currentLineEndPoint = GetEndPoint();
1170
1171 for( SCH_LINE* existingLine : existingWires )
1172 {
1173 VECTOR2I extLineStartPoint = existingLine->GetStartPoint();
1174 VECTOR2I extLineEndPoint = existingLine->GetEndPoint();
1175
1176 if( extLineStartPoint == currentLineStartPoint && extLineEndPoint == currentLineEndPoint )
1177 continue;
1178
1179 if( !ShouldHopOver( existingLine ) )
1180 continue;
1181
1182 SEG currentSegment = SEG( currentLineStartPoint, currentLineEndPoint );
1183 SEG existingSegment = SEG( extLineStartPoint, extLineEndPoint );
1184
1185 if( OPT_VECTOR2I intersect = currentSegment.Intersect( existingSegment, true, false ) )
1186 {
1187 if( IsEndPoint( *intersect ) || existingLine->IsEndPoint( *intersect ) )
1188 continue;
1189
1190 // Ensure intersecting point is not yet entered. it can be already just entered
1191 // if more than two wires are intersecting at the same point,
1192 // creating bad hop over shapes for the current wire
1193 if( intersections.size() == 0 || intersections.back() != *intersect )
1194 intersections.push_back( *intersect );
1195 }
1196 }
1197
1198 if( intersections.empty() )
1199 {
1200 wire_shape.emplace_back( currentLineStartPoint.x, currentLineStartPoint.y, 0 );
1201 wire_shape.emplace_back( currentLineEndPoint.x, currentLineEndPoint.y, 0 );
1202 }
1203 else
1204 {
1205 auto getDistance =
1206 []( const VECTOR2I& a, const VECTOR2I& b ) -> double
1207 {
1208 return std::sqrt( std::pow( a.x - b.x, 2 ) + std::pow( a.y - b.y, 2 ) );
1209 };
1210
1211 std::sort( intersections.begin(), intersections.end(),
1212 [&]( const VECTOR2I& a, const VECTOR2I& b )
1213 {
1214 return getDistance( GetStartPoint(), a ) < getDistance( GetStartPoint(), b );
1215 } );
1216
1217 VECTOR2I currentStart = GetStartPoint();
1218 double R = aArcRadius;
1219
1220 for( const VECTOR2I& hopMid : intersections )
1221 {
1222 // Calculate the angle of the line from start point to end point in radians
1223 double lineAngle = std::atan2( GetEndPoint().y - GetStartPoint().y,
1224 GetEndPoint().x - GetStartPoint().x );
1225
1226 // Normalize to [0, pi) so the arc side doesn't depend
1227 // on which endpoint is start vs end
1228 double arcAngle = lineAngle;
1229
1230 if( arcAngle < 0.0 )
1231 arcAngle += M_PI;
1232 else if( arcAngle >= M_PI )
1233 arcAngle -= M_PI;
1234
1235 VECTOR2I arcMidPoint = { hopMid.x + static_cast<int>( R * std::sin( arcAngle ) ),
1236 hopMid.y - static_cast<int>( R * std::cos( arcAngle ) ) };
1237
1238 VECTOR2I beforeHop = hopMid - KiROUND( R * std::cos( lineAngle ), R * std::sin( lineAngle ) );
1239 VECTOR2I afterHop = hopMid + KiROUND( R * std::cos( lineAngle ), R * std::sin( lineAngle ) );
1240
1241 // Draw the line from the current start point to the before-hop point
1242 wire_shape.emplace_back( currentStart.x, currentStart.y, 0 );
1243 wire_shape.emplace_back( beforeHop.x, beforeHop.y, 0 );
1244
1245 // Create an arc object
1246 wire_shape.emplace_back( beforeHop.x, beforeHop.y, 1 );
1247 wire_shape.emplace_back( arcMidPoint.x, arcMidPoint.y, 1 );
1248 wire_shape.emplace_back( afterHop.x, afterHop.y, 1 );
1249
1250 currentStart = afterHop;
1251 }
1252
1253 // Draw the final line from the current start point to the end point of the original line
1254 wire_shape.emplace_back( currentStart. x,currentStart.y, 0 );
1255 wire_shape.emplace_back( GetEndPoint().x, GetEndPoint().y, 0 );
1256 }
1257
1258 return wire_shape;
1259}
1260
1261
1262static struct SCH_LINE_DESC
1263{
1265 {
1267
1268 if( lineStyleEnum.Choices().GetCount() == 0 )
1269 {
1270 lineStyleEnum.Map( LINE_STYLE::SOLID, _HKI( "Solid" ) )
1271 .Map( LINE_STYLE::DASH, _HKI( "Dashed" ) )
1272 .Map( LINE_STYLE::DOT, _HKI( "Dotted" ) )
1273 .Map( LINE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
1274 .Map( LINE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
1275 }
1276
1278
1279 if( wireLineStyleEnum.Choices().GetCount() == 0 )
1280 {
1281 wireLineStyleEnum.Map( WIRE_STYLE::DEFAULT, _HKI( "Default" ) )
1282 .Map( WIRE_STYLE::SOLID, _HKI( "Solid" ) )
1283 .Map( WIRE_STYLE::DASH, _HKI( "Dashed" ) )
1284 .Map( WIRE_STYLE::DOT, _HKI( "Dotted" ) )
1285 .Map( WIRE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
1286 .Map( WIRE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
1287 }
1288
1292
1293 auto isGraphicLine =
1294 []( INSPECTABLE* aItem ) -> bool
1295 {
1296 if( SCH_LINE* line = dynamic_cast<SCH_LINE*>( aItem ) )
1297 return line->IsGraphicLine();
1298
1299 return false;
1300 };
1301
1302 auto isWireOrBus =
1303 []( INSPECTABLE* aItem ) -> bool
1304 {
1305 if( SCH_LINE* line = dynamic_cast<SCH_LINE*>( aItem ) )
1306 return line->IsWire() || line->IsBus();
1307
1308 return false;
1309 };
1310
1311 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Start X" ),
1314
1315 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Start Y" ),
1318
1319 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "End X" ),
1322
1323 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "End Y" ),
1326
1327 propMgr.AddProperty( new PROPERTY<SCH_LINE, double>( _HKI( "Length" ),
1329
1330 propMgr.AddProperty( new PROPERTY_ENUM<SCH_LINE, LINE_STYLE>( _HKI( "Line Style" ),
1332 .SetAvailableFunc( isGraphicLine );
1333
1336 .SetAvailableFunc( isWireOrBus );
1337
1338 propMgr.AddProperty( new PROPERTY<SCH_LINE, int>( _HKI( "Line Width" ),
1340
1341 propMgr.AddProperty( new PROPERTY<SCH_LINE, COLOR4D>( _HKI( "Color" ),
1343 }
1345
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:44
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:127
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:402
static std::vector< DANGLING_END_ITEM >::iterator get_lower_pos(std::vector< DANGLING_END_ITEM > &aItemListByPos, const VECTOR2I &aPos)
Definition sch_item.cpp:961
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:97
DANGLING_END_T GetType() const
Definition sch_item.h:133
EDA_ITEM * GetItem() const
Definition sch_item.h:131
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:528
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:539
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition eda_item.h:541
bool IsSelected() const
Definition eda_item.h:129
void SetSelected()
Definition eda_item.h:141
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:230
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:38
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
std::shared_ptr< wxString > m_text
Definition color4d.h:399
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:67
Definition kiid.h:48
int GetLineStyle() const
Definition netclass.h:231
int GetWireWidth() const
Definition netclass.h:201
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:216
int GetBusWidth() const
Definition netclass.h:209
Base plotter engine class.
Definition plotter.h:137
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:309
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle)=0
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:319
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:518
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:89
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
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:168
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:164
void SetLocked(bool aLocked) override
Definition sch_item.h:257
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:730
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:272
bool IsLocked() const override
Definition sch_item.cpp:152
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:527
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:345
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:344
void SetConnectivityDirty(bool aDirty=true)
Definition sch_item.h:593
bool IsConnectivityDirty() const
Definition sch_item.h:591
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:56
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:491
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:381
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:792
SCH_LAYER_ID m_layer
Definition sch_item.h:781
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:396
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:913
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:644
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:202
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_line.cpp:825
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:654
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:859
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_line.cpp:983
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:632
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition sch_line.cpp:759
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition sch_line.cpp:473
SCH_LINE(const VECTOR2I &pos=VECTOR2I(0, 0), int layer=LAYER_NOTES)
Definition sch_line.cpp:52
bool IsWire() const
Return true if the line is a wire.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_line.cpp:276
void SetWireStyle(const WIRE_STYLE aStyle)
Definition sch_line.h:186
void SetLineColor(const COLOR4D &aColor)
Definition sch_line.cpp:323
bool CanConnect(const SCH_ITEM *aItem) const override
Definition sch_line.cpp:716
bool IsParallel(const SCH_LINE *aLine) const
Definition sch_line.cpp:486
int GetStartY() const
Definition sch_line.h:143
void SetLineWidth(const int aSize)
Definition sch_line.cpp:389
bool ShouldHopOver(const SCH_LINE *aLine) const
For wires only:
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition sch_line.cpp:440
virtual STROKE_PARAMS GetStroke() const override
Definition sch_line.h:201
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition sch_line.cpp:460
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition sch_line.cpp:778
COLOR4D m_lastResolvedColor
Definition sch_line.h:398
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_line.cpp:376
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:990
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:922
wxString m_operatingPoint
Definition sch_line.h:400
void SetLength(double aLength)
Definition sch_line.cpp:298
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:450
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:765
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:499
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.
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:740
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_line.cpp:108
void SetLineStyle(const LINE_STYLE aStyle)
Definition sch_line.cpp:360
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:208
int GetEndX() const
Definition sch_line.h:150
LINE_STYLE GetLineStyle() const
Definition sch_line.cpp:367
void MoveEnd(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:221
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:620
bool m_endIsDangling
True if end point is not connected.
Definition sch_line.h:387
bool IsConnectable() const override
Definition sch_line.cpp:707
wxString GetFriendlyName() const override
Definition sch_line.cpp:191
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition sch_line.cpp:254
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_line.cpp:430
bool operator==(const SCH_ITEM &aOther) const override
bool operator<(const SCH_ITEM &aItem) const override
Definition sch_line.cpp:836
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:788
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)
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:347
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:244
void MoveStart(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:215
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_line.cpp:149
double GetLength() const
Definition sch_line.cpp:292
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:901
A net chain is a collection of nets that are connected together through passive components.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:119
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:446
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.
@ LAYER_DANGLING
Definition layer_ids.h:479
@ LAYER_WIRE
Definition layer_ids.h:454
@ LAYER_NOTES
Definition layer_ids.h:469
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:495
@ LAYER_BUS
Definition layer_ids.h:455
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:497
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:503
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 void PackColor(types::Color &aOutput, const KIGFX::COLOR4D &aInput)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIGFX::COLOR4D UnpackColor(const types::Color &aInput)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
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:81
@ PIN_END
Definition sch_item.h:83
@ BUS_ENTRY_END
Definition sch_item.h:85
@ WIRE_END
Definition sch_item.h:80
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:65
const SHAPE_LINE_CHAIN chain
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:164
@ SCH_NO_CONNECT_T
Definition typeinfo.h:161
@ SCH_SYMBOL_T
Definition typeinfo.h:173
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:172
@ SCH_LABEL_T
Definition typeinfo.h:168
@ SCH_SHEET_T
Definition typeinfo.h:176
@ SCH_HIER_LABEL_T
Definition typeinfo.h:170
@ SCH_SHEET_PIN_T
Definition typeinfo.h:175
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:162
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:169
@ SCH_JUNCTION_T
Definition typeinfo.h:160
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687