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-2020 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 <fctsys.h>
26 #include <sch_painter.h>
27 #include <plotter.h>
28 #include <sch_line.h>
29 #include <sch_edit_frame.h>
31 #include <netlist_object.h>
32 #include <schematic.h>
33 #include <project/project_file.h>
34 #include <project/net_settings.h>
35 
36 
37 SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
39 {
40  m_start = pos;
41  m_end = pos;
43  m_stroke.SetWidth( 0 );
45  m_stroke.SetColor( COLOR4D::UNSPECIFIED );
46 
47  switch( layer )
48  {
49  default: m_Layer = LAYER_NOTES; break;
50  case LAYER_WIRE: m_Layer = LAYER_WIRE; break;
51  case LAYER_BUS: m_Layer = LAYER_BUS; break;
52  }
53 }
54 
55 
56 SCH_LINE::SCH_LINE( const SCH_LINE& aLine ) :
57  SCH_ITEM( aLine )
58 {
59  m_start = aLine.m_start;
60  m_end = aLine.m_end;
61  m_stroke = aLine.m_stroke;
64 }
65 
66 
68 {
69  return new SCH_LINE( *this );
70 }
71 
72 
73 /*
74  * Conversion between PLOT_DASH_TYPE values and style names displayed
75  */
76 const std::map<PLOT_DASH_TYPE, const char*> lineStyleNames{
77  { PLOT_DASH_TYPE::SOLID, "solid" },
78  { PLOT_DASH_TYPE::DASH, "dashed" },
79  { PLOT_DASH_TYPE::DASHDOT, "dash_dot" },
80  { PLOT_DASH_TYPE::DOT, "dotted" },
81 };
82 
83 
85 {
86  auto resultIt = lineStyleNames.find( aStyle );
87 
88  //legacy behavior is to default to dash if there is no name
89  return resultIt == lineStyleNames.end() ? lineStyleNames.find( PLOT_DASH_TYPE::DASH )->second :
90  resultIt->second;
91 }
92 
93 
94 PLOT_DASH_TYPE SCH_LINE::GetLineStyleByName( const wxString& aStyleName )
95 {
96  PLOT_DASH_TYPE id = PLOT_DASH_TYPE::DEFAULT; // Default style id
97 
98  //find the name by value
99  auto resultIt = std::find_if( lineStyleNames.begin(), lineStyleNames.end(),
100  [aStyleName]( const auto& it ) { return it.second == aStyleName; } );
101 
102  if( resultIt != lineStyleNames.end() )
103  id = resultIt->first;
104 
105  return id;
106 }
107 
108 
109 void SCH_LINE::Move( const wxPoint& aOffset )
110 {
111  if( aOffset != wxPoint( 0, 0 ) )
112  {
113  m_start += aOffset;
114  m_end += aOffset;
115  SetModified();
116  }
117 }
118 
119 
120 void SCH_LINE::MoveStart( const wxPoint& aOffset )
121 {
122  if( aOffset != wxPoint( 0, 0 ) )
123  {
124  m_start += aOffset;
125  SetModified();
126  }
127 }
128 
129 
130 void SCH_LINE::MoveEnd( const wxPoint& aOffset )
131 {
132  if( aOffset != wxPoint( 0, 0 ) )
133  {
134  m_end += aOffset;
135  SetModified();
136  }
137 }
138 
139 
140 #if defined(DEBUG)
141 
142 void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
143 {
144  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
145  << " layer=\"" << m_Layer << '"'
146  << " startIsDangling=\"" << m_startIsDangling
147  << '"' << " endIsDangling=\""
148  << m_endIsDangling << '"' << ">"
149  << " <start" << m_start << "/>"
150  << " <end" << m_end << "/>" << "</"
151  << GetClass().Lower().mb_str() << ">\n";
152 }
153 
154 #endif
155 
156 
157 void SCH_LINE::ViewGetLayers( int aLayers[], int& aCount ) const
158 {
159  aCount = 2;
160  aLayers[0] = m_Layer;
161  aLayers[1] = LAYER_SELECTION_SHADOWS;
162 }
163 
164 
166 {
167  int width = m_stroke.GetWidth() / 2;
168  int extra = m_stroke.GetWidth() & 0x1;
169 
170  int xmin = std::min( m_start.x, m_end.x ) - width;
171  int ymin = std::min( m_start.y, m_end.y ) - width;
172 
173  int xmax = std::max( m_start.x, m_end.x ) + width + extra;
174  int ymax = std::max( m_start.y, m_end.y ) + width + extra;
175 
176  EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin, ymax - ymin ) );
177 
178  return ret;
179 }
180 
181 
182 double SCH_LINE::GetLength() const
183 {
184  return GetLineLength( m_start, m_end );
185 }
186 
187 
188 void SCH_LINE::SetLineColor( const COLOR4D& aColor )
189 {
190  m_stroke.SetColor( aColor );
191 }
192 
193 
194 void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
195 {
196  COLOR4D newColor(r, g, b, a);
197 
198  if( newColor == COLOR4D::UNSPECIFIED )
199  m_stroke.SetColor( COLOR4D::UNSPECIFIED );
200  else
201  {
202  // Eeschema does not allow alpha channel in colors
203  newColor.a = 1.0;
204  m_stroke.SetColor( newColor );
205  }
206 }
207 
208 
210 {
211  NETCLASSPTR netclass = NetClass();
212 
213  if( netclass && netclass->GetSchematicColor() != COLOR4D::UNSPECIFIED )
214  return netclass->GetSchematicColor();
215 
216  return m_stroke.GetColor();
217 }
218 
219 
221 {
222  if( IsGraphicLine() )
223  return PLOT_DASH_TYPE::DASH;
224 
225  return PLOT_DASH_TYPE::SOLID;
226 }
227 
228 
229 void SCH_LINE::SetLineStyle( const int aStyleId )
230 {
231  SetLineStyle( static_cast<PLOT_DASH_TYPE>( aStyleId ) );
232 }
233 
234 
236 {
237  if( aStyle == GetDefaultStyle() )
239  else
240  m_stroke.SetType( aStyle );
241 }
242 
243 
245 {
247  return m_stroke.GetType();
248 
249  return GetDefaultStyle();
250 }
251 
252 
254 {
255  NETCLASSPTR netclass = NetClass();
256 
257  if( netclass )
258  return (PLOT_DASH_TYPE) netclass->GetLineStyle();
259 
260  return GetLineStyle();
261 }
262 
263 
264 void SCH_LINE::SetLineWidth( const int aSize )
265 {
266  m_stroke.SetWidth( aSize );
267 }
268 
269 
271 {
272  NETCLASSPTR netclass = NetClass();
273 
274  if( netclass )
275  return ( m_Layer == LAYER_BUS ) ? netclass->GetBusWidth() : netclass->GetWireWidth();
276 
277  if( m_stroke.GetWidth() == 0 && Schematic() )
278  return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
279 
280  return std::max( m_stroke.GetWidth(), 1 );
281 }
282 
283 
284 void SCH_LINE::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset )
285 {
286  wxDC* DC = aSettings->GetPrintDC();
288 
289  if( color == COLOR4D::UNSPECIFIED )
290  color = aSettings->GetLayerColor( GetLayer() );
291 
292  wxPoint start = m_start;
293  wxPoint end = m_end;
294  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
295 
296  GRLine( nullptr, DC, start.x, start.y, end.x, end.y, penWidth, color,
298 }
299 
300 
301 void SCH_LINE::MirrorX( int aXaxis_position )
302 {
303  MIRROR( m_start.y, aXaxis_position );
304  MIRROR( m_end.y, aXaxis_position );
305 }
306 
307 
308 void SCH_LINE::MirrorY( int aYaxis_position )
309 {
310  MIRROR( m_start.x, aYaxis_position );
311  MIRROR( m_end.x, aYaxis_position );
312 }
313 
314 
315 void SCH_LINE::Rotate( wxPoint aPosition )
316 {
317  RotatePoint( &m_start, aPosition, 900 );
318  RotatePoint( &m_end, aPosition, 900 );
319 }
320 
321 
323 {
324  RotatePoint( &m_start, aPosition, 900 );
325 }
326 
327 
328 void SCH_LINE::RotateEnd( wxPoint aPosition )
329 {
330  RotatePoint( &m_end, aPosition, 900 );
331 }
332 
333 
334 bool SCH_LINE::IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition )
335 {
336  wxPoint first;
337  wxPoint second;
338 
339  if( m_start == aPosition )
340  first = m_end - aPosition;
341  else if( m_end == aPosition )
342  first = m_start - aPosition;
343  else
344  return false;
345 
346  if( aLine->m_start == aPosition )
347  second = aLine->m_end - aPosition;
348  else if( aLine->m_end == aPosition )
349  second = aLine->m_start - aPosition;
350  else
351  return false;
352 
353  return ( sign( first.x ) == sign( second.x ) && sign( first.y ) == sign( second.y ) );
354 }
355 
356 
358 {
359  wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false,
360  wxT( "Cannot test line segment for overlap." ) );
361 
362  wxPoint firstSeg = m_end - m_start;
363  wxPoint secondSeg = aLine->m_end - aLine->m_start;
364 
365  // Use long long here to avoid overflow in calculations
366  return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
367 }
368 
369 
371 {
372  auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool
373  {
374  if( lhs.x == rhs.x )
375  return lhs.y < rhs.y;
376  return lhs.x < rhs.x;
377  };
378 
379  wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, NULL,
380  wxT( "Cannot test line segment for overlap." ) );
381 
382  if( this == aLine || GetLayer() != aLine->GetLayer() )
383  return nullptr;
384 
385  auto leftmost_start = aLine->m_start;
386  auto leftmost_end = aLine->m_end;
387 
388  auto rightmost_start = m_start;
389  auto rightmost_end = m_end;
390 
391  // We place the start to the left and below the end of both lines
392  if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
393  std::swap( leftmost_start, leftmost_end );
394  if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
395  std::swap( rightmost_start, rightmost_end );
396 
397  // -leftmost is the line that starts farthest to the left
398  // -other is the line that is _not_ leftmost
399  // -rightmost is the line that ends farthest to the right. This may or
400  // may not be 'other' as the second line may be completely covered by
401  // the first.
402  if( less( rightmost_start, leftmost_start ) )
403  {
404  std::swap( leftmost_start, rightmost_start );
405  std::swap( leftmost_end, rightmost_end );
406  }
407 
408  auto other_start = rightmost_start;
409  auto other_end = rightmost_end;
410 
411  if( less( rightmost_end, leftmost_end ) )
412  {
413  rightmost_start = leftmost_start;
414  rightmost_end = leftmost_end;
415  }
416 
417  // If we end one before the beginning of the other, no overlap is possible
418  if( less( leftmost_end, other_start ) )
419  {
420  return nullptr;
421  }
422 
423  // Search for a common end:
424  if( ( leftmost_start == other_start ) && ( leftmost_end == other_end ) ) // Trivial case
425  {
426  auto ret = new SCH_LINE( *aLine );
427  ret->SetStartPoint( leftmost_start );
428  ret->SetEndPoint( leftmost_end );
429 
430  if( IsSelected() || aLine->IsSelected() )
431  ret->SetSelected();
432 
433  return ret;
434  }
435 
436  bool colinear = false;
437 
438  /* Test alignment: */
439  if( ( leftmost_start.y == leftmost_end.y ) &&
440  ( other_start.y == other_end.y ) ) // Horizontal segment
441  {
442  colinear = ( leftmost_start.y == other_start.y );
443  }
444  else if( ( leftmost_start.x == leftmost_end.x ) &&
445  ( other_start.x == other_end.x ) ) // Vertical segment
446  {
447  colinear = ( leftmost_start.x == other_start.x );
448  }
449  else
450  {
451  // We use long long here to avoid overflow -- it enforces promotion
452  // Don't use double as we need to make a direct comparison
453  // The slope of the left-most line is dy/dx. Then we check that the slope
454  // from the left most start to the right most start is the same as well as
455  // the slope from the left most start to right most end.
456  long long dx = leftmost_end.x - leftmost_start.x;
457  long long dy = leftmost_end.y - leftmost_start.y;
458  colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
459  ( other_start.x - leftmost_start.x ) * dy ) &&
460  ( ( other_end.y - leftmost_start.y ) * dx ==
461  ( other_end.x - leftmost_start.x ) * dy ) );
462  }
463 
464  // Make a new segment that merges the 2 segments
465  if( colinear )
466  {
467  leftmost_end = rightmost_end;
468 
469  auto ret = new SCH_LINE( *aLine );
470  ret->SetStartPoint( leftmost_start );
471  ret->SetEndPoint( leftmost_end );
472 
473  if( IsSelected() || aLine->IsSelected() )
474  ret->SetSelected();
475 
476  return ret;
477  }
478 
479  return nullptr;
480 }
481 
482 
483 void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
484 {
485  if( IsGraphicLine() )
486  return;
487 
488  if( ( GetLayer() == LAYER_BUS ) || ( GetLayer() == LAYER_WIRE ) )
489  {
491  m_start );
492  aItemList.push_back( item );
493 
495  m_end );
496  aItemList.push_back( item1 );
497  }
498 }
499 
500 
501 bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
502  const SCH_SHEET_PATH* aPath )
503 {
504  bool previousStartState = m_startIsDangling;
505  bool previousEndState = m_endIsDangling;
506 
508 
509  if( GetLayer() == LAYER_WIRE )
510  {
511  for( DANGLING_END_ITEM item : aItemList )
512  {
513  if( item.GetItem() == this )
514  continue;
515 
516  if( item.GetType() == BUS_START_END ||
517  item.GetType() == BUS_END_END ||
518  item.GetType() == BUS_ENTRY_END )
519  continue;
520 
521  if( m_start == item.GetPosition() )
522  m_startIsDangling = false;
523 
524  if( m_end == item.GetPosition() )
525  m_endIsDangling = false;
526 
528  break;
529  }
530  }
531  else if( GetLayer() == LAYER_BUS || IsGraphicLine() )
532  {
533  // Lines on the notes layer and the bus layer cannot be tested for dangling ends.
534  previousStartState = previousEndState = m_startIsDangling = m_endIsDangling = false;
535  }
536 
537  return ( previousStartState != m_startIsDangling ) || ( previousEndState != m_endIsDangling );
538 }
539 
540 
542 {
543  if( m_Layer == LAYER_WIRE || m_Layer == LAYER_BUS )
544  return true;
545 
546  return false;
547 }
548 
549 
550 bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
551 {
552  switch( aItem->Type() )
553  {
554  case SCH_JUNCTION_T:
555  case SCH_NO_CONNECT_T:
556  case SCH_LABEL_T:
557  case SCH_GLOBAL_LABEL_T:
558  case SCH_HIER_LABEL_T:
560  case SCH_COMPONENT_T:
561  case SCH_SHEET_T:
562  case SCH_SHEET_PIN_T:
563  return true;
564 
565  default:
566  return aItem->GetLayer() == m_Layer;
567  }
568 }
569 
570 
571 void SCH_LINE::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
572 {
573  aPoints.push_back( m_start );
574  aPoints.push_back( m_end );
575 }
576 
577 
578 void SCH_LINE::GetSelectedPoints( std::vector< wxPoint >& aPoints ) const
579 {
580  if( m_Flags & STARTPOINT )
581  aPoints.push_back( m_start );
582 
583  if( m_Flags & ENDPOINT )
584  aPoints.push_back( m_end );
585 }
586 
587 
588 wxString SCH_LINE::GetSelectMenuText( EDA_UNITS aUnits ) const
589 {
590  wxString txtfmt, orient;
591 
592  if( m_start.x == m_end.x )
593  orient = _( "Vertical" );
594  else if( m_start.y == m_end.y )
595  orient = _( "Horizontal" );
596 
597  switch( m_Layer )
598  {
599  case LAYER_NOTES: txtfmt = _( "%s Graphic Line from (%s, %s) to (%s, %s)" ); break;
600  case LAYER_WIRE: txtfmt = _( "%s Wire from (%s, %s) to (%s, %s)" ); break;
601  case LAYER_BUS: txtfmt = _( "%s Bus from (%s, %s) to (%s, %s)" ); break;
602  default: txtfmt = _( "%s Line on Unknown Layer from (%s, %s) to (%s, %s)" ); break;
603  }
604 
605  return wxString::Format( txtfmt,
606  orient,
607  MessageTextFromValue( aUnits, m_start.x ),
608  MessageTextFromValue( aUnits, m_start.y ),
609  MessageTextFromValue( aUnits, m_end.x ),
610  MessageTextFromValue( aUnits, m_end.y ) );
611 }
612 
613 
615 {
616  if( m_Layer == LAYER_NOTES )
617  return add_dashed_line_xpm;
618  else if( m_Layer == LAYER_WIRE )
619  return add_line_xpm;
620 
621  return add_bus_xpm;
622 }
623 
624 
626  SCH_SHEET_PATH* aSheetPath )
627 {
628  // Net list item not required for graphic lines.
629  if( IsGraphicLine() )
630  return;
631 
632  NETLIST_OBJECT* item = new NETLIST_OBJECT();
633  item->m_SheetPath = *aSheetPath;
634  item->m_SheetPathInclude = *aSheetPath;
635  item->m_Comp = (SCH_ITEM*) this;
636  item->m_Start = m_start;
637  item->m_End = m_end;
638 
639  if( GetLayer() == LAYER_BUS )
640  {
641  item->m_Type = NETLIST_ITEM::BUS;
642  }
643  else /* WIRE */
644  {
646  }
647 
648  aNetListItems.push_back( item );
649 }
650 
651 
652 bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
653 {
654  if( Type() != aItem.Type() )
655  return Type() < aItem.Type();
656 
657  auto line = static_cast<const SCH_LINE*>( &aItem );
658 
659  if( GetLayer() != line->GetLayer() )
660  return GetLayer() < line->GetLayer();
661 
662  if( GetStartPoint().x != line->GetStartPoint().x )
663  return GetStartPoint().x < line->GetStartPoint().x;
664 
665  if( GetStartPoint().y != line->GetStartPoint().y )
666  return GetStartPoint().y < line->GetStartPoint().y;
667 
668  if( GetEndPoint().x != line->GetEndPoint().x )
669  return GetEndPoint().x < line->GetEndPoint().x;
670 
671  return GetEndPoint().y < line->GetEndPoint().y;
672 }
673 
674 
675 bool SCH_LINE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
676 {
677  // Performance enhancement for connection-building
678  if( aPosition == m_start || aPosition == m_end )
679  return true;
680 
681  // Insure minimum accuracy
682  if( aAccuracy == 0 )
683  aAccuracy = ( GetPenWidth() / 2 ) + 4;
684 
685  return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
686 }
687 
688 
689 bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
690 {
691  if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
692  return false;
693 
694  EDA_RECT rect = aRect;
695 
696  if ( aAccuracy )
697  rect.Inflate( aAccuracy );
698 
699  if( aContained )
700  return rect.Contains( m_start ) && rect.Contains( m_end );
701 
702  return rect.Intersects( m_start, m_end );
703 }
704 
705 
707 {
708  SCH_LINE* item = (SCH_LINE*) aItem;
709 
710  std::swap( m_Layer, item->m_Layer );
711 
712  std::swap( m_start, item->m_start );
713  std::swap( m_end, item->m_end );
714  std::swap( m_startIsDangling, item->m_startIsDangling );
715  std::swap( m_endIsDangling, item->m_endIsDangling );
716  std::swap( m_stroke, item->m_stroke );
717 }
718 
719 
720 bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const
721 {
722  if( m_Layer != LAYER_WIRE && m_Layer != LAYER_BUS )
723  return false;
724 
725  return IsEndPoint( aPosition );
726 }
727 
728 
729 void SCH_LINE::Plot( PLOTTER* aPlotter )
730 {
731  auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
732  int penWidth;
734 
735  if( color == COLOR4D::UNSPECIFIED )
736  color = settings->GetLayerColor( GetLayer() );
737 
738  aPlotter->SetColor( color );
739 
740  switch( m_Layer )
741  {
742  case LAYER_WIRE: penWidth = settings->m_DefaultWireThickness; break;
743  case LAYER_BUS: penWidth = settings->m_DefaultBusThickness; break;
744  default: penWidth = GetPenWidth(); break;
745  }
746 
747  penWidth = std::max( penWidth, aPlotter->RenderSettings()->GetDefaultPenWidth() );
748 
749  if( m_stroke.GetWidth() != 0 )
750  penWidth = m_stroke.GetWidth();
751 
752  aPlotter->SetCurrentLineWidth( penWidth );
753  aPlotter->SetDash( GetEffectiveLineStyle() );
754 
755  aPlotter->MoveTo( m_start );
756  aPlotter->FinishTo( m_end );
757 
758  aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
759 }
760 
761 
762 void SCH_LINE::SetPosition( const wxPoint& aPosition )
763 {
764  m_end = m_end - ( m_start - aPosition );
765  m_start = aPosition;
766 }
767 
768 
770 {
771  wxString msg;
772 
773  switch( GetLayer() )
774  {
775  case LAYER_WIRE: msg = _( "Wire" ); break;
776  case LAYER_BUS: msg = _( "Bus" ); break;
777  default: msg = _( "Graphical" ); break;
778  }
779 
780  aList.push_back( MSG_PANEL_ITEM( _( "Line Type" ), msg, DARKCYAN ) );
781 
783  msg = _( "from netclass" );
784  else
785  msg = GetLineStyleName( GetLineStyle() );
786 
787  aList.push_back( MSG_PANEL_ITEM( _( "Line Style" ), msg, DARKCYAN ) );
788 
789  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
790 
791  if( frame )
792  {
793  if( SCH_CONNECTION* conn = Connection( frame->GetCurrentSheet() ) )
794  {
795  conn->AppendInfoToMsgPanel( aList );
796 
797  NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
798  const wxString& netname = conn->Name( true );
799 
800  if( netSettings.m_NetClassAssignments.count( netname ) )
801  {
802  const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ];
803  aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName, DARKRED ) );
804  }
805  }
806  }
807 }
808 
809 
811 {
812  return ( GetLayer() == LAYER_NOTES );
813 }
814 
815 
816 bool SCH_LINE::IsWire() const
817 {
818  return ( GetLayer() == LAYER_WIRE );
819 }
820 
821 
823 {
824  return m_stroke.GetWidth() == 0 && m_stroke.GetColor() == COLOR4D::UNSPECIFIED
825  && ( m_stroke.GetType() == GetDefaultStyle()
827 }
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_line.cpp:315
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:571
void FinishTo(const wxPoint &pos)
Definition: plotter.h:267
EDA_UNITS
Definition: common.h:198
SCH_LINE * MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:370
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:483
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:84
int sign(T val)
Definition: util.h:101
SCH_LAYER_ID m_Layer
Definition: sch_item.h:192
void SetModified()
Definition: base_struct.cpp:87
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:43
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:209
void SetWidth(int aWidth)
Definition: sch_item.h:170
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_line.h:64
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:810
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:206
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BITMAP_OPAQUE add_dashed_line_xpm[1]
wxPoint GetStartPoint() const
Definition: sch_line.h:94
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
bool IsWire() const
Returns true if the line is a wire.
Definition: sch_line.cpp:816
bool IsSelected() const
Definition: base_struct.h:203
SCH_SHEET_PATH m_SheetPathInclude
virtual void SetColor(COLOR4D color)=0
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:40
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:264
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:328
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:120
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:138
bool IsParallel(SCH_LINE *aLine)
Definition: sch_line.cpp:357
int color
Definition: DXF_plotter.cpp:61
void SetType(PLOT_DASH_TYPE aType)
Definition: sch_item.h:173
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:116
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:729
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_line.cpp:769
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH m_SheetPath
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:550
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
The base class for create windows for drawing purpose.
EDA_ITEM * m_Comp
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:157
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_line.cpp:588
bool Contains(const wxPoint &aPoint) const
Function Contains.
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_line.cpp:675
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:322
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:822
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:109
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:175
bool IsConnectable() const override
Definition: sch_line.cpp:541
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:220
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:235
double a
Alpha component.
Definition: color4d.h:369
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_line.cpp:301
#define NULL
const std::map< PLOT_DASH_TYPE, const char * > lineStyleNames
Definition: sch_line.cpp:76
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_line.cpp:614
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:244
NETCLASSPTR NetClass() const
Definition: sch_item.cpp:160
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:129
const BITMAP_OPAQUE add_line_xpm[1]
Definition: add_line.cpp:30
double GetLength() const
Definition: sch_line.cpp:182
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:39
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:126
int GetPenWidth() const override
Definition: sch_line.cpp:270
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:188
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:87
int GetWidth() const
Definition: sch_item.h:169
SCH_SHEET_PATH.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:232
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:720
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:578
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:94
wxPoint m_end
Line end point.
Definition: sch_line.h:42
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:706
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:150
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:43
PLOT_DASH_TYPE
Enum for choosing dashed line type.
Definition: plotter.h:87
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
void MoveTo(const wxPoint &pos)
Definition: plotter.h:257
bool IsSameQuadrant(SCH_LINE *aLine, const wxPoint &aPosition)
Check if two lines are in the same quadrant as each other, using a reference point as the origin.
Definition: sch_line.cpp:334
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:124
Base plotter engine class.
Definition: plotter.h:114
COLOR4D GetColor() const
Definition: sch_item.h:175
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:253
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:67
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:130
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:652
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
#define _(s)
Definition: 3d_actions.cpp:33
STATUS_FLAGS m_Flags
Definition: base_struct.h:176
#define ENDPOINT
ends. (Used to support dragging.)
Definition: base_struct.h:123
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
PLOT_DASH_TYPE GetType() const
Definition: sch_item.h:172
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
const BITMAP_OPAQUE add_bus_xpm[1]
Definition: add_bus.cpp:30
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:284
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_line.cpp:308
int GetDefaultPenWidth() const
SCH_SHEET_PATH & GetCurrentSheet() const
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:176
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:501
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_line.cpp:165
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:85
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void SetPosition(const wxPoint &aPosition) override
Set the schematic item position to aPosition.
Definition: sch_line.cpp:762
Definition of the NETLIST_OBJECT class.
NETLIST_ITEM m_Type
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
wxPoint m_start
Line start point.
Definition: sch_line.h:41
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:37
wxPenStyle GetwxPenStyle(PLOT_DASH_TYPE aType)
Convert KiCad line plot styles to wxWidgets device context styles.
Definition: plotter.cpp:599
virtual void SetDash(PLOT_DASH_TYPE dashed)=0
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: base_struct.h:122
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Create a new NETLIST_OBJECT for the schematic object and adds it to aNetListItems.
Definition: sch_line.cpp:625
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
wxPoint GetEndPoint() const
Definition: sch_line.h:97