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& pos = wxPoint( 0, 0 ) );
58 
63  SCH_SHEET( const SCH_SHEET& aSheet );
64 
65  ~SCH_SHEET();
66 
67  static inline bool ClassOf( const EDA_ITEM* aItem )
68  {
69  return aItem && SCH_SHEET_T == aItem->Type();
70  }
71 
72  wxString GetClass() const override
73  {
74  return wxT( "SCH_SHEET" );
75  }
76 
86  bool IsMovableFromAnchorPoint() const override { return false; }
87 
88  std::vector<SCH_FIELD>& GetFields() { return m_fields; }
89  const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
90 
96  void SetFields( const std::vector<SCH_FIELD>& aFields )
97  {
98  m_fields = aFields; // vector copying, length is changed possibly
99  }
100 
101  wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }
102 
103  SCH_SCREEN* GetScreen() const { return m_screen; }
104 
105  wxSize GetSize() const { return m_size; }
106  void SetSize( const wxSize& aSize ) { m_size = aSize; }
107 
108  int GetBorderWidth() const { return m_borderWidth; }
109  void SetBorderWidth( int aWidth ) { m_borderWidth = aWidth; }
110 
112  void SetBorderColor( KIGFX::COLOR4D aColor ) { m_borderColor = aColor; }
113 
116 
127  bool UsesDefaultStroke() const;
128 
132  bool IsRootSheet() const;
133 
145  void SetScreen( SCH_SCREEN* aScreen );
146 
152  int GetScreenCount() const;
153 
157  void GetContextualTextVars( wxArrayString* aVars ) const;
158 
164  bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
165 
166  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
167 
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;
172 
182  void AddPin( SCH_SHEET_PIN* aSheetPin );
183 
184  std::vector<SCH_SHEET_PIN*>& GetPins() { return m_pins; }
185 
186  const std::vector<SCH_SHEET_PIN*>& GetPins() const
187  {
188  return m_pins;
189  }
190 
196  void RemovePin( const SCH_SHEET_PIN* aSheetPin );
197 
204  void CleanupSheet();
205 
213  SCH_SHEET_PIN* GetPin( const wxPoint& aPosition );
214 
221  bool HasPin( const wxString& aName ) const;
222 
223  bool HasPins() const { return !m_pins.empty(); }
224 
230  bool HasUndefinedPins() const;
231 
243  int GetMinWidth( bool aFromLeft ) const;
244 
255  int GetMinHeight( bool aFromTop ) const;
256 
257  int GetPenWidth() const override;
258 
259  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
260 
264  const EDA_RECT GetBodyBoundingBox() const;
265 
266  const EDA_RECT GetBoundingBox() const override;
267 
273  wxPoint GetRotationCenter() const;
274 
275  void SwapData( SCH_ITEM* aItem ) override;
276 
280  int SymbolCount() const;
281 
289  bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
290 
301  bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
302 
308  int CountSheets() const;
309 
315  wxString GetFileName() const
316  {
317  return m_fields[ SHEETFILENAME ].GetText();
318  }
319 
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  }
328 
329  // Geometric transforms (used in block operations):
330 
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;
335 
336  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
337 
338  bool IsReplaceable() const override { return true; }
339 
345  void Resize( const wxSize& aSize );
346 
347  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
348 
349  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
350 
351  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
352  const SCH_SHEET_PATH* aPath = nullptr ) override;
353 
354  bool IsConnectable() const override { return true; }
355 
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  }
363 
364  std::vector<wxPoint> GetConnectionPoints() const override;
365 
366  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
367 
368  void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
369 
370  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
371 
372  BITMAPS GetMenuImage() const override;
373 
374  SCH_SHEET& operator=( const SCH_ITEM& aSheet );
375 
376  bool operator <( const SCH_ITEM& aItem ) const override;
377 
378  void ViewGetLayers( int aLayers[], int& aCount ) const override;
379 
380  wxPoint GetPosition() const override { return m_pos; }
381  void SetPosition( const wxPoint& aPosition ) override;
382 
383  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
384  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
385 
386  void Plot( PLOTTER* aPlotter ) const override;
387 
388  EDA_ITEM* Clone() const override;
389 
393  const std::vector<SCH_SHEET_INSTANCE> GetInstances() const;
394 
405  bool AddInstance( const KIID_PATH& aInstance );
406 
412  wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const;
413 
420  void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber );
421 
427  static int ComparePageNum( const wxString& aPageNumberA, const wxString& aPageNumberB );
428 
429 #if defined(DEBUG)
430  void Show( int nestLevel, std::ostream& os ) const override;
431 #endif
432 
433  static const wxString GetDefaultFieldName( int aFieldNdx );
434 
435 protected:
443  void renumberPins();
444 
445 private:
446  bool doIsConnected( const wxPoint& aPosition ) const override;
447 
448  friend class SCH_SHEET_PIN;
449 
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.
452 
453  std::vector<SCH_SHEET_PIN*> m_pins; // The list of sheet connection points.
454  std::vector<SCH_FIELD> m_fields;
455 
456  wxPoint m_pos; // The position of the sheet.
457  wxSize m_size; // The size of the sheet.
461 
462  std::vector<SCH_SHEET_INSTANCE> m_instances;
463 };
464 
465 
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
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
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: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
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: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
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: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
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: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
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: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