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( wxString aFilename )
322  {
323  // Filenames are stored using unix notation
324  aFilename.Replace( wxT("\\"), wxT("/") );
325  m_fields[ SHEETFILENAME ].SetText( aFilename );
326  }
328  // Geometric transforms (used in block operations):
330  void Move( const wxPoint& aMoveVector ) override;
331  void MirrorHorizontally( int aCenter ) override;
332  void MirrorVertically( int aCenter ) override;
333  void Rotate( const wxPoint& aCenter ) override;
335  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
337  bool IsReplaceable() const override { return true; }
344  void Resize( const wxSize& aSize );
346  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
348  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
350  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
351  const SCH_SHEET_PATH* aPath = nullptr ) override;
353  bool IsConnectable() const override { return true; }
355  bool CanConnect( const SCH_ITEM* aItem ) const override
356  {
357  return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE )
358  || ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS )
359  || ( aItem->Type() == SCH_NO_CONNECT_T )
360  || ( aItem->Type() == SCH_SYMBOL_T );
361  }
363  std::vector<wxPoint> GetConnectionPoints() const override;
365  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
367  void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
369  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
371  BITMAPS GetMenuImage() const override;
373  SCH_SHEET& operator=( const SCH_ITEM& aSheet );
375  bool operator <( const SCH_ITEM& aItem ) const override;
377  void ViewGetLayers( int aLayers[], int& aCount ) const override;
379  wxPoint GetPosition() const override { return m_pos; }
380  void SetPosition( const wxPoint& aPosition ) override;
382  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
383  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
385  void Plot( PLOTTER* aPlotter ) const override;
387  EDA_ITEM* Clone() const override;
392  const std::vector<SCH_SHEET_INSTANCE> GetInstances() const;
404  bool AddInstance( const KIID_PATH& aInstance );
411  wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const;
419  void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
426  static int ComparePageNum( const wxString& aPageNumberA, const wxString aPageNumberB );
428 #if defined(DEBUG)
429  void Show( int nestLevel, std::ostream& os ) const override;
430 #endif
432  static const wxString GetDefaultFieldName( int aFieldNdx );
434 protected:
442  void renumberPins();
444 private:
445  bool doIsConnected( const wxPoint& aPosition ) const override;
447  friend class SCH_SHEET_PIN;
449  SCH_SCREEN* m_screen; // Screen that contains the physical data for the sheet. In
450  // complex hierarchies multiple sheets can share a common screen.
452  std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
453  std::vector<SCH_FIELD> m_fields;
455  wxPoint m_pos; // The position of the sheet.
456  wxSize m_size; // The size of the sheet.
461  std::vector<SCH_SHEET_INSTANCE> m_instances;
462 };
465 #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:559
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:630
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:498
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:776
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:458
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
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
int GetMinWidth(bool aFromLeft) const
Return the minimum width of the sheet based on the widths of the sheet pin text.
Definition: sch_sheet.cpp:404
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Definition: sch_sheet.cpp:842
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:157
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:197
wxSize m_size
Definition: sch_sheet.h:456
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:340
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:373
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:111
bool UsesDefaultStroke() const
Test this sheet to see if the default stroke is used to draw the outline.
Definition: sch_sheet.cpp:260
int GetMinHeight(bool aFromTop) const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
Definition: sch_sheet.cpp:438
static int ComparePageNum(const wxString &aPageNumberA, const wxString aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1151
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_sheet.cpp:925
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1077
The base class for create windows for drawing purpose.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:786
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
wxPoint m_pos
Definition: sch_sheet.h:455
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:300
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1136
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:461
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:734
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:961
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:114
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:180
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:830
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_sheet.cpp:706
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:72
int GetBorderWidth() const
Definition: sch_sheet.h:108
void SetFileName(wxString aFilename)
Definition: sch_sheet.h:321
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:115
bool IsConnectable() const override
Definition: sch_sheet.h:353
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:932
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:590
wxString GetName() const
Definition: sch_sheet.h:101
SCH_SHEET(EDA_ITEM *aParent=nullptr, const wxPoint &pos=wxPoint(0, 0))
Definition: sch_sheet.cpp:74
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_sheet.h:337
int m_borderWidth
Definition: sch_sheet.h:457
int GetPenWidth() const override
Definition: sch_sheet.cpp:510
bool IsRootSheet() const
Definition: sch_sheet.cpp:189
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:452
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: sch_sheet.cpp:877
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:569
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:47
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:608
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:866
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:472
wxPoint GetPosition() const override
Definition: sch_sheet.h:379
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:311
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:1011
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:184
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:453
Definition: eda_units.h:38
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:692
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:666
Base plotter engine class.
Definition: plotter.h:121
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_sheet.cpp:266
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:915
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:151
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_sheet.cpp:854
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:355
wxSize GetSize() const
Definition: sch_sheet.h:105
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:352
void SetPosition(const wxPoint &aPosition) override
Definition: sch_sheet.cpp:796
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:459
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:449
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:601
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:211
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:516
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:821
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:328
Definition: eda_item.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:722
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1118
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1047
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1094
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:804
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_sheet.cpp:938
const std::vector< SCH_SHEET_PIN * > & GetPins() const
Definition: sch_sheet.h:186