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 <memory>
29 #include <stddef.h>
30 #include <unordered_set>
31 #include <vector>
32 #include <wx/arrstr.h>
33 #include <wx/chartype.h>
34 #include <wx/gdicmn.h>
35 #include <wx/string.h>
36 
37 #include <base_screen.h>
38 #include <base_struct.h>
39 #include <core/typeinfo.h>
40 #include <kiway_holder.h>
42 #include <marker_base.h>
43 #include <page_info.h>
44 #include <template_fieldnames.h>
45 #include <title_block.h>
46 
47 #include <lib_id.h>
48 #include <sch_rtree.h>
49 #include <sch_sheet.h>
50 #include <sch_sheet_path.h>
51 
52 class BUS_ALIAS;
53 
54 class LIB_PIN;
55 class SCH_COMPONENT;
56 class SCH_LINE;
57 class SCH_TEXT;
58 class PLOTTER;
59 class SCH_SHEET_LIST;
60 
62 {
66 };
67 
68 
70 #define NB_MAX_SHEET 500
71 
73 {
75  int Unit;
76  int Convert;
77 
78  std::vector<std::pair<int, wxString>> Fields;
79 
81  {
82  }
83 };
84 
85 class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
86 {
87 private:
88 
89  wxString m_fileName;
90 
91  int m_refCount;
92 
100  wxArrayString m_clientSheetPathList;
101 
103  PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split
104 
106 
109 
111 
113 
116  std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;
117 
118 public:
119 
123  SCH_SCREEN( KIWAY* aKiway );
124 
125  ~SCH_SCREEN();
126 
128  {
129  return m_rtree;
130  }
131 
132  const EE_RTREE& Items() const
133  {
134  return m_rtree;
135  }
136 
137  bool IsEmpty()
138  {
139  return m_rtree.empty();
140  }
141 
142  static inline bool ClassOf( const EDA_ITEM* aItem )
143  {
144  return aItem && SCH_SCREEN_T == aItem->Type();
145  }
146 
147  virtual wxString GetClass() const override
148  {
149  return wxT( "SCH_SCREEN" );
150  }
151 
152  const PAGE_INFO& GetPageSettings() const { return m_paper; }
153  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
154 
155  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
156 
157  const wxString& GetFileName() const { return m_fileName; }
158 
159  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
160  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
161 
162  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
163 
164  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
165 
166  void DecRefCount();
167 
168  void IncRefCount();
169 
170  int GetRefCount() const { return m_refCount; }
171 
179  int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); }
180 
181  wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; }
182 
183 
184  void Append( SCH_ITEM* aItem );
185 
196  void Append( SCH_SCREEN* aScreen );
197 
201  void Clear( bool aFree = true );
202 
208  void FreeDrawList();
209 
218  SCH_ITEM* GetItem(
219  const wxPoint& aPosition, int aAccuracy = 0, KICAD_T aType = SCH_LOCATE_ANY_T );
220 
221  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
222 
236  void UpdateSymbolLinks( bool aForce = false );
237 
246  void Print( wxDC* aDC );
247 
256  void Plot( PLOTTER* aPlotter );
257 
265  bool Remove( SCH_ITEM* aItem );
266 
272  void Update( SCH_ITEM* aItem );
273 
282  void DeleteItem( SCH_ITEM* aItem );
283 
284  bool CheckIfOnDrawList( SCH_ITEM* st );
285 
291  bool TestDanglingEnds( const SCH_SHEET_PATH* aPath = nullptr );
292 
299  std::set<SCH_ITEM*> MarkConnections( SCH_LINE* aSegment );
300 
301  /* full undo redo management : */
302  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
303  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
304 
317  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
318 
322  void ClearDrawingState();
323 
324  size_t CountConnectedItems( const wxPoint& aPos, bool aTestJunctions );
325 
341  bool IsJunctionNeeded( const wxPoint& aPosition, bool aNew = false );
342 
351  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
352 
362  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
363  bool aEndPointOnly = false );
364 
371  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
372 
379  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
380 
391 
397  void GetHierarchicalItems( EDA_ITEMS& aItems );
398 
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 
539  void DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode );
540 
544  void DeleteMarker( SCH_MARKER* aMarker );
545 
557  void UpdateSymbolLinks( bool aForce = false );
558 
559  void TestDanglingEnds();
560 
572 
579  size_t GetLibNicknames( wxArrayString& aLibNicknames );
580 
588  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
589 
599  bool HasSchematic( const wxString& aSchematicFileName );
600 
605 
606 
618  bool CanCauseCaseSensitivityIssue( const wxString& aSchematicFileName ) const;
619 
620 private:
621  void addScreenToList( SCH_SCREEN* aScreen );
622  void buildScreenList( SCH_SHEET* aSheet);
623 };
624 
625 #endif /* SCREEN_H */
SCH_SHEET_LIST.
KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
LIB_PIN * GetPin(const wxPoint &aPosition, SCH_COMPONENT **aComponent=NULL, bool aEndPointOnly=false)
Test the screen for a component pin item at aPosition.
Definition: sch_screen.cpp:649
const wxString & GetFileName() const
Definition: sch_screen.h:157
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:238
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:970
void DeleteAllMarkers(enum MARKER_BASE::TYPEMARKER aMarkerType)
Delete all electronic rules check markers of aMarkerType from all the screens in the list.
bool empty()
Definition: sch_rtree.h:166
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:335
int GetClientSheetPathsCount()
Definition: sch_screen.h:179
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:491
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:181
bool IsEmpty()
Definition: sch_screen.h:137
int m_refCount
Number of sheets referencing this screen.
Definition: sch_screen.h:91
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:915
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:127
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:162
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:153
Schematic editor (Eeschema) main window.
int GetCount() const
Definition: sch_screen.h:500
EE_RTREE - Implements an R-tree for fast spatial and type indexing of schematic items.
Definition: sch_rtree.h:41
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:749
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
Definition: sch_screen.cpp:947
wxPoint m_aux_origin
Origin of the auxiliary axis, which is used in exports mostly, but not yet in EESCHEMA.
Definition: sch_screen.h:108
wxString m_fileName
File used to load the screen.
Definition: sch_screen.h:89
void SetAuxOrigin(const wxPoint &aPosition)
Definition: sch_screen.h:160
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Definition: sch_screen.h:112
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:152
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:198
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
Definition: sch_screen.h:221
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:793
unsigned int m_index
Definition: sch_screen.h:495
UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
TITLE_BLOCK m_titles
Definition: sch_screen.h:105
PAGE_INFO m_paper
The size of the paper to print or plot on.
Definition: sch_screen.h:103
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:765
#define NULL
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_screen.h:142
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:244
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:603
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
SCH_LINE_TEST_T
Definition: sch_screen.h:61
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
EE_RTREE m_rtree
Definition: sch_screen.h:110
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
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:700
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
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
const EE_RTREE & Items() const
Definition: sch_screen.h:132
SCH_SHEET_PATH.
void DeleteMarker(SCH_MARKER *aMarker)
Delete a specific marker.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:164
void ClearBusAliases()
Removes all bus alias definitions.
Definition: sch_screen.h:456
size_t CountConnectedItems(const wxPoint &aPos, bool aTestJunctions)
Definition: sch_screen.cpp:718
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:212
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:215
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:573
void buildScreenList(SCH_SHEET *aSheet)
void DecRefCount()
Definition: sch_screen.cpp:167
Base plotter engine class.
Definition: plotter.h:104
void addScreenToList(SCH_SCREEN *aScreen)
Definition: sch_screen.cpp:988
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer)
Test if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:419
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
Board layer functions and definitions.
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Return a label item located at aPosition.
Definition: sch_screen.cpp:827
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:891
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:38
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:494
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:175
void ClearAnnotation()
Clear the annotation for all components in the hierarchy.
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases
List of bus aliases stored in this screen.
Definition: sch_screen.h:116
EE_RTREE & Items()
Definition: sch_screen.h:127
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:99
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
std::vector< std::pair< int, wxString > > Fields
Definition: sch_screen.h:78
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:732
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T)
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:273
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:897
bool CanCauseCaseSensitivityIssue(const wxString &aSchematicFileName) const
Check aSchematicFileName for a potential file name case sensitivity issue.
void Print(wxDC *aDC)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:531
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:959
SCH_SCREEN * GetScreen(unsigned int aIndex) const
Definition: sch_screen.cpp:979
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:642
void Update(SCH_ITEM *aItem)
Updates aItem's bounding box in the tree.
Definition: sch_screen.cpp:231
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:627
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:155
void ClearAnnotationOfNewSheetPaths(SCH_SHEET_LIST &aInitialSheetPathList)
Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified an...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BASE_SCREEN class implementation.
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:267
const wxPoint & GetAuxOrigin() const
Definition: sch_screen.h:159
size_t GetLibNicknames(wxArrayString &aLibNicknames)
Fetch all of the symbol library nickames into aLibNicknames.
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
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
void DeleteMarkers(enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode)
Delete all markers of a particular type and error code.
wxArrayString m_clientSheetPathList
the list of scheet paths sharing this screen used in some annotation calculations to update alternate...
Definition: sch_screen.h:100
void IncRefCount()
Definition: sch_screen.cpp:161
int GetRefCount() const
Definition: sch_screen.h:170
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr)
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:775
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:147
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:848
std::set< SCH_ITEM * > MarkConnections(SCH_LINE *aSegment)
Return all wires and junctions connected to aSegment which are not connected any component pin.
Definition: sch_screen.cpp:289
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:419