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.

737 lines
28 KiB

14 years ago
5 years ago
5 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-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. #ifndef MODULE_H_
  25. #define MODULE_H_
  26. #include <deque>
  27. #include <board_item_container.h>
  28. #include <class_board_item.h>
  29. #include <collectors.h>
  30. #include <convert_to_biu.h>
  31. #include <layers_id_colors_and_visibility.h> // ALL_LAYERS definition.
  32. #include <lib_id.h>
  33. #include <list>
  34. #include "zones.h"
  35. #include <fp_text.h>
  36. #include <class_zone.h>
  37. #include <functional>
  38. class LINE_READER;
  39. class EDA_3D_CANVAS;
  40. class D_PAD;
  41. class BOARD;
  42. class MSG_PANEL_ITEM;
  43. class SHAPE;
  44. namespace KIGFX {
  45. class VIEW;
  46. }
  47. enum INCLUDE_NPTH_T
  48. {
  49. DO_NOT_INCLUDE_NPTH = false,
  50. INCLUDE_NPTH = true
  51. };
  52. /**
  53. * Enum MODULE_ATTR_T
  54. * is the set of attributes allowed within a MODULE, using MODULE::SetAttributes()
  55. * and MODULE::GetAttributes(). These are to be ORed together when calling
  56. * MODULE::SetAttributes()
  57. */
  58. enum MODULE_ATTR_T
  59. {
  60. MOD_THROUGH_HOLE = 0x0001,
  61. MOD_SMD = 0x0002,
  62. MOD_EXCLUDE_FROM_POS_FILES = 0x0004,
  63. MOD_EXCLUDE_FROM_BOM = 0x0008,
  64. MOD_BOARD_ONLY = 0x0010 // Footprint has no corresponding symbol
  65. };
  66. class MODULE_3D_SETTINGS
  67. {
  68. public:
  69. MODULE_3D_SETTINGS() :
  70. // Initialize with sensible values
  71. m_Scale { 1, 1, 1 },
  72. m_Rotation { 0, 0, 0 },
  73. m_Offset { 0, 0, 0 },
  74. m_Opacity( 1.0 ),
  75. m_Show( true )
  76. {
  77. }
  78. struct VECTOR3D
  79. {
  80. double x, y, z;
  81. };
  82. VECTOR3D m_Scale; ///< 3D model scaling factor (dimensionless)
  83. VECTOR3D m_Rotation; ///< 3D model rotation (degrees)
  84. VECTOR3D m_Offset; ///< 3D model offset (mm)
  85. double m_Opacity;
  86. wxString m_Filename; ///< The 3D shape filename in 3D library
  87. bool m_Show; ///< Include module in rendering
  88. };
  89. DECL_DEQ_FOR_SWIG( PADS, D_PAD* )
  90. DECL_DEQ_FOR_SWIG( DRAWINGS, BOARD_ITEM* )
  91. DECL_VEC_FOR_SWIG( MODULE_ZONE_CONTAINERS, MODULE_ZONE_CONTAINER* )
  92. DECL_VEC_FOR_SWIG( MODULE_GROUPS, PCB_GROUP* )
  93. DECL_DEQ_FOR_SWIG( MODULES, MODULE* )
  94. class MODULE : public BOARD_ITEM_CONTAINER
  95. {
  96. public:
  97. MODULE( BOARD* parent );
  98. MODULE( const MODULE& aFootprint );
  99. // Move constructor and operator needed due to std containers inside the module
  100. MODULE( MODULE&& aFootprint );
  101. ~MODULE();
  102. MODULE& operator=( const MODULE& aOther );
  103. MODULE& operator=( MODULE&& aOther );
  104. static inline bool ClassOf( const EDA_ITEM* aItem )
  105. {
  106. return aItem && PCB_MODULE_T == aItem->Type();
  107. }
  108. ///> @copydoc BOARD_ITEM_CONTAINER::Add()
  109. void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT ) override;
  110. ///> @copydoc BOARD_ITEM_CONTAINER::Remove()
  111. void Remove( BOARD_ITEM* aItem ) override;
  112. /**
  113. * Function ClearAllNets
  114. * Clear (i.e. force the ORPHANED dummy net info) the net info which
  115. * depends on a given board for all pads of the footprint.
  116. * This is needed when a footprint is copied between the fp editor and
  117. * the board editor for instance, because net info become fully broken
  118. */
  119. void ClearAllNets();
  120. /**
  121. * Function CalculateBoundingBox
  122. * calculates the bounding box in board coordinates.
  123. */
  124. void CalculateBoundingBox();
  125. /**
  126. * Function GetFootprintRect()
  127. * Build and returns the boundary box of the module footprint excluding any text.
  128. * @return EDA_RECT - The rectangle containing the footprint.
  129. */
  130. EDA_RECT GetFootprintRect() const;
  131. /**
  132. * Returns the last calculated bounding box of the footprint (does not recalculate it).
  133. * (call CalculateBoundingBox() to recalculate it)
  134. * @return EDA_RECT - The rectangle containing the footprint
  135. */
  136. EDA_RECT GetBoundingBoxBase() const { return m_BoundaryBox; }
  137. /**
  138. * Returns the bounding box containing pads when the footprint
  139. * is on the front side, orientation 0, position 0,0.
  140. * mainly used in Gerber place file to draw a fp outline when the coutyard
  141. * is missing or broken
  142. * @return EDA_RECT - The rectangle containing the pads for the normalized footprint.
  143. */
  144. EDA_RECT GetFpPadsLocalBbox() const;
  145. /**
  146. * Returns a bounding polygon for the shapes and pads in the module
  147. * This operation is slower but more accurate than calculating a bounding box
  148. */
  149. SHAPE_POLY_SET GetBoundingPoly() const;
  150. // Virtual function
  151. const EDA_RECT GetBoundingBox() const override;
  152. const EDA_RECT GetBoundingBox( bool aIncludeInvisibleText ) const;
  153. PADS& Pads() { return m_pads; }
  154. const PADS& Pads() const { return m_pads; }
  155. DRAWINGS& GraphicalItems() { return m_drawings; }
  156. const DRAWINGS& GraphicalItems() const { return m_drawings; }
  157. MODULE_ZONE_CONTAINERS& Zones() { return m_fp_zones; }
  158. const MODULE_ZONE_CONTAINERS& Zones() const { return m_fp_zones; }
  159. MODULE_GROUPS& Groups() { return m_fp_groups; }
  160. const MODULE_GROUPS& Groups() const { return m_fp_groups; }
  161. bool HasThroughHolePads() const;
  162. std::list<MODULE_3D_SETTINGS>& Models() { return m_3D_Drawings; }
  163. const std::list<MODULE_3D_SETTINGS>& Models() const { return m_3D_Drawings; }
  164. void SetPosition( const wxPoint& aPos ) override;
  165. wxPoint GetPosition() const override { return m_Pos; }
  166. void SetOrientation( double aNewAngle );
  167. void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation * 10.0 ); }
  168. double GetOrientation() const { return m_Orient; }
  169. double GetOrientationDegrees() const { return m_Orient / 10.0; }
  170. double GetOrientationRadians() const { return m_Orient * M_PI / 1800; }
  171. const LIB_ID& GetFPID() const { return m_fpid; }
  172. void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
  173. const wxString& GetDescription() const { return m_Doc; }
  174. void SetDescription( const wxString& aDoc ) { m_Doc = aDoc; }
  175. const wxString& GetKeywords() const { return m_KeyWord; }
  176. void SetKeywords( const wxString& aKeywords ) { m_KeyWord = aKeywords; }
  177. const KIID_PATH& GetPath() const { return m_Path; }
  178. void SetPath( const KIID_PATH& aPath ) { m_Path = aPath; }
  179. int GetLocalSolderMaskMargin() const { return m_LocalSolderMaskMargin; }
  180. void SetLocalSolderMaskMargin( int aMargin ) { m_LocalSolderMaskMargin = aMargin; }
  181. int GetLocalClearance() const { return m_LocalClearance; }
  182. void SetLocalClearance( int aClearance ) { m_LocalClearance = aClearance; }
  183. int GetLocalClearance( wxString* aSource ) const
  184. {
  185. if( aSource )
  186. *aSource = wxString::Format( _( "footprint %s" ), GetReference() );
  187. return m_LocalClearance;
  188. }
  189. int GetLocalSolderPasteMargin() const { return m_LocalSolderPasteMargin; }
  190. void SetLocalSolderPasteMargin( int aMargin ) { m_LocalSolderPasteMargin = aMargin; }
  191. double GetLocalSolderPasteMarginRatio() const { return m_LocalSolderPasteMarginRatio; }
  192. void SetLocalSolderPasteMarginRatio( double aRatio ) { m_LocalSolderPasteMarginRatio = aRatio; }
  193. void SetZoneConnection( ZONE_CONNECTION aType ) { m_ZoneConnection = aType; }
  194. ZONE_CONNECTION GetZoneConnection() const { return m_ZoneConnection; }
  195. void SetThermalWidth( int aWidth ) { m_ThermalWidth = aWidth; }
  196. int GetThermalWidth() const { return m_ThermalWidth; }
  197. void SetThermalGap( int aGap ) { m_ThermalGap = aGap; }
  198. int GetThermalGap() const { return m_ThermalGap; }
  199. int GetAttributes() const { return m_Attributs; }
  200. void SetAttributes( int aAttributes ) { m_Attributs = aAttributes; }
  201. void SetFlag( int aFlag ) { m_arflag = aFlag; }
  202. void IncrementFlag() { m_arflag += 1; }
  203. int GetFlag() const { return m_arflag; }
  204. // A bit of a hack until net ties are supported as first class citizens
  205. bool IsNetTie() const { return GetKeywords().StartsWith( wxT( "net tie" ) ); }
  206. void Move( const wxPoint& aMoveVector ) override;
  207. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  208. void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
  209. /**
  210. * Function MoveAnchorPosition
  211. * Move the reference point of the footprint
  212. * It looks like a move footprint:
  213. * the footprints elements (pads, outlines, edges .. ) are moved
  214. * However:
  215. * - the footprint position is not modified.
  216. * - the relative (local) coordinates of these items are modified
  217. * (a move footprint does not change these local coordinates,
  218. * but changes the footprint position)
  219. */
  220. void MoveAnchorPosition( const wxPoint& aMoveVector );
  221. /**
  222. * function IsFlipped
  223. * @return true if the module is flipped, i.e. on the back side of the board
  224. */
  225. bool IsFlipped() const { return GetLayer() == B_Cu; }
  226. // m_footprintstatus bits:
  227. #define MODULE_is_LOCKED 0x01 ///< module LOCKED: no autoplace allowed
  228. #define MODULE_is_PLACED 0x02 ///< In autoplace: module automatically placed
  229. #define MODULE_to_PLACE 0x04 ///< In autoplace: module waiting for autoplace
  230. #define MODULE_PADS_LOCKED 0x08 ///< In autoplace: module waiting for autoplace
  231. bool IsLocked() const override
  232. {
  233. return ( m_ModuleStatus & MODULE_is_LOCKED ) != 0;
  234. }
  235. /**
  236. * Function SetLocked
  237. * sets the MODULE_is_LOCKED bit in the m_ModuleStatus
  238. * @param isLocked When true means turn on locked status, else unlock
  239. */
  240. void SetLocked( bool isLocked ) override
  241. {
  242. if( isLocked )
  243. m_ModuleStatus |= MODULE_is_LOCKED;
  244. else
  245. m_ModuleStatus &= ~MODULE_is_LOCKED;
  246. }
  247. bool IsPlaced() const { return m_ModuleStatus & MODULE_is_PLACED; }
  248. void SetIsPlaced( bool isPlaced )
  249. {
  250. if( isPlaced )
  251. m_ModuleStatus |= MODULE_is_PLACED;
  252. else
  253. m_ModuleStatus &= ~MODULE_is_PLACED;
  254. }
  255. bool NeedsPlaced() const { return m_ModuleStatus & MODULE_to_PLACE; }
  256. void SetNeedsPlaced( bool needsPlaced )
  257. {
  258. if( needsPlaced )
  259. m_ModuleStatus |= MODULE_to_PLACE;
  260. else
  261. m_ModuleStatus &= ~MODULE_to_PLACE;
  262. }
  263. bool PadsLocked() const { return m_ModuleStatus & MODULE_PADS_LOCKED; }
  264. void SetPadsLocked( bool aPadsLocked )
  265. {
  266. if( aPadsLocked )
  267. m_ModuleStatus |= MODULE_PADS_LOCKED;
  268. else
  269. m_ModuleStatus &= ~MODULE_PADS_LOCKED;
  270. }
  271. void SetLastEditTime( timestamp_t aTime ) { m_LastEditTime = aTime; }
  272. void SetLastEditTime() { m_LastEditTime = time( NULL ); }
  273. timestamp_t GetLastEditTime() const { return m_LastEditTime; }
  274. /* drawing functions */
  275. /**
  276. * function TransformPadsShapesWithClearanceToPolygon
  277. * generate pads shapes on layer aLayer as polygons and adds these polygons to aCornerBuffer
  278. * Useful to generate a polygonal representation of a footprint in 3D view and plot functions,
  279. * when a full polygonal approach is needed
  280. * @param aLayer = the layer to consider, or UNDEFINED_LAYER to consider all
  281. * @param aCornerBuffer = the buffer to store polygons
  282. * @param aClearance = an additionnal size to add to pad shapes
  283. * @param aMaxError = Maximum deviation from true for arcs
  284. * @param aSkipNPTHPadsWihNoCopper = if true, do not add a NPTH pad shape, if the shape has
  285. * same size and position as the hole. Usually, these pads are not drawn on copper
  286. * layers, because there is actually no copper
  287. * Due to diff between layers and holes, these pads must be skipped to be sure
  288. * there is no copper left on the board (for instance when creating Gerber Files or
  289. * 3D shapes). Defaults to false.
  290. * @param aSkipPlatedPads = used on 3D-Viewer to extract plated and nontplated pads.
  291. * @param aSkipNonPlatedPads = used on 3D-Viewer to extract plated and plated pads.
  292. */
  293. void TransformPadsShapesWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  294. PCB_LAYER_ID aLayer,int aClearance,
  295. int aMaxError, ERROR_LOC aErrorLoc,
  296. bool aSkipNPTHPadsWihNoCopper = false,
  297. bool aSkipPlatedPads = false,
  298. bool aSkipNonPlatedPads = false ) const;
  299. /**
  300. * function TransformGraphicShapesWithClearanceToPolygonSet
  301. * generate shapes of graphic items (outlines) on layer aLayer as polygons and adds these
  302. * polygons to aCornerBuffer
  303. * Useful to generate a polygonal representation of a footprint in 3D view and plot functions,
  304. * when a full polygonal approach is needed
  305. * @param aLayer = the layer to consider, or UNDEFINED_LAYER to consider all
  306. * @param aCornerBuffer = the buffer to store polygons
  307. * @param aClearance = a value to inflate shapes
  308. * @param aError = Maximum error between true arc and polygon approx
  309. * @param aIncludeText = True to transform text shapes
  310. * @param aIncludeEdges = True to transform module shapes
  311. */
  312. void TransformGraphicShapesWithClearanceToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
  313. PCB_LAYER_ID aLayer, int aClearance,
  314. int aError, ERROR_LOC aErrorLoc,
  315. bool aIncludeText = true,
  316. bool aIncludeEdges = true ) const;
  317. /**
  318. * @brief TransformGraphicTextWithClearanceToPolygonSet
  319. * This function is the same as TransformGraphicShapesWithClearanceToPolygonSet
  320. * but only generate text
  321. */
  322. void TransformGraphicTextWithClearanceToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
  323. PCB_LAYER_ID aLayer, int aClearance,
  324. int aError, ERROR_LOC aErrorLoc ) const
  325. {
  326. TransformGraphicShapesWithClearanceToPolygonSet( aCornerBuffer, aLayer, aClearance,
  327. aError, aErrorLoc, true, false );
  328. }
  329. /**
  330. * Return the list of system text vars for this footprint.
  331. */
  332. void GetContextualTextVars( wxArrayString* aVars ) const;
  333. /**
  334. * Resolve any references to system tokens supported by the component.
  335. * @param aDepth a counter to limit recursion and circular references.
  336. */
  337. bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
  338. ///> @copydoc EDA_ITEM::GetMsgPanelInfo
  339. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  340. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  341. /**
  342. * Tests if a point is inside the bounding polygon of the module
  343. *
  344. * The other hit test methods are just checking the bounding box, which
  345. * can be quite inaccurate for rotated or oddly-shaped footprints.
  346. *
  347. * @param aPosition is the point to test
  348. * @return true if aPosition is inside the bounding polygon
  349. */
  350. bool HitTestAccurate( const wxPoint& aPosition, int aAccuracy = 0 ) const;
  351. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  352. /**
  353. * Function GetReference
  354. * @return const wxString& - the reference designator text.
  355. */
  356. const wxString GetReference() const
  357. {
  358. return m_Reference->GetText();
  359. }
  360. /**
  361. * Function SetReference
  362. * @param aReference A reference to a wxString object containing the reference designator
  363. * text.
  364. */
  365. void SetReference( const wxString& aReference )
  366. {
  367. m_Reference->SetText( aReference );
  368. }
  369. /**
  370. * Function IncrementReference
  371. * Bumps the current reference by aDelta.
  372. */
  373. void IncrementReference( int aDelta );
  374. /**
  375. * Function GetValue
  376. * @return const wxString& - the value text.
  377. */
  378. const wxString GetValue() const
  379. {
  380. return m_Value->GetText();
  381. }
  382. /**
  383. * Function SetValue
  384. * @param aValue A reference to a wxString object containing the value text.
  385. */
  386. void SetValue( const wxString& aValue )
  387. {
  388. m_Value->SetText( aValue );
  389. }
  390. /// read/write accessors:
  391. FP_TEXT& Value() { return *m_Value; }
  392. FP_TEXT& Reference() { return *m_Reference; }
  393. /// The const versions to keep the compiler happy.
  394. FP_TEXT& Value() const { return *m_Value; }
  395. FP_TEXT& Reference() const { return *m_Reference; }
  396. const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
  397. void SetProperties( const std::map<wxString, wxString>& aProps ) { m_properties = aProps; }
  398. /**
  399. * Function FindPadByName
  400. * returns a D_PAD* with a matching name. Note that names may not be
  401. * unique, depending on how the foot print was created.
  402. * @param aPadName the pad name to find
  403. * @return D_PAD* - The first matching name is returned, or NULL if not found.
  404. */
  405. D_PAD* FindPadByName( const wxString& aPadName ) const;
  406. /**
  407. * Function GetPad
  408. * get a pad at \a aPosition on \a aLayerMask in the footprint.
  409. *
  410. * @param aPosition A wxPoint object containing the position to hit test.
  411. * @param aLayerMask A layer or layers to mask the hit test.
  412. * @return A pointer to a D_PAD object if found otherwise NULL.
  413. */
  414. D_PAD* GetPad( const wxPoint& aPosition, LSET aLayerMask = LSET::AllLayersMask() );
  415. D_PAD* GetTopLeftPad();
  416. /**
  417. * Gets the first pad in the list or NULL if none
  418. * @return first pad or null pointer
  419. */
  420. D_PAD* GetFirstPad() const
  421. {
  422. return m_pads.empty() ? nullptr : m_pads.front();
  423. }
  424. /**
  425. * GetPadCount
  426. * returns the number of pads.
  427. *
  428. * @param aIncludeNPTH includes non-plated through holes when true. Does not include
  429. * non-plated through holes when false.
  430. * @return the number of pads according to \a aIncludeNPTH.
  431. */
  432. unsigned GetPadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const;
  433. /**
  434. * GetUniquePadCount
  435. * returns the number of unique pads.
  436. * A complex pad can be built with many pads having the same pad name
  437. * to create a complex shape or fragmented solder paste areas.
  438. *
  439. * GetUniquePadCount calculate the count of not blank pad names
  440. *
  441. * @param aIncludeNPTH includes non-plated through holes when true. Does not include
  442. * non-plated through holes when false.
  443. * @return the number of unique pads according to \a aIncludeNPTH.
  444. */
  445. unsigned GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const;
  446. /**
  447. * Function GetNextPadName
  448. * returns the next available pad name in the module
  449. *
  450. * @param aFillSequenceGaps true if the numbering should "fill in" gaps in the sequence,
  451. * else return the highest value + 1
  452. * @return the next available pad name
  453. */
  454. wxString GetNextPadName( const wxString& aLastPadName ) const;
  455. double GetArea( int aPadding = 0 ) const;
  456. KIID GetLink() const { return m_Link; }
  457. void SetLink( const KIID& aLink ) { m_Link = aLink; }
  458. int GetPlacementCost180() const { return m_CntRot180; }
  459. void SetPlacementCost180( int aCost ) { m_CntRot180 = aCost; }
  460. int GetPlacementCost90() const { return m_CntRot90; }
  461. void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; }
  462. BOARD_ITEM* Duplicate() const override;
  463. /**
  464. * Function DuplicateItem
  465. * Duplicate a given item within the module, optionally adding it to the board
  466. * @return the new item, or NULL if the item could not be duplicated
  467. */
  468. BOARD_ITEM* DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule = false );
  469. /**
  470. * Function Add3DModel
  471. * adds \a a3DModel definition to the end of the 3D model list.
  472. *
  473. * @param a3DModel A pointer to a #MODULE_3D_SETTINGS to add to the list.
  474. */
  475. void Add3DModel( MODULE_3D_SETTINGS* a3DModel );
  476. SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
  477. wxString GetClass() const override
  478. {
  479. return wxT( "MODULE" );
  480. }
  481. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  482. BITMAP_DEF GetMenuImage() const override;
  483. EDA_ITEM* Clone() const override;
  484. /**
  485. * Function RunOnChildren
  486. *
  487. * Invokes a function on all BOARD_ITEMs that belong to the module (pads, drawings, texts).
  488. * Note that this function should not add or remove items to the module
  489. * @param aFunction is the function to be invoked.
  490. */
  491. void RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction ) const;
  492. /**
  493. * Returns a set of all layers that this module has drawings on similar to ViewGetLayers()
  494. *
  495. * @param aLayers is an array to store layer ids
  496. * @param aCount is the number of layers stored in the array
  497. * @param aIncludePads controls whether to also include pad layers
  498. */
  499. void GetAllDrawingLayers( int aLayers[], int& aCount, bool aIncludePads = true ) const;
  500. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  501. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  502. virtual const BOX2I ViewBBox() const override;
  503. /**
  504. * static function IsLibNameValid
  505. * Test for validity of a name of a footprint to be used in a footprint library
  506. * ( no spaces, dir separators ... )
  507. * @param aName = the name in library to validate
  508. * @return true if the given name is valid
  509. */
  510. static bool IsLibNameValid( const wxString& aName );
  511. /**
  512. * static function StringLibNameInvalidChars
  513. * Test for validity of the name in a library of the footprint
  514. * ( no spaces, dir separators ... )
  515. * @param aUserReadable = false to get the list of invalid chars
  516. * true to get a readable form (i.e ' ' = 'space' '\\t'= 'tab')
  517. * @return a constant std::string giving the list of invalid chars in lib name
  518. */
  519. static const wxChar* StringLibNameInvalidChars( bool aUserReadable );
  520. /**
  521. * Function SetInitialComments
  522. * takes ownership of caller's heap allocated aInitialComments block. The comments
  523. * are single line strings already containing the s-expression comments with optional
  524. * leading whitespace and then a '#' character followed by optional single line text
  525. * (text with no line endings, not even one).
  526. * This block of single line comments will be output upfront of any generated
  527. * s-expression text in the PCBIO::Format() function.
  528. * <p>
  529. * Note that a block of single line comments constitutes a multiline block of single
  530. * line comments. That is, the block is made of consecutive single line comments.
  531. * @param aInitialComments is a heap allocated wxArrayString or NULL, which the caller
  532. * gives up ownership of over to this MODULE.
  533. */
  534. void SetInitialComments( wxArrayString* aInitialComments )
  535. {
  536. delete m_initial_comments;
  537. m_initial_comments = aInitialComments;
  538. }
  539. /**
  540. * Function CoverageRatio
  541. * Calculates the ratio of total area of the footprint pads and graphical items
  542. * to the area of the footprint. Used by selection tool heuristics.
  543. * @return the ratio
  544. */
  545. double CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const;
  546. /// Return the initial comments block or NULL if none, without transfer of ownership.
  547. const wxArrayString* GetInitialComments() const { return m_initial_comments; }
  548. /** Used in DRC to test the courtyard area (a complex polygon)
  549. * @return the courtyard polygon
  550. */
  551. SHAPE_POLY_SET& GetPolyCourtyardFront() { return m_poly_courtyard_front; }
  552. SHAPE_POLY_SET& GetPolyCourtyardBack() { return m_poly_courtyard_back; }
  553. /**
  554. * Builds complex polygons of the courtyard areas from graphic items on the courtyard layers
  555. * @remark sets the MALFORMED_FRONT_COURTYARD and MALFORMED_BACK_COURTYARD status flags if
  556. * the given courtyard layer does not contain a (single) closed shape
  557. */
  558. void BuildPolyCourtyards();
  559. virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;
  560. virtual void SwapData( BOARD_ITEM* aImage ) override;
  561. struct cmp_drawings
  562. {
  563. bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  564. };
  565. struct cmp_pads
  566. {
  567. bool operator()( const D_PAD* aFirst, const D_PAD* aSecond ) const;
  568. };
  569. #if defined(DEBUG)
  570. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  571. #endif
  572. private:
  573. DRAWINGS m_drawings; // BOARD_ITEMs for drawings on the board, owned by pointer.
  574. PADS m_pads; // D_PAD items, owned by pointer
  575. MODULE_ZONE_CONTAINERS m_fp_zones; // MODULE_ZONE_CONTAINER items, owned by pointer
  576. MODULE_GROUPS m_fp_groups; // PCB_GROUP items, owned by pointer
  577. double m_Orient; // Orientation in tenths of a degree, 900=90.0 degrees.
  578. wxPoint m_Pos; // Position of module on the board in internal units.
  579. FP_TEXT* m_Reference; // Component reference designator value (U34, R18..)
  580. FP_TEXT* m_Value; // Component value (74LS00, 22K..)
  581. LIB_ID m_fpid; // The #LIB_ID of the MODULE.
  582. int m_Attributs; // Flag bits ( see Mod_Attribut )
  583. int m_ModuleStatus; // For autoplace: flags (LOCKED, FIELDS_AUTOPLACED)
  584. EDA_RECT m_BoundaryBox; // Bounding box : coordinates on board, real orientation.
  585. ZONE_CONNECTION m_ZoneConnection;
  586. int m_ThermalWidth;
  587. int m_ThermalGap;
  588. int m_LocalClearance;
  589. int m_LocalSolderMaskMargin; // Solder mask margin
  590. int m_LocalSolderPasteMargin; // Solder paste margin absolute value
  591. double m_LocalSolderPasteMarginRatio; // Solder mask margin ratio value of pad size
  592. wxString m_Doc; // File name and path for documentation file.
  593. wxString m_KeyWord; // Search keywords to find module in library.
  594. KIID_PATH m_Path; // Path to associated symbol ([sheetUUID, .., symbolUUID]).
  595. timestamp_t m_LastEditTime;
  596. int m_arflag; // Use to trace ratsnest and auto routing.
  597. KIID m_Link; // Temporary logical link used during editing
  598. int m_CntRot90; // Horizontal automatic placement cost ( 0..10 ).
  599. int m_CntRot180; // Vertical automatic placement cost ( 0..10 ).
  600. std::list<MODULE_3D_SETTINGS> m_3D_Drawings; // Linked list of 3D models.
  601. std::map<wxString, wxString> m_properties;
  602. wxArrayString* m_initial_comments; // s-expression comments in the module,
  603. // lazily allocated only if needed for speed
  604. SHAPE_POLY_SET m_poly_courtyard_front; // Note that a module can have both front and back
  605. SHAPE_POLY_SET m_poly_courtyard_back; // courtyards populated.
  606. };
  607. #endif // MODULE_H_