KiCad PCB EDA Suite
sch_text.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <sch_component.h>
33 #include <sch_edit_frame.h>
34 #include <plotter.h>
35 #include <msgpanel.h>
36 #include <gal/stroke_font.h>
37 #include <bitmaps.h>
38 #include <sch_text.h>
39 #include <schematic.h>
40 #include <netlist_object.h>
42 #include <sch_painter.h>
43 #include <default_values.h>
44 #include <wx/debug.h>
45 #include <html_messagebox.h>
46 #include <project/project_file.h>
47 #include <project/net_settings.h>
48 
50 
51 
52 void IncrementLabelMember( wxString& name, int aIncrement )
53 {
54  int ii, nn;
55  long number = 0;
56 
57  ii = name.Len() - 1; nn = 0;
58 
59  if( !wxIsdigit( name.GetChar( ii ) ) )
60  return;
61 
62  while( ii >= 0 && wxIsdigit( name.GetChar( ii ) ) )
63  {
64  ii--;
65  nn++;
66  }
67 
68  ii++; /* digits are starting at ii position */
69  wxString litt_number = name.Right( nn );
70 
71  if( litt_number.ToLong( &number ) )
72  {
73  number += aIncrement;
74  name.Remove( ii ); name << number;
75  }
76 }
77 
78 
79 /* Coding polygons for global symbol graphic shapes.
80  * the first parml is the number of corners
81  * others are the corners coordinates in reduced units
82  * the real coordinate is the reduced coordinate * text half size
83  */
84 static int TemplateIN_HN[] = { 6, 0, 0, -1, -1, -2, -1, -2, 1, -1, 1, 0, 0 };
85 static int TemplateIN_HI[] = { 6, 0, 0, 1, 1, 2, 1, 2, -1, 1, -1, 0, 0 };
86 static int TemplateIN_UP[] = { 6, 0, 0, 1, -1, 1, -2, -1, -2, -1, -1, 0, 0 };
87 static int TemplateIN_BOTTOM[] = { 6, 0, 0, 1, 1, 1, 2, -1, 2, -1, 1, 0, 0 };
88 
89 static int TemplateOUT_HN[] = { 6, -2, 0, -1, 1, 0, 1, 0, -1, -1, -1, -2, 0 };
90 static int TemplateOUT_HI[] = { 6, 2, 0, 1, -1, 0, -1, 0, 1, 1, 1, 2, 0 };
91 static int TemplateOUT_UP[] = { 6, 0, -2, 1, -1, 1, 0, -1, 0, -1, -1, 0, -2 };
92 static int TemplateOUT_BOTTOM[] = { 6, 0, 2, 1, 1, 1, 0, -1, 0, -1, 1, 0, 2 };
93 
94 static int TemplateUNSPC_HN[] = { 5, 0, -1, -2, -1, -2, 1, 0, 1, 0, -1 };
95 static int TemplateUNSPC_HI[] = { 5, 0, -1, 2, -1, 2, 1, 0, 1, 0, -1 };
96 static int TemplateUNSPC_UP[] = { 5, 1, 0, 1, -2, -1, -2, -1, 0, 1, 0 };
97 static int TemplateUNSPC_BOTTOM[] = { 5, 1, 0, 1, 2, -1, 2, -1, 0, 1, 0 };
98 
99 static int TemplateBIDI_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
100 static int TemplateBIDI_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
101 static int TemplateBIDI_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
102 static int TemplateBIDI_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
103 
104 static int Template3STATE_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
105 static int Template3STATE_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
106 static int Template3STATE_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
107 static int Template3STATE_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
108 
109 static int* TemplateShape[5][4] =
110 {
116 };
117 
118 
119 SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
120  SCH_ITEM( NULL, aType ),
121  EDA_TEXT( text ),
122  m_shape( PINSHEETLABEL_SHAPE::PS_INPUT ),
123  m_isDangling( false ),
124  m_connectionType( CONNECTION_TYPE::NONE ),
125  m_spin_style( LABEL_SPIN_STYLE::LEFT )
126 {
128 
129  SetTextPos( pos );
130  SetMultilineAllowed( true );
131 }
132 
133 
134 SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
135  SCH_ITEM( aText ),
136  EDA_TEXT( aText ),
137  m_shape( aText.m_shape ),
138  m_isDangling( aText.m_isDangling ),
139  m_connectionType( aText.m_connectionType ),
140  m_spin_style( aText.m_spin_style )
141 { }
142 
143 
145 {
146  return new SCH_TEXT( *this );
147 }
148 
149 
150 void SCH_TEXT::IncrementLabel( int aIncrement )
151 {
152  wxString text = GetText();
153  IncrementLabelMember( text, aIncrement );
154  SetText(text );
155 }
156 
157 
159 {
160  wxPoint text_offset;
161 
162  // add an offset to x (or y) position to aid readability of text on a wire or line
163  int dist = GetTextOffset( aSettings ) + GetPenWidth();
164 
165  switch( GetLabelSpinStyle() )
166  {
169  text_offset.x = -dist;
170  break; // Vert Orientation
171  default:
174  text_offset.y = -dist;
175  break; // Horiz Orientation
176  }
177 
178  return text_offset;
179 }
180 
181 
182 void SCH_TEXT::MirrorY( int aYaxis_position )
183 {
184  // Text is NOT really mirrored; it is moved to a suitable horizontal position
186 
187  SetTextX( Mirror( GetTextPos().x, aYaxis_position ) );
188 }
189 
190 
191 void SCH_TEXT::MirrorX( int aXaxis_position )
192 {
193  // Text is NOT really mirrored; it is moved to a suitable vertical position
195 
196  SetTextY( Mirror( GetTextPos().y, aXaxis_position ) );
197 }
198 
199 
200 void SCH_TEXT::Rotate( wxPoint aPosition )
201 {
202  wxPoint pt = GetTextPos();
203  RotatePoint( &pt, aPosition, 900 );
204  SetTextPos( pt );
205 
206  SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
207 
208  if( this->Type() == SCH_TEXT_T )
209  {
210  int dy = 0;
211 
212  switch( GetLabelSpinStyle() )
213  {
216  dy = GetTextHeight();
217  break;
220  default:
221  dy = 0;
222  break;
223  }
224 
225  SetTextY( GetTextPos().y + dy );
226  }
227 }
228 
229 
231 {
232  m_spin_style = aSpinStyle;
233 
234  // Assume "Right" and Left" mean which side of the anchor the text will be on
235  // Thus we want to left justify text up agaisnt the anchor if we are on the right
236  switch( aSpinStyle )
237  {
238  default:
239  wxASSERT_MSG( 1, "Bad spin style" );
240  break;
241 
242  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
243  //
244  m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
248  break;
249 
250  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
254  break;
255 
256  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
260  break;
261 
262  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
266  break;
267  }
268 }
269 
270 
272 {
273  SCH_TEXT* item = (SCH_TEXT*) aItem;
274 
275  std::swap( m_Layer, item->m_Layer );
276 
277  std::swap( m_shape, item->m_shape );
278  std::swap( m_isDangling, item->m_isDangling );
279  std::swap( m_spin_style, item->m_spin_style );
280 
281  SwapText( *item );
282  SwapEffects( *item );
283 }
284 
285 
286 bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
287 {
288  if( Type() != aItem.Type() )
289  return Type() < aItem.Type();
290 
291  auto other = static_cast<const SCH_TEXT*>( &aItem );
292 
293  if( GetLayer() != other->GetLayer() )
294  return GetLayer() < other->GetLayer();
295 
296  if( GetPosition().x != other->GetPosition().x )
297  return GetPosition().x < other->GetPosition().x;
298 
299  if( GetPosition().y != other->GetPosition().y )
300  return GetPosition().y < other->GetPosition().y;
301 
302  return GetText() < other->GetText();
303 }
304 
305 
307 {
308  SCH_RENDER_SETTINGS* renderSettings = static_cast<SCH_RENDER_SETTINGS*>( aSettings );
309 
310  if( renderSettings )
311  return KiROUND( renderSettings->m_TextOffsetRatio * GetTextSize().y );
312 
313  return 0;
314 }
315 
316 
318 {
319  return GetEffectiveTextPenWidth();
320 }
321 
322 
323 void SCH_TEXT::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
324 {
325  COLOR4D color = aSettings->GetLayerColor( m_Layer );
326  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
327 
328  EDA_TEXT::Print( aSettings, text_offset, color );
329 }
330 
331 
332 void SCH_TEXT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
333 {
334  // Normal text labels cannot be tested for dangling ends.
335  if( Type() == SCH_TEXT_T )
336  return;
337 
338  DANGLING_END_ITEM item( LABEL_END, this, GetTextPos() );
339  aItemList.push_back( item );
340 }
341 
342 
343 bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
344  const SCH_SHEET_PATH* aPath )
345 {
346  // Normal text labels cannot be tested for dangling ends.
347  if( Type() == SCH_TEXT_T )
348  return false;
349 
350  bool previousState = m_isDangling;
351  m_isDangling = true;
353 
354  for( unsigned ii = 0; ii < aItemList.size(); ii++ )
355  {
356  DANGLING_END_ITEM& item = aItemList[ii];
357 
358  if( item.GetItem() == this )
359  continue;
360 
361  switch( item.GetType() )
362  {
363  case PIN_END:
364  case LABEL_END:
365  case SHEET_LABEL_END:
366  case NO_CONNECT_END:
367  if( GetTextPos() == item.GetPosition() )
368  {
369  m_isDangling = false;
370 
371  if( aPath && item.GetType() != PIN_END )
372  m_connected_items[ *aPath ].insert( static_cast<SCH_ITEM*>( item.GetItem() ) );
373  }
374 
375  break;
376 
377 
378  case BUS_START_END:
381 
382  case WIRE_START_END:
383  {
384  // These schematic items have created 2 DANGLING_END_ITEM one per end. But being
385  // a paranoid programmer, I'll check just in case.
386  ii++;
387 
388  wxCHECK_MSG( ii < aItemList.size(), previousState != m_isDangling,
389  wxT( "Dangling end type list overflow. Bad programmer!" ) );
390 
391  int accuracy = 1; // We have rounding issues with an accuracy of 0
392 
393  DANGLING_END_ITEM & nextItem = aItemList[ii];
395  nextItem.GetPosition(), accuracy );
396 
397  if( !m_isDangling )
398  {
401 
402  // Add the line to the connected items, since it won't be picked
403  // up by a search of intersecting connection points
404  if( aPath )
405  {
406  auto sch_item = static_cast<SCH_ITEM*>( item.GetItem() );
407  AddConnectionTo( *aPath, sch_item );
408  sch_item->AddConnectionTo( *aPath, this );
409  }
410  }
411  }
412  break;
413 
414  default:
415  break;
416  }
417 
418  if( !m_isDangling )
419  break;
420  }
421 
422  if( m_isDangling )
424 
425  return previousState != m_isDangling;
426 }
427 
428 
429 void SCH_TEXT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
430 {
431  // Normal text labels do not have connection points. All others do.
432  if( Type() == SCH_TEXT_T )
433  return;
434 
435  aPoints.push_back( GetTextPos() );
436 }
437 
438 
440 {
441  EDA_RECT rect = GetTextBox();
442 
443  if( GetTextAngle() != 0 ) // Rotate rect
444  {
445  wxPoint pos = rect.GetOrigin();
446  wxPoint end = rect.GetEnd();
447 
448  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
449  RotatePoint( &end, GetTextPos(), GetTextAngle() );
450 
451  rect.SetOrigin( pos );
452  rect.SetEnd( end );
453  }
454 
455  rect.Normalize();
456  return rect;
457 }
458 
459 
461 {
462  switch( aType )
463  {
464  case PINSHEETLABEL_SHAPE::PS_INPUT: return _( "Input" );
465  case PINSHEETLABEL_SHAPE::PS_OUTPUT: return _( "Output" );
466  case PINSHEETLABEL_SHAPE::PS_BIDI: return _( "Bidirectional" );
467  case PINSHEETLABEL_SHAPE::PS_TRISTATE: return _( "Tri-State" );
468  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: return _( "Passive" );
469  default: return wxT( "???" );
470  }
471 }
472 
473 
474 void SCH_TEXT::GetContextualTextVars( wxArrayString* aVars ) const
475 {
477  aVars->push_back( wxT( "CONNECTION_TYPE" ) );
478 
479  if( Type() == SCH_SHEET_PIN_T && m_Parent )
480  static_cast<SCH_SHEET*>( m_Parent )->GetContextualTextVars( aVars );
481 }
482 
483 
484 wxString SCH_TEXT::GetShownText( int aDepth ) const
485 {
486  std::function<bool( wxString* )> textResolver =
487  [&]( wxString* token ) -> bool
488  {
489  if( ( Type() == SCH_GLOBAL_LABEL_T
490  || Type() == SCH_HIER_LABEL_T
491  || Type() == SCH_SHEET_PIN_T )
492  && token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) )
493  {
494  *token = getElectricalTypeLabel( GetShape() );
495  return true;
496  }
497 
498  if( Type() == SCH_SHEET_PIN_T && m_Parent )
499  {
500  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_Parent );
501 
502  if( sheet->ResolveTextVar( token, aDepth ) )
503  return true;
504  }
505 
506  if( Type() == SCH_TEXT_T )
507  {
508  if( token->Contains( ':' ) )
509  {
510  if( Schematic()->ResolveCrossReference( token, aDepth ) )
511  return true;
512  }
513  else
514  {
515  SCHEMATIC* schematic = Schematic();
516  SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
517 
518  if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
519  return true;
520  }
521  }
522 
523  return false;
524  };
525 
526  bool processTextVars = false;
527  wxString text = EDA_TEXT::GetShownText( &processTextVars );
528 
529  if( processTextVars )
530  {
531  wxCHECK_MSG( Schematic(), wxEmptyString,
532  "No parent SCHEMATIC set for SCH_TEXT!" );
533 
534  PROJECT* project = nullptr;
535 
536  if( Schematic() )
537  project = &Schematic()->Prj();
538 
539  if( aDepth < 10 )
540  text = ExpandTextVars( text, &textResolver, project );
541  }
542 
543  return text;
544 }
545 
546 
547 wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
548 {
549  return wxString::Format( _( "Graphic Text \"%s\"" ), GetChars( ShortenedShownText() ) );
550 }
551 
552 
554 {
555  return text_xpm;
556 }
557 
558 
560  SCH_SHEET_PATH* aSheetPath )
561 {
562  if( GetLayer() == LAYER_NOTES || GetLayer() == LAYER_SHEETLABEL )
563  return;
564 
565  NETLIST_OBJECT* item = new NETLIST_OBJECT();
566  item->m_SheetPath = *aSheetPath;
567  item->m_SheetPathInclude = *aSheetPath;
568  item->m_Comp = (SCH_ITEM*) this;
569  item->m_Type = NETLIST_ITEM::LABEL;
570 
571  if( GetLayer() == LAYER_GLOBLABEL )
573  else if( GetLayer() == LAYER_HIERLABEL )
575 
576  item->m_Label = GetText();
577  item->m_Start = item->m_End = GetTextPos();
578 
579  aNetListItems.push_back( item );
580 
581  // If a bus connects to label
583  item->ConvertBusToNetListItems( aNetListItems );
584 }
585 
586 
587 bool SCH_TEXT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
588 {
589  EDA_RECT bBox = GetBoundingBox();
590  bBox.Inflate( aAccuracy );
591  return bBox.Contains( aPosition );
592 }
593 
594 
595 bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
596 {
597  EDA_RECT bBox = GetBoundingBox();
598  bBox.Inflate( aAccuracy );
599 
600  if( aContained )
601  return aRect.Contains( bBox );
602 
603  return aRect.Intersects( bBox );
604 }
605 
606 
607 void SCH_TEXT::Plot( PLOTTER* aPlotter )
608 {
609  static std::vector<wxPoint> Poly;
610  COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() );
611  int penWidth = GetEffectiveTextPenWidth( aPlotter->RenderSettings()->GetDefaultPenWidth() );
612 
613  aPlotter->SetCurrentLineWidth( penWidth );
614 
615  if( IsMultilineAllowed() )
616  {
617  std::vector<wxPoint> positions;
618  wxArrayString strings_list;
619  wxStringSplit( GetShownText(), strings_list, '\n' );
620  positions.reserve( strings_list.Count() );
621 
622  GetLinePositions( positions, (int) strings_list.Count() );
623 
624  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
625  {
626  wxPoint textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
627  wxString& txt = strings_list.Item( ii );
628  aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
629  GetVertJustify(), penWidth, IsItalic(), IsBold() );
630  }
631  }
632  else
633  {
634  wxPoint textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
635 
636  aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
637  GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
638  }
639 
640  // Draw graphic symbol for global or hierarchical labels
641  CreateGraphicShape( aPlotter->RenderSettings(), Poly, GetTextPos() );
642 
643  if( Poly.size() )
644  aPlotter->PlotPoly( Poly, NO_FILL, penWidth );
645 }
646 
647 
649 {
650  wxString msg;
651 
652  switch( Type() )
653  {
654  case SCH_TEXT_T: msg = _( "Graphic Text" ); break;
655  case SCH_LABEL_T: msg = _( "Label" ); break;
656  case SCH_GLOBAL_LABEL_T: msg = _( "Global Label" ); break;
657  case SCH_HIER_LABEL_T: msg = _( "Hierarchical Label" ); break;
658  case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break;
659  default: return;
660  }
661 
662  aList.push_back( MSG_PANEL_ITEM( msg, GetShownText(), DARKCYAN ) );
663 
664  switch( GetLabelSpinStyle() )
665  {
666  case LABEL_SPIN_STYLE::LEFT: msg = _( "Horizontal left" ); break;
667  case LABEL_SPIN_STYLE::UP: msg = _( "Vertical up" ); break;
668  case LABEL_SPIN_STYLE::RIGHT: msg = _( "Horizontal right" ); break;
669  case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Vertical down" ); break;
670  default: msg = wxT( "???" ); break;
671  }
672 
673  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, BROWN ) );
674 
675  wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
676  int style = 0;
677 
678  if( IsItalic() )
679  style = 1;
680 
681  if( IsBold() )
682  style += 2;
683 
684  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), textStyle[style], BROWN ) );
685 
686  // Display electrical type if it is relevant
688  {
689  msg = getElectricalTypeLabel( GetShape() );
690  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, BLUE ) );
691  }
692 
693  // Display text size (X or Y value, with are the same value in Eeschema)
694  msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextWidth(), true );
695  aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg, RED ) );
696 
697  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
698 
699  if( frame )
700  {
701  if( SCH_CONNECTION* conn = Connection( frame->GetCurrentSheet() ) )
702  {
703  conn->AppendInfoToMsgPanel( aList );
704 
705  NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
706  const wxString& netname = conn->Name( true );
707 
708  if( netSettings.m_NetClassAssignments.count( netname ) )
709  {
710  const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ];
711  aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName, DARKRED ) );
712  }
713  }
714  }
715 }
716 
717 #if defined(DEBUG)
718 
719 void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
720 {
721  // XML output:
722  wxString s = GetClass();
723 
724  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
725  << " layer=\"" << m_Layer << '"'
726  << " shape=\"" << static_cast<int>( m_shape ) << '"'
727  << " dangling=\"" << m_isDangling << '"'
728  << '>'
729  << TO_UTF8( GetText() )
730  << "</" << s.Lower().mb_str() << ">\n";
731 }
732 
733 #endif
734 
735 
736 SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text )
737  : SCH_TEXT( pos, text, SCH_LABEL_T )
738 {
741  m_isDangling = true;
742  SetMultilineAllowed( false );
743 }
744 
745 
747 {
748  return new SCH_LABEL( *this );
749 }
750 
751 
752 bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
753 {
754  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
755  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, EOT };
756 
757  if( SCH_ITEM::IsType( aScanTypes ) )
758  return true;
759 
760  wxCHECK_MSG( Schematic(), false, "No parent SCHEMATIC set for SCH_LABEL!" );
761 
762  SCH_SHEET_PATH current = Schematic()->CurrentSheet();
763 
764  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
765  {
766  if( *p == SCH_LABEL_LOCATE_WIRE_T )
767  {
768  wxASSERT( m_connected_items.count( current ) );
769 
770  for( SCH_ITEM* connection : m_connected_items.at( current ) )
771  {
772  if( connection->IsType( wireTypes ) )
773  return true;
774  }
775  }
776  else if ( *p == SCH_LABEL_LOCATE_BUS_T )
777  {
778  wxASSERT( m_connected_items.count( current ) );
779 
780  for( SCH_ITEM* connection : m_connected_items.at( current ) )
781  {
782  if( connection->IsType( busTypes ) )
783  return true;
784  }
785  }
786  }
787 
788  return false;
789 }
790 
791 
793 {
794  EDA_RECT rect = GetTextBox();
795 
796  // In practice this is controlled by the current TextOffsetRatio, but the default is
797  // close enough for hit-testing, etc.
798  int margin = Mils2iu( TXT_MARGIN );
799 
800  rect.Inflate( margin );
801 
802  if( GetTextAngle() != 0.0 )
803  {
804  // Rotate rect
805  wxPoint pos = rect.GetOrigin();
806  wxPoint end = rect.GetEnd();
807 
808  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
809  RotatePoint( &end, GetTextPos(), GetTextAngle() );
810 
811  rect.SetOrigin( pos );
812  rect.SetEnd( end );
813 
814  rect.Normalize();
815  }
816 
817  return rect;
818 }
819 
820 
821 wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
822 {
823  return wxString::Format( _( "Label %s" ), ShortenedShownText() );
824 }
825 
826 
828 {
829  return add_line_label_xpm;
830 }
831 
832 
833 SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text )
834  : SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
835 {
838  m_isDangling = true;
839  SetMultilineAllowed( false );
840 }
841 
842 
844 {
845  return new SCH_GLOBALLABEL( *this );
846 }
847 
848 
850 {
851  wxPoint text_offset;
852  int dist = GetTextOffset( aSettings );
853 
854  switch( m_shape )
855  {
859  dist += GetTextHeight() * 3 / 4; // Use three-quarters-height as proxy for triangle size
860  break;
861 
864  default:
865  break;
866  }
867 
868  switch( GetLabelSpinStyle() )
869  {
870  default:
871  case LABEL_SPIN_STYLE::LEFT: text_offset.x -= dist; break;
872  case LABEL_SPIN_STYLE::UP: text_offset.y -= dist; break;
873  case LABEL_SPIN_STYLE::RIGHT: text_offset.x += dist; break;
874  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y += dist; break;
875  }
876 
877  return text_offset;
878 }
879 
880 
882 {
883  m_spin_style = aSpinStyle;
884 
885  switch( aSpinStyle )
886  {
887  default:
888  wxASSERT_MSG( 1, "Bad spin style" );
889  break;
890 
891  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
892  //
893  m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
897  break;
898 
899  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
903  break;
904 
905  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
909  break;
910 
911  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
915  break;
916  }
917 }
918 
919 
920 void SCH_GLOBALLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
921 {
922  static std::vector <wxPoint> Poly;
923 
924  wxDC* DC = aSettings->GetPrintDC();
925  COLOR4D color = aSettings->GetLayerColor( m_Layer );
926  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
927  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
928 
929  EDA_TEXT::Print( aSettings, text_offset, color );
930 
931  CreateGraphicShape( aSettings, Poly, GetTextPos() + aOffset );
932  GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
933 }
934 
935 
937  std::vector<wxPoint>& aPoints, const wxPoint& Pos )
938 {
939  int margin = GetTextOffset( aRenderSettings );
940  int halfSize = ( GetTextHeight() / 2 ) + margin;
941  int linewidth = GetPenWidth();
942  int symb_len = LenSize( GetShownText(), linewidth ) + 2 * margin;
943 
944  int x = symb_len + linewidth + 3;
945  int y = halfSize + linewidth + 3;
946 
947  aPoints.clear();
948 
949  // Create outline shape : 6 points
950  aPoints.emplace_back( wxPoint( 0, 0 ) );
951  aPoints.emplace_back( wxPoint( 0, -y ) ); // Up
952  aPoints.emplace_back( wxPoint( -x, -y ) ); // left
953  aPoints.emplace_back( wxPoint( -x, 0 ) ); // Up left
954  aPoints.emplace_back( wxPoint( -x, y ) ); // left down
955  aPoints.emplace_back( wxPoint( 0, y ) ); // down
956 
957  int x_offset = 0;
958 
959  switch( m_shape )
960  {
962  x_offset = -halfSize;
963  aPoints[0].x += halfSize;
964  break;
965 
967  aPoints[3].x -= halfSize;
968  break;
969 
972  x_offset = -halfSize;
973  aPoints[0].x += halfSize;
974  aPoints[3].x -= halfSize;
975  break;
976 
978  default:
979  break;
980  }
981 
982  int angle = 0;
983 
984  switch( GetLabelSpinStyle() )
985  {
986  default:
987  case LABEL_SPIN_STYLE::LEFT: break;
988  case LABEL_SPIN_STYLE::UP: angle = -900; break;
989  case LABEL_SPIN_STYLE::RIGHT: angle = 1800; break;
990  case LABEL_SPIN_STYLE::BOTTOM: angle = 900; break;
991  }
992 
993  // Rotate outlines and move corners in real position
994  for( wxPoint& aPoint : aPoints )
995  {
996  aPoint.x += x_offset;
997 
998  if( angle )
999  RotatePoint( &aPoint, angle );
1000 
1001  aPoint += Pos;
1002  }
1003 
1004  aPoints.push_back( aPoints[0] ); // closing
1005 }
1006 
1007 
1009 {
1010  int x = GetTextPos().x;
1011  int y = GetTextPos().y;
1012  int penWidth = GetEffectiveTextPenWidth();
1013 
1014  // In practice this is controlled by the current TextOffsetRatio, but the default is
1015  // close enough for hit-testing, etc.
1016  int margin = Mils2iu( TXT_MARGIN );
1017 
1018  int height = ( (GetTextHeight() * 15) / 10 ) + penWidth + 2 * margin;
1019  int length = LenSize( GetShownText(), penWidth )
1020  + height // add height for triangular shapes
1021  + 2 * margin;
1022 
1023  int dx, dy;
1024 
1025  switch( GetLabelSpinStyle() ) // respect orientation
1026  {
1027  default:
1029  dx = -length;
1030  dy = height;
1031  x += margin;
1032  y -= height / 2;
1033  break;
1034 
1035  case LABEL_SPIN_STYLE::UP:
1036  dx = height;
1037  dy = -length;
1038  x -= height / 2;
1039  y += margin;
1040  break;
1041 
1043  dx = length;
1044  dy = height;
1045  x -= margin;
1046  y -= height / 2;
1047  break;
1048 
1050  dx = height;
1051  dy = length;
1052  x -= height / 2;
1053  y -= margin;
1054  break;
1055  }
1056 
1057  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1058  box.Normalize();
1059  return box;
1060 }
1061 
1062 
1064 {
1065  return wxString::Format( _( "Global Label %s" ), ShortenedShownText() );
1066 }
1067 
1068 
1070 {
1071  return add_glabel_xpm;
1072 }
1073 
1074 
1075 SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType )
1076  : SCH_TEXT( pos, text, aType )
1077 {
1080  m_isDangling = true;
1081  SetMultilineAllowed( false );
1082 }
1083 
1084 
1086 {
1087  return new SCH_HIERLABEL( *this );
1088 }
1089 
1090 
1092 {
1093  m_spin_style = aSpinStyle;
1094 
1095  // Assume "Right" and Left" mean which side of the port symbol the text will be on
1096  // If we are left of the symbol, we want to right justify to line up with the symbol
1097  switch( aSpinStyle )
1098  {
1099  default:
1100  wxLogWarning( "SetLabelSpinStyle bad spin style" );
1101  break;
1102 
1104  //
1105  m_spin_style = LABEL_SPIN_STYLE::LEFT; // Handle the error spin style by resetting
1109  break;
1110 
1111  case LABEL_SPIN_STYLE::UP:
1115  break;
1116 
1121  break;
1122 
1127  break;
1128  }
1129 }
1130 
1131 
1132 void SCH_HIERLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset )
1133 {
1134  wxCHECK_RET( Schematic(), "No parent SCHEMATIC set for SCH_LABEL!" );
1135 
1136  static std::vector <wxPoint> Poly;
1137 
1138  wxDC* DC = aSettings->GetPrintDC();
1139  SCH_CONNECTION* conn = Connection( Schematic()->CurrentSheet() );
1140  bool isBus = conn && conn->IsBus();
1141  COLOR4D color = aSettings->GetLayerColor( isBus ? LAYER_BUS : m_Layer );
1142  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
1143  wxPoint textOffset = offset + GetSchematicTextOffset( aSettings );
1144 
1145  EDA_TEXT::Print( aSettings, textOffset, color );
1146 
1147  CreateGraphicShape( aSettings, Poly, GetTextPos() + offset );
1148  GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
1149 }
1150 
1151 
1153  std::vector<wxPoint>& aPoints, const wxPoint& Pos )
1154 {
1155  int* Template = TemplateShape[static_cast<int>( m_shape )][static_cast<int>( m_spin_style )];
1156  int halfSize = GetTextHeight() / 2;
1157  int imax = *Template;
1158  Template++;
1159 
1160  aPoints.clear();
1161 
1162  for( int ii = 0; ii < imax; ii++ )
1163  {
1164  wxPoint corner;
1165  corner.x = ( halfSize * (*Template) ) + Pos.x;
1166  Template++;
1167 
1168  corner.y = ( halfSize * (*Template) ) + Pos.y;
1169  Template++;
1170 
1171  aPoints.push_back( corner );
1172  }
1173 }
1174 
1175 
1177 {
1178  int penWidth = GetEffectiveTextPenWidth();
1179 
1180  // In practice this is controlled by the current TextOffsetRatio, but the default is
1181  // close enough for hit-testing, etc.
1182  int margin = Mils2iu( TXT_MARGIN );
1183 
1184  int x = GetTextPos().x;
1185  int y = GetTextPos().y;
1186 
1187  int height = GetTextHeight() + penWidth + 2 * margin;
1188  int length = LenSize( GetShownText(), penWidth )
1189  + height // add height for triangular shapes
1190  + 2 * margin;
1191 
1192  int dx, dy;
1193 
1194  switch( GetLabelSpinStyle() )
1195  {
1196  default:
1198  dx = -length;
1199  dy = height;
1200  x += Mils2iu( DANGLING_SYMBOL_SIZE );
1201  y -= height / 2;
1202  break;
1203 
1204  case LABEL_SPIN_STYLE::UP:
1205  dx = height;
1206  dy = -length;
1207  x -= height / 2;
1208  y += Mils2iu( DANGLING_SYMBOL_SIZE );
1209  break;
1210 
1212  dx = length;
1213  dy = height;
1214  x -= Mils2iu( DANGLING_SYMBOL_SIZE );
1215  y -= height / 2;
1216  break;
1217 
1219  dx = height;
1220  dy = length;
1221  x -= height / 2;
1222  y -= Mils2iu( DANGLING_SYMBOL_SIZE );
1223  break;
1224  }
1225 
1226  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1227  box.Normalize();
1228  return box;
1229 }
1230 
1231 
1233 {
1234  wxPoint text_offset;
1235  int dist = GetTextOffset( aSettings );
1236 
1237  dist += GetTextWidth();
1238 
1239  switch( GetLabelSpinStyle() )
1240  {
1241  default:
1242  case LABEL_SPIN_STYLE::LEFT: text_offset.x = -dist; break; // Orientation horiz normale
1243  case LABEL_SPIN_STYLE::UP: text_offset.y = -dist; break; // Orientation vert UP
1244  case LABEL_SPIN_STYLE::RIGHT: text_offset.x = dist; break; // Orientation horiz inverse
1245  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y = dist; break; // Orientation vert BOTTOM
1246  }
1247 
1248  return text_offset;
1249 }
1250 
1251 
1253 {
1254  return wxString::Format( _( "Hierarchical Label %s" ), ShortenedShownText() );
1255 }
1256 
1257 
1259 {
1261 }
1262 
1263 
1264 void SCH_TEXT::ShowSyntaxHelp( wxWindow* aParentWindow )
1265 {
1266  wxString msg = _(
1267  "<table>"
1268  " <tr>"
1269  " <th>Markup</th>"
1270  " <th></th>"
1271  " <th>Result</th>"
1272  " </tr>"
1273  " <tr>"
1274  " <td>&nbsp;<br><samp>^{superscript}</samp></td>"
1275  " <td></td>"
1276  " <td>&nbsp;<br><samp><sup>superscript</sup>&nbsp;</samp></td>"
1277  " </tr>"
1278  " <tr>"
1279  " <td>&nbsp;<br><samp>Driver Board^{Rev A}</samp></td>"
1280  " <td></td>"
1281  " <td>&nbsp;<br><samp>Driver Board<sup>Rev A</sup></samp></td>"
1282  " </tr>"
1283  " <tr><td><br></td></tr>"
1284  " <tr>"
1285  " <td>&nbsp;<br><samp>_{subscript}</samp></td>"
1286  " <td></td>"
1287  " <td>&nbsp;<br><samp><sub>subscript</sub>&nbsp;</samp></td>"
1288  " </tr>"
1289  " <tr>"
1290  " <td>&nbsp;<br><samp>D_{0} - D_{15}</samp></td>"
1291  " <td></td>"
1292  " <td>&nbsp;<br><samp>D<sub>0</sub> - D<sub>31</sub></samp></td>"
1293  " </tr>"
1294  " <tr><td></td></tr>"
1295  " <tr>"
1296  " <td>"
1297  " &nbsp;<br><samp>~overbar</samp><br>"
1298  " &nbsp;<br><samp>~CLK</samp><br>"
1299  " &nbsp;<br><samp>~~</samp>"
1300  " </td>"
1301  " <td></td>"
1302  " <td>"
1303  " <samp><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u></samp><br>"
1304  " <samp>overbar</samp><br>"
1305  " <samp><u>&nbsp;&nbsp;&nbsp;</u></samp><br>"
1306  " <samp>CLK</samp><br>"
1307  " <samp>&nbsp;</samp><br>"
1308  " <samp>~</samp>"
1309  " </td>"
1310  " </tr>"
1311  " <tr><td><br></td></tr>"
1312  " <tr>"
1313  " <td>&nbsp;<br><samp>${variable}</samp></td>"
1314  " <td></td>"
1315  " <td>&nbsp;<br><samp><i>variable_value</i></samp></td>"
1316  " </tr>"
1317  " <tr>"
1318  " <td>&nbsp;<br><samp>${REVISION}</samp></td>"
1319  " <td></td>"
1320  " <td>&nbsp;<br><samp>2020.1</samp></td>"
1321  " </tr>"
1322  " <tr><td><br></td></tr>"
1323  " <tr>"
1324  " <td>&nbsp;<br><samp>${refdes:field}</samp></td>"
1325  " <td></td>"
1326  " <td>&nbsp;<br><samp><i>field_value</i> of symbol <i>refdes</i></samp></td>"
1327  " </tr>"
1328  " <tr>"
1329  " <td>&nbsp;<br><samp>${R3:VALUE}</samp></td>"
1330  " <td></td>"
1331  " <td>&nbsp;<br><samp>150K</samp></td>"
1332  " </tr>"
1333  " <tr><td><br></td></tr>"
1334  " <tr><td><br></td></tr>"
1335  " <tr>"
1336  " <th>Bus Definition</th>"
1337  " <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>"
1338  " <th>Resultant Nets</th>"
1339  " </tr>"
1340  " <tr>"
1341  " <td>&nbsp;<br><samp>prefix[m..n]</samp></td>"
1342  " <td></td>"
1343  " <td>&nbsp;<br><samp>prefixm to prefixn</samp></td>"
1344  " </tr>"
1345  " <tr>"
1346  " <td>&nbsp;<br><samp>D[0..7]</samp></td>"
1347  " <td></td>"
1348  " <td>&nbsp;<br><samp>D0, D1, D2, D3, D4, D5, D6, D7</samp></td>"
1349  " </tr>"
1350  " <tr><td><br></td></tr>"
1351  " <tr><samp>"
1352  " <td>&nbsp;<br><samp>{net1 net2 ...}</samp></td>"
1353  " <td></td>"
1354  " <td>&nbsp;<br><samp>net1, net2, ...</samp></td>"
1355  " </tr>"
1356  " <tr>"
1357  " <td>&nbsp;<br><samp>{SCL SDA}</samp></td>"
1358  " <td></td>"
1359  " <td>&nbsp;<br><samp>SCL, SDA</samp></td>"
1360  " </tr></samp>"
1361  " <tr><td><br></td></tr>"
1362  " <tr>"
1363  " <td>&nbsp;<br><samp>prefix{net1 net2 ...}</samp></td>"
1364  " <td></td>"
1365  " <td>&nbsp;<br><samp>prefix.net1, prefix.net2, ...</samp></td>"
1366  " </tr>"
1367  " <tr>"
1368  " <td>&nbsp;<br><samp>USB1{DP DM}</samp></td>"
1369  " <td></td>"
1370  " <td>&nbsp;<br><samp>USB1.DP, USB1.DM</samp></td>"
1371  " </tr>"
1372  " <tr><td><br></td></tr>"
1373  " <tr>"
1374  " <td>&nbsp;<br><samp>MEM{D[1..2] LATCH}</samp></td>"
1375  " <td></td>"
1376  " <td>&nbsp;<br>"
1377  " <samp>MEM.D1, MEM.D2, MEM.LATCH</samp>"
1378  " </td>"
1379  " </tr>"
1380  " <tr>"
1381  " <td>&nbsp;<br><samp>MEM{D_{[1..2]} ~LATCH}</samp></td>"
1382  " <td></td>"
1383  " <td>"
1384  " <samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1385  " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1386  " <u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u></samp><br>"
1387  " <samp>MEM.D<sub>1</sub>, MEM.D<sub>2</sub>, MEM.LATCH</samp>"
1388  " </td>"
1389  " </tr>"
1390  "</table>" );
1391 
1392  HTML_MESSAGE_BOX dlg( aParentWindow, _( "Syntax Help" ) );
1393  dlg.SetDialogSizeInDU( 280, 280 );
1394 
1395  dlg.AddHTML_Text( msg );
1396  dlg.ShowModal();
1397 }
#define TEXT_ANGLE_HORIZ
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:341
EDA_UNITS
Definition: common.h:198
bool IsBold() const
Definition: eda_text.h:183
SCH_LAYER_ID m_Layer
Definition: sch_item.h:192
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:827
static int Template3STATE_HN[]
Definition: sch_text.cpp:104
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:43
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:151
static int TemplateUNSPC_HN[]
Definition: sch_text.cpp:94
wxPoint GetPosition() const
Definition: sch_item.h:140
#define KI_FALLTHROUGH
static int Template3STATE_HI[]
Definition: sch_text.cpp:105
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
static int TemplateUNSPC_HI[]
Definition: sch_text.cpp:95
PROJECT holds project specific data.
Definition: project.h:61
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:199
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
#define TEXT_ANGLE_VERT
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
static int TemplateOUT_UP[]
Definition: sch_text.cpp:91
SCH_SHEET_PATH m_SheetPathInclude
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Adds a connection link between this item and another.
Definition: sch_item.cpp:182
LABEL_SPIN_STYLE m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:184
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections.
Definition: sch_text.h:171
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:544
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:1063
static int TemplateOUT_HN[]
Definition: sch_text.cpp:89
virtual wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const
Definition: sch_text.cpp:158
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_text.cpp:587
int color
Definition: DXF_plotter.cpp:61
EDA_RECT GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:222
static int TemplateUNSPC_UP[]
Definition: sch_text.cpp:96
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:247
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:116
static int TemplateIN_UP[]
Definition: sch_text.cpp:86
const BITMAP_OPAQUE text_xpm[1]
Definition: text.cpp:27
Definition: color4d.h:61
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:174
static int TemplateOUT_HI[]
Definition: sch_text.cpp:90
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:1132
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:547
static int TemplateBIDI_HI[]
Definition: sch_text.cpp:100
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:821
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH m_SheetPath
static void ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1264
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
CONNECTION_TYPE
const BITMAP_OPAQUE add_hierarchical_label_xpm[1]
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Function PlotPoly.
SCH_GLOBALLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:833
The base class for create windows for drawing purpose.
CONNECTION_TYPE m_connectionType
Definition: sch_text.h:173
EDA_ITEM * m_Comp
const BITMAP_OPAQUE add_line_label_xpm[1]
bool Contains(const wxPoint &aPoint) const
Function Contains.
static int Template3STATE_BOTTOM[]
Definition: sch_text.cpp:107
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_text.cpp:191
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:1069
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:400
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
int GetTextHeight() const
Definition: eda_text.h:245
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:222
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
static int TemplateIN_BOTTOM[]
Definition: sch_text.cpp:87
int GetPenWidth() const override
Definition: sch_text.cpp:317
void SetTextX(int aX)
Definition: eda_text.h:250
wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const override
Definition: sch_text.cpp:1232
bool IsItalic() const
Definition: eda_text.h:180
No connection to this item.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:113
static int TemplateOUT_BOTTOM[]
Definition: sch_text.cpp:92
virtual void CreateGraphicShape(RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos)
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.h:258
void GetContextualTextVars(wxArrayString *aVars) const
Returns the set of contextual text variable tokens for this text item.
Definition: sch_text.cpp:474
const wxPoint GetEnd() const
Definition: eda_rect.h:116
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:746
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:188
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:144
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Add all the connection points for this item to aPoints.
Definition: sch_text.cpp:429
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:1085
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
#define NULL
#define DANGLING_SYMBOL_SIZE
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:137
void SetEnd(int x, int y)
Definition: eda_rect.h:192
static int TemplateIN_HI[]
Definition: sch_text.cpp:85
const wxSize & GetTextSize() const
Definition: eda_text.h:239
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:203
static int Template3STATE_UP[]
Definition: sch_text.cpp:106
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:243
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:201
EDA_ITEM * GetItem() const
Definition: sch_item.h:141
static int TemplateBIDI_HN[]
Definition: sch_text.cpp:99
void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:1091
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1008
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
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_text.cpp:332
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1176
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:232
int GetTextOffset(RENDER_SETTINGS *aSettings) const
Definition: sch_text.cpp:306
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:439
SCH_SHEET_PATH.
void CreateGraphicShape(RENDER_SETTINGS *aRenderSettings, std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:936
HTML_MESSAGE_BOX.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.cpp:484
wxPoint GetPosition() const override
Definition: sch_text.h:313
Definition: color4d.h:59
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:196
bool IsMultilineAllowed() const
Definition: eda_text.h:197
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
static int TemplateBIDI_BOTTOM[]
Definition: sch_text.cpp:102
This item represents a net.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
void SetDialogSizeInDU(int aWidth, int aHeight)
set the dialog size, using a "logical value.
void Normalize()
Function Normalize ensures that the height ant width are positive.
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:124
const BITMAP_OPAQUE add_glabel_xpm[1]
Definition: add_glabel.cpp:42
Base plotter engine class.
Definition: plotter.h:114
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:286
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:143
Definition: color4d.h:56
PINSHEETLABEL_SHAPE
Definition: sch_text.h:150
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
int GetTextWidth() const
Definition: eda_text.h:242
static int TemplateBIDI_UP[]
Definition: sch_text.cpp:101
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
const char * name
Definition: DXF_plotter.cpp:60
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
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:607
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:920
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:202
#define TXT_MARGIN
The default pin len value when creating pins(can be changed in preference menu)
#define _(s)
Definition: 3d_actions.cpp:33
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:271
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_text.cpp:200
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:205
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:553
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
T Mirror(T aPoint, T aMirrorRef)
Function MIRROR Mirror aPoint in aMirrorRef.
Definition: macros.h:170
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
DANGLING_END_T GetType() const
Definition: sch_item.h:143
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:323
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:68
static int * TemplateShape[5][4]
Definition: sch_text.cpp:109
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
#define TO_UTF8(wxstring)
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_text.cpp:343
wxString ExpandTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject)
Expand '${var-name}' templates in text.
Definition: common.cpp:382
void IncrementLabelMember(wxString &name, int aIncrement)
Definition: sch_text.cpp:52
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.
void GetLinePositions(std::vector< wxPoint > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
Definition: eda_text.cpp:423
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:792
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:70
wxString getElectricalTypeLabel(PINSHEETLABEL_SHAPE aType)
Definition: sch_text.cpp:460
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
SCH_SHEET_PATH & GetCurrentSheet() const
void CreateGraphicShape(RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1152
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:167
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:85
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:204
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:167
void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:881
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_text.cpp:752
SCH_HIERLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_HIER_LABEL_T)
Definition: sch_text.cpp:1075
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:843
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
static int TemplateUNSPC_BOTTOM[]
Definition: sch_text.cpp:97
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:230
bool IsBus() const
Definition of the NETLIST_OBJECT class.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:1252
Message panel definition file.
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_text.cpp:182
NETLIST_ITEM m_Type
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:1258
SCH_TEXT(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:119
SCH_LABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:736
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:134
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const override
Definition: sch_text.cpp:849
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_text.cpp:648
This item represents a bus vector.
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_text.cpp:559
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
static int TemplateIN_HN[]
Definition: sch_text.cpp:84
void SetTextY(int aY)
Definition: eda_text.h:251
void ConvertBusToNetListItems(NETLIST_OBJECT_LIST &aNetListItems)
Function ConvertBusToNetListItems breaks the text of a bus label type net list object into as many me...
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:237
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:122
void IncrementLabel(int aIncrement)
Increment the label text, if it ends with a number.
Definition: sch_text.cpp:150
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99