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