KiCad PCB EDA Suite
sch_screen.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) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2019 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 SCREEN_H
31 #define SCREEN_H
32 
33 #include <unordered_set>
34 
35 #include <macros.h>
36 #include <dlist.h>
37 #include <sch_item.h>
38 #include <lib_draw_item.h>
39 #include <base_screen.h>
40 #include <title_block.h>
41 #include <page_info.h>
42 #include <kiway_player.h>
43 #include <sch_marker.h>
44 #include <bus_alias.h>
45 
46 
47 class LIB_PIN;
48 class SCH_COMPONENT;
49 class SCH_SHEET_LIST;
50 class SCH_SHEET_PATH;
51 class SCH_SHEET_PIN;
52 class SCH_LINE;
53 class SCH_TEXT;
54 class PLOTTER;
55 class SCH_SHEET_LIST;
56 
57 
59 {
63 };
64 
65 
67 #define NB_MAX_SHEET 500
68 
69 
70 class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
71 {
72 private:
73 
74  wxString m_fileName;
75 
76  int m_refCount;
77 
85  wxArrayString m_clientSheetPathList;
86 
88  PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split
89 
91 
93  wxPoint m_aux_origin;
94 
96 
98 
101  std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;
102 
103 public:
104 
108  SCH_SCREEN( KIWAY* aKiway );
109 
110  ~SCH_SCREEN();
111 
113 
114  virtual wxString GetClass() const override
115  {
116  return wxT( "SCH_SCREEN" );
117  }
118 
119  const PAGE_INFO& GetPageSettings() const { return m_paper; }
120  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
121 
122  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
123 
124  const wxString& GetFileName() const { return m_fileName; }
125 
126  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
127  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
128 
129  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
130  //TITLE_BLOCK& GetTitleBlock() const { return (TITLE_BLOCK&) m_titles; }
131  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
132 
133  void DecRefCount();
134 
135  void IncRefCount();
136 
137  int GetRefCount() const { return m_refCount; }
138 
146  int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); }
147 
148  wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; }
149 
153  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
154 
155  void Append( SCH_ITEM* aItem )
156  {
157  m_drawList.Append( aItem );
159  }
160 
171  void Append( SCH_SCREEN* aScreen );
172 
178  void Append( DLIST< SCH_ITEM >& aList )
179  {
180  m_drawList.Append( aList );
182  }
183 
187  void Clear();
188 
194  void FreeDrawList();
195 
204  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
205  KICAD_T aType = SCH_LOCATE_ANY_T ) const;
206 
207  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
208 
222  void UpdateSymbolLinks( bool aForce = false );
223 
233  void Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
234 
243  void Plot( PLOTTER* aPlotter );
244 
251  void Remove( SCH_ITEM* aItem );
252 
261  void DeleteItem( SCH_ITEM* aItem );
262 
263  bool CheckIfOnDrawList( SCH_ITEM* st );
264 
269  bool TestDanglingEnds();
270 
276  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
277 
284  void MarkConnections( SCH_LINE* aSegment );
285 
286  /* full undo redo management : */
287  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
288  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
289 
302  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
303 
307  void ClearDrawingState();
308 
309  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
310 
326  bool IsJunctionNeeded( const wxPoint& aPosition, bool aNew = false );
327 
336  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
337 
347  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
348  bool aEndPointOnly = false ) const;
349 
357  SCH_SHEET* GetSheet( const wxString& aName );
358 
365  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
366 
373  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
374 
385 
391  void GetHierarchicalItems( EDA_ITEMS& aItems );
392 
400  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
401 
412  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
413  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
414 
415  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
416  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
417  {
418  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
419  }
420 
421  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
422  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
423  {
424  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
425  }
426 
435  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
436 
447  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
448  const wxString& aFootPrint, bool aSetVisible );
449 
453  void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
454 
459  {
460  m_aliases.clear();
461  }
462 
466  std::unordered_set< std::shared_ptr<BUS_ALIAS> > GetBusAliases()
467  {
468  return m_aliases;
469  }
470 
474  static bool IsBusAlias( const wxString& aLabel );
475 
480  static std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel );
481 
482 #if defined(DEBUG)
483  void Show( int nestLevel, std::ostream& os ) const override;
484 #endif
485 };
486 
487 
494 {
495 private:
496  std::vector< SCH_SCREEN* > m_screens;
497  unsigned int m_index;
498 
499 public:
500  SCH_SCREENS( SCH_SHEET* aSheet = NULL );
501  ~SCH_SCREENS();
502  int GetCount() const { return m_screens.size(); }
503  SCH_SCREEN* GetFirst();
504  SCH_SCREEN* GetNext();
505  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
506 
510  void ClearAnnotation();
511 
520  void ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetPathList );
521 
530 
536  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
537 
547  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
548  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
549 
561  void UpdateSymbolLinks( bool aForce = false );
562 
563  void TestDanglingEnds();
564 
576 
583  size_t GetLibNicknames( wxArrayString& aLibNicknames );
584 
592  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
593 
598 
599 
600 private:
601  void addScreenToList( SCH_SCREEN* aScreen );
602  void buildScreenList( SCH_SHEET* aSheet);
603 };
604 
605 #endif /* SCREEN_H */
Class SCH_SHEET_LIST.
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_player.h:49
const wxString & GetFileName() const
Definition: sch_screen.h:124
SCH_SCREEN * GetNext()
void DeleteAllMarkers(enum MARKER_BASE::TYPEMARKER aMarkerType)
Delete all electronic rules check markers of aMarkerType from all the screens in the list.
bool IsJunctionNeeded(const wxPoint &aPosition, bool aNew=false)
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:350
SCH_SHEET * GetSheet(const wxString &aName)
Returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:667
int GetClientSheetPathsCount()
Definition: sch_screen.h:146
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in m_drawL...
Definition: sch_screen.cpp:502
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:148
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:704
int m_refCount
Number of sheets referencing this screen.
Definition: sch_screen.h:76
int ChangeSymbolLibNickname(const wxString &aFrom, const wxString &aTo)
Change all of the symbol library nicknames.
static std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aLabel)
Returns a pointer to a bus alias object for the given label, or null if one doesn't exist.
Definition: sch_screen.cpp:932
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:104
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:129
T * begin() const
Definition: dlist.h:218
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:120
Schematic editor (Eeschema) main window.
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:189
int GetCount() const
Definition: sch_screen.h:502
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:741
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
Definition: sch_screen.cpp:984
wxPoint m_aux_origin
Origin of the auxiliary axis, which is used in exports mostly, but not yet in EESCHEMA.
Definition: sch_screen.h:93
wxString m_fileName
File used to load the screen.
Definition: sch_screen.h:74
void SetAuxOrigin(const wxPoint &aPosition)
Definition: sch_screen.h:127
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Definition: sch_screen.h:97
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:119
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
This file contains miscellaneous commonly used macros and functions.
LIB_PIN * GetPin(const wxPoint &aPosition, SCH_COMPONENT **aComponent=NULL, bool aEndPointOnly=false) const
Test the screen for a component pin item at aPosition.
Definition: sch_screen.cpp:611
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_screen.h:207
SCH_LINE * GetLine(const wxPoint &aPosition, int aAccuracy=0, int aLayer=LAYER_NOTES, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Return a line item located at aPosition.
Definition: sch_screen.cpp:807
unsigned int m_index
Definition: sch_screen.h:497
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
TITLE_BLOCK m_titles
Definition: sch_screen.h:90
PAGE_INFO m_paper
The size of the paper to print or plot on.
Definition: sch_screen.h:88
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:758
void Append(DLIST< SCH_ITEM > &aList)
Add aList of SCH_ITEM objects to the list for draw items for the sheet.
Definition: sch_screen.h:178
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:195
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:588
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
SCH_LINE_TEST_T
Definition: sch_screen.h:58
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
void MarkConnections(SCH_LINE *aSegment)
Add all wires and junctions connected to aSegment which are not connected any component pin to aItemL...
Definition: sch_screen.cpp:308
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:237
void Clear()
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:172
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:684
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:56
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
SCH_LINE * GetWire(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:415
Class SCH_SHEET_PATH.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:131
void ClearBusAliases()
Removes all bus alias definitions.
Definition: sch_screen.h:458
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:183
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:201
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:576
int GetMarkerCount(enum MARKER_BASE::TYPEMARKER aMarkerType, enum MARKER_BASE::MARKER_SEVERITY aSeverity)
Return the number of ERC markers of aMarkerType from all of the screens in the list.
DLIST< SCH_ITEM > m_drawList
Object list for the screen.
Definition: sch_screen.h:95
void buildScreenList(SCH_SHEET *aSheet)
void DecRefCount()
Definition: sch_screen.cpp:150
Base plotter engine class.
Definition: plotter.h:97
void addScreenToList(SCH_SCREEN *aScreen)
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer)
Test if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:430
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Return a label item located at aPosition.
Definition: sch_screen.cpp:841
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:908
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:496
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:155
void ClearAnnotation()
Clear the annotation for all components in the hierarchy.
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:772
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases
List of bus aliases stored in this screen.
Definition: sch_screen.h:101
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Return a wire or bus item located at aPosition.
Definition: sch_screen.cpp:793
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:722
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
void ReplaceWires(DLIST< SCH_ITEM > &aWireList)
Replace all of the wires, buses, and junctions in the screen with aWireList.
Definition: sch_screen.cpp:282
static bool IsBusAlias(const wxString &aLabel)
Returns true if the given string is a valid bus alias in a loaded screen.
Definition: sch_screen.cpp:914
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:996
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:604
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:589
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:122
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC)
Draw all the items in the screen to aCanvas.
Definition: sch_screen.cpp:530
void ClearAnnotationOfNewSheetPaths(SCH_SHEET_LIST &aInitialSheetPathList)
Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified an...
BASE_SCREEN class implementation.
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:221
const wxPoint & GetAuxOrigin() const
Definition: sch_screen.h:126
DLIST< SCH_ITEM > & GetDrawList()
Definition: sch_screen.h:112
size_t GetLibNicknames(wxArrayString &aLibNicknames)
Fetch all of the symbol library nickames into aLibNicknames.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases()
Returns a list of bus aliases defined in this screen.
Definition: sch_screen.h:466
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:493
wxArrayString m_clientSheetPathList
the list of scheet paths sharing this screen used in some annotation calculations to update alternate...
Definition: sch_screen.h:85
void IncRefCount()
Definition: sch_screen.cpp:144
int GetRefCount() const
Definition: sch_screen.h:137
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:114
bool SetComponentFootprint(SCH_SHEET_PATH *aSheetPath, const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Search this screen for a symbol with aReference and set the footprint field to aFootPrint if found.
Definition: sch_screen.cpp:862
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:421
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:153