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.

764 lines
29 KiB

14 years ago
14 years ago
14 years ago
11 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
* 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
11 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2017 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_module.h
  26. * @brief Module description (excepted pads)
  27. */
  28. #ifndef MODULE_H_
  29. #define MODULE_H_
  30. #include <list>
  31. #include <dlist.h>
  32. #include <layers_id_colors_and_visibility.h> // ALL_LAYERS definition.
  33. #include <class_board_item.h>
  34. #include <board_item_container.h>
  35. #include <collectors.h>
  36. #include <lib_id.h>
  37. #include <class_text_mod.h>
  38. #include "zones.h"
  39. #include <core/iterators.h>
  40. #include <functional>
  41. class LINE_READER;
  42. class EDA_3D_CANVAS;
  43. class EDA_DRAW_PANEL;
  44. class D_PAD;
  45. class BOARD;
  46. class MSG_PANEL_ITEM;
  47. namespace KIGFX {
  48. class VIEW;
  49. }
  50. enum INCLUDE_NPTH_T
  51. {
  52. DO_NOT_INCLUDE_NPTH = false,
  53. INCLUDE_NPTH = true
  54. };
  55. /**
  56. * Enum MODULE_ATTR_T
  57. * is the set of attributes allowed within a MODULE, using MODULE::SetAttributes()
  58. * and MODULE::GetAttributes(). These are to be ORed together when calling
  59. * MODULE::SetAttributes()
  60. */
  61. enum MODULE_ATTR_T
  62. {
  63. MOD_DEFAULT = 0, ///< default
  64. MOD_CMS = 1, ///< Set for modules listed in the automatic insertion list
  65. ///< (usually SMD footprints)
  66. MOD_VIRTUAL = 2 ///< Virtual component: when created by copper shapes on
  67. ///< board (Like edge card connectors, mounting hole...)
  68. };
  69. class MODULE_3D_SETTINGS
  70. {
  71. public:
  72. MODULE_3D_SETTINGS() :
  73. // Initialize with sensible values
  74. m_Scale { 1, 1, 1 },
  75. m_Rotation { 0, 0, 0 },
  76. m_Offset { 0, 0, 0 },
  77. m_Preview( true )
  78. {
  79. }
  80. struct VECTOR3D
  81. {
  82. double x, y, z;
  83. };
  84. VECTOR3D m_Scale; ///< 3D model scaling factor (dimensionless)
  85. VECTOR3D m_Rotation; ///< 3D model rotation (degrees)
  86. VECTOR3D m_Offset; ///< 3D model offset (mm)
  87. wxString m_Filename; ///< The 3D shape filename in 3D library
  88. bool m_Preview; ///< Include module in 3D preview
  89. };
  90. class MODULE : public BOARD_ITEM_CONTAINER
  91. {
  92. public:
  93. MODULE( BOARD* parent );
  94. MODULE( const MODULE& aModule );
  95. ~MODULE();
  96. MODULE& operator=( const MODULE& aOther );
  97. static inline bool ClassOf( const EDA_ITEM* aItem )
  98. {
  99. return PCB_MODULE_T == aItem->Type();
  100. }
  101. MODULE* Next() const { return static_cast<MODULE*>( Pnext ); }
  102. MODULE* Back() const { return static_cast<MODULE*>( Pback ); }
  103. ///> @copydoc BOARD_ITEM_CONTAINER::Add()
  104. void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) override;
  105. ///> @copydoc BOARD_ITEM_CONTAINER::Remove()
  106. void Remove( BOARD_ITEM* aItem ) override;
  107. /**
  108. * Function ClearAllNets
  109. * Clear (i.e. force the ORPHANED dummy net info) the net info which
  110. * depends on a given board for all pads of the footprint.
  111. * This is needed when a footprint is copied between the fp editor and
  112. * the board editor for instance, because net info become fully broken
  113. */
  114. void ClearAllNets();
  115. /**
  116. * Function CalculateBoundingBox
  117. * calculates the bounding box in board coordinates.
  118. */
  119. void CalculateBoundingBox();
  120. /**
  121. * Function GetFootprintRect()
  122. * Returns the area of the module footprint excluding any text.
  123. * @return EDA_RECT - The rectangle containing the footprint.
  124. */
  125. EDA_RECT GetFootprintRect() const;
  126. /**
  127. * Returns a bounding polygon for the shapes and pads in the module
  128. * This operation is slower but more accurate than calculating a bounding box
  129. */
  130. SHAPE_POLY_SET GetBoundingPoly() const;
  131. // Virtual function
  132. const EDA_RECT GetBoundingBox() const override;
  133. DLIST<D_PAD>& PadsList() { return m_Pads; }
  134. const DLIST<D_PAD>& PadsList() const { return m_Pads; }
  135. DLIST<BOARD_ITEM>& GraphicalItemsList() { return m_Drawings; }
  136. const DLIST<BOARD_ITEM>& GraphicalItemsList() const { return m_Drawings; }
  137. DLIST_ITERATOR_WRAPPER<D_PAD> Pads()
  138. {
  139. return DLIST_ITERATOR_WRAPPER<D_PAD>( m_Pads );
  140. }
  141. DLIST_ITERATOR_WRAPPER<BOARD_ITEM> GraphicalItems()
  142. {
  143. return DLIST_ITERATOR_WRAPPER<BOARD_ITEM>( m_Drawings );
  144. }
  145. std::list<MODULE_3D_SETTINGS>& Models() { return m_3D_Drawings; }
  146. const std::list<MODULE_3D_SETTINGS>& Models() const { return m_3D_Drawings; }
  147. void SetPosition( const wxPoint& aPos ) override;
  148. const wxPoint GetPosition() const override { return m_Pos; }
  149. void SetOrientation( double newangle );
  150. void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation * 10.0 ); }
  151. double GetOrientation() const { return m_Orient; }
  152. double GetOrientationDegrees() const { return m_Orient / 10.0; }
  153. double GetOrientationRadians() const { return m_Orient * M_PI / 1800; }
  154. const LIB_ID& GetFPID() const { return m_fpid; }
  155. void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
  156. const wxString& GetDescription() const { return m_Doc; }
  157. void SetDescription( const wxString& aDoc ) { m_Doc = aDoc; }
  158. const wxString& GetKeywords() const { return m_KeyWord; }
  159. void SetKeywords( const wxString& aKeywords ) { m_KeyWord = aKeywords; }
  160. const wxString& GetPath() const { return m_Path; }
  161. void SetPath( const wxString& aPath ) { m_Path = aPath; }
  162. int GetLocalSolderMaskMargin() const { return m_LocalSolderMaskMargin; }
  163. void SetLocalSolderMaskMargin( int aMargin ) { m_LocalSolderMaskMargin = aMargin; }
  164. int GetLocalClearance() const { return m_LocalClearance; }
  165. void SetLocalClearance( int aClearance ) { m_LocalClearance = aClearance; }
  166. int GetLocalSolderPasteMargin() const { return m_LocalSolderPasteMargin; }
  167. void SetLocalSolderPasteMargin( int aMargin ) { m_LocalSolderPasteMargin = aMargin; }
  168. double GetLocalSolderPasteMarginRatio() const { return m_LocalSolderPasteMarginRatio; }
  169. void SetLocalSolderPasteMarginRatio( double aRatio ) { m_LocalSolderPasteMarginRatio = aRatio; }
  170. void SetZoneConnection( ZoneConnection aType ) { m_ZoneConnection = aType; }
  171. ZoneConnection GetZoneConnection() const { return m_ZoneConnection; }
  172. void SetThermalWidth( int aWidth ) { m_ThermalWidth = aWidth; }
  173. int GetThermalWidth() const { return m_ThermalWidth; }
  174. void SetThermalGap( int aGap ) { m_ThermalGap = aGap; }
  175. int GetThermalGap() const { return m_ThermalGap; }
  176. int GetAttributes() const { return m_Attributs; }
  177. void SetAttributes( int aAttributes ) { m_Attributs = aAttributes; }
  178. void SetFlag( int aFlag ) { m_arflag = aFlag; }
  179. void IncrementFlag() { m_arflag += 1; }
  180. int GetFlag() const { return m_arflag; }
  181. // A bit of a hack until net ties are supported as first class citizens
  182. bool IsNetTie() const { return GetKeywords().StartsWith( wxT( "net tie" ) ); }
  183. void Move( const wxPoint& aMoveVector ) override;
  184. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  185. void Flip( const wxPoint& aCentre ) override;
  186. /**
  187. * Function MoveAnchorPosition
  188. * Move the reference point of the footprint
  189. * It looks like a move footprint:
  190. * the footprints elements (pads, outlines, edges .. ) are moved
  191. * However:
  192. * - the footprint position is not modified.
  193. * - the relative (local) coordinates of these items are modified
  194. * (a move footprint does not change these local coordinates,
  195. * but changes the footprint position)
  196. */
  197. void MoveAnchorPosition( const wxPoint& aMoveVector );
  198. /**
  199. * function IsFlipped
  200. * @return true if the module is flipped, i.e. on the back side of the board
  201. */
  202. bool IsFlipped() const { return GetLayer() == B_Cu; }
  203. // m_ModuleStatus bits:
  204. #define MODULE_is_LOCKED 0x01 ///< module LOCKED: no autoplace allowed
  205. #define MODULE_is_PLACED 0x02 ///< In autoplace: module automatically placed
  206. #define MODULE_to_PLACE 0x04 ///< In autoplace: module waiting for autoplace
  207. #define MODULE_PADS_LOCKED 0x08 ///< In autoplace: module waiting for autoplace
  208. bool IsLocked() const override
  209. {
  210. return ( m_ModuleStatus & MODULE_is_LOCKED ) != 0;
  211. }
  212. /**
  213. * Function SetLocked
  214. * sets the MODULE_is_LOCKED bit in the m_ModuleStatus
  215. * @param isLocked When true means turn on locked status, else unlock
  216. */
  217. void SetLocked( bool isLocked ) override
  218. {
  219. if( isLocked )
  220. m_ModuleStatus |= MODULE_is_LOCKED;
  221. else
  222. m_ModuleStatus &= ~MODULE_is_LOCKED;
  223. }
  224. bool IsPlaced() const { return m_ModuleStatus & MODULE_is_PLACED; }
  225. void SetIsPlaced( bool isPlaced )
  226. {
  227. if( isPlaced )
  228. m_ModuleStatus |= MODULE_is_PLACED;
  229. else
  230. m_ModuleStatus &= ~MODULE_is_PLACED;
  231. }
  232. bool NeedsPlaced() const { return m_ModuleStatus & MODULE_to_PLACE; }
  233. void SetNeedsPlaced( bool needsPlaced )
  234. {
  235. if( needsPlaced )
  236. m_ModuleStatus |= MODULE_to_PLACE;
  237. else
  238. m_ModuleStatus &= ~MODULE_to_PLACE;
  239. }
  240. bool PadsLocked() const { return m_ModuleStatus & MODULE_PADS_LOCKED; }
  241. void SetPadsLocked( bool aPadsLocked )
  242. {
  243. if( aPadsLocked )
  244. m_ModuleStatus |= MODULE_PADS_LOCKED;
  245. else
  246. m_ModuleStatus &= ~MODULE_PADS_LOCKED;
  247. }
  248. void SetLastEditTime( timestamp_t aTime ) { m_LastEditTime = aTime; }
  249. void SetLastEditTime() { m_LastEditTime = time( NULL ); }
  250. timestamp_t GetLastEditTime() const { return m_LastEditTime; }
  251. /* drawing functions */
  252. /**
  253. * Function Draw
  254. * draws the footprint to the \a aDC.
  255. * @param aPanel = draw panel, Used to know the clip box
  256. * @param aDC = Current Device Context
  257. * @param aDrawMode = GR_OR, GR_XOR..
  258. * @param aOffset = draw offset (usually wxPoint(0,0)
  259. */
  260. void Draw( EDA_DRAW_PANEL* aPanel,
  261. wxDC* aDC,
  262. GR_DRAWMODE aDrawMode,
  263. const wxPoint& aOffset = ZeroOffset ) override;
  264. /**
  265. * Function DrawOutlinesWhenMoving
  266. * draws in XOR mode the footprint when moving it to the \a aDC.
  267. * To speed up the drawing, only a simplified shape is drawn
  268. * @param aPanel = draw panel, Used to know the clip box
  269. * @param aDC = Current Device Context
  270. * @param aMoveVector = the offset between the curr position and
  271. * the draw position.
  272. */
  273. void DrawOutlinesWhenMoving( EDA_DRAW_PANEL* aPanel,
  274. wxDC* aDC, const wxPoint& aMoveVector );
  275. /**
  276. * function TransformPadsShapesWithClearanceToPolygon
  277. * generate pads shapes on layer aLayer as polygons,
  278. * and adds these polygons to aCornerBuffer
  279. * Useful to generate a polygonal representation of a footprint
  280. * in 3D view and plot functions, when a full polygonal approach is needed
  281. * @param aLayer = the layer to consider, or UNDEFINED_LAYER to consider all
  282. * @param aCornerBuffer = the buffer to store polygons
  283. * @param aInflateValue = an additionnal size to add to pad shapes
  284. * aInflateValue = 0 to have the exact pad size
  285. * @param aCircleToSegmentsCount = number of segments to generate a circle
  286. * @param aCorrectionFactor = the correction to apply to a circle radius
  287. * to approximate a circle by the polygon.
  288. * if aCorrectionFactor = 1.0, the polygon is inside the circle
  289. * the radius of circle approximated by segments is
  290. * initial radius * aCorrectionFactor
  291. * @param aSkipNPTHPadsWihNoCopper = if true, do not add a NPTH pad shape,
  292. * if the shape has same size and position as the hole. Usually, these
  293. * pads are not drawn on copper layers, because there is actually no copper
  294. * Due to diff between layers and holes, these pads must be skipped to be sure
  295. * there is no copper left on the board (for instance when creating Gerber Files or 3D shapes)
  296. * default = false
  297. */
  298. void TransformPadsShapesWithClearanceToPolygon( PCB_LAYER_ID aLayer,
  299. SHAPE_POLY_SET& aCornerBuffer,
  300. int aInflateValue,
  301. int aCircleToSegmentsCount,
  302. double aCorrectionFactor,
  303. bool aSkipNPTHPadsWihNoCopper = false ) const;
  304. /**
  305. * function TransformGraphicShapesWithClearanceToPolygonSet
  306. * generate shapes of graphic items (outlines) on layer aLayer as polygons,
  307. * and adds these polygons to aCornerBuffer
  308. * Useful to generate a polygonal representation of a footprint
  309. * in 3D view and plot functions, when a full polygonal approach is needed
  310. * @param aLayer = the layer to consider, or UNDEFINED_LAYER to consider all
  311. * @param aCornerBuffer = the buffer to store polygons
  312. * @param aInflateValue = a value to inflate shapes
  313. * aInflateValue = 0 to have the exact shape size
  314. * @param aCircleToSegmentsCount = number of segments to generate a circle
  315. * @param aCorrectionFactor = the correction to apply to a circle radius
  316. * to approximate a circle by the polygon.
  317. * if aCorrectionFactor = 1.0, the polygon is inside the circle
  318. * the radius of circle approximated by segments is
  319. * initial radius * aCorrectionFactor
  320. * @param aCircleToSegmentsCountForTexts = number of segments to generate
  321. * a circle when building the texts polygonal shapes of the stroke font
  322. * if 0, use the aCircleToSegmentsCount value
  323. */
  324. void TransformGraphicShapesWithClearanceToPolygonSet( PCB_LAYER_ID aLayer,
  325. SHAPE_POLY_SET& aCornerBuffer,
  326. int aInflateValue,
  327. int aCircleToSegmentsCount,
  328. double aCorrectionFactor,
  329. int aCircleToSegmentsCountForTexts = 0,
  330. bool aIncludeText = true ) const;
  331. /**
  332. * @brief TransformGraphicTextWithClearanceToPolygonSet
  333. * This function is the same as TransformGraphicShapesWithClearanceToPolygonSet
  334. * but only generate text
  335. * @param aLayer
  336. * @param aCornerBuffer
  337. * @param aInflateValue
  338. * @param aCircleToSegmentsCount
  339. * @param aCorrectionFactor
  340. * @param aCircleToSegmentsCountForTexts
  341. */
  342. void TransformGraphicTextWithClearanceToPolygonSet( PCB_LAYER_ID aLayer,
  343. SHAPE_POLY_SET& aCornerBuffer,
  344. int aInflateValue,
  345. int aCircleToSegmentsCount,
  346. double aCorrectionFactor,
  347. int aCircleToSegmentsCountForTexts = 0 ) const;
  348. /**
  349. * Function DrawEdgesOnly
  350. * Draws the footprint edges only to the current Device Context
  351. * @param panel = The active Draw Panel (used to know the clip box)
  352. * @param DC = current Device Context
  353. * @param offset = draw offset (usually wxPoint(0,0)
  354. * @param draw_mode = GR_OR, GR_XOR, GR_AND
  355. */
  356. void DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
  357. GR_DRAWMODE draw_mode );
  358. /**
  359. * Function DrawAncre
  360. * Draw the anchor cross (vertical)
  361. * Must be done after the pads, because drawing the hole will erase overwrite
  362. * every thing already drawn.
  363. */
  364. void DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC,
  365. const wxPoint& offset, int dim_ancre, GR_DRAWMODE draw_mode );
  366. ///> @copydoc EDA_ITEM::GetMsgPanelInfo
  367. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
  368. bool HitTest( const wxPoint& aPosition ) const override;
  369. /**
  370. * Tests if a point is inside the bounding polygon of the module
  371. *
  372. * The other hit test methods are just checking the bounding box, which
  373. * can be quite inaccurate for rotated or oddly-shaped footprints.
  374. *
  375. * @param aPosition is the point to test
  376. * @return true if aPosition is inside the bounding polygon
  377. */
  378. bool HitTestAccurate( const wxPoint& aPosition ) const;
  379. bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  380. /**
  381. * Function GetReference
  382. * @return const wxString& - the reference designator text.
  383. */
  384. const wxString& GetReference() const
  385. {
  386. return m_Reference->GetText();
  387. }
  388. /**
  389. * Function SetReference
  390. * @param aReference A reference to a wxString object containing the reference designator
  391. * text.
  392. */
  393. void SetReference( const wxString& aReference )
  394. {
  395. m_Reference->SetText( aReference );
  396. }
  397. /**
  398. * Function IncrementReference
  399. * Bumps the current reference by aDelta.
  400. */
  401. void IncrementReference( int aDelta );
  402. /**
  403. * Function GetValue
  404. * @return const wxString& - the value text.
  405. */
  406. const wxString& GetValue() const
  407. {
  408. return m_Value->GetText();
  409. }
  410. /**
  411. * Function SetValue
  412. * @param aValue A reference to a wxString object containing the value text.
  413. */
  414. void SetValue( const wxString& aValue )
  415. {
  416. m_Value->SetText( aValue );
  417. }
  418. /// read/write accessors:
  419. TEXTE_MODULE& Value() { return *m_Value; }
  420. TEXTE_MODULE& Reference() { return *m_Reference; }
  421. /// The const versions to keep the compiler happy.
  422. TEXTE_MODULE& Value() const { return *m_Value; }
  423. TEXTE_MODULE& Reference() const { return *m_Reference; }
  424. /**
  425. * Function FindPadByName
  426. * returns a D_PAD* with a matching name. Note that names may not be
  427. * unique, depending on how the foot print was created.
  428. * @param aPadName the pad name to find
  429. * @return D_PAD* - The first matching name is returned, or NULL if not
  430. * found.
  431. */
  432. D_PAD* FindPadByName( const wxString& aPadName ) const;
  433. /**
  434. * Function GetPad
  435. * get a pad at \a aPosition on \a aLayerMask in the footprint.
  436. *
  437. * @param aPosition A wxPoint object containing the position to hit test.
  438. * @param aLayerMask A layer or layers to mask the hit test.
  439. * @return A pointer to a D_PAD object if found otherwise NULL.
  440. */
  441. D_PAD* GetPad( const wxPoint& aPosition, LSET aLayerMask = LSET::AllLayersMask() );
  442. D_PAD* GetTopLeftPad();
  443. /**
  444. * GetPadCount
  445. * returns the number of pads.
  446. *
  447. * @param aIncludeNPTH includes non-plated through holes when true. Does not include
  448. * non-plated through holes when false.
  449. * @return the number of pads according to \a aIncludeNPTH.
  450. */
  451. unsigned GetPadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const;
  452. /**
  453. * GetUniquePadCount
  454. * returns the number of unique pads.
  455. * A complex pad can be built with many pads having the same pad name
  456. * to create a complex shape or fragmented solder paste areas.
  457. *
  458. * GetUniquePadCount calculate the count of not blank pad names
  459. *
  460. * @param aIncludeNPTH includes non-plated through holes when true. Does not include
  461. * non-plated through holes when false.
  462. * @return the number of unique pads according to \a aIncludeNPTH.
  463. */
  464. unsigned GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const;
  465. /**
  466. * Function GetNextPadName
  467. * returns the next available pad name in the module
  468. *
  469. * @param aFillSequenceGaps true if the numbering should "fill in" gaps in
  470. * the sequence, else return the highest value + 1
  471. * @return the next available pad name
  472. */
  473. wxString GetNextPadName( bool aFillSequenceGaps ) const;
  474. double GetArea( int aPadding = 0 ) const;
  475. timestamp_t GetLink() const { return m_Link; }
  476. void SetLink( timestamp_t aLink ) { m_Link = aLink; }
  477. int GetPlacementCost180() const { return m_CntRot180; }
  478. void SetPlacementCost180( int aCost ) { m_CntRot180 = aCost; }
  479. int GetPlacementCost90() const { return m_CntRot90; }
  480. void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; }
  481. /**
  482. * Function Duplicate
  483. * Duplicate a given item within the module, without adding to the board
  484. * @return the new item, or NULL if the item could not be duplicated
  485. */
  486. BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem,
  487. bool aIncrementPadNumbers,
  488. bool aAddToModule = false );
  489. /**
  490. * Function Add3DModel
  491. * adds \a a3DModel definition to the end of the 3D model list.
  492. *
  493. * @param a3DModel A pointer to a #MODULE_3D_SETTINGS to add to the list.
  494. */
  495. void Add3DModel( MODULE_3D_SETTINGS* a3DModel );
  496. SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
  497. wxString GetClass() const override
  498. {
  499. return wxT( "MODULE" );
  500. }
  501. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  502. BITMAP_DEF GetMenuImage() const override;
  503. EDA_ITEM* Clone() const override;
  504. /**
  505. * Function RunOnChildren
  506. *
  507. * Invokes a function on all BOARD_ITEMs that belong to the module (pads, drawings, texts).
  508. * @param aFunction is the function to be invoked.
  509. */
  510. void RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction );
  511. /**
  512. * Returns a set of all layers that this module has drawings on
  513. * similar to ViewGetLayers()
  514. *
  515. * @param aLayers is an array to store layer ids
  516. * @param aCount is the number of layers stored in the array
  517. * @param aIncludePads controls whether to also include pad layers
  518. */
  519. void GetAllDrawingLayers( int aLayers[], int& aCount, bool aIncludePads = true ) const;
  520. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  521. virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  522. virtual const BOX2I ViewBBox() const override;
  523. /**
  524. * Function CopyNetlistSettings
  525. * copies the netlist settings to \a aModule.
  526. * Used to copy some footprint parameters when replacing a footprint by an other
  527. * footprint when reading a netlist, or in exchange footprint dialog
  528. *
  529. * The netlist settings are all of the #MODULE settings not define by a #MODULE in
  530. * a netlist. These setting include placement prms (position, orientation, side)
  531. * and optionally local prms( clearances, zone connection type, etc).
  532. * The reference designator, value, path, and physical geometry settings are not
  533. * copied.
  534. *
  535. * @param aModule is the #MODULE to copy the settings to.
  536. * @param aCopyLocalSettings = false to copy only module placement
  537. * true to also copy local prms
  538. */
  539. void CopyNetlistSettings( MODULE* aModule, bool aCopyLocalSettings );
  540. /**
  541. * static function IsLibNameValid
  542. * Test for validity of a name of a footprint to be used in a footprint library
  543. * ( no spaces, dir separators ... )
  544. * @param aName = the name in library to validate
  545. * @return true if the given name is valid
  546. */
  547. static bool IsLibNameValid( const wxString& aName );
  548. /**
  549. * static function StringLibNameInvalidChars
  550. * Test for validity of the name in a library of the footprint
  551. * ( no spaces, dir separators ... )
  552. * @param aUserReadable = false to get the list of invalid chars
  553. * true to get a readable form (i.e ' ' = 'space' '\\t'= 'tab')
  554. * @return a constant std::string giving the list of invalid chars in lib name
  555. */
  556. static const wxChar* StringLibNameInvalidChars( bool aUserReadable );
  557. /**
  558. * Function SetInitialComments
  559. * takes ownership of caller's heap allocated aInitialComments block. The comments
  560. * are single line strings already containing the s-expression comments with
  561. * optional leading whitespace and then a '#' character followed by optional
  562. * single line text (text with no line endings, not even one).
  563. * This block of single line comments will be output upfront of any generated
  564. * s-expression text in the PCBIO::Format() function.
  565. * <p>
  566. * Note that a block of single line comments constitutes a multiline block of
  567. * single line comments. That is, the block is made of consecutive single line
  568. * comments.
  569. * @param aInitialComments is a heap allocated wxArrayString or NULL, which the caller
  570. * gives up ownership of over to this MODULE.
  571. */
  572. void SetInitialComments( wxArrayString* aInitialComments )
  573. {
  574. delete m_initial_comments;
  575. m_initial_comments = aInitialComments;
  576. }
  577. /**
  578. * Function CoverageRatio
  579. * Calculates the ratio of total area of the footprint pads and graphical items
  580. * to the area of the footprint. Used by selection tool heuristics.
  581. * @return the ratio
  582. */
  583. double CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const;
  584. /// Return the initial comments block or NULL if none, without transfer of ownership.
  585. const wxArrayString* GetInitialComments() const { return m_initial_comments; }
  586. /** Used in DRC to test the courtyard area (a complex polygon)
  587. * @return the courtyard polygon
  588. */
  589. SHAPE_POLY_SET& GetPolyCourtyardFront() { return m_poly_courtyard_front; }
  590. SHAPE_POLY_SET& GetPolyCourtyardBack() { return m_poly_courtyard_back; }
  591. /** Used in DRC to build the courtyard area (a complex polygon)
  592. * from graphic items put on the courtyard
  593. * @return true if OK, or no courtyard defined,
  594. * false only if the polygon cannot be built due to amalformed courtyard shape
  595. * The polygon cannot be built if segments/arcs on courtyard layers
  596. * cannot be grouped in a polygon.
  597. */
  598. bool BuildPolyCourtyard();
  599. virtual void SwapData( BOARD_ITEM* aImage ) override;
  600. #if defined(DEBUG)
  601. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  602. #endif
  603. private:
  604. DLIST<D_PAD> m_Pads; ///< Linked list of pads.
  605. DLIST<BOARD_ITEM> m_Drawings; ///< Linked list of graphical items.
  606. std::list<MODULE_3D_SETTINGS> m_3D_Drawings; ///< Linked list of 3D models.
  607. double m_Orient; ///< Orientation in tenths of a degree, 900=90.0 degrees.
  608. wxPoint m_Pos; ///< Position of module on the board in internal units.
  609. TEXTE_MODULE* m_Reference; ///< Component reference designator value (U34, R18..)
  610. TEXTE_MODULE* m_Value; ///< Component value (74LS00, 22K..)
  611. LIB_ID m_fpid; ///< The #LIB_ID of the MODULE.
  612. int m_Attributs; ///< Flag bits ( see Mod_Attribut )
  613. int m_ModuleStatus; ///< For autoplace: flags (LOCKED, AUTOPLACED)
  614. EDA_RECT m_BoundaryBox; ///< Bounding box : coordinates on board, real orientation.
  615. // The final margin is the sum of these 2 values
  616. int m_ThermalWidth;
  617. int m_ThermalGap;
  618. wxString m_Doc; ///< File name and path for documentation file.
  619. wxString m_KeyWord; ///< Search keywords to find module in library.
  620. wxString m_Path;
  621. ZoneConnection m_ZoneConnection;
  622. timestamp_t m_LastEditTime;
  623. int m_arflag; ///< Use to trace ratsnest and auto routing.
  624. timestamp_t m_Link; ///< Temporary logical link used during editing
  625. int m_CntRot90; ///< Horizontal automatic placement cost ( 0..10 ).
  626. int m_CntRot180; ///< Vertical automatic placement cost ( 0..10 ).
  627. // Local tolerances. When zero, this means the corresponding netclass value
  628. // is used. Usually theses local tolerances zero, in deference to the
  629. // corresponding netclass values.
  630. int m_LocalClearance;
  631. int m_LocalSolderMaskMargin; ///< Solder mask margin
  632. int m_LocalSolderPasteMargin; ///< Solder paste margin absolute value
  633. double m_LocalSolderPasteMarginRatio; ///< Solder mask margin ratio
  634. ///< value of pad size
  635. wxArrayString* m_initial_comments; ///< leading s-expression comments in the module,
  636. ///< lazily allocated only if needed for speed
  637. /// Used in DRC to test the courtyard area (a polygon which can be not basic
  638. /// Note also a footprint can have courtyards on bot board sides
  639. SHAPE_POLY_SET m_poly_courtyard_front;
  640. SHAPE_POLY_SET m_poly_courtyard_back;
  641. };
  642. #endif // MODULE_H_