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.

497 lines
17 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
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 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 <pcbnew.h>
  31. #include <class_board_item.h>
  32. #include <class_board_connected_item.h>
  33. #include <PolyLine.h>
  34. #include <trigo.h>
  35. class TRACK;
  36. class VIA;
  37. class D_PAD;
  38. class MSG_PANEL_ITEM;
  39. // Via types
  40. enum VIATYPE_T
  41. {
  42. VIA_THROUGH = 3, /* Always a through hole via */
  43. VIA_BLIND_BURIED = 2, /* this via can be on internal layers */
  44. VIA_MICROVIA = 1, /* this via which connect from an external layer
  45. * to the near neighbor internal layer */
  46. VIA_NOT_DEFINED = 0 /* not yet used */
  47. };
  48. #define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
  49. #define MIN_VIA_DRAW_SIZE 4 /// Minimum size in pixel for full drawing
  50. /**
  51. * Function GetTrack
  52. * is a helper function to locate a trace segment having an end point at \a aPosition
  53. * on \a aLayerMask starting at \a aStartTrace and end at \a aEndTrace.
  54. * <p>
  55. * The segments of track that are flagged as deleted or busy are ignored. Layer
  56. * visibility is also ignored.
  57. * </p>
  58. * @param aStartTrace A pointer to the TRACK object to begin searching.
  59. * @param aEndTrace A pointer to the TRACK object to stop the search. A NULL value
  60. * searches to the end of the list.
  61. * @param aPosition A wxPoint object containing the position to test.
  62. * @param aLayerMask A layer or layers to mask the hit test. Use -1 to ignore
  63. * layer mask.
  64. * @return A TRACK object pointer if found otherwise NULL.
  65. */
  66. TRACK* GetTrack( TRACK* aStartTrace, const TRACK* aEndTrace,
  67. const wxPoint& aPosition, LSET aLayerMask );
  68. class TRACK : public BOARD_CONNECTED_ITEM
  69. {
  70. public:
  71. static inline bool ClassOf( const EDA_ITEM* aItem )
  72. {
  73. return aItem && PCB_TRACE_T == aItem->Type();
  74. }
  75. BOARD_CONNECTED_ITEM* start; // pointers to a connected item (pad or track)
  76. BOARD_CONNECTED_ITEM* end;
  77. double m_Param; // Auxiliary variable ( used in some computations )
  78. TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
  79. // Do not create a copy constructor. The one generated by the compiler is adequate.
  80. TRACK* Next() const { return static_cast<TRACK*>( Pnext ); }
  81. TRACK* Back() const { return static_cast<TRACK*>( Pback ); }
  82. virtual void Move( const wxPoint& aMoveVector )
  83. {
  84. m_Start += aMoveVector;
  85. m_End += aMoveVector;
  86. }
  87. virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
  88. virtual void Flip( const wxPoint& aCentre );
  89. void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // was overload
  90. const wxPoint& GetPosition() const { return m_Start; } // was overload
  91. void SetWidth( int aWidth ) { m_Width = aWidth; }
  92. int GetWidth() const { return m_Width; }
  93. void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
  94. const wxPoint& GetEnd() const { return m_End; }
  95. void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
  96. const wxPoint& GetStart() const { return m_Start; }
  97. /// Return the selected endpoint (start or end)
  98. const wxPoint& GetEndPoint( ENDPOINT_T aEndPoint ) const
  99. {
  100. if( aEndPoint == ENDPOINT_START )
  101. return m_Start;
  102. else
  103. return m_End;
  104. }
  105. // Virtual function
  106. const EDA_RECT GetBoundingBox() const;
  107. /**
  108. * Function GetBestInsertPoint
  109. * searches the "best" insertion point within the track linked list.
  110. * The best point is the begging of the corresponding net code section.
  111. * (The BOARD::m_Track and BOARD::m_Zone lists are sorted by netcode.)
  112. * @param aPcb The BOARD to search for the insertion point.
  113. * @return TRACK* - the item found in the linked list (or NULL if no track)
  114. */
  115. TRACK* GetBestInsertPoint( BOARD* aPcb );
  116. /* Search (within the track linked list) the first segment matching the netcode
  117. * ( the linked list is always sorted by net codes )
  118. */
  119. TRACK* GetStartNetCode( int NetCode );
  120. /* Search (within the track linked list) the last segment matching the netcode
  121. * ( the linked list is always sorted by net codes )
  122. */
  123. TRACK* GetEndNetCode( int NetCode );
  124. /**
  125. * Function GetLength
  126. * returns the length of the track using the hypotenuse calculation.
  127. * @return double - the length of the track
  128. */
  129. double GetLength() const
  130. {
  131. return GetLineLength( m_Start, m_End );
  132. }
  133. /* Display on screen: */
  134. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  135. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
  136. /**
  137. * Function TransformShapeWithClearanceToPolygon
  138. * Convert the track shape to a closed polygon
  139. * Used in filling zones calculations
  140. * Circles (vias) and arcs (ends of tracks) are approximated by segments
  141. * @param aCornerBuffer = a buffer to store the polygon
  142. * @param aClearanceValue = the clearance around the pad
  143. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  144. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  145. * clearance when the circle is approximated by segment bigger or equal
  146. * to the real clearance value (usually near from 1.0)
  147. */
  148. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  149. int aClearanceValue,
  150. int aCircleToSegmentsCount,
  151. double aCorrectionFactor ) const;
  152. /**
  153. * Function IsPointOnEnds
  154. * returns STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if
  155. * point if near (dist = min_dist) end point,STARTPOINT|ENDPOINT if point if near
  156. * (dist = min_dist) both ends, or 0 if none of the above.
  157. * if min_dist < 0: min_dist = track_width/2
  158. */
  159. STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
  160. /**
  161. * Function IsNull
  162. * returns true if segment length is zero.
  163. */
  164. bool IsNull();
  165. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  166. /**
  167. * Function ShowWidth
  168. * returns the width of the track in displayable user units.
  169. */
  170. wxString ShowWidth() const;
  171. SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
  172. const KICAD_T scanTypes[] );
  173. virtual bool HitTest( const wxPoint& aPosition ) const;
  174. /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
  175. * bool aContained = true, int aAccuracy ) const
  176. */
  177. virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
  178. /**
  179. * Function GetVia
  180. * finds the first VIA object at \a aPosition on \a aLayer starting at the trace.
  181. *
  182. * @param aPosition The wxPoint to HitTest() against.
  183. * @param aLayer The layer to match, pass -1 for a don't care.
  184. * @return A pointer to a VIA object if found, else NULL.
  185. */
  186. VIA* GetVia( const wxPoint& aPosition, LAYER_ID aLayer = UNDEFINED_LAYER );
  187. /**
  188. * Function GetVia
  189. * finds the first VIA object at \a aPosition on \a aLayer starting at the trace
  190. * and ending at \a aEndTrace.
  191. *
  192. * @param aEndTrace Pointer to the last TRACK object to end search.
  193. * @param aPosition The wxPoint to HitTest() against.
  194. * @param aLayerMask The layers to match, pass -1 for a don't care.
  195. * @return A pointer to a VIA object if found, else NULL.
  196. */
  197. VIA* GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LSET aLayerMask );
  198. /**
  199. * Function GetTrack
  200. * return the trace segment connected to the segment at \a aEndPoint from \a
  201. * aStartTrace to \a aEndTrace.
  202. *
  203. * @param aStartTrace A pointer to the TRACK object to begin searching.
  204. * @param aEndTrace A pointer to the TRACK object to stop the search. A NULL value
  205. * searches to the end of the list.
  206. * @param aEndPoint The start or end point of the segment to test against.
  207. * @param aSameNetOnly if true stop searching when the netcode changes
  208. * @param aSequential If true, forces a forward sequential search,
  209. * which is restartable; the default search can be faster but the
  210. * position of the returned track in the list is unpredictable
  211. * @return A TRACK object pointer if found otherwise NULL.
  212. */
  213. TRACK* GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, ENDPOINT_T aEndPoint,
  214. bool aSameNetOnly, bool aSequential );
  215. /**
  216. * Function GetEndSegments
  217. * get the segments connected to the end point of the track.
  218. * return 1 if OK, 0 when a track is a closed loop
  219. * and the beginning and the end of the track in *StartTrack and *EndTrack
  220. * Modify *StartTrack en *EndTrack :
  221. * (*StartTrack)->m_Start coordinate is the beginning of the track
  222. * (*EndTrack)->m_End coordinate is the end of the track
  223. * Segments connected must be consecutive in list
  224. */
  225. int GetEndSegments( int NbSegm, TRACK** StartTrack, TRACK** EndTrack );
  226. wxString GetClass() const
  227. {
  228. return wxT( "TRACK" );
  229. }
  230. /**
  231. * Function GetClearance
  232. * returns the clearance in internal units. If \a aItem is not NULL then the
  233. * returned clearance is the greater of this object's clearance and
  234. * aItem's clearance. If \a aItem is NULL, then this objects clearance
  235. * is returned.
  236. * @param aItem is another BOARD_CONNECTED_ITEM or NULL
  237. * @return int - the clearance in internal units.
  238. */
  239. virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
  240. virtual wxString GetSelectMenuText() const;
  241. virtual BITMAP_DEF GetMenuImage() const { return showtrack_xpm; }
  242. virtual EDA_ITEM* Clone() const;
  243. /// @copydoc VIEW_ITEM::ViewGetLayers()
  244. virtual void ViewGetLayers( int aLayers[], int& aCount ) const;
  245. /// @copydoc VIEW_ITEM::ViewGetLOD()
  246. virtual unsigned int ViewGetLOD( int aLayer ) const;
  247. #if defined (DEBUG)
  248. virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
  249. /**
  250. * Function ShowState
  251. * converts a set of state bits to a wxString
  252. * @param stateBits Is an OR-ed together set of bits like BUSY, EDIT, etc.
  253. */
  254. static wxString ShowState( int stateBits );
  255. #endif
  256. protected:
  257. /**
  258. * Function GetMsgPanelInfoBase
  259. * Display info about the track segment only, and does not calculate the full track length
  260. * @param aList A list of #MSG_PANEL_ITEM objects to add status information.
  261. */
  262. virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
  263. /**
  264. * Helper function for the common panel info */
  265. void GetMsgPanelInfoBase_Common( std::vector< MSG_PANEL_ITEM >& aList );
  266. /**
  267. * Helper for drawing the short netname in tracks */
  268. void DrawShortNetname( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
  269. EDA_COLOR_T aBgColor );
  270. int m_Width; ///< Thickness of track, or via diameter
  271. wxPoint m_Start; ///< Line start point
  272. wxPoint m_End; ///< Line end point
  273. private:
  274. // make SetNext() and SetBack() private so that they may not be called from anywhere.
  275. // list management is done on TRACKs using DLIST<TRACK> only.
  276. void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
  277. void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
  278. };
  279. class SEGZONE : public TRACK
  280. {
  281. public:
  282. SEGZONE( BOARD_ITEM* aParent );
  283. // Do not create a copy constructor. The one generated by the compiler is adequate.
  284. wxString GetClass() const
  285. {
  286. return wxT( "ZONE" );
  287. }
  288. SEGZONE* Next() const { return static_cast<SEGZONE*>( Pnext ); }
  289. wxString GetSelectMenuText() const;
  290. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  291. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
  292. BITMAP_DEF GetMenuImage() const { return add_zone_xpm; }
  293. EDA_ITEM* Clone() const;
  294. protected:
  295. virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
  296. };
  297. class VIA : public TRACK
  298. {
  299. public:
  300. VIA( BOARD_ITEM* aParent );
  301. static inline bool ClassOf( const EDA_ITEM *aItem )
  302. {
  303. return aItem && PCB_VIA_T == aItem->Type();
  304. }
  305. // Do not create a copy constructor. The one generated by the compiler is adequate.
  306. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  307. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
  308. bool IsOnLayer( LAYER_ID aLayer ) const;
  309. virtual LSET GetLayerSet() const;
  310. /**
  311. * Function SetLayerPair
  312. * For a via m_Layer contains the top layer, the other layer is in
  313. * m_BottomLayer
  314. * @param aTopLayer = first layer connected by the via
  315. * @param aBottomLayer = last layer connected by the via
  316. */
  317. void SetLayerPair( LAYER_ID aTopLayer, LAYER_ID aBottomLayer );
  318. /**
  319. * Function LayerPair
  320. * Return the 2 layers used by the via (the via actually uses
  321. * all layers between these 2 layers)
  322. * @param top_layer = pointer to the first layer (can be null)
  323. * @param bottom_layer = pointer to the last layer (can be null)
  324. */
  325. void LayerPair( LAYER_ID* top_layer, LAYER_ID* bottom_layer ) const;
  326. const wxPoint& GetPosition() const { return m_Start; } // was overload
  327. void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload
  328. virtual bool HitTest( const wxPoint& aPosition ) const;
  329. virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
  330. wxString GetClass() const
  331. {
  332. return wxT( "VIA" );
  333. }
  334. wxString GetSelectMenuText() const;
  335. BITMAP_DEF GetMenuImage() const { return via_sketch_xpm; }
  336. EDA_ITEM* Clone() const;
  337. /// @copydoc VIEW_ITEM::ViewGetLayers()
  338. virtual void ViewGetLayers( int aLayers[], int& aCount ) const;
  339. virtual void Flip( const wxPoint& aCentre );
  340. #if defined (DEBUG)
  341. virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
  342. #endif
  343. VIATYPE_T GetViaType() const { return m_ViaType; }
  344. void SetViaType( VIATYPE_T aViaType ) { m_ViaType = aViaType; }
  345. /**
  346. * Function SetDrill
  347. * sets the drill value for vias.
  348. * @param aDrill is the new drill diameter
  349. */
  350. void SetDrill( int aDrill ) { m_Drill = aDrill; }
  351. /**
  352. * Function GetDrill
  353. * returns the local drill setting for this VIA. If you want the calculated value,
  354. * use GetDrillValue() instead.
  355. */
  356. int GetDrill() const { return m_Drill; }
  357. /**
  358. * Function GetDrillValue
  359. * "calculates" the drill value for vias (m-Drill if > 0, or default
  360. * drill value for the board.
  361. * @return real drill_value
  362. */
  363. int GetDrillValue() const;
  364. /**
  365. * Function SetDrillDefault
  366. * sets the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER.
  367. */
  368. void SetDrillDefault() { m_Drill = UNDEFINED_DRILL_DIAMETER; }
  369. /**
  370. * Function IsDrillDefault
  371. * @return true if the drill value is default value (-1)
  372. */
  373. bool IsDrillDefault() const { return m_Drill <= 0; }
  374. protected:
  375. virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
  376. private:
  377. /// The bottom layer of the via (the top layer is in m_Layer)
  378. LAYER_ID m_BottomLayer;
  379. VIATYPE_T m_ViaType; // Type of via
  380. int m_Drill; // for vias: via drill (- 1 for default value)
  381. };
  382. /// Scan a track list for the first VIA o NULL if not found (or NULL passed)
  383. inline VIA* GetFirstVia( TRACK* aTrk, const TRACK* aStopPoint = NULL )
  384. {
  385. while( aTrk && (aTrk != aStopPoint) && (aTrk->Type() != PCB_VIA_T) )
  386. aTrk = aTrk->Next();
  387. // It could stop because of the stop point, not on a via
  388. if( aTrk && (aTrk->Type() == PCB_VIA_T) )
  389. return static_cast<VIA*>( aTrk );
  390. else
  391. return NULL;
  392. }
  393. #endif // CLASS_TRACK_H