KiCad PCB EDA Suite
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 (C) 1992-2022 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 <plotters/plotter.h>
32#include <sch_line.h>
33#include <sch_edit_frame.h>
35#include <schematic.h>
36#include <connection_graph.h>
39#include <trigo.h>
40#include <board_item.h>
41
42
43SCH_LINE::SCH_LINE( const VECTOR2I& pos, int layer ) :
44 SCH_ITEM( nullptr, SCH_LINE_T )
45{
46 m_start = pos;
47 m_end = pos;
48 m_stroke.SetWidth( 0 );
50 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
51
52 switch( layer )
53 {
54 default: m_layer = LAYER_NOTES; break;
55 case LAYER_WIRE: m_layer = LAYER_WIRE; break;
56 case LAYER_BUS: m_layer = LAYER_BUS; break;
57 }
58
59 if( layer == LAYER_NOTES )
61 else
63
64 if( layer == LAYER_WIRE )
66 else if( layer == LAYER_BUS )
68 else
70
72 m_lastResolvedColor = COLOR4D::UNSPECIFIED;
73}
74
75
77 SCH_ITEM( aLine )
78{
79 m_start = aLine.m_start;
80 m_end = aLine.m_end;
81 m_stroke = aLine.m_stroke;
84
88}
89
90wxString SCH_LINE::GetNetname( const SCH_SHEET_PATH& aSheet )
91{
92 std::list<const SCH_LINE *> checkedLines;
93 checkedLines.push_back(this);
94 return FindWireSegmentNetNameRecursive( this, checkedLines, aSheet );
95}
96
98 std::list<const SCH_LINE *> &checkedLines,
99 const SCH_SHEET_PATH& aSheet ) const
100{
101 for ( auto connected : line->ConnectedItems( aSheet ) )
102 {
103 if( connected->Type() == SCH_LINE_T )
104 {
105 if( std::find(checkedLines.begin(), checkedLines.end(), connected ) == checkedLines.end() )
106 {
107 SCH_LINE* connectedLine = static_cast<SCH_LINE*>( connected );
108 checkedLines.push_back( connectedLine );
109
110 wxString netName = FindWireSegmentNetNameRecursive( connectedLine, checkedLines,
111 aSheet );
112
113 if( !netName.IsEmpty() )
114 return netName;
115 }
116 }
117 else if( connected->Type() == SCH_LABEL_T
118 || connected->Type() == SCH_GLOBAL_LABEL_T
119 || connected->Type() == SCH_DIRECTIVE_LABEL_T)
120 {
121 return static_cast<SCH_TEXT*>( connected )->GetText();
122 }
123
124 }
125 return "";
126}
127
129{
130 return new SCH_LINE( *this );
131}
132
133
134void SCH_LINE::Move( const VECTOR2I& aOffset )
135{
136 if( aOffset != VECTOR2I( 0, 0 ) )
137 {
138 m_start += aOffset;
139 m_end += aOffset;
140 SetModified();
141 }
142}
143
144
145void SCH_LINE::MoveStart( const VECTOR2I& aOffset )
146{
147 if( aOffset != VECTOR2I( 0, 0 ) )
148 {
149 m_start += aOffset;
150 SetModified();
151 }
152}
153
154
155void SCH_LINE::MoveEnd( const VECTOR2I& aOffset )
156{
157 if( aOffset != VECTOR2I( 0, 0 ) )
158 {
159 m_end += aOffset;
160 SetModified();
161 }
162}
163
164
165#if defined(DEBUG)
166
167void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
168{
169 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
170 << " layer=\"" << m_layer << '"'
171 << " startIsDangling=\"" << m_startIsDangling
172 << '"' << " endIsDangling=\""
173 << m_endIsDangling << '"' << ">"
174 << " <start" << m_start << "/>"
175 << " <end" << m_end << "/>" << "</"
176 << GetClass().Lower().mb_str() << ">\n";
177}
178
179#endif
180
181
182void SCH_LINE::ViewGetLayers( int aLayers[], int& aCount ) const
183{
184 aCount = 3;
185 aLayers[0] = LAYER_DANGLING;
186 aLayers[1] = m_layer;
187 aLayers[2] = LAYER_SELECTION_SHADOWS;
188}
189
190
192{
193 int width = GetPenWidth() / 2;
194
195 int xmin = std::min( m_start.x, m_end.x ) - width;
196 int ymin = std::min( m_start.y, m_end.y ) - width;
197
198 int xmax = std::max( m_start.x, m_end.x ) + width + 1;
199 int ymax = std::max( m_start.y, m_end.y ) + width + 1;
200
201 BOX2I ret( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin, ymax - ymin ) );
202
203 return ret;
204}
205
206
208{
209 return GetLineLength( m_start, m_end );
210}
211
212
213void SCH_LINE::SetLineColor( const COLOR4D& aColor )
214{
215 m_stroke.SetColor( aColor );
217}
218
219
220void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
221{
222 COLOR4D newColor(r, g, b, a);
223
224 if( newColor == COLOR4D::UNSPECIFIED )
225 {
226 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
227 }
228 else
229 {
230 // Eeschema does not allow alpha channel in colors
231 newColor.a = 1.0;
232 m_stroke.SetColor( newColor );
233 }
234}
235
236
238{
239 if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED )
241 else if( !IsConnectable() )
242 m_lastResolvedColor = COLOR4D::UNSPECIFIED;
243 else if( !IsConnectivityDirty() )
244 m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
245
246 return m_lastResolvedColor;
247}
248
249
250void SCH_LINE::SetLineStyle( const int aStyleId )
251{
252 SetLineStyle( static_cast<PLOT_DASH_TYPE>( aStyleId ) );
253}
254
255
257{
258 m_stroke.SetPlotStyle( aStyle );
260}
261
262
264{
266 return m_stroke.GetPlotStyle();
267
269}
270
271
273{
276 else if( !IsConnectable() )
278 else if( !IsConnectivityDirty() )
280
282}
283
284
285void SCH_LINE::SetLineWidth( const int aSize )
286{
287 m_stroke.SetWidth( aSize );
289}
290
291
293{
294 SCHEMATIC* schematic = Schematic();
295
296 switch ( m_layer )
297 {
298 default:
299 if( m_stroke.GetWidth() > 0 )
300 return m_stroke.GetWidth();
301
302 if( schematic )
303 return schematic->Settings().m_DefaultLineWidth;
304
306
307 case LAYER_WIRE:
308 if( m_stroke.GetWidth() > 0 )
310 else if( !IsConnectivityDirty() )
311 m_lastResolvedWidth = GetEffectiveNetClass()->GetWireWidth();
312
313 return m_lastResolvedWidth;
314
315 case LAYER_BUS:
316 if( m_stroke.GetWidth() > 0 )
318 else if( !IsConnectivityDirty() )
319 m_lastResolvedWidth = GetEffectiveNetClass()->GetBusWidth();
320
321 return m_lastResolvedWidth;
322 }
323}
324
325
326void SCH_LINE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset )
327{
328 wxDC* DC = aSettings->GetPrintDC();
330
331 if( color == COLOR4D::UNSPECIFIED )
332 color = aSettings->GetLayerColor( GetLayer() );
333
334 VECTOR2I start = m_start;
335 VECTOR2I end = m_end;
337 int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
338
339 if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE )
340 {
341 GRLine( DC, start.x, start.y, end.x, end.y, penWidth, color );
342 }
343 else
344 {
345 SHAPE_SEGMENT segment( start, end );
346
347 STROKE_PARAMS::Stroke( &segment, lineStyle, penWidth, aSettings,
348 [&]( const VECTOR2I& a, const VECTOR2I& b )
349 {
350 GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
351 } );
352 }
353}
354
355
356void SCH_LINE::MirrorVertically( int aCenter )
357{
358 if( m_flags & STARTPOINT )
359 MIRROR( m_start.y, aCenter );
360
361 if( m_flags & ENDPOINT )
362 MIRROR( m_end.y, aCenter );
363}
364
365
367{
368 if( m_flags & STARTPOINT )
369 MIRROR( m_start.x, aCenter );
370
371 if( m_flags & ENDPOINT )
372 MIRROR( m_end.x, aCenter );
373}
374
375
376void SCH_LINE::Rotate( const VECTOR2I& aCenter )
377{
378 // When we allow off grid items, the
379 // else if should become a plain if to allow
380 // rotation around the center of the line
381 if( m_flags & STARTPOINT )
382 RotatePoint( m_start, aCenter, ANGLE_90 );
383
384 else if( m_flags & ENDPOINT )
385 RotatePoint( m_end, aCenter, ANGLE_90 );
386}
387
388
389void SCH_LINE::RotateStart( const VECTOR2I& aCenter )
390{
391 RotatePoint( m_start, aCenter, ANGLE_90 );
392}
393
394
395void SCH_LINE::RotateEnd( const VECTOR2I& aCenter )
396{
397 RotatePoint( m_end, aCenter, ANGLE_90 );
398}
399
400
401int SCH_LINE::GetAngleFrom( const VECTOR2I& aPoint ) const
402{
403 VECTOR2I vec;
404
405 if( aPoint == m_start )
406 vec = m_end - aPoint;
407 else
408 vec = m_start - aPoint;
409
410 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
411}
412
413
414int SCH_LINE::GetReverseAngleFrom( const VECTOR2I& aPoint ) const
415{
416 VECTOR2I vec;
417
418 if( aPoint == m_end )
419 vec = m_start - aPoint;
420 else
421 vec = m_end - aPoint;
422
423 return KiROUND( EDA_ANGLE( vec ).AsDegrees() );
424}
425
426
427bool SCH_LINE::IsParallel( const SCH_LINE* aLine ) const
428{
429 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, false,
430 wxT( "Cannot test line segment for overlap." ) );
431
432 VECTOR2I firstSeg = m_end - m_start;
433 VECTOR2I secondSeg = aLine->m_end - aLine->m_start;
434
435 // Use long long here to avoid overflow in calculations
436 return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
437}
438
439
440SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions )
441{
442 auto less =
443 []( const VECTOR2I& lhs, const VECTOR2I& rhs ) -> bool
444 {
445 if( lhs.x == rhs.x )
446 return lhs.y < rhs.y;
447
448 return lhs.x < rhs.x;
449 };
450
451 wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, nullptr,
452 wxT( "Cannot test line segment for overlap." ) );
453
454 if( this == aLine || GetLayer() != aLine->GetLayer() )
455 return nullptr;
456
457 VECTOR2I leftmost_start = aLine->m_start;
458 VECTOR2I leftmost_end = aLine->m_end;
459
460 VECTOR2I rightmost_start = m_start;
461 VECTOR2I rightmost_end = m_end;
462
463 // We place the start to the left and below the end of both lines
464 if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
465 std::swap( leftmost_start, leftmost_end );
466 if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
467 std::swap( rightmost_start, rightmost_end );
468
469 // - leftmost is the line that starts farthest to the left
470 // - other is the line that is _not_ leftmost
471 // - rightmost is the line that ends farthest to the right. This may or may not be 'other'
472 // as the second line may be completely covered by the first.
473 if( less( rightmost_start, leftmost_start ) )
474 {
475 std::swap( leftmost_start, rightmost_start );
476 std::swap( leftmost_end, rightmost_end );
477 }
478
479 VECTOR2I other_start = rightmost_start;
480 VECTOR2I other_end = rightmost_end;
481
482 if( less( rightmost_end, leftmost_end ) )
483 {
484 rightmost_start = leftmost_start;
485 rightmost_end = leftmost_end;
486 }
487
488 // If we end one before the beginning of the other, no overlap is possible
489 if( less( leftmost_end, other_start ) )
490 {
491 return nullptr;
492 }
493
494 // Search for a common end:
495 if( ( leftmost_start == other_start ) && ( leftmost_end == other_end ) ) // Trivial case
496 {
497 SCH_LINE* ret = new SCH_LINE( *aLine );
498 ret->SetStartPoint( leftmost_start );
499 ret->SetEndPoint( leftmost_end );
500 ret->SetConnectivityDirty( true );
501
502 if( IsSelected() || aLine->IsSelected() )
503 ret->SetSelected();
504
505 return ret;
506 }
507
508 bool colinear = false;
509
510 /* Test alignment: */
511 if( ( leftmost_start.y == leftmost_end.y ) &&
512 ( other_start.y == other_end.y ) ) // Horizontal segment
513 {
514 colinear = ( leftmost_start.y == other_start.y );
515 }
516 else if( ( leftmost_start.x == leftmost_end.x ) &&
517 ( other_start.x == other_end.x ) ) // Vertical segment
518 {
519 colinear = ( leftmost_start.x == other_start.x );
520 }
521 else
522 {
523 // We use long long here to avoid overflow -- it enforces promotion
524 // The slope of the left-most line is dy/dx. Then we check that the slope from the
525 // left most start to the right most start is the same as well as the slope from the
526 // left most start to right most end.
527 long long dx = leftmost_end.x - leftmost_start.x;
528 long long dy = leftmost_end.y - leftmost_start.y;
529 colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
530 ( other_start.x - leftmost_start.x ) * dy ) &&
531 ( ( other_end.y - leftmost_start.y ) * dx ==
532 ( other_end.x - leftmost_start.x ) * dy ) );
533 }
534
535 if( !colinear )
536 return nullptr;
537
538 // We either have a true overlap or colinear touching segments. We always want to merge
539 // the former, but the later only get merged if there no junction at the touch point.
540
541 bool touching = leftmost_end == rightmost_start;
542
543 if( touching && aCheckJunctions && aScreen->IsJunction( leftmost_end ) )
544 return nullptr;
545
546 // Make a new segment that merges the 2 segments
547 leftmost_end = rightmost_end;
548
549 SCH_LINE* ret = new SCH_LINE( *aLine );
550 ret->SetStartPoint( leftmost_start );
551 ret->SetEndPoint( leftmost_end );
552 ret->SetConnectivityDirty( true );
553
554 if( IsSelected() || aLine->IsSelected() )
555 ret->SetSelected();
556
557 return ret;
558}
559
560
561void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
562{
563 if( IsConnectable() )
564 {
565 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_start );
566 aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_end );
567 }
568}
569
570
571bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
572 const SCH_SHEET_PATH* aPath )
573{
574 if( IsConnectable() )
575 {
576 bool previousStartState = m_startIsDangling;
577 bool previousEndState = m_endIsDangling;
578
580
581 for( DANGLING_END_ITEM item : aItemList )
582 {
583 if( item.GetItem() == this )
584 continue;
585
586 if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
587 || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
588 {
589 if( m_start == item.GetPosition() )
590 m_startIsDangling = false;
591
592 if( m_end == item.GetPosition() )
593 m_endIsDangling = false;
594
596 break;
597 }
598 }
599
600 // We only use the bus dangling state for automatic line starting, so we don't care if it
601 // has changed or not (and returning true will result in extra work)
602 if( IsBus() )
603 return false;
604
605 return previousStartState != m_startIsDangling || previousEndState != m_endIsDangling;
606 }
607
608 return false;
609}
610
611
613{
614 if( m_layer == LAYER_WIRE || m_layer == LAYER_BUS )
615 return true;
616
617 return false;
618}
619
620
621bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
622{
623 if( m_layer == LAYER_WIRE )
624 {
625 switch( aItem->Type() )
626 {
627 case SCH_JUNCTION_T:
628 case SCH_NO_CONNECT_T:
629 case SCH_LABEL_T:
631 case SCH_HIER_LABEL_T:
634 case SCH_SYMBOL_T:
635 case SCH_SHEET_T:
636 case SCH_SHEET_PIN_T:
637 return true;
638 default:
639 break;
640 }
641 }
642 else if( m_layer == LAYER_BUS )
643 {
644 switch( aItem->Type() )
645 {
646 case SCH_JUNCTION_T:
647 case SCH_LABEL_T:
649 case SCH_HIER_LABEL_T:
652 case SCH_SHEET_T:
653 case SCH_SHEET_PIN_T:
654 return true;
655 default:
656 break;
657 }
658 }
659
660 return aItem->GetLayer() == m_layer;
661}
662
663
664std::vector<VECTOR2I> SCH_LINE::GetConnectionPoints() const
665{
666 return { m_start, m_end };
667}
668
669
671{
672 switch( aItem->Type() )
673 {
674 case SCH_LINE_T:
675 return IsBus() == static_cast<const SCH_LINE*>( aItem )->IsBus();
676
677 default:
678 return true;
679 }
680}
681
682
683void SCH_LINE::GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const
684{
685 if( m_flags & STARTPOINT )
686 aPoints.push_back( m_start );
687
688 if( m_flags & ENDPOINT )
689 aPoints.push_back( m_end );
690}
691
692
693wxString SCH_LINE::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
694{
695 wxString txtfmt;
696
697 if( m_start.x == m_end.x )
698 {
699 switch( m_layer )
700 {
701 case LAYER_WIRE: txtfmt = _( "Vertical Wire, length %s" ); break;
702 case LAYER_BUS: txtfmt = _( "Vertical Bus, length %s" ); break;
703 default: txtfmt = _( "Vertical Graphic Line, length %s" ); break;
704 }
705 }
706 else if( m_start.y == m_end.y )
707 {
708 switch( m_layer )
709 {
710 case LAYER_WIRE: txtfmt = _( "Horizontal Wire, length %s" ); break;
711 case LAYER_BUS: txtfmt = _( "Horizontal Bus, length %s" ); break;
712 default: txtfmt = _( "Horizontal Graphic Line, length %s" ); break;
713 }
714 }
715 else
716 {
717 switch( m_layer )
718 {
719 case LAYER_WIRE: txtfmt = _( "Wire, length %s" ); break;
720 case LAYER_BUS: txtfmt = _( "Bus, length %s" ); break;
721 default: txtfmt = _( "Graphic Line, length %s" ); break;
722 }
723 }
724
725 return wxString::Format( txtfmt,
726 aUnitsProvider->MessageTextFromValue( EuclideanNorm( m_start - m_end ) ) );
727}
728
729
731{
732 if( m_layer == LAYER_NOTES )
734 else if( m_layer == LAYER_WIRE )
735 return BITMAPS::add_line;
736
737 return BITMAPS::add_bus;
738}
739
740
741bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
742{
743 if( Type() != aItem.Type() )
744 return Type() < aItem.Type();
745
746 const SCH_LINE* line = static_cast<const SCH_LINE*>( &aItem );
747
748 if( GetLayer() != line->GetLayer() )
749 return GetLayer() < line->GetLayer();
750
751 if( GetStartPoint().x != line->GetStartPoint().x )
752 return GetStartPoint().x < line->GetStartPoint().x;
753
754 if( GetStartPoint().y != line->GetStartPoint().y )
755 return GetStartPoint().y < line->GetStartPoint().y;
756
757 if( GetEndPoint().x != line->GetEndPoint().x )
758 return GetEndPoint().x < line->GetEndPoint().x;
759
760 return GetEndPoint().y < line->GetEndPoint().y;
761}
762
763
764bool SCH_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
765{
766 // Performance enhancement for connection-building
767 if( aPosition == m_start || aPosition == m_end )
768 return true;
769
770 if( aAccuracy >= 0 )
771 aAccuracy += GetPenWidth() / 2;
772 else
773 aAccuracy = abs( aAccuracy );
774
775 return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
776}
777
778
779bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
780{
782 return false;
783
784 BOX2I rect = aRect;
785
786 if ( aAccuracy )
787 rect.Inflate( aAccuracy );
788
789 if( aContained )
790 return rect.Contains( m_start ) && rect.Contains( m_end );
791
792 return rect.Intersects( m_start, m_end );
793}
794
795
797{
798 SCH_LINE* item = (SCH_LINE*) aItem;
799
800 std::swap( m_layer, item->m_layer );
801
802 std::swap( m_start, item->m_start );
803 std::swap( m_end, item->m_end );
804 std::swap( m_startIsDangling, item->m_startIsDangling );
805 std::swap( m_endIsDangling, item->m_endIsDangling );
806 std::swap( m_stroke, item->m_stroke );
807}
808
809
810bool SCH_LINE::doIsConnected( const VECTOR2I& aPosition ) const
811{
812 if( m_layer != LAYER_WIRE && m_layer != LAYER_BUS )
813 return false;
814
815 return IsEndPoint( aPosition );
816}
817
818
819void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
820{
821 if( aBackground )
822 return;
823
824 auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
825 int penWidth = std::max( GetPenWidth(), settings->GetMinPenWidth() );
827
828 if( color == COLOR4D::UNSPECIFIED )
829 color = settings->GetLayerColor( GetLayer() );
830
831 aPlotter->SetColor( color );
832
833 aPlotter->SetCurrentLineWidth( penWidth );
834 aPlotter->SetDash( penWidth, GetEffectiveLineStyle() );
835
836 aPlotter->MoveTo( m_start );
837 aPlotter->FinishTo( m_end );
838
839 aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
840
841 // Plot attributes to a hypertext menu
842 std::vector<wxString> properties;
843 BOX2I bbox = GetBoundingBox();
844 bbox.Inflate( GetPenWidth() * 3 );
845
846 if( GetLayer() == LAYER_WIRE )
847 {
848 if( SCH_CONNECTION* connection = Connection() )
849 {
850 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
851 _( "Net" ),
852 connection->Name() ) );
853
854 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
855 _( "Resolved netclass" ),
856 GetEffectiveNetClass()->GetName() ) );
857 }
858 }
859 else if( GetLayer() == LAYER_BUS )
860 {
861 if( SCH_CONNECTION* connection = Connection() )
862 {
863 for( std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
864 properties.emplace_back( wxT( "!" ) + member->Name() );
865 }
866
867 }
868
869 if( !properties.empty() )
870 aPlotter->HyperlinkMenu( bbox, properties );
871}
872
873
874void SCH_LINE::SetPosition( const VECTOR2I& aPosition )
875{
876 m_end = m_end - ( m_start - aPosition );
877 m_start = aPosition;
878}
879
880
881void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
882{
883 wxString msg;
884
885 switch( GetLayer() )
886 {
887 case LAYER_WIRE: msg = _( "Wire" ); break;
888 case LAYER_BUS: msg = _( "Bus" ); break;
889 default: msg = _( "Graphical" ); break;
890 }
891
892 aList.emplace_back( _( "Line Type" ), msg );
893
894 PLOT_DASH_TYPE lineStyle = GetLineStyle();
895
896 if( GetEffectiveLineStyle() != lineStyle )
897 aList.emplace_back( _( "Line Style" ), _( "from netclass" ) );
898 else
899 m_stroke.GetMsgPanelInfo( aFrame, aList, true, false );
900
901 SCH_CONNECTION* conn = nullptr;
902
903 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
904 conn = Connection();
905
906 if( conn )
907 {
908 conn->AppendInfoToMsgPanel( aList );
909
910 if( !conn->IsBus() )
911 {
912 aList.emplace_back( _( "Resolved Netclass" ),
913 UnescapeString( GetEffectiveNetClass()->GetName() ) );
914 }
915 }
916}
917
918
920{
921 return ( GetLayer() == LAYER_NOTES );
922}
923
924
926{
927 return ( GetLayer() == LAYER_WIRE );
928}
929
930
931bool SCH_LINE::IsBus() const
932{
933 return ( GetLayer() == LAYER_BUS );
934}
935
int color
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
@ add_dashed_line
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:269
bool Contains(const Vec &aPoint) const
Definition: box2.h:141
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:82
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
void SetModified()
Definition: eda_item.cpp:64
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:500
bool IsSelected() const
Definition: eda_item.h:107
void SetSelected()
Definition: eda_item.h:118
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double a
Alpha component.
Definition: color4d.h:387
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Store schematic specific render settings.
Definition: sch_painter.h:71
Base plotter engine class.
Definition: plotter.h:110
virtual void SetDash(int aLineWidth, PLOT_DASH_TYPE aLineStyle)=0
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:247
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:257
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:141
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:446
virtual void SetColor(const COLOR4D &color)=0
Holds all the data relating to one schematic.
Definition: schematic.h:61
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
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:147
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:187
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:166
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:415
bool IsConnectivityDirty() const
Definition: sch_item.h:413
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:146
SCH_LAYER_ID m_layer
Definition: sch_item.h:491
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
int GetPenWidth() const override
Definition: sch_line.cpp:292
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:376
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:810
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:561
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:139
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:128
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:730
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:322
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:764
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_line.cpp:874
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:664
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:414
SCH_LINE(const VECTOR2I &pos=VECTOR2I(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:43
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:925
void RotateEnd(const VECTOR2I &aCenter)
Definition: sch_line.cpp:395
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:191
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_line.cpp:182
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:213
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:621
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:427
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:285
void RotateStart(const VECTOR2I &aCenter)
Definition: sch_line.cpp:389
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:366
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:401
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition: sch_line.cpp:683
COLOR4D m_lastResolvedColor
Definition: sch_line.h:334
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:881
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_line.cpp:693
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:59
VECTOR2I GetEndPoint() const
Definition: sch_line.h:143
VECTOR2I GetStartPoint() const
Definition: sch_line.h:138
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:670
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:440
VECTOR2I m_start
Line start point.
Definition: sch_line.h:324
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:931
int m_lastResolvedWidth
Definition: sch_line.h:333
VECTOR2I m_end
Line end point.
Definition: sch_line.h:325
PLOT_DASH_TYPE m_lastResolvedLineStyle
Definition: sch_line.h:332
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:134
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, 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:571
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:256
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:263
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:155
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:327
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:323
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:796
bool IsConnectable() const override
Definition: sch_line.cpp:612
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:356
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:741
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:326
wxString GetNetname(const SCH_SHEET_PATH &aSheet)
This function travel though all the connected wire segments to look for connected labels.
Definition: sch_line.cpp:90
bool IsEndPoint(const VECTOR2I &aPoint) const
Definition: sch_line.h:92
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:819
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:919
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:237
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:145
double GetLength() const
Definition: sch_line.cpp:207
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:272
wxString FindWireSegmentNetNameRecursive(SCH_LINE *line, std::list< const SCH_LINE * > &checkedLines, const SCH_SHEET_PATH &aSheet) const
Recursively called function to travel through the connected wires and find a connected net name label...
Definition: sch_line.cpp:97
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:144
bool IsJunction(const VECTOR2I &aPosition) const
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:419
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
int GetWidth() const
Definition: stroke_params.h:98
void SetWidth(int aWidth)
Definition: stroke_params.h:99
void SetColor(const KIGFX::COLOR4D &aColor)
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
static void Stroke(const SHAPE *aShape, PLOT_DASH_TYPE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, std::function< void(const VECTOR2I &a, const VECTOR2I &b)> aStroker)
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
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:414
#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.
E_SERIE r
Definition: eserie.cpp:41
void GRLine(wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:162
@ LAYER_DANGLING
Definition: layer_ids.h:368
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_BUS
Definition: layer_ids.h:345
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
Definition: eda_units.cpp:98
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
@ BUS_END
Definition: sch_item.h:66
@ PIN_END
Definition: sch_item.h:68
@ BUS_ENTRY_END
Definition: sch_item.h:70
@ WIRE_END
Definition: sch_item.h:65
wxString UnescapeString(const wxString &aSource)
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
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:129
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
double GetLineLength(const VECTOR2I &aPointA, const VECTOR2I &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:188
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:154
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:157
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:144
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_JUNCTION_T
Definition: typeinfo.h:142
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618