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.

346 lines
11 KiB

14 years ago
14 years ago
14 years ago
14 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) 2018 Jean-Pierre Charras, jp.charras at wandadoo.fr
  5. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file class_board_item.h
  26. * @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
  27. */
  28. #ifndef BOARD_ITEM_STRUCT_H
  29. #define BOARD_ITEM_STRUCT_H
  30. #include <base_struct.h>
  31. #include <gr_basic.h>
  32. #include <layers_id_colors_and_visibility.h>
  33. class BOARD;
  34. class BOARD_ITEM_CONTAINER;
  35. class EDA_DRAW_PANEL;
  36. class SHAPE_POLY_SET;
  37. /**
  38. * Enum STROKE_T
  39. * is the set of shapes for segments (graphic segments and tracks) which are often
  40. * in the .m_Shape member
  41. */
  42. enum STROKE_T
  43. {
  44. S_SEGMENT = 0, ///< usual segment : line with rounded ends
  45. S_RECT, ///< segment with non rounded ends
  46. S_ARC, ///< Arcs (with rounded ends)
  47. S_CIRCLE, ///< ring
  48. S_POLYGON, ///< polygon (not yet used for tracks, but could be in microwave apps)
  49. S_CURVE, ///< Bezier Curve
  50. S_LAST ///< last value for this list
  51. };
  52. /**
  53. * Class BOARD_ITEM
  54. * is a base class for any item which can be embedded within the BOARD
  55. * container class, and therefore instances of derived classes should only be
  56. * found in Pcbnew or other programs that use class BOARD and its contents.
  57. * The corresponding class in Eeschema is SCH_ITEM.
  58. */
  59. class BOARD_ITEM : public EDA_ITEM
  60. {
  61. protected:
  62. PCB_LAYER_ID m_Layer;
  63. static int getTrailingInt( const wxString& aStr );
  64. static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
  65. public:
  66. BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
  67. EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
  68. {
  69. }
  70. // Do not create a copy constructor & operator=.
  71. // The ones generated by the compiler are adequate.
  72. virtual const wxPoint GetPosition() const = 0;
  73. /**
  74. * Function GetCenter()
  75. *
  76. * This defaults to the same point as returned by GetPosition(), unless
  77. * overridden
  78. *
  79. * @return centre point of the item
  80. */
  81. virtual const wxPoint GetCenter() const { return GetPosition(); }
  82. virtual void SetPosition( const wxPoint& aPos ) = 0;
  83. /**
  84. * Function IsConnected()
  85. * Returns information if the object is derived from BOARD_CONNECTED_ITEM.
  86. * @return True if the object is of BOARD_CONNECTED_ITEM type, false otherwise.
  87. */
  88. virtual bool IsConnected() const
  89. {
  90. return false;
  91. }
  92. /**
  93. * A value of wxPoint(0,0) which can be passed to the Draw() functions.
  94. */
  95. static wxPoint ZeroOffset;
  96. BOARD_ITEM* Next() const { return static_cast<BOARD_ITEM*>( Pnext ); }
  97. BOARD_ITEM* Back() const { return static_cast<BOARD_ITEM*>( Pback ); }
  98. BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_Parent; }
  99. /**
  100. * Function GetLayer
  101. * returns the primary layer this item is on.
  102. */
  103. virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
  104. /**
  105. * Function GetLayerSet
  106. * returns a "layer mask", which is a bitmap of all layers on which the
  107. * TRACK segment or VIA physically resides.
  108. * @return int - a layer mask, see layers_id_colors_visibility.h.
  109. */
  110. virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
  111. /**
  112. * Function SetLayer
  113. * sets the layer this item is on.
  114. * @param aLayer The layer number.
  115. * is virtual because some items (in fact: class DIMENSION)
  116. * have a slightly different initialization
  117. */
  118. virtual void SetLayer( PCB_LAYER_ID aLayer )
  119. {
  120. // trap any invalid layers, then go find the caller and fix it.
  121. // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
  122. m_Layer = aLayer;
  123. }
  124. /**
  125. * Function Draw
  126. * BOARD_ITEMs have their own color information.
  127. */
  128. virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  129. GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;
  130. /**
  131. * Swap data between aItem and aImage.
  132. * aItem and aImage should have the same type
  133. * Used in undo redo command to swap values between an item and its copy
  134. * Only values like layer, size .. which are modified by edition are swapped,
  135. * not the pointers like
  136. * Pnext and Pback because aItem is not changed in the linked list
  137. * @param aImage = the item image which contains data to swap
  138. */
  139. virtual void SwapData( BOARD_ITEM* aImage );
  140. /**
  141. * Function IsOnLayer
  142. * tests to see if this object is on the given layer. Is virtual so
  143. * objects like D_PAD, which reside on multiple layers can do their own
  144. * form of testing.
  145. * @param aLayer The layer to test for.
  146. * @return bool - true if on given layer, else false.
  147. */
  148. virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
  149. {
  150. return m_Layer == aLayer;
  151. }
  152. /**
  153. * Function IsTrack
  154. * tests to see if this object is a track or via (or microvia).
  155. * form of testing.
  156. * @return bool - true if a track or via, else false.
  157. */
  158. bool IsTrack() const
  159. {
  160. return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
  161. }
  162. /**
  163. * Function IsLocked
  164. * @return bool - true if the object is locked, else false
  165. */
  166. virtual bool IsLocked() const
  167. {
  168. // only MODULEs & TRACKs can be locked at this time.
  169. return false;
  170. }
  171. /**
  172. * Function SetLocked
  173. * modifies 'lock' status for of the item.
  174. */
  175. virtual void SetLocked( bool aLocked )
  176. {
  177. // only MODULEs & TRACKs can be locked at this time.
  178. }
  179. /**
  180. * Function UnLink
  181. * detaches this object from its owner. This base class implementation
  182. * should work for all derived classes which are held in a DLIST<>.
  183. */
  184. virtual void UnLink();
  185. /**
  186. * Function DeleteStructure
  187. * deletes this object after UnLink()ing it from its owner if it has one.
  188. */
  189. void DeleteStructure();
  190. /**
  191. * Function ShowShape
  192. * converts the enum STROKE_T integer value to a wxString.
  193. */
  194. static wxString ShowShape( STROKE_T aShape );
  195. // Some geometric transforms, that must be rewritten for derived classes
  196. /**
  197. * Function Move
  198. * move this object.
  199. * @param aMoveVector - the move vector for this object.
  200. */
  201. virtual void Move( const wxPoint& aMoveVector )
  202. {
  203. wxMessageBox( wxT( "virtual BOARD_ITEM::Move used, should not occur" ), GetClass() );
  204. }
  205. void Move( const VECTOR2I& aMoveVector )
  206. {
  207. Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
  208. }
  209. /**
  210. * Function Rotate
  211. * Rotate this object.
  212. * @param aRotCentre - the rotation point.
  213. * @param aAngle - the rotation angle in 0.1 degree.
  214. */
  215. virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
  216. {
  217. wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
  218. }
  219. void Rotate( const VECTOR2I& aRotCentre, double aAngle )
  220. {
  221. Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
  222. }
  223. /**
  224. * Function Flip
  225. * Flip this object, i.e. change the board side for this object
  226. * @param aCentre - the rotation point.
  227. */
  228. virtual void Flip( const wxPoint& aCentre )
  229. {
  230. wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
  231. }
  232. void Flip( const VECTOR2I& aCentre )
  233. {
  234. Flip( wxPoint( aCentre.x, aCentre.y ) );
  235. }
  236. /**
  237. * Function GetBoard
  238. * returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
  239. */
  240. virtual BOARD* GetBoard() const;
  241. /**
  242. * Function GetLayerName
  243. * returns the name of the PCB layer on which the item resides.
  244. *
  245. * @return wxString containing the layer name associated with this item.
  246. */
  247. wxString GetLayerName() const;
  248. virtual bool HitTest( const wxPoint& aPosition ) const override
  249. {
  250. return EDA_ITEM::HitTest( aPosition );
  251. }
  252. /**
  253. * Function HitTest
  254. * tests if the \a aRect intersects or contains this object (depending on \a aContained).
  255. *
  256. * @param aRect A reference to an EDA_RECT object containg the area to test.
  257. * @param aContained Test if \a aRect contains this object completly.
  258. * @param aAccuracy Increase the item bounding box by this amount.
  259. * @return bool - True if \a aRect contains this object completly or if \a aRect intersects
  260. * the object and \a aContained is False, otherwise false.
  261. */
  262. virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0) const
  263. {
  264. return false; // derived classes should override this function
  265. }
  266. /**
  267. * Function FormatInternalUnits
  268. * converts \a aValue from board internal units to a string appropriate for writing to file.
  269. *
  270. * @note Internal units for board items can be either deci-mils or nanometers depending
  271. * on how KiCad is build.
  272. * @param aValue A coordinate value to convert.
  273. * @return A std::string object containing the converted value.
  274. */
  275. static std::string FormatInternalUnits( int aValue );
  276. /**
  277. * Function FormatAngle
  278. * converts \a aAngle from board units to a string appropriate for writing to file.
  279. *
  280. * @note Internal angles for board items can be either degrees or tenths of degree
  281. * on how KiCad is built.
  282. * @param aAngle A angle value to convert.
  283. * @return A std::string object containing the converted angle.
  284. */
  285. static std::string FormatAngle( double aAngle );
  286. static std::string FormatInternalUnits( const wxPoint& aPoint );
  287. static std::string FormatInternalUnits( const VECTOR2I& aPoint );
  288. static std::string FormatInternalUnits( const wxSize& aSize );
  289. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  290. virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  291. int aClearanceValue,
  292. int aCircleToSegmentsCount,
  293. double aCorrectionFactor ) const;
  294. };
  295. #endif /* BOARD_ITEM_STRUCT_H */