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-2018 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 
32 #ifndef BASE_STRUCT_H_
33 #define BASE_STRUCT_H_
34 
35 #include <core/typeinfo.h>
36 
37 #include <bitmap_types.h>
38 #include <view/view_item.h>
39 
40 #if defined(DEBUG)
41 #include <iostream> // needed for Show()
42 extern std::ostream& operator <<( std::ostream& out, const wxSize& size );
43 
44 extern std::ostream& operator <<( std::ostream& out, const wxPoint& pt );
45 #endif
46 
47 
52 enum FILL_T {
53  NO_FILL, // Poly, Square, Circle, Arc = option No Fill
54  FILLED_SHAPE, /* Poly, Square, Circle, Arc = option Fill
55  * with current color ("Solid shape") */
56  FILLED_WITH_BG_BODYCOLOR /* Poly, Square, Circle, Arc = option Fill
57  * with background body color, translucent
58  * (texts inside this shape can be seen)
59  * not filled in B&W mode when plotting or
60  * printing */
61 };
62 
63 
67 };
68 
69 
70 class wxFindReplaceData;
71 class EDA_ITEM;
72 class EDA_DRAW_FRAME;
73 class EDA_RECT;
74 class DHEAD;
76 
77 
98 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
99 
100 typedef const INSPECTOR_FUNC& INSPECTOR;
101 
102 
103 // These define are used for the .m_Flags and .m_UndoRedoStatus member of the
104 // class EDA_ITEM
105 #define IS_CHANGED (1 << 0)
106 #define IS_LINKED (1 << 1)
107 #define IN_EDIT (1 << 2)
108 #define IS_MOVED (1 << 3)
109 #define IS_NEW (1 << 4)
110 #define IS_RESIZED (1 << 5)
111 #define IS_DRAGGED (1 << 6)
112 #define IS_DELETED (1 << 7)
113 #define IS_WIRE_IMAGE (1 << 8)
114 #define STARTPOINT (1 << 9)
115 #define ENDPOINT (1 << 10)
116 #define SELECTED (1 << 11)
117 #define SELECTEDNODE (1 << 12)
118 #define STRUCT_DELETED (1 << 13)
119 #define CANDIDATE (1 << 14)
120 #define SKIP_STRUCT (1 << 15)
121 #define DO_NOT_DRAW (1 << 16)
122 #define IS_CANCELLED (1 << 17)
123 #define TRACK_LOCKED (1 << 18)
125 #define TRACK_AR (1 << 19)
126 #define FLAG1 (1 << 20)
127 #define FLAG0 (1 << 21)
128 #define BEGIN_ONPAD (1 << 22)
129 #define END_ONPAD (1 << 23)
130 #define BUSY (1 << 24)
131 #define HIGHLIGHTED (1 << 25)
133 #define BRIGHTENED (1 << 26)
134 
135 #define DP_COUPLED (1 << 27)
136 #define UR_TRANSIENT (1 << 28)
138 
139 
140 #define EDA_ITEM_ALL_FLAGS -1
141 
142 typedef unsigned STATUS_FLAGS;
143 
155 typedef long timestamp_t;
156 
163 {
164 private:
165 
173 
174 protected:
178 
181 
184 
187 
188 private:
189 
190  void initVars();
191 
192 protected:
193 
194  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
195  EDA_ITEM( KICAD_T idType );
196  EDA_ITEM( const EDA_ITEM& base );
197 
198 public:
199 
200  virtual ~EDA_ITEM() { };
201 
209  inline KICAD_T Type() const
210  {
211  return m_StructType;
212  }
213 
214  void SetTimeStamp( timestamp_t aNewTimeStamp ) { m_TimeStamp = aNewTimeStamp; }
216 
217  EDA_ITEM* Next() const { return Pnext; }
218  EDA_ITEM* Back() const { return Pback; }
219  EDA_ITEM* GetParent() const { return m_Parent; }
220  DHEAD* GetList() const { return m_List; }
221 
222  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
223  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
224  void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
225  void SetList( DHEAD* aList ) { m_List = aList; }
226 
227  inline bool IsNew() const { return m_Flags & IS_NEW; }
228  inline bool IsModified() const { return m_Flags & IS_CHANGED; }
229  inline bool IsMoving() const { return m_Flags & IS_MOVED; }
230  inline bool IsDragging() const { return m_Flags & IS_DRAGGED; }
231  inline bool IsWireImage() const { return m_Flags & IS_WIRE_IMAGE; }
232  inline bool IsSelected() const { return m_Flags & SELECTED; }
233  inline bool IsResized() const { return m_Flags & IS_RESIZED; }
234  inline bool IsHighlighted() const { return m_Flags & HIGHLIGHTED; }
235  inline bool IsBrightened() const { return m_Flags & BRIGHTENED; }
236 
237  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
238  inline void SetSelected() { SetFlags( SELECTED ); }
239  inline void SetHighlighted() { SetFlags( HIGHLIGHTED ); }
240  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
241 
242  inline void ClearSelected() { ClearFlags( SELECTED ); }
244  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
245 
246  void SetModified();
247 
248  int GetState( int type ) const
249  {
250  return m_Status & type;
251  }
252 
253  void SetState( int type, int state )
254  {
255  if( state )
256  m_Status |= type; // state = ON or OFF
257  else
258  m_Status &= ~type;
259  }
260 
261  STATUS_FLAGS GetStatus() const { return m_Status; }
262  void SetStatus( STATUS_FLAGS aStatus ) { m_Status = aStatus; }
263 
264  void SetFlags( STATUS_FLAGS aMask ) { m_Flags |= aMask; }
265  void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; }
266  STATUS_FLAGS GetFlags() const { return m_Flags; }
267 
276  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
277 
288  virtual void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
289  {
290  }
291 
299  virtual bool HitTest( const wxPoint& aPosition ) const
300  {
301  return false; // derived classes should override this function
302  }
303 
304 
314  virtual const EDA_RECT GetBoundingBox() const;
315 
329  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
330 
348  static SEARCH_RESULT IterateForward( EDA_ITEM* listStart,
349  INSPECTOR inspector,
350  void* testData,
351  const KICAD_T scanTypes[] );
352 
367  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
368 
374  virtual wxString GetClass() const = 0;
375 
385  virtual wxString GetSelectMenuText() const;
386 
394  virtual BITMAP_DEF GetMenuImage() const;
395 
411  virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
412  {
413  return false;
414  }
415 
428  bool Replace( wxFindReplaceData& aSearchData, wxString& aText );
429 
443  virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
444 
455  virtual bool IsReplaceable() const { return false; }
456 
463  bool operator<( const EDA_ITEM& aItem ) const;
464 
474  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
475 
480  EDA_ITEM& operator=( const EDA_ITEM& aItem );
481 
482  virtual const BOX2I ViewBBox() const override;
483 
484  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
485 
486 #if defined(DEBUG)
487 
495  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
496  // pure virtual so compiler warns if somebody mucks up a derived declaration
497 
498  void ShowDummy( std::ostream& os ) const;
499 
507  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
508 
509 #endif
510 
511 protected:
521  bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
522 };
523 
524 
532 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
533 
534 
541 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
542 
543 
544 #endif // BASE_STRUCT_H_
DHEAD * GetList() const
Definition: base_struct.h:220
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
virtual bool IsReplaceable() const
Function IsReplaceable.
Definition: base_struct.h:455
void SetModified()
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:155
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 GetFlags() const
Definition: base_struct.h:266
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
static SEARCH_RESULT IterateForward(EDA_ITEM *listStart, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function IterateForward walks through the object tree calling the inspector() on each object type req...
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:176
bool IsMoving() const
Definition: base_struct.h:229
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:179
bool IsResized() const
Definition: base_struct.h:233
timestamp_t m_TimeStamp
Time stamp used for logical links.
Definition: base_struct.h:180
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:75
PNG memory record (file in memory).
Definition: bitmap_types.h:41
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:223
bool IsBrightened() const
Definition: base_struct.h:235
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Class DHEAD is only for use by template class DLIST, use that instead.
Definition: dlist.h:40
KICAD_T m_StructType
Run time identification, keep private so it can never be changed after a constructor sets it...
Definition: base_struct.h:171
bool IsNew() const
Definition: base_struct.h:227
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:242
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
EDA_ITEM * Back() const
Definition: base_struct.h:218
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:411
bool IsModified() const
Definition: base_struct.h:228
void SetBrightened()
Definition: base_struct.h:240
bool IsSelected() const
Definition: base_struct.h:232
EDA_ITEM * GetParent() const
Definition: base_struct.h:219
virtual ~EDA_ITEM()
Definition: base_struct.h:200
bool IsHighlighted() const
Definition: base_struct.h:234
void SetList(DHEAD *aList)
Definition: base_struct.h:225
EDA_ITEM * Next() const
Definition: base_struct.h:217
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:84
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:261
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:63
int GetState(int type) const
Definition: base_struct.h:248
#define EDA_ITEM_ALL_FLAGS
Definition: base_struct.h:140
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void ClearBrightened()
Definition: base_struct.h:244
#define IS_NEW
New item, just created.
Definition: base_struct.h:109
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:100
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:111
#define SELECTED
Definition: base_struct.h:116
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:105
VIEW_ITEM class definition.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:264
void ClearHighlighted()
Definition: base_struct.h:243
void SetSelected()
Definition: base_struct.h:238
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:224
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:541
STATUS_FLAGS m_Status
Definition: base_struct.h:172
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:276
void SetWireImage()
Definition: base_struct.h:237
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:532
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:133
unsigned STATUS_FLAGS
Definition: base_struct.h:142
virtual bool HitTest(const wxPoint &aPosition) const
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: base_struct.h:299
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:474
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: base_struct.h:288
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
Definition: base_struct.h:113
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:65
void SetHighlighted()
Definition: base_struct.h:239
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:222
virtual wxString GetClass() const =0
Function GetClass returns the class name.
#define HIGHLIGHTED
item is drawn in normal colors, when the rest is darkened
Definition: base_struct.h:132
void SetState(int type, int state)
Definition: base_struct.h:253
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:443
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:186
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
#define IS_RESIZED
Item being resized.
Definition: base_struct.h:110
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:262
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:52
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
bool IsWireImage() const
Definition: base_struct.h:231
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
SEARCH_RESULT
Definition: base_struct.h:64
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
bool m_forceVisible
Set to true to override the visibility setting of the item.
Definition: base_struct.h:183
void initVars()
Definition: base_struct.cpp:87
DHEAD * m_List
which DLIST I am on.
Definition: base_struct.h:177
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:175
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
wxString & operator<<(wxString &aString, const wxPoint &aPos)
Operator << overload outputs a point to the argument string in a format resembling "@ (x...
Definition: base_units.cpp:401
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:214
bool IsDragging() const
Definition: base_struct.h:230
#define IS_MOVED
Item being moved.
Definition: base_struct.h:108