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