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.

481 lines
15 KiB

  1. /****************************************************************/
  2. /* Headers fo library definition and lib component definitions */
  3. /****************************************************************/
  4. #ifndef CLASSES_BODY_ITEMS_H
  5. #define CLASSES_BODY_ITEMS_H
  6. #define TARGET_PIN_DIAM 12 /* Circle diameter drawn at the active end of pins */
  7. #define DEFAULT_TEXT_SIZE 50 /* Default size for field texts */
  8. #define PART_NAME_LEN 15 /* Maximum length of part name. */
  9. #define PREFIX_NAME_LEN 5 /* Maximum length of prefix (IC, R, SW etc.). */
  10. #define PIN_WIDTH 100 /* Width between 2 pins in internal units. */
  11. #define PIN_LENGTH 300 /* Default Length of each pin to be drawn. */
  12. #define INVERT_PIN_RADIUS 35 /* Radius of inverted pin circle. */
  13. #define CLOCK_PIN_DIM 40 /* Dim of clock pin symbol. */
  14. #define IEEE_SYMBOL_PIN_DIM 40 /* Dim of special pin symbol. */
  15. /**
  16. * Enum FILL_T
  17. * is the set of fill types used in plotting or drawing enclosed areas.
  18. */
  19. enum FILL_T {
  20. NO_FILL, // Poly, Square, Circle, Arc = option No Fill
  21. FILLED_SHAPE, // Poly, Square, Circle, Arc = option Fill with current color ("Solid shape")
  22. FILLED_WITH_BG_BODYCOLOR, /* Poly, Square, Circle, Arc = option Fill with background body color,
  23. * translucent (texts inside this shape can be seen)
  24. * not filled in B&W mode when plotting or printing
  25. */
  26. };
  27. /**
  28. * Enum ElectricPinType
  29. * is the set of schematic pin types, used in ERC tests.
  30. */
  31. enum ElectricPinType { /* Type des Pins. si modif: modifier tableau des mgs suivant */
  32. PIN_INPUT,
  33. PIN_OUTPUT,
  34. PIN_BIDI,
  35. PIN_TRISTATE,
  36. PIN_PASSIVE,
  37. PIN_UNSPECIFIED,
  38. PIN_POWER_IN,
  39. PIN_POWER_OUT,
  40. PIN_OPENCOLLECTOR,
  41. PIN_OPENEMITTER,
  42. PIN_NC, /* No connect */
  43. PIN_NMAX /* End of List (no used as pin type) */
  44. };
  45. /* Messages d'affichage du type electrique */
  46. eda_global const wxChar* MsgPinElectricType[]
  47. #ifdef MAIN
  48. = {
  49. wxT( "input" ),
  50. wxT( "output" ),
  51. wxT( "BiDi" ),
  52. wxT( "3state" ),
  53. wxT( "passive" ),
  54. wxT( "unspc" ),
  55. wxT( "power_in" ),
  56. wxT( "power_out" ),
  57. wxT( "openCol" ),
  58. wxT( "openEm" ),
  59. wxT( "?????" )
  60. }
  61. #endif
  62. ;
  63. /* Autres bits: bits du membre .Flag des Pins */
  64. #define PINNOTDRAW 1 /* si 1: pin invisible */
  65. /**
  66. * Enum DrawPinShape
  67. * is the set of shapes allowed for pins.
  68. */
  69. enum DrawPinShape {
  70. NONE = 0,
  71. INVERT = 1,
  72. CLOCK = 2,
  73. LOWLEVEL_IN = 4,
  74. LOWLEVEL_OUT = 8
  75. };
  76. /**
  77. * Enum DrawPinOrient
  78. * is the set of orientations allowed for pins.
  79. */
  80. enum DrawPinOrient {
  81. PIN_RIGHT = 'R',
  82. PIN_LEFT = 'L',
  83. PIN_UP = 'U',
  84. PIN_DOWN = 'D',
  85. };
  86. // Struct to pass parameters for drawing pins, in function Draw
  87. class DrawPinPrms
  88. {
  89. public:
  90. EDA_LibComponentStruct* m_Entry; // Pointer to the component in lib
  91. bool m_DrawPinText; // Are pin texts drawn ?
  92. DrawPinPrms(EDA_LibComponentStruct* entry, bool drawpintext = true)
  93. {
  94. m_Entry = entry;
  95. m_DrawPinText = drawpintext;
  96. }
  97. };
  98. /****************************************************************************/
  99. /* Classes for handle the body items of a compoment: pins add graphic items */
  100. /****************************************************************************/
  101. /* class LibEDA_BaseStruct : Basic class for items used in a library component
  102. * (graphic shapes, texts, fields, pins)
  103. */
  104. class LibEDA_BaseStruct : public EDA_BaseStruct
  105. {
  106. public:
  107. int m_Unit; /* Unit identification (for multi part per parkage)
  108. * 0 if the item is common to all units */
  109. int m_Convert; /* Shape identification (for parts which have a convert shape)
  110. * 0 if the item is common to all shapes */
  111. wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */
  112. int m_Width; /* Tickness */
  113. FILL_T m_Fill; /* NO_FILL, FILLED_SHAPE or FILLED_WITH_BG_BODYCOLOR. has meaning only for some items */
  114. public:
  115. LibEDA_BaseStruct* Next()
  116. {
  117. return (LibEDA_BaseStruct*) Pnext;
  118. }
  119. LibEDA_BaseStruct( KICAD_T struct_type );
  120. virtual ~LibEDA_BaseStruct() { }
  121. /** Function Draw (virtual pure)
  122. * Draw A body item
  123. * @param aPanel = DrawPanel to use (can be null) mainly used for clipping purposes
  124. * @param aDC = Device Context (can be null)
  125. * @param aOffset = offset to draw
  126. * @param aColor = -1 to use the normal body item color, or use this color if >= 0
  127. * @param aDrawMode = GR_OR, GR_XOR, ...
  128. * @param aData = value or pointer used to pass others parametres, depending on body items.
  129. * used for some items to force to force no fill mode
  130. * ( has meaning only for items what can be filled ). used in printing or moving objects mode
  131. * or to pass refernce to the lib component for pins
  132. * @param aTransformMatrix = Transform Matrix (rotaion, mirror ..)
  133. */
  134. virtual void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  135. int aDrawMode, void * aData, int aTransformMatrix[2][2] ) = 0;
  136. /**
  137. * Function Save
  138. * writes the data structures for this object out to a FILE in "*.brd" format.
  139. * @param aFile The FILE to write to.
  140. * @return bool - true if success writing else false.
  141. */
  142. virtual bool Save( FILE* aFile ) const = 0;
  143. void Display_Infos_DrawEntry( WinEDA_DrawFrame* frame );
  144. };
  145. /********/
  146. /* Pins */
  147. /********/
  148. class LibDrawPin : public LibEDA_BaseStruct
  149. {
  150. public:
  151. int m_PinLen; /* Pin lenght */
  152. int m_Orient; /* Pin orientation (Up, Down, Left, Right) */
  153. int m_PinShape; /* Bitwise ORed: Pin shape (see enum DrawPinShape) */
  154. int m_PinType; /* Electrical pin properties */
  155. int m_Attributs; /* bit 0 != 0: pin invisible */
  156. long m_PinNum; /* Pin number: 4 Ascii code like "12" or "anod" or "G6"
  157. * "12" is stored as "12\0\0" ans does not depend on endian type*/
  158. wxString m_PinName;
  159. int m_PinNumSize, m_PinNameSize; /* Pin num and Pin name sizes */
  160. // int m_PinNumWidth, m_PinNameWidth; /* (Currently Unused) Pin num and Pin name text width */
  161. public:
  162. LibDrawPin();
  163. ~LibDrawPin() { }
  164. virtual wxString GetClass() const
  165. {
  166. return wxT( "LibDrawPin" );
  167. }
  168. /**
  169. * Function Save
  170. * writes the data structures for this object out to a FILE in "*.brd" format.
  171. * @param aFile The FILE to write to.
  172. * @return bool - true if success writing else false.
  173. */
  174. virtual bool Save( FILE* aFile ) const;
  175. LibDrawPin* GenCopy();
  176. void Display_Infos( WinEDA_DrawFrame* frame );
  177. wxPoint ReturnPinEndPoint();
  178. int ReturnPinDrawOrient( int TransMat[2][2] );
  179. void ReturnPinStringNum( wxString& buffer ) const;
  180. void SetPinNumFromString( wxString& buffer );
  181. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  182. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  183. void DrawPinSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pin_pos,
  184. int orient,
  185. int DrawMode, int Color = -1 );
  186. void DrawPinTexts( WinEDA_DrawPanel* panel, wxDC* DC,
  187. wxPoint& pin_pos, int orient,
  188. int TextInside, bool DrawPinNum, bool DrawPinName,
  189. int Color, int DrawMode );
  190. void PlotPinTexts( wxPoint& pin_pos, int orient,
  191. int TextInside, bool DrawPinNum, bool DrawPinName );
  192. };
  193. /**************************/
  194. /* Graphic Body Item: Arc */
  195. /**************************/
  196. class LibDrawArc : public LibEDA_BaseStruct
  197. {
  198. public:
  199. int m_Rayon;
  200. int t1, t2; /* position des 2 extremites de l'arc en 0.1 degres */
  201. wxPoint m_ArcStart, m_ArcEnd; /* position des 2 extremites de l'arc en coord reelles*/
  202. public:
  203. LibDrawArc();
  204. ~LibDrawArc() { }
  205. virtual wxString GetClass() const
  206. {
  207. return wxT( "LibDrawArc" );
  208. }
  209. /**
  210. * Function Save
  211. * writes the data structures for this object out to a FILE in "*.brd" format.
  212. * @param aFile The FILE to write to.
  213. * @return bool - true if success writing else false.
  214. */
  215. virtual bool Save( FILE* aFile ) const;
  216. LibDrawArc* GenCopy();
  217. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  218. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  219. };
  220. /*****************************/
  221. /* Graphic Body Item: Circle */
  222. /*****************************/
  223. class LibDrawCircle : public LibEDA_BaseStruct
  224. {
  225. public:
  226. int m_Rayon;
  227. public:
  228. LibDrawCircle();
  229. ~LibDrawCircle() { }
  230. virtual wxString GetClass() const
  231. {
  232. return wxT( "LibDrawCircle" );
  233. }
  234. /**
  235. * Function Save
  236. * writes the data structures for this object out to a FILE in "*.brd" format.
  237. * @param aFile The FILE to write to.
  238. * @return bool - true if success writing else false.
  239. */
  240. virtual bool Save( FILE* aFile ) const;
  241. LibDrawCircle* GenCopy();
  242. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  243. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  244. };
  245. /*********************************************/
  246. /* Graphic Body Item: Text */
  247. /* This is only a graphic text. */
  248. /* Fields like Ref , value... are not Text, */
  249. /* they are a separate class */
  250. /*********************************************/
  251. class LibDrawText : public LibEDA_BaseStruct
  252. {
  253. public:
  254. int m_Horiz;
  255. wxSize m_Size;
  256. int m_Type;
  257. wxString m_Text;
  258. public:
  259. LibDrawText();
  260. ~LibDrawText() { }
  261. virtual wxString GetClass() const
  262. {
  263. return wxT( "LibDrawText" );
  264. }
  265. /**
  266. * Function Save
  267. * writes the data structures for this object out to a FILE in "*.brd" format.
  268. * @param aFile The FILE to write to.
  269. * @return bool - true if success writing else false.
  270. */
  271. virtual bool Save( FILE* aFile ) const;
  272. LibDrawText* GenCopy();
  273. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  274. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  275. };
  276. /********************************/
  277. /* Graphic Body Item: Rectangle */
  278. /********************************/
  279. class LibDrawSquare : public LibEDA_BaseStruct
  280. {
  281. public:
  282. wxPoint m_End;
  283. public:
  284. LibDrawSquare();
  285. ~LibDrawSquare() { }
  286. virtual wxString GetClass() const
  287. {
  288. return wxT( "LibDrawSquare" );
  289. }
  290. /**
  291. * Function Save
  292. * writes the data structures for this object out to a FILE in "*.brd" format.
  293. * @param aFile The FILE to write to.
  294. * @return bool - true if success writing else false.
  295. */
  296. virtual bool Save( FILE* aFile ) const;
  297. LibDrawSquare* GenCopy();
  298. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  299. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  300. };
  301. /**********************************/
  302. /* Graphic Body Item: single line */
  303. /**********************************/
  304. class LibDrawSegment : public LibEDA_BaseStruct
  305. {
  306. public:
  307. wxPoint m_End;
  308. public:
  309. LibDrawSegment();
  310. ~LibDrawSegment() { }
  311. virtual wxString GetClass() const
  312. {
  313. return wxT( "LibDrawSegment" );
  314. }
  315. /**
  316. * Function Save
  317. * writes the data structures for this object out to a FILE in "*.brd" format.
  318. * @param aFile The FILE to write to.
  319. * @return bool - true if success writing else false.
  320. */
  321. virtual bool Save( FILE* aFile ) const;
  322. LibDrawSegment* GenCopy();
  323. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  324. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  325. };
  326. /*********************************************/
  327. /* Graphic Body Item: Polygon (set of lines) */
  328. /*********************************************/
  329. class LibDrawPolyline : public LibEDA_BaseStruct
  330. {
  331. public:
  332. int m_CornersCount;
  333. int* m_PolyList;
  334. public:
  335. LibDrawPolyline();
  336. ~LibDrawPolyline()
  337. {
  338. if( m_PolyList )
  339. free( m_PolyList );
  340. }
  341. virtual wxString GetClass() const
  342. {
  343. return wxT( "LibDrawPolyline" );
  344. }
  345. /**
  346. * Function Save
  347. * writes the data structures for this object out to a FILE in "*.brd" format.
  348. * @param aFile The FILE to write to.
  349. * @return bool - true if success writing else false.
  350. */
  351. virtual bool Save( FILE* aFile ) const;
  352. LibDrawPolyline* GenCopy();
  353. void AddPoint( const wxPoint& point );
  354. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  355. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  356. };
  357. /**********/
  358. /* Fields */
  359. /**********/
  360. /* Fields , same as component fields.
  361. * can be defined in libraries (mandatory for ref and value, ca be useful for footprints)
  362. * 2 Fields are always defined :
  363. * Prefix (U, IC..) with gives the reference in schematic)
  364. * Name (74LS00..) used to find the component in libraries, and give the default value in schematic
  365. */
  366. class LibDrawField : public LibEDA_BaseStruct
  367. {
  368. public:
  369. int m_FieldId; /* 0 a 11
  370. * 0 = Reference; 1 = Value
  371. * 2 = Default footprint, 3 = subsheet (not used, reserved)
  372. * .. 11 other fields
  373. */
  374. wxSize m_Size;
  375. int m_Orient; /* Orientation */
  376. int m_Attributs; /* Attributes (Non visible ...) */
  377. int m_HJustify, m_VJustify; /* Horiz and Vert Text Justifications */
  378. wxString m_Text; /* Field Data */
  379. wxString m_Name; /* Field Name */
  380. public:
  381. LibDrawField( int idfield = 2 );
  382. ~LibDrawField();
  383. virtual wxString GetClass() const
  384. {
  385. return wxT( "LibDrawField" );
  386. }
  387. /**
  388. * Function Save
  389. * writes the data structures for this object out to a FILE in "*.brd" format.
  390. * @param aFile The FILE to write to.
  391. * @return bool - true if success writing else false.
  392. */
  393. virtual bool Save( FILE* aFile ) const;
  394. LibDrawField* GenCopy();
  395. void Copy( LibDrawField* Target );
  396. void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
  397. int aDrawMode, void * aData, int aTransformMatrix[2][2] );
  398. /**
  399. * Function HitTest
  400. * tests if the given wxPoint is within the bounds of this object.
  401. * @param refPos A wxPoint to test, in Field coordinate system
  402. * @return bool - true if a hit, else false
  403. */
  404. bool HitTest( const wxPoint& refPos );
  405. };
  406. #endif // CLASSES_BODY_ITEMS_H