KiCad PCB EDA Suite
class_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 CLASS_SCREEN_H
31 #define CLASS_SCREEN_H
32 
33 #include <macros.h>
34 #include <dlist.h>
35 #include <sch_item_struct.h>
36 #include <class_base_screen.h>
37 #include <class_title_block.h>
38 #include <class_page_info.h>
39 #include <kiway_player.h>
40 #include <sch_marker.h>
41 
42 #include <../eeschema/general.h>
43 
44 
45 class LIB_PIN;
46 class SCH_COMPONENT;
47 class SCH_SHEET_PATH;
48 class SCH_SHEET_PIN;
49 class SCH_LINE;
50 class SCH_TEXT;
51 class PLOTTER;
52 
53 
55 {
59 };
60 
61 
63 #define NB_MAX_SHEET 500
64 
65 
66 class SCH_SCREEN : public BASE_SCREEN, public KIWAY_HOLDER
67 {
68 private:
69 
70  wxString m_fileName;
71 
72  int m_refCount;
73 
76  PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split
77 
79 
82 
84 
86 
97  void addConnectedItemsToBlock( const wxPoint& aPosition );
98 
99 public:
100 
104  SCH_SCREEN( KIWAY* aKiway );
105 
106  ~SCH_SCREEN();
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 
136  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
137 
138  void Append( SCH_ITEM* aItem )
139  {
140  m_drawList.Append( aItem );
142  }
143 
154  void Append( SCH_SCREEN* aScreen );
155 
161  void Append( DLIST< SCH_ITEM >& aList )
162  {
163  m_drawList.Append( aList );
165  }
166 
173 
179  void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); }
180 
184  void Clear();
185 
191  void FreeDrawList();
192 
201  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
202  KICAD_T aType = NOT_USED ) const;
203 
204  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
205 
218  void UpdateSymbolLinks( bool aForce = false );
219 
231  void Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode,
232  COLOR4D aColor = COLOR4D::UNSPECIFIED );
233 
242  void Plot( PLOTTER* aPlotter );
243 
250  void Remove( SCH_ITEM* aItem );
251 
260  void DeleteItem( SCH_ITEM* aItem );
261 
262  bool CheckIfOnDrawList( SCH_ITEM* st );
263 
270  bool SchematicCleanUp();
271 
277  bool TestDanglingEnds();
278 
290  void ExtractWires( DLIST< SCH_ITEM >& aList, bool aCreateCopy );
291 
297  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
298 
305  void MarkConnections( SCH_LINE* aSegment );
306 
318  int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
319 
327  bool BreakSegment( const wxPoint& aPoint );
328 
336 
337  /* full undo redo management : */
338  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
339  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
340 
353  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
354 
358  void ClearDrawingState();
359 
360  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
361 
377  bool IsJunctionNeeded( const wxPoint& aPosition );
378 
387  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
388 
398  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
399  bool aEndPointOnly = false ) const;
400 
408  SCH_SHEET* GetSheet( const wxString& aName );
409 
416  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
417 
424  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
425 
431  void GetHierarchicalItems( EDA_ITEMS& aItems );
432 
440  int GetNode( const wxPoint& aPosition, EDA_ITEMS& aList );
441 
449  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
450 
461  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
462  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
463 
464  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
465  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
466  {
467  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
468  }
469 
470  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
471  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
472  {
473  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
474  }
475 
484  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
485 
496  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
497  const wxString& aFootPrint, bool aSetVisible );
498 
505  void SelectBlockItems();
506 
512  int UpdatePickList();
513 
514 #if defined(DEBUG)
515  void Show( int nestLevel, std::ostream& os ) const override;
516 #endif
517 };
518 
519 
526 {
527 private:
528  std::vector< SCH_SCREEN* > m_screens;
529  unsigned int m_index;
530 
531 public:
532  SCH_SCREENS( SCH_SHEET* aSheet = NULL );
533  ~SCH_SCREENS();
534  int GetCount() const { return m_screens.size(); }
535  SCH_SCREEN* GetFirst();
536  SCH_SCREEN* GetNext();
537  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
538 
542  void ClearAnnotation();
543 
547  void SchematicCleanUp();
548 
557 
563  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
564 
574  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
575  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
576 
587  void UpdateSymbolLinks( bool aForce = false );
588 
589  void TestDanglingEnds();
590 
602 
609  size_t GetLibNicknames( wxArrayString& aLibNicknames );
610 
618  int ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo );
619 
620 private:
621  void addScreenToList( SCH_SCREEN* aScreen );
622  void buildScreenList( SCH_SHEET* aSheet);
623 };
624 
625 #endif /* CLASS_SCREEN_H */
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_player.h:48
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:670
const wxPoint & GetAuxOrigin() const
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
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...
SCH_SCREEN * GetScreen(unsigned int aIndex) const
EDA_ITEM * GetCurItem() const
Base schematic object class definition.
SCH_SHEET * GetSheet(const wxString &aName)
Returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:633
bool BreakSegment(const wxPoint &aPoint)
Checks every wire and bus for a intersection at aPoint and break into two segments at aPoint if an in...
Definition: sch_screen.cpp:897
SCH_LINE_TEST_T
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:487
the 3d code uses this value
Definition: typeinfo.h:80
const wxString & GetFileName() const
int m_refCount
Number of sheets referencing this screen.
int ChangeSymbolLibNickname(const wxString &aFrom, const wxString &aTo)
Change all of the symbol library nicknames.
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:93
T * begin() const
Definition: dlist.h:218
int GetRefCount() const
void SetPageSettings(const PAGE_INFO &aPageSettings)
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:170
bool BreakSegmentsOnJunctions()
Tests all junctions and bus entries in the schematic for intersections with wires and buses and break...
Definition: sch_screen.cpp:926
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.
wxString m_fileName
File used to load the screen.
void SetAuxOrigin(const wxPoint &aPosition)
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
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.
void Place(SCH_EDIT_FRAME *frame, wxDC *DC)
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:989
unsigned int m_index
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
TITLE_BLOCK m_titles
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...
void addConnectedItemsToBlock(const wxPoint &aPosition)
Add items connected at aPosition to the block pick list.
Definition: sch_screen.cpp:796
PAGE_INFO m_paper
The size of the paper to print or plot on.
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:707
int UpdatePickList()
Add all the items in the screen within the block selection rectangle to the pick list.
Definition: sch_screen.cpp:840
void Append(DLIST< SCH_ITEM > &aList)
Add aList of SCH_ITEM objects to the list for draw items for the sheet.
bool SchematicCleanUp()
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
Definition: sch_screen.cpp:438
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:176
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:544
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
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:307
void SchematicCleanUp()
Merge and break wire segments in the entire schematic hierarchy.
void Clear()
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:153
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Draw all the items in the screen to aCanvas.
Definition: sch_screen.cpp:513
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
int GetNode(const wxPoint &aPosition, EDA_ITEMS &aList)
Return all the items at aPosition that form a node.
Definition: sch_screen.cpp:955
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:650
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)
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)
void SelectBlockItems()
Create a list of items found when a block command is initiated.
Definition: sch_screen.cpp:721
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:164
const TITLE_BLOCK & GetTitleBlock() const
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:542
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.
void buildScreenList(SCH_SHEET *aSheet)
void DecRefCount()
Definition: sch_screen.cpp:131
Base plotter engine class.
Definition: class_plotter.h:97
SCH_ITEM * GetDrawItems() const
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:367
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
BASE_SCREEN class implementation.
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Return a label item located at aPosition.
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
std::vector< SCH_SCREEN * > m_screens
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:215
void Append(SCH_ITEM *aItem)
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:876
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
int GetCount() const
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:577
void ExtractWires(DLIST< SCH_ITEM > &aList, bool aCreateCopy)
Extracts the old wires, junctions and buses.
Definition: sch_screen.cpp:253
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Return a wire or bus item located at aPosition.
Definition: sch_screen.cpp:974
const PAGE_INFO & GetPageSettings() const
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:688
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:281
SCH_SCREEN * GetFirst()
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:570
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:555
void SetFileName(const wxString &aFileName)
bool IsJunctionNeeded(const wxPoint &aPosition)
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:349
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:199
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...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void IncRefCount()
Definition: sch_screen.cpp:125
virtual wxString GetClass() const override
Function GetClass returns the class name.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
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)