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.

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