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.

430 lines
15 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2011 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_track.h
  26. * @brief Definitions for tracks, vias and zones.
  27. */
  28. #ifndef CLASS_TRACK_H
  29. #define CLASS_TRACK_H
  30. #include <class_board_item.h>
  31. #include <class_board_connected_item.h>
  32. #include <PolyLine.h>
  33. #include <trigo.h>
  34. class TRACK;
  35. class D_PAD;
  36. class MSG_PANEL_ITEM;
  37. // Via attributes (m_Shape parameter)
  38. #define VIA_THROUGH 3 /* Always a through hole via */
  39. #define VIA_BLIND_BURIED 2 /* this via can be on internal layers */
  40. #define VIA_MICROVIA 1 /* this via which connect from an external layer
  41. * to the near neighbor internal layer */
  42. #define VIA_NOT_DEFINED 0 /* not yet used */
  43. #define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
  44. #define MIN_VIA_DRAW_SIZE 4 /// Minimum size in pixel for full drawing
  45. /**
  46. * Function GetTrace
  47. * is a helper function to locate a trace segment having an end point at \a aPosition
  48. * on \a aLayerMask starting at \a aStartTrace and end at \a aEndTrace.
  49. * <p>
  50. * The segments of track that are flagged as deleted or busy are ignored. Layer
  51. * visibility is also ignored.
  52. * </p>
  53. * @param aStartTrace A pointer to the TRACK object to begin searching.
  54. * @param aEndTrace A pointer to the TRACK object to stop the search. A NULL value
  55. * searches to the end of the list.
  56. * @param aPosition A wxPoint object containing the position to test.
  57. * @param aLayerMask A layer or layers to mask the hit test. Use -1 to ignore
  58. * layer mask.
  59. * @return A TRACK object pointer if found otherwise NULL.
  60. */
  61. extern TRACK* GetTrace( TRACK* aStartTrace, TRACK* aEndTrace, const wxPoint& aPosition,
  62. LAYER_MSK aLayerMask );
  63. class TRACK : public BOARD_CONNECTED_ITEM
  64. {
  65. // make SetNext() and SetBack() private so that they may not be called from anywhere.
  66. // list management is done on TRACKs using DLIST<TRACK> only.
  67. private:
  68. void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
  69. void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
  70. protected:
  71. int m_Width; // Thickness of track, or via diameter
  72. wxPoint m_Start; // Line start point
  73. wxPoint m_End; // Line end point
  74. int m_Shape; // vias: shape and type, Track = shape..
  75. int m_Drill; // for vias: via drill (- 1 for default value)
  76. public:
  77. BOARD_CONNECTED_ITEM* start; // pointers to a connected item (pad or track)
  78. BOARD_CONNECTED_ITEM* end;
  79. double m_Param; // Auxiliary variable ( used in some computations )
  80. TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
  81. // Do not create a copy constructor. The one generated by the compiler is adequate.
  82. TRACK* Next() const { return (TRACK*) Pnext; }
  83. TRACK* Back() const { return (TRACK*) Pback; }
  84. virtual void Move( const wxPoint& aMoveVector )
  85. {
  86. m_Start += aMoveVector;
  87. m_End += aMoveVector;
  88. }
  89. virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
  90. virtual void Flip( const wxPoint& aCentre );
  91. void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // was overload
  92. const wxPoint& GetPosition() const { return m_Start; } // was overload
  93. void SetWidth( int aWidth ) { m_Width = aWidth; }
  94. int GetWidth() const { return m_Width; }
  95. void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
  96. const wxPoint& GetEnd() const { return m_End; }
  97. void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
  98. const wxPoint& GetStart() const { return m_Start; }
  99. int GetShape() const { return m_Shape; }
  100. void SetShape( int aShape ) { m_Shape = aShape; }
  101. EDA_RECT GetBoundingBox() const;
  102. /**
  103. * Function GetBestInsertPoint
  104. * searches the "best" insertion point within the track linked list.
  105. * The best point is the begging of the corresponding net code section.
  106. * (The BOARD::m_Track and BOARD::m_Zone lists are sorted by netcode.)
  107. * @param aPcb The BOARD to search for the insertion point.
  108. * @return TRACK* - the item found in the linked list (or NULL if no track)
  109. */
  110. TRACK* GetBestInsertPoint( BOARD* aPcb );
  111. /* Search (within the track linked list) the first segment matching the netcode
  112. * ( the linked list is always sorted by net codes )
  113. */
  114. TRACK* GetStartNetCode( int NetCode );
  115. /* Search (within the track linked list) the last segment matching the netcode
  116. * ( the linked list is always sorted by net codes )
  117. */
  118. TRACK* GetEndNetCode( int NetCode );
  119. /**
  120. * Function GetLength
  121. * returns the length of the track using the hypotenuse calculation.
  122. * @return double - the length of the track
  123. */
  124. double GetLength() const
  125. {
  126. return GetLineLength( m_Start, m_End );
  127. }
  128. /* Display on screen: */
  129. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  130. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
  131. /**
  132. * Function TransformShapeWithClearanceToPolygon
  133. * Convert the track shape to a closed polygon
  134. * Used in filling zones calculations
  135. * Circles (vias) and arcs (ends of tracks) are approximated by segments
  136. * @param aCornerBuffer = a buffer to store the polygon
  137. * @param aClearanceValue = the clearance around the pad
  138. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  139. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  140. * clearance when the circle is approximated by segment bigger or equal
  141. * to the real clearance value (usually near from 1.0)
  142. */
  143. void TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
  144. int aClearanceValue,
  145. int aCircleToSegmentsCount,
  146. double aCorrectionFactor ) const;
  147. /**
  148. * Function SetDrill
  149. * sets the drill value for vias.
  150. * @param aDrill is the new drill diameter
  151. */
  152. void SetDrill( int aDrill ) { m_Drill = aDrill; }
  153. /**
  154. * Function GetDrill
  155. * returns the local drill setting for this VIA. If you want the calculated value,
  156. * use GetDrillValue() instead.
  157. */
  158. int GetDrill() const { return m_Drill; }
  159. /**
  160. * Function GetDrillValue
  161. * "calculates" the drill value for vias (m-Drill if > 0, or default
  162. * drill value for the board.
  163. * @return real drill_value
  164. */
  165. int GetDrillValue() const;
  166. /**
  167. * Function SetDrillDefault
  168. * sets the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER.
  169. */
  170. void SetDrillDefault() { m_Drill = UNDEFINED_DRILL_DIAMETER; }
  171. /**
  172. * Function IsDrillDefault
  173. * @return true if the drill value is default value (-1)
  174. */
  175. bool IsDrillDefault() { return m_Drill <= 0; }
  176. /**
  177. * Function GetLayerMask
  178. * returns a "layer mask", which is a bitmap of all layers on which the
  179. * TRACK segment or SEGVIA physically resides.
  180. * @return int - a layer mask, see pcbstruct.h's LAYER_BACK, etc.
  181. */
  182. LAYER_MSK GetLayerMask() const;
  183. /**
  184. * Function IsPointOnEnds
  185. * returns STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if
  186. * point if near (dist = min_dist) end point,STARTPOINT|ENDPOINT if point if near
  187. * (dist = min_dist) both ends, or 0 if none of the above.
  188. * if min_dist < 0: min_dist = track_width/2
  189. */
  190. STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
  191. /**
  192. * Function IsNull
  193. * returns true if segment length is zero.
  194. */
  195. bool IsNull();
  196. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  197. /**
  198. * Function GetMsgPanelInfoBase
  199. * Display info about the track segment only, and does not calculate the full track length
  200. * @param aList A list of #MSG_PANEL_ITEM objects to add status information.
  201. */
  202. void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
  203. /**
  204. * Function ShowWidth
  205. * returns the width of the track in displayable user units.
  206. */
  207. wxString ShowWidth() const;
  208. SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
  209. const KICAD_T scanTypes[] );
  210. virtual bool HitTest( const wxPoint& aPosition );
  211. virtual bool HitTest( const EDA_RECT& aRect ) const;
  212. /**
  213. * Function GetVia
  214. * finds the first SEGVIA object at \a aPosition on \a aLayer starting at the trace.
  215. *
  216. * @param aPosition The wxPoint to HitTest() against.
  217. * @param aLayer The layer to match, pass -1 for a don't care.
  218. * @return A pointer to a SEGVIA object if found, else NULL.
  219. */
  220. TRACK* GetVia( const wxPoint& aPosition, LAYER_NUM aLayer = UNDEFINED_LAYER );
  221. /**
  222. * Function GetVia
  223. * finds the first SEGVIA object at \a aPosition on \a aLayer starting at the trace
  224. * and ending at \a aEndTrace.
  225. *
  226. * @param aEndTrace Pointer to the last TRACK object to end search.
  227. * @param aPosition The wxPoint to HitTest() against.
  228. * @param aLayerMask The layers to match, pass -1 for a don't care.
  229. * @return A pointer to a SEGVIA object if found, else NULL.
  230. */
  231. TRACK* GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LAYER_MSK aLayerMask );
  232. /**
  233. * Function GetTrace
  234. * return the trace segment connected to the segment at \a aEndPoint from \a
  235. * aStartTrace to \a aEndTrace.
  236. *
  237. * @param aStartTrace A pointer to the TRACK object to begin searching.
  238. * @param aEndTrace A pointer to the TRACK object to stop the search. A NULL value
  239. * searches to the end of the list.
  240. * @param aEndPoint The start or end point of the segment to test against.
  241. * @return A TRACK object pointer if found otherwise NULL.
  242. */
  243. TRACK* GetTrace( TRACK* aStartTrace, TRACK* aEndTrace, int aEndPoint );
  244. /**
  245. * Function GetEndSegments
  246. * get the segments connected to the end point of the track.
  247. * return 1 if OK, 0 when a track is a closed loop
  248. * and the beginning and the end of the track in *StartTrack and *EndTrack
  249. * Modify *StartTrack en *EndTrack :
  250. * (*StartTrack)->m_Start coordinate is the beginning of the track
  251. * (*EndTrack)->m_End coordinate is the end of the track
  252. * Segments connected must be consecutive in list
  253. */
  254. int GetEndSegments( int NbSegm, TRACK** StartTrack, TRACK** EndTrack );
  255. wxString GetClass() const
  256. {
  257. return wxT( "TRACK" );
  258. }
  259. /**
  260. * Function GetClearance
  261. * returns the clearance in internal units. If \a aItem is not NULL then the
  262. * returned clearance is the greater of this object's clearance and
  263. * aItem's clearance. If \a aItem is NULL, then this objects clearance
  264. * is returned.
  265. * @param aItem is another BOARD_CONNECTED_ITEM or NULL
  266. * @return int - the clearance in internal units.
  267. */
  268. virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
  269. virtual wxString GetSelectMenuText() const;
  270. virtual BITMAP_DEF GetMenuImage() const { return showtrack_xpm; }
  271. virtual EDA_ITEM* Clone() const;
  272. /// @copydoc VIEW_ITEM::ViewGetLayers()
  273. virtual void ViewGetLayers( int aLayers[], int& aCount ) const;
  274. /// @copydoc VIEW_ITEM::ViewGetLOD()
  275. virtual unsigned int ViewGetLOD( int aLayer ) const;
  276. #if defined (DEBUG)
  277. virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
  278. /**
  279. * Function ShowState
  280. * converts a set of state bits to a wxString
  281. * @param stateBits Is an OR-ed together set of bits like BUSY, EDIT, etc.
  282. */
  283. static wxString ShowState( int stateBits );
  284. #endif
  285. };
  286. class SEGZONE : public TRACK
  287. {
  288. public:
  289. SEGZONE( BOARD_ITEM* aParent );
  290. // Do not create a copy constructor. The one generated by the compiler is adequate.
  291. wxString GetClass() const
  292. {
  293. return wxT( "ZONE" );
  294. }
  295. SEGZONE* Next() const { return (SEGZONE*) Pnext; }
  296. wxString GetSelectMenuText() const;
  297. BITMAP_DEF GetMenuImage() const { return add_zone_xpm; }
  298. EDA_ITEM* Clone() const;
  299. };
  300. class SEGVIA : public TRACK
  301. {
  302. public:
  303. SEGVIA( BOARD_ITEM* aParent );
  304. // Do not create a copy constructor. The one generated by the compiler is adequate.
  305. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  306. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
  307. bool IsOnLayer( LAYER_NUM aLayer ) const;
  308. /**
  309. * Function SetLayerPair
  310. * set the .m_Layer member param:
  311. * For a via m_Layer contains the 2 layers :
  312. * top layer and bottom layer used by the via.
  313. * The via connect all layers from top layer to bottom layer
  314. * 4 bits for the first layer and 4 next bits for the second layer
  315. * @param top_layer = first layer connected by the via
  316. * @param bottom_layer = last layer connected by the via
  317. */
  318. void SetLayerPair( LAYER_NUM top_layer, LAYER_NUM bottom_layer );
  319. /**
  320. * Function ReturnLayerPair
  321. * Return the 2 layers used by the via (the via actually uses
  322. * all layers between these 2 layers)
  323. * @param top_layer = pointer to the first layer (can be null)
  324. * @param bottom_layer = pointer to the last layer (can be null)
  325. */
  326. void ReturnLayerPair( LAYER_NUM* top_layer, LAYER_NUM* bottom_layer ) const;
  327. const wxPoint& GetPosition() const { return m_Start; } // was overload
  328. void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload
  329. wxString GetClass() const
  330. {
  331. return wxT( "VIA" );
  332. }
  333. wxString GetSelectMenuText() const;
  334. BITMAP_DEF GetMenuImage() const { return via_sketch_xpm; }
  335. EDA_ITEM* Clone() const;
  336. /// @copydoc VIEW_ITEM::ViewGetLayers()
  337. virtual void ViewGetLayers( int aLayers[], int& aCount ) const;
  338. #if defined (DEBUG)
  339. virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
  340. #endif
  341. };
  342. #endif /* CLASS_TRACK_H */