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