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.

380 lines
13 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
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
  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 "class_sch_cmp_field.h"
  8. class SCH_SHEET_PATH;
  9. /**
  10. * Holder of an error message and may be thrown from functions.
  11. */
  12. struct Error
  13. {
  14. wxString errorText;
  15. Error( const wxChar* aMsg ) :
  16. errorText( aMsg )
  17. {
  18. }
  19. Error( const wxString& aMsg ) :
  20. errorText( aMsg )
  21. {
  22. }
  23. };
  24. /**
  25. * Enum NumFieldType
  26. * is the numbered set of all fields a SCH_COMPONENT can hold
  27. * Note more than 8 user fields are allowed, but for efficiency reasons
  28. * the defualt number of users fields is 8
  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. DEFAULT_NUMBER_OF_FIELDS
  44. };
  45. /// A container for several SCH_FIELD items
  46. typedef std::vector<SCH_FIELD> SCH_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_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
  79. * per package)
  80. */
  81. wxArrayString m_PathsAndReferences;
  82. void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
  83. public:
  84. SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ),
  85. SCH_ITEM* aParent = NULL );
  86. /**
  87. * Create schematic component from library component object.
  88. *
  89. * @param libComponent - Component library object to create schematic
  90. * component from.
  91. * @param sheet - Schematic sheet the component is place into.
  92. * @param unit - Part for components that have multiple parts per
  93. * package.
  94. * @param convert - Use the alternate body style for the schematic
  95. * component.
  96. * @param pos - Position to place new component.
  97. * @param setNewItemFlag - Set the component IS_NEW and IS_MOVED flags.
  98. */
  99. SCH_COMPONENT( LIB_COMPONENT& libComponent, SCH_SHEET_PATH* sheet,
  100. int unit = 0, int convert = 0,
  101. const wxPoint& pos = wxPoint( 0, 0 ),
  102. bool setNewItemFlag = false );
  103. /**
  104. * Copy Constructor
  105. * clones \a aTemplate into this object. All fields are copied as is except
  106. * for the linked list management pointers which are set to NULL, and the
  107. * SCH_FIELD's m_Parent pointers which are set to the new parent,
  108. * i.e. this new object.
  109. */
  110. SCH_COMPONENT( const SCH_COMPONENT& aTemplate );
  111. ~SCH_COMPONENT() { }
  112. virtual wxString GetClass() const
  113. {
  114. return wxT( "SCH_COMPONENT" );
  115. }
  116. /**
  117. * Function Save
  118. * writes the data structures for this object out to a FILE in "*.brd"
  119. * format.
  120. * @param aFile The FILE to write to.
  121. * @return bool - true if success writing else false.
  122. */
  123. bool Save( FILE* aFile ) const;
  124. /**
  125. * Function Load
  126. * reads a component in from a file. The file stream must be positioned at
  127. * the first field of the file, not at the component tag.
  128. * @param aFile The FILE to read from.
  129. * @throw Error containing the error message text if there is a file format
  130. * error or if the disk read has failed.
  131. * void Load( FILE* aFile ) throw( Error );
  132. */
  133. /**
  134. * Function GenCopy
  135. * returns a copy of this object but with the linked list pointers
  136. * set to NULL.
  137. * @return SCH_COMPONENT* - a copy of me.
  138. */
  139. SCH_COMPONENT* GenCopy()
  140. {
  141. return new SCH_COMPONENT( *this );
  142. }
  143. void SetOrientation( int aOrientation );
  144. /** function GetOrientation()
  145. * Used to display component orientation (in dialog editor or info)
  146. * @return the orientation and mirror
  147. * Note: Because there are different ways to have a given orientation/mirror,
  148. * the orientation/mirror is not necessary what the used does
  149. * (example : a mirrorX then a mirrorY give no mirror but rotate the
  150. * component).
  151. * So this function find a rotation and a mirror value
  152. * ( CMP_MIRROR_X because this is the first mirror option tested)
  153. * but can differs from the orientation made by an user
  154. * ( a CMP_MIRROR_Y is find as a CMP_MIRROR_X + orientation 180, because
  155. * they are equivalent)
  156. */
  157. int GetOrientation();
  158. wxPoint GetScreenCoord( const wxPoint& coord );
  159. void DisplayInfo( WinEDA_DrawFrame* frame );
  160. /**
  161. * Suppress annotation ( i.i IC23 changed to IC? and part reset to 1)
  162. * @param aSheet: SCH_SHEET_PATH value: if NULL remove all annotations,
  163. * else remove annotation relative to this sheetpath
  164. */
  165. void ClearAnnotation( SCH_SHEET_PATH* aSheet );
  166. /** function SetTimeStamp
  167. * Change the old time stamp to the new time stamp.
  168. * the time stamp is also modified in paths
  169. * @param aNewTimeStamp = new time stamp
  170. */
  171. void SetTimeStamp( long aNewTimeStamp);
  172. /**
  173. * Function GetBoundaryBox
  174. * returns the orthogonal, bounding box of this object for display purposes.
  175. * This box should be an enclosing perimeter for graphic items and pins.
  176. * this include only fields defined in library
  177. * use GetBoundingBox() to include fields in schematic
  178. */
  179. EDA_Rect GetBoundaryBox() const;
  180. /**
  181. * Function GetBoundingBox
  182. * returns the orthogonal, bounding box of this object for display purposes.
  183. * This box should be an enclosing perimeter for visible components of this
  184. * object, and the units should be in the pcb or schematic coordinate system.
  185. * It is OK to overestimate the size by a few counts.
  186. */
  187. EDA_Rect GetBoundingBox();
  188. /**
  189. * Function ReturnFieldName
  190. * returns the Field name given a field index like (REFERENCE, VALUE ..)
  191. * @reeturn wxString - the field name or wxEmptyString if invalid field
  192. * index.
  193. */
  194. wxString ReturnFieldName( int aFieldNdx ) const;
  195. /**
  196. * Function GetField
  197. * returns a field.
  198. * @param aFieldNdx An index into the array of fields
  199. * @return SCH_FIELD* - the field value or NULL if does not exist
  200. */
  201. SCH_FIELD* GetField( int aFieldNdx ) const;
  202. /**
  203. * Function AddField
  204. * adds a field to the component. The field is copied as it is put into
  205. * the component.
  206. * @param aField A const reference to the SCH_FIELD to add.
  207. */
  208. void AddField( const SCH_FIELD& aField );
  209. void SetFields( const SCH_FIELDS& aFields )
  210. {
  211. m_Fields = aFields; // vector copying, length is changed possibly
  212. }
  213. /**
  214. * Function GetFieldCount
  215. * returns the number of fields in this component.
  216. */
  217. int GetFieldCount() const { return (int) m_Fields.size(); }
  218. /**
  219. * Find a component pin by number.
  220. *
  221. * @param number - The number of the pin to find.
  222. * @return Pin object if found, otherwise NULL.
  223. */
  224. LIB_PIN* GetPin( const wxString& number );
  225. virtual void Draw( WinEDA_DrawPanel* panel,
  226. wxDC* DC,
  227. const wxPoint& offset,
  228. int draw_mode,
  229. int Color = -1 )
  230. {
  231. Draw( panel, DC, offset, draw_mode, Color, true );
  232. }
  233. void Draw( WinEDA_DrawPanel* panel,
  234. wxDC* DC,
  235. const wxPoint& offset,
  236. int draw_mode,
  237. int Color,
  238. bool DrawPinText );
  239. void SwapData( SCH_COMPONENT* copyitem );
  240. void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
  241. // returns a unique ID, in the form of a path.
  242. wxString GetPath( SCH_SHEET_PATH* sheet );
  243. /**
  244. * Function GetRef
  245. * returns the reference, for the given sheet path.
  246. */
  247. const wxString GetRef( SCH_SHEET_PATH* sheet );
  248. // Set the reference, for the given sheet path.
  249. void SetRef( SCH_SHEET_PATH* sheet, const wxString& ref );
  250. /**
  251. * Function AddHierarchicalReference
  252. * adds a full hierarchical reference (path + local reference)
  253. * @param aPath = hierarchical path (/<sheet timestamp>/component
  254. * timestamp> like /05678E50/A23EF560)
  255. * @param aRef = local reference like C45, R56
  256. * @param aMulti = part selection, used in multi part per package (0 or 1
  257. * for non multi)
  258. */
  259. void AddHierarchicalReference( const wxString& aPath,
  260. const wxString& aRef,
  261. int aMulti );
  262. // returns the unit selection, for the given sheet path.
  263. int GetUnitSelection( SCH_SHEET_PATH* aSheet );
  264. // Set the unit selection, for the given sheet path.
  265. void SetUnitSelection( SCH_SHEET_PATH* aSheet,
  266. int aUnitSelection );
  267. /** Function GetPenSize
  268. * @return the size of the "pen" that be used to draw or plot this item
  269. * for a component, has no meaning, but it is necessary to satisfy the
  270. * SCH_ITEM class requirements.
  271. */
  272. virtual int GetPenSize( ) { return 0; }
  273. // Geometric transforms (used in block operations):
  274. /** virtual function Move
  275. * move item to a new position.
  276. * @param aMoveVector = the displacement vector
  277. */
  278. virtual void Move( const wxPoint& aMoveVector )
  279. {
  280. m_Pos += aMoveVector;
  281. for( int ii = 0; ii < GetFieldCount(); ii++ )
  282. GetField( ii )->Move( aMoveVector );
  283. }
  284. /** virtual function Mirror_Y
  285. * mirror item relative to an Y axis
  286. * @param aYaxis_position = the y axis position
  287. */
  288. virtual void Mirror_Y(int aYaxis_position);
  289. /**
  290. * Compare schematic component reference and value fields against search string.
  291. *
  292. * @param aSearchData - Criteria to search against.
  293. * @param aAuxData - a pointer on auxiliary data, if needed.
  294. * When searching string in REFERENCE field we must know the sheet path
  295. * This param is used in this case
  296. * @return True if this component reference or value field matches the search criteria.
  297. */
  298. virtual bool Matches( wxFindReplaceData& aSearchData, void * aAuxData );
  299. #if defined (DEBUG)
  300. /**
  301. * Function Show
  302. * is used to output the object tree, currently for debugging only.
  303. * @param nestLevel An aid to prettier tree indenting, and is the level
  304. * of nesting of this object within the overall tree.
  305. * @param os The ostream& to output to.
  306. */
  307. void Show( int nestLevel, std::ostream& os );
  308. #endif
  309. };
  310. #endif /* COMPONENT_CLASS_H */