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 
25 #ifndef SCREEN_H
26 #define SCREEN_H
27 
28 #include <unordered_set>
29 #include <macros.h>
30 #include <dlist.h>
31 #include <sch_item.h>
32 #include <lib_item.h>
33 #include <base_screen.h>
34 #include <title_block.h>
35 #include <page_info.h>
36 #include <kiway_holder.h>
37 #include <sch_marker.h>
38 #include <bus_alias.h>
39 
40 
41 class LIB_PIN;
42 class SCH_COMPONENT;
43 class SCH_SHEET_LIST;
44 class SCH_SHEET_PATH;
45 class SCH_SHEET_PIN;
46 class SCH_LINE;
47 class SCH_TEXT;
48 class PLOTTER;
49 class SCH_SHEET_LIST;
50 
51 
53 {
57 };
58 
59 
61 #define NB_MAX_SHEET 500
62 
63 
64 class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
65 {
66 private:
67 
68  wxString m_fileName;
69 
70  int m_refCount;
71 
79  wxArrayString m_clientSheetPathList;
80 
82  PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split
83 
85 
87  wxPoint m_aux_origin;
88 
90 
92 
95  std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;
96 
97 public:
98 
102  SCH_SCREEN( KIWAY* aKiway );
103 
104  ~SCH_SCREEN();
105 
107 
108  virtual wxString GetClass() const override
109  {
110  return wxT( "SCH_SCREEN" );
111  }
112 
113  const PAGE_INFO& GetPageSettings() const { return m_paper; }
114  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
115 
116  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
117 
118  const wxString& GetFileName() const { return m_fileName; }
119 
120  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
121  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
122 
123  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
124  //TITLE_BLOCK& GetTitleBlock() const { return (TITLE_BLOCK&) m_titles; }
125  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
126 
127  void DecRefCount();
128 
129  void IncRefCount();
130 
131  int GetRefCount() const { return m_refCount; }
132 
140  int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); }
141 
142  wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; }
143 
147  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
148 
149  void Append( SCH_ITEM* aItem )
150  {
151  m_drawList.Append( aItem );
153  }
154 
165  void Append( SCH_SCREEN* aScreen );
166 
172  void Append( DLIST< SCH_ITEM >& aList )
173  {
174  m_drawList.Append( aList );
176  }
177 
181  void Clear();
182 
188  void FreeDrawList();
189 
198  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
199  KICAD_T aType = SCH_LOCATE_ANY_T ) const;
200 
201  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
202 
216  void UpdateSymbolLinks( bool aForce = false );
217 
226  void Print( wxDC* aDC );
227 
236  void Plot( PLOTTER* aPlotter );
237 
244  void Remove( SCH_ITEM* aItem );
245 
254  void DeleteItem( SCH_ITEM* aItem );
255 
256  bool CheckIfOnDrawList( SCH_ITEM* st );
257 
262  bool TestDanglingEnds();
263 
269  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
270 
277  void MarkConnections( SCH_LINE* aSegment );
278 
279  /* full undo redo management : */
280  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
281  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
282 
295  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
296 
300  void ClearDrawingState();
301 
302  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
303 
319  bool IsJunctionNeeded( const wxPoint& aPosition, bool aNew = false );
320 
329  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
330 
340  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
341  bool aEndPointOnly = false ) const;
342 
350  SCH_SHEET* GetSheet( const wxString& aName );
351 
358  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
359 
366  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
367 
378 
384  void GetHierarchicalItems( EDA_ITEMS& aItems );
385 
393  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
394 
405  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
406  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
407 
408  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
409  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
410  {
411  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
412  }
413 
414  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
415  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
416  {
417  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
418  }
419 
428  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
429 
440  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
441  const wxString& aFootPrint, bool aSetVisible );
442 
446  void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
447 
452  {
453  m_aliases.clear();
454  }
455 
459  std::unordered_set< std::shared_ptr<BUS_ALIAS> > GetBusAliases()
460  {
461  return m_aliases;
462  }
463 
467  static bool IsBusAlias( const wxString& aLabel );
468 
473  static std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel );
474 
475 #if defined(DEBUG)
476  void Show( int nestLevel, std::ostream& os ) const override;
477 #endif
478 };
479 
480 
487 {
488 private:
489  std::vector< SCH_SCREEN* > m_screens;
490  unsigned int m_index;
491 
492 public:
493  SCH_SCREENS( SCH_SHEET* aSheet = NULL );
494  ~SCH_SCREENS();
495  int GetCount() const { return m_screens.size(); }
496  SCH_SCREEN* GetFirst();
497  SCH_SCREEN* GetNext();
498  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
499 
503  void ClearAnnotation();
504 
513  void ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetPathList );
514 
523 
529  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
530 
540  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
541  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
542 
554  void UpdateSymbolLinks( bool aForce = false );
555 
556  void TestDanglingEnds();
557 
569 
576  size_t GetLibNicknames( wxArrayString& aLibNicknames );
577 
585  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
586 
596  bool HasSchematic( const wxString& aSchematicFileName );
597 
602 
603 
604 private:
605  void addScreenToList( SCH_SCREEN* aScreen );
606  void buildScreenList( SCH_SHEET* aSheet);
607 };
608 
609 #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_holder.h:39
const wxString & GetFileName() const
Definition: sch_screen.h:118
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:347
SCH_SHEET * GetSheet(const wxString &aName)
Returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:676
int GetClientSheetPathsCount()
Definition: sch_screen.h:140
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:499
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:142
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:713
int m_refCount
Number of sheets referencing this screen.
Definition: sch_screen.h:70
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:941
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:104
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:123
T * begin() const
Definition: dlist.h:218
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:114
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:495
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:750
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
Definition: sch_screen.cpp:993
wxPoint m_aux_origin
Origin of the auxiliary axis, which is used in exports mostly, but not yet in EESCHEMA.
Definition: sch_screen.h:87
wxString m_fileName
File used to load the screen.
Definition: sch_screen.h:68
void SetAuxOrigin(const wxPoint &aPosition)
Definition: sch_screen.h:121
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Definition: sch_screen.h:91
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:113
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:620
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_screen.h:201
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:816
unsigned int m_index
Definition: sch_screen.h:490
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
TITLE_BLOCK m_titles
Definition: sch_screen.h:84
PAGE_INFO m_paper
The size of the paper to print or plot on.
Definition: sch_screen.h:82
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:767
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:172
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:622
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:52
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
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:305
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:234
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
bool HasSchematic(const wxString &aSchematicFileName)
Check if one of the schematics in the list of screens is aSchematicFileName.
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:693
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:75
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:408
Class SCH_SHEET_PATH.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:125
void ClearBusAliases()
Removes all bus alias definitions.
Definition: sch_screen.h:451
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:204
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:550
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:89
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:427
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:850
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:917
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:489
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:149
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:781
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases
List of bus aliases stored in this screen.
Definition: sch_screen.h:95
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:802
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:731
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:279
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:923
void Print(wxDC *aDC)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:527
SCH_SCREEN * GetFirst()
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:613
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:598
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:116
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:218
const wxPoint & GetAuxOrigin() const
Definition: sch_screen.h:120
DLIST< SCH_ITEM > & GetDrawList()
Definition: sch_screen.h:106
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:459
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:486
wxArrayString m_clientSheetPathList
the list of scheet paths sharing this screen used in some annotation calculations to update alternate...
Definition: sch_screen.h:79
void IncRefCount()
Definition: sch_screen.cpp:144
int GetRefCount() const
Definition: sch_screen.h:131
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:108
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:871
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:414
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:147