KiCad PCB EDA Suite
sch_text.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <sch_component.h>
32 #include <sch_edit_frame.h>
33 #include <plotter.h>
34 #include <widgets/msgpanel.h>
35 #include <gal/stroke_font.h>
36 #include <bitmaps.h>
37 #include <kicad_string.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>
45 #include <project/project_file.h>
46 #include <project/net_settings.h>
47 #include <sch_iref.h>
48 #include <dialog_helpers.h>
49 #include <trigo.h>
50 
52 
53 
54 void IncrementLabelMember( wxString& name, int aIncrement )
55 {
56  int ii, nn;
57  long number = 0;
58 
59  ii = name.Len() - 1; nn = 0;
60 
61  if( !wxIsdigit( name.GetChar( ii ) ) )
62  return;
63 
64  while( ii >= 0 && wxIsdigit( name.GetChar( ii ) ) )
65  {
66  ii--;
67  nn++;
68  }
69 
70  ii++; /* digits are starting at ii position */
71  wxString litt_number = name.Right( nn );
72 
73  if( litt_number.ToLong( &number ) )
74  {
75  number += aIncrement;
76  name.Remove( ii ); name << number;
77  }
78 }
79 
80 
81 /* Coding polygons for global symbol graphic shapes.
82  * the first parml is the number of corners
83  * others are the corners coordinates in reduced units
84  * the real coordinate is the reduced coordinate * text half size
85  */
86 static int TemplateIN_HN[] = { 6, 0, 0, -1, -1, -2, -1, -2, 1, -1, 1, 0, 0 };
87 static int TemplateIN_HI[] = { 6, 0, 0, 1, 1, 2, 1, 2, -1, 1, -1, 0, 0 };
88 static int TemplateIN_UP[] = { 6, 0, 0, 1, -1, 1, -2, -1, -2, -1, -1, 0, 0 };
89 static int TemplateIN_BOTTOM[] = { 6, 0, 0, 1, 1, 1, 2, -1, 2, -1, 1, 0, 0 };
90 
91 static int TemplateOUT_HN[] = { 6, -2, 0, -1, 1, 0, 1, 0, -1, -1, -1, -2, 0 };
92 static int TemplateOUT_HI[] = { 6, 2, 0, 1, -1, 0, -1, 0, 1, 1, 1, 2, 0 };
93 static int TemplateOUT_UP[] = { 6, 0, -2, 1, -1, 1, 0, -1, 0, -1, -1, 0, -2 };
94 static int TemplateOUT_BOTTOM[] = { 6, 0, 2, 1, 1, 1, 0, -1, 0, -1, 1, 0, 2 };
95 
96 static int TemplateUNSPC_HN[] = { 5, 0, -1, -2, -1, -2, 1, 0, 1, 0, -1 };
97 static int TemplateUNSPC_HI[] = { 5, 0, -1, 2, -1, 2, 1, 0, 1, 0, -1 };
98 static int TemplateUNSPC_UP[] = { 5, 1, 0, 1, -2, -1, -2, -1, 0, 1, 0 };
99 static int TemplateUNSPC_BOTTOM[] = { 5, 1, 0, 1, 2, -1, 2, -1, 0, 1, 0 };
100 
101 static int TemplateBIDI_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
102 static int TemplateBIDI_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
103 static int TemplateBIDI_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
104 static int TemplateBIDI_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
105 
106 static int Template3STATE_HN[] = { 5, 0, 0, -1, -1, -2, 0, -1, 1, 0, 0 };
107 static int Template3STATE_HI[] = { 5, 0, 0, 1, -1, 2, 0, 1, 1, 0, 0 };
108 static int Template3STATE_UP[] = { 5, 0, 0, -1, -1, 0, -2, 1, -1, 0, 0 };
109 static int Template3STATE_BOTTOM[] = { 5, 0, 0, -1, 1, 0, 2, 1, 1, 0, 0 };
110 
111 static int* TemplateShape[5][4] =
112 {
118 };
119 
120 
121 SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) :
122  SCH_ITEM( NULL, aType ),
123  EDA_TEXT( text ),
124  m_shape( PINSHEETLABEL_SHAPE::PS_INPUT ),
125  m_isDangling( false ),
126  m_connectionType( CONNECTION_TYPE::NONE ),
127  m_spin_style( LABEL_SPIN_STYLE::LEFT )
128 {
130 
131  SetTextPos( pos );
132  SetMultilineAllowed( true );
133 }
134 
135 
136 SCH_TEXT::SCH_TEXT( const SCH_TEXT& aText ) :
137  SCH_ITEM( aText ),
138  EDA_TEXT( aText ),
139  m_shape( aText.m_shape ),
140  m_isDangling( aText.m_isDangling ),
141  m_connectionType( aText.m_connectionType ),
142  m_spin_style( aText.m_spin_style )
143 { }
144 
145 
147 {
148  return new SCH_TEXT( *this );
149 }
150 
151 
152 void SCH_TEXT::IncrementLabel( int aIncrement )
153 {
154  wxString text = GetText();
155  IncrementLabelMember( text, aIncrement );
156  SetText(text );
157 }
158 
159 
161 {
162  wxPoint text_offset;
163 
164  // add an offset to x (or y) position to aid readability of text on a wire or line
165  int dist = GetTextOffset( aSettings ) + GetPenWidth();
166 
167  switch( GetLabelSpinStyle() )
168  {
171  text_offset.x = -dist;
172  break; // Vert Orientation
173  default:
176  text_offset.y = -dist;
177  break; // Horiz Orientation
178  }
179 
180  return text_offset;
181 }
182 
183 
184 void SCH_TEXT::MirrorY( int aYaxis_position )
185 {
186  // Text is NOT really mirrored; it is moved to a suitable horizontal position
188 
189  SetTextX( MIRRORVAL( GetTextPos().x, aYaxis_position ) );
190 }
191 
192 
193 void SCH_TEXT::MirrorX( int aXaxis_position )
194 {
195  // Text is NOT really mirrored; it is moved to a suitable vertical position
197 
198  SetTextY( MIRRORVAL( GetTextPos().y, aXaxis_position ) );
199 }
200 
201 
202 void SCH_TEXT::Rotate( wxPoint aPosition )
203 {
204  wxPoint pt = GetTextPos();
205  RotatePoint( &pt, aPosition, 900 );
206  SetTextPos( pt );
207 
208  SetLabelSpinStyle( GetLabelSpinStyle().RotateCW() );
209 
210  if( this->Type() == SCH_TEXT_T )
211  {
212  int dy = 0;
213 
214  switch( GetLabelSpinStyle() )
215  {
218  dy = GetTextHeight();
219  break;
222  default:
223  dy = 0;
224  break;
225  }
226 
227  SetTextY( GetTextPos().y + dy );
228  }
229 }
230 
231 
233 {
234  m_spin_style = aSpinStyle;
235 
236  // Assume "Right" and Left" mean which side of the anchor the text will be on
237  // Thus we want to left justify text up agaisnt the anchor if we are on the right
238  switch( aSpinStyle )
239  {
240  default:
241  wxASSERT_MSG( 1, "Bad spin style" );
242  break;
243 
244  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
245  //
246  m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
250  break;
251 
252  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
256  break;
257 
258  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation - Right justified
262  break;
263 
264  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
268  break;
269  }
270 }
271 
272 
274 {
275  SCH_TEXT* item = (SCH_TEXT*) aItem;
276 
277  std::swap( m_Layer, item->m_Layer );
278 
279  std::swap( m_shape, item->m_shape );
280  std::swap( m_isDangling, item->m_isDangling );
281  std::swap( m_spin_style, item->m_spin_style );
282 
283  SwapText( *item );
284  SwapEffects( *item );
285 }
286 
287 
288 bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
289 {
290  if( Type() != aItem.Type() )
291  return Type() < aItem.Type();
292 
293  auto other = static_cast<const SCH_TEXT*>( &aItem );
294 
295  if( GetLayer() != other->GetLayer() )
296  return GetLayer() < other->GetLayer();
297 
298  if( GetPosition().x != other->GetPosition().x )
299  return GetPosition().x < other->GetPosition().x;
300 
301  if( GetPosition().y != other->GetPosition().y )
302  return GetPosition().y < other->GetPosition().y;
303 
304  return GetText() < other->GetText();
305 }
306 
307 
309 {
310  SCH_RENDER_SETTINGS* renderSettings = static_cast<SCH_RENDER_SETTINGS*>( aSettings );
311 
312  if( renderSettings )
313  return KiROUND( renderSettings->m_TextOffsetRatio * GetTextSize().y );
314 
315  return 0;
316 }
317 
318 
320 {
321  return GetEffectiveTextPenWidth();
322 }
323 
324 
325 void SCH_TEXT::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
326 {
327  COLOR4D color = aSettings->GetLayerColor( m_Layer );
328  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
329 
330  EDA_TEXT::Print( aSettings, text_offset, color );
331 }
332 
333 
334 void SCH_TEXT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
335 {
336  // Normal text labels cannot be tested for dangling ends.
337  if( Type() == SCH_TEXT_T )
338  return;
339 
340  DANGLING_END_ITEM item( LABEL_END, this, GetTextPos() );
341  aItemList.push_back( item );
342 }
343 
344 
345 bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
346  const SCH_SHEET_PATH* aPath )
347 {
348  // Normal text labels cannot be tested for dangling ends.
349  if( Type() == SCH_TEXT_T )
350  return false;
351 
352  bool previousState = m_isDangling;
353  m_isDangling = true;
355 
356  for( unsigned ii = 0; ii < aItemList.size(); ii++ )
357  {
358  DANGLING_END_ITEM& item = aItemList[ii];
359 
360  if( item.GetItem() == this )
361  continue;
362 
363  switch( item.GetType() )
364  {
365  case PIN_END:
366  case LABEL_END:
367  case SHEET_LABEL_END:
368  case NO_CONNECT_END:
369  if( GetTextPos() == item.GetPosition() )
370  {
371  m_isDangling = false;
372 
373  if( aPath && item.GetType() != PIN_END )
374  m_connected_items[ *aPath ].insert( static_cast<SCH_ITEM*>( item.GetItem() ) );
375  }
376 
377  break;
378 
379 
380  case BUS_START_END:
383 
384  case WIRE_START_END:
385  {
386  // These schematic items have created 2 DANGLING_END_ITEM one per end. But being
387  // a paranoid programmer, I'll check just in case.
388  ii++;
389 
390  wxCHECK_MSG( ii < aItemList.size(), previousState != m_isDangling,
391  wxT( "Dangling end type list overflow. Bad programmer!" ) );
392 
393  int accuracy = 1; // We have rounding issues with an accuracy of 0
394 
395  DANGLING_END_ITEM & nextItem = aItemList[ii];
397  nextItem.GetPosition(), accuracy );
398 
399  if( !m_isDangling )
400  {
403 
404  // Add the line to the connected items, since it won't be picked
405  // up by a search of intersecting connection points
406  if( aPath )
407  {
408  auto sch_item = static_cast<SCH_ITEM*>( item.GetItem() );
409  AddConnectionTo( *aPath, sch_item );
410  sch_item->AddConnectionTo( *aPath, this );
411  }
412  }
413  }
414  break;
415 
416  default:
417  break;
418  }
419 
420  if( !m_isDangling )
421  break;
422  }
423 
424  if( m_isDangling )
426 
427  return previousState != m_isDangling;
428 }
429 
430 
431 std::vector<wxPoint> SCH_TEXT::GetConnectionPoints() const
432 {
433  // Normal text labels do not have connection points. All others do.
434  if( Type() == SCH_TEXT_T )
435  return {};
436 
437  return { GetTextPos() };
438 }
439 
440 
442 {
443  EDA_RECT rect = GetTextBox();
444 
445  if( GetTextAngle() != 0 ) // Rotate rect
446  {
447  wxPoint pos = rect.GetOrigin();
448  wxPoint end = rect.GetEnd();
449 
450  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
451  RotatePoint( &end, GetTextPos(), GetTextAngle() );
452 
453  rect.SetOrigin( pos );
454  rect.SetEnd( end );
455  }
456 
457  rect.Normalize();
458  return rect;
459 }
460 
461 
463 {
464  switch( aType )
465  {
466  case PINSHEETLABEL_SHAPE::PS_INPUT: return _( "Input" );
467  case PINSHEETLABEL_SHAPE::PS_OUTPUT: return _( "Output" );
468  case PINSHEETLABEL_SHAPE::PS_BIDI: return _( "Bidirectional" );
469  case PINSHEETLABEL_SHAPE::PS_TRISTATE: return _( "Tri-State" );
470  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: return _( "Passive" );
471  default: return wxT( "???" );
472  }
473 }
474 
475 
476 void SCH_TEXT::GetContextualTextVars( wxArrayString* aVars ) const
477 {
479  aVars->push_back( wxT( "CONNECTION_TYPE" ) );
480 
481  if( Type() == SCH_SHEET_PIN_T && m_Parent )
482  static_cast<SCH_SHEET*>( m_Parent )->GetContextualTextVars( aVars );
483 }
484 
485 
486 wxString SCH_TEXT::GetShownText( int aDepth ) const
487 {
488  std::function<bool( wxString* )> textResolver =
489  [&]( wxString* token ) -> bool
490  {
491  if( ( Type() == SCH_GLOBAL_LABEL_T
492  || Type() == SCH_HIER_LABEL_T
493  || Type() == SCH_SHEET_PIN_T )
494  && token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) )
495  {
496  *token = getElectricalTypeLabel( GetShape() );
497  return true;
498  }
499 
500  if( Type() == SCH_SHEET_PIN_T && m_Parent )
501  {
502  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_Parent );
503 
504  if( sheet->ResolveTextVar( token, aDepth ) )
505  return true;
506  }
507 
508  if( Type() == SCH_TEXT_T )
509  {
510  if( token->Contains( ':' ) )
511  {
512  if( Schematic()->ResolveCrossReference( token, aDepth ) )
513  return true;
514  }
515  else
516  {
517  SCHEMATIC* schematic = Schematic();
518  SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
519 
520  if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
521  return true;
522  }
523  }
524 
525  return false;
526  };
527 
528  bool processTextVars = false;
529  wxString text = EDA_TEXT::GetShownText( &processTextVars );
530 
531  if( processTextVars )
532  {
533  wxCHECK_MSG( Schematic(), wxEmptyString,
534  "No parent SCHEMATIC set for SCH_TEXT!" );
535 
536  PROJECT* project = nullptr;
537 
538  if( Schematic() )
539  project = &Schematic()->Prj();
540 
541  if( aDepth < 10 )
542  text = ExpandTextVars( text, &textResolver, project );
543  }
544 
545  return text;
546 }
547 
548 
549 wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
550 {
551  return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() );
552 }
553 
554 
556 {
557  return text_xpm;
558 }
559 
560 
561 bool SCH_TEXT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
562 {
563  EDA_RECT bBox = GetBoundingBox();
564  bBox.Inflate( aAccuracy );
565  return bBox.Contains( aPosition );
566 }
567 
568 
569 bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
570 {
571  EDA_RECT bBox = GetBoundingBox();
572  bBox.Inflate( aAccuracy );
573 
574  if( aContained )
575  return aRect.Contains( bBox );
576 
577  return aRect.Intersects( bBox );
578 }
579 
580 
581 void SCH_TEXT::Plot( PLOTTER* aPlotter )
582 {
583  static std::vector<wxPoint> Poly;
584  COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() );
585  int penWidth = GetEffectiveTextPenWidth( aPlotter->RenderSettings()->GetDefaultPenWidth() );
586 
587  penWidth = std::max( penWidth, aPlotter->RenderSettings()->GetMinPenWidth() );
588  aPlotter->SetCurrentLineWidth( penWidth );
589 
590  if( IsMultilineAllowed() )
591  {
592  std::vector<wxPoint> positions;
593  wxArrayString strings_list;
594  wxStringSplit( GetShownText(), strings_list, '\n' );
595  positions.reserve( strings_list.Count() );
596 
597  GetLinePositions( positions, (int) strings_list.Count() );
598 
599  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
600  {
601  wxPoint textpos = positions[ii] + GetSchematicTextOffset( aPlotter->RenderSettings() );
602  wxString& txt = strings_list.Item( ii );
603  aPlotter->Text( textpos, color, txt, GetTextAngle(), GetTextSize(), GetHorizJustify(),
604  GetVertJustify(), penWidth, IsItalic(), IsBold() );
605  }
606  }
607  else
608  {
609  wxPoint textpos = GetTextPos() + GetSchematicTextOffset( aPlotter->RenderSettings() );
610 
611  aPlotter->Text( textpos, color, GetShownText(), GetTextAngle(), GetTextSize(),
612  GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold() );
613  }
614 
615  // Draw graphic symbol for global or hierarchical labels
616  CreateGraphicShape( aPlotter->RenderSettings(), Poly, GetTextPos() );
617 
618  if( Poly.size() )
619  aPlotter->PlotPoly( Poly, FILL_TYPE::NO_FILL, penWidth );
620 }
621 
622 
624 {
625  wxString msg;
626 
627  switch( Type() )
628  {
629  case SCH_TEXT_T: msg = _( "Graphic Text" ); break;
630  case SCH_LABEL_T: msg = _( "Label" ); break;
631  case SCH_GLOBAL_LABEL_T: msg = _( "Global Label" ); break;
632  case SCH_HIER_LABEL_T: msg = _( "Hierarchical Label" ); break;
633  case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break;
634  default: return;
635  }
636 
637  aList.push_back( MSG_PANEL_ITEM( msg, GetShownText(), DARKCYAN ) );
638 
639  switch( GetLabelSpinStyle() )
640  {
641  case LABEL_SPIN_STYLE::LEFT: msg = _( "Horizontal left" ); break;
642  case LABEL_SPIN_STYLE::UP: msg = _( "Vertical up" ); break;
643  case LABEL_SPIN_STYLE::RIGHT: msg = _( "Horizontal right" ); break;
644  case LABEL_SPIN_STYLE::BOTTOM: msg = _( "Vertical down" ); break;
645  default: msg = wxT( "???" ); break;
646  }
647 
648  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, BROWN ) );
649 
650  wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
651  int style = 0;
652 
653  if( IsItalic() )
654  style = 1;
655 
656  if( IsBold() )
657  style += 2;
658 
659  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), textStyle[style], BROWN ) );
660 
661  // Display electrical type if it is relevant
663  {
664  msg = getElectricalTypeLabel( GetShape() );
665  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, BLUE ) );
666  }
667 
668  // Display text size (X or Y value, with are the same value in Eeschema)
669  msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextWidth() );
670  aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg, RED ) );
671 
672  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
673 
674  if( frame )
675  {
676  if( SCH_CONNECTION* conn = Connection() )
677  {
678  conn->AppendInfoToMsgPanel( aList );
679 
680  NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
681  const wxString& netname = conn->Name( true );
682 
683  if( netSettings.m_NetClassAssignments.count( netname ) )
684  {
685  const wxString& netclassName = netSettings.m_NetClassAssignments[ netname ];
686  aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName, DARKRED ) );
687  }
688  }
689  }
690 }
691 
692 #if defined(DEBUG)
693 
694 void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
695 {
696  // XML output:
697  wxString s = GetClass();
698 
699  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
700  << " layer=\"" << m_Layer << '"'
701  << " shape=\"" << static_cast<int>( m_shape ) << '"'
702  << " dangling=\"" << m_isDangling << '"'
703  << '>'
704  << TO_UTF8( GetText() )
705  << "</" << s.Lower().mb_str() << ">\n";
706 }
707 
708 #endif
709 
710 
711 SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text )
712  : SCH_TEXT( pos, text, SCH_LABEL_T )
713 {
716  m_isDangling = true;
717  SetMultilineAllowed( false );
718 }
719 
720 
722 {
723  return new SCH_LABEL( *this );
724 }
725 
726 
727 bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
728 {
729  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
730  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, EOT };
731 
732  if( SCH_ITEM::IsType( aScanTypes ) )
733  return true;
734 
735  wxCHECK_MSG( Schematic(), false, "No parent SCHEMATIC set for SCH_LABEL!" );
736 
737  SCH_SHEET_PATH current = Schematic()->CurrentSheet();
738 
739  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
740  {
741  if( *p == SCH_LABEL_LOCATE_WIRE_T )
742  {
743  wxASSERT( m_connected_items.count( current ) );
744 
745  for( SCH_ITEM* connection : m_connected_items.at( current ) )
746  {
747  if( connection->IsType( wireTypes ) )
748  return true;
749  }
750  }
751  else if ( *p == SCH_LABEL_LOCATE_BUS_T )
752  {
753  wxASSERT( m_connected_items.count( current ) );
754 
755  for( SCH_ITEM* connection : m_connected_items.at( current ) )
756  {
757  if( connection->IsType( busTypes ) )
758  return true;
759  }
760  }
761  }
762 
763  return false;
764 }
765 
766 
768 {
769  EDA_RECT rect = GetTextBox();
770 
771  // In practice this is controlled by the current TextOffsetRatio, but the default is
772  // close enough for hit-testing, etc.
773  int margin = Mils2iu( TXT_MARGIN );
774 
775  rect.Inflate( margin );
776 
777  if( GetTextAngle() != 0.0 )
778  {
779  // Rotate rect
780  wxPoint pos = rect.GetOrigin();
781  wxPoint end = rect.GetEnd();
782 
783  RotatePoint( &pos, GetTextPos(), GetTextAngle() );
784  RotatePoint( &end, GetTextPos(), GetTextAngle() );
785 
786  rect.SetOrigin( pos );
787  rect.SetEnd( end );
788 
789  rect.Normalize();
790  }
791 
792  return rect;
793 }
794 
795 
796 wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
797 {
798  return wxString::Format( _( "Label '%s'" ), ShortenedShownText() );
799 }
800 
801 
803 {
804  return add_line_label_xpm;
805 }
806 
807 
808 SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text )
809  : SCH_TEXT( pos, text, SCH_GLOBAL_LABEL_T )
810 {
813  m_isDangling = true;
814  m_iref = nullptr;
815  SetMultilineAllowed( false );
816  m_savedIrefPos = wxDefaultPosition;
817 }
818 
819 
821 {
822  return new SCH_GLOBALLABEL( *this );
823 }
824 
825 
827 {
828  wxPoint text_offset;
829  int dist = GetTextOffset( aSettings );
830 
831  switch( m_shape )
832  {
836  dist += GetTextHeight() * 3 / 4; // Use three-quarters-height as proxy for triangle size
837  break;
838 
841  default:
842  break;
843  }
844 
845  switch( GetLabelSpinStyle() )
846  {
847  default:
848  case LABEL_SPIN_STYLE::LEFT: text_offset.x -= dist; break;
849  case LABEL_SPIN_STYLE::UP: text_offset.y -= dist; break;
850  case LABEL_SPIN_STYLE::RIGHT: text_offset.x += dist; break;
851  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y += dist; break;
852  }
853 
854  return text_offset;
855 }
856 
857 
859 {
860  m_spin_style = aSpinStyle;
861 
862  switch( aSpinStyle )
863  {
864  default:
865  wxASSERT_MSG( 1, "Bad spin style" );
866  break;
867 
868  case LABEL_SPIN_STYLE::RIGHT: // Horiz Normal Orientation
869  //
870  m_spin_style = LABEL_SPIN_STYLE::RIGHT; // Handle the error spin style by resetting
874  break;
875 
876  case LABEL_SPIN_STYLE::UP: // Vert Orientation UP
880  break;
881 
882  case LABEL_SPIN_STYLE::LEFT: // Horiz Orientation
886  break;
887 
888  case LABEL_SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM
892  break;
893  }
894 }
895 
896 
897 void SCH_GLOBALLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
898 {
899  static std::vector <wxPoint> Poly;
900 
901  wxDC* DC = aSettings->GetPrintDC();
902  COLOR4D color = aSettings->GetLayerColor( m_Layer );
903  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
904  wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings );
905 
906  EDA_TEXT::Print( aSettings, text_offset, color );
907 
908  CreateGraphicShape( aSettings, Poly, GetTextPos() + aOffset );
909  GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
910 }
911 
912 
914  std::vector<wxPoint>& aPoints, const wxPoint& Pos )
915 {
916  int margin = GetTextOffset( aRenderSettings );
917  int halfSize = ( GetTextHeight() / 2 ) + margin;
918  int linewidth = GetPenWidth();
919  int symb_len = LenSize( GetShownText(), linewidth ) + 2 * margin;
920 
921  int x = symb_len + linewidth + 3;
922  int y = halfSize + linewidth + 3;
923 
924  aPoints.clear();
925 
926  // Create outline shape : 6 points
927  aPoints.emplace_back( wxPoint( 0, 0 ) );
928  aPoints.emplace_back( wxPoint( 0, -y ) ); // Up
929  aPoints.emplace_back( wxPoint( -x, -y ) ); // left
930  aPoints.emplace_back( wxPoint( -x, 0 ) ); // Up left
931  aPoints.emplace_back( wxPoint( -x, y ) ); // left down
932  aPoints.emplace_back( wxPoint( 0, y ) ); // down
933 
934  int x_offset = 0;
935 
936  switch( m_shape )
937  {
939  x_offset = -halfSize;
940  aPoints[0].x += halfSize;
941  break;
942 
944  aPoints[3].x -= halfSize;
945  break;
946 
949  x_offset = -halfSize;
950  aPoints[0].x += halfSize;
951  aPoints[3].x -= halfSize;
952  break;
953 
955  default:
956  break;
957  }
958 
959  int angle = 0;
960 
961  switch( GetLabelSpinStyle() )
962  {
963  default:
964  case LABEL_SPIN_STYLE::LEFT: break;
965  case LABEL_SPIN_STYLE::UP: angle = -900; break;
966  case LABEL_SPIN_STYLE::RIGHT: angle = 1800; break;
967  case LABEL_SPIN_STYLE::BOTTOM: angle = 900; break;
968  }
969 
970  // Rotate outlines and move corners in real position
971  for( wxPoint& aPoint : aPoints )
972  {
973  aPoint.x += x_offset;
974 
975  if( angle )
976  RotatePoint( &aPoint, angle );
977 
978  aPoint += Pos;
979  }
980 
981  aPoints.push_back( aPoints[0] ); // closing
982 }
983 
984 
986 {
987  int x = GetTextPos().x;
988  int y = GetTextPos().y;
989  int penWidth = GetEffectiveTextPenWidth();
990 
991  // In practice this is controlled by the current TextOffsetRatio, but the default is
992  // close enough for hit-testing, etc.
993  int margin = Mils2iu( TXT_MARGIN );
994 
995  int height = ( (GetTextHeight() * 15) / 10 ) + penWidth + 2 * margin;
996  int length = LenSize( GetShownText(), penWidth )
997  + height // add height for triangular shapes
998  + 2 * margin;
999 
1000  int dx, dy;
1001 
1002  switch( GetLabelSpinStyle() ) // respect orientation
1003  {
1004  default:
1006  dx = -length;
1007  dy = height;
1008  x += margin;
1009  y -= height / 2;
1010  break;
1011 
1012  case LABEL_SPIN_STYLE::UP:
1013  dx = height;
1014  dy = -length;
1015  x -= height / 2;
1016  y += margin;
1017  break;
1018 
1020  dx = length;
1021  dy = height;
1022  x -= margin;
1023  y -= height / 2;
1024  break;
1025 
1027  dx = height;
1028  dy = length;
1029  x -= height / 2;
1030  y -= margin;
1031  break;
1032  }
1033 
1034  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1035  box.Normalize();
1036  return box;
1037 }
1038 
1039 
1041 {
1042  return wxString::Format( _( "Global Label '%s'" ), ShortenedShownText() );
1043 }
1044 
1045 
1047 {
1048  return add_glabel_xpm;
1049 }
1050 
1051 
1052 SCH_HIERLABEL::SCH_HIERLABEL( const wxPoint& pos, const wxString& text, KICAD_T aType )
1053  : SCH_TEXT( pos, text, aType )
1054 {
1057  m_isDangling = true;
1058  SetMultilineAllowed( false );
1059 }
1060 
1061 
1063 {
1064  return new SCH_HIERLABEL( *this );
1065 }
1066 
1067 
1069 {
1070  m_spin_style = aSpinStyle;
1071 
1072  // Assume "Right" and Left" mean which side of the port symbol the text will be on
1073  // If we are left of the symbol, we want to right justify to line up with the symbol
1074  switch( aSpinStyle )
1075  {
1076  default:
1077  wxLogWarning( "SetLabelSpinStyle bad spin style" );
1078  break;
1079 
1081  //
1082  m_spin_style = LABEL_SPIN_STYLE::LEFT; // Handle the error spin style by resetting
1086  break;
1087 
1088  case LABEL_SPIN_STYLE::UP:
1092  break;
1093 
1098  break;
1099 
1104  break;
1105  }
1106 }
1107 
1108 
1109 void SCH_HIERLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& offset )
1110 {
1111  wxCHECK_RET( Schematic(), "No parent SCHEMATIC set for SCH_LABEL!" );
1112 
1113  static std::vector <wxPoint> Poly;
1114 
1115  wxDC* DC = aSettings->GetPrintDC();
1116  SCH_CONNECTION* conn = Connection();
1117  bool isBus = conn && conn->IsBus();
1118  COLOR4D color = aSettings->GetLayerColor( isBus ? LAYER_BUS : m_Layer );
1119  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
1120  wxPoint textOffset = offset + GetSchematicTextOffset( aSettings );
1121 
1122  EDA_TEXT::Print( aSettings, textOffset, color );
1123 
1124  CreateGraphicShape( aSettings, Poly, GetTextPos() + offset );
1125  GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color );
1126 }
1127 
1128 
1130  std::vector<wxPoint>& aPoints, const wxPoint& Pos )
1131 {
1132  int* Template = TemplateShape[static_cast<int>( m_shape )][static_cast<int>( m_spin_style )];
1133  int halfSize = GetTextHeight() / 2;
1134  int imax = *Template;
1135  Template++;
1136 
1137  aPoints.clear();
1138 
1139  for( int ii = 0; ii < imax; ii++ )
1140  {
1141  wxPoint corner;
1142  corner.x = ( halfSize * (*Template) ) + Pos.x;
1143  Template++;
1144 
1145  corner.y = ( halfSize * (*Template) ) + Pos.y;
1146  Template++;
1147 
1148  aPoints.push_back( corner );
1149  }
1150 }
1151 
1152 
1154 {
1155  int penWidth = GetEffectiveTextPenWidth();
1156 
1157  // In practice this is controlled by the current TextOffsetRatio, but the default is
1158  // close enough for hit-testing, etc.
1159  int margin = Mils2iu( TXT_MARGIN );
1160 
1161  int x = GetTextPos().x;
1162  int y = GetTextPos().y;
1163 
1164  int height = GetTextHeight() + penWidth + 2 * margin;
1165  int length = LenSize( GetShownText(), penWidth )
1166  + height // add height for triangular shapes
1167  + 2 * margin;
1168 
1169  int dx, dy;
1170 
1171  switch( GetLabelSpinStyle() )
1172  {
1173  default:
1175  dx = -length;
1176  dy = height;
1177  x += Mils2iu( DANGLING_SYMBOL_SIZE );
1178  y -= height / 2;
1179  break;
1180 
1181  case LABEL_SPIN_STYLE::UP:
1182  dx = height;
1183  dy = -length;
1184  x -= height / 2;
1185  y += Mils2iu( DANGLING_SYMBOL_SIZE );
1186  break;
1187 
1189  dx = length;
1190  dy = height;
1191  x -= Mils2iu( DANGLING_SYMBOL_SIZE );
1192  y -= height / 2;
1193  break;
1194 
1196  dx = height;
1197  dy = length;
1198  x -= height / 2;
1199  y -= Mils2iu( DANGLING_SYMBOL_SIZE );
1200  break;
1201  }
1202 
1203  EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) );
1204  box.Normalize();
1205  return box;
1206 }
1207 
1208 
1210 {
1211  wxPoint text_offset;
1212  int dist = GetTextOffset( aSettings );
1213 
1214  dist += GetTextWidth();
1215 
1216  switch( GetLabelSpinStyle() )
1217  {
1218  default:
1219  case LABEL_SPIN_STYLE::LEFT: text_offset.x = -dist; break; // Orientation horiz normale
1220  case LABEL_SPIN_STYLE::UP: text_offset.y = -dist; break; // Orientation vert UP
1221  case LABEL_SPIN_STYLE::RIGHT: text_offset.x = dist; break; // Orientation horiz inverse
1222  case LABEL_SPIN_STYLE::BOTTOM: text_offset.y = dist; break; // Orientation vert BOTTOM
1223  }
1224 
1225  return text_offset;
1226 }
1227 
1228 
1230 {
1231  return wxString::Format( _( "Hierarchical Label '%s'" ), ShortenedShownText() );
1232 }
1233 
1234 
1236 {
1238 }
1239 
1240 
1241 HTML_MESSAGE_BOX* SCH_TEXT::ShowSyntaxHelp( wxWindow* aParentWindow )
1242 {
1243  wxString msg =
1244 #include "sch_text_help_md.h"
1245  ;
1246 
1247  HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
1248  dlg->SetDialogSizeInDU( 280, 280 );
1249 
1250  wxString html_txt;
1251  ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
1252  dlg->m_htmlWindow->AppendToPage( html_txt );
1253  dlg->ShowModeless();
1254 
1255  return dlg;
1256 }
#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:189
SCH_LAYER_ID m_Layer
Definition: sch_item.h:199
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:802
static int Template3STATE_HN[]
Definition: sch_text.cpp:106
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:43
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Definition: base_units.cpp:123
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: eda_item.h:163
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:150
static int TemplateUNSPC_HN[]
Definition: sch_text.cpp:96
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:140
static int Template3STATE_HI[]
Definition: sch_text.cpp:107
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
static int TemplateUNSPC_HI[]
Definition: sch_text.cpp:97
PROJECT holds project specific data.
Definition: project.h:63
PNG memory record (file in memory).
Definition: bitmap_def.h:29
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:44
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
static int TemplateOUT_UP[]
Definition: sch_text.cpp:93
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Adds a connection link between this item and another.
Definition: sch_item.cpp:186
LABEL_SPIN_STYLE m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:185
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections.
Definition: sch_text.h:172
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:540
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:1040
T MIRRORVAL(T aPoint, T aMirrorRef)
Function MIRROR Mirror aPoint in aMirrorRef.
Definition: macros.h:131
static int TemplateOUT_HN[]
Definition: sch_text.cpp:91
virtual wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const
Definition: sch_text.cpp:160
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_text.cpp:561
int color
Definition: DXF_plotter.cpp:60
EDA_RECT GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:222
static int TemplateUNSPC_UP[]
Definition: sch_text.cpp:98
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
static int TemplateIN_UP[]
Definition: sch_text.cpp:88
const BITMAP_OPAQUE text_xpm[1]
Definition: text.cpp:24
SCH_IREF * m_iref
Definition: sch_text.h:432
Definition: color4d.h:62
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
double GetTextAngle() const
Definition: eda_text.h:180
static int TemplateOUT_HI[]
Definition: sch_text.cpp:92
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:1109
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Draw a polygon ( filled or not )
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:549
static int TemplateBIDI_HI[]
Definition: sch_text.cpp:102
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:796
Schematic editor (Eeschema) main window.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
CONNECTION_TYPE
const BITMAP_OPAQUE add_hierarchical_label_xpm[1]
SCH_GLOBALLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:808
The base class for create windows for drawing purpose.
CONNECTION_TYPE m_connectionType
Definition: sch_text.h:174
const BITMAP_OPAQUE add_line_label_xpm[1]
bool Contains(const wxPoint &aPoint) const
Function Contains.
Definition: eda_rect.cpp:57
static int Template3STATE_BOTTOM[]
Definition: sch_text.cpp:109
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_text.cpp:193
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:156
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:1046
int GetTextHeight() const
Definition: eda_text.h:251
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:219
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:147
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
static int TemplateIN_BOTTOM[]
Definition: sch_text.cpp:89
int GetPenWidth() const override
Definition: sch_text.cpp:319
void SetTextX(int aX)
Definition: eda_text.h:256
wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const override
Definition: sch_text.cpp:1209
bool IsItalic() const
Definition: eda_text.h:186
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)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
static int TemplateOUT_BOTTOM[]
Definition: sch_text.cpp:94
virtual void CreateGraphicShape(RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos)
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.h:259
void GetContextualTextVars(wxArrayString *aVars) const
Returns the set of contextual text variable tokens for this text item.
Definition: sch_text.cpp:476
const wxPoint GetEnd() const
Definition: eda_rect.h:116
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:721
int LenSize(const wxString &aLine, int aThickness) const
Definition: eda_text.cpp:187
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:146
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:1062
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:120
#define NULL
#define DANGLING_SYMBOL_SIZE
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:143
void SetEnd(int x, int y)
Definition: eda_rect.h:192
static int TemplateIN_HI[]
Definition: sch_text.cpp:87
const wxSize & GetTextSize() const
Definition: eda_text.h:245
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
static int Template3STATE_UP[]
Definition: sch_text.cpp:108
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:170
Helper dialog and control classes.
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:201
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, COLOR4D aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:400
EDA_ITEM * GetItem() const
Definition: sch_item.h:141
static int TemplateBIDI_HN[]
Definition: sch_text.cpp:101
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:1068
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:985
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: eda_item.h:251
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:334
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1153
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:233
int GetTextOffset(RENDER_SETTINGS *aSettings) const
Definition: sch_text.cpp:308
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:441
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void CreateGraphicShape(RENDER_SETTINGS *aRenderSettings, std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:913
HTML_MESSAGE_BOX.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.cpp:486
wxPoint GetPosition() const override
Definition: sch_text.h:312
Definition: color4d.h:60
std::unordered_map< SCH_SHEET_PATH, SCH_ITEM_SET > m_connected_items
Stores pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:206
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:202
bool IsMultilineAllowed() const
Definition: eda_text.h:203
static int TemplateBIDI_BOTTOM[]
Definition: sch_text.cpp:104
This item represents a net.
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:796
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
wxString ExpandTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject, const std::function< bool(wxString *)> *aFallbackResolver)
Expand '${var-name}' templates in text.
Definition: common.cpp:58
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
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.
wxPoint m_savedIrefPos
Definition: sch_text.h:433
void Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
const BITMAP_OPAQUE add_glabel_xpm[1]
Definition: add_glabel.cpp:42
Base plotter engine class.
Definition: plotter.h:131
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:288
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_text.cpp:1241
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:142
Definition: color4d.h:57
PINSHEETLABEL_SHAPE
Definition: sch_text.h:151
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:165
int GetTextWidth() const
Definition: eda_text.h:248
static int TemplateBIDI_UP[]
Definition: sch_text.cpp:103
const char * name
Definition: DXF_plotter.cpp:59
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:581
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_text.cpp:431
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:897
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:208
#define TXT_MARGIN
The default pin len value when creating pins(can be changed in preference menu)
#define _(s)
Definition: 3d_actions.cpp:33
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:273
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_text.cpp:202
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:206
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:555
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:79
DANGLING_END_T GetType() const
Definition: sch_item.h:143
void Print(RENDER_SETTINGS *aSettings, const wxPoint &offset) override
Print a schematic item.
Definition: sch_text.cpp:325
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
static int * TemplateShape[5][4]
Definition: sch_text.cpp:111
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
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:345
void IncrementLabelMember(wxString &name, int aIncrement)
Definition: sch_text.cpp:54
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:103
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests 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:423
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:767
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:70
wxString getElectricalTypeLabel(PINSHEETLABEL_SHAPE aType)
Definition: sch_text.cpp:462
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
void CreateGraphicShape(RENDER_SETTINGS *aSettings, std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1129
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:168
Definitions of the SCH_IREF class and derivatives for Eeschema.
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:85
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:203
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:173
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:858
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_text.cpp:727
SCH_HIERLABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_HIER_LABEL_T)
Definition: sch_text.cpp:1052
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:820
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
static int TemplateUNSPC_BOTTOM[]
Definition: sch_text.cpp:99
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:232
bool IsBus() const
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:1229
Message panel definition file.
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_text.cpp:184
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:1235
SCH_TEXT(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:121
SCH_LABEL(const wxPoint &aPos=wxPoint(0, 0), const wxString &aText=wxEmptyString)
Definition: sch_text.cpp:711
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:140
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxPoint GetSchematicTextOffset(RENDER_SETTINGS *aSettings) const override
Definition: sch_text.cpp:826
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_text.cpp:623
This item represents a bus vector.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
static int TemplateIN_HN[]
Definition: sch_text.cpp:86
void SetTextY(int aY)
Definition: eda_text.h:257
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:238
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:121
void IncrementLabel(int aIncrement)
Increment the label text, if it ends with a number.
Definition: sch_text.cpp:152
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100