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.

541 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
16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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 (C) 2004-2022 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. #ifndef EDA_ITEM_H
  27. #define EDA_ITEM_H
  28. #include <deque>
  29. #include <core/typeinfo.h>
  30. #include <eda_item_flags.h>
  31. #include <eda_search_data.h>
  32. #include <view/view_item.h>
  33. #include <kiid.h>
  34. enum class BITMAPS : unsigned int;
  35. enum class INSPECT_RESULT
  36. {
  37. QUIT,
  38. CONTINUE
  39. };
  40. /**
  41. * Additional flag values wxFindReplaceData::m_Flags
  42. */
  43. enum FIND_REPLACE_FLAGS
  44. {
  45. // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
  46. FR_CURRENT_SHEET_ONLY = 0x4 << 1, // Search the current sheet only.
  47. FR_SEARCH_ALL_FIELDS = 0x4 << 2, // Search hidden fields too.
  48. FR_SEARCH_ALL_PINS = 0x4 << 3, // Search pin name and number.
  49. FR_MATCH_WILDCARD = 0x4 << 4, // Use simple wild card matching (* & ?).
  50. FR_SEARCH_WRAP = 0x4 << 5, // Wrap around the start or end of search.
  51. FR_SEARCH_REPLACE = 0x4 << 7, // Search for a item that has replaceable text.
  52. FR_REPLACE_ITEM_FOUND = 0x4 << 8, // Indicates an item with replaceable text has been found.
  53. FR_REPLACE_REFERENCES = 0x4 << 9 // Don't replace in references.
  54. };
  55. class wxFindReplaceData;
  56. class EDA_DRAW_FRAME;
  57. class EDA_RECT;
  58. class MSG_PANEL_ITEM;
  59. /**
  60. * Used to inspect and possibly collect the (search) results of iterating over a list or
  61. * tree of #KICAD_T objects.
  62. *
  63. * Provide an implementation as needed to inspect EDA_ITEMs visited via #EDA_ITEM::Visit()
  64. * and #EDA_ITEM::IterateForward().
  65. *
  66. * FYI the std::function may hold a lambda, std::bind, pointer to func, or ptr to member
  67. * function, per modern C++. It is used primarily for searching, but not limited to that.
  68. * It can also collect or modify the scanned objects. 'Capturing' lambdas are particularly
  69. * convenient because they can use context and this often means @a aTestData is not used.
  70. *
  71. * @param aItem An #EDA_ITEM to examine.
  72. * @param aTestData is arbitrary data needed by the inspector to determine
  73. * if the EDA_ITEM under test meets its match criteria, and is often NULL
  74. * with the advent of capturing lambdas.
  75. * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
  76. * stop the scan, else #SEARCH_CONTINUE;
  77. */
  78. typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
  79. ///< std::function passed to nested users by ref, avoids copying std::function.
  80. typedef const INSPECTOR_FUNC& INSPECTOR;
  81. /**
  82. * A base class for most all the KiCad significant classes used in schematics and boards.
  83. */
  84. class EDA_ITEM : public KIGFX::VIEW_ITEM
  85. {
  86. public:
  87. virtual ~EDA_ITEM() { };
  88. /**
  89. * Returns the type of object.
  90. *
  91. * This attribute should never be changed after a ctor sets it, so there is no public
  92. * "setter" method.
  93. *
  94. * @return the type of object.
  95. */
  96. inline KICAD_T Type() const { return m_structType; }
  97. EDA_ITEM* GetParent() const { return m_parent; }
  98. virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
  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 IsDragging() const { return m_flags & IS_DRAGGING; }
  103. inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
  104. inline bool IsSelected() const { return m_flags & SELECTED; }
  105. inline bool IsEntered() const { return m_flags & ENTERED; }
  106. inline bool IsResized() const { return m_flags & IS_RESIZING; }
  107. inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
  108. inline bool IsRollover() const
  109. {
  110. return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
  111. }
  112. inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
  113. inline void SetSelected() { SetFlags( SELECTED ); }
  114. inline void SetBrightened() { SetFlags( BRIGHTENED ); }
  115. inline void ClearSelected() { ClearFlags( SELECTED ); }
  116. inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
  117. void SetModified();
  118. int GetState( EDA_ITEM_FLAGS type ) const
  119. {
  120. return m_status & type;
  121. }
  122. void SetState( EDA_ITEM_FLAGS type, bool state )
  123. {
  124. if( state )
  125. m_status |= type; // state = ON or OFF
  126. else
  127. m_status &= ~type;
  128. }
  129. EDA_ITEM_FLAGS GetStatus() const { return m_status; }
  130. void SetStatus( EDA_ITEM_FLAGS aStatus ) { m_status = aStatus; }
  131. void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
  132. void ClearFlags( EDA_ITEM_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
  133. EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
  134. bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
  135. EDA_ITEM_FLAGS GetEditFlags() const
  136. {
  137. constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVING | IS_RESIZING | IS_DRAGGING
  138. | IS_CHANGED | IS_WIRE_IMAGE | STRUCT_DELETED );
  139. return m_flags & mask;
  140. }
  141. void ClearTempFlags()
  142. {
  143. ClearFlags( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT | DO_NOT_DRAW );
  144. }
  145. void ClearEditFlags()
  146. {
  147. ClearFlags( GetEditFlags() );
  148. }
  149. virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
  150. void SetIsShownAsBitmap( bool aBitmap )
  151. {
  152. if( aBitmap )
  153. SetFlags( IS_SHOWN_AS_BITMAP );
  154. else
  155. ClearFlags( IS_SHOWN_AS_BITMAP );
  156. }
  157. inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
  158. /**
  159. * Check whether the item is one of the listed types.
  160. *
  161. * @param aScanTypes List of item types
  162. * @return true if the item type is contained in the list aScanTypes
  163. */
  164. virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
  165. {
  166. for( KICAD_T scanType : aScanTypes )
  167. {
  168. if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
  169. return true;
  170. }
  171. return false;
  172. }
  173. /**
  174. * Set and clear force visible flag used to force the item to be drawn even if it's draw
  175. * attribute is set to not visible.
  176. *
  177. * @param aEnable True forces the item to be drawn. False uses the item's visibility
  178. * setting to determine if the item is to be drawn.
  179. */
  180. void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
  181. bool IsForceVisible() const { return m_forceVisible; }
  182. /**
  183. * Populate \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
  184. * purposes.
  185. *
  186. * @param aList is the list to populate.
  187. */
  188. virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  189. {
  190. }
  191. /**
  192. * Test if \a aPosition is inside or on the boundary of this item.
  193. *
  194. * @param aPosition A reference to a VECTOR2I object containing the coordinates to test.
  195. * @param aAccuracy Increase the item bounding box by this amount.
  196. * @return True if \a aPosition is within the item bounding box.
  197. */
  198. virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
  199. {
  200. return false; // derived classes should override this function
  201. }
  202. /**
  203. * Test if \a aRect intersects this item.
  204. *
  205. * @param aRect A reference to a #BOX2I object containing the rectangle to test.
  206. * @param aContained Set to true to test for containment instead of an intersection.
  207. * @param aAccuracy Increase \a aRect by this amount.
  208. * @return True if \a aRect contains or intersects the item bounding box.
  209. */
  210. virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
  211. {
  212. return false; // derived classes should override this function
  213. }
  214. /**
  215. * Return the orthogonal bounding box of this object for display purposes.
  216. *
  217. * This box should be an enclosing perimeter for visible components of this
  218. * object, and the units should be in the pcb or schematic coordinate
  219. * system. It is OK to overestimate the size by a few counts.
  220. */
  221. virtual const BOX2I GetBoundingBox() const;
  222. virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
  223. virtual void SetPosition( const VECTOR2I& aPos ){};
  224. /**
  225. * Similar to GetPosition, but allows items to return their visual center rather
  226. * than their anchor.
  227. */
  228. virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
  229. /**
  230. * Return the coordinates that should be used for sorting this element
  231. * visually compared to other elements. For instance, for lines the midpoint
  232. * might be a better sorting point than either end.
  233. *
  234. * @return X,Y coordinate of the sort point
  235. */
  236. virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
  237. /**
  238. * Create a duplicate of this item with linked list members set to NULL.
  239. *
  240. * The default version will return NULL in release builds and likely crash the
  241. * program. In debug builds, a warning message indicating the derived class
  242. * has not implemented cloning. This really should be a pure virtual function.
  243. * Due to the fact that there are so many objects derived from EDA_ITEM, the
  244. * decision was made to return NULL until all the objects derived from EDA_ITEM
  245. * implement cloning. Once that happens, this function should be made pure.
  246. *
  247. * @return A clone of the item.
  248. */
  249. virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
  250. /**
  251. * May be re-implemented for each derived class in order to handle all the types given
  252. * by its member data.
  253. *
  254. * Implementations should call inspector->Inspect() on types in aScanTypes, and may use
  255. * #IterateForward() to do so on lists of such data.
  256. *
  257. * @param inspector An #INSPECTOR instance to use in the inspection.
  258. * @param testData Arbitrary data used by the inspector.
  259. * @param aScanTypes Which #KICAD_T types are of interest and the order in which they should
  260. * be processed.
  261. * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
  262. * else #SCAN_CONTINUE, and determined by the inspector.
  263. */
  264. virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  265. const std::vector<KICAD_T>& aScanTypes );
  266. /**
  267. * This changes first parameter to avoid the DList and use the main queue instead.
  268. */
  269. template< class T >
  270. static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
  271. const std::vector<KICAD_T>& scanTypes )
  272. {
  273. for( const auto& it : aList )
  274. {
  275. if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
  276. testData,
  277. scanTypes ) == INSPECT_RESULT::QUIT )
  278. {
  279. return INSPECT_RESULT::QUIT;
  280. }
  281. }
  282. return INSPECT_RESULT::CONTINUE;
  283. }
  284. /**
  285. * Change first parameter to avoid the DList and use std::vector instead.
  286. */
  287. template <class T>
  288. static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
  289. void* testData, const std::vector<KICAD_T>& scanTypes )
  290. {
  291. for( const auto& it : aList )
  292. {
  293. if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
  294. testData,
  295. scanTypes ) == INSPECT_RESULT::QUIT )
  296. {
  297. return INSPECT_RESULT::QUIT;
  298. }
  299. }
  300. return INSPECT_RESULT::CONTINUE;
  301. }
  302. /**
  303. * Return the class name.
  304. */
  305. virtual wxString GetClass() const = 0;
  306. /**
  307. * Return a translated description of the type for this EDA_ITEM for display in user facing
  308. * messages.
  309. */
  310. wxString GetTypeDesc();
  311. /**
  312. * Return the text to display to be used in the selection clarification context menu
  313. * when multiple items are found at the current cursor position.
  314. *
  315. * The default version of this function raises an assertion in the debug mode and
  316. * returns a string to indicate that it was not overridden to provide the object
  317. * specific text.
  318. *
  319. * @return The menu text string.
  320. */
  321. virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
  322. /**
  323. * Return a pointer to an image to be used in menus.
  324. *
  325. * The default version returns the right arrow image. Override this function to provide
  326. * object specific menu images.
  327. *
  328. * @return The menu image associated with the item.
  329. */
  330. virtual BITMAPS GetMenuImage() const;
  331. /**
  332. * Compare the item against the search criteria in \a aSearchData.
  333. *
  334. * The base class returns false since many of the objects derived from EDA_ITEM
  335. * do not have any text to search.
  336. *
  337. * @param aSearchData A reference to a wxFindReplaceData object containing the
  338. * search criteria.
  339. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  340. * @return True if the item's text matches the search criteria in \a aSearchData.
  341. */
  342. virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  343. {
  344. return false;
  345. }
  346. /**
  347. * Perform a text replace on \a aText using the find and replace criteria in
  348. * \a aSearchData on items that support text find and replace.
  349. *
  350. * @param aSearchData A reference to a wxFindReplaceData object containing the
  351. * search and replace criteria.
  352. * @param aText A reference to a wxString object containing the text to be replaced.
  353. * @return True if \a aText was modified, otherwise false.
  354. */
  355. static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
  356. /**
  357. * Perform a text replace using the find and replace criteria in \a aSearchData
  358. * on items that support text find and replace.
  359. *
  360. * This function must be overridden for items that support text replace.
  361. *
  362. * @param aSearchData A reference to a wxFindReplaceData object containing the search and
  363. * replace criteria.
  364. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  365. * @return True if the item text was modified, otherwise false.
  366. */
  367. virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
  368. {
  369. return false;
  370. }
  371. /**
  372. * Override this method in any derived object that supports test find and replace.
  373. *
  374. * @return True if the item has replaceable text that can be modified using
  375. * the find and replace dialog.
  376. */
  377. virtual bool IsReplaceable() const { return false; }
  378. /**
  379. * Test if another item is less than this object.
  380. *
  381. * @param aItem - Item to compare against.
  382. * @return - True if \a aItem is less than the item.
  383. */
  384. bool operator<( const EDA_ITEM& aItem ) const;
  385. /**
  386. * Helper function to be used by the C++ STL sort algorithm for sorting a STL
  387. * container of #EDA_ITEM pointers.
  388. *
  389. * @param aLeft The left hand item to compare.
  390. * @param aRight The right hand item to compare.
  391. * @return True if \a aLeft is less than \a aRight.
  392. */
  393. static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
  394. /**
  395. * Assign the members of \a aItem to another object.
  396. */
  397. EDA_ITEM& operator=( const EDA_ITEM& aItem );
  398. virtual const BOX2I ViewBBox() const override;
  399. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  400. #if defined(DEBUG)
  401. /**
  402. * Output the object tree, currently for debugging only.
  403. *
  404. * This is pure virtual so compiler warns if somebody mucks up a derived declaration.
  405. *
  406. * @param nestLevel An aid to prettier tree indenting, and is the level
  407. * of nesting of this object within the overall tree.
  408. * @param os The ostream& to output to.
  409. */
  410. virtual void Show( int nestLevel, std::ostream& os ) const = 0;
  411. void ShowDummy( std::ostream& os ) const; ///< call this if you are a lazy developer
  412. /**
  413. * Output nested space for pretty indenting.
  414. *
  415. * @param nestLevel The nest count.
  416. * @param os The ostream&, where to output
  417. * @return The std::ostream& for continuation.
  418. **/
  419. static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
  420. #endif
  421. protected:
  422. EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
  423. EDA_ITEM( KICAD_T idType );
  424. EDA_ITEM( const EDA_ITEM& base );
  425. /**
  426. * Compare \a aText against search criteria in \a aSearchData.
  427. *
  428. * This is a helper function for simplify derived class logic.
  429. *
  430. * @param aText A reference to a wxString object containing the string to test.
  431. * @param aSearchData The criteria to search against.
  432. * @return True if \a aText matches the search criteria in \a aSearchData.
  433. */
  434. bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
  435. public:
  436. const KIID m_Uuid;
  437. protected:
  438. EDA_ITEM_FLAGS m_status;
  439. EDA_ITEM* m_parent; ///< Linked list: Link (parent struct)
  440. bool m_forceVisible;
  441. EDA_ITEM_FLAGS m_flags;
  442. private:
  443. /**
  444. * Run time identification, _keep private_ so it can never be changed after a ctor
  445. * sets it. See comment near SetType() regarding virtual functions.
  446. */
  447. KICAD_T m_structType;
  448. };
  449. /**
  450. * Provide cloning capabilities for all Boost pointer containers of #EDA_ITEM pointers.
  451. *
  452. * @param aItem EDA_ITEM to clone.
  453. * @return Clone of \a aItem.
  454. */
  455. inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
  456. /**
  457. * Define list of drawing items for screens.
  458. *
  459. * The standard C++ container was chosen so the pointer can be removed from a list without
  460. * it being destroyed.
  461. */
  462. typedef std::vector< EDA_ITEM* > EDA_ITEMS;
  463. #endif // EDA_ITEM_H