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-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
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 
30 class KIID_PATH;
31 class SCH_SCREEN;
32 class SCH_SHEET_PIN;
33 class SCH_SHEET_PATH;
34 class 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 {
43  SHEETNAME = 0,
45 
48 };
49 
50 
54 class SCH_SHEET : public SCH_ITEM
55 {
56 public:
57  SCH_SHEET( EDA_ITEM* aParent = nullptr, const wxPoint& aPos = wxPoint( 0, 0 ),
58  wxSize aSize = wxSize( Mils2iu( MIN_SHEET_WIDTH ), Mils2iu( MIN_SHEET_HEIGHT ) ),
59  FIELDS_AUTOPLACED aAutoplaceFields = FIELDS_AUTOPLACED_AUTO );
60 
65  SCH_SHEET( const SCH_SHEET& aSheet );
66 
67  ~SCH_SHEET();
68 
69  static inline bool ClassOf( const EDA_ITEM* aItem )
70  {
71  return aItem && SCH_SHEET_T == aItem->Type();
72  }
73 
74  wxString GetClass() const override
75  {
76  return wxT( "SCH_SHEET" );
77  }
78 
88  bool IsMovableFromAnchorPoint() const override { return false; }
89 
90  std::vector<SCH_FIELD>& GetFields() { return m_fields; }
91  const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
92 
98  void SetFields( const std::vector<SCH_FIELD>& aFields );
99 
100  wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }
101 
102  SCH_SCREEN* GetScreen() const { return m_screen; }
103 
104  wxSize GetSize() const { return m_size; }
105  void SetSize( const wxSize& aSize ) { m_size = aSize; }
106 
107  int GetBorderWidth() const { return m_borderWidth; }
108  void SetBorderWidth( int aWidth ) { m_borderWidth = aWidth; }
109 
111  void SetBorderColor( KIGFX::COLOR4D aColor ) { m_borderColor = aColor; }
112 
115 
126  bool UsesDefaultStroke() const;
127 
131  bool IsRootSheet() const;
132 
144  void SetScreen( SCH_SCREEN* aScreen );
145 
151  int GetScreenCount() const;
152 
156  void GetContextualTextVars( wxArrayString* aVars ) const;
157 
163  bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
164 
165  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
166 
167  /* there is no member for orientation in sch_sheet, to preserve file
168  * format, we detect orientation based on pin edges
169  */
170  bool IsVerticalOrientation() const;
171 
181  void AddPin( SCH_SHEET_PIN* aSheetPin );
182 
183  std::vector<SCH_SHEET_PIN*>& GetPins() { return m_pins; }
184 
185  const std::vector<SCH_SHEET_PIN*>& GetPins() const
186  {
187  return m_pins;
188  }
189 
195  void RemovePin( const SCH_SHEET_PIN* aSheetPin );
196 
203  void CleanupSheet();
204 
212  SCH_SHEET_PIN* GetPin( const wxPoint& aPosition );
213 
220  bool HasPin( const wxString& aName ) const;
221 
222  bool HasPins() const { return !m_pins.empty(); }
223 
229  bool HasUndefinedPins() const;
230 
242  int GetMinWidth( bool aFromLeft ) const;
243 
254  int GetMinHeight( bool aFromTop ) const;
255 
256  int GetPenWidth() const override;
257 
258  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
259 
263  const EDA_RECT GetBodyBoundingBox() const;
264 
265  const EDA_RECT GetBoundingBox() const override;
266 
272  wxPoint GetRotationCenter() const;
273 
274  void SwapData( SCH_ITEM* aItem ) override;
275 
279  int SymbolCount() const;
280 
288  bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
289 
300  bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
301 
307  int CountSheets() const;
308 
314  wxString GetFileName() const
315  {
316  return m_fields[ SHEETFILENAME ].GetText();
317  }
318 
319  // Set a new filename without changing anything else
320  void SetFileName( const wxString& aFilename )
321  {
322  // Filenames are stored using unix notation
323  wxString tmp = aFilename;
324  tmp.Replace( wxT( "\\" ), wxT( "/" ) );
325  m_fields[ SHEETFILENAME ].SetText( tmp );
326  }
327 
328  // Geometric transforms (used in block operations):
329 
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;
334 
335  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
336 
337  bool IsReplaceable() const override { return true; }
338 
344  void Resize( const wxSize& aSize );
345 
346  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
347 
348  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
349 
350  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
351  const SCH_SHEET_PATH* aPath = nullptr ) override;
352 
353  bool IsConnectable() const override { return true; }
354 
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  }
362 
363  std::vector<wxPoint> GetConnectionPoints() const override;
364 
365  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
366 
367  void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
368 
369  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
370 
371  BITMAPS GetMenuImage() const override;
372 
373  SCH_SHEET& operator=( const SCH_ITEM& aSheet );
374 
375  bool operator <( const SCH_ITEM& aItem ) const override;
376 
377  void ViewGetLayers( int aLayers[], int& aCount ) const override;
378 
379  wxPoint GetPosition() const override { return m_pos; }
380  void SetPosition( const wxPoint& aPosition ) override;
381 
382  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
383  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
384 
385  void Plot( PLOTTER* aPlotter ) const override;
386 
387  EDA_ITEM* Clone() const override;
388 
392  const std::vector<SCH_SHEET_INSTANCE>& GetInstances() const { return m_instances; }
393 
394  void SetInstances( const std::vector<SCH_SHEET_INSTANCE>& aInstances )
395  {
396  m_instances = aInstances;
397  }
398 
414  bool AddInstance( const SCH_SHEET_PATH& aInstance );
415 
426  wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const;
427 
439  void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
440 
446  static int ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB );
447 
448 #if defined(DEBUG)
449  void Show( int nestLevel, std::ostream& os ) const override;
450 #endif
451 
452  static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslated = true );
453 
454 protected:
462  void renumberPins();
463 
464 private:
465  bool doIsConnected( const wxPoint& aPosition ) const override;
466 
467  friend class SCH_SHEET_PIN;
468 
469  SCH_SCREEN* m_screen; // Screen that contains the physical data for the sheet. In
470  // complex hierarchies multiple sheets can share a common screen.
471 
472  std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
473  std::vector<SCH_FIELD> m_fields;
474 
475  wxPoint m_pos; // The position of the sheet.
476  wxSize m_size; // The size of the sheet.
480 
481  std::vector<SCH_SHEET_INSTANCE> m_instances;
482 };
483 
484 
485 #endif // SCH_SHEEET_H
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:622
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:693
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:555
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:839
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:478
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.cpp:320
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:320
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:461
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:925
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:175
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:215
wxSize m_size
Definition: sch_sheet.h:476
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1227
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:382
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:415
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:53
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:110
bool UsesDefaultStroke() const
Test this sheet to see if the default stroke is used to draw the outline.
Definition: sch_sheet.cpp:280
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:495
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:1008
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1148
The base class for create windows for drawing purpose.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:859
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:102
wxPoint m_pos
Definition: sch_sheet.h:475
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:342
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1210
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:93
KICAD_T
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:481
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:37
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:797
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:1044
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:113
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:108
void SetInstances(const std::vector< SCH_SHEET_INSTANCE > &aInstances)
Definition: sch_sheet.h:394
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:90
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:198
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:913
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:769
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:74
int GetBorderWidth() const
Definition: sch_sheet.h:107
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:114
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:1015
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:653
wxString GetName() const
Definition: sch_sheet.h:100
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:477
int GetPenWidth() const override
Definition: sch_sheet.cpp:567
bool IsRootSheet() const
Definition: sch_sheet.cpp:207
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:472
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:960
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:111
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:88
const EDA_RECT GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
Definition: sch_sheet.cpp:632
SHEET_FIELD_TYPE
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:671
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:314
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:949
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:529
wxPoint GetPosition() const override
Definition: sch_sheet.h:379
SCH_SHEET(EDA_ITEM *aParent=nullptr, const wxPoint &aPos=wxPoint(0, 0), wxSize aSize=wxSize(Mils2iu(MIN_SHEET_WIDTH), Mils2iu(MIN_SHEET_HEIGHT)), FIELDS_AUTOPLACED aAutoplaceFields=FIELDS_AUTOPLACED_AUTO)
Definition: sch_sheet.cpp:90
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:353
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:105
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_sheet.cpp:1083
FIELDS_AUTOPLACED
Definition: sch_item.h:52
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:259
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:183
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:473
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:392
EDA_UNITS
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:755
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:729
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:286
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:998
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:169
BITMAPS
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:937
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:355
wxSize GetSize() const
Definition: sch_sheet.h:104
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:394
void SetPosition(const wxPoint &aPosition) override
Definition: sch_sheet.cpp:879
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:479
Handle the component boundary box.
Definition: eda_rect.h:42
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_sheet.h:69
SCH_SCREEN * m_screen
Definition: sch_sheet.h:469
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:38
bool HasPins() const
Definition: sch_sheet.h:222
wxPoint GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:664
const std::vector< SCH_FIELD > & GetFields() const
Definition: sch_sheet.h:91
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:229
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:579
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:904
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:370
SEARCH_RESULT
Definition: eda_item.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_sheet.cpp:785
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1190
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1118
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1165
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:887
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 inside or on the boundary of this item.
Definition: sch_sheet.cpp:1021
const std::vector< SCH_SHEET_PIN * > & GetPins() const
Definition: sch_sheet.h:185