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.

475 lines
14 KiB

8 years ago
14 years ago
14 years ago
14 years ago
14 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
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-2020 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 <board_connected_item.h>
  31. #include <class_board_item.h>
  32. #include <convert_to_biu.h>
  33. #include <pcb_display_options.h>
  34. #include <pcbnew.h>
  35. #include <geometry/seg.h>
  36. #include <geometry/shape_arc.h>
  37. #include <trigo.h>
  38. class TRACK;
  39. class VIA;
  40. class D_PAD;
  41. class MSG_PANEL_ITEM;
  42. class SHAPE_POLY_SET;
  43. // Flag used in locate routines (from which endpoint work)
  44. enum ENDPOINT_T : int
  45. {
  46. ENDPOINT_START = 0,
  47. ENDPOINT_END = 1
  48. };
  49. // Via types
  50. // Note that this enum must be synchronized to GAL_LAYER_ID
  51. enum class VIATYPE : int
  52. {
  53. THROUGH = 3, /* Always a through hole via */
  54. BLIND_BURIED = 2, /* this via can be on internal layers */
  55. MICROVIA = 1, /* this via which connect from an external layer
  56. * to the near neighbor internal layer */
  57. NOT_DEFINED = 0 /* not yet used */
  58. };
  59. #define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
  60. #define MIN_VIA_DRAW_SIZE 4 /// Minimum size in pixel for full drawing
  61. // Used for tracks and vias for algorithmic safety, not to enforce constraints
  62. #define GEOMETRY_MIN_SIZE ( int )( 0.001 * IU_PER_MM )
  63. class TRACK : public BOARD_CONNECTED_ITEM
  64. {
  65. public:
  66. static inline bool ClassOf( const EDA_ITEM* aItem )
  67. {
  68. return aItem && PCB_TRACE_T == aItem->Type();
  69. }
  70. TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
  71. // Do not create a copy constructor. The one generated by the compiler is adequate.
  72. void Move( const wxPoint& aMoveVector ) override
  73. {
  74. m_Start += aMoveVector;
  75. m_End += aMoveVector;
  76. }
  77. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  78. void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
  79. void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; }
  80. const wxPoint GetPosition() const override { return m_Start; }
  81. void SetWidth( int aWidth ) { m_Width = aWidth; }
  82. int GetWidth() const { return m_Width; }
  83. void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
  84. const wxPoint& GetEnd() const { return m_End; }
  85. void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
  86. const wxPoint& GetStart() const { return m_Start; }
  87. /// Return the selected endpoint (start or end)
  88. const wxPoint& GetEndPoint( ENDPOINT_T aEndPoint ) const
  89. {
  90. if( aEndPoint == ENDPOINT_START )
  91. return m_Start;
  92. else
  93. return m_End;
  94. }
  95. // Virtual function
  96. const EDA_RECT GetBoundingBox() const override;
  97. bool IsLocked() const override
  98. {
  99. return GetState( TRACK_LOCKED );
  100. }
  101. void SetLocked( bool aLocked ) override
  102. {
  103. return SetState( TRACK_LOCKED, aLocked );
  104. }
  105. /**
  106. * Function GetLength
  107. * returns the length of the track using the hypotenuse calculation.
  108. * @return double - the length of the track
  109. */
  110. virtual double GetLength() const
  111. {
  112. return GetLineLength( m_Start, m_End );
  113. }
  114. void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset ) override;
  115. /**
  116. * Function TransformShapeWithClearanceToPolygon
  117. * Convert the track shape to a closed polygon
  118. * Used in filling zones calculations
  119. * Circles (vias) and arcs (ends of tracks) are approximated by segments
  120. * @param aCornerBuffer = a buffer to store the polygon
  121. * @param aClearanceValue = the clearance around the pad
  122. * @param aError = the maximum deviation from true circle
  123. * @param ignoreLineWidth = used for edge cut items where the line width is only
  124. * for visualization
  125. */
  126. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
  127. int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
  128. /**
  129. * Function IsPointOnEnds
  130. * returns STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if
  131. * point if near (dist = min_dist) end point,STARTPOINT|ENDPOINT if point if near
  132. * (dist = min_dist) both ends, or 0 if none of the above.
  133. * if min_dist < 0: min_dist = track_width/2
  134. */
  135. STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 ) const;
  136. /**
  137. * Function IsNull
  138. * returns true if segment length is zero.
  139. */
  140. bool IsNull() const
  141. {
  142. return ( Type() == PCB_VIA_T ) || ( m_Start == m_End );
  143. }
  144. void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
  145. SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
  146. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  147. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  148. bool ApproxCollinear( const TRACK& aTrack )
  149. {
  150. SEG a( m_Start, m_End );
  151. SEG b( aTrack.GetStart(), aTrack.GetEnd() );
  152. return a.ApproxCollinear( b );
  153. }
  154. wxString GetClass() const override
  155. {
  156. return wxT( "TRACK" );
  157. }
  158. /**
  159. * Function GetClearance
  160. * returns the clearance in internal units. If \a aItem is not NULL then the
  161. * returned clearance is the greater of this object's clearance and
  162. * aItem's clearance. If \a aItem is NULL, then this objects clearance
  163. * is returned.
  164. * @param aItem is another BOARD_CONNECTED_ITEM or NULL
  165. * @return int - the clearance in internal units.
  166. */
  167. virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const override;
  168. virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  169. BITMAP_DEF GetMenuImage() const override;
  170. virtual EDA_ITEM* Clone() const override;
  171. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  172. virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  173. const BOX2I ViewBBox() const override;
  174. virtual void SwapData( BOARD_ITEM* aImage ) override;
  175. /**
  176. * @return true because a track or a via is always on a copper layer.
  177. */
  178. bool IsOnCopperLayer() const override
  179. {
  180. return true;
  181. }
  182. #if defined (DEBUG)
  183. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  184. /**
  185. * Function ShowState
  186. * converts a set of state bits to a wxString
  187. * @param stateBits Is an OR-ed together set of bits like BUSY, EDIT, etc.
  188. */
  189. static wxString ShowState( int stateBits );
  190. #endif
  191. protected:
  192. /**
  193. * Function GetMsgPanelInfoBase
  194. * Display info about the track segment only, and does not calculate the full track length
  195. * @param aList A list of #MSG_PANEL_ITEM objects to add status information.
  196. */
  197. virtual void GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList );
  198. void GetMsgPanelInfoBase_Common( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList );
  199. int m_Width; ///< Thickness of track, or via diameter
  200. wxPoint m_Start; ///< Line start point
  201. wxPoint m_End; ///< Line end point
  202. };
  203. class ARC : public TRACK
  204. {
  205. public:
  206. ARC( BOARD_ITEM* aParent ) : TRACK( aParent, PCB_ARC_T ){};
  207. ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ) :
  208. TRACK( aParent, PCB_ARC_T )
  209. {
  210. m_Start = wxPoint( aArc->GetP0() );
  211. m_End = wxPoint( aArc->GetP1() );
  212. m_Mid = wxPoint( aArc->GetArcMid() );
  213. }
  214. static inline bool ClassOf( const EDA_ITEM *aItem )
  215. {
  216. return aItem && PCB_ARC_T == aItem->Type();
  217. }
  218. virtual void Move( const wxPoint& aMoveVector ) override
  219. {
  220. m_Start += aMoveVector;
  221. m_Mid += aMoveVector;
  222. m_End += aMoveVector;
  223. }
  224. virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  225. virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
  226. void SetMid( const wxPoint& aMid ) { m_Mid = aMid; }
  227. const wxPoint& GetMid() const { return m_Mid; }
  228. void SetPosition( const wxPoint& aPos ) override
  229. {
  230. printf("Setting the arc position\n");
  231. m_Start = aPos;
  232. }
  233. virtual const wxPoint GetPosition() const override;
  234. double GetRadius() const;
  235. double GetAngle() const;
  236. double GetArcAngleStart() const;
  237. double GetArcAngleEnd() const;
  238. virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  239. virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  240. wxString GetClass() const override
  241. {
  242. return wxT( "ARC" );
  243. }
  244. //TODO(snh): Add GetSelectMenuText() and GetMsgPanelInfoBase()
  245. /**
  246. * Function GetLength
  247. * returns the length of the arc track using a series of segment approximations.
  248. * @return double - the length of the track
  249. */
  250. virtual double GetLength() const override
  251. {
  252. //TODO(snh): Add proper arc length calc
  253. return GetLineLength( m_Start, m_Mid ) + GetLineLength( m_Mid, m_End );
  254. }
  255. EDA_ITEM* Clone() const override;
  256. virtual void SwapData( BOARD_ITEM* aImage ) override;
  257. protected:
  258. private:
  259. wxPoint m_Mid; ///< Arc mid point, halfway between start and end
  260. };
  261. class VIA : public TRACK
  262. {
  263. public:
  264. VIA( BOARD_ITEM* aParent );
  265. static inline bool ClassOf( const EDA_ITEM *aItem )
  266. {
  267. return aItem && PCB_VIA_T == aItem->Type();
  268. }
  269. // Do not create a copy constructor. The one generated by the compiler is adequate.
  270. void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset ) override;
  271. bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
  272. virtual LSET GetLayerSet() const override;
  273. /**
  274. * Function SetLayerPair
  275. * For a via m_Layer contains the top layer, the other layer is in
  276. * m_BottomLayer
  277. * @param aTopLayer = first layer connected by the via
  278. * @param aBottomLayer = last layer connected by the via
  279. */
  280. void SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer );
  281. void SetBottomLayer( PCB_LAYER_ID aLayer );
  282. void SetTopLayer( PCB_LAYER_ID aLayer );
  283. /**
  284. * Function LayerPair
  285. * Return the 2 layers used by the via (the via actually uses
  286. * all layers between these 2 layers)
  287. * @param top_layer = pointer to the first layer (can be null)
  288. * @param bottom_layer = pointer to the last layer (can be null)
  289. */
  290. void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const;
  291. PCB_LAYER_ID TopLayer() const;
  292. PCB_LAYER_ID BottomLayer() const;
  293. /**
  294. * Function SanitizeLayers
  295. * Check so that the layers are correct dependin on the type of via, and
  296. * so that the top actually is on top.
  297. */
  298. void SanitizeLayers();
  299. const wxPoint GetPosition() const override { return m_Start; }
  300. void SetPosition( const wxPoint& aPoint ) override { m_Start = aPoint; m_End = aPoint; }
  301. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  302. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  303. wxString GetClass() const override
  304. {
  305. return wxT( "VIA" );
  306. }
  307. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  308. BITMAP_DEF GetMenuImage() const override;
  309. EDA_ITEM* Clone() const override;
  310. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  311. unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  312. void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
  313. #if defined (DEBUG)
  314. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  315. #endif
  316. VIATYPE GetViaType() const
  317. {
  318. return m_ViaType;
  319. }
  320. void SetViaType( VIATYPE aViaType )
  321. {
  322. m_ViaType = aViaType;
  323. }
  324. /**
  325. * Function SetDrill
  326. * sets the drill value for vias.
  327. * @param aDrill is the new drill diameter
  328. */
  329. void SetDrill( int aDrill ) { m_Drill = aDrill; }
  330. /**
  331. * Function GetDrill
  332. * returns the local drill setting for this VIA. If you want the calculated value,
  333. * use GetDrillValue() instead.
  334. */
  335. int GetDrill() const { return m_Drill; }
  336. /**
  337. * Function GetDrillValue
  338. * "calculates" the drill value for vias (m-Drill if > 0, or default
  339. * drill value for the board.
  340. * @return real drill_value
  341. */
  342. int GetDrillValue() const;
  343. /**
  344. * Function SetDrillDefault
  345. * sets the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER.
  346. */
  347. void SetDrillDefault() { m_Drill = UNDEFINED_DRILL_DIAMETER; }
  348. /**
  349. * Function IsDrillDefault
  350. * @return true if the drill value is default value (-1)
  351. */
  352. bool IsDrillDefault() const { return m_Drill <= 0; }
  353. virtual void SwapData( BOARD_ITEM* aImage ) override;
  354. protected:
  355. void GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
  356. private:
  357. /// The bottom layer of the via (the top layer is in m_Layer)
  358. PCB_LAYER_ID m_BottomLayer;
  359. VIATYPE m_ViaType; // Type of via
  360. int m_Drill; // for vias: via drill (- 1 for default value)
  361. };
  362. #endif // CLASS_TRACK_H