KiCad PCB EDA Suite
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
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
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  *
20  * or you may search the 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  */
25 #ifndef SCH_SHEEET_H
26 #define SCH_SHEEET_H
28 #include <sch_field.h>
30 class KIID_PATH;
31 class SCH_SCREEN;
32 class SCH_SHEET_PIN;
33 class SCH_SHEET_PATH;
34 class EDA_DRAW_FRAME;
37 #define MIN_SHEET_WIDTH 500 // Units are mils.
38 #define MIN_SHEET_HEIGHT 150 // Units are mils.
42 {
43  SHEETNAME = 0,
48 };
54 class SCH_SHEET : public SCH_ITEM
55 {
56 public:
57  SCH_SHEET( EDA_ITEM* aParent = nullptr, const wxPoint& pos = wxPoint( 0, 0 ) );
63  SCH_SHEET( const SCH_SHEET& aSheet );
65  ~SCH_SHEET();
67  static inline bool ClassOf( const EDA_ITEM* aItem )
68  {
69  return aItem && SCH_SHEET_T == aItem->Type();
70  }
72  wxString GetClass() const override
73  {
74  return wxT( "SCH_SHEET" );
75  }
86  bool IsMovableFromAnchorPoint() const override { return false; }
88  std::vector<SCH_FIELD>& GetFields() { return m_fields; }
89  const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
96  void SetFields( const std::vector<SCH_FIELD>& aFields )
97  {
98  m_fields = aFields; // vector copying, length is changed possibly
99  }
101  wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }
103  SCH_SCREEN* GetScreen() const { return m_screen; }
105  wxSize GetSize() const { return m_size; }
106  void SetSize( const wxSize& aSize ) { m_size = aSize; }
108  int GetBorderWidth() const { return m_borderWidth; }
109  void SetBorderWidth( int aWidth ) { m_borderWidth = aWidth; }
112  void SetBorderColor( KIGFX::COLOR4D aColor ) { m_borderColor = aColor; }
127  bool UsesDefaultStroke() const;
132  bool IsRootSheet() const;
145  void SetScreen( SCH_SCREEN* aScreen );
152  int GetScreenCount() const;
157  void GetContextualTextVars( wxArrayString* aVars ) const;
164  bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
166  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
168  /* there is no member for orientation in sch_sheet, to preserve file
169  * format, we detect orientation based on pin edges
170  */
171  bool IsVerticalOrientation() const;
182  void AddPin( SCH_SHEET_PIN* aSheetPin );
184  std::vector<SCH_SHEET_PIN*>& GetPins() { return m_pins; }
186  const std::vector<SCH_SHEET_PIN*>& GetPins() const
187  {
188  return m_pins;
189  }
196  void RemovePin( const SCH_SHEET_PIN* aSheetPin );
204  void CleanupSheet();
213  SCH_SHEET_PIN* GetPin( const wxPoint& aPosition );
221  bool HasPin( const wxString& aName ) const;
223  bool HasPins() const { return !m_pins.empty(); }
230  bool HasUndefinedPins() const;
243  int GetMinWidth( bool aFromLeft ) const;
255  int GetMinHeight( bool aFromTop ) const;
257  int GetPenWidth() const override;
259  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
264  const EDA_RECT GetBodyBoundingBox() const;
266  const EDA_RECT GetBoundingBox() const override;
273  wxPoint GetRotationCenter() const;
275  void SwapData( SCH_ITEM* aItem ) override;
280  int SymbolCount() const;
289  bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
301  bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
308  int CountSheets() const;
315  wxString GetFileName() const
316  {
317  return m_fields[ SHEETFILENAME ].GetText();
318  }
320  // Set a new filename without changing anything else
321  void SetFileName( const wxString& aFilename )
322  {
323  // Filenames are stored using unix notation
324  wxString tmp = aFilename;
325  tmp.Replace( wxT( "\\" ), wxT( "/" ) );
326  m_fields[ SHEETFILENAME ].SetText( tmp );
327  }
329  // Geometric transforms (used in block operations):
331  void Move( const wxPoint& aMoveVector ) override;
332  void MirrorHorizontally( int aCenter ) override;
333  void MirrorVertically( int aCenter ) override;
334  void Rotate( const wxPoint& aCenter ) override;
336  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
338  bool IsReplaceable() const override { return true; }
345  void Resize( const wxSize& aSize );
347  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
349  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
351  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
352  const SCH_SHEET_PATH* aPath = nullptr ) override;
354  bool IsConnectable() const override { return true; }
356  bool CanConnect( const SCH_ITEM* aItem ) const override
357  {
358  return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE )
359  || ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS )
360  || ( aItem->Type() == SCH_NO_CONNECT_T )
361  || ( aItem->Type() == SCH_SYMBOL_T );
362  }
364  std::vector<wxPoint> GetConnectionPoints() const override;
366  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
368  void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
370  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
372  BITMAPS GetMenuImage() const override;
374  SCH_SHEET& operator=( const SCH_ITEM& aSheet );
376  bool operator <( const SCH_ITEM& aItem ) const override;
378  void ViewGetLayers( int aLayers[], int& aCount ) const override;
380  wxPoint GetPosition() const override { return m_pos; }
381  void SetPosition( const wxPoint& aPosition ) override;
383  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
384  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
386  void Plot( PLOTTER* aPlotter ) const override;
388  EDA_ITEM* Clone() const override;
393  const std::vector<SCH_SHEET_INSTANCE> GetInstances() const;
405  bool AddInstance( const KIID_PATH& aInstance );
412  wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const;
420  void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
427  static int ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB );
429 #if defined(DEBUG)
430  void Show( int nestLevel, std::ostream& os ) const override;
431 #endif
433  static const wxString GetDefaultFieldName( int aFieldNdx );
435 protected:
443  void renumberPins();
445 private:
446  bool doIsConnected( const wxPoint& aPosition ) const override;
448  friend class SCH_SHEET_PIN;
450  SCH_SCREEN* m_screen; // Screen that contains the physical data for the sheet. In
451  // complex hierarchies multiple sheets can share a common screen.
453  std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
454  std::vector<SCH_FIELD> m_fields;
456  wxPoint m_pos; // The position of the sheet.
457  wxSize m_size; // The size of the sheet.
462  std::vector<SCH_SHEET_INSTANCE> m_instances;
463 };
466 #endif // SCH_SHEEET_H
const std::vector< SCH_SHEET_INSTANCE > GetInstances() const
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:564
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:635
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:497
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:781
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:459
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
Definition: sch_sheet.h:96
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:321
int GetMinWidth(bool aFromLeft) const
Return the minimum width of the sheet based on the widths of the sheet pin text.
Definition: sch_sheet.cpp:403
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Definition: sch_sheet.cpp:847
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:156
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:196
wxSize m_size
Definition: sch_sheet.h:457
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1144
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:339
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:372
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:111
bool UsesDefaultStroke() const
Test this sheet to see if the default stroke is used to draw the outline.
Definition: sch_sheet.cpp:259
int GetMinHeight(bool aFromTop) const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
Definition: sch_sheet.cpp:437
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_sheet.cpp:930
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1070
The base class for create windows for drawing purpose.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:791
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
wxPoint m_pos
Definition: sch_sheet.h:456
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:299
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1129
Definition: eda_item.h:94
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
std::vector< SCH_SHEET_INSTANCE > m_instances
Definition: sch_sheet.h:462
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:739
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:966
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:114
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:109
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:179
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:835
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:711
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:72
int GetBorderWidth() const
Definition: sch_sheet.h:108
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:115
bool IsConnectable() const override
Definition: sch_sheet.h:354
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:937
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:595
wxString GetName() const
Definition: sch_sheet.h:101
SCH_SHEET(EDA_ITEM *aParent=nullptr, const wxPoint &pos=wxPoint(0, 0))
Definition: sch_sheet.cpp:73
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_sheet.h:338
int m_borderWidth
Definition: sch_sheet.h:458
int GetPenWidth() const override
Definition: sch_sheet.cpp:509
bool IsRootSheet() const
Definition: sch_sheet.cpp:188
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:453
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: sch_sheet.cpp:882
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:112
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:86
const EDA_RECT GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
Definition: sch_sheet.cpp:574
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:46
Definition: sch_sheet.h:41
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
int SymbolCount() const
Count our own symbols, without the power symbols.
Definition: sch_sheet.cpp:613
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:871
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:471
wxPoint GetPosition() const override
Definition: sch_sheet.h:380
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:310
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void SetSize(const wxSize &aSize)
Definition: sch_sheet.h:106
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_sheet.cpp:1005
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:268
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:184
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:454
Definition: eda_units.h:38
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:697
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:671
Base plotter engine class.
Definition: plotter.h:121
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_sheet.cpp:265
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:920
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:150
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_sheet.cpp:859
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:356
wxSize GetSize() const
Definition: sch_sheet.h:105
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:351
void SetPosition(const wxPoint &aPosition) override
Definition: sch_sheet.cpp:801
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:460
Handle the component boundary box.
Definition: eda_rect.h:42
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_sheet.h:67
SCH_SCREEN * m_screen
Definition: sch_sheet.h:450
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
bool HasPins() const
Definition: sch_sheet.h:223
wxPoint GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:606
const std::vector< SCH_FIELD > & GetFields() const
Definition: sch_sheet.h:89
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:210
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:521
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:826
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:327
Definition: eda_item.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:727
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1111
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1040
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1087
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:809
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_sheet.cpp:943
const std::vector< SCH_SHEET_PIN * > & GetPins() const
Definition: sch_sheet.h:186