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.

337 lines
11 KiB

18 years ago
18 years ago
18 years ago
  1. /*****************************************************************************/
  2. /* sch_item_struct.h : Basic classes for most eeschema items descriptions */
  3. /*****************************************************************************/
  4. #ifndef SCH_ITEM_STRUCT_H
  5. #define SCH_ITEM_STRUCT_H
  6. #include <vector>
  7. #include <class_base_screen.h>
  8. using namespace std;
  9. class SCH_ITEM;
  10. class LINE_READER;
  11. class SCH_EDIT_FRAME;
  12. class wxFindReplaceData;
  13. class PLOTTER;
  14. typedef boost::ptr_vector< SCH_ITEM > SCH_ITEMS;
  15. typedef SCH_ITEMS::iterator SCH_ITEMS_ITR;
  16. typedef vector< SCH_ITEMS_ITR > SCH_ITEMS_ITRS;
  17. /* used to calculate the pen size from default value
  18. * the actual pen size is default value * BUS_WIDTH_EXPAND
  19. */
  20. #if defined(KICAD_GOST)
  21. #define BUS_WIDTH_EXPAND 3.6
  22. #else
  23. #define BUS_WIDTH_EXPAND 1.4
  24. #endif
  25. enum DANGLING_END_T {
  26. UNKNOWN = 0,
  27. WIRE_START_END,
  28. WIRE_END_END,
  29. BUS_START_END,
  30. BUS_END_END,
  31. JUNCTION_END,
  32. PIN_END,
  33. LABEL_END,
  34. ENTRY_END,
  35. SHEET_LABEL_END
  36. };
  37. // A helper class to store a list of items that can be connected to something:
  38. class DANGLING_END_ITEM
  39. {
  40. public:
  41. const void* m_Item; // a pointer to the parent
  42. wxPoint m_Pos; // the position of the connecting point
  43. DANGLING_END_T m_Type; // type of parent
  44. DANGLING_END_ITEM( DANGLING_END_T type, const void* aItem )
  45. {
  46. m_Item = aItem;
  47. m_Type = type;
  48. }
  49. };
  50. /**
  51. * Class SCH_ITEM
  52. * is a base class for any item which can be embedded within the SCHEMATIC
  53. * container class, and therefore instances of derived classes should only be
  54. * found in EESCHEMA or other programs that use class SCHEMATIC and its contents.
  55. * The corresponding class in PCBNEW is BOARD_ITEM.
  56. */
  57. class SCH_ITEM : public EDA_ITEM
  58. {
  59. protected:
  60. int m_Layer;
  61. EDA_ITEMS m_connections; ///< List of items connected to this item.
  62. public:
  63. SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
  64. SCH_ITEM( const SCH_ITEM& aItem );
  65. ~SCH_ITEM();
  66. virtual wxString GetClass() const
  67. {
  68. return wxT( "SCH_ITEM" );
  69. }
  70. SCH_ITEM* Clone() const { return ( SCH_ITEM* ) EDA_ITEM::Clone(); }
  71. /**
  72. * Function SwapDate
  73. * swap the internal data structures \a aItem with the schematic item.
  74. * Obviously, aItem must have the same type than me
  75. * @param aItem The item to swap the data structures with.
  76. */
  77. virtual void SwapData( SCH_ITEM* aItem );
  78. SCH_ITEM* Next() { return (SCH_ITEM*) Pnext; }
  79. SCH_ITEM* Back() { return (SCH_ITEM*) Pback; }
  80. /**
  81. * Function GetLayer
  82. * returns the layer this item is on.
  83. */
  84. int GetLayer() const { return m_Layer; }
  85. /**
  86. * Function SetLayer
  87. * sets the layer this item is on.
  88. * @param aLayer The layer number.
  89. */
  90. void SetLayer( int aLayer ) { m_Layer = aLayer; }
  91. /**
  92. * Function GetPenSize virtual pure
  93. * @return the size of the "pen" that be used to draw or plot this item
  94. */
  95. virtual int GetPenSize() const { return 0; }
  96. /**
  97. * Function Draw
  98. */
  99. virtual void Draw( EDA_DRAW_PANEL* aPanel,
  100. wxDC* aDC,
  101. const wxPoint& aOffset,
  102. int aDrawMode,
  103. int aColor = -1 ) = 0;
  104. /* Place function */
  105. virtual void Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC );
  106. /**
  107. * Function Move
  108. * moves the item by \a aMoveVector to a new position.
  109. * @param aMoveVector = the displacement vector
  110. */
  111. virtual void Move( const wxPoint& aMoveVector ) = 0;
  112. /**
  113. * Function Mirror_Y
  114. * mirrors item relative to an Y axis about \a aYaxis_position.
  115. * @param aYaxis_position The Y axis position to mirror around.
  116. */
  117. virtual void Mirror_Y( int aYaxis_position ) = 0;
  118. virtual void Mirror_X( int aXaxis_position ) = 0;
  119. virtual void Rotate( wxPoint rotationPoint ) = 0;
  120. /**
  121. * Function Save
  122. * writes the data structures for this object out to a FILE in "*.sch" format.
  123. * @param aFile The FILE to write to.
  124. * @return bool - true if success writing else false.
  125. */
  126. virtual bool Save( FILE* aFile ) const = 0;
  127. /**
  128. * Function Load
  129. * reads a schematic item from \a aLine in a .sch file.
  130. *
  131. * @param aLine - Essentially this is file to read the object from.
  132. * @param aErrorMsg - Description of the error if an error occurs while loading the object.
  133. * @return True if the object loaded successfully.
  134. */
  135. virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
  136. /**
  137. * Function Matches
  138. * compares the schematic item against search \a aSearchData.
  139. *
  140. * The base class returns false since many of the objects derived from
  141. * SCH_ITEM do not have any text to search.
  142. *
  143. * @todo - This should probably be pushed down to EDA_ITEM so that
  144. * searches can be done on all of the Kicad applications that use
  145. * objects derived from EDA_ITEM.
  146. *
  147. * @param aSearchData - The search criteria.
  148. * @param aAuxData - a pointer on auxiliary data, if needed (NULL if not used).
  149. * When searching string in REFERENCE field we must know the sheet path
  150. * This param is used in such cases
  151. * @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
  152. * @return True if this schematic text item matches the search criteria.
  153. */
  154. virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
  155. { return false; }
  156. /**
  157. * Compare schematic item against search string.
  158. *
  159. * @param aText - String test.
  160. * @param aSearchData - The criteria to search against.
  161. * @return True if this item matches the search criteria.
  162. */
  163. bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
  164. /**
  165. * Function GetEndPoints
  166. * adds the schematic item end points to \a aItemList if the item has end points.
  167. *
  168. * The default version doesn't do anything since many of the schematic object cannot
  169. * be tested for dangling ends. If you add a new schematic item that can have a
  170. * dangling end ( no connect ), override this method to provide the correct end
  171. * points.
  172. *
  173. * @param aItemList - List of DANGLING_END_ITEMS to add to.
  174. */
  175. virtual void GetEndPoints( vector< DANGLING_END_ITEM >& aItemList ) {}
  176. /**
  177. * Function IsDanglingStateChanged
  178. * tests the schematic item to \a aItemList to check if it's dangling state has changed.
  179. *
  180. * Note that the return value only true when the state of the test has changed. Use
  181. * the IsDangling() method to get the current dangling state of the item. Some of
  182. * the schematic objects cannot be tested for a dangling state, the default method
  183. * always returns false. Only override the method if the item can be tested for a
  184. * dangling state.
  185. *
  186. * @param aItemList - List of items to test item against.
  187. * @return True if the dangling state has changed from it's current setting.
  188. */
  189. virtual bool IsDanglingStateChanged( vector< DANGLING_END_ITEM >& aItemList ) { return false; }
  190. virtual bool IsDangling() const { return false; }
  191. /**
  192. * Function IsSelectStateChanged
  193. * checks if the selection state of an item inside \a aRect has changed.
  194. *
  195. * This is used by the block selection code to verify if an item is selected or not.
  196. * True is be return anytime the select state changes. If you need to know the
  197. * the current selection state, use the IsSelected() method.
  198. *
  199. * @param aRect - Rectangle to test against.
  200. */
  201. virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
  202. /**
  203. * Function IsConnectable
  204. * returns true if the schematic item can connect to another schematic item.
  205. */
  206. virtual bool IsConnectable() const { return false; }
  207. /**
  208. * Function GetConnectionPoints
  209. * add all the connection points for this item to \a aPoints.
  210. *
  211. * Not all schematic items have connection points so the default method does nothing.
  212. *
  213. * @param aPoints List of connection points to add to.
  214. */
  215. virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const { }
  216. /**
  217. * Function ClearConnections
  218. * clears all of the connection items from the list.
  219. *
  220. * The vector release method is used to prevent the item pointers from being deleted.
  221. * Do not use the vector erase method on the connection list.
  222. */
  223. void ClearConnections() { m_connections.clear(); }
  224. /**
  225. * Function IsConnected
  226. * tests the item to see if it is connected to \a aPoint.
  227. *
  228. * @param aPoint - Position to test for connection.
  229. * @return True if connection to \a aPoint exists.
  230. */
  231. bool IsConnected( const wxPoint& aPoint ) const;
  232. virtual bool HitTest( const wxPoint& aPosition ) { return HitTest( aPosition, 0 ); }
  233. /**
  234. * Function HitTest
  235. * tests if \a aPoint is contained within or on the bounding box of an item.
  236. *
  237. * @param aPoint - Point to test.
  238. * @param aAccuracy - Increase the item bounding box by this amount.
  239. * @return True if \a aPoint is within the item bounding box.
  240. */
  241. bool HitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const
  242. {
  243. return doHitTest( aPoint, aAccuracy );
  244. }
  245. /**
  246. * Function HitTest
  247. * tests if \a aRect intersects or is contained within the bounding box of an item.
  248. *
  249. * @param aRect - Rectangle to test.
  250. * @param aContained - Set to true to test for containment instead of an intersection.
  251. * @param aAccuracy - Increase aRect by this amount.
  252. * @return True if \a aRect contains or intersects the item bounding box.
  253. */
  254. bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const
  255. {
  256. return doHitTest( aRect, aContained, aAccuracy );
  257. }
  258. virtual bool CanIncrementLabel() const { return false; }
  259. void Plot( PLOTTER* aPlotter ) { doPlot( aPlotter ); }
  260. virtual bool operator <( const SCH_ITEM& aItem ) const;
  261. /**
  262. * @note - The DoXXX() functions below are used to enforce the interface while retaining
  263. * the ability of change the implementation behavior of derived classes. See
  264. * Herb Sutters explanation of virtuality as to why you might want to do this at:
  265. * http://www.gotw.ca/publications/mill18.htm.
  266. */
  267. private:
  268. virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy ) const
  269. {
  270. return false;
  271. }
  272. virtual bool doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  273. {
  274. return false;
  275. }
  276. virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
  277. virtual void doPlot( PLOTTER* aPlotter );
  278. };
  279. extern bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 );
  280. #endif /* SCH_ITEM_STRUCT_H */