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-2017 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 
30 #ifndef SCH_SHEEET_H
31 #define SCH_SHEEET_H
32 
33 #include <boost/ptr_container/ptr_vector.hpp>
34 #include <sch_text.h>
35 
36 
37 class LINE_READER;
38 class SCH_SCREEN;
39 class SCH_SHEET;
40 class SCH_SHEET_PIN;
41 class SCH_SHEET_PATH;
42 class DANGLING_END_ITEM;
43 class SCH_EDIT_FRAME;
45 
46 
47 #define MIN_SHEET_WIDTH 500
48 #define MIN_SHEET_HEIGHT 150
49 
50 
62 {
63 public:
74  {
80  };
81 
82 private:
83  int m_number;
84 
89 
90 public:
91  SCH_SHEET_PIN( SCH_SHEET* parent,
92  const wxPoint& pos = wxPoint( 0, 0 ),
93  const wxString& text = wxEmptyString );
94 
95  // Do not create a copy constructor. The one generated by the compiler is adequate.
96 
98 
99  wxString GetClass() const override
100  {
101  return wxT( "SCH_SHEET_PIN" );
102  }
103 
104  bool operator ==( const SCH_SHEET_PIN* aPin ) const;
105 
112  bool IsMovableFromAnchorPoint() override { return true; }
113 
114  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
115  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
116 
123  void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos ) override;
124 
125  void SwapData( SCH_ITEM* aItem ) override;
126 
127  int GetPenSize() const override;
128 
134  int GetNumber() const { return m_number; }
135 
141  void SetNumber( int aNumber );
142 
143  void SetEdge( SHEET_SIDE aEdge );
144 
145  SHEET_SIDE GetEdge() const;
146 
151  void ConstrainOnEdge( wxPoint Pos );
152 
159  SCH_SHEET* GetParent() const { return (SCH_SHEET*) m_Parent; }
160 
161 #if defined(DEBUG)
162  void Show( int nestLevel, std::ostream& os ) const override;
163 #endif
164 
165  // Geometric transforms (used in block operations):
166 
167  void Move( const wxPoint& aMoveVector ) override
168  {
169  Offset( aMoveVector );
170  }
171 
172  void MirrorY( int aYaxis_position ) override;
173 
174  void Rotate( wxPoint aPosition ) override;
175 
176  void MirrorX( int aXaxis_position ) override;
177 
178  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
179 
180  bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override
181  {
182  return EDA_ITEM::Replace( aSearchData, m_Text );
183  }
184 
185  bool IsReplaceable() const override { return true; }
186 
187  void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
188 
189  bool IsConnectable() const override { return true; }
190 
191  wxString GetSelectMenuText() const override;
192 
193  BITMAP_DEF GetMenuImage() const override;
194 
195  void SetPosition( const wxPoint& aPosition ) override { ConstrainOnEdge( aPosition ); }
196 
197  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
198 
199  EDA_ITEM* Clone() const override;
200 };
201 
202 
203 typedef boost::ptr_vector<SCH_SHEET_PIN> SCH_SHEET_PINS;
204 
205 
209 class SCH_SHEET : public SCH_ITEM
210 {
211  friend class SCH_SHEET_PIN;
212 
216 
218  SCH_SHEET_PINS m_pins;
219 
222  wxString m_fileName;
223 
226  wxString m_name;
227 
230 
233 
236 
238  wxSize m_size;
239 
240 public:
241  SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) );
242 
247  SCH_SHEET( const SCH_SHEET& aSheet );
248 
249  ~SCH_SHEET();
250 
251  wxString GetClass() const override
252  {
253  return wxT( "SCH_SHEET" );
254  }
255 
265  bool IsMovableFromAnchorPoint() override { return false; }
266 
267  wxString GetName() const { return m_name; }
268 
269  void SetName( const wxString& aName ) { m_name = aName; }
270 
271  int GetSheetNameSize() const { return m_sheetNameSize; }
272 
273  void SetSheetNameSize( int aSize ) { m_sheetNameSize = aSize; }
274 
275  int GetFileNameSize() const { return m_fileNameSize; }
276 
277  void SetFileNameSize( int aSize ) { m_fileNameSize = aSize; }
278 
279  SCH_SCREEN* GetScreen() { return m_screen; }
280 
281  wxSize GetSize() { return m_size; }
282 
283  void SetSize( const wxSize& aSize ) { m_size = aSize; }
284 
294  SCH_SHEET* GetRootSheet();
295 
307  void SetScreen( SCH_SCREEN* aScreen );
308 
314  int GetScreenCount() const;
315 
316  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
317 
318  /* there is no member for orientation in sch_sheet, to preserve file
319  * format, we detect orientation based on pin edges
320  */
321  bool IsVerticalOrientation() const;
322 
332  void AddPin( SCH_SHEET_PIN* aSheetPin );
333 
334  SCH_SHEET_PINS& GetPins() { return m_pins; }
335 
336  SCH_SHEET_PINS& GetPins() const
337  {
338  return const_cast< SCH_SHEET_PINS& >( m_pins );
339  }
340 
346  void RemovePin( SCH_SHEET_PIN* aSheetPin );
347 
354  void CleanupSheet();
355 
363  SCH_SHEET_PIN* GetPin( const wxPoint& aPosition );
364 
372  bool HasPin( const wxString& aName );
373 
374  bool HasPins() { return !m_pins.empty(); }
375 
381  bool HasUndefinedPins();
382 
394  int GetMinWidth() const;
395 
406  int GetMinHeight() const;
407 
408  int GetPenSize() const override;
409 
410  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
411  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
412 
413  EDA_RECT const GetBoundingBox() const override;
414 
420  wxPoint GetResizePosition() const;
421 
422  void SwapData( SCH_ITEM* aItem ) override;
423 
429  int ComponentCount();
430 
438  bool SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen );
439 
450  bool LocatePathOfScreen( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aList );
451 
457  int CountSheets();
458 
464  wxString GetFileName( void ) const;
465 
466  // Set a new filename without changing anything else
467  void SetFileName( const wxString& aFilename )
468  {
469  m_fileName = aFilename;
470  // Filenames are stored using unix notation
471  m_fileName.Replace( wxT("\\"), wxT("/") );
472  }
473 
474  bool ChangeFileName( SCH_EDIT_FRAME* aFrame, const wxString& aFileName );
475 
476  // Geometric transforms (used in block operations):
477 
478  void Move( const wxPoint& aMoveVector ) override
479  {
480  m_pos += aMoveVector;
481 
482  for( SCH_SHEET_PIN& pin : m_pins )
483  {
484  pin.Move( aMoveVector );
485  }
486  }
487 
488  void MirrorY( int aYaxis_position ) override;
489 
490  void MirrorX( int aXaxis_position ) override;
491 
492  void Rotate( wxPoint aPosition ) override;
493 
494  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
495 
496  bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override;
497 
498  bool IsReplaceable() const override { return true; }
499 
505  void Resize( const wxSize& aSize );
506 
510  wxPoint GetSheetNamePosition();
511 
515  wxPoint GetFileNamePosition();
516 
517  void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) override;
518 
519  bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) override;
520 
521  bool IsDangling() const override;
522 
523  bool IsSelectStateChanged( const wxRect& aRect ) override;
524 
525  bool IsConnectable() const override { return true; }
526 
527  bool CanConnect( const SCH_ITEM* aItem ) const override
528  {
529  return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE ) ||
530  ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_BUS ) ||
531  ( aItem->Type() == SCH_NO_CONNECT_T );
532  }
533 
534  void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
535 
536  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
537 
538  wxString GetSelectMenuText() const override;
539 
540  BITMAP_DEF GetMenuImage() const override;
541 
542  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
543  SCH_SHEET_PATH* aSheetPath ) override;
544 
545  SCH_ITEM& operator=( const SCH_ITEM& aSheet );
546 
547  wxPoint GetPosition() const override { return m_pos; }
548 
549  void SetPosition( const wxPoint& aPosition ) override;
550 
551  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
552 
553  bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
554 
555  void Plot( PLOTTER* aPlotter ) override;
556 
557  EDA_ITEM* Clone() const override;
558 
559 #if defined(DEBUG)
560  void Show( int nestLevel, std::ostream& os ) const override;
561 #endif
562 
563 protected:
564 
572  void renumberPins();
573 };
574 
575 
576 typedef std::vector< SCH_SHEET* > SCH_SHEETS; // no ownership over contained SCH_SHEETs
577 
578 #endif // SCH_SHEEET_H
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:227
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:179
void SetFileNameSize(int aSize)
Definition: sch_sheet.h:277
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:159
std::vector< SCH_SHEET * > SCH_SHEETS
Definition: sch_sheet.h:576
wxString m_Text
Definition: eda_text.h:344
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:334
PNG memory record (file in memory).
Definition: bitmap_types.h:41
virtual bool IsDangling() const override
Definition: sch_text.h:177
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
SCH_SHEET_PIN(SCH_SHEET *parent, const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString)
bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:467
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: sch_text.cpp:607
int m_sheetNameSize
The height of the text used to draw the sheet name.
Definition: sch_sheet.h:229
SHEET_SIDE GetEdge() const
wxSize m_size
The size of the sheet.
Definition: sch_sheet.h:238
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_sheet.h:99
wxString m_name
This is equivalent to the reference designator for components and is stored in F0 sheet pin in the sc...
Definition: sch_sheet.h:226
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
Definition: sch_sheet.h:189
bool IsMovableFromAnchorPoint() override
Return true for items which are moved with the anchor point at mouse cursor and false for items moved...
Definition: sch_sheet.h:112
Schematic editor (Eeschema) main window.
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_sheet.h:185
bool operator==(const SCH_SHEET_PIN *aPin) const
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
wxPoint m_pos
The position of the sheet.
Definition: sch_sheet.h:235
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_sheet.h:180
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
wxString m_fileName
The file name is also in the SCH_SCREEN object associated with the sheet.
Definition: sch_sheet.h:222
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:100
int GetSheetNameSize() const
Definition: sch_sheet.h:271
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_sheet.h:251
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
Definition: sch_sheet.h:525
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_text.cpp:460
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_sheet.h:498
bool HasPins()
Definition: sch_sheet.h:374
void SetSheetNameSize(int aSize)
Definition: sch_sheet.h:273
void SetName(const wxString &aName)
Definition: sch_sheet.h:269
SCH_SHEET_PINS m_pins
The list of sheet connection points.
Definition: sch_sheet.h:218
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
bool IsMovableFromAnchorPoint() override
Return true for items which are moved with the anchor point at mouse cursor and false for items moved...
Definition: sch_sheet.h:265
void SetEdge(SHEET_SIDE aEdge)
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:134
int GetFileNameSize() const
Definition: sch_sheet.h:275
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_sheet.h:167
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_text.cpp:1311
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
Class SCH_SHEET_PATH.
void ConstrainOnEdge(wxPoint Pos)
Adjust label position to edge based on proximity to vertical or horizontal edge of the parent sheet...
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:547
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
void SetSize(const wxSize &aSize)
Definition: sch_sheet.h:283
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_sheet.h:195
Base plotter engine class.
Definition: plotter.h:96
int m_fileNameSize
The height of the text used to draw the file name.
Definition: sch_sheet.h:232
virtual bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Definition: sch_text.cpp:447
SHEET_SIDE
Defines the edge of the sheet that the sheet pin is positioned SHEET_LEFT_SIDE = 0: pin on left side ...
Definition: sch_sheet.h:73
void SetNumber(int aNumber)
Set the sheet label number.
boost::ptr_vector< SCH_SHEET_PIN > SCH_SHEET_PINS
Definition: sch_sheet.h:203
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
virtual void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_text.cpp:559
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points...
int m_number
Label number use for saving sheet label to file.
Definition: sch_sheet.h:83
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_sheet.h:527
virtual bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList) override
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it&#39;s dangling state...
Definition: sch_text.cpp:394
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
SCH_SCREEN * m_screen
Screen that contains the physical data for the sheet.
Definition: sch_sheet.h:215
SCH_SHEET_PINS & GetPins() const
Definition: sch_sheet.h:336
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
SEARCH_RESULT
Definition: base_struct.h:64
wxString GetName() const
Definition: sch_sheet.h:267
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
int GetPenSize() const override
Function GetPenSize virtual pure.
Implementation of the label properties dialog.
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_sheet.h:478
wxSize GetSize()
Definition: sch_sheet.h:281
SHEET_SIDE m_edge
Definition: sch_sheet.h:88
virtual void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
Definition: sch_text.cpp:511
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39