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