KiCad PCB EDA Suite
base_struct.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) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef BASE_STRUCT_H_
28 #define BASE_STRUCT_H_
29 
30 #include <deque>
31 
32 #include <core/typeinfo.h>
33 #include "common.h"
34 #include <wx/fdrepdlg.h>
35 #include <bitmap_types.h>
36 #include <view/view_item.h>
37 
42 enum FILL_T {
44  FILLED_SHAPE, // Fill with object color ("Solid shape")
45  FILLED_WITH_BG_BODYCOLOR, // Fill with background body color
46  // (not filled in B&W mode when plotting or printing)
47  FILLED_WITH_COLOR // Fill with a user-defined color (currently sheets only)
48 };
49 
50 
51 enum class SEARCH_RESULT
52 {
53  QUIT,
54  CONTINUE
55 };
56 
57 
62 {
63  // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
64  FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1, // Search the current sheet only.
65  FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2, // Search hidden fields too.
66  FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3, // Search pin name and number.
67  FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4, // Use simple wild card matching (* & ?).
68  FR_SEARCH_WRAP = wxFR_MATCHCASE << 5, // Wrap around the start or end of search.
69  FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7, // Search for a item that has replaceable text.
70  FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8, // Indicates an item with replaceable text has
71  // been found.
72  FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9 // Don't replace in references.
73 };
74 
75 
76 class wxFindReplaceData;
77 class EDA_ITEM;
78 class EDA_DRAW_FRAME;
79 class EDA_RECT;
81 
82 
103 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
104 
105 typedef const INSPECTOR_FUNC& INSPECTOR;
106 
107 
108 // These define are used for the .m_Flags and .m_UndoRedoStatus member of the
109 // class EDA_ITEM
110 //
111 // NB: DO NOT ADD FLAGS ANYWHERE BUT AT THE END: THE FLAG-SET IS STORED AS AN INTEGER IN FILES.
112 //
113 #define IS_CHANGED (1 << 0)
114 #define IS_LINKED (1 << 1)
115 #define IN_EDIT (1 << 2)
116 #define IS_MOVED (1 << 3)
117 #define IS_NEW (1 << 4)
118 #define IS_RESIZED (1 << 5)
119 #define IS_DRAGGED (1 << 6)
120 #define IS_DELETED (1 << 7)
121 #define IS_WIRE_IMAGE (1 << 8)
122 #define STARTPOINT (1 << 9)
123 #define ENDPOINT (1 << 10)
124 #define SELECTED (1 << 11)
125 #define TEMP_SELECTED (1 << 12)
126 #define STRUCT_DELETED (1 << 13)
127 #define CANDIDATE (1 << 14)
128 #define SKIP_STRUCT (1 << 15)
129 #define DO_NOT_DRAW (1 << 16)
130 #define IS_PASTED (1 << 17)
131 #define TRACK_LOCKED (1 << 18)
132 #define TRACK_AR (1 << 19)
133 #define OBSOLETE_1 (1 << 20)
134 #define OBSOLETE_2 (1 << 21)
135 #define BEGIN_ONPAD (1 << 22)
136 #define END_ONPAD (1 << 23)
137 #define OBSOLETE_3 (1 << 24)
138 #define OBSOLETE_4 (1 << 25)
139 #define BRIGHTENED (1 << 26)
140 
141 #define DP_COUPLED (1 << 27)
142 #define UR_TRANSIENT (1 << 28)
144 
145 #define IS_DANGLING (1 << 29)
146 
147 // WARNING: if you add flags, you'll probably need to adjust the masks in GetEditFlags() and
148 // ClearTempFlags().
149 
150 #define EDA_ITEM_ALL_FLAGS -1
151 
152 typedef unsigned STATUS_FLAGS;
153 
160 {
161 public:
162  const KIID m_Uuid;
163 
164 private:
171 
172 protected:
177 
178 protected:
179  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
180  EDA_ITEM( KICAD_T idType );
181  EDA_ITEM( const EDA_ITEM& base );
182 
183 public:
184  virtual ~EDA_ITEM() { };
185 
193  inline KICAD_T Type() const { return m_StructType; }
194 
195  EDA_ITEM* GetParent() const { return m_Parent; }
196  virtual void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
197 
198  inline bool IsModified() const { return m_Flags & IS_CHANGED; }
199  inline bool IsNew() const { return m_Flags & IS_NEW; }
200  inline bool IsMoving() const { return m_Flags & IS_MOVED; }
201  inline bool IsDragging() const { return m_Flags & IS_DRAGGED; }
202  inline bool IsWireImage() const { return m_Flags & IS_WIRE_IMAGE; }
203  inline bool IsSelected() const { return m_Flags & SELECTED; }
204  inline bool IsResized() const { return m_Flags & IS_RESIZED; }
205  inline bool IsBrightened() const { return m_Flags & BRIGHTENED; }
206 
207  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
208  inline void SetSelected() { SetFlags( SELECTED ); }
209  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
210 
211  inline void ClearSelected() { ClearFlags( SELECTED ); }
212  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
213 
214  void SetModified();
215 
216  int GetState( int type ) const
217  {
218  return m_Status & type;
219  }
220 
221  void SetState( int type, int state )
222  {
223  if( state )
224  m_Status |= type; // state = ON or OFF
225  else
226  m_Status &= ~type;
227  }
228 
229  STATUS_FLAGS GetStatus() const { return m_Status; }
230  void SetStatus( STATUS_FLAGS aStatus ) { m_Status = aStatus; }
231 
232  void SetFlags( STATUS_FLAGS aMask ) { m_Flags |= aMask; }
233  void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; }
234  STATUS_FLAGS GetFlags() const { return m_Flags; }
235  bool HasFlag( STATUS_FLAGS aFlag ) { return ( m_Flags & aFlag ) == aFlag; }
236 
238  {
239  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVED | IS_RESIZED | IS_DRAGGED |
241 
242  return m_Flags & mask;
243  }
244 
246  {
248  DO_NOT_DRAW );
249  }
250 
252  {
254  }
255 
262  virtual bool IsType( const KICAD_T aScanTypes[] ) const
263  {
264  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
265  return true;
266 
267  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
268  {
269  if( m_StructType == *p )
270  return true;
271  }
272 
273  return false;
274  }
275 
284  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
285 
286  bool IsForceVisible() const { return m_forceVisible; }
287 
295  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
296  {
297  }
298 
307  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
308  {
309  return false; // derived classes should override this function
310  }
311 
321  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
322  {
323  return false; // derived classes should override this function
324  }
325 
335  virtual const EDA_RECT GetBoundingBox() const;
336 
337  virtual const wxPoint GetPosition() const { return wxPoint(); }
338 
344  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
345 
359  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
360 
375  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
376 
382  template< class T >
383  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
384  INSPECTOR inspector,
385  void* testData,
386  const KICAD_T scanTypes[] )
387  {
388  for( auto it : aList )
389  {
390  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
392  return SEARCH_RESULT::QUIT;
393  }
394 
396  }
397 
403  template <class T>
405  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
406  {
407  for( auto it : aList )
408  {
409  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
411  return SEARCH_RESULT::QUIT;
412  }
413 
415  }
416 
422  virtual wxString GetClass() const = 0;
423 
433  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
434 
442  virtual BITMAP_DEF GetMenuImage() const;
443 
457  virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData )
458  {
459  return false;
460  }
461 
474  static bool Replace( wxFindReplaceData& aSearchData, wxString& aText );
475 
489  virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
490 
501  virtual bool IsReplaceable() const { return false; }
502 
509  bool operator<( const EDA_ITEM& aItem ) const;
510 
520  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
521 
526  EDA_ITEM& operator=( const EDA_ITEM& aItem );
527 
528  virtual const BOX2I ViewBBox() const override;
529 
530  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
531 
532 #if defined(DEBUG)
533 
541  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
542  // pure virtual so compiler warns if somebody mucks up a derived declaration
543 
544  void ShowDummy( std::ostream& os ) const;
545 
553  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
554 
555 #endif
556 
557 protected:
567  bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
568 };
569 
570 
578 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
579 
580 
587 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
588 
589 
590 #endif // BASE_STRUCT_H_
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:114
EDA_UNITS
Definition: common.h:198
#define TEMP_SELECTED
flag indicating that the structure has already selected
Definition: base_struct.h:125
void SetModified()
Definition: base_struct.cpp:85
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:229
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: base_struct.h:80
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void ClearTempFlags()
Definition: base_struct.h:245
bool IsModified() const
Definition: base_struct.h:198
bool IsSelected() const
Definition: base_struct.h:203
KICAD_T m_StructType
Run time identification, keep private so it can never be changed after a constructor sets it.
Definition: base_struct.h:170
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
void ClearSelected()
Definition: base_struct.h:211
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
bool IsMoving() const
Definition: base_struct.h:200
virtual const wxPoint GetFocusPosition() const
Function GetFocusPosition similar to GetPosition, but allows items to return their visual center rath...
Definition: base_struct.h:344
void SetBrightened()
Definition: base_struct.h:209
virtual ~EDA_ITEM()
Definition: base_struct.h:184
bool IsBrightened() const
Definition: base_struct.h:205
#define CANDIDATE
flag indicating that the structure is connected
Definition: base_struct.h:127
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
The base class for create windows for drawing purpose.
#define EDA_ITEM_ALL_FLAGS
Definition: base_struct.h:150
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool IsDragging() const
Definition: base_struct.h:201
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
bool IsNew() const
Definition: base_struct.h:199
virtual const wxPoint GetPosition() const
Definition: base_struct.h:337
void ClearBrightened()
Definition: base_struct.h:212
#define IS_NEW
New item, just created.
Definition: base_struct.h:117
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:307
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:105
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:119
#define SELECTED
Definition: base_struct.h:124
Definition: common.h:68
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:113
VIEW_ITEM class definition.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
#define NULL
void SetSelected()
Definition: base_struct.h:208
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:237
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:587
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: base_struct.h:295
STATUS_FLAGS m_Status
Definition: base_struct.h:173
void SetForceVisible(bool aEnable)
Function SetForceVisible is used to set and cleag force visible flag used to force the item to be dra...
Definition: base_struct.h:284
bool IsResized() const
Definition: base_struct.h:204
void SetWireImage()
Definition: base_struct.h:207
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Function new_clone provides cloning capabilities for all Boost pointer containers of EDA_ITEM pointer...
Definition: base_struct.h:578
bool IsWireImage() const
Definition: base_struct.h:202
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
unsigned STATUS_FLAGS
Definition: base_struct.h:152
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:126
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
static bool Sort(const EDA_ITEM *aLeft, const EDA_ITEM *aRight)
Function Sort is a helper function to be used by the C++ STL sort algorithm for sorting a STL contain...
Definition: base_struct.h:520
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
Definition: base_struct.h:121
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: base_struct.cpp:57
const KIID m_Uuid
Definition: base_struct.h:162
bool IsForceVisible() const
Definition: base_struct.h:286
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void SetState(int type, int state)
Definition: base_struct.h:221
virtual bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL)
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: base_struct.h:489
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
STATUS_FLAGS m_Flags
Definition: base_struct.h:176
#define ENDPOINT
ends. (Used to support dragging.)
Definition: base_struct.h:123
virtual bool IsReplaceable() const
Function IsReplaceable.
Definition: base_struct.h:501
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const
Function HitTest tests if aRect intersects or is contained within the bounding box of an item.
Definition: base_struct.h:321
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
The common library.
#define IS_RESIZED
Item being resized.
Definition: base_struct.h:118
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:230
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:233
static SEARCH_RESULT IterateForward(std::deque< T > &aList, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
Definition: base_struct.h:383
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: base_struct.cpp:95
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
bool HasFlag(STATUS_FLAGS aFlag)
Definition: base_struct.h:235
SEARCH_RESULT
Definition: base_struct.h:51
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
void ClearEditFlags()
Definition: base_struct.h:251
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:234
bool m_forceVisible
Definition: base_struct.h:175
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:457
int GetState(int type) const
Definition: base_struct.h:216
static SEARCH_RESULT IterateForward(std::vector< T > &aList, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
Definition: base_struct.h:404
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: base_struct.h:61
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:129
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
Definition: base_struct.h:130
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: base_struct.h:122
#define IS_MOVED
Item being moved.
Definition: base_struct.h:116