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 
98  void addConnectedItemsToBlock( const wxPoint& aPosition );
99 
100 public:
101 
105  SCH_SCREEN( KIWAY* aKiway );
106 
107  ~SCH_SCREEN();
108 
109  virtual wxString GetClass() const override
110  {
111  return wxT( "SCH_SCREEN" );
112  }
113 
114  const PAGE_INFO& GetPageSettings() const { return m_paper; }
115  void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
116 
117  void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
118 
119  const wxString& GetFileName() const { return m_fileName; }
120 
121  const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
122  void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
123 
124  const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
125  //TITLE_BLOCK& GetTitleBlock() const { return (TITLE_BLOCK&) m_titles; }
126  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
127 
128  void DecRefCount();
129 
130  void IncRefCount();
131 
132  int GetRefCount() const { return m_refCount; }
133 
138  SCH_ITEM* GetDrawItems() const { return m_drawList.begin(); }
139 
140  void Append( SCH_ITEM* aItem )
141  {
142  m_drawList.Append( aItem );
144  }
145 
152  void Append( DLIST< SCH_ITEM >& aList )
153  {
154  m_drawList.Append( aList );
156  }
157 
164 
170  void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); }
171 
176  void Clear();
177 
183  void FreeDrawList();
184 
193  SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
194  KICAD_T aType = NOT_USED ) const;
195 
196  void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
197 
208 
220  void Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode,
221  COLOR4D aColor = COLOR4D::UNSPECIFIED );
222 
232  void Plot( PLOTTER* aPlotter );
233 
241  void Remove( SCH_ITEM* aItem );
242 
250  void DeleteItem( SCH_ITEM* aItem );
251 
252  bool CheckIfOnDrawList( SCH_ITEM* st );
253 
261  bool SchematicCleanUp();
262 
268  bool TestDanglingEnds();
269 
282  void ExtractWires( DLIST< SCH_ITEM >& aList, bool aCreateCopy );
283 
290  void ReplaceWires( DLIST< SCH_ITEM >& aWireList );
291 
298  void MarkConnections( SCH_LINE* aSegment );
299 
311  int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
312 
320  bool BreakSegment( const wxPoint& aPoint );
321 
329 
330  /* full undo redo management : */
331  // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
332  // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
333 
345  virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override;
346 
354  bool Save( FILE* aFile ) const;
355 
359  void ClearDrawingState();
360 
361  int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
362 
379  bool IsJunctionNeeded( const wxPoint& aPosition );
380 
390  bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
391 
401  LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
402  bool aEndPointOnly = false ) const;
403 
412  SCH_SHEET* GetSheet( const wxString& aName );
413 
420  SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
421 
428  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
429 
435  void GetHierarchicalItems( EDA_ITEMS& aItems );
436 
445  int GetNode( const wxPoint& aPosition, EDA_ITEMS& aList );
446 
455  SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
456 
468  SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
469  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
470 
471  SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
472  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
473  {
474  return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
475  }
476 
477  SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
478  SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
479  {
480  return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
481  }
482 
492  SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
493 
505  bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
506  const wxString& aFootPrint, bool aSetVisible );
507 
514  void SelectBlockItems();
515 
521  int UpdatePickList();
522 
523 #if defined(DEBUG)
524  void Show( int nestLevel, std::ostream& os ) const override;
525 #endif
526 };
527 
528 
535 {
536 private:
537  std::vector< SCH_SCREEN* > m_screens;
538  unsigned int m_index;
539 
540 public:
541  SCH_SCREENS();
542  ~SCH_SCREENS();
543  int GetCount() const { return m_screens.size(); }
544  SCH_SCREEN* GetFirst();
545  SCH_SCREEN* GetNext();
546  SCH_SCREEN* GetScreen( unsigned int aIndex ) const;
547 
552  void ClearAnnotation();
553 
558  void SchematicCleanUp();
559 
568 
575  void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
576 
587  int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType,
588  enum MARKER_BASE::MARKER_SEVERITY aSeverity );
589 
598  void UpdateSymbolLinks();
599 
600  void TestDanglingEnds();
601 
614 
615 private:
616  void AddScreenToList( SCH_SCREEN* aScreen );
617  void BuildScreenList( EDA_ITEM* aItem );
618 };
619 
620 #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:721
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)
Function DeleteAllMarkers deletes all electronic rules check markers of aMarkerType from all the scre...
SCH_SCREEN * GetScreen(unsigned int aIndex) const
EDA_ITEM * GetCurItem() const
Base schematic object class definition.
SCH_SHEET * GetSheet(const wxString &aName)
Function GetSheet returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:684
bool BreakSegment(const wxPoint &aPoint)
Function BreakSegment checks every wire and bus for a intersection at aPoint and break into two segme...
Definition: sch_screen.cpp:936
SCH_LINE_TEST_T
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
the 3d code uses this value
Definition: typeinfo.h:92
const wxString & GetFileName() const
int m_refCount
Number of sheets referencing this screen.
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:95
T * begin() const
Definition: dlist.h:218
int GetRefCount() const
void SetPageSettings(const PAGE_INFO &aPageSettings)
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void Remove(SCH_ITEM *aItem)
Function Remove removes aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:158
bool BreakSegmentsOnJunctions()
Function BreakSegmentsOnJunctions tests all junctions and bus entries in the schematic for intersecti...
Definition: sch_screen.cpp:965
wxPoint m_aux_origin
Origin of the auxilliary 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:90
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)
Function GetLine returns a line item located at aPosition.
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)
Functions GetConnection adds all of the wires and junctions to aList that make up a connection to the...
bool Save(FILE *aFile) const
Function Save writes the data structures for this object out to aFile in "*.sch" format.
Definition: sch_screen.cpp:475
void BuildScreenList(EDA_ITEM *aItem)
void addConnectedItemsToBlock(const wxPoint &aPosition)
Function addConnectedItemsToBlock add items connected at aPosition to the block pick list...
Definition: sch_screen.cpp:835
PAGE_INFO m_paper
The size of the paper to print or plot on.
void GetHierarchicalItems(EDA_ITEMS &aItems)
Function GetHierarchicalItems adds all schematic sheet and component object in the screen to aItems...
Definition: sch_screen.cpp:758
int UpdatePickList()
Function UpdatePickList adds all the items in the screen within the block selection rectangle to the ...
Definition: sch_screen.cpp:879
void Append(DLIST< SCH_ITEM > &aList)
Function Append adds aList of SCH_ITEM objects to the list for draw items for the sheet...
bool SchematicCleanUp()
Function SchematicCleanUp performs routine schematic cleaning including breaking wire and buses and d...
Definition: sch_screen.cpp:426
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
void DeleteItem(SCH_ITEM *aItem)
Function DeleteItem removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:164
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 AddScreenToList(SCH_SCREEN *aScreen)
void MarkConnections(SCH_LINE *aSegment)
Function MarkConnections add all wires and junctions connected to aSegment which are not connected an...
Definition: sch_screen.cpp:295
void UpdateSymbolLinks()
initializes or reinitializes the weak reference to the LIB_PART for each SCH_COMPONENT found in the f...
void SchematicCleanUp()
Function SchematicCleanUp merges and breaks wire segments in the entire schematic hierarchy...
void Clear()
Function Clear deletes all draw items and clears the project settings.
Definition: sch_screen.cpp:141
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Function Draw draws all the items in the screen to aCanvas.
Definition: sch_screen.cpp:558
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)
Function GetNode returns all the items at aPosition that form a node.
Definition: sch_screen.cpp:994
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Function GetSheetLabel test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:701
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
bool HasNoFullyDefinedLibIds()
Function HasNoFullyDefinedLibIds.
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()
Function SelectBlockItems creates a list of items found when a block command is initiated.
Definition: sch_screen.cpp:772
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:152
const TITLE_BLOCK & GetTitleBlock() const
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
void Plot(PLOTTER *aPlotter)
Function Plot plots all the schematic objects to aPlotter.
Definition: sch_screen.cpp:584
int GetMarkerCount(enum MARKER_BASE::TYPEMARKER aMarkerType, enum MARKER_BASE::MARKER_SEVERITY aSeverity)
Function GetMarkerCount returns the number of ERC markers of aMarkerType from all of the screens in t...
DLIST< SCH_ITEM > m_drawList
Object list for the screen.
void DecRefCount()
Definition: sch_screen.cpp:133
Base plotter engine class.
Definition: plot_common.h:86
SCH_ITEM * GetDrawItems() const
Function GetDrawItems().
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer)
Function IsTerminalPoint tests if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:355
BASE_SCREEN class implementation.
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Function GetLabel returns a label item located at aPosition.
Class SCH_LINE is a segment description base class to describe items which have 2 end points (track...
Definition: sch_line.h:42
std::vector< SCH_SCREEN * > m_screens
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=NOT_USED) const
Function GetItem checks aPosition within a distance of aAccuracy for items of type aFilter...
Definition: sch_screen.cpp:203
void Append(SCH_ITEM *aItem)
void ClearAnnotation()
Function ClearAnnotation clears the annotation for all components in the hierarchy.
bool TestDanglingEnds()
Function TestDanglingEnds tests all of the connectible objects in the schematic for unused connection...
Definition: sch_screen.cpp:915
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
void CheckComponentsToPartsLinks()
Function CheckComponentsToPartsLink initializes or reinitializes the weak reference to the LIB_PART f...
Definition: sch_screen.cpp:532
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
Function GetPin test the screen for a component pin item at aPosition.
Definition: sch_screen.cpp:628
void ExtractWires(DLIST< SCH_ITEM > &aList, bool aCreateCopy)
Function ExtractWires extracts the old wires, junctions and buses.
Definition: sch_screen.cpp:241
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Function GetWireOrBus returns a wire or bus item located at aPosition.
const PAGE_INFO & GetPageSettings() const
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Function ClearAnnotation clears the annotation for the components in aSheetPath on the screen...
Definition: sch_screen.cpp:739
int ReplaceDuplicateTimeStamps()
Function ReplaceDuplicateTimeStamps test all sheet and component objects in the schematic for duplica...
void ReplaceWires(DLIST< SCH_ITEM > &aWireList)
Function ReplaceWires replaces all of the wires, buses, and junctions in the screen with aWireList...
Definition: sch_screen.cpp:269
SCH_SCREEN * GetFirst()
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:621
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Function ClearUndoORRedoList free the undo or redo list from List element Wrappers are deleted...
Definition: sch_screen.cpp:597
void SetFileName(const wxString &aFileName)
bool IsJunctionNeeded(const wxPoint &aPosition)
Function IsJunctionNeeded tests if a junction is required for the items at aPosition on the screen...
Definition: sch_screen.cpp:337
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:187
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Class SCH_SCREENS is a container class that holds multiple SCH_SCREENs in a hierarchy.
void IncRefCount()
Definition: sch_screen.cpp:127
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)
Function SetFootprintField searches screen for a component with aReference and set the footprint fiel...
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)