KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <cstdlib>
27
28#include <bitmaps.h>
29#include <core/mirror.h>
30#include <core/kicad_algo.h>
31#include <sch_draw_panel.h>
32#include <trigo.h>
33#include <sch_edit_frame.h>
34#include <plotters/plotter.h>
35#include <sch_plotter.h>
36#include <string_utils.h>
37#include <widgets/msgpanel.h>
38#include <math/util.h> // for KiROUND
39#include <sch_sheet.h>
40#include <sch_sheet_path.h>
41#include <sch_sheet_pin.h>
42#include <sch_symbol.h>
43#include <sch_painter.h>
44#include <schematic.h>
47#include <trace_helpers.h>
48#include <pgm_base.h>
49#include <wx/log.h>
50
51// N.B. Do not change these values without transitioning the file format
52#define SHEET_NAME_CANONICAL "Sheetname"
53#define SHEET_FILE_CANONICAL "Sheetfile"
54#define USER_FIELD_CANONICAL "Field%d"
55
58
59const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated )
60{
61 if( !aTranslated )
62 {
63 switch( aFieldNdx )
64 {
67 default: return wxString::Format( wxS( USER_FIELD_CANONICAL ), aFieldNdx );
68 }
69 }
70 else
71 {
72 switch( aFieldNdx )
73 {
74 case SHEETNAME: return _( SHEET_NAME_CANONICAL );
75 case SHEETFILENAME: return _( SHEET_FILE_CANONICAL );
76 default: return wxString::Format( _( USER_FIELD_CANONICAL ), aFieldNdx );
77 }
78 }
79}
80
81
82SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const VECTOR2I& aPos, VECTOR2I aSize ) :
83 SCH_ITEM( aParent, SCH_SHEET_T ),
84 m_excludedFromSim( false ),
85 m_excludedFromBOM( false ),
86 m_excludedFromBoard( false ),
87 m_DNP( false )
88{
90 m_pos = aPos;
91 m_size = aSize;
92 m_screen = nullptr;
93
94 m_borderWidth = 0;
95 m_borderColor = COLOR4D::UNSPECIFIED;
96 m_backgroundColor = COLOR4D::UNSPECIFIED;
98
99 m_fields.emplace_back( aPos, SHEETNAME, this, GetDefaultFieldName( SHEETNAME, DO_TRANSLATE ) );
100 m_fields.back().SetVisible( true );
101 m_fields.back().SetLayer( LAYER_SHEETNAME );
102
103 m_fields.emplace_back( aPos, SHEETFILENAME, this,
105 m_fields.back().SetVisible( true );
106 m_fields.back().SetLayer( LAYER_SHEETNAME );
107
109}
110
111
113 SCH_ITEM( aSheet )
114{
115 m_pos = aSheet.m_pos;
116 m_size = aSheet.m_size;
117 m_layer = aSheet.m_layer;
118 const_cast<KIID&>( m_Uuid ) = aSheet.m_Uuid;
119 m_fields = aSheet.m_fields;
121 m_screen = aSheet.m_screen;
122
126 m_DNP = aSheet.m_DNP;
127
131 m_instances = aSheet.m_instances;
132
133 for( SCH_SHEET_PIN* pin : aSheet.m_pins )
134 {
135 m_pins.emplace_back( new SCH_SHEET_PIN( *pin ) );
136 m_pins.back()->SetParent( this );
137 }
138
139 for( SCH_FIELD& field : m_fields )
140 field.SetParent( this );
141
142 if( m_screen )
144}
145
146
148{
149 // also, look at the associated sheet & its reference count
150 // perhaps it should be deleted also.
151 if( m_screen )
152 {
154
155 if( m_screen->GetRefCount() == 0 )
156 delete m_screen;
157 }
158
159 // We own our pins; delete them
160 for( SCH_SHEET_PIN* pin : m_pins )
161 delete pin;
162}
163
164
166{
167 return new SCH_SHEET( *this );
168}
169
170
172{
173 if( aScreen == m_screen )
174 return;
175
176 if( m_screen != nullptr )
177 {
179
180 if( m_screen->GetRefCount() == 0 )
181 {
182 delete m_screen;
183 m_screen = nullptr;
184 }
185 }
186
187 m_screen = aScreen;
188
189 if( m_screen )
191}
192
193
195{
196 if( m_screen == nullptr )
197 return 0;
198
199 return m_screen->GetRefCount();
200}
201
202
204{
205 wxCHECK_MSG( Schematic(), false, "Can't call IsRootSheet without setting a schematic" );
206
207 return &Schematic()->Root() == this;
208}
209
210
211void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const
212{
213 auto add =
214 [&]( const wxString& aVar )
215 {
216 if( !alg::contains( *aVars, aVar ) )
217 aVars->push_back( aVar );
218 };
219
220 for( const SCH_FIELD& field : m_fields )
221 {
222 if( field.IsMandatory() )
223 add( field.GetCanonicalName().Upper() );
224 else
225 add( field.GetName() );
226 }
227
228 SCH_SHEET_PATH sheetPath = findSelf();
229
230 if( sheetPath.size() >= 2 )
231 {
232 sheetPath.pop_back();
233 sheetPath.Last()->GetContextualTextVars( aVars );
234 }
235 else if( Schematic() )
236 {
238 }
239
240 add( wxT( "#" ) );
241 add( wxT( "##" ) );
242 add( wxT( "SHEETPATH" ) );
243 add( wxT( "EXCLUDE_FROM_BOM" ) );
244 add( wxT( "EXCLUDE_FROM_BOARD" ) );
245 add( wxT( "EXCLUDE_FROM_SIM" ) );
246 add( wxT( "DNP" ) );
247 add( wxT( "ERC_ERROR <message_text>" ) );
248 add( wxT( "ERC_WARNING <message_text>" ) );
249
251}
252
253
254bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
255{
256 wxCHECK( aPath, false );
257
258 SCHEMATIC* schematic = Schematic();
259
260 if( !schematic )
261 return false;
262
263 if( token->Contains( ':' ) )
264 {
265 if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
266 return true;
267 }
268
269 for( const SCH_FIELD& field : m_fields )
270 {
271 wxString fieldName = field.IsMandatory() ? field.GetCanonicalName().Upper()
272 : field.GetName();
273
274 if( token->IsSameAs( fieldName ) )
275 {
276 *token = field.GetShownText( aPath, false, aDepth + 1 );
277 return true;
278 }
279 }
280
281 PROJECT* project = &schematic->Prj();
282
283 // We cannot resolve text variables initially on load as we need to first load the screen and
284 // then parse the hierarchy. So skip the resolution if the screen isn't set yet
286 {
287 return true;
288 }
289
290 if( token->IsSameAs( wxT( "#" ) ) )
291 {
292 *token = wxString::Format( "%s", aPath->GetPageNumber() );
293 return true;
294 }
295 else if( token->IsSameAs( wxT( "##" ) ) )
296 {
297 *token = wxString::Format( wxT( "%d" ), (int) schematic->Hierarchy().size() );
298 return true;
299 }
300 else if( token->IsSameAs( wxT( "SHEETPATH" ) ) )
301 {
302 *token = aPath->PathHumanReadable();
303 return true;
304 }
305 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOM" ) ) )
306 {
307 *token = wxEmptyString;
308
309 if( aPath->GetExcludedFromBOM() || this->GetExcludedFromBOM() )
310 *token = _( "Excluded from BOM" );
311
312 return true;
313 }
314 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOARD" ) ) )
315 {
316 *token = wxEmptyString;
317
318 if( aPath->GetExcludedFromBoard() || this->GetExcludedFromBoard() )
319 *token = _( "Excluded from board" );
320
321 return true;
322 }
323 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_SIM" ) ) )
324 {
325 *token = wxEmptyString;
326
327 if( aPath->GetExcludedFromSim() || this->GetExcludedFromSim() )
328 *token = _( "Excluded from simulation" );
329
330 return true;
331 }
332 else if( token->IsSameAs( wxT( "DNP" ) ) )
333 {
334 *token = wxEmptyString;
335
336 if( aPath->GetDNP() || this->GetDNP() )
337 *token = _( "DNP" );
338
339 return true;
340 }
341
342 // See if parent can resolve it (these will recurse to ancestors)
343
344 if( aPath->size() >= 2 )
345 {
346 SCH_SHEET_PATH path = *aPath;
347 path.pop_back();
348
349 if( path.Last()->ResolveTextVar( &path, token, aDepth + 1 ) )
350 return true;
351 }
352 else
353 {
354 if( schematic->ResolveTextVar( aPath, token, aDepth + 1 ) )
355 return true;
356 }
357
358 return false;
359}
360
361
363{
364 SCH_ITEM::SwapFlags( aItem );
365
366 wxCHECK_RET( aItem->Type() == SCH_SHEET_T,
367 wxString::Format( wxT( "SCH_SHEET object cannot swap data with %s object." ),
368 aItem->GetClass() ) );
369
370 SCH_SHEET* sheet = ( SCH_SHEET* ) aItem;
371
372 std::swap( m_pos, sheet->m_pos );
373 std::swap( m_size, sheet->m_size );
374 m_fields.swap( sheet->m_fields );
375 std::swap( m_fieldsAutoplaced, sheet->m_fieldsAutoplaced );
376 m_pins.swap( sheet->m_pins );
377
378 // Update parent pointers after swapping.
379 for( SCH_SHEET_PIN* sheetPin : m_pins )
380 sheetPin->SetParent( this );
381
382 for( SCH_SHEET_PIN* sheetPin : sheet->m_pins )
383 sheetPin->SetParent( sheet );
384
385 for( SCH_FIELD& field : m_fields )
386 field.SetParent( this );
387
388 for( SCH_FIELD& field : sheet->m_fields )
389 field.SetParent( sheet );
390
391 std::swap( m_excludedFromSim, sheet->m_excludedFromSim );
392 std::swap( m_excludedFromBOM, sheet->m_excludedFromBOM );
393 std::swap( m_excludedFromBoard, sheet->m_excludedFromBoard );
394 std::swap( m_DNP, sheet->m_DNP );
395
396 std::swap( m_borderWidth, sheet->m_borderWidth );
397 std::swap( m_borderColor, sheet->m_borderColor );
398 std::swap( m_backgroundColor, sheet->m_backgroundColor );
399 std::swap( m_instances, sheet->m_instances );
400}
401
402
403void SCH_SHEET::SetFields( const std::vector<SCH_FIELD>& aFields )
404{
405 m_fields = aFields;
406
407 // Ensure that mandatory fields are at the beginning
408 std::sort( m_fields.begin(), m_fields.end(),
409 []( const SCH_FIELD& a, const SCH_FIELD& b )
410 {
411 return a.GetId() < b.GetId();
412 } );
413
414 // After mandatory fields, the rest should be sequential user fields
415 for( int ii = 0; ii < static_cast<int>( m_fields.size() ); ++ii )
416 {
417 if( !m_fields[ii].IsMandatory() )
418 m_fields[ii].SetId( ii );
419 }
420
421 // Make sure that we get the UNIX variant of the file path
422 SetFileName( m_fields[SHEETFILENAME].GetText() );
423}
424
425
427{
428 wxASSERT( aSheetPin != nullptr );
429 wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
430
431 aSheetPin->SetParent( this );
432 m_pins.push_back( aSheetPin );
433 renumberPins();
434}
435
436
437void SCH_SHEET::RemovePin( const SCH_SHEET_PIN* aSheetPin )
438{
439 wxASSERT( aSheetPin != nullptr );
440 wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
441
442 for( auto i = m_pins.begin(); i < m_pins.end(); ++i )
443 {
444 if( *i == aSheetPin )
445 {
446 m_pins.erase( i );
447 renumberPins();
448 return;
449 }
450 }
451}
452
453
454bool SCH_SHEET::HasPin( const wxString& aName ) const
455{
456 for( SCH_SHEET_PIN* pin : m_pins )
457 {
458 if( pin->GetText().Cmp( aName ) == 0 )
459 return true;
460 }
461
462 return false;
463}
464
465
466bool SCH_SHEET::doIsConnected( const VECTOR2I& aPosition ) const
467{
468 for( SCH_SHEET_PIN* sheetPin : m_pins )
469 {
470 if( sheetPin->GetPosition() == aPosition )
471 return true;
472 }
473
474 return false;
475}
476
477
479{
480 int leftRight = 0;
481 int topBottom = 0;
482
483 for( SCH_SHEET_PIN* pin : m_pins )
484 {
485 switch( pin->GetSide() )
486 {
487 case SHEET_SIDE::LEFT: leftRight++; break;
488 case SHEET_SIDE::RIGHT: leftRight++; break;
489 case SHEET_SIDE::TOP: topBottom++; break;
490 case SHEET_SIDE::BOTTOM: topBottom++; break;
491 default: break;
492 }
493 }
494
495 return topBottom > 0 && leftRight == 0;
496}
497
498
500{
501 for( SCH_SHEET_PIN* pin : m_pins )
502 {
503 /* Search the schematic for a hierarchical label corresponding to this sheet label. */
504 const SCH_HIERLABEL* HLabel = nullptr;
505
506 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_HIER_LABEL_T ) )
507 {
508 if( !pin->GetText().Cmp( static_cast<SCH_HIERLABEL*>( aItem )->GetText() ) )
509 {
510 HLabel = static_cast<SCH_HIERLABEL*>( aItem );
511 break;
512 }
513 }
514
515 if( HLabel == nullptr ) // Corresponding hierarchical label not found.
516 return true;
517 }
518
519 return false;
520}
521
522
523int bumpToNextGrid( const int aVal, const int aDirection )
524{
525 constexpr int gridSize = schIUScale.MilsToIU( 50 );
526
527 int base = aVal / gridSize;
528 int excess = abs( aVal % gridSize );
529
530 if( aDirection > 0 )
531 {
532 return ( base + 1 ) * gridSize;
533 }
534 else if( excess > 0 )
535 {
536 return ( base ) * gridSize;
537 }
538 else
539 {
540 return ( base - 1 ) * gridSize;
541 }
542}
543
544
545int SCH_SHEET::GetMinWidth( bool aFromLeft ) const
546{
547 int pinsLeft = m_pos.x + m_size.x;
548 int pinsRight = m_pos.x;
549
550 for( size_t i = 0; i < m_pins.size(); i++ )
551 {
552 SHEET_SIDE edge = m_pins[i]->GetSide();
553
554 if( edge == SHEET_SIDE::TOP || edge == SHEET_SIDE::BOTTOM )
555 {
556 BOX2I pinRect = m_pins[i]->GetBoundingBox();
557
558 pinsLeft = std::min( pinsLeft, pinRect.GetLeft() );
559 pinsRight = std::max( pinsRight, pinRect.GetRight() );
560 }
561 }
562
563 pinsLeft = bumpToNextGrid( pinsLeft, -1 );
564 pinsRight = bumpToNextGrid( pinsRight, 1 );
565
566 int pinMinWidth;
567
568 if( pinsLeft >= pinsRight )
569 pinMinWidth = 0;
570 else if( aFromLeft )
571 pinMinWidth = pinsRight - m_pos.x;
572 else
573 pinMinWidth = m_pos.x + m_size.x - pinsLeft;
574
575 return std::max( pinMinWidth, schIUScale.MilsToIU( MIN_SHEET_WIDTH ) );
576}
577
578
579int SCH_SHEET::GetMinHeight( bool aFromTop ) const
580{
581 int pinsTop = m_pos.y + m_size.y;
582 int pinsBottom = m_pos.y;
583
584 for( size_t i = 0; i < m_pins.size(); i++ )
585 {
586 SHEET_SIDE edge = m_pins[i]->GetSide();
587
588 if( edge == SHEET_SIDE::RIGHT || edge == SHEET_SIDE::LEFT )
589 {
590 BOX2I pinRect = m_pins[i]->GetBoundingBox();
591
592 pinsTop = std::min( pinsTop, pinRect.GetTop() );
593 pinsBottom = std::max( pinsBottom, pinRect.GetBottom() );
594 }
595 }
596
597 pinsTop = bumpToNextGrid( pinsTop, -1 );
598 pinsBottom = bumpToNextGrid( pinsBottom, 1 );
599
600 int pinMinHeight;
601
602 if( pinsTop >= pinsBottom )
603 pinMinHeight = 0;
604 else if( aFromTop )
605 pinMinHeight = pinsBottom - m_pos.y;
606 else
607 pinMinHeight = m_pos.y + m_size.y - pinsTop;
608
609 return std::max( pinMinHeight, schIUScale.MilsToIU( MIN_SHEET_HEIGHT ) );
610}
611
612
614{
615 std::vector<SCH_SHEET_PIN*> pins = m_pins;
616
617 m_pins.clear();
618
619 for( SCH_SHEET_PIN* pin : pins )
620 {
621 /* Search the schematic for a hierarchical label corresponding to this sheet label. */
622 const SCH_HIERLABEL* HLabel = nullptr;
623
624 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_HIER_LABEL_T ) )
625 {
626 if( pin->GetText().CmpNoCase( static_cast<SCH_HIERLABEL*>( aItem )->GetText() ) == 0 )
627 {
628 HLabel = static_cast<SCH_HIERLABEL*>( aItem );
629 break;
630 }
631 }
632
633 if( HLabel )
634 m_pins.push_back( pin );
635 }
636}
637
638
640{
641 for( SCH_SHEET_PIN* pin : m_pins )
642 {
643 if( pin->HitTest( aPosition ) )
644 return pin;
645 }
646
647 return nullptr;
648}
649
650
652{
653 if( GetBorderWidth() > 0 )
654 return GetBorderWidth();
655
656 if( Schematic() )
658
660}
661
662
664{
665 VECTOR2I textSize = m_fields[SHEETNAME].GetTextSize();
666 int borderMargin = KiROUND( GetPenWidth() / 2.0 ) + 4;
667 int margin = borderMargin + KiROUND( std::max( textSize.x, textSize.y ) * 0.5 );
668
670 {
671 m_fields[SHEETNAME].SetTextPos( m_pos + VECTOR2I( -margin, m_size.y ) );
672 m_fields[ SHEETNAME ].SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
673 m_fields[ SHEETNAME ].SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
674 m_fields[ SHEETNAME ].SetTextAngle( ANGLE_VERTICAL );
675 }
676 else
677 {
678 m_fields[SHEETNAME].SetTextPos( m_pos + VECTOR2I( 0, -margin ) );
679 m_fields[ SHEETNAME ].SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
680 m_fields[ SHEETNAME ].SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
681 m_fields[ SHEETNAME ].SetTextAngle( ANGLE_HORIZONTAL );
682 }
683
684 textSize = m_fields[ SHEETFILENAME ].GetTextSize();
685 margin = borderMargin + KiROUND( std::max( textSize.x, textSize.y ) * 0.4 );
686
688 {
689 m_fields[SHEETFILENAME].SetTextPos( m_pos + VECTOR2I( m_size.x + margin, m_size.y ) );
690 m_fields[ SHEETFILENAME ].SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
691 m_fields[ SHEETFILENAME ].SetVertJustify( GR_TEXT_V_ALIGN_TOP );
692 m_fields[ SHEETFILENAME ].SetTextAngle( ANGLE_VERTICAL );
693 }
694 else
695 {
696 m_fields[SHEETFILENAME].SetTextPos( m_pos + VECTOR2I( 0, m_size.y + margin ) );
697 m_fields[ SHEETFILENAME ].SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
698 m_fields[ SHEETFILENAME ].SetVertJustify( GR_TEXT_V_ALIGN_TOP );
699 m_fields[ SHEETFILENAME ].SetTextAngle( ANGLE_HORIZONTAL );
700 }
701
702 if( aAlgo == AUTOPLACE_AUTO || aAlgo == AUTOPLACE_MANUAL )
703 m_fieldsAutoplaced = aAlgo;
704}
705
706
707std::vector<int> SCH_SHEET::ViewGetLayers() const
708{
709 // Sheet pins are drawn by their parent sheet, so the parent needs to draw to LAYER_DANGLING
712}
713
714
716{
718 BOX2I box( m_pos, m_size );
719 int lineWidth = GetPenWidth();
720 int textLength = 0;
721
722 // Calculate bounding box X size:
723 end.x = std::max( m_size.x, textLength );
724
725 // Calculate bounding box pos:
726 end.y = m_size.y;
727 end += m_pos;
728
729 box.SetEnd( end );
730 box.Inflate( lineWidth / 2 );
731
732 return box;
733}
734
735
737{
738 BOX2I bbox = GetBodyBoundingBox();
739
740 for( const SCH_FIELD& field : m_fields )
741 bbox.Merge( field.GetBoundingBox() );
742
743 return bbox;
744}
745
746
748{
749 BOX2I box( m_pos, m_size );
750 return box.GetCenter();
751}
752
753
755{
756 int n = 0;
757
758 if( m_screen )
759 {
760 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SYMBOL_T ) )
761 {
762 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem;
763
764 if( symbol->GetField( VALUE_FIELD )->GetText().GetChar( 0 ) != '#' )
765 n++;
766 }
767
768 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
769 n += static_cast<const SCH_SHEET*>( aItem )->SymbolCount();
770 }
771
772 return n;
773}
774
775
776bool SCH_SHEET::SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen )
777{
778 if( m_screen )
779 {
780 // Only check the root sheet once and don't recurse.
781 if( !GetParent() )
782 {
783 if( m_screen && m_screen->GetFileName().Cmp( aFilename ) == 0 )
784 {
785 *aScreen = m_screen;
786 return true;
787 }
788 }
789
790 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
791 {
792 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
793 SCH_SCREEN* screen = sheet->m_screen;
794
795 // Must use the screen's path (which is always absolute) rather than the
796 // sheet's (which could be relative).
797 if( screen && screen->GetFileName().Cmp( aFilename ) == 0 )
798 {
799 *aScreen = screen;
800 return true;
801 }
802
803 if( sheet->SearchHierarchy( aFilename, aScreen ) )
804 return true;
805 }
806 }
807
808 return false;
809}
810
811
813{
814 if( m_screen )
815 {
816 aList->push_back( this );
817
818 if( m_screen == aScreen )
819 return true;
820
821 for( EDA_ITEM* item : m_screen->Items().OfType( SCH_SHEET_T ) )
822 {
823 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
824
825 if( sheet->LocatePathOfScreen( aScreen, aList ) )
826 return true;
827 }
828
829 aList->pop_back();
830 }
831
832 return false;
833}
834
835
837{
838 int count = 1; //1 = this!!
839
840 if( m_screen )
841 {
842 for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SHEET_T ) )
843 count += static_cast<SCH_SHEET*>( aItem )->CountSheets();
844 }
845
846 return count;
847}
848
849
850void SCH_SHEET::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
851{
852 // Don't use GetShownText(); we want to see the variable references here
853 aList.emplace_back( _( "Sheet Name" ),
854 KIUI::EllipsizeStatusText( aFrame, m_fields[ SHEETNAME ].GetText() ) );
855
856 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
857 {
858 SCH_SHEET_PATH path = schframe->GetCurrentSheet();
859 path.push_back( this );
860
861 aList.emplace_back( _( "Hierarchical Path" ), path.PathHumanReadable( false, true ) );
862 }
863
864 // Don't use GetShownText(); we want to see the variable references here
865 aList.emplace_back( _( "File Name" ),
866 KIUI::EllipsizeStatusText( aFrame, m_fields[ SHEETFILENAME ].GetText() ) );
867
868 wxArrayString msgs;
869 wxString msg;
870
871 if( GetExcludedFromSim() )
872 msgs.Add( _( "Simulation" ) );
873
874 if( GetExcludedFromBOM() )
875 msgs.Add( _( "BOM" ) );
876
878 msgs.Add( _( "Board" ) );
879
880 if( GetDNP() )
881 msgs.Add( _( "DNP" ) );
882
883 msg = wxJoin( msgs, '|' );
884 msg.Replace( '|', wxS( ", " ) );
885
886 if( !msg.empty() )
887 aList.emplace_back( _( "Exclude from" ), msg );
888}
889
890
892{
893 VECTOR2I delta = aPosition - m_pos;
894
895 m_pos = aPosition;
896
897 for( SCH_FIELD& field : m_fields )
898 field.Move( delta );
899}
900
901
902void SCH_SHEET::Move( const VECTOR2I& aMoveVector )
903{
904 m_pos += aMoveVector;
905
906 for( SCH_SHEET_PIN* pin : m_pins )
907 pin->Move( aMoveVector );
908
909 for( SCH_FIELD& field : m_fields )
910 field.Move( aMoveVector );
911}
912
913
914void SCH_SHEET::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
915{
916 VECTOR2I prev = m_pos;
917
918 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
919 RotatePoint( &m_size.x, &m_size.y, aRotateCCW ? ANGLE_90 : ANGLE_270 );
920
921 if( m_size.x < 0 )
922 {
923 m_pos.x += m_size.x;
924 m_size.x = -m_size.x;
925 }
926
927 if( m_size.y < 0 )
928 {
929 m_pos.y += m_size.y;
930 m_size.y = -m_size.y;
931 }
932
933 // Pins must be rotated first as that's how we determine vertical vs horizontal
934 // orientation for auto-placement
935 for( SCH_SHEET_PIN* sheetPin : m_pins )
936 sheetPin->Rotate( aCenter, aRotateCCW );
937
939 {
941 }
942 else
943 {
944 // Move the fields to the new position because the parent itself has moved.
945 for( SCH_FIELD& field : m_fields )
946 {
947 VECTOR2I pos = field.GetTextPos();
948 pos.x -= prev.x - m_pos.x;
949 pos.y -= prev.y - m_pos.y;
950 field.SetTextPos( pos );
951 }
952 }
953}
954
955
957{
958 int dy = m_pos.y;
959
960 MIRROR( m_pos.y, aCenter );
961 m_pos.y -= m_size.y;
962 dy -= m_pos.y; // 0,dy is the move vector for this transform
963
964 for( SCH_SHEET_PIN* sheetPin : m_pins )
965 sheetPin->MirrorVertically( aCenter );
966
967 for( SCH_FIELD& field : m_fields )
968 {
969 VECTOR2I pos = field.GetTextPos();
970 pos.y -= dy;
971 field.SetTextPos( pos );
972 }
973}
974
975
977{
978 int dx = m_pos.x;
979
980 MIRROR( m_pos.x, aCenter );
981 m_pos.x -= m_size.x;
982 dx -= m_pos.x; // dx,0 is the move vector for this transform
983
984 for( SCH_SHEET_PIN* sheetPin : m_pins )
985 sheetPin->MirrorHorizontally( aCenter );
986
987 for( SCH_FIELD& field : m_fields )
988 {
989 VECTOR2I pos = field.GetTextPos();
990 pos.x -= dx;
991 field.SetTextPos( pos );
992 }
993}
994
995
996void SCH_SHEET::SetPosition( const VECTOR2I& aPosition )
997{
998 // Remember the sheet and all pin sheet positions must be
999 // modified. So use Move function to do that.
1000 Move( aPosition - m_pos );
1001}
1002
1003
1004void SCH_SHEET::Resize( const VECTOR2I& aSize )
1005{
1006 if( aSize == m_size )
1007 return;
1008
1009 m_size = aSize;
1010
1011 // Move the fields if we're in autoplace mode
1014
1015 // Move the sheet labels according to the new sheet size.
1016 for( SCH_SHEET_PIN* sheetPin : m_pins )
1017 sheetPin->ConstrainOnEdge( sheetPin->GetPosition(), false );
1018}
1019
1020
1021bool SCH_SHEET::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
1022{
1023 // Sheets are searchable via the child field and pin item text.
1024 return false;
1025}
1026
1027
1029{
1030 int id = 2;
1031
1032 for( SCH_SHEET_PIN* pin : m_pins )
1033 {
1034 pin->SetNumber( id );
1035 id++;
1036 }
1037}
1038
1039
1041{
1042 wxCHECK_MSG( Schematic(), SCH_SHEET_PATH(), "Can't call findSelf without a schematic" );
1043
1044 SCH_SHEET_PATH sheetPath = Schematic()->CurrentSheet();
1045
1046 while( !sheetPath.empty() && sheetPath.Last() != this )
1047 sheetPath.pop_back();
1048
1049 if( sheetPath.empty() )
1050 {
1051 // If we weren't in the hierarchy, then we must be a child of the current sheet.
1052 sheetPath = Schematic()->CurrentSheet();
1053 sheetPath.push_back( const_cast<SCH_SHEET*>( this ) );
1054 }
1055
1056 return sheetPath;
1057}
1058
1059
1060void SCH_SHEET::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
1061{
1062 for( SCH_SHEET_PIN* sheetPin : m_pins )
1063 {
1064 wxCHECK2_MSG( sheetPin->Type() == SCH_SHEET_PIN_T, continue,
1065 wxT( "Invalid item in schematic sheet pin list. Bad programmer!" ) );
1066
1067 sheetPin->GetEndPoints( aItemList );
1068 }
1069}
1070
1071
1072bool SCH_SHEET::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
1073 std::vector<DANGLING_END_ITEM>& aItemListByPos,
1074 const SCH_SHEET_PATH* aPath )
1075{
1076 bool changed = false;
1077
1078 for( SCH_SHEET_PIN* sheetPin : m_pins )
1079 changed |= sheetPin->UpdateDanglingState( aItemListByType, aItemListByPos );
1080
1081 return changed;
1082}
1083
1084
1086 const SCH_SHEET_PATH* aInstance ) const
1087{
1088 // Do not compare to ourself.
1089 if( aItem == this )
1090 return false;
1091
1092 const SCH_SHEET* sheet = dynamic_cast<const SCH_SHEET*>( aItem );
1093
1094 // Don't compare against a different SCH_ITEM.
1095 wxCHECK( sheet, false );
1096
1097 if( GetPosition() != sheet->GetPosition() )
1098 return true;
1099
1100 // Technically this cannot happen because undo/redo does not support reloading sheet
1101 // file association changes. This was just added so that it doesn't get missed should
1102 // we ever fix the undo/redo issue.
1103 if( ( GetFileName() != sheet->GetFileName() ) || ( GetName() != sheet->GetName() ) )
1104 return true;
1105
1106 if( m_pins.size() != sheet->m_pins.size() )
1107 return true;
1108
1109 for( size_t i = 0; i < m_pins.size(); i++ )
1110 {
1111 if( m_pins[i]->HasConnectivityChanges( sheet->m_pins[i] ) )
1112 return true;
1113 }
1114
1115 return false;
1116}
1117
1118
1119std::vector<VECTOR2I> SCH_SHEET::GetConnectionPoints() const
1120{
1121 std::vector<VECTOR2I> retval;
1122
1123 for( SCH_SHEET_PIN* sheetPin : m_pins )
1124 retval.push_back( sheetPin->GetPosition() );
1125
1126 return retval;
1127}
1128
1129
1130INSPECT_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData,
1131 const std::vector<KICAD_T>& aScanTypes )
1132{
1133 for( KICAD_T scanType : aScanTypes )
1134 {
1135 // If caller wants to inspect my type
1136 if( scanType == SCH_LOCATE_ANY_T || scanType == Type() )
1137 {
1138 if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) )
1139 return INSPECT_RESULT::QUIT;
1140 }
1141
1142 if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T )
1143 {
1144 // Test the sheet fields.
1145 for( SCH_FIELD& field : m_fields )
1146 {
1147 if( INSPECT_RESULT::QUIT == aInspector( &field, this ) )
1148 return INSPECT_RESULT::QUIT;
1149 }
1150 }
1151
1152 if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_SHEET_PIN_T )
1153 {
1154 // Test the sheet labels.
1155 for( SCH_SHEET_PIN* sheetPin : m_pins )
1156 {
1157 if( INSPECT_RESULT::QUIT == aInspector( sheetPin, this ) )
1158 return INSPECT_RESULT::QUIT;
1159 }
1160 }
1161 }
1162
1163 return INSPECT_RESULT::CONTINUE;
1164}
1165
1166
1167void SCH_SHEET::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
1168{
1169 for( SCH_FIELD& field : m_fields )
1170 aFunction( &field );
1171
1172 for( SCH_SHEET_PIN* pin : m_pins )
1173 aFunction( pin );
1174}
1175
1176
1177wxString SCH_SHEET::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1178{
1179 return wxString::Format( _( "Hierarchical Sheet %s" ),
1180 aFull ? m_fields[ SHEETNAME ].GetShownText( false )
1181 : KIUI::EllipsizeMenuText( m_fields[ SHEETNAME ].GetText() ) );
1182}
1183
1184
1186{
1187 return BITMAPS::add_hierarchical_subsheet;
1188}
1189
1190
1191bool SCH_SHEET::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1192{
1193 BOX2I rect = GetBodyBoundingBox();
1194
1195 rect.Inflate( aAccuracy );
1196
1197 return rect.Contains( aPosition );
1198}
1199
1200
1201bool SCH_SHEET::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1202{
1203 BOX2I rect = aRect;
1204
1205 rect.Inflate( aAccuracy );
1206
1207 if( aContained )
1208 return rect.Contains( GetBodyBoundingBox() );
1209
1210 return rect.Intersects( GetBodyBoundingBox() );
1211}
1212
1213
1214void SCH_SHEET::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1215 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1216{
1217 if( aBackground && !aPlotter->GetColorMode() )
1218 return;
1219
1220 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1221 COLOR4D borderColor = GetBorderColor();
1222 COLOR4D backgroundColor = GetBackgroundColor();
1223
1224 if( renderSettings->m_OverrideItemColors || borderColor == COLOR4D::UNSPECIFIED )
1225 borderColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_SHEET );
1226
1227 if( renderSettings->m_OverrideItemColors || backgroundColor == COLOR4D::UNSPECIFIED )
1228 backgroundColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_SHEET_BACKGROUND );
1229
1230 if( aBackground && backgroundColor.a > 0.0 )
1231 {
1232 aPlotter->SetColor( backgroundColor );
1233 aPlotter->Rect( m_pos, m_pos + m_size, FILL_T::FILLED_SHAPE, 1 );
1234 }
1235 else
1236 {
1237 aPlotter->SetColor( borderColor );
1238
1239 int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
1240 aPlotter->Rect( m_pos, m_pos + m_size, FILL_T::NO_FILL, penWidth );
1241 }
1242
1243 // Make the sheet object a clickable hyperlink (e.g. for PDF plotter)
1244 if( aPlotOpts.m_PDFHierarchicalLinks )
1245 {
1246 aPlotter->HyperlinkBox( GetBoundingBox(),
1247 EDA_TEXT::GotoPageHref( findSelf().GetPageNumber() ) );
1248 }
1249 else if( aPlotOpts.m_PDFPropertyPopups )
1250 {
1251 std::vector<wxString> properties;
1252
1253 properties.emplace_back( EDA_TEXT::GotoPageHref( findSelf().GetPageNumber() ) );
1254
1255 for( const SCH_FIELD& field : GetFields() )
1256 {
1257 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), field.GetName(),
1258 field.GetShownText( false ) ) );
1259 }
1260
1261 aPlotter->HyperlinkMenu( GetBoundingBox(), properties );
1262 }
1263
1264 // Plot sheet pins
1265 for( SCH_SHEET_PIN* sheetPin : m_pins )
1266 sheetPin->Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
1267
1268 // Plot the fields
1269 for( SCH_FIELD& field : m_fields )
1270 field.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
1271
1272 if( GetDNP() )
1273 {
1275 BOX2I bbox = GetBodyBoundingBox();
1276 BOX2I pins = GetBoundingBox();
1277 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(),
1278 pins.GetEnd().x - bbox.GetEnd().x ),
1279 std::max( bbox.GetY() - pins.GetY(),
1280 pins.GetEnd().y - bbox.GetEnd().y ) );
1281 int strokeWidth = 3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
1282
1283 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
1284 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
1285 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
1286
1287 aPlotter->SetColor( colors->GetColor( LAYER_DNP_MARKER ) );
1288
1289 aPlotter->ThickSegment( bbox.GetOrigin(), bbox.GetEnd(), strokeWidth, FILLED, nullptr );
1290
1291 aPlotter->ThickSegment( bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
1292 bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ),
1293 strokeWidth, FILLED, nullptr );
1294 }
1295}
1296
1297
1298void SCH_SHEET::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
1299 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
1300{
1301 wxDC* DC = aSettings->GetPrintDC();
1302 VECTOR2I pos = m_pos + aOffset;
1303 int lineWidth = GetEffectivePenWidth( aSettings );
1304 COLOR4D border = GetBorderColor();
1305 COLOR4D background = GetBackgroundColor();
1306
1307 if( aSettings->m_OverrideItemColors || border == COLOR4D::UNSPECIFIED )
1308 border = aSettings->GetLayerColor( LAYER_SHEET );
1309
1310 if( aSettings->m_OverrideItemColors || background == COLOR4D::UNSPECIFIED )
1311 background = aSettings->GetLayerColor( LAYER_SHEET_BACKGROUND );
1312
1313 if( GetGRForceBlackPenState() ) // printing in black & white
1314 background = COLOR4D::UNSPECIFIED;
1315
1316 if( background.a > 0.0 )
1317 GRFilledRect( DC, pos, pos + m_size, 0, background, background );
1318
1319 GRRect( DC, pos, pos + m_size, lineWidth, border );
1320
1321 for( SCH_FIELD& field : m_fields )
1322 field.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
1323
1324 for( SCH_SHEET_PIN* sheetPin : m_pins )
1325 sheetPin->Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
1326
1327 if( GetDNP() )
1328 {
1329 BOX2I bbox = GetBodyBoundingBox();
1330 BOX2I pins = GetBoundingBox();
1331 COLOR4D dnp_color = aSettings->GetLayerColor( LAYER_DNP_MARKER );
1332 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
1333 std::max( bbox.GetY() - pins.GetY(),
1334 pins.GetEnd().y - bbox.GetEnd().y ) );
1335
1336 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
1337 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
1338 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
1339
1340 GRFilledSegment( DC, bbox.GetOrigin(), bbox.GetEnd(),
1342 dnp_color );
1343
1344 GRFilledSegment( DC, bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
1345 bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ),
1347 dnp_color );
1348 }
1349}
1350
1351
1353{
1354 wxCHECK_MSG( Type() == aItem.Type(), *this,
1355 wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
1356 GetClass() );
1357
1358 if( &aItem != this )
1359 {
1360 SCH_ITEM::operator=( aItem );
1361
1362 SCH_SHEET* sheet = (SCH_SHEET*) &aItem;
1363
1364 m_pos = sheet->m_pos;
1365 m_size = sheet->m_size;
1366 m_fields = sheet->m_fields;
1367
1368 for( SCH_SHEET_PIN* pin : sheet->m_pins )
1369 {
1370 m_pins.emplace_back( new SCH_SHEET_PIN( *pin ) );
1371 m_pins.back()->SetParent( this );
1372 }
1373
1374 for( const SCH_SHEET_INSTANCE& instance : sheet->m_instances )
1375 m_instances.emplace_back( instance );
1376 }
1377
1378 return *this;
1379}
1380
1381
1382bool SCH_SHEET::operator <( const SCH_ITEM& aItem ) const
1383{
1384 if( Type() != aItem.Type() )
1385 return Type() < aItem.Type();
1386
1387 auto sheet = static_cast<const SCH_SHEET*>( &aItem );
1388
1389 if (m_fields[ SHEETNAME ].GetText() != sheet->m_fields[ SHEETNAME ].GetText() )
1390 return m_fields[ SHEETNAME ].GetText() < sheet->m_fields[ SHEETNAME ].GetText();
1391
1392 if (m_fields[ SHEETFILENAME ].GetText() != sheet->m_fields[ SHEETFILENAME ].GetText() )
1393 return m_fields[ SHEETFILENAME ].GetText() < sheet->m_fields[ SHEETFILENAME ].GetText();
1394
1395 return false;
1396}
1397
1398
1399void SCH_SHEET::RemoveInstance( const KIID_PATH& aInstancePath )
1400{
1401 // Search for an existing path and remove it if found (should not occur)
1402 for( unsigned ii = 0; ii < m_instances.size(); ii++ )
1403 {
1404 if( m_instances[ii].m_Path == aInstancePath )
1405 {
1406 wxLogTrace( traceSchSheetPaths, "Removing sheet instance:\n"
1407 " sheet path %s\n"
1408 " page %s, from project %s.",
1409 aInstancePath.AsString(),
1410 m_instances[ii].m_PageNumber,
1411 m_instances[ii].m_ProjectName );
1412
1413 m_instances.erase( m_instances.begin() + ii );
1414 ii--;
1415 }
1416 }
1417}
1418
1419
1421{
1422 SCH_SHEET_INSTANCE oldInstance;
1423
1424 if( getInstance( oldInstance, aInstance.m_Path ) )
1425 RemoveInstance( aInstance.m_Path );
1426
1427 m_instances.emplace_back( aInstance );
1428
1429}
1430
1431
1433{
1434 for( const SCH_SHEET_INSTANCE& instance : m_instances )
1435 {
1436 // if aSheetPath is found, nothing to do:
1437 if( instance.m_Path == aPath )
1438 return false;
1439 }
1440
1441 wxLogTrace( traceSchSheetPaths, wxT( "Adding instance `%s` to sheet `%s`." ),
1442 aPath.AsString(),
1443 ( GetName().IsEmpty() ) ? wxString( wxT( "root" ) ) : GetName() );
1444
1445 SCH_SHEET_INSTANCE instance;
1446
1447 instance.m_Path = aPath;
1448
1449 // This entry does not exist: add it with an empty page number.
1450 m_instances.emplace_back( instance );
1451 return true;
1452}
1453
1454
1455bool SCH_SHEET::getInstance( SCH_SHEET_INSTANCE& aInstance, const KIID_PATH& aSheetPath,
1456 bool aTestFromEnd ) const
1457{
1458 for( const SCH_SHEET_INSTANCE& instance : m_instances )
1459 {
1460 if( !aTestFromEnd )
1461 {
1462 if( instance.m_Path == aSheetPath )
1463 {
1464 aInstance = instance;
1465 return true;
1466 }
1467 }
1468 else if( instance.m_Path.EndsWith( aSheetPath ) )
1469 {
1470 aInstance = instance;
1471 return true;
1472 }
1473 }
1474
1475 return false;
1476}
1477
1478
1480{
1481 for( const SCH_SHEET_INSTANCE& instance : m_instances )
1482 {
1483 if( instance.m_Path.size() == 0 )
1484 return true;
1485 }
1486
1487 return false;
1488}
1489
1490
1492{
1493 for( const SCH_SHEET_INSTANCE& instance : m_instances )
1494 {
1495 if( instance.m_Path.size() == 0 )
1496 return instance;
1497 }
1498
1499 wxFAIL;
1500
1502
1503 return dummy;
1504}
1505
1506
1507wxString SCH_SHEET::getPageNumber( const KIID_PATH& aPath ) const
1508{
1509 wxString pageNumber;
1510
1511 for( const SCH_SHEET_INSTANCE& instance : m_instances )
1512 {
1513 if( instance.m_Path == aPath )
1514 {
1515 pageNumber = instance.m_PageNumber;
1516 break;
1517 }
1518 }
1519
1520 return pageNumber;
1521}
1522
1523
1524void SCH_SHEET::setPageNumber( const KIID_PATH& aPath, const wxString& aPageNumber )
1525{
1526 for( SCH_SHEET_INSTANCE& instance : m_instances )
1527 {
1528 if( instance.m_Path == aPath )
1529 {
1530 instance.m_PageNumber = aPageNumber;
1531 break;
1532 }
1533 }
1534}
1535
1536
1538{
1539 // Avoid self comparison.
1540 if( &aOther == this )
1541 return false;
1542
1543 // A difference in the instance data count implies a page numbering change.
1544 if( GetInstances().size() != aOther.GetInstances().size() )
1545 return true;
1546
1547 std::vector<SCH_SHEET_INSTANCE> instances = GetInstances();
1548 std::vector<SCH_SHEET_INSTANCE> otherInstances = aOther.GetInstances();
1549
1550 // Sorting may not be necessary but there is no guarantee that sheet
1551 // instance data will be in the correct KIID_PATH order. We should
1552 // probably use a std::map instead of a std::vector to store the sheet
1553 // instance data.
1554 std::sort( instances.begin(), instances.end(),
1555 []( const SCH_SHEET_INSTANCE& aLhs, const SCH_SHEET_INSTANCE& aRhs )
1556 {
1557 if( aLhs.m_Path > aRhs.m_Path )
1558 return true;
1559
1560 return false;
1561 } );
1562 std::sort( otherInstances.begin(), otherInstances.end(),
1563 []( const SCH_SHEET_INSTANCE& aLhs, const SCH_SHEET_INSTANCE& aRhs )
1564 {
1565 if( aLhs.m_Path > aRhs.m_Path )
1566 return true;
1567
1568 return false;
1569 } );
1570
1571 auto itThis = instances.begin();
1572 auto itOther = otherInstances.begin();
1573
1574 while( itThis != instances.end() )
1575 {
1576 if( ( itThis->m_Path == itOther->m_Path )
1577 && ( itThis->m_PageNumber != itOther->m_PageNumber ) )
1578 {
1579 return true;
1580 }
1581
1582 itThis++;
1583 itOther++;
1584 }
1585
1586 return false;
1587}
1588
1589
1590int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB )
1591{
1592 if( aPageNumberA == aPageNumberB )
1593 return 0; // A == B
1594
1595 // First sort numerically if the page numbers are integers
1596 long pageA, pageB;
1597 bool isIntegerPageA = aPageNumberA.ToLong( &pageA );
1598 bool isIntegerPageB = aPageNumberB.ToLong( &pageB );
1599
1600 if( isIntegerPageA && isIntegerPageB )
1601 {
1602 if( pageA < pageB )
1603 return -1; //A < B
1604 else
1605 return 1; // A > B
1606 }
1607
1608 // Numerical page numbers always before strings
1609 if( isIntegerPageA )
1610 return -1; //A < B
1611 else if( isIntegerPageB )
1612 return 1; // A > B
1613
1614 // If not numeric, then sort as strings using natural sort
1615 int result = StrNumCmp( aPageNumberA, aPageNumberB );
1616
1617 // Divide by zero bad.
1618 wxCHECK( result != 0, 0 );
1619
1620 result = result / std::abs( result );
1621
1622 return result;
1623}
1624
1625
1626bool SCH_SHEET::operator==( const SCH_ITEM& aOther ) const
1627{
1628 if( Type() != aOther.Type() )
1629 return false;
1630
1631 const SCH_SHEET* other = static_cast<const SCH_SHEET*>( &aOther );
1632
1633 if( m_pos != other->m_pos )
1634 return false;
1635
1636 if( m_size != other->m_size )
1637 return false;
1638
1639 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
1640 return false;
1641
1642 if( GetExcludedFromBOM() != other->GetExcludedFromBOM() )
1643 return false;
1644
1645 if( GetExcludedFromBoard() != other->GetExcludedFromBoard() )
1646 return false;
1647
1648 if( GetDNP() != other->GetDNP() )
1649 return false;
1650
1651 if( GetBorderColor() != other->GetBorderColor() )
1652 return false;
1653
1654 if( GetBackgroundColor() != other->GetBackgroundColor() )
1655 return false;
1656
1657 if( GetBorderWidth() != other->GetBorderWidth() )
1658 return false;
1659
1660 if( GetFields().size() != other->GetFields().size() )
1661 return false;
1662
1663 for( size_t i = 0; i < GetFields().size(); ++i )
1664 {
1665 if( !( GetFields()[i] == other->GetFields()[i] ) )
1666 return false;
1667 }
1668
1669 return true;
1670}
1671
1672
1673double SCH_SHEET::Similarity( const SCH_ITEM& aOther ) const
1674{
1675 if( Type() != aOther.Type() )
1676 return 0.0;
1677
1678 const SCH_SHEET* other = static_cast<const SCH_SHEET*>( &aOther );
1679
1680 if( m_screen->GetFileName() == other->m_screen->GetFileName() )
1681 return 1.0;
1682
1683 return 0.0;
1684}
1685
1686
1687#if defined(DEBUG)
1688
1689void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const
1690{
1691 // XML output:
1692 wxString s = GetClass();
1693
1694 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">" << " sheet_name=\""
1695 << TO_UTF8( m_fields[ SHEETNAME ].GetText() ) << '"' << ">\n";
1696
1697 // show all the pins, and check the linked list integrity
1698 for( SCH_SHEET_PIN* sheetPin : m_pins )
1699 sheetPin->Show( nestLevel + 1, os );
1700
1701 NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n" << std::flush;
1702}
1703
1704#endif
1705
1706static struct SCH_SHEET_DESC
1707{
1709 {
1713
1714 propMgr.AddProperty( new PROPERTY<SCH_SHEET, wxString>( _HKI( "Sheet Name" ),
1716
1717 propMgr.AddProperty( new PROPERTY<SCH_SHEET, int>( _HKI( "Border Width" ),
1719 PROPERTY_DISPLAY::PT_SIZE ) );
1720
1721 propMgr.AddProperty( new PROPERTY<SCH_SHEET, COLOR4D>( _HKI( "Border Color" ),
1723
1724 propMgr.AddProperty( new PROPERTY<SCH_SHEET, COLOR4D>( _HKI( "Background Color" ),
1726
1727 const wxString groupAttributes = _HKI( "Attributes" );
1728
1729 propMgr.AddProperty( new PROPERTY<SCH_SHEET, bool>( _HKI( "Exclude From Board" ),
1731 groupAttributes );
1732 propMgr.AddProperty( new PROPERTY<SCH_SHEET, bool>( _HKI( "Exclude From Simulation" ),
1734 groupAttributes );
1735 propMgr.AddProperty(
1736 new PROPERTY<SCH_SHEET, bool>( _HKI( "Exclude From Bill of Materials" ),
1739 groupAttributes );
1740 propMgr.AddProperty( new PROPERTY<SCH_SHEET, bool>( _HKI( "Do not Populate" ),
1742 groupAttributes );
1743 }
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr const Vec GetEnd() const
Definition: box2.h:212
constexpr coord_type GetY() const
Definition: box2.h:208
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr coord_type GetX() const
Definition: box2.h:207
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
constexpr const Vec GetCenter() const
Definition: box2.h:230
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr coord_type GetLeft() const
Definition: box2.h:228
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr const Vec & GetOrigin() const
Definition: box2.h:210
constexpr coord_type GetRight() const
Definition: box2.h:217
constexpr void SetEnd(coord_type x, coord_type y)
Definition: box2.h:297
constexpr coord_type GetTop() const
Definition: box2.h:229
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
constexpr coord_type GetBottom() const
Definition: box2.h:222
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
const KIID m_Uuid
Definition: eda_item.h:488
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
static wxString GotoPageHref(const wxString &aDestination)
Generate a href to a page in the current schematic.
Definition: eda_text.cpp:1301
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:241
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double a
Alpha component.
Definition: color4d.h:395
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
wxString AsString() const
Definition: kiid.cpp:356
Definition: kiid.h:49
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
Base plotter engine class.
Definition: plotter.h:105
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:553
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
virtual void HyperlinkBox(const BOX2I &aBox, const wxString &aDestinationURL)
Create a clickable hyperlink with a rectangular click area.
Definition: plotter.h:456
bool GetColorMode() const
Definition: plotter.h:133
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition: plotter.h:467
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
virtual void SetColor(const COLOR4D &color)=0
Container for project specific data.
Definition: project.h:64
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Holds all the data relating to one schematic.
Definition: schematic.h:83
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:162
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:322
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:224
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:263
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:238
SCH_SHEET & Root() const
Definition: schematic.h:131
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:98
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:452
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:53
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:101
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:665
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
AUTOPLACE_ALGO m_fieldsAutoplaced
Definition: sch_item.h:722
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:352
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:177
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:474
SCH_LAYER_ID m_layer
Definition: sch_item.h:718
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition: sch_screen.h:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
void DecRefCount()
Definition: sch_screen.cpp:134
void IncRefCount()
Definition: sch_screen.cpp:128
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
int GetRefCount() const
Definition: sch_screen.h:161
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
bool empty() const
Forwarded method from std::vector.
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
wxString GetPageNumber() const
bool GetExcludedFromSim() const
bool GetExcludedFromBoard() const
bool GetDNP() const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:59
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:1060
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:211
friend SCH_SHEET_PATH
Definition: sch_sheet.h:477
bool GetExcludedFromBOM() const
Definition: sch_sheet.h:380
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:122
friend class SCH_SHEET_PIN
Definition: sch_sheet.h:542
VECTOR2I m_size
Definition: sch_sheet.h:559
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:316
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition: sch_sheet.cpp:1085
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:310
bool IsRootSheet() const
Definition: sch_sheet.cpp:203
bool getInstance(SCH_SHEET_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_sheet.cpp:1455
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated)
Definition: sch_sheet.cpp:59
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:1185
void RemoveInstance(const KIID_PATH &aInstancePath)
Definition: sch_sheet.cpp:1399
bool addInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1432
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:426
bool HasRootInstance() const
Check to see if this sheet has a root sheet instance.
Definition: sch_sheet.cpp:1479
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:80
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:1167
int GetPenWidth() const override
Definition: sch_sheet.cpp:651
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:165
SCH_SHEET_PATH findSelf() const
Get the sheetpath of this sheet.
Definition: sch_sheet.cpp:1040
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:1021
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_sheet.cpp:1673
VECTOR2I m_pos
Definition: sch_sheet.h:558
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:96
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:561
bool m_excludedFromBOM
Definition: sch_sheet.h:554
wxString GetName() const
Definition: sch_sheet.h:110
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:1028
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
Definition: sch_sheet.h:379
VECTOR2I GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:747
SCH_SHEET_PIN * GetPin(const VECTOR2I &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:639
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1382
bool GetExcludedFromBoard() const
Definition: sch_sheet.h:386
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:613
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_sheet.cpp:1298
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:437
void SetPositionIgnoringPins(const VECTOR2I &aPosition)
Definition: sch_sheet.cpp:891
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:776
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:812
std::vector< SCH_SHEET_INSTANCE > m_instances
Definition: sch_sheet.h:564
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:499
bool m_excludedFromSim
Definition: sch_sheet.h:553
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_sheet.cpp:996
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:125
int SymbolCount() const
Count our own symbols, without the power symbols.
Definition: sch_sheet.cpp:754
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_sheet.cpp:1214
void AddInstance(const SCH_SHEET_INSTANCE &aInstance)
Definition: sch_sheet.cpp:1420
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:545
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_sheet.cpp:1626
SCH_SCREEN * m_screen
Definition: sch_sheet.h:546
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_sheet.cpp:707
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:551
void SetDNP(bool aDNP)
Definition: sch_sheet.h:392
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:562
SCH_SHEET(EDA_ITEM *aParent=nullptr, const VECTOR2I &aPos=VECTOR2I(0, 0), VECTOR2I aSize=VECTOR2I(schIUScale.MilsToIU(MIN_SHEET_WIDTH), schIUScale.MilsToIU(MIN_SHEET_HEIGHT)))
Definition: sch_sheet.cpp:82
void SetName(const wxString &aName)
Definition: sch_sheet.h:111
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:836
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:404
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
Definition: sch_sheet.cpp:715
bool HasPin(const wxString &aName) const
Check if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:454
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compare page numbers of schematic sheets.
Definition: sch_sheet.cpp:1590
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:976
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
Definition: sch_sheet.cpp:403
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:194
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:171
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1352
bool HasPageNumberChanges(const SCH_SHEET &aOther) const
Check if the instance data of this sheet has any changes compared to aOther.
Definition: sch_sheet.cpp:1537
const SCH_SHEET_INSTANCE & GetRootInstance() const
Return the root sheet instance data.
Definition: sch_sheet.cpp:1491
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:466
bool m_excludedFromBoard
Definition: sch_sheet.h:555
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:736
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:1119
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:121
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:550
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &aScanTypes) 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:1130
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:119
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:956
void setPageNumber(const KIID_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1524
bool GetExcludedFromSim() const override
Definition: sch_sheet.h:374
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Definition: sch_sheet.cpp:663
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_sheet.cpp:362
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:579
int m_borderWidth
Definition: sch_sheet.h:560
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_sheet.cpp:1177
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos, 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:1072
void Resize(const VECTOR2I &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:1004
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:902
int GetBorderWidth() const
Definition: sch_sheet.h:118
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
Definition: sch_sheet.h:385
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:850
bool m_DNP
Definition: sch_sheet.h:556
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:914
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:254
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:424
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:478
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
Definition: sch_sheet.h:373
bool GetDNP() const
Set or clear the 'Do Not Populate' flags.
Definition: sch_sheet.h:391
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_sheet.cpp:1191
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:124
wxString getPageNumber(const KIID_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1507
Schematic symbol object.
Definition: sch_symbol.h:77
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:907
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieve a color settings object that applications can read colors from.
bool TextVarResolver(wxString *aToken, const PROJECT *aProject, int aFlags=0) const
static void GetContextualTextVars(wxArrayString *aVars)
Definition: title_block.cpp:75
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:406
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition: eda_item.h:82
void GRRect(wxDC *DC, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, const COLOR4D &aColor)
Definition: gr_basic.cpp:397
void GRFilledSegment(wxDC *aDC, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, const COLOR4D &aColor)
Definition: gr_basic.cpp:278
static const bool FILLED
Definition: gr_basic.cpp:30
void GRFilledRect(wxDC *DC, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition: gr_basic.cpp:404
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
@ LAYER_DANGLING
Definition: layer_ids.h:466
@ LAYER_SHEETNAME
Definition: layer_ids.h:461
@ LAYER_SHEET_BACKGROUND
Definition: layer_ids.h:474
@ LAYER_HIERLABEL
Definition: layer_ids.h:446
@ LAYER_SHEETFIELDS
Definition: layer_ids.h:463
@ LAYER_SHEET
Definition: layer_ids.h:460
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:483
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:462
@ LAYER_DNP_MARKER
Definition: layer_ids.h:467
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:45
Message panel definition file.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:214
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
Definition: ui_common.cpp:196
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
AUTOPLACE_ALGO
Definition: sch_item.h:68
@ AUTOPLACE_MANUAL
Definition: sch_item.h:71
@ AUTOPLACE_AUTO
Definition: sch_item.h:70
static wxString s_CanonicalSheetFile(SHEET_FILE_CANONICAL)
#define SHEET_NAME_CANONICAL
Definition: sch_sheet.cpp:52
int bumpToNextGrid(const int aVal, const int aDirection)
Definition: sch_sheet.cpp:523
static wxString s_CanonicalSheetName(SHEET_NAME_CANONICAL)
static struct SCH_SHEET_DESC _SCH_SHEET_DESC
#define SHEET_FILE_CANONICAL
Definition: sch_sheet.cpp:53
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:40
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:39
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SHEET_SIDE
Define the edge of the sheet that the sheet pin is positioned.
Definition: sch_sheet_pin.h:46
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:403
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
bool m_PDFPropertyPopups
Definition: sch_plotter.h:91
bool m_PDFHierarchicalLinks
Definition: sch_plotter.h:92
A simple container for sheet instance information.
#define USER_FIELD_CANONICAL
#define DO_TRANSLATE
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
VECTOR2I end
constexpr int delta
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_TOP
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:198
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:173
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695