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-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 SCREEN_H
31 #define SCREEN_H
32 
33 #include <unordered_set>
34 
35 #include <macros.h>
36 #include <dlist.h>
37 #include <sch_item_struct.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 #include <../eeschema/general.h>
47 
48 
49 class LIB_PIN;
50 class SCH_COMPONENT;
51 class SCH_SHEET_LIST;
52 class SCH_SHEET_PATH;
53 class SCH_SHEET_PIN;
54 class SCH_LINE;
55 class SCH_TEXT;
56 class PLOTTER;
57 class SCH_SHEET_LIST;
58 
59 
61 {
65 };
66 
67 
69 #define NB_MAX_SHEET 500
70 
71 
72 class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
73 {
74 private:
75 
76  wxString m_fileName;
77 
78  int m_refCount;
79 
87  wxArrayString m_clientSheetPathList;
88 
90  PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split
91 
93 
95  wxPoint m_aux_origin;
96 
98 
100 
103  std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;
104 
115  void addConnectedItemsToBlock( const SCH_ITEM* aItem, const wxPoint& aPosition );
116 
117 public:
118 
122  SCH_SCREEN( KIWAY* aKiway );
123 
124  ~SCH_SCREEN();
125 
127 
128  virtual wxString GetClass() const override
129  {
130  return wxT( "SCH_SCREEN" );
131  }
132 
133  const PAGE_INFO& GetPageSettings() const { return m_paper; }
134  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
135 
136  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
137 
138  const wxString& GetFileName() const { return m_fileName; }
139 
140  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
141  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
142 
143  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
144  //TITLE_BLOCK& GetTitleBlock() const { return (TITLE_BLOCK&) m_titles; }
145  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
146 
147  void DecRefCount();
148 
149  void IncRefCount();
150 
151  int GetRefCount() const { return m_refCount; }
152 
160  int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); }
161 
162  wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; }
163 
167  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
168 
169  void Append( SCH_ITEM* aItem )
170  {
171  m_drawList.Append( aItem );
173  }
174 
185  void Append( SCH_SCREEN* aScreen );
186 
192  void Append( DLIST< SCH_ITEM >& aList )
193  {
194  m_drawList.Append( aList );
196  }
197 
205 
211  void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); }
212  void SetCurLibItem( LIB_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); }
213 
217  void Clear();
218 
224  void FreeDrawList();
225 
234  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
235  KICAD_T aType = NOT_USED ) const;
236 
237  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
238 
251  void UpdateSymbolLinks( bool aForce = false );
252 
262  void Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
263 
272  void Plot( PLOTTER* aPlotter );
273 
280  void Remove( SCH_ITEM* aItem );
281 
290  void DeleteItem( SCH_ITEM* aItem );
291 
292  bool CheckIfOnDrawList( SCH_ITEM* st );
293 
298  bool TestDanglingEnds();
299 
305  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
306 
313  void MarkConnections( SCH_LINE* aSegment );
314 
326  int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
327 
328  /* full undo redo management : */
329  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
330  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
331 
344  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
345 
349  void ClearDrawingState();
350 
351  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
352 
368  bool IsJunctionNeeded( const wxPoint& aPosition, bool aNew = false );
369 
378  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
379 
389  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
390  bool aEndPointOnly = false ) const;
391 
399  SCH_SHEET* GetSheet( const wxString& aName );
400 
407  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
408 
415  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
416 
427 
433  void GetHierarchicalItems( EDA_ITEMS& aItems );
434 
442  int GetNode( const wxPoint& aPosition, EDA_ITEMS& aList );
443 
451  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
452 
463  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
464  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
465 
466  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
467  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
468  {
469  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
470  }
471 
472  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
473  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
474  {
475  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
476  }
477 
486  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
487 
498  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
499  const wxString& aFootPrint, bool aSetVisible );
500 
507  void SelectBlockItems();
508 
514  int UpdatePickList();
515 
519  void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
520 
525  {
526  m_aliases.clear();
527  }
528 
532  std::unordered_set< std::shared_ptr<BUS_ALIAS> > GetBusAliases()
533  {
534  return m_aliases;
535  }
536 
540  static bool IsBusAlias( const wxString& aLabel );
541 
546  static std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel );
547 
548 #if defined(DEBUG)
549  void Show( int nestLevel, std::ostream& os ) const override;
550 #endif
551 };
552 
553 
560 {
561 private:
562  std::vector< SCH_SCREEN* > m_screens;
563  unsigned int m_index;
564 
565 public:
566  SCH_SCREENS( SCH_SHEET* aSheet = NULL );
567  ~SCH_SCREENS();
568  int GetCount() const { return m_screens.size(); }
569  SCH_SCREEN* GetFirst();
570  SCH_SCREEN* GetNext();
571  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
572 
576  void ClearAnnotation();
577 
586  void ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetPathList );
587 
596 
602  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
603 
613  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
614  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
615 
626  void UpdateSymbolLinks( bool aForce = false );
627 
628  void TestDanglingEnds();
629 
641 
648  size_t GetLibNicknames( wxArrayString& aLibNicknames );
649 
657  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
658 
663 
664 
665 private:
666  void addScreenToList( SCH_SCREEN* aScreen );
667  void buildScreenList( SCH_SHEET* aSheet);
668 };
669 
670 #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
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Definition: base_screen.h:231
const wxString & GetFileName() const
Definition: sch_screen.h:138
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.
Base schematic object class definition.
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:340
SCH_SHEET * GetSheet(const wxString &aName)
Returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:657
int GetClientSheetPathsCount()
Definition: sch_screen.h:160
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:492
the 3d code uses this value
Definition: typeinfo.h:80
SCH_MARKER class definition.
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:162
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:694
int m_refCount
Number of sheets referencing this screen.
Definition: sch_screen.h:78
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.
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:103
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:143
T * begin() const
Definition: dlist.h:218
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:134
Schematic editor (Eeschema) main window.
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:188
int GetCount() const
Definition: sch_screen.h:568
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:731
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
wxPoint m_aux_origin
Origin of the auxiliary axis, which is used in exports mostly, but not yet in EESCHEMA.
Definition: sch_screen.h:95
LIB_ITEM * GetCurLibItem() const
Definition: sch_screen.h:204
wxString m_fileName
File used to load the screen.
Definition: sch_screen.h:76
void SetAuxOrigin(const wxPoint &aPosition)
Definition: sch_screen.h:141
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Definition: sch_screen.h:99
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:133
void addConnectedItemsToBlock(const SCH_ITEM *aItem, const wxPoint &aPosition)
Add items connected at aPosition to the block pick list.
Definition: sch_screen.cpp:841
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:203
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:68
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:601
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_screen.h:237
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.
unsigned int m_index
Definition: sch_screen.h:563
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
TITLE_BLOCK m_titles
Definition: sch_screen.h:92
int GetConnection(const wxPoint &aPosition, PICKED_ITEMS_LIST &aList, bool aFullConnection)
Adds all of the wires and junctions to aList that make up a connection to the object at aPosition.
PAGE_INFO m_paper
The size of the paper to print or plot on.
Definition: sch_screen.h:90
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:748
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=NOT_USED) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:236
int UpdatePickList()
Add all the items in the screen within the block selection rectangle to the pick list.
Definition: sch_screen.cpp:906
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:192
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:194
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:561
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:60
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:298
void Clear()
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:171
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
int GetNode(const wxPoint &aPosition, EDA_ITEMS &aList)
Return all the items at aPosition that form a node.
Definition: sch_screen.cpp:964
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:674
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
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:466
Class SCH_SHEET_PATH.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:145
void SelectBlockItems()
Create a list of items found when a block command is initiated.
Definition: sch_screen.cpp:762
void ClearBusAliases()
Removes all bus alias definitions.
Definition: sch_screen.h:524
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:182
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:208
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:566
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:97
void buildScreenList(SCH_SHEET *aSheet)
void DecRefCount()
Definition: sch_screen.cpp:149
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:420
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.
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:562
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:169
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:943
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases
List of bus aliases stored in this screen.
Definition: sch_screen.h:103
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:211
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:72
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Return a wire or bus item located at aPosition.
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:712
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:272
static bool IsBusAlias(const wxString &aLabel)
Returns true if the given string is a valid bus alias in a loaded screen.
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:594
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:579
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:136
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC)
Draw all the items in the screen to aCanvas.
Definition: sch_screen.cpp:520
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:220
const wxPoint & GetAuxOrigin() const
Definition: sch_screen.h:140
DLIST< SCH_ITEM > & GetDrawList()
Definition: sch_screen.h:126
size_t GetLibNicknames(wxArrayString &aLibNicknames)
Fetch all of the symbol library nickames into aLibNicknames.
void SetCurLibItem(LIB_ITEM *aItem)
Definition: sch_screen.h:212
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases()
Returns a list of bus aliases defined in this screen.
Definition: sch_screen.h:532
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:559
wxArrayString m_clientSheetPathList
the list of scheet paths sharing this screen used in some annotation calculations to update alternate...
Definition: sch_screen.h:87
void IncRefCount()
Definition: sch_screen.cpp:143
int GetRefCount() const
Definition: sch_screen.h:151
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:128
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.
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:472
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:167