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.

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