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.

392 lines
13 KiB

14 years ago
18 years ago
14 years ago
14 years ago
14 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /**
  2. * @file class_module.h
  3. * @brief Module description (excepted pads)
  4. */
  5. #ifndef _MODULE_H_
  6. #define _MODULE_H_
  7. #include "dlist.h"
  8. #include "layers_id_colors_and_visibility.h" // ALL_LAYERS definition.
  9. #include "class_board_item.h"
  10. #include "class_text_mod.h"
  11. class LINE_READER;
  12. class EDA_3D_CANVAS;
  13. class S3D_MASTER;
  14. class EDA_DRAW_PANEL;
  15. class D_PAD;
  16. class BOARD;
  17. /**
  18. * Enum MODULE_ATTR_T
  19. * is the set of attributes allowed within a MODULE, using MODULE::SetAttributes()
  20. * and MODULE::GetAttributes(). These are to be ORed together when calling
  21. * MODULE::SetAttrbute()
  22. */
  23. enum MODULE_ATTR_T
  24. {
  25. MOD_DEFAULT = 0, ///< default
  26. MOD_CMS = 1, ///< Set for modules listed in the automatic insertion list
  27. ///< (usually SMD footprints)
  28. MOD_VIRTUAL = 2 ///< Virtual component: when created by copper shapes on
  29. ///< board (Like edge card connectors, mounting hole...)
  30. };
  31. class MODULE : public BOARD_ITEM
  32. {
  33. public:
  34. double m_Orient; // orientation in 0.1 degrees
  35. wxPoint m_Pos; // Real coord on board
  36. DLIST<D_PAD> m_Pads; /* Pad list (linked list) */
  37. DLIST<BOARD_ITEM> m_Drawings; /* Graphic items list (linked list) */
  38. DLIST<S3D_MASTER> m_3D_Drawings; /* First item of the 3D shapes (linked list)*/
  39. TEXTE_MODULE* m_Reference; // Component reference (U34, R18..)
  40. TEXTE_MODULE* m_Value; // Component value (74LS00, 22K..)
  41. wxString m_LibRef; /* Name of the module in library (and
  42. * the default value when loading a
  43. * module from the library) */
  44. wxString m_AlternateReference; /* Used when m_Reference cannot
  45. * be used to identify the
  46. * footprint ( after a full
  47. * reannotation of the schematic */
  48. int m_Attributs; ///< Flag bits ( see Mod_Attribut )
  49. int flag; /* Use to trace ratsnest and auto routing. */
  50. int m_ModuleStatus; ///< For autoplace: flags (LOCKED, AUTOPLACED)
  51. // m_ModuleStatus bits:
  52. #define MODULE_is_LOCKED 0x01 ///< module LOCKED: no autoplace allowed
  53. #define MODULE_is_PLACED 0x02 ///< In autoplace: module automatically placed
  54. #define MODULE_to_PLACE 0x04 ///< In autoplace: module waiting for autoplace
  55. EDA_RECT m_BoundaryBox; // Bounding box : coordinates on board, real orientation.
  56. int m_PadNum; // Pad count
  57. int m_AltPadNum; /* Pad with netcode > 0 (active pads) count */
  58. int m_CntRot90; ///< Automatic placement : cost ( 0..10 )
  59. ///< for 90 degrees rotation (Horiz<->Vertical)
  60. int m_CntRot180; ///< Automatic placement : cost ( 0..10 )
  61. ///< for 180 degrees rotation (UP <->Down)
  62. wxSize m_Ext; /* Automatic placement margin around the module */
  63. double m_Surface; // Bounding box area
  64. unsigned long m_Link; /* Temporary variable ( used in editions, ...) */
  65. long m_LastEdit_Time;
  66. wxString m_Path;
  67. wxString m_Doc; // Module Description (info for users)
  68. wxString m_KeyWord; // Keywords to select the module in lib
  69. // Local tolerances. When zero, this means the corresponding netclass value
  70. // is used. Usually theses local tolerances zero, in deference to the
  71. // corresponding netclass values.
  72. int m_LocalClearance;
  73. int m_LocalSolderMaskMargin; ///< Solder mask margin
  74. int m_LocalSolderPasteMargin; ///< Solder paste margin
  75. ///< absolute value
  76. double m_LocalSolderPasteMarginRatio; ///< Solder mask margin ratio
  77. ///< value of pad size
  78. // The final margin is the sum of these 2 values
  79. public:
  80. MODULE( BOARD* parent );
  81. MODULE( MODULE* module );
  82. ~MODULE();
  83. MODULE* Next() const { return (MODULE*) Pnext; }
  84. MODULE* Back() const { return (MODULE*) Pback; }
  85. void Copy( MODULE* Module ); // Copy structure
  86. /*
  87. * Function Add
  88. * adds the given item to this MODULE and takes ownership of its memory.
  89. * @param aBoardItem The item to add to this board.
  90. * @param doInsert If true, then insert, else append
  91. * void Add( BOARD_ITEM* aBoardItem, bool doInsert = true );
  92. */
  93. /**
  94. * Function CalculateBoundingBox
  95. * calculates the bounding box in board coordinates.
  96. */
  97. void CalculateBoundingBox();
  98. /**
  99. * Function GetFootPrintRect()
  100. * Returns the area of the module footprint excluding any text.
  101. * @return EDA_RECT - The rectangle containing the footprint.
  102. */
  103. EDA_RECT GetFootPrintRect() const;
  104. /**
  105. * Function GetBoundingBox
  106. * returns the bounding box of this
  107. * footprint. Mainly used to redraw the screen area occupied by
  108. * the footprint.
  109. * @return EDA_RECT - The rectangle containing the footprint and texts.
  110. */
  111. EDA_RECT GetBoundingBox() const;
  112. void SetPosition( const wxPoint& aPos ); // overload
  113. const wxPoint GetPosition() const { return m_Pos; } // overload
  114. void SetOrientation( double newangle );
  115. double GetOrientation() const { return m_Orient; }
  116. const wxString& GetLibRef() const { return m_LibRef; }
  117. void SetLibRef( const wxString& aLibRef ) { m_LibRef = aLibRef; }
  118. const wxString& GetDescription() const { return m_Doc; }
  119. void SetDescription( const wxString& aDoc ) { m_Doc = aDoc; }
  120. const wxString& GetKeywords() const { return m_KeyWord; }
  121. void SetKeywords( const wxString& aKeywords ) { m_KeyWord = aKeywords; }
  122. const wxString& GetPath() const { return m_Path; }
  123. void SetPath( const wxString& aPath ) { m_Path = aPath; }
  124. int GetLocalSolderMaskMargin() const { return m_LocalSolderMaskMargin; }
  125. void SetLocalSolderMaskMargin( int aMargin ) { m_LocalSolderMaskMargin = aMargin; }
  126. int GetLocalClearance() const { return m_LocalClearance; }
  127. void SetLocalClearance( int aClearance ) { m_LocalClearance = aClearance; }
  128. int GetLocalSolderPasteMargin() const { return m_LocalSolderPasteMargin; }
  129. void SetLocalSolderPasteMargin( int aMargin ) { m_LocalSolderPasteMargin = aMargin; }
  130. double GetLocalSolderPasteMarginRatio() const { return m_LocalSolderPasteMarginRatio; }
  131. void SetLocalSolderPasteMarginRatio( double aRatio ) { m_LocalSolderPasteMarginRatio = aRatio; }
  132. int GetAttributes() const { return m_Attributs; }
  133. void SetAttributes( int aAttributes ) { m_Attributs = aAttributes; }
  134. /**
  135. * Function Move
  136. * move this object.
  137. * @param aMoveVector - the move vector for this object.
  138. */
  139. virtual void Move( const wxPoint& aMoveVector );
  140. /**
  141. * Function Rotate
  142. * Rotate this object.
  143. * @param aRotCentre - the rotation point.
  144. * @param aAngle - the rotation angle in 0.1 degree.
  145. */
  146. virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
  147. /**
  148. * Function Flip
  149. * Flip this object, i.e. change the board side for this object
  150. * @param aCentre - the rotation point.
  151. */
  152. virtual void Flip( const wxPoint& aCentre );
  153. /**
  154. * Function IsLocked
  155. * (virtual from BOARD_ITEM )
  156. * @return bool - true if the MODULE is locked, else false
  157. */
  158. bool IsLocked() const
  159. {
  160. return (m_ModuleStatus & MODULE_is_LOCKED) != 0;
  161. }
  162. /**
  163. * Function SetLocked
  164. * sets the MODULE_is_LOCKED bit in the m_ModuleStatus
  165. * @param isLocked When true means turn on locked status, else unlock
  166. */
  167. void SetLocked( bool isLocked )
  168. {
  169. if( isLocked )
  170. m_ModuleStatus |= MODULE_is_LOCKED;
  171. else
  172. m_ModuleStatus &= ~MODULE_is_LOCKED;
  173. }
  174. bool IsPlaced() const { return (m_ModuleStatus & MODULE_is_PLACED); }
  175. void SetIsPlaced( bool isPlaced )
  176. {
  177. if( isPlaced )
  178. m_ModuleStatus |= MODULE_is_PLACED;
  179. else
  180. m_ModuleStatus &= ~MODULE_is_PLACED;
  181. }
  182. void SetLastEditTime( long aTime ) { m_LastEdit_Time = aTime; }
  183. long GetLastEditTime() const { return m_LastEdit_Time; }
  184. /* Reading and writing data on files */
  185. /**
  186. * Function Save
  187. * writes the data structures for this object out to a FILE in "*.brd"
  188. * format.
  189. * @param aFile The FILE to write to.
  190. * @return bool - true if success writing else false.
  191. */
  192. bool Save( FILE* aFile ) const;
  193. int Write_3D_Descr( FILE* File ) const;
  194. int ReadDescr( LINE_READER* aReader );
  195. /**
  196. * Function Read_GPCB_Descr
  197. * reads a footprint description in GPCB format (newlib version)
  198. * @param CmpFullFileName = Full file name (there is one footprint per file.
  199. * this is also the footprint name
  200. * @return bool - true if success reading else false.
  201. */
  202. bool Read_GPCB_Descr( const wxString& CmpFullFileName );
  203. int Read_3D_Descr( LINE_READER* aReader );
  204. /* drawing functions */
  205. /**
  206. * Function Draw
  207. * Draw the text according to the footprint pos and orient
  208. * @param aPanel = draw panel, Used to know the clip box
  209. * @param aDC = Current Device Context
  210. * @param aDrawMode = GR_OR, GR_XOR..
  211. * @param aOffset = draw offset (usually wxPoint(0,0)
  212. */
  213. void Draw( EDA_DRAW_PANEL* aPanel,
  214. wxDC* aDC,
  215. int aDrawMode,
  216. const wxPoint& aOffset = ZeroOffset );
  217. void Draw3D( EDA_3D_CANVAS* glcanvas );
  218. void DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, int draw_mode );
  219. void DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC,
  220. const wxPoint& offset, int dim_ancre, int draw_mode );
  221. /**
  222. * Function DisplayInfo
  223. * has knowledge about the frame and how and where to put status information
  224. * about this object into the frame's message panel.
  225. * @param frame A EDA_DRAW_FRAME in which to print status information.
  226. */
  227. void DisplayInfo( EDA_DRAW_FRAME* frame );
  228. /**
  229. * Function HitTest
  230. * tests if the given wxPoint is within the bounds of this object.
  231. * @param aRefPos is a wxPoint to test.
  232. * @return bool - true if a hit, else false.
  233. */
  234. bool HitTest( const wxPoint& aRefPos );
  235. /**
  236. * Function HitTest (overlaid)
  237. * tests if the given EDA_RECT intersect the bounds of this object.
  238. * @param aRefArea is the given EDA_RECT.
  239. * @return bool - true if a hit, else false.
  240. */
  241. bool HitTest( EDA_RECT& aRefArea );
  242. /**
  243. * Function GetReference
  244. * @return const wxString& - the reference designator text.
  245. */
  246. const wxString& GetReference() const
  247. {
  248. return m_Reference->m_Text;
  249. }
  250. /**
  251. * Function GetValue
  252. * @return const wxString& - the value text.
  253. */
  254. const wxString& GetValue()
  255. {
  256. return m_Value->m_Text;
  257. }
  258. /**
  259. * Function FindPadByName
  260. * returns a D_PAD* with a matching name. Note that names may not be
  261. * unique, depending on how the foot print was created.
  262. * @param aPadName the pad name to find
  263. * @return D_PAD* - The first matching name is returned, or NULL if not
  264. * found.
  265. */
  266. D_PAD* FindPadByName( const wxString& aPadName ) const;
  267. /**
  268. * Function GetPad
  269. * get a pad at \a aPosition on \a aLayer in the footprint.
  270. *
  271. * @param aPosition A wxPoint object containing the position to hit test.
  272. * @param aLayerMask A layer or layers to mask the hit test.
  273. * @return A pointer to a D_PAD object if found otherwise NULL.
  274. */
  275. D_PAD* GetPad( const wxPoint& aPosition, int aLayerMask = ALL_LAYERS );
  276. /**
  277. * Function Visit
  278. * should be re-implemented for each derived class in order to handle
  279. * all the types given by its member data. Implementations should call
  280. * inspector->Inspect() on types in scanTypes[], and may use IterateForward()
  281. * to do so on lists of such data.
  282. * @param inspector An INSPECTOR instance to use in the inspection.
  283. * @param testData Arbitrary data used by the inspector.
  284. * @param scanTypes Which KICAD_T types are of interest and the order
  285. * is significant too, terminated by EOT.
  286. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
  287. * else SCAN_CONTINUE;
  288. */
  289. SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
  290. const KICAD_T scanTypes[] );
  291. /**
  292. * Function GetClass
  293. * returns the class name.
  294. * @return wxString
  295. */
  296. virtual wxString GetClass() const
  297. {
  298. return wxT( "MODULE" );
  299. }
  300. virtual wxString GetSelectMenuText() const;
  301. virtual BITMAP_DEF GetMenuImage() const { return module_xpm; }
  302. #if defined(DEBUG)
  303. /**
  304. * Function Show
  305. * is used to output the object tree, currently for debugging only.
  306. * @param nestLevel An aid to prettier tree indenting, and is the level
  307. * of nesting of this object within the overall tree.
  308. * @param os The ostream& to output to.
  309. */
  310. virtual void Show( int nestLevel, std::ostream& os );
  311. #endif
  312. };
  313. #endif // _MODULE_H_