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  m_fields = aFields; // vector copying, length is changed possibly
101  }
102 
103  wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }
104 
105  SCH_SCREEN* GetScreen() const { return m_screen; }
106 
107  wxSize GetSize() const { return m_size; }
108  void SetSize( const wxSize& aSize ) { m_size = aSize; }
109 
110  int GetBorderWidth() const { return m_borderWidth; }
111  void SetBorderWidth( int aWidth ) { m_borderWidth = aWidth; }
112 
114  void SetBorderColor( KIGFX::COLOR4D aColor ) { m_borderColor = aColor; }
115 
118 
129  bool UsesDefaultStroke() const;
130 
134  bool IsRootSheet() const;
135 
147  void SetScreen( SCH_SCREEN* aScreen );
148 
154  int GetScreenCount() const;
155 
159  void GetContextualTextVars( wxArrayString* aVars ) const;
160 
166  bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
167 
168  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
169 
170  /* there is no member for orientation in sch_sheet, to preserve file
171  * format, we detect orientation based on pin edges
172  */
173  bool IsVerticalOrientation() const;
174 
184  void AddPin( SCH_SHEET_PIN* aSheetPin );
185 
186  std::vector<SCH_SHEET_PIN*>& GetPins() { return m_pins; }
187 
188  const std::vector<SCH_SHEET_PIN*>& GetPins() const
189  {
190  return m_pins;
191  }
192 
198  void RemovePin( const SCH_SHEET_PIN* aSheetPin );
199 
206  void CleanupSheet();
207 
215  SCH_SHEET_PIN* GetPin( const wxPoint& aPosition );
216 
223  bool HasPin( const wxString& aName ) const;
224 
225  bool HasPins() const { return !m_pins.empty(); }
226 
232  bool HasUndefinedPins() const;
233 
245  int GetMinWidth( bool aFromLeft ) const;
246 
257  int GetMinHeight( bool aFromTop ) const;
258 
259  int GetPenWidth() const override;
260 
261  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
262 
266  const EDA_RECT GetBodyBoundingBox() const;
267 
268  const EDA_RECT GetBoundingBox() const override;
269 
275  wxPoint GetRotationCenter() const;
276 
277  void SwapData( SCH_ITEM* aItem ) override;
278 
282  int SymbolCount() const;
283 
291  bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
292 
303  bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
304 
310  int CountSheets() const;
311 
317  wxString GetFileName() const
318  {
319  return m_fields[ SHEETFILENAME ].GetText();
320  }
321 
322  // Set a new filename without changing anything else
323  void SetFileName( const wxString& aFilename )
324  {
325  // Filenames are stored using unix notation
326  wxString tmp = aFilename;
327  tmp.Replace( wxT( "\\" ), wxT( "/" ) );
328  m_fields[ SHEETFILENAME ].SetText( tmp );
329  }
330 
331  // Geometric transforms (used in block operations):
332 
333  void Move( const wxPoint& aMoveVector ) override;
334  void MirrorHorizontally( int aCenter ) override;
335  void MirrorVertically( int aCenter ) override;
336  void Rotate( const wxPoint& aCenter ) override;
337 
338  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
339 
340  bool IsReplaceable() const override { return true; }
341 
347  void Resize( const wxSize& aSize );
348 
349  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
350 
351  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
352 
353  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
354  const SCH_SHEET_PATH* aPath = nullptr ) override;
355 
356  bool IsConnectable() const override { return true; }
357 
358  bool CanConnect( const SCH_ITEM* aItem ) const override
359  {
360  return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE )
361  || ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS )
362  || ( aItem->Type() == SCH_NO_CONNECT_T )
363  || ( aItem->Type() == SCH_SYMBOL_T );
364  }
365 
366  std::vector<wxPoint> GetConnectionPoints() const override;
367 
368  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
369 
370  void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
371 
372  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
373 
374  BITMAPS GetMenuImage() const override;
375 
376  SCH_SHEET& operator=( const SCH_ITEM& aSheet );
377 
378  bool operator <( const SCH_ITEM& aItem ) const override;
379 
380  void ViewGetLayers( int aLayers[], int& aCount ) const override;
381 
382  wxPoint GetPosition() const override { return m_pos; }
383  void SetPosition( const wxPoint& aPosition ) override;
384 
385  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
386  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
387 
388  void Plot( PLOTTER* aPlotter ) const override;
389 
390  EDA_ITEM* Clone() const override;
391 
395  const std::vector<SCH_SHEET_INSTANCE>& GetInstances() const { return m_instances; }
396 
397  void SetInstances( const std::vector<SCH_SHEET_INSTANCE>& aInstances )
398  {
399  m_instances = aInstances;
400  }
401 
417  bool AddInstance( const SCH_SHEET_PATH& aInstance );
418 
429  wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const;
430 
442  void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
443 
449  static int ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB );
450 
451 #if defined(DEBUG)
452  void Show( int nestLevel, std::ostream& os ) const override;
453 #endif
454 
455  static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslated = true );
456 
457 protected:
465  void renumberPins();
466 
467 private:
468  bool doIsConnected( const wxPoint& aPosition ) const override;
469 
470  friend class SCH_SHEET_PIN;
471 
472  SCH_SCREEN* m_screen; // Screen that contains the physical data for the sheet. In
473  // complex hierarchies multiple sheets can share a common screen.
474 
475  std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
476  std::vector<SCH_FIELD> m_fields;
477 
478  wxPoint m_pos; // The position of the sheet.
479  wxSize m_size; // The size of the sheet.
483 
484  std::vector<SCH_SHEET_INSTANCE> m_instances;
485 };
486 
487 
488 #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:595
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:666
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:528
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_sheet.cpp:812
KIGFX::COLOR4D m_borderColor
Definition: sch_sheet.h:481
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:98
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: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:434
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:898
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:212
wxSize m_size
Definition: sch_sheet.h:479
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1200
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_sheet.cpp:355
bool HasUndefinedPins() const
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:388
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:50
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:113
bool UsesDefaultStroke() const
Test this sheet to see if the default stroke is used to draw the outline.
Definition: sch_sheet.cpp:275
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:468
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:981
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_sheet.cpp:1121
The base class for create windows for drawing purpose.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_sheet.cpp:832
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
wxPoint m_pos
Definition: sch_sheet.h:478
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:315
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1183
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:484
#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:770
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_sheet.cpp:1017
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:116
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:111
void SetInstances(const std::vector< SCH_SHEET_INSTANCE > &aInstances)
Definition: sch_sheet.h:397
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:195
void renumberPins()
Renumber the sheet pins in the sheet.
Definition: sch_sheet.cpp:886
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:742
wxString GetClass() const override
Return the class name.
Definition: sch_sheet.h:74
int GetBorderWidth() const
Definition: sch_sheet.h:110
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:117
bool IsConnectable() const override
Definition: sch_sheet.h:356
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_sheet.cpp:988
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_sheet.cpp:626
wxString GetName() const
Definition: sch_sheet.h:103
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_sheet.h:340
int m_borderWidth
Definition: sch_sheet.h:480
int GetPenWidth() const override
Definition: sch_sheet.cpp:540
bool IsRootSheet() const
Definition: sch_sheet.cpp:204
std::vector< SCH_SHEET_PIN * > m_pins
Definition: sch_sheet.h:475
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:933
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:114
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:605
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:644
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:317
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_sheet.cpp:922
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:502
wxPoint GetPosition() const override
Definition: sch_sheet.h:382
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:87
void RemovePin(const SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:326
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:108
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_sheet.cpp:1056
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:186
std::vector< SCH_FIELD > m_fields
Definition: sch_sheet.h:476
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:395
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:728
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:702
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:281
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction) override
Definition: sch_sheet.cpp:971
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:166
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:910
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:358
wxSize GetSize() const
Definition: sch_sheet.h:107
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:367
void SetPosition(const wxPoint &aPosition) override
Definition: sch_sheet.cpp:852
KIGFX::COLOR4D m_backgroundColor
Definition: sch_sheet.h:482
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:472
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:225
wxPoint GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:637
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:226
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:552
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_sheet.cpp:877
bool HasPin(const wxString &aName) const
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:343
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:758
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1163
SCH_SHEET & operator=(const SCH_ITEM &aSheet)
Definition: sch_sheet.cpp:1091
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:1138
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:860
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:994
const std::vector< SCH_SHEET_PIN * > & GetPins() const
Definition: sch_sheet.h:188