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