You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
19 KiB

Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
17 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
  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 The KiCad Developers, see AUTHORS.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. #ifndef EDA_ITEM_H
  27. #define EDA_ITEM_H
  28. #include <deque>
  29. #include <api/serializable.h>
  30. #include <core/typeinfo.h>
  31. #include <eda_item_flags.h>
  32. #include <eda_search_data.h>
  33. #include <view/view_item.h>
  34. #include <kiid.h>
  35. enum class BITMAPS : unsigned int;
  36. enum class INSPECT_RESULT
  37. {
  38. QUIT,
  39. CONTINUE
  40. };
  41. enum RECURSE_MODE
  42. {
  43. RECURSE,
  44. NO_RECURSE,
  45. };
  46. /**
  47. * Additional flag values wxFindReplaceData::m_Flags
  48. */
  49. class UNITS_PROVIDER;
  50. class EDA_DRAW_FRAME;
  51. class EDA_GROUP;
  52. class MSG_PANEL_ITEM;
  53. class EMBEDDED_FILES;
  54. namespace google { namespace protobuf { class Any; } }
  55. /**
  56. * Used to inspect and possibly collect the (search) results of iterating over a list or
  57. * tree of #KICAD_T objects.
  58. *
  59. * Provide an implementation as needed to inspect EDA_ITEMs visited via #EDA_ITEM::Visit()
  60. * and #EDA_ITEM::IterateForward().
  61. *
  62. * FYI the std::function may hold a lambda, std::bind, pointer to func, or ptr to member
  63. * function, per modern C++. It is used primarily for searching, but not limited to that.
  64. * It can also collect or modify the scanned objects. 'Capturing' lambdas are particularly
  65. * convenient because they can use context and this often means @a aTestData is not used.
  66. *
  67. * @param aItem An #EDA_ITEM to examine.
  68. * @param aTestData is arbitrary data needed by the inspector to determine
  69. * if the EDA_ITEM under test meets its match criteria, and is often NULL
  70. * with the advent of capturing lambdas.
  71. * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
  72. * stop the scan, else #SEARCH_CONTINUE;
  73. */
  74. typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
  75. /// std::function passed to nested users by ref, avoids copying std::function.
  76. typedef const INSPECTOR_FUNC& INSPECTOR;
  77. /**
  78. * A base class for most all the KiCad significant classes used in schematics and boards.
  79. */
  80. class EDA_ITEM : public KIGFX::VIEW_ITEM, public SERIALIZABLE
  81. {
  82. public:
  83. virtual ~EDA_ITEM() { wxASSERT( m_group == nullptr ); };
  84. /**
  85. * Returns the type of object.
  86. *
  87. * This attribute should never be changed after a ctor sets it, so there is no public
  88. * "setter" method.
  89. *
  90. * @return the type of object.
  91. */
  92. inline KICAD_T Type() const { return m_structType; }
  93. EDA_ITEM* GetParent() const { return m_parent; }
  94. virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
  95. virtual void SetParentGroup( EDA_GROUP* aGroup ) { m_group = aGroup; }
  96. virtual EDA_GROUP* GetParentGroup() const { return m_group; }
  97. virtual bool IsLocked() const { return false; }
  98. virtual void SetLocked( bool aLocked ) {}
  99. inline bool IsModified() const { return m_flags & IS_CHANGED; }
  100. inline bool IsNew() const { return m_flags & IS_NEW; }
  101. inline bool IsMoving() const { return m_flags & IS_MOVING; }
  102. inline bool IsSelected() const { return m_flags & SELECTED; }
  103. inline bool IsEntered() const { return m_flags & ENTERED; }
  104. inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
  105. inline bool IsRollover() const { return m_isRollover; }
  106. inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; }
  107. inline void SetSelected() { SetFlags( SELECTED ); }
  108. inline void SetBrightened() { SetFlags( BRIGHTENED ); }
  109. inline void ClearSelected() { ClearFlags( SELECTED ); }
  110. inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
  111. void SetModified();
  112. void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
  113. void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
  114. void ClearFlags( EDA_ITEM_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
  115. EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
  116. bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
  117. EDA_ITEM_FLAGS GetEditFlags() const
  118. {
  119. constexpr int mask =
  120. ( IS_NEW | IS_PASTED | IS_MOVING | IS_BROKEN | IS_CHANGED | STRUCT_DELETED );
  121. return m_flags & mask;
  122. }
  123. virtual void ClearEditFlags()
  124. {
  125. ClearFlags( GetEditFlags() );
  126. }
  127. EDA_ITEM_FLAGS GetTempFlags() const
  128. {
  129. constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
  130. return m_flags & mask;
  131. }
  132. virtual void ClearTempFlags()
  133. {
  134. ClearFlags( GetTempFlags() );
  135. }
  136. virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
  137. void SetIsShownAsBitmap( bool aBitmap )
  138. {
  139. if( aBitmap )
  140. SetFlags( IS_SHOWN_AS_BITMAP );
  141. else
  142. ClearFlags( IS_SHOWN_AS_BITMAP );
  143. }
  144. inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
  145. /**
  146. * Check whether the item is one of the listed types.
  147. *
  148. * @param aScanTypes List of item types
  149. * @return true if the item type is contained in the list aScanTypes
  150. */
  151. virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
  152. {
  153. for( KICAD_T scanType : aScanTypes )
  154. {
  155. if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
  156. return true;
  157. }
  158. return false;
  159. }
  160. /**
  161. * Set and clear force visible flag used to force the item to be drawn even if it's draw
  162. * attribute is set to not visible.
  163. *
  164. * @param aEnable True forces the item to be drawn. False uses the item's visibility
  165. * setting to determine if the item is to be drawn.
  166. */
  167. void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
  168. bool IsForceVisible() const { return m_forceVisible; }
  169. /**
  170. * Populate \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
  171. * purposes.
  172. *
  173. * @param aFrame is the EDA_DRAW_FRAME that displays the message panel
  174. * @param aList is the list to populate.
  175. */
  176. virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  177. {
  178. }
  179. virtual wxString GetFriendlyName() const;
  180. /**
  181. * Test if \a aPosition is inside or on the boundary of this item.
  182. *
  183. * @param aPosition A reference to a VECTOR2I object containing the coordinates to test.
  184. * @param aAccuracy Increase the item bounding box by this amount.
  185. * @return True if \a aPosition is within the item bounding box.
  186. */
  187. virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
  188. {
  189. return false; // derived classes should override this function
  190. }
  191. /**
  192. * Test if \a aRect intersects this item.
  193. *
  194. * @param aRect A reference to a #BOX2I object containing the rectangle to test.
  195. * @param aContained Set to true to test for containment instead of an intersection.
  196. * @param aAccuracy Increase \a aRect by this amount.
  197. * @return True if \a aRect contains or intersects the item bounding box.
  198. */
  199. virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
  200. {
  201. return false; // derived classes should override this function
  202. }
  203. /**
  204. * Return the orthogonal bounding box of this object for display purposes.
  205. *
  206. * This box should be an enclosing perimeter for visible components of this
  207. * object, and the units should be in the pcb or schematic coordinate
  208. * system. It is OK to overestimate the size by a few counts.
  209. */
  210. virtual const BOX2I GetBoundingBox() const;
  211. virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
  212. virtual void SetPosition( const VECTOR2I& aPos ){};
  213. /**
  214. * Similar to GetPosition() but allows items to return their visual center rather
  215. * than their anchor.
  216. */
  217. virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
  218. /**
  219. * Return the coordinates that should be used for sorting this element
  220. * visually compared to other elements. For instance, for lines the midpoint
  221. * might be a better sorting point than either end.
  222. *
  223. * @return X,Y coordinate of the sort point
  224. */
  225. virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
  226. /**
  227. * Create a duplicate of this item with linked list members set to NULL.
  228. *
  229. * The default version will return NULL in release builds and likely crash the
  230. * program. In debug builds, a warning message indicating the derived class
  231. * has not implemented cloning. This really should be a pure virtual function.
  232. * Due to the fact that there are so many objects derived from EDA_ITEM, the
  233. * decision was made to return NULL until all the objects derived from EDA_ITEM
  234. * implement cloning. Once that happens, this function should be made pure.
  235. *
  236. * @return A clone of the item.
  237. */
  238. virtual EDA_ITEM* Clone() const;
  239. /**
  240. * May be re-implemented for each derived class in order to handle all the types given
  241. * by its member data.
  242. *
  243. * Implementations should call inspector->Inspect() on types in aScanTypes, and may use
  244. * #IterateForward() to do so on lists of such data.
  245. *
  246. * @param inspector An #INSPECTOR instance to use in the inspection.
  247. * @param testData Arbitrary data used by the inspector.
  248. * @param aScanTypes Which #KICAD_T types are of interest and the order in which they should
  249. * be processed.
  250. * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
  251. * else #SCAN_CONTINUE, and determined by the inspector.
  252. */
  253. virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  254. const std::vector<KICAD_T>& aScanTypes );
  255. /**
  256. * This changes first parameter to avoid the DList and use the main queue instead.
  257. */
  258. template< class T >
  259. static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
  260. const std::vector<KICAD_T>& scanTypes )
  261. {
  262. for( const auto& it : aList )
  263. {
  264. EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
  265. if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
  266. {
  267. return INSPECT_RESULT::QUIT;
  268. }
  269. }
  270. return INSPECT_RESULT::CONTINUE;
  271. }
  272. /**
  273. * Change first parameter to avoid the DList and use std::vector instead.
  274. */
  275. template <class T>
  276. static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
  277. void* testData, const std::vector<KICAD_T>& scanTypes )
  278. {
  279. for( const auto& it : aList )
  280. {
  281. EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
  282. if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
  283. {
  284. return INSPECT_RESULT::QUIT;
  285. }
  286. }
  287. return INSPECT_RESULT::CONTINUE;
  288. }
  289. /**
  290. * Return the class name.
  291. */
  292. virtual wxString GetClass() const = 0;
  293. /**
  294. * Return a translated description of the type for this EDA_ITEM for display in user facing
  295. * messages.
  296. */
  297. wxString GetTypeDesc() const;
  298. /**
  299. * Return a user-visible description string of this item. This description is used in
  300. * disambiguation menus, the message panel, ERC/DRC reports, etc.
  301. *
  302. * The default version of this function raises an assertion in the debug mode and
  303. * returns a string to indicate that it was not overridden to provide the object
  304. * specific text.
  305. *
  306. * @param aLong indicates a long string is acceptable
  307. * @return The menu text string.
  308. */
  309. virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
  310. /**
  311. * Return a pointer to an image to be used in menus.
  312. *
  313. * The default version returns the right arrow image. Override this function to provide
  314. * object specific menu images.
  315. *
  316. * @return The menu image associated with the item.
  317. */
  318. virtual BITMAPS GetMenuImage() const;
  319. /**
  320. * Compare the item against the search criteria in \a aSearchData.
  321. *
  322. * The base class returns false since many of the objects derived from EDA_ITEM
  323. * do not have any text to search.
  324. *
  325. * @param aSearchData A reference to a wxFindReplaceData object containing the
  326. * search criteria.
  327. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  328. * @return True if the item's text matches the search criteria in \a aSearchData.
  329. */
  330. virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  331. {
  332. return false;
  333. }
  334. /**
  335. * Perform a text replace on \a aText using the find and replace criteria in
  336. * \a aSearchData on items that support text find and replace.
  337. *
  338. * @param aSearchData A reference to a wxFindReplaceData object containing the
  339. * search and replace criteria.
  340. * @param aText A reference to a wxString object containing the text to be replaced.
  341. * @return True if \a aText was modified, otherwise false.
  342. */
  343. static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
  344. /**
  345. * Perform a text replace using the find and replace criteria in \a aSearchData
  346. * on items that support text find and replace.
  347. *
  348. * This function must be overridden for items that support text replace.
  349. *
  350. * @param aSearchData A reference to a wxFindReplaceData object containing the search and
  351. * replace criteria.
  352. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  353. * @return True if the item text was modified, otherwise false.
  354. */
  355. virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
  356. {
  357. return false;
  358. }
  359. /**
  360. * Override this method in any derived object that supports test find and replace.
  361. *
  362. * @return True if the item has replaceable text that can be modified using
  363. * the find and replace dialog.
  364. */
  365. virtual bool IsReplaceable() const { return false; }
  366. /**
  367. * Test if another item is less than this object.
  368. *
  369. * @param aItem - Item to compare against.
  370. * @return - True if \a aItem is less than the item.
  371. */
  372. bool operator<( const EDA_ITEM& aItem ) const;
  373. /**
  374. * Helper function to be used by the C++ STL sort algorithm for sorting a STL
  375. * container of #EDA_ITEM pointers.
  376. *
  377. * @param aLeft The left hand item to compare.
  378. * @param aRight The right hand item to compare.
  379. * @return True if \a aLeft is less than \a aRight.
  380. */
  381. static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
  382. /**
  383. * Assign the members of \a aItem to another object.
  384. */
  385. EDA_ITEM& operator=( const EDA_ITEM& aItem );
  386. virtual const BOX2I ViewBBox() const override;
  387. virtual std::vector<int> ViewGetLayers() const override;
  388. virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
  389. #if defined(DEBUG)
  390. /**
  391. * Output the object tree, currently for debugging only.
  392. *
  393. * This is pure virtual so compiler warns if somebody mucks up a derived declaration.
  394. *
  395. * @param nestLevel An aid to prettier tree indenting, and is the level
  396. * of nesting of this object within the overall tree.
  397. * @param os The ostream& to output to.
  398. */
  399. virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
  400. void ShowDummy( std::ostream& os ) const; ///< call this if you are a lazy developer
  401. /**
  402. * Output nested space for pretty indenting.
  403. *
  404. * @param nestLevel The nest count.
  405. * @param os The ostream&, where to output
  406. * @return The std::ostream& for continuation.
  407. **/
  408. static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
  409. #endif
  410. protected:
  411. EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
  412. EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
  413. EDA_ITEM( const EDA_ITEM& base );
  414. /**
  415. * Compare \a aText against search criteria in \a aSearchData.
  416. *
  417. * This is a helper function for simplify derived class logic.
  418. *
  419. * @param aText A reference to a wxString object containing the string to test.
  420. * @param aSearchData The criteria to search against.
  421. * @return True if \a aText matches the search criteria in \a aSearchData.
  422. */
  423. bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
  424. public:
  425. const KIID m_Uuid;
  426. private:
  427. /**
  428. * Run time identification, _keep private_ so it can never be changed after a ctor sets it.
  429. *
  430. * See comment near SetType() regarding virtual functions.
  431. */
  432. KICAD_T m_structType;
  433. protected:
  434. EDA_ITEM_FLAGS m_flags;
  435. EDA_ITEM* m_parent; ///< Linked list: Link (parent struct).
  436. EDA_GROUP* m_group; ///< The group this item belongs to
  437. bool m_forceVisible;
  438. bool m_isRollover;
  439. };
  440. /**
  441. * Provide cloning capabilities for all Boost pointer containers of #EDA_ITEM pointers.
  442. *
  443. * @param aItem EDA_ITEM to clone.
  444. * @return Clone of \a aItem.
  445. */
  446. inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
  447. /**
  448. * Comparison functor for sorting EDA_ITEM pointers by their UUID.
  449. */
  450. struct CompareByUuid
  451. {
  452. bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
  453. {
  454. assert( item1 != nullptr && item2 != nullptr );
  455. if( item1->m_Uuid == item2->m_Uuid )
  456. return item1 < item2;
  457. return item1->m_Uuid < item2->m_Uuid;
  458. }
  459. };
  460. /**
  461. * Define list of drawing items for screens.
  462. *
  463. * The standard C++ container was chosen so the pointer can be removed from a list without
  464. * it being destroyed.
  465. */
  466. typedef std::vector< EDA_ITEM* > EDA_ITEMS;
  467. typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
  468. #endif // EDA_ITEM_H