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  static inline bool ClassOf( const EDA_ITEM* aItem )
109  {
110  return aItem && SCH_SCREEN_T == aItem->Type();
111  }
112 
113  virtual wxString GetClass() const override
114  {
115  return wxT( "SCH_SCREEN" );
116  }
117 
118  const PAGE_INFO& GetPageSettings() const { return m_paper; }
119  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
120 
121  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
122 
123  const wxString& GetFileName() const { return m_fileName; }
124 
125  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
126  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
127 
128  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
129  //TITLE_BLOCK& GetTitleBlock() const { return (TITLE_BLOCK&) m_titles; }
130  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
131 
132  void DecRefCount();
133 
134  void IncRefCount();
135 
136  int GetRefCount() const { return m_refCount; }
137 
145  int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); }
146 
147  wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; }
148 
152  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
153 
154  void Append( SCH_ITEM* aItem )
155  {
156  m_drawList.Append( aItem );
158  }
159 
170  void Append( SCH_SCREEN* aScreen );
171 
177  void Append( DLIST< SCH_ITEM >& aList )
178  {
179  m_drawList.Append( aList );
181  }
182 
186  void Clear();
187 
193  void FreeDrawList();
194 
203  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
204  KICAD_T aType = SCH_LOCATE_ANY_T ) const;
205 
206  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
207 
221  void UpdateSymbolLinks( bool aForce = false );
222 
231  void Print( wxDC* aDC );
232 
241  void Plot( PLOTTER* aPlotter );
242 
249  void Remove( SCH_ITEM* aItem );
250 
259  void DeleteItem( SCH_ITEM* aItem );
260 
261  bool CheckIfOnDrawList( SCH_ITEM* st );
262 
267  bool TestDanglingEnds();
268 
274  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
275 
282  void MarkConnections( SCH_LINE* aSegment );
283 
284  /* full undo redo management : */
285  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
286  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
287 
300  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
301 
305  void ClearDrawingState();
306 
307  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
308 
324  bool IsJunctionNeeded( const wxPoint& aPosition, bool aNew = false );
325 
334  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
335 
345  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
346  bool aEndPointOnly = false ) const;
347 
355  SCH_SHEET* GetSheet( const wxString& aName );
356 
363  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
364 
371  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
372 
383 
389  void GetHierarchicalItems( EDA_ITEMS& aItems );
390 
398  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
399 
410  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
411  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
412 
413  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
414  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
415  {
416  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
417  }
418 
419  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
420  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
421  {
422  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
423  }
424 
433  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
434 
445  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
446  const wxString& aFootPrint, bool aSetVisible );
447 
451  void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
452 
457  {
458  m_aliases.clear();
459  }
460 
464  std::unordered_set< std::shared_ptr<BUS_ALIAS> > GetBusAliases()
465  {
466  return m_aliases;
467  }
468 
472  static bool IsBusAlias( const wxString& aLabel );
473 
478  static std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel );
479 
480 #if defined(DEBUG)
481  void Show( int nestLevel, std::ostream& os ) const override;
482 #endif
483 };
484 
485 
492 {
493 private:
494  std::vector< SCH_SCREEN* > m_screens;
495  unsigned int m_index;
496 
497 public:
498  SCH_SCREENS( SCH_SHEET* aSheet = NULL );
499  ~SCH_SCREENS();
500  int GetCount() const { return m_screens.size(); }
501  SCH_SCREEN* GetFirst();
502  SCH_SCREEN* GetNext();
503  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
504 
508  void ClearAnnotation();
509 
518  void ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetPathList );
519 
528 
534  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
535 
545  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
546  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
547 
559  void UpdateSymbolLinks( bool aForce = false );
560 
561  void TestDanglingEnds();
562 
574 
581  size_t GetLibNicknames( wxArrayString& aLibNicknames );
582 
590  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
591 
601  bool HasSchematic( const wxString& aSchematicFileName );
602 
607 
608 
609 private:
610  void addScreenToList( SCH_SCREEN* aScreen );
611  void buildScreenList( SCH_SHEET* aSheet);
612 };
613 
614 #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:123
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:994
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:674
int GetClientSheetPathsCount()
Definition: sch_screen.h:145
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:497
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:147
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:711
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:937
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:104
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:128
T * begin() const
Definition: dlist.h:218
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:119
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:500
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:748
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
Definition: sch_screen.cpp:971
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:126
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:118
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:618
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_screen.h:206
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:812
unsigned int m_index
Definition: sch_screen.h:495
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:765
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:177
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_screen.h:108
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:642
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:274
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:691
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:413
Class SCH_SHEET_PATH.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:130
void ClearBusAliases()
Removes all bus alias definitions.
Definition: sch_screen.h:456
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:209
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:548
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:425
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:846
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:913
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:494
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:154
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:779
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
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Return a wire or bus item located at aPosition.
Definition: sch_screen.cpp:798
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:729
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:919
void Print(wxDC *aDC)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:525
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:983
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:611
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:596
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:121
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:125
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:464
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:491
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:136
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:113
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:867
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:419
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:152