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.

596 lines
23 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
17 years ago
17 years ago
17 years ago
18 years ago
18 years ago
19 years ago
19 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-2020 KiCad Developers, see change_log.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef BASE_STRUCT_H_
  27. #define BASE_STRUCT_H_
  28. #include <deque>
  29. #include <core/typeinfo.h>
  30. #include "common.h"
  31. #include <wx/fdrepdlg.h>
  32. #include <bitmap_types.h>
  33. #include <view/view_item.h>
  34. /**
  35. * Enum FILL_T
  36. * is the set of fill types used in plotting or drawing enclosed areas.
  37. */
  38. enum FILL_T {
  39. NO_FILL,
  40. FILLED_SHAPE, // Fill with object color ("Solid shape")
  41. FILLED_WITH_BG_BODYCOLOR, // Fill with background body color
  42. // (not filled in B&W mode when plotting or printing)
  43. FILLED_WITH_COLOR // Fill with a user-defined color (currently sheets only)
  44. };
  45. enum class SEARCH_RESULT
  46. {
  47. QUIT,
  48. CONTINUE
  49. };
  50. /**
  51. * Additional flag values wxFindReplaceData::m_Flags
  52. */
  53. enum FIND_REPLACE_FLAGS
  54. {
  55. // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
  56. FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1, // Search the current sheet only.
  57. FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2, // Search hidden fields too.
  58. FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3, // Search pin name and number.
  59. FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4, // Use simple wild card matching (* & ?).
  60. FR_SEARCH_WRAP = wxFR_MATCHCASE << 5, // Wrap around the start or end of search.
  61. FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7, // Search for a item that has replaceable text.
  62. FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8, // Indicates an item with replaceable text has
  63. // been found.
  64. FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9 // Don't replace in references.
  65. };
  66. class wxFindReplaceData;
  67. class EDA_ITEM;
  68. class EDA_DRAW_FRAME;
  69. class EDA_RECT;
  70. class MSG_PANEL_ITEM;
  71. /**
  72. * Typedef INSPECTOR
  73. * is used to inspect and possibly collect the
  74. * (search) results of iterating over a list or tree of KICAD_T objects.
  75. * Provide an implementation as needed to inspect EDA_ITEMs visited via
  76. * EDA_ITEM::Visit() and EDA_ITEM::IterateForward().
  77. * <p>
  78. * FYI the std::function may hold a lambda, std::bind, pointer to func, or
  79. * ptr to member function, per modern C++. It is used primarily for searching,
  80. * but not limited to that. It can also collect or modify the scanned objects.
  81. * 'Capturing' lambdas are particularly convenient because they can use context
  82. * and this often means @a aTestData is not used.
  83. *
  84. * @param aItem An EDA_ITEM to examine.
  85. * @param aTestData is arbitrary data needed by the inspector to determine
  86. * if the EDA_ITEM under test meets its match criteria, and is often NULL
  87. * with the advent of capturing lambdas.
  88. * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
  89. * stop the scan, else #SEARCH_CONTINUE;
  90. */
  91. typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
  92. typedef const INSPECTOR_FUNC& INSPECTOR; /// std::function passed to nested users by ref, avoids copying std::function
  93. // These define are used for the .m_Flags and .m_UndoRedoStatus member of the
  94. // class EDA_ITEM
  95. //
  96. // NB: DO NOT ADD FLAGS ANYWHERE BUT AT THE END: THE FLAG-SET IS STORED AS AN INTEGER IN FILES.
  97. //
  98. #define IS_CHANGED (1 << 0) ///< Item was edited, and modified
  99. #define IS_LINKED (1 << 1) ///< Used in calculation to mark linked items (temporary use)
  100. #define IN_EDIT (1 << 2) ///< Item currently edited
  101. #define IS_MOVED (1 << 3) ///< Item being moved
  102. #define IS_NEW (1 << 4) ///< New item, just created
  103. #define IS_RESIZED (1 << 5) ///< Item being resized
  104. #define IS_DRAGGED (1 << 6) ///< Item being dragged
  105. #define IS_DELETED (1 << 7)
  106. #define IS_WIRE_IMAGE (1 << 8) ///< Item to be drawn as wireframe while editing
  107. #define STARTPOINT (1 << 9) ///< When a line is selected, these flags indicate which
  108. #define ENDPOINT (1 << 10) ///< ends. (Used to support dragging.)
  109. #define SELECTED (1 << 11)
  110. #define TEMP_SELECTED (1 << 12) ///< flag indicating that the structure has already selected
  111. #define STRUCT_DELETED (1 << 13) ///< flag indication structures to be erased
  112. #define CANDIDATE (1 << 14) ///< flag indicating that the structure is connected
  113. #define SKIP_STRUCT (1 << 15) ///< flag indicating that the structure should be ignored
  114. #define DO_NOT_DRAW (1 << 16) ///< Used to disable draw function
  115. #define IS_PASTED (1 << 17) ///< Modifier on IS_NEW which indicates it came from clipboard
  116. #define TRACK_LOCKED (1 << 18) ///< Pcbnew: track locked: protected from global deletion
  117. #define TRACK_AR (1 << 19) ///< Pcbnew: autorouted track
  118. #define FLAG1 (1 << 20) ///< Pcbnew: flag used in local computations
  119. #define FLAG0 (1 << 21) ///< Pcbnew: flag used in local computations
  120. #define BEGIN_ONPAD (1 << 22) ///< Pcbnew: flag set for track segment starting on a pad
  121. #define END_ONPAD (1 << 23) ///< Pcbnew: flag set for track segment ending on a pad
  122. #define BUSY (1 << 24) ///< Pcbnew: flag indicating that the structure has
  123. ///< already been edited, in some functions
  124. #define HIGHLIGHTED (1 << 25) ///< item is drawn in normal colors, when the rest is darkened
  125. #define BRIGHTENED (1 << 26) ///< item is drawn with a bright contour
  126. #define DP_COUPLED (1 << 27) ///< item is coupled with another item making a differential pair
  127. ///< (applies to segments only)
  128. #define UR_TRANSIENT (1 << 28) ///< indicates the item is owned by the undo/redo stack
  129. #define IS_DANGLING (1 << 29) ///< indicates a pin is dangling
  130. // WARNING: if you add flags, you'll probably need to adjust the masks in GetEditFlags() and
  131. // ClearTempFlags().
  132. // NOTE: The HIGHLIGHTED flag is basically deprecated, it was used for cross-probing before eeschema
  133. // supported real object selection.
  134. #define EDA_ITEM_ALL_FLAGS -1
  135. typedef unsigned STATUS_FLAGS;
  136. /**
  137. * EDA_ITEM
  138. * is a base class for most all the KiCad significant classes, used in
  139. * schematics and boards.
  140. */
  141. class EDA_ITEM : public KIGFX::VIEW_ITEM
  142. {
  143. public:
  144. const KIID m_Uuid;
  145. private:
  146. /**
  147. * Run time identification, _keep private_ so it can never be changed after
  148. * a constructor sets it. See comment near SetType() regarding virtual
  149. * functions.
  150. */
  151. KICAD_T m_StructType;
  152. protected:
  153. STATUS_FLAGS m_Status;
  154. EDA_ITEM* m_Parent; ///< Linked list: Link (parent struct)
  155. bool m_forceVisible;
  156. STATUS_FLAGS m_Flags;
  157. protected:
  158. EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
  159. EDA_ITEM( KICAD_T idType );
  160. EDA_ITEM( const EDA_ITEM& base );
  161. public:
  162. virtual ~EDA_ITEM() { };
  163. /**
  164. * Function Type()
  165. *
  166. * returns the type of object. This attribute should never be changed
  167. * after a constructor sets it, so there is no public "setter" method.
  168. * @return KICAD_T - the type of object.
  169. */
  170. inline KICAD_T Type() const { return m_StructType; }
  171. EDA_ITEM* GetParent() const { return m_Parent; }
  172. virtual void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
  173. inline bool IsNew() const { return m_Flags & IS_NEW; }
  174. inline bool IsModified() const { return m_Flags & IS_CHANGED; }
  175. inline bool IsMoving() const { return m_Flags & IS_MOVED; }
  176. inline bool IsDragging() const { return m_Flags & IS_DRAGGED; }
  177. inline bool IsWireImage() const { return m_Flags & IS_WIRE_IMAGE; }
  178. inline bool IsSelected() const { return m_Flags & SELECTED; }
  179. inline bool IsResized() const { return m_Flags & IS_RESIZED; }
  180. inline bool IsHighlighted() const { return m_Flags & HIGHLIGHTED; }
  181. inline bool IsBrightened() const { return m_Flags & BRIGHTENED; }
  182. inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
  183. inline void SetSelected() { SetFlags( SELECTED ); }
  184. inline void SetHighlighted() { SetFlags( HIGHLIGHTED ); }
  185. inline void SetBrightened() { SetFlags( BRIGHTENED ); }
  186. inline void ClearSelected() { ClearFlags( SELECTED ); }
  187. inline void ClearHighlighted() { ClearFlags( HIGHLIGHTED ); }
  188. inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
  189. void SetModified();
  190. int GetState( int type ) const
  191. {
  192. return m_Status & type;
  193. }
  194. void SetState( int type, int state )
  195. {
  196. if( state )
  197. m_Status |= type; // state = ON or OFF
  198. else
  199. m_Status &= ~type;
  200. }
  201. STATUS_FLAGS GetStatus() const { return m_Status; }
  202. void SetStatus( STATUS_FLAGS aStatus ) { m_Status = aStatus; }
  203. void SetFlags( STATUS_FLAGS aMask ) { m_Flags |= aMask; }
  204. void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; }
  205. STATUS_FLAGS GetFlags() const { return m_Flags; }
  206. bool HasFlag( STATUS_FLAGS aFlag ) { return ( m_Flags & aFlag ) == aFlag; }
  207. STATUS_FLAGS GetEditFlags() const
  208. {
  209. int mask = EDA_ITEM_ALL_FLAGS - ( SELECTED | TEMP_SELECTED | HIGHLIGHTED | BRIGHTENED |
  210. STARTPOINT | ENDPOINT | IS_DANGLING |
  211. BEGIN_ONPAD | END_ONPAD | DP_COUPLED );
  212. return m_Flags & mask;
  213. }
  214. void ClearTempFlags()
  215. {
  216. ClearFlags( STARTPOINT | ENDPOINT | CANDIDATE | IS_LINKED | SKIP_STRUCT | DO_NOT_DRAW );
  217. }
  218. void ClearEditFlags()
  219. {
  220. ClearFlags( GetEditFlags() );
  221. }
  222. /**
  223. * Function IsType
  224. * Checks whether the item is one of the listed types
  225. * @param aScanTypes List of item types
  226. * @return true if the item type is contained in the list aScanTypes
  227. */
  228. virtual bool IsType( const KICAD_T aScanTypes[] ) const
  229. {
  230. if( aScanTypes[0] == SCH_LOCATE_ANY_T )
  231. return true;
  232. for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
  233. {
  234. if( m_StructType == *p )
  235. return true;
  236. }
  237. return false;
  238. }
  239. /**
  240. * Function SetForceVisible
  241. * is used to set and cleag force visible flag used to force the item to be drawn
  242. * even if it's draw attribute is set to not visible.
  243. *
  244. * @param aEnable True forces the item to be drawn. False uses the item's visibility
  245. * setting to determine if the item is to be drawn.
  246. */
  247. void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
  248. bool IsForceVisible() const { return m_forceVisible; }
  249. /**
  250. * Function GetMsgPanelInfo
  251. * populates \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
  252. * purposes.
  253. *
  254. * @param aList is the list to populate.
  255. */
  256. virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  257. {
  258. }
  259. /**
  260. * Function HitTest
  261. * tests if \a aPosition is contained within or on the bounding box of an item.
  262. *
  263. * @param aPosition A reference to a wxPoint object containing the coordinates to test.
  264. * @param aAccuracy Increase the item bounding box by this amount.
  265. * @return True if \a aPosition is within the item bounding box.
  266. */
  267. virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
  268. {
  269. return false; // derived classes should override this function
  270. }
  271. /**
  272. * Function HitTest
  273. * tests if \a aRect intersects or is contained within the bounding box of an item.
  274. *
  275. * @param aRect A reference to a EDA_RECT object containing the rectangle to test.
  276. * @param aContained Set to true to test for containment instead of an intersection.
  277. * @param aAccuracy Increase \a aRect by this amount.
  278. * @return True if \a aRect contains or intersects the item bounding box.
  279. */
  280. virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
  281. {
  282. return false; // derived classes should override this function
  283. }
  284. /**
  285. * Function GetBoundingBox
  286. * returns the orthogonal, bounding box of this object for display
  287. * purposes.
  288. * This box should be an enclosing perimeter for visible components of this
  289. * object, and the units should be in the pcb or schematic coordinate
  290. * system.
  291. * It is OK to overestimate the size by a few counts.
  292. */
  293. virtual const EDA_RECT GetBoundingBox() const;
  294. virtual const wxPoint GetPosition() const { return wxPoint(); }
  295. /**
  296. * Function GetFocusPosition
  297. * similar to GetPosition, but allows items to return their visual center rather
  298. * than their anchor.
  299. */
  300. virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
  301. /**
  302. * Function Clone
  303. * creates a duplicate of this item with linked list members set to NULL.
  304. *
  305. * The default version will return NULL in release builds and likely crash the
  306. * program. In debug builds, a warning message indicating the derived class
  307. * has not implemented cloning. This really should be a pure virtual function.
  308. * Due to the fact that there are so many objects derived from EDA_ITEM, the
  309. * decision was made to return NULL until all the objects derived from EDA_ITEM
  310. * implement cloning. Once that happens, this function should be made pure.
  311. *
  312. * @return A clone of the item.
  313. */
  314. virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
  315. /**
  316. * Function Visit
  317. * may be re-implemented for each derived class in order to handle
  318. * all the types given by its member data. Implementations should call
  319. * inspector->Inspect() on types in scanTypes[], and may use
  320. * IterateForward()
  321. * to do so on lists of such data.
  322. * @param inspector An INSPECTOR instance to use in the inspection.
  323. * @param testData Arbitrary data used by the inspector.
  324. * @param scanTypes Which KICAD_T types are of interest and the order
  325. * is significant too, terminated by EOT.
  326. * @return SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
  327. * else SCAN_CONTINUE, and determined by the inspector.
  328. */
  329. virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
  330. /**
  331. * @copydoc SEARCH_RESULT IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
  332. *
  333. * This changes first parameter to avoid the DList and use the main queue instead
  334. */
  335. template< class T >
  336. static SEARCH_RESULT IterateForward( std::deque<T>& aList,
  337. INSPECTOR inspector,
  338. void* testData,
  339. const KICAD_T scanTypes[] )
  340. {
  341. for( auto it : aList )
  342. {
  343. if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
  344. == SEARCH_RESULT::QUIT )
  345. return SEARCH_RESULT::QUIT;
  346. }
  347. return SEARCH_RESULT::CONTINUE;
  348. }
  349. /**
  350. * @copydoc SEARCH_RESULT IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
  351. *
  352. * This changes first parameter to avoid the DList and use std::vector instead
  353. */
  354. template <class T>
  355. static SEARCH_RESULT IterateForward(
  356. std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
  357. {
  358. for( auto it : aList )
  359. {
  360. if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
  361. == SEARCH_RESULT::QUIT )
  362. return SEARCH_RESULT::QUIT;
  363. }
  364. return SEARCH_RESULT::CONTINUE;
  365. }
  366. /**
  367. * Function GetClass
  368. * returns the class name.
  369. * @return wxString
  370. */
  371. virtual wxString GetClass() const = 0;
  372. /**
  373. * Function GetSelectMenuText
  374. * returns the text to display to be used in the selection clarification context menu
  375. * when multiple items are found at the current cursor position. The default version
  376. * of this function raises an assertion in the debug mode and returns a string to
  377. * indicate that it was not overridden to provide the object specific text.
  378. *
  379. * @return The menu text string.
  380. */
  381. virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
  382. /**
  383. * Function GetMenuImage
  384. * returns a pointer to an image to be used in menus. The default version returns
  385. * the right arrow image. Override this function to provide object specific menu
  386. * images.
  387. * @return The menu image associated with the item.
  388. */
  389. virtual BITMAP_DEF GetMenuImage() const;
  390. /**
  391. * Function Matches
  392. * compares the item against the search criteria in \a aSearchData.
  393. *
  394. * The base class returns false since many of the objects derived from EDA_ITEM
  395. * do not have any text to search.
  396. *
  397. * @param aSearchData A reference to a wxFindReplaceData object containing the
  398. * search criteria.
  399. * @param aAuxData A pointer to optional data required for the search or NULL
  400. * if not used.
  401. * @return True if the item's text matches the search criteria in \a aSearchData.
  402. */
  403. virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData )
  404. {
  405. return false;
  406. }
  407. /**
  408. * Helper function used in search and replace dialog
  409. * Function Replace
  410. * performs a text replace on \a aText using the find and replace criteria in
  411. * \a aSearchData on items that support text find and replace.
  412. *
  413. * @param aSearchData A reference to a wxFindReplaceData object containing the
  414. * search and replace criteria.
  415. * @param aText A reference to a wxString object containing the text to be
  416. * replaced.
  417. * @return True if \a aText was modified, otherwise false.
  418. */
  419. static bool Replace( wxFindReplaceData& aSearchData, wxString& aText );
  420. /**
  421. * Function Replace
  422. * performs a text replace using the find and replace criteria in \a aSearchData
  423. * on items that support text find and replace.
  424. *
  425. * This function must be overridden for items that support text replace.
  426. *
  427. * @param aSearchData A reference to a wxFindReplaceData object containing the
  428. * search and replace criteria.
  429. * @param aAuxData A pointer to optional data required for the search or NULL
  430. * if not used.
  431. * @return True if the item text was modified, otherwise false.
  432. */
  433. virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
  434. /**
  435. * Function IsReplaceable
  436. * <p>
  437. * Override this method in any derived object that supports test find and
  438. * replace.
  439. * </p>
  440. *
  441. * @return True if the item has replaceable text that can be modified using
  442. * the find and replace dialog.
  443. */
  444. virtual bool IsReplaceable() const { return false; }
  445. /**
  446. * Test if another item is less than this object.
  447. *
  448. * @param aItem - Item to compare against.
  449. * @return - True if \a aItem is less than the item.
  450. */
  451. bool operator<( const EDA_ITEM& aItem ) const;
  452. /**
  453. * Function Sort
  454. * is a helper function to be used by the C++ STL sort algorithm for sorting a STL
  455. * container of EDA_ITEM pointers.
  456. *
  457. * @param aLeft The left hand item to compare.
  458. * @param aRight The right hand item to compare.
  459. * @return True if \a aLeft is less than \a aRight.
  460. */
  461. static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
  462. /**
  463. * Operator assignment
  464. * is used to assign the members of \a aItem to another object.
  465. */
  466. EDA_ITEM& operator=( const EDA_ITEM& aItem );
  467. virtual const BOX2I ViewBBox() const override;
  468. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  469. #if defined(DEBUG)
  470. /**
  471. * Function Show
  472. * is used to output the object tree, currently for debugging only.
  473. * @param nestLevel An aid to prettier tree indenting, and is the level
  474. * of nesting of this object within the overall tree.
  475. * @param os The ostream& to output to.
  476. */
  477. virtual void Show( int nestLevel, std::ostream& os ) const = 0;
  478. // pure virtual so compiler warns if somebody mucks up a derived declaration
  479. void ShowDummy( std::ostream& os ) const; ///< call this if you are a lazy developer
  480. /**
  481. * Function NestedSpace
  482. * outputs nested space for pretty indenting.
  483. * @param nestLevel The nest count
  484. * @param os The ostream&, where to output
  485. * @return std::ostream& - for continuation.
  486. **/
  487. static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
  488. #endif
  489. protected:
  490. /**
  491. * Function Matches
  492. * compares \a aText against search criteria in \a aSearchData.
  493. * This is a helper function for simplify derived class logic.
  494. *
  495. * @param aText A reference to a wxString object containing the string to test.
  496. * @param aSearchData The criteria to search against.
  497. * @return True if \a aText matches the search criteria in \a aSearchData.
  498. */
  499. bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
  500. };
  501. /**
  502. * Function new_clone
  503. * provides cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
  504. *
  505. * @param aItem EDA_ITEM to clone.
  506. * @return Clone of \a aItem.
  507. */
  508. inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
  509. /**
  510. * Define list of drawing items for screens.
  511. *
  512. * The standard C++ container was chosen so the pointer can be removed from a list without
  513. * it being destroyed.
  514. */
  515. typedef std::vector< EDA_ITEM* > EDA_ITEMS;
  516. #endif // BASE_STRUCT_H_