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.

569 lines
20 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
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 <geometry/shape_line_chain.h>
  30. #include <api/serializable.h>
  31. #include <core/typeinfo.h>
  32. #include <eda_item_flags.h>
  33. #include <eda_search_data.h>
  34. #include <view/view_item.h>
  35. #include <kiid.h>
  36. enum class BITMAPS : unsigned int;
  37. enum class INSPECT_RESULT
  38. {
  39. QUIT,
  40. CONTINUE
  41. };
  42. enum RECURSE_MODE
  43. {
  44. RECURSE,
  45. NO_RECURSE,
  46. };
  47. #define IGNORE_PARENT_GROUP false
  48. /**
  49. * Additional flag values wxFindReplaceData::m_Flags
  50. */
  51. class UNITS_PROVIDER;
  52. class EDA_DRAW_FRAME;
  53. class EDA_GROUP;
  54. class MSG_PANEL_ITEM;
  55. class EMBEDDED_FILES;
  56. namespace google { namespace protobuf { class Any; } }
  57. /**
  58. * Used to inspect and possibly collect the (search) results of iterating over a list or
  59. * tree of #KICAD_T objects.
  60. *
  61. * Provide an implementation as needed to inspect EDA_ITEMs visited via #EDA_ITEM::Visit()
  62. * and #EDA_ITEM::IterateForward().
  63. *
  64. * FYI the std::function may hold a lambda, std::bind, pointer to func, or ptr to member
  65. * function, per modern C++. It is used primarily for searching, but not limited to that.
  66. * It can also collect or modify the scanned objects. 'Capturing' lambdas are particularly
  67. * convenient because they can use context and this often means @a aTestData is not used.
  68. *
  69. * @param aItem An #EDA_ITEM to examine.
  70. * @param aTestData is arbitrary data needed by the inspector to determine
  71. * if the EDA_ITEM under test meets its match criteria, and is often NULL
  72. * with the advent of capturing lambdas.
  73. * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
  74. * stop the scan, else #SEARCH_CONTINUE;
  75. */
  76. typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
  77. /// std::function passed to nested users by ref, avoids copying std::function.
  78. typedef const INSPECTOR_FUNC& INSPECTOR;
  79. /**
  80. * A base class for most all the KiCad significant classes used in schematics and boards.
  81. */
  82. class EDA_ITEM : public KIGFX::VIEW_ITEM, public SERIALIZABLE
  83. {
  84. public:
  85. virtual ~EDA_ITEM() = default;
  86. /**
  87. * Returns the type of object.
  88. *
  89. * This attribute should never be changed after a ctor sets it, so there is no public
  90. * "setter" method.
  91. *
  92. * @return the type of object.
  93. */
  94. inline KICAD_T Type() const { return m_structType; }
  95. EDA_ITEM* GetParent() const { return m_parent; }
  96. virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
  97. virtual void SetParentGroup( EDA_GROUP* aGroup ) { m_group = aGroup; }
  98. virtual EDA_GROUP* GetParentGroup() const { return m_group; }
  99. KIID GetParentGroupId() const;
  100. virtual bool IsLocked() const { return false; }
  101. virtual void SetLocked( bool aLocked ) {}
  102. inline bool IsModified() const { return m_flags & IS_CHANGED; }
  103. inline bool IsNew() const { return m_flags & IS_NEW; }
  104. inline bool IsMoving() const { return m_flags & IS_MOVING; }
  105. inline bool IsSelected() const { return m_flags & SELECTED; }
  106. inline bool IsEntered() const { return m_flags & ENTERED; }
  107. inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
  108. inline bool IsRollover() const { return m_isRollover; }
  109. inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; }
  110. inline void SetSelected() { SetFlags( SELECTED ); }
  111. inline void SetBrightened() { SetFlags( BRIGHTENED ); }
  112. inline void ClearSelected() { ClearFlags( SELECTED ); }
  113. inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
  114. void SetModified();
  115. void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
  116. void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
  117. void ClearFlags( EDA_ITEM_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
  118. EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
  119. bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
  120. EDA_ITEM_FLAGS GetEditFlags() const
  121. {
  122. constexpr int mask =
  123. ( IS_NEW | IS_PASTED | IS_MOVING | IS_BROKEN | IS_CHANGED | STRUCT_DELETED );
  124. return m_flags & mask;
  125. }
  126. virtual void ClearEditFlags()
  127. {
  128. ClearFlags( GetEditFlags() );
  129. }
  130. EDA_ITEM_FLAGS GetTempFlags() const
  131. {
  132. constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT | SELECTION_CANDIDATE
  133. | CONNECTIVITY_CANDIDATE );
  134. return m_flags & mask;
  135. }
  136. virtual void ClearTempFlags()
  137. {
  138. ClearFlags( GetTempFlags() );
  139. }
  140. virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
  141. void SetIsShownAsBitmap( bool aBitmap )
  142. {
  143. if( aBitmap )
  144. SetFlags( IS_SHOWN_AS_BITMAP );
  145. else
  146. ClearFlags( IS_SHOWN_AS_BITMAP );
  147. }
  148. inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
  149. /**
  150. * Check whether the item is one of the listed types.
  151. *
  152. * @param aScanTypes List of item types
  153. * @return true if the item type is contained in the list aScanTypes
  154. */
  155. virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
  156. {
  157. for( KICAD_T scanType : aScanTypes )
  158. {
  159. if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
  160. return true;
  161. }
  162. return false;
  163. }
  164. /**
  165. * Set and clear force visible flag used to force the item to be drawn even if it's draw
  166. * attribute is set to not visible.
  167. *
  168. * @param aEnable True forces the item to be drawn. False uses the item's visibility
  169. * setting to determine if the item is to be drawn.
  170. */
  171. void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
  172. bool IsForceVisible() const { return m_forceVisible; }
  173. /**
  174. * Populate \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
  175. * purposes.
  176. *
  177. * @param aFrame is the EDA_DRAW_FRAME that displays the message panel
  178. * @param aList is the list to populate.
  179. */
  180. virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  181. {
  182. }
  183. virtual wxString GetFriendlyName() const;
  184. /**
  185. * Test if \a aPosition is inside or on the boundary of this item.
  186. *
  187. * @param aPosition A reference to a VECTOR2I object containing the coordinates to test.
  188. * @param aAccuracy Increase the item bounding box by this amount.
  189. * @return True if \a aPosition is within the item bounding box.
  190. */
  191. virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
  192. {
  193. return false; // derived classes should override this function
  194. }
  195. /**
  196. * Test if \a aRect intersects this item.
  197. *
  198. * @param aRect A reference to a #BOX2I object containing the rectangle to test.
  199. * @param aContained Set to true to test for containment instead of an intersection.
  200. * @param aAccuracy Increase \a aRect by this amount.
  201. * @return True if \a aRect contains or intersects the item bounding box.
  202. */
  203. virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
  204. {
  205. return false; // derived classes should override this function
  206. }
  207. /**
  208. * Test if \a aPoly intersects this item.
  209. *
  210. * @param aPoly A reference to a #SHAPE_LINE_CHAIN object containing the polygon or polyline to test.
  211. * @param aContained Set to true to test for containment instead of an intersection.
  212. * @return True if \a aPoly contains or intersects the item.
  213. */
  214. virtual bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
  215. {
  216. return false; // derived classes should override this function
  217. }
  218. /**
  219. * Return the orthogonal bounding box of this object for display purposes.
  220. *
  221. * This box should be an enclosing perimeter for visible components of this
  222. * object, and the units should be in the pcb or schematic coordinate
  223. * system. It is OK to overestimate the size by a few counts.
  224. */
  225. virtual const BOX2I GetBoundingBox() const;
  226. virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
  227. virtual void SetPosition( const VECTOR2I& aPos ){};
  228. /**
  229. * Similar to GetPosition() but allows items to return their visual center rather
  230. * than their anchor.
  231. */
  232. virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
  233. /**
  234. * Return the coordinates that should be used for sorting this element
  235. * visually compared to other elements. For instance, for lines the midpoint
  236. * might be a better sorting point than either end.
  237. *
  238. * @return X,Y coordinate of the sort point
  239. */
  240. virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
  241. /**
  242. * Create a duplicate of this item with linked list members set to NULL.
  243. *
  244. * The default version will return NULL in release builds and likely crash the
  245. * program. In debug builds, a warning message indicating the derived class
  246. * has not implemented cloning. This really should be a pure virtual function.
  247. * Due to the fact that there are so many objects derived from EDA_ITEM, the
  248. * decision was made to return NULL until all the objects derived from EDA_ITEM
  249. * implement cloning. Once that happens, this function should be made pure.
  250. *
  251. * @return A clone of the item.
  252. */
  253. virtual EDA_ITEM* Clone() const;
  254. /**
  255. * May be re-implemented for each derived class in order to handle all the types given
  256. * by its member data.
  257. *
  258. * Implementations should call inspector->Inspect() on types in aScanTypes, and may use
  259. * #IterateForward() to do so on lists of such data.
  260. *
  261. * @param inspector An #INSPECTOR instance to use in the inspection.
  262. * @param testData Arbitrary data used by the inspector.
  263. * @param aScanTypes Which #KICAD_T types are of interest and the order in which they should
  264. * be processed.
  265. * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
  266. * else #SCAN_CONTINUE, and determined by the inspector.
  267. */
  268. virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  269. const std::vector<KICAD_T>& aScanTypes );
  270. /**
  271. * This changes first parameter to avoid the DList and use the main queue instead.
  272. */
  273. template< class T >
  274. static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
  275. const std::vector<KICAD_T>& scanTypes )
  276. {
  277. for( const auto& it : aList )
  278. {
  279. EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
  280. if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
  281. {
  282. return INSPECT_RESULT::QUIT;
  283. }
  284. }
  285. return INSPECT_RESULT::CONTINUE;
  286. }
  287. /**
  288. * Change first parameter to avoid the DList and use std::vector instead.
  289. */
  290. template <class T>
  291. static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
  292. void* testData, const std::vector<KICAD_T>& scanTypes )
  293. {
  294. for( const auto& it : aList )
  295. {
  296. EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
  297. if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
  298. {
  299. return INSPECT_RESULT::QUIT;
  300. }
  301. }
  302. return INSPECT_RESULT::CONTINUE;
  303. }
  304. /**
  305. * Return a translated description of the type for this EDA_ITEM for display in user facing
  306. * messages.
  307. */
  308. wxString GetTypeDesc() const;
  309. /**
  310. * Return a user-visible description string of this item. This description is used in
  311. * disambiguation menus, the message panel, ERC/DRC reports, etc.
  312. *
  313. * The default version of this function raises an assertion in the debug mode and
  314. * returns a string to indicate that it was not overridden to provide the object
  315. * specific text.
  316. *
  317. * @param aLong indicates a long string is acceptable
  318. * @return The menu text string.
  319. */
  320. virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
  321. /**
  322. * Return a pointer to an image to be used in menus.
  323. *
  324. * The default version returns the right arrow image. Override this function to provide
  325. * object specific menu images.
  326. *
  327. * @return The menu image associated with the item.
  328. */
  329. virtual BITMAPS GetMenuImage() const;
  330. /**
  331. * Compare the item against the search criteria in \a aSearchData.
  332. *
  333. * The base class returns false since many of the objects derived from EDA_ITEM
  334. * do not have any text to search.
  335. *
  336. * @param aSearchData A reference to a wxFindReplaceData object containing the
  337. * search criteria.
  338. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  339. * @return True if the item's text matches the search criteria in \a aSearchData.
  340. */
  341. virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
  342. {
  343. return false;
  344. }
  345. /**
  346. * Perform a text replace on \a aText using the find and replace criteria in
  347. * \a aSearchData on items that support text find and replace.
  348. *
  349. * @param aSearchData A reference to a wxFindReplaceData object containing the
  350. * search and replace criteria.
  351. * @param aText A reference to a wxString object containing the text to be replaced.
  352. * @return True if \a aText was modified, otherwise false.
  353. */
  354. static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
  355. /**
  356. * Perform a text replace using the find and replace criteria in \a aSearchData
  357. * on items that support text find and replace.
  358. *
  359. * This function must be overridden for items that support text replace.
  360. *
  361. * @param aSearchData A reference to a wxFindReplaceData object containing the search and
  362. * replace criteria.
  363. * @param aAuxData A pointer to optional data required for the search or NULL if not used.
  364. * @return True if the item text was modified, otherwise false.
  365. */
  366. virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
  367. {
  368. return false;
  369. }
  370. /**
  371. * Override this method in any derived object that supports test find and replace.
  372. *
  373. * @return True if the item has replaceable text that can be modified using
  374. * the find and replace dialog.
  375. */
  376. virtual bool IsReplaceable() const { return false; }
  377. /**
  378. * Test if another item is less than this object.
  379. *
  380. * @param aItem - Item to compare against.
  381. * @return - True if \a aItem is less than the item.
  382. */
  383. bool operator<( const EDA_ITEM& aItem ) const;
  384. /**
  385. * Helper function to be used by the C++ STL sort algorithm for sorting a STL
  386. * container of #EDA_ITEM pointers.
  387. *
  388. * @param aLeft The left hand item to compare.
  389. * @param aRight The right hand item to compare.
  390. * @return True if \a aLeft is less than \a aRight.
  391. */
  392. static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
  393. /**
  394. * Assign the members of \a aItem to another object.
  395. */
  396. EDA_ITEM& operator=( const EDA_ITEM& aItem );
  397. virtual const BOX2I ViewBBox() const override;
  398. virtual std::vector<int> ViewGetLayers() const override;
  399. virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
  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 { ShowDummy( os ); };
  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, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
  423. EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
  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. EDA_ITEM* findParent( KICAD_T aType ) const;
  436. public:
  437. const KIID m_Uuid;
  438. private:
  439. /**
  440. * Run time identification, _keep private_ so it can never be changed after a ctor sets it.
  441. *
  442. * See comment near SetType() regarding virtual functions.
  443. */
  444. KICAD_T m_structType;
  445. protected:
  446. EDA_ITEM_FLAGS m_flags;
  447. EDA_ITEM* m_parent; ///< Owner.
  448. EDA_GROUP* m_group; ///< The group this item belongs to, if any. No ownership implied.
  449. bool m_forceVisible;
  450. bool m_isRollover;
  451. };
  452. /**
  453. * Provide cloning capabilities for all Boost pointer containers of #EDA_ITEM pointers.
  454. *
  455. * @param aItem EDA_ITEM to clone.
  456. * @return Clone of \a aItem.
  457. */
  458. inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
  459. /**
  460. * Comparison functor for sorting EDA_ITEM pointers by their UUID.
  461. */
  462. struct CompareByUuid
  463. {
  464. bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
  465. {
  466. assert( item1 != nullptr && item2 != nullptr );
  467. if( item1->m_Uuid == item2->m_Uuid )
  468. return item1 < item2;
  469. return item1->m_Uuid < item2->m_Uuid;
  470. }
  471. };
  472. /**
  473. * Define list of drawing items for screens.
  474. *
  475. * The standard C++ container was chosen so the pointer can be removed from a list without
  476. * it being destroyed.
  477. */
  478. typedef std::vector< EDA_ITEM* > EDA_ITEMS;
  479. typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
  480. #endif // EDA_ITEM_H