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.

350 lines
11 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
17 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*****************************************************/
  2. /* Definitions for the Component classes for EESchema */
  3. /*****************************************************/
  4. #ifndef COMPONENT_CLASS_H
  5. #define COMPONENT_CLASS_H
  6. #include "class_sch_screen.h"
  7. #include <wx/arrstr.h>
  8. #include <wx/dynarray.h>
  9. #include "class_sch_cmp_field.h"
  10. WX_DECLARE_OBJARRAY( DrawSheetPath, ArrayOfSheetLists );
  11. /**
  12. * Holder of an error message and may be thrown from functions.
  13. */
  14. struct Error
  15. {
  16. wxString errorText;
  17. Error( const wxChar* aMsg ) :
  18. errorText( aMsg )
  19. {
  20. }
  21. Error( const wxString& aMsg ) :
  22. errorText( aMsg )
  23. {
  24. }
  25. };
  26. /**
  27. * Enum NumFieldType
  28. * is the numbered set of all fields a SCH_COMPONENT can hold
  29. */
  30. enum NumFieldType {
  31. REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
  32. VALUE, ///< Field Value of part, i.e. "3.3K"
  33. FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300"
  34. DATASHEET, ///< name of datasheet
  35. FIELD1,
  36. FIELD2,
  37. FIELD3,
  38. FIELD4,
  39. FIELD5,
  40. FIELD6,
  41. FIELD7,
  42. FIELD8,
  43. NUMBER_OF_FIELDS
  44. };
  45. /// A container for several SCH_CMP_FIELD items
  46. typedef std::vector<SCH_CMP_FIELD> SCH_CMP_FIELDS;
  47. /**
  48. * Class SCH_COMPONENT
  49. * describes a real schematic component
  50. */
  51. class SCH_COMPONENT : public SCH_ITEM
  52. {
  53. friend class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC;
  54. public:
  55. int m_Multi; // In multi unit chip - which unit to draw.
  56. wxPoint m_Pos;
  57. wxString m_ChipName; /* Key to look for in the library,
  58. * i.e. "74LS00". */
  59. wxString m_PrefixString; /* C, R, U, Q etc - the first character
  60. * which typically indicates what the
  61. * component is. Determined, upon
  62. * placement, from the library component.
  63. * determined, upon file load, by the
  64. * first non-digits in the reference
  65. * fields. */
  66. int m_Convert; /* Handle multiple shape (for instance
  67. * De Morgan conversion) */
  68. int m_Transform[2][2]; /* The rotation/mirror transformation
  69. * matrix. */
  70. private:
  71. SCH_CMP_FIELDS m_Fields; ///< variable length list of fields
  72. /* Hierarchical references.
  73. * format is
  74. * path reference multi
  75. * with:
  76. * path = /<timestamp1>/<timestamp2> (subsheet path, = / for the root sheet)
  77. * reference = reference for this path (C23, R5, U78 ... )
  78. * multi = part selection in multi parts per package (0 or 1 for one part per package)
  79. */
  80. wxArrayString m_PathsAndReferences;
  81. void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
  82. public:
  83. SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ),
  84. SCH_ITEM* aParent = NULL );
  85. /**
  86. * Create schematic component from library component object.
  87. *
  88. * @param libComponent - Component library object to create schematic
  89. * component from.
  90. * @param sheet - Schematic sheet the component is place into.
  91. * @param unit - Part for components that have multiple parts per
  92. * package.
  93. * @param convert - Use the alternate body style for the schematic
  94. * component.
  95. * @param pos - Position to place new component.
  96. * @param setNewItemFlag - Set the component IS_NEW and IS_MOVED flags.
  97. */
  98. SCH_COMPONENT( LIB_COMPONENT& libComponent, DrawSheetPath* sheet,
  99. int unit = 0, int convert = 0,
  100. const wxPoint& pos = wxPoint( 0, 0 ),
  101. bool setNewItemFlag = false );
  102. /**
  103. * Copy Constructor
  104. * clones \a aTemplate into this object. All fields are copied as is except
  105. * for the linked list management pointers which are set to NULL, and the
  106. * SCH_CMP_FIELD's m_Parent pointers which are set to the new parent,
  107. * i.e. this new object.
  108. */
  109. SCH_COMPONENT( const SCH_COMPONENT& aTemplate );
  110. ~SCH_COMPONENT() { }
  111. virtual wxString GetClass() const
  112. {
  113. return wxT( "SCH_COMPONENT" );
  114. }
  115. /**
  116. * Function Save
  117. * writes the data structures for this object out to a FILE in "*.brd"
  118. * format.
  119. * @param aFile The FILE to write to.
  120. * @return bool - true if success writing else false.
  121. */
  122. bool Save( FILE* aFile ) const;
  123. /**
  124. * Function Load
  125. * reads a component in from a file. The file stream must be positioned at
  126. * the first field of the file, not at the component tag.
  127. * @param aFile The FILE to read from.
  128. * @throw Error containing the error message text if there is a file format
  129. * error or if the disk read has failed.
  130. void Load( FILE* aFile ) throw( Error );
  131. */
  132. /**
  133. * Function GenCopy
  134. * returns a copy of this object but with the linked list pointers
  135. * set to NULL.
  136. * @return SCH_COMPONENT* - a copy of me.
  137. */
  138. SCH_COMPONENT* GenCopy()
  139. {
  140. return new SCH_COMPONENT( *this );
  141. }
  142. void SetRotationMiroir( int type );
  143. /** function GetRotationMiroir()
  144. * Used to display component orientation (in dialog editor or info)
  145. * @return the orientation and mirror
  146. * Note: Because there are different ways to have a given orientation/mirror,
  147. * the orientation/mirror is not necessary wht the used does
  148. * (example : a mirrorX then a mirrorY give no mirror but rotate the component).
  149. * So this function find a rotation and a mirror value
  150. * ( CMP_MIROIR_X because this is the first mirror option tested)
  151. * but can differs from the orientation made by an user
  152. * ( a CMP_MIROIR_Y is find as a CMP_MIROIR_X + orientation 180, because they are equivalent)
  153. */
  154. int GetRotationMiroir();
  155. wxPoint GetScreenCoord( const wxPoint& coord );
  156. void DisplayInfo( WinEDA_DrawFrame* frame );
  157. /**
  158. * Suppress annotation ( i.i IC23 changed to IC? and part reset to 1)
  159. * @param aSheet: DrawSheetPath value: if NULL remove all annotations,
  160. * else remove annotation relative to this sheetpath
  161. */
  162. void ClearAnnotation( DrawSheetPath* aSheet );
  163. /** function SetTimeStamp
  164. * Change the old time stamp to the new time stamp.
  165. * the time stamp is also modified in paths
  166. * @param aNewTimeStamp = new time stamp
  167. */
  168. void SetTimeStamp( long aNewTimeStamp);
  169. EDA_Rect GetBoundaryBox() const;
  170. EDA_Rect GetBoundingBox();
  171. /**
  172. * Function ReturnFieldName
  173. * returns the Field name given a field index like (REFERENCE, VALUE ..)
  174. * @reeturn wxString - the field name or wxEmptyString if invalid field
  175. * index.
  176. */
  177. wxString ReturnFieldName( int aFieldNdx ) const;
  178. /**
  179. * Function GetField
  180. * returns a field.
  181. * @param aFieldNdx An index into the array of fields
  182. * @return SCH_CMP_FIELD* - the field value or NULL if does not exist
  183. */
  184. SCH_CMP_FIELD* GetField( int aFieldNdx ) const;
  185. /**
  186. * Function AddField
  187. * adds a field to the component. The field is copied as it is put into
  188. * the component.
  189. * @param aField A const reference to the SCH_CMP_FIELD to add.
  190. */
  191. void AddField( const SCH_CMP_FIELD& aField );
  192. void SetFields( const SCH_CMP_FIELDS& aFields )
  193. {
  194. m_Fields = aFields; // vector copying, length is changed possibly
  195. }
  196. /**
  197. * Function GetFieldCount
  198. * returns the number of fields in this component.
  199. */
  200. int GetFieldCount() const { return (int) m_Fields.size(); }
  201. /**
  202. * Find a component pin by number.
  203. *
  204. * @param number - The number of the pin to find.
  205. * @return Pin object if found, otherwise NULL.
  206. */
  207. LIB_PIN* GetPin( const wxString& number );
  208. virtual void Draw( WinEDA_DrawPanel* panel,
  209. wxDC* DC,
  210. const wxPoint& offset,
  211. int draw_mode,
  212. int Color = -1 )
  213. {
  214. Draw( panel, DC, offset, draw_mode, Color, true );
  215. }
  216. void Draw( WinEDA_DrawPanel* panel,
  217. wxDC* DC,
  218. const wxPoint& offset,
  219. int draw_mode,
  220. int Color,
  221. bool DrawPinText );
  222. void SwapData( SCH_COMPONENT* copyitem );
  223. void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
  224. // returns a unique ID, in the form of a path.
  225. wxString GetPath( DrawSheetPath* sheet );
  226. /**
  227. * Function GetRef
  228. * returns the reference, for the given sheet path.
  229. */
  230. const wxString GetRef( DrawSheetPath* sheet );
  231. // Set the reference, for the given sheet path.
  232. void SetRef( DrawSheetPath* sheet, const wxString& ref );
  233. /**
  234. * Function AddHierarchicalReference
  235. * adds a full hierachical reference (path + local reference)
  236. * @param aPath = hierarchical path (/<sheet timestamp>/component
  237. * timestamp> like /05678E50/A23EF560)
  238. * @param aRef = local reference like C45, R56
  239. * @param aMulti = part selection, used in multi part per package (0 or 1
  240. * for non multi)
  241. */
  242. void AddHierarchicalReference( const wxString& aPath,
  243. const wxString& aRef,
  244. int aMulti );
  245. //returns the unit selection, for the given sheet path.
  246. int GetUnitSelection( DrawSheetPath* aSheet );
  247. //Set the unit selection, for the given sheet path.
  248. void SetUnitSelection( DrawSheetPath* aSheet,
  249. int aUnitSelection );
  250. /** Function GetPenSize
  251. * @return the size of the "pen" that be used to draw or plot this item
  252. * for a component, has no meaning, but it is necessary to satisfy the SCH_ITEM class requirements
  253. */
  254. virtual int GetPenSize( ) { return 0; }
  255. // Geometric transforms (used in block operations):
  256. /** virtual function Move
  257. * move item to a new position.
  258. * @param aMoveVector = the displacement vector
  259. */
  260. virtual void Move(const wxPoint& aMoveVector)
  261. {
  262. m_Pos += aMoveVector;
  263. for( int ii = 0; ii < GetFieldCount(); ii++ )
  264. GetField( ii )->Move(aMoveVector);
  265. }
  266. /** virtual function Mirror_Y
  267. * mirror item relative to an Y axis
  268. * @param aYaxis_position = the y axis position
  269. */
  270. virtual void Mirror_Y(int aYaxis_position);
  271. #if defined (DEBUG)
  272. /**
  273. * Function Show
  274. * is used to output the object tree, currently for debugging only.
  275. * @param nestLevel An aid to prettier tree indenting, and is the level
  276. * of nesting of this object within the overall tree.
  277. * @param os The ostream& to output to.
  278. */
  279. void Show( int nestLevel, std::ostream& os );
  280. #endif
  281. };
  282. #endif /* COMPONENT_CLASS_H */