KiCad PCB EDA Suite
sch_sheet.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) 1992-2021 Kicad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <bitmaps.h>
26 #include <core/mirror.h>
27 #include <sch_draw_panel.h>
28 #include <gr_text.h>
29 #include <trigo.h>
30 #include <sch_edit_frame.h>
31 #include <plotter.h>
32 #include <kicad_string.h>
33 #include <widgets/msgpanel.h>
34 #include <math/util.h> // for KiROUND
35 #include <sch_sheet.h>
36 #include <sch_sheet_path.h>
37 #include <sch_sheet_pin.h>
38 #include <sch_symbol.h>
39 #include <sch_painter.h>
40 #include <schematic.h>
42 #include <trace_helpers.h>
43 #include <pgm_base.h>
44 
45 
46 const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx )
47 {
48  static void* locale = nullptr;
49  static wxString sheetnameDefault;
50  static wxString sheetfilenameDefault;
51  static wxString fieldDefault;
52 
53  // Fetching translations can take a surprising amount of time when loading libraries,
54  // so only do it when necessary.
55  if( Pgm().GetLocale() != locale )
56  {
57  sheetnameDefault = _( "Sheet name" );
58  sheetfilenameDefault = _( "Sheet file" );
59  fieldDefault = _( "Field%d" );
60  locale = Pgm().GetLocale();
61  }
62 
63  // Fixed values for the mandatory fields
64  switch( aFieldNdx )
65  {
66  case SHEETNAME: return sheetnameDefault;
67  case SHEETFILENAME: return sheetfilenameDefault;
68  default: return wxString::Format( fieldDefault, aFieldNdx );
69  }
70 }
71 
72 
73 SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const wxPoint& pos ) :
74  SCH_ITEM( aParent, SCH_SHEET_T )
75 {
77  m_pos = pos;
78  m_size = wxSize( Mils2iu( MIN_SHEET_WIDTH ), Mils2iu( MIN_SHEET_HEIGHT ) );
79  m_screen = NULL;
80 
81  for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
82  {
83  m_fields.emplace_back( pos, i, this, GetDefaultFieldName( i ) );
84  m_fields.back().SetVisible( true );
85 
86  if( i == SHEETNAME )
87  m_fields.back().SetLayer( LAYER_SHEETNAME );
88  else if( i == SHEETFILENAME )
89  m_fields.back().SetLayer( LAYER_SHEETFILENAME );
90  else
91  m_fields.back().SetLayer( LAYER_SHEETFIELDS );
92  }
93 
95 
96  m_borderWidth = 0;
97  m_borderColor = COLOR4D::UNSPECIFIED;
98  m_backgroundColor = COLOR4D::UNSPECIFIED;
99 }
100 
101 
102 SCH_SHEET::SCH_SHEET( const SCH_SHEET& aSheet ) :
103  SCH_ITEM( aSheet )
104 {
105  m_pos = aSheet.m_pos;
106  m_size = aSheet.m_size;
107  m_layer = aSheet.m_layer;
108  const_cast<KIID&>( m_Uuid ) = aSheet.m_Uuid;
109  m_fields = aSheet.m_fields;
111  m_screen = aSheet.m_screen;
112 
113  for( SCH_SHEET_PIN* pin : aSheet.m_pins )
114  {
115  m_pins.emplace_back( new SCH_SHEET_PIN( *pin ) );
116  m_pins.back()->SetParent( this );
117  }
118 
119  for( SCH_FIELD& field : m_fields )
120  field.SetParent( this );
121 
122  m_borderWidth = aSheet.m_borderWidth;
123  m_borderColor = aSheet.m_borderColor;
125  m_instances = aSheet.m_instances;
126 
127  if( m_screen )
129 }
130 
131 
133 {
134  // also, look at the associated sheet & its reference count
135  // perhaps it should be deleted also.
136  if( m_screen )
137  {
139 
140  if( m_screen->GetRefCount() == 0 )
141  delete m_screen;
142  }
143 
144  // We own our pins; delete them
145  for( SCH_SHEET_PIN* pin : m_pins )
146  delete pin;
147 }
148 
149 
151 {
152  return new SCH_SHEET( *this );
153 }
154 
155 
157 {
158  if( aScreen == m_screen )
159  return;
160 
161  if( m_screen != NULL )
162  {
164 
165  if( m_screen->GetRefCount() == 0 )
166  {
167  delete m_screen;
168  m_screen = NULL;
169  }
170  }
171 
172  m_screen = aScreen;
173 
174  if( m_screen )
176 }
177 
178 
180 {
181  if( m_screen == NULL )
182  return 0;
183 
184  return m_screen->GetRefCount();
185 }
186 
187 
189 {
190  wxCHECK_MSG( Schematic(), false, "Can't call IsRootSheet without setting a schematic" );
191 
192  return &Schematic()->Root() == this;
193 }
194 
195 
196 void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const
197 {
198  for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
199  aVars->push_back( m_fields[i].GetCanonicalName().Upper() );
200 
201  for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields.size(); ++i )
202  aVars->push_back( m_fields[i].GetName() );
203 
204  aVars->push_back( wxT( "#" ) );
205  aVars->push_back( wxT( "##" ) );
207 }
208 
209 
210 bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const
211 {
212  for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
213  {
214  if( token->IsSameAs( m_fields[i].GetCanonicalName().Upper() ) )
215  {
216  *token = m_fields[i].GetShownText( aDepth + 1 );
217  return true;
218  }
219  }
220 
221  for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields.size(); ++i )
222  {
223  if( token->IsSameAs( m_fields[i].GetName() ) )
224  {
225  *token = m_fields[i].GetShownText( aDepth + 1 );
226  return true;
227  }
228  }
229 
230  PROJECT *project = &Schematic()->Prj();
231 
232  if( m_screen->GetTitleBlock().TextVarResolver( token, project ) )
233  {
234  return true;
235  }
236 
237  if( token->IsSameAs( wxT( "#" ) ) )
238  {
239  for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
240  {
241  if( sheet.Last() == this ) // Current sheet path found
242  {
243  *token = wxString::Format( "%s", sheet.GetPageNumber() );
244  return true;
245  }
246  }
247  }
248  else if( token->IsSameAs( wxT( "##" ) ) )
249  {
250  SCH_SHEET_LIST sheetList = Schematic()->GetSheets();
251  *token = wxString::Format( wxT( "%d" ), (int) sheetList.size() );
252  return true;
253  }
254 
255  return false;
256 }
257 
258 
260 {
261  return m_borderWidth == 0 && m_borderColor == COLOR4D::UNSPECIFIED;
262 }
263 
264 
266 {
267  wxCHECK_RET( aItem->Type() == SCH_SHEET_T,
268  wxString::Format( wxT( "SCH_SHEET object cannot swap data with %s object." ),
269  aItem->GetClass() ) );
270 
271  SCH_SHEET* sheet = ( SCH_SHEET* ) aItem;
272 
273  std::swap( m_pos, sheet->m_pos );
274  std::swap( m_size, sheet->m_size );
275  m_fields.swap( sheet->m_fields );
276  std::swap( m_fieldsAutoplaced, sheet->m_fieldsAutoplaced );
277  m_pins.swap( sheet->m_pins );
278 
279  // Update parent pointers after swapping.
280  for( SCH_SHEET_PIN* sheetPin : m_pins )
281  sheetPin->SetParent( this );
282 
283  for( SCH_SHEET_PIN* sheetPin : sheet->m_pins )
284  sheetPin->SetParent( sheet );
285 
286  for( SCH_FIELD& field : m_fields )
287  field.SetParent( this );
288 
289  for( SCH_FIELD& field : sheet->m_fields )
290  field.SetParent( sheet );
291 
292  std::swap( m_borderWidth, sheet->m_borderWidth );
293  std::swap( m_borderColor, sheet->m_borderColor );
294  std::swap( m_backgroundColor, sheet->m_backgroundColor );
295  std::swap( m_instances, sheet->m_instances );
296 }
297 
298 
300 {
301  wxASSERT( aSheetPin != NULL );
302  wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
303 
304  aSheetPin->SetParent( this );
305  m_pins.push_back( aSheetPin );
306  renumberPins();
307 }
308 
309 
310 void SCH_SHEET::RemovePin( const SCH_SHEET_PIN* aSheetPin )
311 {
312  wxASSERT( aSheetPin != NULL );
313  wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
314 
315  for( auto i = m_pins.begin(); i < m_pins.end(); ++i )
316  {
317  if( *i == aSheetPin )
318  {
319  m_pins.erase( i );
320  renumberPins();
321  return;
322  }
323  }
324 }
325 
326 
327 bool SCH_SHEET::HasPin( const wxString& aName ) const
328 {
329  for( SCH_SHEET_PIN* pin : m_pins )
330  {
331  if( pin->GetText().CmpNoCase( aName ) == 0 )
332  return true;
333  }
334 
335  return false;
336 }
337 
338 
339 bool SCH_SHEET::doIsConnected( const wxPoint& aPosition ) const
340 {
341  for( SCH_SHEET_PIN* sheetPin : m_pins )
342  {
343  if( sheetPin->GetPosition() == aPosition )
344  return true;
345  }
346 
347  return false;
348 }
349 
350 
352 {
353  int leftRight = 0;
354  int topBottom = 0;
355 
356  for( SCH_SHEET_PIN* pin : m_pins )
357  {
358  switch( pin->GetEdge() )
359  {
360  case SHEET_LEFT_SIDE: leftRight++; break;
361  case SHEET_RIGHT_SIDE: leftRight++; break;
362  case SHEET_TOP_SIDE: topBottom++; break;
363  case SHEET_BOTTOM_SIDE: topBottom++; break;
364  default: break;
365  }
366  }
367 
368  return topBottom > 0 && leftRight == 0;
369 }
370 
371 
373 {
374  for( SCH_SHEET_PIN* pin : m_pins )
375  {
376  /* Search the schematic for a hierarchical label corresponding to this sheet label. */
377  const SCH_HIERLABEL* HLabel = nullptr;
378  for( auto aItem : m_screen->Items().OfType( SCH_HIER_LABEL_T ) )
379  {
380  if( !pin->GetText().CmpNoCase( static_cast<SCH_HIERLABEL*>( aItem )->GetText() ) )
381  {
382  HLabel = static_cast<SCH_HIERLABEL*>( aItem );
383  break;
384  }
385  }
386 
387  if( HLabel == nullptr ) // Corresponding hierarchical label not found.
388  return true;
389  }
390 
391  return false;
392 }
393 
394 
395 int bumpToNextGrid( const int aVal, const int aDirection )
396 {
397  constexpr int gridSize = Mils2iu( 50 );
398 
399  return ( KiROUND( aVal / gridSize ) * gridSize ) + ( aDirection * gridSize );
400 }
401 
402 
403 int SCH_SHEET::GetMinWidth( bool aFromLeft ) const
404 {
405  int pinsLeft = m_pos.x + m_size.x;
406  int pinsRight = m_pos.x;
407 
408  for( size_t i = 0; i < m_pins.size(); i++ )
409  {
410  int edge = m_pins[i]->GetEdge();
411 
412  if( edge == SHEET_TOP_SIDE || edge == SHEET_BOTTOM_SIDE )
413  {
414  EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
415 
416  pinsLeft = std::min( pinsLeft, pinRect.GetLeft() );
417  pinsRight = std::max( pinsRight, pinRect.GetRight() );
418  }
419  }
420 
421  pinsLeft = bumpToNextGrid( pinsLeft, -1 );
422  pinsRight = bumpToNextGrid( pinsRight, 1 );
423 
424  int pinMinWidth;
425 
426  if( pinsLeft >= pinsRight )
427  pinMinWidth = 0;
428  else if( aFromLeft )
429  pinMinWidth = pinsRight - m_pos.x;
430  else
431  pinMinWidth = m_pos.x + m_size.x - pinsLeft;
432 
433  return std::max( pinMinWidth, Mils2iu( MIN_SHEET_WIDTH ) );
434 }
435 
436 
437 int SCH_SHEET::GetMinHeight( bool aFromTop ) const
438 {
439  int pinsTop = m_pos.y + m_size.y;
440  int pinsBottom = m_pos.y;
441 
442  for( size_t i = 0; i < m_pins.size(); i++ )
443  {
444  int edge = m_pins[i]->GetEdge();
445 
446  if( edge == SHEET_RIGHT_SIDE || edge == SHEET_LEFT_SIDE )
447  {
448  EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
449 
450  pinsTop = std::min( pinsTop, pinRect.GetTop() );
451  pinsBottom = std::max( pinsBottom, pinRect.GetBottom() );
452  }
453  }
454 
455  pinsTop = bumpToNextGrid( pinsTop, -1 );
456  pinsBottom = bumpToNextGrid( pinsBottom, 1 );
457 
458  int pinMinHeight;
459 
460  if( pinsTop >= pinsBottom )
461  pinMinHeight = 0;
462  else if( aFromTop )
463  pinMinHeight = pinsBottom - m_pos.y;
464  else
465  pinMinHeight = m_pos.y + m_size.y - pinsTop;
466 
467  return std::max( pinMinHeight, Mils2iu( MIN_SHEET_HEIGHT ) );
468 }
469 
470 
472 {
473  auto i = m_pins.begin();
474 
475  while( i != m_pins.end() )
476  {
477  /* Search the schematic for a hierarchical label corresponding to this sheet label. */
478  const SCH_HIERLABEL* HLabel = NULL;
479 
480  for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_HIER_LABEL_T ) )
481  {
482  if( (*i)->GetText().CmpNoCase( static_cast<SCH_HIERLABEL*>( aItem )->GetText() ) == 0 )
483  {
484  HLabel = static_cast<SCH_HIERLABEL*>( aItem );
485  break;
486  }
487  }
488 
489  if( HLabel == NULL ) // Hlabel not found: delete sheet label.
490  i = m_pins.erase( i );
491  else
492  ++i;
493  }
494 }
495 
496 
497 SCH_SHEET_PIN* SCH_SHEET::GetPin( const wxPoint& aPosition )
498 {
499  for( SCH_SHEET_PIN* pin : m_pins )
500  {
501  if( pin->HitTest( aPosition ) )
502  return pin;
503  }
504 
505  return NULL;
506 }
507 
508 
510 {
511  return std::max( GetBorderWidth(), 1 );
512 }
513 
514 
515 void SCH_SHEET::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
516 {
517  wxSize textSize = m_fields[ SHEETNAME ].GetTextSize();
518  int borderMargin = KiROUND( GetPenWidth() / 2.0 ) + 4;
519  int margin = borderMargin + KiROUND( std::max( textSize.x, textSize.y ) * 0.5 );
520 
521  if( IsVerticalOrientation() )
522  {
523  m_fields[ SHEETNAME ].SetTextPos( m_pos + wxPoint( -margin, m_size.y ) );
524  m_fields[ SHEETNAME ].SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
525  m_fields[ SHEETNAME ].SetVertJustify(GR_TEXT_VJUSTIFY_BOTTOM );
526  m_fields[ SHEETNAME ].SetTextAngle( TEXT_ANGLE_VERT );
527  }
528  else
529  {
530  m_fields[ SHEETNAME ].SetTextPos( m_pos + wxPoint( 0, -margin ) );
531  m_fields[ SHEETNAME ].SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
532  m_fields[ SHEETNAME ].SetVertJustify(GR_TEXT_VJUSTIFY_BOTTOM );
533  m_fields[ SHEETNAME ].SetTextAngle( TEXT_ANGLE_HORIZ );
534  }
535 
536  textSize = m_fields[ SHEETFILENAME ].GetTextSize();
537  margin = borderMargin + KiROUND( std::max( textSize.x, textSize.y ) * 0.4 );
538 
539  if( IsVerticalOrientation() )
540  {
541  m_fields[ SHEETFILENAME ].SetTextPos( m_pos + wxPoint( m_size.x + margin, m_size.y ) );
542  m_fields[ SHEETFILENAME ].SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
543  m_fields[ SHEETFILENAME ].SetVertJustify(GR_TEXT_VJUSTIFY_TOP );
544  m_fields[ SHEETFILENAME ].SetTextAngle( TEXT_ANGLE_VERT );
545  }
546  else
547  {
548  m_fields[ SHEETFILENAME ].SetTextPos( m_pos + wxPoint( 0, m_size.y + margin ) );
549  m_fields[ SHEETFILENAME ].SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
550  m_fields[ SHEETFILENAME ].SetVertJustify(GR_TEXT_VJUSTIFY_TOP );
551  m_fields[ SHEETFILENAME ].SetTextAngle( TEXT_ANGLE_HORIZ );
552  }
553 
555 }
556 
557 
558 void SCH_SHEET::ViewGetLayers( int aLayers[], int& aCount ) const
559 {
560  aCount = 4;
561  aLayers[0] = LAYER_HIERLABEL;
562  aLayers[1] = LAYER_SHEET;
563  aLayers[2] = LAYER_SHEET_BACKGROUND;
564  aLayers[3] = LAYER_SELECTION_SHADOWS;
565 }
566 
567 
569 {
570  wxPoint end;
571  EDA_RECT box( m_pos, m_size );
572  int lineWidth = GetPenWidth();
573  int textLength = 0;
574 
575  // Calculate bounding box X size:
576  end.x = std::max( m_size.x, textLength );
577 
578  // Calculate bounding box pos:
579  end.y = m_size.y;
580  end += m_pos;
581 
582  box.SetEnd( end );
583  box.Inflate( lineWidth / 2 );
584 
585  return box;
586 }
587 
588 
590 {
592 
593  for( const SCH_FIELD& field : m_fields )
594  box.Merge( field.GetBoundingBox() );
595 
596  return box;
597 }
598 
599 
601 {
602  EDA_RECT box( m_pos, m_size );
603  return box.GetCenter();
604 }
605 
606 
608 {
609  int n = 0;
610 
611  if( m_screen )
612  {
613  for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_COMPONENT_T ) )
614  {
615  SCH_COMPONENT* symbol = (SCH_COMPONENT*) aItem;
616 
617  if( symbol->GetField( VALUE_FIELD )->GetText().GetChar( 0 ) != '#' )
618  n++;
619  }
620 
621  for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
622  n += static_cast<const SCH_SHEET*>( aItem )->SymbolCount();
623  }
624 
625  return n;
626 }
627 
628 
629 bool SCH_SHEET::SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen )
630 {
631  if( m_screen )
632  {
633  // Only check the root sheet once and don't recurse.
634  if( !GetParent() )
635  {
636  if( m_screen && m_screen->GetFileName().Cmp( aFilename ) == 0 )
637  {
638  *aScreen = m_screen;
639  return true;
640  }
641  }
642 
643  for( auto aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
644  {
645  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
646  SCH_SCREEN* screen = sheet->m_screen;
647 
648  // Must use the screen's path (which is always absolute) rather than the
649  // sheet's (which could be relative).
650  if( screen && screen->GetFileName().Cmp( aFilename ) == 0 )
651  {
652  *aScreen = screen;
653  return true;
654  }
655 
656  if( sheet->SearchHierarchy( aFilename, aScreen ) )
657  return true;
658  }
659  }
660 
661  return false;
662 }
663 
664 
666 {
667  if( m_screen )
668  {
669  aList->push_back( this );
670 
671  if( m_screen == aScreen )
672  return true;
673 
674  for( auto item : m_screen->Items().OfType( SCH_SHEET_T ) )
675  {
676  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
677 
678  if( sheet->LocatePathOfScreen( aScreen, aList ) )
679  {
680  return true;
681  }
682  }
683 
684  aList->pop_back();
685  }
686 
687  return false;
688 }
689 
690 
692 {
693  int count = 1; //1 = this!!
694 
695  if( m_screen )
696  {
697  for( auto aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
698  count += static_cast<SCH_SHEET*>( aItem )->CountSheets();
699  }
700 
701  return count;
702 }
703 
704 
706 {
707  aList.emplace_back( _( "Sheet Name" ), m_fields[ SHEETNAME ].GetText() );
708 
709  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
710  {
711  SCH_SHEET_PATH path = schframe->GetCurrentSheet();
712  path.push_back( this );
713 
714  aList.emplace_back( _( "Hierarchical Path" ), path.PathHumanReadable( false ) );
715  }
716 
717  aList.emplace_back( _( "File Name" ), m_fields[ SHEETFILENAME ].GetText() );
718 }
719 
720 
721 void SCH_SHEET::Move( const wxPoint& aMoveVector )
722 {
723  m_pos += aMoveVector;
724 
725  for( SCH_SHEET_PIN* pin : m_pins )
726  pin->Move( aMoveVector );
727 
728  for( SCH_FIELD& field : m_fields )
729  field.Move( aMoveVector );
730 }
731 
732 
733 void SCH_SHEET::Rotate( wxPoint aCenter )
734 {
735  wxPoint prev = m_pos;
736 
737  RotatePoint( &m_pos, aCenter, 900 );
738  RotatePoint( &m_size.x, &m_size.y, 900 );
739 
740  if( m_size.x < 0 )
741  {
742  m_pos.x += m_size.x;
743  m_size.x = -m_size.x;
744  }
745 
746  if( m_size.y < 0 )
747  {
748  m_pos.y += m_size.y;
749  m_size.y = -m_size.y;
750  }
751 
752  // Pins must be rotated first as that's how we determine vertical vs horizontal
753  // orientation for auto-placement
754  for( SCH_SHEET_PIN* sheetPin : m_pins )
755  sheetPin->Rotate( aCenter );
756 
758  {
759  AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
760  }
761  else
762  {
763  // Move the fields to the new position because the parent itself has moved.
764  for( SCH_FIELD& field : m_fields )
765  {
766  wxPoint pos = field.GetTextPos();
767  pos.x -= prev.x - m_pos.x;
768  pos.y -= prev.y - m_pos.y;
769  field.SetTextPos( pos );
770  }
771  }
772 }
773 
774 
775 void SCH_SHEET::MirrorVertically( int aCenter )
776 {
777  MIRROR( m_pos.y, aCenter );
778  m_pos.y -= m_size.y;
779 
780  for( SCH_SHEET_PIN* sheetPin : m_pins )
781  sheetPin->MirrorVertically( aCenter );
782 }
783 
784 
785 void SCH_SHEET::MirrorHorizontally( int aCenter )
786 {
787  MIRROR( m_pos.x, aCenter );
788  m_pos.x -= m_size.x;
789 
790  for( SCH_SHEET_PIN* sheetPin : m_pins )
791  sheetPin->MirrorHorizontally( aCenter );
792 }
793 
794 
795 void SCH_SHEET::SetPosition( const wxPoint& aPosition )
796 {
797  // Remember the sheet and all pin sheet positions must be
798  // modified. So use Move function to do that.
799  Move( aPosition - m_pos );
800 }
801 
802 
803 void SCH_SHEET::Resize( const wxSize& aSize )
804 {
805  if( aSize == m_size )
806  return;
807 
808  m_size = aSize;
809 
810  // Move the fields if we're in autoplace mode
812  AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
813 
814  // Move the sheet labels according to the new sheet size.
815  for( SCH_SHEET_PIN* sheetPin : m_pins )
816  sheetPin->ConstrainOnEdge( sheetPin->GetPosition() );
817 }
818 
819 
820 bool SCH_SHEET::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
821 {
822  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText( EDA_UNITS::MILLIMETRES ) );
823 
824  // Sheets are searchable via the child field and pin item text.
825  return false;
826 }
827 
828 
830 {
831  int id = 2;
832 
833  for( SCH_SHEET_PIN* pin : m_pins )
834  {
835  pin->SetNumber( id );
836  id++;
837  }
838 }
839 
840 
841 void SCH_SHEET::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
842 {
843  for( SCH_SHEET_PIN* sheetPin : m_pins )
844  {
845  wxCHECK2_MSG( sheetPin->Type() == SCH_SHEET_PIN_T, continue,
846  wxT( "Invalid item in schematic sheet pin list. Bad programmer!" ) );
847 
848  sheetPin->GetEndPoints( aItemList );
849  }
850 }
851 
852 
853 bool SCH_SHEET::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
854  const SCH_SHEET_PATH* aPath )
855 {
856  bool changed = false;
857 
858  for( SCH_SHEET_PIN* sheetPin : m_pins )
859  changed |= sheetPin->UpdateDanglingState( aItemList );
860 
861  return changed;
862 }
863 
864 
865 std::vector<wxPoint> SCH_SHEET::GetConnectionPoints() const
866 {
867  std::vector<wxPoint> retval;
868 
869  for( SCH_SHEET_PIN* sheetPin : m_pins )
870  retval.push_back( sheetPin->GetPosition() );
871 
872  return retval;
873 }
874 
875 
876 SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, const KICAD_T aFilterTypes[] )
877 {
878  KICAD_T stype;
879 
880  for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
881  {
882  // If caller wants to inspect my type
883  if( stype == SCH_LOCATE_ANY_T || stype == Type() )
884  {
885  if( SEARCH_RESULT::QUIT == aInspector( this, NULL ) )
886  return SEARCH_RESULT::QUIT;
887  }
888 
889  if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T )
890  {
891  // Test the sheet fields.
892  for( SCH_FIELD& field : m_fields )
893  {
894  if( SEARCH_RESULT::QUIT == aInspector( &field, this ) )
895  return SEARCH_RESULT::QUIT;
896  }
897  }
898 
899  if( stype == SCH_LOCATE_ANY_T || stype == SCH_SHEET_PIN_T )
900  {
901  // Test the sheet labels.
902  for( SCH_SHEET_PIN* sheetPin : m_pins )
903  {
904  if( SEARCH_RESULT::QUIT == aInspector( sheetPin, this ) )
905  return SEARCH_RESULT::QUIT;
906  }
907  }
908  }
909 
911 }
912 
913 
914 void SCH_SHEET::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
915 {
916  for( SCH_FIELD& field : m_fields )
917  aFunction( &field );
918 
919  for( SCH_SHEET_PIN* pin : m_pins )
920  aFunction( pin );
921 }
922 
923 
924 wxString SCH_SHEET::GetSelectMenuText( EDA_UNITS aUnits ) const
925 {
926  return wxString::Format( _( "Hierarchical Sheet %s" ),
927  m_fields[ SHEETNAME ].GetText() );
928 }
929 
930 
932 {
934 }
935 
936 
937 bool SCH_SHEET::HitTest( const wxPoint& aPosition, int aAccuracy ) const
938 {
939  EDA_RECT rect = GetBodyBoundingBox();
940 
941  rect.Inflate( aAccuracy );
942 
943  return rect.Contains( aPosition );
944 }
945 
946 
947 bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
948 {
949  EDA_RECT rect = aRect;
950 
951  rect.Inflate( aAccuracy );
952 
953  if( aContained )
954  return rect.Contains( GetBodyBoundingBox() );
955 
956  return rect.Intersects( GetBodyBoundingBox() );
957 }
958 
959 
960 void SCH_SHEET::Plot( PLOTTER* aPlotter ) const
961 {
962  wxString msg;
963  wxPoint pos;
964  auto* settings = dynamic_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
965  bool override = settings ? settings->m_OverrideItemColors : false;
966  COLOR4D borderColor = GetBorderColor();
967  COLOR4D backgroundColor = GetBackgroundColor();
968 
969  if( override || borderColor == COLOR4D::UNSPECIFIED )
970  borderColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_SHEET );
971 
972  if( override || backgroundColor == COLOR4D::UNSPECIFIED )
973  backgroundColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_SHEET_BACKGROUND );
974 
975  aPlotter->SetColor( backgroundColor );
976  // Do not fill shape in B&W mode, otherwise texts are unreadable
977  bool fill = aPlotter->GetColorMode();
978 
980  1.0 );
981 
982  aPlotter->SetColor( borderColor );
983 
984  int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );
985  aPlotter->SetCurrentLineWidth( penWidth );
986 
987  aPlotter->MoveTo( m_pos );
988  pos = m_pos;
989  pos.x += m_size.x;
990 
991  aPlotter->LineTo( pos );
992  pos.y += m_size.y;
993 
994  aPlotter->LineTo( pos );
995  pos = m_pos;
996  pos.y += m_size.y;
997 
998  aPlotter->LineTo( pos );
999  aPlotter->FinishTo( m_pos );
1000 
1001  for( SCH_FIELD field : m_fields )
1002  field.Plot( aPlotter );
1003 
1004  /* Draw texts : SheetLabel */
1005  for( SCH_SHEET_PIN* sheetPin : m_pins )
1006  sheetPin->Plot( aPlotter );
1007 }
1008 
1009 
1010 void SCH_SHEET::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
1011 {
1012  wxDC* DC = aSettings->GetPrintDC();
1013  wxPoint pos = m_pos + aOffset;
1014  int lineWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
1015  const auto* settings = dynamic_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
1016  bool override = settings && settings->m_OverrideItemColors;
1017  COLOR4D border = GetBorderColor();
1018  COLOR4D background = GetBackgroundColor();
1019 
1020  if( override || border == COLOR4D::UNSPECIFIED )
1021  border = aSettings->GetLayerColor( LAYER_SHEET );
1022 
1023  if( override || background == COLOR4D::UNSPECIFIED )
1024  background = aSettings->GetLayerColor( LAYER_SHEET_BACKGROUND );
1025 
1026  if( GetGRForceBlackPenState() ) // printing in black & white
1027  background = COLOR4D::UNSPECIFIED;
1028 
1029  if( background != COLOR4D::UNSPECIFIED )
1030  {
1031  GRFilledRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, 0,
1032  background, background );
1033  }
1034 
1035  GRRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, lineWidth, border );
1036 
1037  for( SCH_FIELD& field : m_fields )
1038  field.Print( aSettings, aOffset );
1039 
1040  /* Draw text : SheetLabel */
1041  for( SCH_SHEET_PIN* sheetPin : m_pins )
1042  sheetPin->Print( aSettings, aOffset );
1043 }
1044 
1045 
1047 {
1048  wxCHECK_MSG( Type() == aItem.Type(), *this,
1049  wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
1050  GetClass() );
1051 
1052  if( &aItem != this )
1053  {
1054  SCH_ITEM::operator=( aItem );
1055 
1056  SCH_SHEET* sheet = (SCH_SHEET*) &aItem;
1057 
1058  m_pos = sheet->m_pos;
1059  m_size = sheet->m_size;
1060  m_fields = sheet->m_fields;
1061 
1062  for( SCH_SHEET_PIN* pin : sheet->m_pins )
1063  {
1064  m_pins.emplace_back( new SCH_SHEET_PIN( *pin ) );
1065  m_pins.back()->SetParent( this );
1066  }
1067 
1068  for( const SCH_SHEET_INSTANCE& instance : sheet->m_instances )
1069  m_instances.emplace_back( instance );
1070  }
1071 
1072  return *this;
1073 }
1074 
1075 
1076 bool SCH_SHEET::operator <( const SCH_ITEM& aItem ) const
1077 {
1078  if( Type() != aItem.Type() )
1079  return Type() < aItem.Type();
1080 
1081  auto sheet = static_cast<const SCH_SHEET*>( &aItem );
1082 
1083  if (m_fields[ SHEETNAME ].GetText() != sheet->m_fields[ SHEETNAME ].GetText() )
1084  return m_fields[ SHEETNAME ].GetText() < sheet->m_fields[ SHEETNAME ].GetText();
1085 
1086  if (m_fields[ SHEETFILENAME ].GetText() != sheet->m_fields[ SHEETFILENAME ].GetText() )
1087  return m_fields[ SHEETFILENAME ].GetText() < sheet->m_fields[ SHEETFILENAME ].GetText();
1088 
1089  return false;
1090 }
1091 
1092 
1093 bool SCH_SHEET::AddInstance( const KIID_PATH& aSheetPath )
1094 {
1095  // a empty sheet path is illegal:
1096  wxCHECK( aSheetPath.size() > 0, false );
1097 
1098  wxString path;
1099 
1100  for( const SCH_SHEET_INSTANCE& instance : m_instances )
1101  {
1102  // if aSheetPath is found, nothing to do:
1103  if( instance.m_Path == aSheetPath )
1104  return false;
1105  }
1106 
1107  SCH_SHEET_INSTANCE instance;
1108 
1109  instance.m_Path = aSheetPath;
1110 
1111  // This entry does not exist: add it with an empty page number.
1112  m_instances.emplace_back( instance );
1113  return true;
1114 }
1115 
1116 
1117 wxString SCH_SHEET::GetPageNumber( const SCH_SHEET_PATH& aInstance ) const
1118 {
1119  wxString pageNumber;
1120  KIID_PATH path = aInstance.Path();
1121 
1122  for( const SCH_SHEET_INSTANCE& instance : m_instances )
1123  {
1124  if( instance.m_Path == path )
1125  {
1126  pageNumber = instance.m_PageNumber;
1127  break;
1128  }
1129  }
1130 
1131  return pageNumber;
1132 }
1133 
1134 
1135 void SCH_SHEET::SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber )
1136 {
1137  KIID_PATH path = aInstance.Path();
1138 
1139  for( SCH_SHEET_INSTANCE& instance : m_instances )
1140  {
1141  if( instance.m_Path == path )
1142  {
1143  instance.m_PageNumber = aPageNumber;
1144  break;
1145  }
1146  }
1147 }
1148 
1149 
1150 int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString aPageNumberB )
1151 {
1152  if( aPageNumberA == aPageNumberB )
1153  return 0; // A == B
1154 
1155  // First sort numerically if the page numbers are integers
1156  long pageA, pageB;
1157  bool isIntegerPageA = aPageNumberA.ToLong( &pageA );
1158  bool isIntegerPageB = aPageNumberB.ToLong( &pageB );
1159 
1160  if( isIntegerPageA && isIntegerPageB )
1161  {
1162  if( pageA < pageB )
1163  return -1; //A < B
1164  else
1165  return 1; // A > B
1166  }
1167 
1168  // Numerical page numbers always before strings
1169  if( isIntegerPageA )
1170  return -1; //A < B
1171  else if( isIntegerPageB )
1172  return 1; // A > B
1173 
1174  // If not numeric, then sort as strings
1175  int result = aPageNumberA.Cmp( aPageNumberB );
1176 
1177  if( result > 0 )
1178  return 1; // A > B
1179 
1180  return -1; //A < B
1181 }
1182 
1183 
1184 #if defined(DEBUG)
1185 
1186 void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const
1187 {
1188  // XML output:
1189  wxString s = GetClass();
1190 
1191  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">" << " sheet_name=\""
1192  << TO_UTF8( m_fields[ SHEETNAME ].GetText() ) << '"' << ">\n";
1193 
1194  // show all the pins, and check the linked list integrity
1195  for( SCH_SHEET_PIN* sheetPin : m_pins )
1196  sheetPin->Show( nestLevel + 1, os );
1197 
1198  NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n" << std::flush;
1199 }
1200 
1201 #endif
void FinishTo(const wxPoint &pos)
Definition: plotter.h:267
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
#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
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:216
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
const wxString & GetFileName() const
Definition: sch_screen.h:133
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_sheet.cpp:558
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:629
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:497
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:775
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:431
Container for project specific data.
Definition: project.h:62
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:458
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:665
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
virtual void SetColor(COLOR4D color)=0
int GetTop() const
Definition: eda_rect.h:118
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
int GetMinWidth(bool aFromLeft) const
Return the minimum width of the sheet based on the widths of the sheet pin text.
Definition: sch_sheet.cpp:403
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_sheet.cpp:841
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void GRFilledRect(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:882
friend class SCH_SHEET_PIN
Definition: sch_sheet.h:447
int GetLeft() const
Definition: eda_rect.h:117
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:156
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:196
wxSize m_size
Definition: sch_sheet.h:456
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:339
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:372
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:138
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:111
bool UsesDefaultStroke() const
Test this sheet to see if the default stroke is used to draw the outline.
Definition: sch_sheet.cpp:259
Schematic editor (Eeschema) main window.
int GetMinHeight(bool aFromTop) const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
Definition: sch_sheet.cpp:437
static int ComparePageNum(const wxString &aPageNumberA, const wxString aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1150
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
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_sheet.cpp:924
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1076
The base class for create windows for drawing purpose.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:785
wxPoint m_pos
Definition: sch_sheet.h:455
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:299
static void GetContextualTextVars(wxArrayString *aVars)
Definition: title_block.cpp:73
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:498
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1135
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:95
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
std::vector< SCH_SHEET_INSTANCE > m_instances
Definition: sch_sheet.h:461
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:37
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:166
int GetBottom() const
Definition: eda_rect.h:119
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
void pop_back()
Forwarded method from std::vector.
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:960
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:114
void Rotate(wxPoint aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:733
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:179
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
void LineTo(const wxPoint &pos)
Definition: plotter.h:262
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:829
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_sheet.cpp:705
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:72
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:842
int GetBorderWidth() const
Definition: sch_sheet.h:108
SCH_LAYER_ID m_layer
Definition: sch_item.h:496
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:931
Field Value of part, i.e. "3.3K".
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:589
#define NULL
SCH_SHEET(EDA_ITEM *aParent=nullptr, const wxPoint &pos=wxPoint(0, 0))
Definition: sch_sheet.cpp:73
int m_borderWidth
Definition: sch_sheet.h:457
void SetEnd(int x, int y)
Definition: eda_rect.h:187
int GetPenWidth() const override
Definition: sch_sheet.cpp:509
bool IsRootSheet() const
Definition: sch_sheet.cpp:188
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:452
int GetRight() const
Definition: eda_rect.h:116
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_sheet.cpp:876
EDA_ITEM * GetParent() const
Definition: eda_item.h:165
const EDA_RECT GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
Definition: sch_sheet.cpp:568
wxLogTrace helper definitions.
wxDC * GetPrintDC() const
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:46
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
int SymbolCount() const
Count our own symbols, without the power symbols.
Definition: sch_sheet.cpp:607
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:865
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:471
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:177
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:310
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
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_sheet.cpp:1010
const KIID m_Uuid
Definition: eda_item.h:525
void MoveTo(const wxPoint &pos)
Definition: plotter.h:257
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
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:453
EDA_UNITS
Definition: eda_units.h:38
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:691
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
void DecRefCount()
Definition: sch_screen.cpp:112
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:665
Base plotter engine class.
Definition: plotter.h:121
SCH_SHEET & Root() const
Definition: schematic.h:92
A simple container for sheet instance information.
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:155
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_sheet.cpp:265
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:914
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:150
see class PGM_BASE
const wxChar *const traceFindItem
Flag to enable find debug tracing.
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
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_sheet.cpp:853
#define _(s)
Definition: 3d_actions.cpp:33
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:351
void SetPosition(const wxPoint &aPosition) override
Definition: sch_sheet.cpp:795
EE_RTREE & Items()
Definition: sch_screen.h:103
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:459
Handle the component boundary box.
Definition: eda_rect.h:42
Schematic symbol object.
Definition: sch_symbol.h:78
SCH_SCREEN * m_screen
Definition: sch_sheet.h:449
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
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:38
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
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:206
int GetDefaultPenWidth() const
wxPoint GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:600
bool TextVarResolver(wxString *aToken, const PROJECT *aProject) const
Definition: title_block.cpp:91
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
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:515
const wxPoint GetCenter() const
Definition: eda_rect.h:109
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:209
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:820
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:327
SEARCH_RESULT
Definition: eda_item.h:41
Message panel definition file.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:721
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
int bumpToNextGrid(const int aVal, const int aDirection)
Definition: sch_sheet.cpp:395
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1117
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1046
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
void IncRefCount()
Definition: sch_screen.cpp:106
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1093
int GetRefCount() const
Definition: sch_screen.h:144
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:803
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_sheet.cpp:937
bool GetColorMode() const
Definition: plotter.h:152