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 <[email protected]>
6  * Copyright (C) 1992-2021 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 <sch_symbol.h>
32 #include <sch_edit_frame.h>
33 #include <plotters/plotter.h>
34 #include <widgets/msgpanel.h>
35 #include <gal/stroke_font.h>
36 #include <bitmaps.h>
37 #include <string_utils.h>
38 #include <sch_text.h>
39 #include <schematic.h>
41 #include <sch_painter.h>
42 #include <default_values.h>
43 #include <wx/debug.h>
44 #include <wx/log.h>
46 #include <project/project_file.h>
47 #include <project/net_settings.h>
48 #include <core/mirror.h>
49 #include <core/kicad_algo.h>
50 #include <trigo.h>
51 
53 
54 
55 bool IncrementLabelMember( wxString& name, int aIncrement )
56 {
57  if( name.IsEmpty() )
58  return true;
59 
60  wxString suffix;
61  wxString digits;
62  wxString outputFormat;
63  wxString outputNumber;
64  int ii = name.Len() - 1;
65  int dCount = 0;
66 
67  while( ii >= 0 && !wxIsdigit( name.GetChar( ii ) ) )
68  {
69  suffix = name.GetChar( ii ) + suffix;
70  ii--;
71  }
72 
73  while( ii >= 0 && wxIsdigit( name.GetChar( ii ) ) )
74  {
75  digits = name.GetChar( ii ) + digits;
76  ii--;
77  dCount++;
78  }
79 
80  if( digits.IsEmpty() )
81  return true;
82 
83  long number = 0;
84 
85  if( digits.ToLong( &number ) )
86  {
87  number += aIncrement;
88 
89  // Don't let result go below zero
90 
91  if( number > -1 )
92  {
93  name.Remove( ii + 1 );
94  //write out a format string with correct number of leading zeroes
95  outputFormat.Printf( wxT( "%%0%dd" ), dCount );
96  //write out the number using the format string
97  outputNumber.Printf( outputFormat, number );
98  name << outputNumber << suffix;
99  return true;
100  }
101  }
102 
103  return false;
104 }
105 
106 
107 /* Coding polygons for global symbol graphic shapes.
108  * the first parml is the number of corners
109  * others are the corners coordinates in reduced units
110  * the real coordinate is the reduced coordinate * text half size
111  */
112 static int TemplateIN_HN[] = { 6, 0, 0, -1, -1, -2, -1, -2, 1, -1, 1, 0, 0 };
113 static int TemplateIN_HI[] = { 6, 0, 0, 1, 1, 2, 1, 2, -1, 1, -1, 0, 0 };
114 static int TemplateIN_UP[] = { 6, 0, 0, 1, -1, 1, -2, -1, -2, -1, -1, 0, 0 };
115 static int TemplateIN_BOTTOM[] = { 6, 0, 0, 1, 1, 1, 2, -1, 2, -1, 1, 0, 0 };
116 
117 static int TemplateOUT_HN[] = { 6, -2, 0, -1, 1, 0, 1, 0, -1, -1, -1, -2, 0 };
118 static int TemplateOUT_HI[] = { 6, 2, 0, 1, -1, 0, -1, 0, 1, 1, 1, 2, 0 };
119 static int TemplateOUT_UP[] = { 6, 0, -2, 1, -1, 1, 0, -1, 0, -1, -1, 0, -2 };
120 static int TemplateOUT_BOTTOM[] = { 6, 0, 2, 1, 1, 1, 0, -1, 0, -1, 1, 0, 2 };
121 
122 static int TemplateUNSPC_HN[] = { 5, 0, -1, -2, -1, -2, 1, 0, 1, 0, -1 };
123 static int TemplateUNSPC_HI[] = { 5, 0, -1, 2, -1, 2, 1, 0, 1, 0, -1 };
124 static int TemplateUNSPC_UP[] = { 5, 1, 0, 1, -2, -1, -2, -1, 0, 1, 0 };
125 static int TemplateUNSPC_BOTTOM[] = { 5, 1, 0, 1, 2, -1, 2, -1, 0, 1, 0 };
126 
127 static int TemplateBIDI_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
128 static int TemplateBIDI_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
129 static int TemplateBIDI_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
130 static int TemplateBIDI_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
131 
132 static int Template3STATE_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
133 static int Template3STATE_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
134 static int Template3STATE_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
135 static int Template3STATE_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
136 
137 static int* TemplateShape[5][4] =
138 {
144 };
145 
146 
148 {
149  SPIN newSpin = m_spin;
150 
151  switch( m_spin )
152  {
153  case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::UP; break;
154  case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
155  case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
156  case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::LEFT; break;
157  default: wxLogWarning( wxT( "RotateCW encountered unknown current spin style" ) ); break;
158  }
159 
160  return LABEL_SPIN_STYLE( newSpin );
161 }
162 
163 
165 {
166  SPIN newSpin = m_spin;
167 
168  switch( m_spin )
169  {
170  case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
171  case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
172  case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::UP; break;
173  case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::LEFT; break;
174  default: wxLogWarning( wxT( "RotateCCW encountered unknown current spin style" ) ); break;
175  }
176 
177  return LABEL_SPIN_STYLE( newSpin );
178 }
179 
180 
182 {
183  SPIN newSpin = m_spin;
184 
185  switch( m_spin )
186  {
187  case LABEL_SPIN_STYLE::UP: newSpin = LABEL_SPIN_STYLE::BOTTOM; break;
188  case LABEL_SPIN_STYLE::BOTTOM: newSpin = LABEL_SPIN_STYLE::UP; break;
189  case LABEL_SPIN_STYLE::LEFT: break;
190  case LABEL_SPIN_STYLE::RIGHT: break;
191  default: wxLogWarning( wxT( "MirrorX encountered unknown current spin style" ) ); break;
192  }
193 
194  return LABEL_SPIN_STYLE( newSpin );
195 }
196 
197 
199 {
200  SPIN newSpin = m_spin;
201 
202  switch( m_spin )
203  {
204  case LABEL_SPIN_STYLE::LEFT: newSpin = LABEL_SPIN_STYLE::RIGHT; break;
205  case LABEL_SPIN_STYLE::RIGHT: newSpin = LABEL_SPIN_STYLE::LEFT; break;
206  case LABEL_SPIN_STYLE::UP: break;
207  case LABEL_SPIN_STYLE::BOTTOM: break;
208  default: wxLogWarning( wxT( "MirrorY encountered unknown current spin style" ) ); break;
209  }
210 
211  return LABEL_SPIN_STYLE( newSpin );
212 }
213 
214 
215 SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
216  SCH_ITEM( nullptr, aType ),
217  EDA_TEXT( text ),
218  m_shape( PINSHEETLABEL_SHAPE::PS_INPUT ),
219  m_isDangling( false ),
220  m_connectionType( CONNECTION_TYPE::NONE )
221 {
223 
224  SetTextPos( pos );
226  SetMultilineAllowed( true );
227 }
228 
229 
230 SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
231  SCH_ITEM( aText ),
232  EDA_TEXT( aText ),
233  m_shape( aText.m_shape ),
234  m_isDangling( aText.m_isDangling ),
235  m_connectionType( aText.m_connectionType ),
236  m_spin_style( aText.m_spin_style )
237 { }
238 
239 
241 {
242  return new SCH_TEXT( *this );
243 }
244 
245 
246 bool SCH_TEXT::IncrementLabel( int aIncrement )
247 {
248  wxString text = GetText();
249  bool ReturnVal = IncrementLabelMember( text, aIncrement );
250 
251  if( ReturnVal )
252  SetText( text );
253 
254  return ReturnVal;
255 }
256 
257 
258 wxPoint SCH_TEXT::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const
259 {
260  wxPoint text_offset;
261 
262  // add an offset to x (or y) position to aid readability of text on a wire or line
263  int dist = GetTextOffset( aSettings ) + GetPenWidth();
264 
265  switch( GetLabelSpinStyle() )
266  {
269  text_offset.x = -dist;
270  break; // Vert Orientation
271  default:
274  text_offset.y = -dist;
275  break; // Horiz Orientation
276  }
277 
278  return text_offset;
279 }
280 
281 
282 void SCH_TEXT::MirrorHorizontally( int aCenter )
283 {
284  // Text is NOT really mirrored; it is moved to a suitable horizontal position
285  SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
286 
287  SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
288 }
289 
290 
291 void SCH_TEXT::MirrorVertically( int aCenter )
292 {
293  // Text is NOT really mirrored; it is moved to a suitable vertical position
294  SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
295 
296  SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
297 }
298 
299 
300 void SCH_TEXT::Rotate( const wxPoint& aCenter )
301 {
302  wxPoint pt = GetTextPos();
303  RotatePoint( &pt, aCenter, 900 );
304  wxPoint offset = pt - GetTextPos();
305 
306  Rotate90( false );
307 
308  SetTextPos( GetTextPos() + offset );
309 }
310 
311 
312 void SCH_TEXT::Rotate90( bool aClockwise )
313 {
314  if( aClockwise )
315  SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
316  else
317  SetLabelSpinStyle( GetLabelSpinStyle().RotateCCW() );
318 }
319 
320 
321 void SCH_TEXT::MirrorSpinStyle( bool aLeftRight )
322 {
323  if( aLeftRight )
324  SetLabelSpinStyle( GetLabelSpinStyle().MirrorY() );
325  else
326  SetLabelSpinStyle( GetLabelSpinStyle().MirrorX() );
327 }
328 
329 
331 {
332  m_spin_style = aSpinStyle;
333 
334  // Assume "Right" and Left" mean which side of the anchor the text will be on
335  // Thus we want to left justify text up against the anchor if we are on the right
336  switch( aSpinStyle )
337  {
338  default:
339  wxASSERT_MSG( 1, wxT( "Bad spin style" ) );
340  break;
341 
342  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
343  //
344  m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
348  break;
349 
350  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
354  break;
355 
356  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
360  break;
361 
362  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
366  break;
367  }
368 }
369 
370 
372 {
373  SCH_TEXT* item = (SCH_TEXT*) aItem;
374 
375  std::swap( m_layer, item->m_layer );
376 
377  std::swap( m_shape, item->m_shape );
378  std::swap( m_isDangling, item->m_isDangling );
379  std::swap( m_spin_style, item->m_spin_style );
380 
381  SwapText( *item );
382  SwapEffects( *item );
383 }
384 
385 
386 bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
387 {
388  if( Type() != aItem.Type() )
389  return Type() < aItem.Type();
390 
391  auto other = static_cast<const SCH_TEXT*>( &aItem );
392 
393  if( GetLayer() != other->GetLayer() )
394  return GetLayer() < other->GetLayer();
395 
396  if( GetPosition().x != other->GetPosition().x )
397  return GetPosition().x < other->GetPosition().x;
398 
399  if( GetPosition().y != other->GetPosition().y )
400  return GetPosition().y < other->GetPosition().y;
401 
402  return GetText() < other->GetText();
403 }
404 
405 
406 int SCH_TEXT::GetTextOffset( const RENDER_SETTINGS* aSettings ) const
407 {
408  double ratio;
409 
410  if( aSettings )
411  ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_TextOffsetRatio;
412  else if( Schematic() )
413  ratio = Schematic()->Settings().m_TextOffsetRatio;
414  else
415  ratio = DEFAULT_TEXT_OFFSET_RATIO; // For previews (such as in Preferences), etc.
416 
417  return KiROUND( ratio * GetTextSize().y );
418 
419  return 0;
420 }
421 
422 
423 int SCH_TEXT::GetLabelBoxExpansion( const RENDER_SETTINGS* aSettings ) const
424 {
425  double ratio;
426 
427  if( aSettings )
428  ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_LabelSizeRatio;
429  else if( Schematic() )
430  ratio = Schematic()->Settings().m_LabelSizeRatio;
431  else
432  ratio = DEFAULT_LABEL_SIZE_RATIO; // For previews (such as in Preferences), etc.
433 
434  return KiROUND( ratio * GetTextSize().y );
435 
436  return 0;
437 }
438 
439 
441 {
442  return GetEffectiveTextPenWidth();
443 }
444 
445 
446 void SCH_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
447 {
448  COLOR4D color = aSettings->GetLayerColor( m_layer );
449  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
450 
451  EDA_TEXT::Print( aSettings, text_offset, color );
452 }
453 
454 
455 void SCH_TEXT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
456 {
457  // Normal text labels cannot be tested for dangling ends.
458  if( Type() == SCH_TEXT_T )
459  return;
460 
461  DANGLING_END_ITEM item( LABEL_END, this, GetTextPos() );
462  aItemList.push_back( item );
463 }
464 
465 
466 bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
467  const SCH_SHEET_PATH* aPath )
468 {
469  // Normal text labels cannot be tested for dangling ends.
470  if( Type() == SCH_TEXT_T )
471  return false;
472 
473  bool previousState = m_isDangling;
474  m_isDangling = true;
476 
477  for( unsigned ii = 0; ii < aItemList.size(); ii++ )
478  {
479  DANGLING_END_ITEM& item = aItemList[ii];
480 
481  if( item.GetItem() == this )
482  continue;
483 
484  switch( item.GetType() )
485  {
486  case PIN_END:
487  case LABEL_END:
488  case SHEET_LABEL_END:
489  case NO_CONNECT_END:
490  if( GetTextPos() == item.GetPosition() )
491  {
492  m_isDangling = false;
493 
494  if( aPath && item.GetType() != PIN_END )
495  AddConnectionTo( *aPath, static_cast<SCH_ITEM*>( item.GetItem() ) );
496  }
497 
498  break;
499 
500  case BUS_END:
503 
504  case WIRE_END:
505  {
506  DANGLING_END_ITEM& nextItem = aItemList[++ii];
507 
508  int accuracy = 1; // We have rounding issues with an accuracy of 0
509 
511  nextItem.GetPosition(), accuracy );
512 
513  if( !m_isDangling )
514  {
517 
518  // Add the line to the connected items, since it won't be picked
519  // up by a search of intersecting connection points
520  if( aPath )
521  {
522  auto sch_item = static_cast<SCH_ITEM*>( item.GetItem() );
523  AddConnectionTo( *aPath, sch_item );
524  sch_item->AddConnectionTo( *aPath, this );
525  }
526  }
527  }
528  break;
529 
530  default:
531  break;
532  }
533 
534  if( !m_isDangling )
535  break;
536  }
537 
538  if( m_isDangling )
540 
541  return previousState != m_isDangling;
542 }
543 
544 
545 std::vector<wxPoint> SCH_TEXT::GetConnectionPoints() const
546 {
547  // Normal text labels do not have connection points. All others do.
548  if( Type() == SCH_TEXT_T )
549  return {};
550 
551  return { GetTextPos() };
552 }
553 
554 
556 {
557  EDA_RECT rect = GetTextBox();
558 
559  if( GetTextAngle() != 0 ) // Rotate rect.
560  {
561  wxPoint pos = rect.GetOrigin();
562  wxPoint end = rect.GetEnd();
563 
564  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
565  RotatePoint( &end, GetTextPos(), GetTextAngle() );
566 
567  rect.SetOrigin( pos );
568  rect.SetEnd( end );
569  }
570 
571  rect.Normalize();
572  return rect;
573 }
574 
575 
577 {
578  switch( aType )
579  {
580  case PINSHEETLABEL_SHAPE::PS_INPUT: return _( "Input" );
581  case PINSHEETLABEL_SHAPE::PS_OUTPUT: return _( "Output" );
582  case PINSHEETLABEL_SHAPE::PS_BIDI: return _( "Bidirectional" );
583  case PINSHEETLABEL_SHAPE::PS_TRISTATE: return _( "Tri-State" );
584  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: return _( "Passive" );
585  default: return wxT( "???" );
586  }
587 }
588 
589 
590 void SCH_TEXT::GetContextualTextVars( wxArrayString* aVars ) const
591 {
593  aVars->push_back( wxT( "CONNECTION_TYPE" ) );
594 
595  if( Type() == SCH_SHEET_PIN_T && m_parent )
596  static_cast<SCH_SHEET*>( m_parent )->GetContextualTextVars( aVars );
597 }
598 
599 
600 wxString SCH_TEXT::GetShownText( int aDepth ) const
601 {
602  std::function<bool( wxString* )> textResolver =
603  [&]( wxString* token ) -> bool
604  {
605  if( ( Type() == SCH_GLOBAL_LABEL_T
606  || Type() == SCH_HIER_LABEL_T
607  || Type() == SCH_SHEET_PIN_T )
608  && token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) )
609  {
610  *token = getElectricalTypeLabel( GetShape() );
611  return true;
612  }
613 
614  if( Type() == SCH_SHEET_PIN_T && m_parent )
615  {
616  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
617 
618  if( sheet->ResolveTextVar( token, aDepth ) )
619  return true;
620  }
621 
622  if( token->Contains( ':' ) )
623  {
624  if( Schematic()->ResolveCrossReference( token, aDepth ) )
625  return true;
626  }
627  else
628  {
629  SCHEMATIC* schematic = Schematic();
630  SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
631 
632  if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
633  return true;
634  }
635 
636  return false;
637  };
638 
639  std::function<bool( wxString* )> schematicTextResolver =
640  [&]( wxString* token ) -> bool
641  {
642  return Schematic()->ResolveTextVar( token, aDepth + 1 );
643  };
644 
645  wxString text = EDA_TEXT::GetShownText();
646 
647  if( text == wxT( "~" ) ) // Legacy placeholder for empty string
648  {
649  text = "";
650  }
651  else if( HasTextVars() )
652  {
653  wxCHECK_MSG( Schematic(), wxEmptyString, wxT( "No parent SCHEMATIC set for SCH_TEXT!" ) );
654 
655  PROJECT* project = nullptr;
656 
657  if( Schematic() )
658  project = &Schematic()->Prj();
659 
660  if( aDepth < 10 )
661  text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project );
662  }
663 
664  return text;
665 }
666 
667 
668 wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
669 {
670  return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() );
671 }
672 
673 
675 {
676  return BITMAPS::text;
677 }
678 
679 
680 bool SCH_TEXT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
681 {
682  EDA_RECT bBox = GetBoundingBox();
683  bBox.Inflate( aAccuracy );
684  return bBox.Contains( aPosition );
685 }
686 
687 
688 bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
689 {
690  EDA_RECT bBox = GetBoundingBox();
691  bBox.Inflate( aAccuracy );
692 
693  if( aContained )
694  return aRect.Contains( bBox );
695 
696  return aRect.Intersects( bBox );
697 }
698 
699 
700 void SCH_TEXT::Plot( PLOTTER* aPlotter ) const
701 {
702  static std::vector<wxPoint> s_poly;
703 
704  RENDER_SETTINGS* settings = aPlotter->RenderSettings();
705  SCH_CONNECTION* connection = Connection();
706  int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
707  COLOR4D color = settings->GetLayerColor( layer );
708  int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
709 
710  penWidth = std::max( penWidth, settings->GetMinPenWidth() );
711  aPlotter->SetCurrentLineWidth( penWidth );
712 
713  if( IsMultilineAllowed() )
714  {
715  std::vector<wxPoint> positions;
716  wxArrayString strings_list;
717  wxStringSplit( GetShownText(), strings_list, '\n' );
718  positions.reserve( strings_list.Count() );
719 
720  GetLinePositions( positions, (int) strings_list.Count() );
721 
722  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
723  {
724  wxPoint textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
725  wxString& txt = strings_list.Item( ii );
726  aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
727  GetVertJustify(), penWidth, IsItalic(), IsBold() );
728  }
729  }
730  else
731  {
732  wxPoint textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
733 
734  aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
735  GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
736  }
737 
738  // Draw graphic symbol for global or hierarchical labels
739  CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() );
740 
741  if( s_poly.size() )
742  aPlotter->PlotPoly( s_poly, FILL_T::NO_FILL, penWidth );
743 }
744 
745 
746 void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
747 {
748  wxString msg;
749 
750  switch( Type() )
751  {
752  case SCH_TEXT_T: msg = _( "Graphic Text" ); break;
753  case SCH_LABEL_T: msg = _( "Label" ); break;
754  case SCH_GLOBAL_LABEL_T: msg = _( "Global Label" ); break;
755  case SCH_HIER_LABEL_T: msg = _( "Hierarchical Label" ); break;
756  case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break;
757  default: return;
758  }
759 
760  // Don't use GetShownText() here; we want to show the user the variable references
761  aList.emplace_back( msg, UnescapeString( GetText() ) );
762 
763  // Display electrical type if it is relevant
765  aList.emplace_back( _( "Type" ), getElectricalTypeLabel( GetShape() ) );
766 
767  wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
768  int style = 0;
769 
770  if( IsItalic() )
771  style = 1;
772 
773  if( IsBold() )
774  style += 2;
775 
776  aList.emplace_back( _( "Style" ), textStyle[style] );
777 
778  aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
779  GetTextWidth() ) );
780 
781  switch( GetLabelSpinStyle() )
782  {
783  case LABEL_SPIN_STYLE::LEFT: msg = _( "Align right" ); break;
784  case LABEL_SPIN_STYLE::UP: msg = _( "Align bottom" ); break;
785  case LABEL_SPIN_STYLE::RIGHT: msg = _( "Align left" ); break;
786  case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Align top" ); break;
787  default: msg = wxT( "???" ); break;
788  }
789 
790  aList.emplace_back( _( "Justification" ), msg );
791 
792  SCH_CONNECTION* conn = nullptr;
793 
794  if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
795  conn = Connection();
796 
797  if( conn )
798  {
799  conn->AppendInfoToMsgPanel( aList );
800 
801  if( !conn->IsBus() )
802  {
803  NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
804  const wxString& netname = conn->Name( true );
805 
806  if( netSettings.m_NetClassAssignments.count( netname ) )
807  {
808  const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ];
809  aList.emplace_back( _( "Assigned Netclass" ), netclassName );
810  }
811  }
812  }
813 }
814 
815 
816 #if defined(DEBUG)
817 
818 void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
819 {
820  // XML output:
821  wxString s = GetClass();
822 
823  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
824  << " layer=\"" << m_layer << '"'
825  << " shape=\"" << static_cast<int>( m_shape ) << '"'
826  << " dangling=\"" << m_isDangling << '"'
827  << '>'
828  << TO_UTF8( GetText() )
829  << "</" << s.Lower().mb_str() << ">\n";
830 }
831 
832 #endif
833 
834 
835 SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text )
836  : SCH_TEXT( pos, text, SCH_LABEL_T )
837 {
840  m_isDangling = true;
841  SetMultilineAllowed( false );
842 }
843 
844 
846 {
847  return new SCH_LABEL( *this );
848 }
849 
850 
851 bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
852 {
853  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_PIN_T, EOT };
854  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, EOT };
855 
856  if( SCH_ITEM::IsType( aScanTypes ) )
857  return true;
858 
859  wxCHECK_MSG( Schematic(), false, wxT( "No parent SCHEMATIC set for SCH_LABEL!" ) );
860 
861  // Ensure m_connected_items for Schematic()->CurrentSheet() exists.
862  // Can be not the case when "this" is living in clipboard
863  if( m_connected_items.find( Schematic()->CurrentSheet() ) == m_connected_items.end() )
864  return false;
865 
866  const SCH_ITEM_SET& item_set = m_connected_items.at( Schematic()->CurrentSheet() );
867 
868  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
869  {
870  if( *p == SCH_LABEL_LOCATE_WIRE_T )
871  {
872  for( SCH_ITEM* connection : item_set )
873  {
874  if( connection->IsType( wireTypes ) )
875  return true;
876  }
877  }
878  else if ( *p == SCH_LABEL_LOCATE_BUS_T )
879  {
880  for( SCH_ITEM* connection : item_set )
881  {
882  if( connection->IsType( busTypes ) )
883  return true;
884  }
885  }
886  }
887 
888  return false;
889 }
890 
891 
893 {
894  EDA_RECT rect = GetTextBox();
895 
896  rect.Offset( 0, -GetTextOffset() );
897 
898  if( GetTextAngle() != 0.0 )
899  {
900  // Rotate rect
901  wxPoint pos = rect.GetOrigin();
902  wxPoint end = rect.GetEnd();
903 
904  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
905  RotatePoint( &end, GetTextPos(), GetTextAngle() );
906 
907  rect.SetOrigin( pos );
908  rect.SetEnd( end );
909 
910  rect.Normalize();
911  }
912 
913  // Labels have a position point that is outside of the TextBox
914  rect.Merge( GetPosition() );
915 
916  return rect;
917 }
918 
919 
920 void SCH_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
921 {
922  aCount = 0;
923 
924  if( m_layer != LAYER_NOTES )
925  aLayers[ aCount++ ] = LAYER_DANGLING;
926 
927  aLayers[ aCount++ ] = m_layer;
928  aLayers[ aCount++ ] = LAYER_SELECTION_SHADOWS;
929 }
930 
931 
932 wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
933 {
934  return wxString::Format( _( "Label '%s'" ), ShortenedShownText() );
935 }
936 
937 
939 {
941 }
942 
943 
944 SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) :
946  m_intersheetRefsField( { 0, 0 }, 0, this )
947 {
948  m_layer = LAYER_GLOBLABEL;
950  m_isDangling = true;
951  SetMultilineAllowed( false );
952 
953  SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
954 
955  m_intersheetRefsField.SetText( wxT( "${INTERSHEET_REFS}" ) );
956  m_intersheetRefsField.SetLayer( LAYER_GLOBLABEL );
957  m_intersheetRefsField.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
958  m_fieldsAutoplaced = FIELDS_AUTOPLACED_AUTO;
959 }
960 
961 
963  SCH_TEXT( aGlobalLabel ),
964  m_intersheetRefsField( { 0, 0 }, 0, this )
965 {
966  m_intersheetRefsField = aGlobalLabel.m_intersheetRefsField;
967 
968  // Re-parent the fields, which before this had aGlobalLabel as parent
969  m_intersheetRefsField.SetParent( this );
970 
971  m_fieldsAutoplaced = aGlobalLabel.m_fieldsAutoplaced;
972 }
973 
974 
976 {
977  return new SCH_GLOBALLABEL( *this );
978 }
979 
980 
982 {
983  SCH_TEXT::SwapData( aItem );
984 
985  SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( aItem );
986 
987  // Swap field data wholesale...
988  std::swap( m_intersheetRefsField, globalLabel->m_intersheetRefsField );
989 
990  // ...and then reset parent pointers.
991  globalLabel->m_intersheetRefsField.SetParent( globalLabel );
993 }
994 
995 
996 SEARCH_RESULT SCH_GLOBALLABEL::Visit( INSPECTOR aInspector, void* testData,
997  const KICAD_T aFilterTypes[] )
998 {
999  KICAD_T stype;
1000 
1001  for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
1002  {
1003  // If caller wants to inspect my type
1004  if( stype == SCH_LOCATE_ANY_T || stype == Type() )
1005  {
1006  if( SEARCH_RESULT::QUIT == aInspector( this, nullptr ) )
1007  return SEARCH_RESULT::QUIT;
1008  }
1009 
1010  if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T )
1011  {
1012  if( SEARCH_RESULT::QUIT == aInspector( GetIntersheetRefs(), this ) )
1013  return SEARCH_RESULT::QUIT;
1014  }
1015  }
1016 
1017  return SEARCH_RESULT::CONTINUE;
1018 }
1019 
1020 
1021 void SCH_GLOBALLABEL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
1022 {
1023  aFunction( &m_intersheetRefsField );
1024 }
1025 
1026 
1028 {
1029  int horiz = GetLabelBoxExpansion( aSettings );
1030 
1031  // Center the text on the center line of "E" instead of "R" to make room for an overbar
1032  int vert = GetTextHeight() * 0.0715;
1033 
1034  switch( m_shape )
1035  {
1039  horiz += GetTextHeight() * 3 / 4; // Use three-quarters-height as proxy for triangle size
1040  break;
1041 
1044  default:
1045  break;
1046  }
1047 
1048  switch( GetLabelSpinStyle() )
1049  {
1050  default:
1051  case LABEL_SPIN_STYLE::LEFT: return wxPoint( -horiz, vert );
1052  case LABEL_SPIN_STYLE::UP: return wxPoint( vert, -horiz );
1053  case LABEL_SPIN_STYLE::RIGHT: return wxPoint( horiz, vert );
1054  case LABEL_SPIN_STYLE::BOTTOM: return wxPoint( vert, horiz );
1055  }
1056 }
1057 
1058 
1060 {
1061  m_spin_style = aSpinStyle;
1062 
1063  switch( aSpinStyle )
1064  {
1065  default:
1066  wxASSERT_MSG( 1, wxT( "Bad spin style" ) );
1069 
1070  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
1073  break;
1074 
1075  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
1078  break;
1079 
1080  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
1083  break;
1084 
1085  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
1088  break;
1089  }
1090 }
1091 
1092 
1093 void SCH_GLOBALLABEL::Rotate( const wxPoint& aCenter )
1094 {
1095  wxPoint pt = GetTextPos();
1096  RotatePoint( &pt, aCenter, 900 );
1097  wxPoint offset = pt - GetTextPos();
1098 
1099  Rotate90( false );
1100 
1101  SetTextPos( GetTextPos() + offset );
1103 }
1104 
1105 
1106 void SCH_GLOBALLABEL::Rotate90( bool aClockwise )
1107 {
1108  SCH_TEXT::Rotate90( aClockwise );
1109 
1112  {
1113  if( !aClockwise )
1115 
1117  }
1120  {
1121  if( !aClockwise )
1123 
1125  }
1128  {
1129  if( aClockwise )
1131 
1133  }
1136  {
1137  if( aClockwise )
1139 
1141  }
1142 
1143  wxPoint pos = m_intersheetRefsField.GetTextPos();
1144  RotatePoint( &pos, GetPosition(), aClockwise ? -900 : 900 );
1146 }
1147 
1148 
1149 void SCH_GLOBALLABEL::MirrorSpinStyle( bool aLeftRight )
1150 {
1151  SCH_TEXT::MirrorSpinStyle( aLeftRight );
1152 
1153  if( ( aLeftRight && m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_HORIZ )
1154  || ( !aLeftRight && m_intersheetRefsField.GetTextAngle() == TEXT_ANGLE_VERT ) )
1155  {
1158  else
1160  }
1161 
1162  wxPoint pos = m_intersheetRefsField.GetTextPos();
1163  wxPoint delta = GetPosition() - pos;
1164 
1165  if( aLeftRight )
1166  pos.x = GetPosition().x + delta.x;
1167  else
1168  pos.y = GetPosition().y + delta.y;
1169 
1171 }
1172 
1173 
1175 {
1176  wxPoint old_pos = GetPosition();
1177  SCH_TEXT::MirrorHorizontally( aCenter );
1178 
1181  else
1183 
1184  wxPoint pos = m_intersheetRefsField.GetTextPos();
1185  wxPoint delta = old_pos - pos;
1186  pos.x = GetPosition().x + delta.x;
1187 
1189 }
1190 
1191 
1193 {
1194  wxPoint old_pos = GetPosition();
1195  SCH_TEXT::MirrorVertically( aCenter );
1196  wxPoint pos = m_intersheetRefsField.GetTextPos();
1197  wxPoint delta = old_pos - pos;
1198  pos.y = GetPosition().y + delta.y;
1199 
1201 }
1202 
1203 
1205 {
1210 
1212  AutoplaceFields( nullptr, false );
1213 }
1214 
1215 
1216 void SCH_GLOBALLABEL::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
1217 {
1218  int margin = GetTextOffset() * 2;
1219  int labelLen = GetBoundingBoxBase().GetSizeMax();
1220  int penOffset = GetPenWidth() / 2;
1221 
1222  // Set both axes to penOffset; we're going to overwrite the text axis below
1223  wxPoint offset( -penOffset, -penOffset );
1224 
1225  switch( GetLabelSpinStyle() )
1226  {
1227  default:
1231  offset.x = - ( labelLen + margin / 2 );
1232  break;
1233 
1234  case LABEL_SPIN_STYLE::UP:
1237  offset.y = - ( labelLen + margin / 2 );
1238  break;
1239 
1243  offset.x = labelLen + margin /2 ;
1244  break;
1245 
1249  offset.y = labelLen + margin / 2;
1250  break;
1251  }
1252 
1254 
1256 }
1257 
1258 
1259 bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
1260 {
1261  if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() )
1262  {
1263  SCHEMATIC_SETTINGS& settings = Schematic()->Settings();
1264  wxString ref;
1265  auto it = Schematic()->GetPageRefsMap().find( GetText() );
1266 
1267  if( it == Schematic()->GetPageRefsMap().end() )
1268  {
1269  ref = wxT( "?" );
1270  }
1271  else
1272  {
1273  std::vector<wxString> pageListCopy;
1274 
1275  pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
1276  std::sort( pageListCopy.begin(), pageListCopy.end(),
1277  []( const wxString& a, const wxString& b ) -> bool
1278  {
1279  return StrNumCmp( a, b, true ) < 0;
1280  } );
1281 
1282  if( !settings.m_IntersheetRefsListOwnPage )
1283  {
1284  wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
1285  alg::delete_matching( pageListCopy, currentPage );
1286  }
1287 
1288  if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )
1289  {
1290  ref.Append( wxString::Format( wxT( "%s..%s" ),
1291  pageListCopy.front(),
1292  pageListCopy.back() ) );
1293  }
1294  else
1295  {
1296  for( const wxString& pageNo : pageListCopy )
1297  ref.Append( wxString::Format( wxT( "%s," ), pageNo ) );
1298 
1299  if( !ref.IsEmpty() && ref.Last() == ',' )
1300  ref.RemoveLast();
1301  }
1302  }
1303 
1304  *token = settings.m_IntersheetRefsPrefix + ref + settings.m_IntersheetRefsSuffix;
1305  return true;
1306  }
1307 
1308  return false;
1309 }
1310 
1311 
1312 void SCH_GLOBALLABEL::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
1313 {
1314  static std::vector<wxPoint> s_poly;
1315 
1316  SCH_CONNECTION* connection = Connection();
1317  int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer;
1318  wxDC* DC = aSettings->GetPrintDC();
1319  COLOR4D color = aSettings->GetLayerColor( layer );
1320  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
1321  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
1322 
1323  EDA_TEXT::Print( aSettings, text_offset, color );
1324 
1325  CreateGraphicShape( aSettings, s_poly, GetTextPos() + aOffset );
1326  GRPoly( nullptr, DC, s_poly.size(), &s_poly[0], false, penWidth, color, color );
1327 
1329  m_intersheetRefsField.Print( aSettings, aOffset );
1330 }
1331 
1332 
1333 void SCH_GLOBALLABEL::Plot( PLOTTER* aPlotter ) const
1334 {
1335  SCH_TEXT::Plot( aPlotter );
1336 
1337  bool show = Schematic()->Settings().m_IntersheetRefsShow;
1338 
1339  if ( show )
1340  m_intersheetRefsField.Plot( aPlotter );
1341 }
1342 
1343 
1345  std::vector<wxPoint>& aPoints, const wxPoint& Pos ) const
1346 {
1347  int margin = GetLabelBoxExpansion( aRenderSettings );
1348  int halfSize = ( GetTextHeight() / 2 ) + margin;
1349  int linewidth = GetPenWidth();
1350  int symb_len = LenSize( GetShownText(), linewidth ) + 2 * margin;
1351 
1352  int x = symb_len + linewidth + 3;
1353  int y = halfSize + linewidth + 3;
1354 
1355  aPoints.clear();
1356 
1357  // Create outline shape : 6 points
1358  aPoints.emplace_back( wxPoint( 0, 0 ) );
1359  aPoints.emplace_back( wxPoint( 0, -y ) ); // Up
1360  aPoints.emplace_back( wxPoint( -x, -y ) ); // left
1361  aPoints.emplace_back( wxPoint( -x, 0 ) ); // Up left
1362  aPoints.emplace_back( wxPoint( -x, y ) ); // left down
1363  aPoints.emplace_back( wxPoint( 0, y ) ); // down
1364 
1365  int x_offset = 0;
1366 
1367  switch( m_shape )
1368  {
1370  x_offset = -halfSize;
1371  aPoints[0].x += halfSize;
1372  break;
1373 
1375  aPoints[3].x -= halfSize;
1376  break;
1377 
1380  x_offset = -halfSize;
1381  aPoints[0].x += halfSize;
1382  aPoints[3].x -= halfSize;
1383  break;
1384 
1386  default:
1387  break;
1388  }
1389 
1390  int angle = 0;
1391 
1392  switch( GetLabelSpinStyle() )
1393  {
1394  default:
1395  case LABEL_SPIN_STYLE::LEFT: break;
1396  case LABEL_SPIN_STYLE::UP: angle = -900; break;
1397  case LABEL_SPIN_STYLE::RIGHT: angle = 1800; break;
1398  case LABEL_SPIN_STYLE::BOTTOM: angle = 900; break;
1399  }
1400 
1401  // Rotate outlines and move corners in real position
1402  for( wxPoint& aPoint : aPoints )
1403  {
1404  aPoint.x += x_offset;
1405 
1406  if( angle )
1407  RotatePoint( &aPoint, angle );
1408 
1409  aPoint += Pos;
1410  }
1411 
1412  aPoints.push_back( aPoints[0] ); // closing
1413 }
1414 
1415 
1417 {
1418  // build the bounding box on the global label only, without taking in account
1419  // the intersheets references, just the bounding box of the graphic shape
1420  int x = GetTextPos().x;
1421  int y = GetTextPos().y;
1422  int penWidth = GetEffectiveTextPenWidth();
1423  int margin = GetTextOffset();
1424  int height = ( ( GetTextHeight() * 15 ) / 10 ) + penWidth + margin;
1425  int length = LenSize( GetShownText(), penWidth )
1426  + height // add height for triangular shapes
1427  - margin; // margin added to height not needed here
1428 
1429  int dx, dy;
1430 
1431  switch( GetLabelSpinStyle() ) // respect orientation
1432  {
1433  default:
1435  dx = -length;
1436  dy = height;
1437  y -= height / 2;
1438  break;
1439 
1440  case LABEL_SPIN_STYLE::UP:
1441  dx = height;
1442  dy = -length;
1443  x -= height / 2;
1444  break;
1445 
1447  dx = length;
1448  dy = height;
1449  y -= height / 2;
1450  break;
1451 
1453  dx = height;
1454  dy = length;
1455  x -= height / 2;
1456  break;
1457  }
1458 
1459  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1460 
1461  box.Normalize();
1462  return box;
1463 }
1464 
1465 
1467 {
1468  // build the bounding box on the global label only, including the intersheets references
1469  // full bounding box if they are shown
1470 
1471  EDA_RECT box( GetBoundingBoxBase() );
1472 
1473  // Note: Schematic() can be null in preference preview panel
1474  if( Schematic() && Schematic()->Settings().m_IntersheetRefsShow )
1475  {
1477  box.Normalize();
1478  }
1479 
1480  return box;
1481 }
1482 
1483 
1485 {
1486  return wxString::Format( _( "Global Label '%s'" ), ShortenedShownText() );
1487 }
1488 
1489 
1491 {
1492  return BITMAPS::add_glabel;
1493 }
1494 
1495 
1496 bool SCH_GLOBALLABEL::HitTest( const wxPoint& aPosition, int aAccuracy ) const
1497 {
1498  EDA_RECT bbox = GetBoundingBoxBase();
1499  bbox.Inflate( aAccuracy );
1500 
1501  if( !bbox.Contains( aPosition ) )
1502  {
1504  {
1506  bbox.Inflate( aAccuracy );
1507 
1508  return bbox.Contains( aPosition );
1509  }
1510 
1511  return false;
1512  }
1513 
1514  return true;
1515 }
1516 
1517 
1518 bool SCH_GLOBALLABEL::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
1519 {
1520  EDA_RECT bbox = GetBoundingBoxBase();
1521 
1522  if( aContained )
1523  {
1524  if( Schematic() && Schematic()->Settings().m_IntersheetRefsShow )
1526 
1527  bbox.Inflate( aAccuracy );
1528  return aRect.Contains( bbox );
1529  }
1530 
1531  bbox.Inflate( aAccuracy );
1532 
1533  if( aRect.Intersects( bbox ) )
1534  return true;
1535 
1537  {
1539  bbox.Inflate( aAccuracy );
1540 
1541  return aRect.Intersects( bbox );
1542  }
1543 
1544  return false;
1545 }
1546 
1547 
1548 SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType )
1549  : SCH_TEXT( pos, text, aType )
1550 {
1553  m_isDangling = true;
1554  SetMultilineAllowed( false );
1555 }
1556 
1557 
1559 {
1560  return new SCH_HIERLABEL( *this );
1561 }
1562 
1563 
1565 {
1566  m_spin_style = aSpinStyle;
1567 
1568  // Assume "Right" and Left" mean which side of the port symbol the text will be on
1569  // If we are left of the symbol, we want to right justify to line up with the symbol
1570  switch( aSpinStyle )
1571  {
1572  default:
1573  wxLogWarning( wxT( "SetLabelSpinStyle bad spin style" ) );
1574  break;
1575 
1577  //
1578  m_spin_style = LABEL_SPIN_STYLE::LEFT; // Handle the error spin style by resetting
1582  break;
1583 
1584  case LABEL_SPIN_STYLE::UP:
1588  break;
1589 
1594  break;
1595 
1600  break;
1601  }
1602 }
1603 
1604 
1605 void SCH_HIERLABEL::Print( const RENDER_SETTINGS* aSettings, const wxPoint& offset )
1606 {
1607  wxCHECK_RET( Schematic(), wxT( "No parent SCHEMATIC set for SCH_LABEL!" ) );
1608 
1609  static std::vector <wxPoint> Poly;
1610 
1611  wxDC* DC = aSettings->GetPrintDC();
1612  SCH_CONNECTION* conn = Connection();
1613  bool isBus = conn && conn->IsBus();
1614  COLOR4D color = aSettings->GetLayerColor( isBus ? LAYER_BUS : m_layer );
1615  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
1616  wxPoint textOffset = offset + GetSchematicTextOffset( aSettings );
1617 
1618  EDA_TEXT::Print( aSettings, textOffset, color );
1619 
1620  CreateGraphicShape( aSettings, Poly, GetTextPos() + offset );
1621  GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
1622 }
1623 
1624 
1626  std::vector<wxPoint>& aPoints, const wxPoint& aPos ) const
1627 {
1628  CreateGraphicShape( aSettings, aPoints, aPos, m_shape );
1629 }
1630 
1631 
1633  std::vector<wxPoint>& aPoints, const wxPoint& aPos,
1634  PINSHEETLABEL_SHAPE aShape ) const
1635 {
1636  int* Template = TemplateShape[static_cast<int>( aShape )][static_cast<int>( m_spin_style )];
1637  int halfSize = GetTextHeight() / 2;
1638  int imax = *Template;
1639  Template++;
1640 
1641  aPoints.clear();
1642 
1643  for( int ii = 0; ii < imax; ii++ )
1644  {
1645  wxPoint corner;
1646  corner.x = ( halfSize * (*Template) ) + aPos.x;
1647  Template++;
1648 
1649  corner.y = ( halfSize * (*Template) ) + aPos.y;
1650  Template++;
1651 
1652  aPoints.push_back( corner );
1653  }
1654 }
1655 
1656 
1658 {
1659  int penWidth = GetEffectiveTextPenWidth();
1660  int margin = GetTextOffset();
1661 
1662  int x = GetTextPos().x;
1663  int y = GetTextPos().y;
1664 
1665  int height = GetTextHeight() + penWidth + margin;
1666  int length = LenSize( GetShownText(), penWidth )
1667  + height; // add height for triangular shapes
1668 
1669  int dx, dy;
1670 
1671  switch( GetLabelSpinStyle() )
1672  {
1673  default:
1675  dx = -length;
1676  dy = height;
1677  x += Mils2iu( DANGLING_SYMBOL_SIZE );
1678  y -= height / 2;
1679  break;
1680 
1681  case LABEL_SPIN_STYLE::UP:
1682  dx = height;
1683  dy = -length;
1684  x -= height / 2;
1685  y += Mils2iu( DANGLING_SYMBOL_SIZE );
1686  break;
1687 
1689  dx = length;
1690  dy = height;
1691  x -= Mils2iu( DANGLING_SYMBOL_SIZE );
1692  y -= height / 2;
1693  break;
1694 
1696  dx = height;
1697  dy = length;
1698  x -= height / 2;
1699  y -= Mils2iu( DANGLING_SYMBOL_SIZE );
1700  break;
1701  }
1702 
1703  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1704  box.Normalize();
1705  return box;
1706 }
1707 
1708 
1710 {
1711  wxPoint text_offset;
1712  int dist = GetTextOffset( aSettings );
1713 
1714  dist += GetTextWidth();
1715 
1716  switch( GetLabelSpinStyle() )
1717  {
1718  default:
1719  case LABEL_SPIN_STYLE::LEFT: text_offset.x = -dist; break; // Orientation horiz normale
1720  case LABEL_SPIN_STYLE::UP: text_offset.y = -dist; break; // Orientation vert UP
1721  case LABEL_SPIN_STYLE::RIGHT: text_offset.x = dist; break; // Orientation horiz inverse
1722  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y = dist; break; // Orientation vert BOTTOM
1723  }
1724 
1725  return text_offset;
1726 }
1727 
1728 
1730 {
1731  return wxString::Format( _( "Hierarchical Label '%s'" ), ShortenedShownText() );
1732 }
1733 
1734 
1736 {
1738 }
1739 
1740 
1741 HTML_MESSAGE_BOX* SCH_TEXT::ShowSyntaxHelp( wxWindow* aParentWindow )
1742 {
1743  wxString msg =
1744 #include "sch_text_help_md.h"
1745  ;
1746 
1747  HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
1748  wxSize sz( 320, 320 );
1749 
1750  dlg->SetMinSize( dlg->ConvertDialogToPixels( sz ) );
1751  dlg->SetDialogSizeInDU( sz.x, sz.y );
1752 
1753  wxString html_txt;
1754  ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
1755  dlg->AddHTML_Text( html_txt );
1756  dlg->ShowModeless();
1757 
1758  return dlg;
1759 }
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:291
const EDA_RECT GetBoundingBoxBase() const
Return the bounding box on the global label only, without taking in account the intersheet references...
Definition: sch_text.cpp:1416
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_text.cpp:1021
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:71
bool IsBold() const
Definition: eda_text.h:204
void Offset(int dx, int dy)
Definition: eda_rect.h:156
#define DEFAULT_LABEL_SIZE_RATIO
The offset of the pin name string from the end of the pin in mils.
static int Template3STATE_HN[]
Definition: sch_text.cpp:132
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:44
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:153
static int TemplateUNSPC_HN[]
Definition: sch_text.cpp:122
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:121
static int Template3STATE_HI[]
Definition: sch_text.cpp:133
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:220
static int TemplateUNSPC_HI[]
Definition: sch_text.cpp:123
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
Container for project specific data.
Definition: project.h:62
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:1093
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:57
Holds all the data relating to one schematic.
Definition: schematic.h:59
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
static int TemplateOUT_UP[]
Definition: sch_text.cpp:119
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:1312
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:183
LABEL_SPIN_STYLE m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:278
wxPoint GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_text.cpp:1027
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections.
Definition: sch_text.h:264
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_text.cpp:1484
static int TemplateOUT_HN[]
Definition: sch_text.cpp:117
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:420
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_text.cpp:680
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
void SetItalic(bool isItalic)
Definition: eda_text.h:200
int color
Definition: DXF_plotter.cpp:57
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:239
static int TemplateUNSPC_UP[]
Definition: sch_text.cpp:124
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:267
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:104
static int TemplateIN_UP[]
Definition: sch_text.cpp:114
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:1333
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:195
static int TemplateOUT_HI[]
Definition: sch_text.cpp:118
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:130
NET_SETTINGS & NetSettings()
Definition: project_file.h:96
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_text.cpp:668
static int TemplateBIDI_HI[]
Definition: sch_text.cpp:128
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_text.cpp:932
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:258
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
CONNECTION_TYPE
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:1605
SCH_GLOBALLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:944
int GetTextThickness() const
Definition: eda_text.h:181
The base class for create windows for drawing purpose.
CONNECTION_TYPE m_connectionType
Definition: sch_text.h:266
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Override basic hit test to allow testing separately for label and intersheet refs which can move inde...
Definition: sch_text.cpp:1496
virtual wxPoint GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_text.cpp:258
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:489
bool IsConnectivityDirty() const
Definition: sch_item.h:413
static int Template3STATE_BOTTOM[]
Definition: sch_text.cpp:135
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:93
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void MirrorSpinStyle(bool aLeftRight) override
Definition: sch_text.cpp:1149
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:159
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:1735
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_text.cpp:920
int GetTextHeight() const
Definition: eda_text.h:265
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:138
static int TemplateIN_BOTTOM[]
Definition: sch_text.cpp:115
int GetPenWidth() const override
Definition: sch_text.cpp:440
void SetTextX(int aX)
Definition: eda_text.h:270
bool IsItalic() const
Definition: eda_text.h:201
No connection to this item.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static int TemplateOUT_BOTTOM[]
Definition: sch_text.cpp:120
void GetContextualTextVars(wxArrayString *aVars) const
Return the set of contextual text variable tokens for this text item.
Definition: sch_text.cpp:590
std::vector< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:134
const wxPoint GetEnd() const
Definition: eda_rect.h:112
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:845
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:204
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: sch_text.cpp:1259
SCH_LAYER_ID m_layer
Definition: sch_item.h:487
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:300
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:240
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:1558
wxString Name(bool aIgnoreSheet=false) const
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:219
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
#define DANGLING_SYMBOL_SIZE
< The size of the rectangle indicating an unconnected wire or label
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: schematic.cpp:123
wxPoint GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_text.cpp:1709
const wxPoint GetOrigin() const
Definition: eda_rect.h:110
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:172
void SetEnd(int x, int y)
Definition: eda_rect.h:191
static int TemplateIN_HI[]
Definition: sch_text.cpp:113
wxString GetPageNumber() const
const wxSize & GetTextSize() const
Definition: eda_text.h:259
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:223
static int Template3STATE_UP[]
Definition: sch_text.cpp:134
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
bool IncrementLabel(int aIncrement)
Increment the label text, if it ends with a number.
Definition: sch_text.cpp:246
bool TestSegmentHit(const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
LABEL_SPIN_STYLE()=default
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:255
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:218
EDA_ITEM * GetItem() const
Definition: sch_item.h:122
static int TemplateBIDI_HN[]
Definition: sch_text.cpp:127
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:282
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:1564
#define _(s)
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:32
const EDA_RECT GetBoundingBox() const override
Return the bounding box on the global label only, including the intersheet references.
Definition: sch_text.cpp:1466
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:182
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:455
void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1625
wxDC * GetPrintDC() const
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:1657
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:159
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:406
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: sch_text.cpp:996
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:555
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateIntersheetRefProps()
Definition: sch_text.cpp:1204
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.cpp:600
wxPoint GetPosition() const override
Definition: sch_text.h:241
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:446
LABEL_SPIN_STYLE MirrorY()
Mirror the label spin style across the Y axis or simply swaps left and right.
Definition: sch_text.cpp:198
std::unordered_map< SCH_SHEET_PATH, SCH_ITEM_SET > m_connected_items
Store pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:494
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:216
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:1192
wxString UnescapeString(const wxString &aSource)
bool IsMultilineAllowed() const
Definition: eda_text.h:217
static int TemplateBIDI_BOTTOM[]
Definition: sch_text.cpp:130
This item represents a net.
LABEL_SPIN_STYLE RotateCCW()
Definition: sch_text.cpp:164
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
virtual void Rotate90(bool aClockwise)
Definition: sch_text.cpp:312
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:259
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:1174
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
EDA_UNITS
Definition: eda_units.h:38
void SetDialogSizeInDU(int aWidth, int aHeight)
Set the dialog size, using a "logical" value.
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
SCH_FIELD * GetIntersheetRefs()
Definition: sch_text.h:415
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:938
No updates are required.
Definition: view_item.h:46
virtual void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos) const
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.h:181
Base plotter engine class.
Definition: plotter.h:121
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:386
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1741
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:145
PINSHEETLABEL_SHAPE
Definition: sch_text.h:95
LABEL_SPIN_STYLE MirrorX()
Mirror the label spin style across the X axis or simply swaps up and bottom.
Definition: sch_text.cpp:181
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:156
int GetTextWidth() const
Definition: eda_text.h:262
static int TemplateBIDI_UP[]
Definition: sch_text.cpp:129
LABEL_SPIN_STYLE RotateCW()
Definition: sch_text.cpp:147
const char * name
Definition: DXF_plotter.cpp:56
SCH_FIELD m_intersheetRefsField
Definition: sch_text.h:435
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void CreateGraphicShape(const RENDER_SETTINGS *aRenderSettings, std::vector< wxPoint > &aPoints, const wxPoint &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1344
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:305
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_text.cpp:545
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:222
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:371
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
virtual wxString GetClass() const override
Return the class name.
Definition: sch_text.h:130
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
Handle the component boundary box.
Definition: eda_rect.h:42
int GetLabelBoxExpansion(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:423
DANGLING_END_T GetType() const
Definition: sch_item.h:124
T MIRRORVAL(T aPoint, T aMirrorRef)
Returns the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:31
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:73
static int * TemplateShape[5][4]
Definition: sch_text.cpp:137
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_text.cpp:1216
These settings were stored in SCH_BASE_FRAME previously.
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:466
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
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:443
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:892
std::map< wxString, std::set< wxString > > & GetPageRefsMap()
Definition: schematic.h:162
Store schematic specific render settings.
Definition: sch_painter.h:66
wxString getElectricalTypeLabel(PINSHEETLABEL_SHAPE aType)
Definition: sch_text.cpp:576
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:1490
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:700
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=nullptr)
Draw text with the plotter.
Definition: gr_text.cpp:219
constexpr int delta
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:260
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:180
virtual void MirrorSpinStyle(bool aLeftRight)
Definition: sch_text.cpp:321
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:79
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:229
#define TEXT_ANGLE_VERT
Definition: eda_text.h:72
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:188
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
Draw a new polyline and fill it if Fill, in drawing space.
Definition: gr_basic.cpp:453
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:1059
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: sch_text.cpp:851
SCH_HIERLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_HIER_LABEL_T)
Definition: sch_text.cpp:1548
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:975
static int TemplateUNSPC_BOTTOM[]
Definition: sch_text.cpp:125
void delete_matching(_Container &__c, _Value __value)
Covers for the horrifically named std::remove and std::remove_if (neither of which remove anything).
Definition: kicad_algo.h:164
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:330
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:121
bool IsBus() const
SEARCH_RESULT
Definition: eda_item.h:41
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_text.cpp:1729
Message panel definition file.
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:202
void Rotate90(bool aClockwise) override
Definition: sch_text.cpp:1106
SCH_TEXT(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:215
void SetBold(bool aBold)
Definition: eda_text.h:203
void SetPosition(const wxPoint &aPosition) override
Definition: sch_field.cpp:822
SCH_LABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:835
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
int GetSizeMax() const
Definition: eda_rect.h:105
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:162
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:981
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:674
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:773
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_text.cpp:746
This item represents a bus vector.
bool IncrementLabelMember(wxString &name, int aIncrement)
Definition: sch_text.cpp:55
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
static int TemplateIN_HN[]
Definition: sch_text.cpp:112
void SetTextY(int aY)
Definition: eda_text.h:271
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:161
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103