KiCad PCB EDA Suite
sch_sheet.h
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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef SCH_SHEEET_H
26#define SCH_SHEEET_H
27
28#include <sch_field.h>
29
30class KIID_PATH;
31class SCH_SCREEN;
32class SCH_SHEET_PIN;
33class SCH_SHEET_PATH;
34class EDA_DRAW_FRAME;
35
36
37#define MIN_SHEET_WIDTH 500 // Units are mils.
38#define MIN_SHEET_HEIGHT 150 // Units are mils.
39
40
42{
45
48};
49
50
54class SCH_SHEET : public SCH_ITEM
55{
56public:
57 SCH_SHEET( EDA_ITEM* aParent = nullptr, const VECTOR2I& aPos = VECTOR2I( 0, 0 ),
58 wxSize aSize = wxSize( schIUScale.MilsToIU( MIN_SHEET_WIDTH ),
60 FIELDS_AUTOPLACED aAutoplaceFields = FIELDS_AUTOPLACED_AUTO );
61
66 SCH_SHEET( const SCH_SHEET& aSheet );
67
68 ~SCH_SHEET();
69
70 static inline bool ClassOf( const EDA_ITEM* aItem )
71 {
72 return aItem && SCH_SHEET_T == aItem->Type();
73 }
74
75 wxString GetClass() const override
76 {
77 return wxT( "SCH_SHEET" );
78 }
79
89 bool IsMovableFromAnchorPoint() const override { return false; }
90
91 std::vector<SCH_FIELD>& GetFields() { return m_fields; }
92 const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
93
99 void SetFields( const std::vector<SCH_FIELD>& aFields );
100
101 wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }
102 void SetName( const wxString& aName ) { m_fields[ SHEETNAME ].SetText( aName ); }
103
104 SCH_SCREEN* GetScreen() const { return m_screen; }
105
106 wxSize GetSize() const { return m_size; }
107 void SetSize( const wxSize& aSize ) { m_size = aSize; }
108
109 int GetBorderWidth() const { return m_borderWidth; }
110 void SetBorderWidth( int aWidth ) { m_borderWidth = aWidth; }
111
113 void SetBorderColor( KIGFX::COLOR4D aColor ) { m_borderColor = aColor; }
114
117
121 bool IsRootSheet() const;
122
134 void SetScreen( SCH_SCREEN* aScreen );
135
141 int GetScreenCount() const;
142
146 void GetContextualTextVars( wxArrayString* aVars ) const;
147
153 bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
154
155 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
156
157 /* there is no member for orientation in sch_sheet, to preserve file
158 * format, we detect orientation based on pin edges
159 */
160 bool IsVerticalOrientation() const;
161
171 void AddPin( SCH_SHEET_PIN* aSheetPin );
172
173 std::vector<SCH_SHEET_PIN*>& GetPins() { return m_pins; }
174 const std::vector<SCH_SHEET_PIN*>& GetPins() const { return m_pins; }
175
181 void RemovePin( const SCH_SHEET_PIN* aSheetPin );
182
189 void CleanupSheet();
190
198 SCH_SHEET_PIN* GetPin( const VECTOR2I& aPosition );
199
206 bool HasPin( const wxString& aName ) const;
207
208 bool HasPins() const { return !m_pins.empty(); }
209
215 bool HasUndefinedPins() const;
216
228 int GetMinWidth( bool aFromLeft ) const;
229
240 int GetMinHeight( bool aFromTop ) const;
241
242 int GetPenWidth() const override;
243
244 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
245
249 const BOX2I GetBodyBoundingBox() const;
250
251 const BOX2I GetBoundingBox() const override;
252
259
260 void SwapData( SCH_ITEM* aItem ) override;
261
265 int SymbolCount() const;
266
274 bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
275
286 bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
287
293 int CountSheets() const;
294
300 wxString GetFileName() const
301 {
302 return m_fields[ SHEETFILENAME ].GetText();
303 }
304
305 // Set a new filename without changing anything else
306 void SetFileName( const wxString& aFilename )
307 {
308 // Filenames are stored using unix notation
309 wxString tmp = aFilename;
310 tmp.Replace( wxT( "\\" ), wxT( "/" ) );
311 m_fields[ SHEETFILENAME ].SetText( tmp );
312 }
313
314 // Geometric transforms (used in block operations):
315
316 void Move( const VECTOR2I& aMoveVector ) override;
317 void MirrorHorizontally( int aCenter ) override;
318 void MirrorVertically( int aCenter ) override;
319 void Rotate( const VECTOR2I& aCenter ) override;
320
321 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
322
323 bool IsReplaceable() const override { return true; }
324
330 void Resize( const wxSize& aSize );
331
332 void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
333
334 void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
335
336 bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
337 const SCH_SHEET_PATH* aPath = nullptr ) override;
338
339 bool IsConnectable() const override { return true; }
340
341 bool CanConnect( const SCH_ITEM* aItem ) const override
342 {
343 return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE )
344 || ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS )
345 || ( aItem->Type() == SCH_NO_CONNECT_T )
346 || ( aItem->Type() == SCH_SYMBOL_T );
347 }
348
349 std::vector<VECTOR2I> GetConnectionPoints() const override;
350
351 INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
352 const std::vector<KICAD_T>& aScanTypes ) override;
353
354 void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
355
356 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
357
358 BITMAPS GetMenuImage() const override;
359
360 SCH_SHEET& operator=( const SCH_ITEM& aSheet );
361
362 bool operator <( const SCH_ITEM& aItem ) const override;
363
364 void ViewGetLayers( int aLayers[], int& aCount ) const override;
365
366 VECTOR2I GetPosition() const override { return m_pos; }
367 void SetPosition( const VECTOR2I& aPosition ) override;
368
369 bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
370 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
371
372 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
373
374 EDA_ITEM* Clone() const override;
375
379 const std::vector<SCH_SHEET_INSTANCE>& GetInstances() const { return m_instances; }
380
381 void SetInstances( const std::vector<SCH_SHEET_INSTANCE>& aInstances )
382 {
383 m_instances = aInstances;
384 }
385
401 bool AddInstance( const SCH_SHEET_PATH& aInstance );
402
408 static int ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB );
409
410#if defined(DEBUG)
411 void Show( int nestLevel, std::ostream& os ) const override;
412#endif
413
414 static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslated = true );
415
416protected:
418
429 wxString getPageNumber( const SCH_SHEET_PATH& aInstance ) const;
430
442 void setPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
443
451 void renumberPins();
452
457 SCH_SHEET_PATH findSelf() const;
458
459private:
460 bool doIsConnected( const VECTOR2I& aPosition ) const override;
461
462 friend class SCH_SHEET_PIN;
463
464private:
465 SCH_SCREEN* m_screen; // Screen that contains the physical data for the
466 // sheet. In complex hierarchies multiple sheets
467 // can share a common screen.
468
469 std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
470 std::vector<SCH_FIELD> m_fields;
471
472 VECTOR2I m_pos; // The position of the sheet.
473 wxSize m_size; // The size of the sheet.
477
478 std::vector<SCH_SHEET_INSTANCE> m_instances;
479};
480
481
482#endif // SCH_SHEEET_H
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition: plotter.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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:55
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:955
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:202
friend SCH_SHEET_PATH
Definition: sch_sheet.h:417
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:809
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:113
const std::vector< SCH_SHEET_PIN * > & GetPins() const
Definition: sch_sheet.h:174
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:306
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:300
bool IsRootSheet() const
Definition: sch_sheet.cpp:194
void SetInstances(const std::vector< SCH_SHEET_INSTANCE > &aInstances)
Definition: sch_sheet.h:381
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:1044
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_sheet.cpp:967
void SetSize(const wxSize &aSize)
Definition: sch_sheet.h:107
void setPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1252
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:55
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:353
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:75
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:1027
int GetPenWidth() const override
Definition: sch_sheet.cpp:578
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:156
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_sheet.cpp:1037
bool IsConnectable() const override
Definition: sch_sheet.h:339
SCH_SHEET_PATH findSelf() const
Get the sheetpath of this sheet.
Definition: sch_sheet.cpp:935
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:916
VECTOR2I m_pos
Definition: sch_sheet.h:472
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:91
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:475
wxString GetName() const
Definition: sch_sheet.h:101
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:923
VECTOR2I GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:678
SCH_SHEET(EDA_ITEM *aParent=nullptr, const VECTOR2I &aPos=VECTOR2I(0, 0), wxSize aSize=wxSize(schIUScale.MilsToIU(MIN_SHEET_WIDTH), schIUScale.MilsToIU(MIN_SHEET_HEIGHT)), FIELDS_AUTOPLACED aAutoplaceFields=FIELDS_AUTOPLACED_AUTO)
Definition: sch_sheet.cpp:77
SCH_SHEET_PIN * GetPin(const VECTOR2I &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:566
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1188
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:540
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:364
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:707
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:743
std::vector< SCH_SHEET_INSTANCE > m_instances
Definition: sch_sheet.h:478
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:426
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_sheet.cpp:891
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:116
int SymbolCount() const
Count our own symbols, without the power symbols.
Definition: sch_sheet.cpp:685
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_sheet.h:323
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:472
SCH_SCREEN * m_screen
Definition: sch_sheet.h:465
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:633
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:470
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:476
void SetName(const wxString &aName)
Definition: sch_sheet.h:102
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:767
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:104
bool HasPins() const
Definition: sch_sheet.h:208
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:366
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
Definition: sch_sheet.cpp:646
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:381
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1270
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1205
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:899
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:871
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:1073
wxString getPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1231
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
Definition: sch_sheet.cpp:331
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:185
wxSize m_size
Definition: sch_sheet.h:473
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1158
wxSize GetSize() const
Definition: sch_sheet.h:106
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:393
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:590
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:667
const std::vector< SCH_FIELD > & GetFields() const
Definition: sch_sheet.h:92
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:979
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:112
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:469
bool IsMovableFromAnchorPoint() const override
Return true for items which are moved with the anchor point at mouse cursor and false for items moved...
Definition: sch_sheet.h:89
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:341
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:990
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:110
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_sheet.h:70
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:851
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_sheet.cpp:297
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:506
int m_borderWidth
Definition: sch_sheet.h:474
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:797
int GetBorderWidth() const
Definition: sch_sheet.h:109
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:781
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:173
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:379
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:405
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_sheet.cpp:1126
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:233
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:1050
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:115
INSPECT_RESULT
Definition: eda_item.h:42
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:78
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_BUS
Definition: layer_ids.h:345
FIELDS_AUTOPLACED
Definition: sch_item.h:55
@ FIELDS_AUTOPLACED_AUTO
Definition: sch_item.h:57
SHEET_FIELD_TYPE
Definition: sch_sheet.h:42
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
@ SHEETNAME
Definition: sch_sheet.h:43
@ SHEETFILENAME
Definition: sch_sheet.h:44
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:38
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:37
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_SHEET_T
Definition: typeinfo.h:158
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618