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.

487 lines
17 KiB

18 years ago
17 years ago
17 years ago
17 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /********************************************/
  2. /* Definitions for the EESchema program: */
  3. /********************************************/
  4. #ifndef CLASS_SCREEN_H
  5. #define CLASS_SCREEN_H
  6. #include "macros.h"
  7. #include "sch_item_struct.h"
  8. #include "class_base_screen.h"
  9. #include "../eeschema/general.h"
  10. class LIB_PIN;
  11. class SCH_COMPONENT;
  12. class SCH_SHEET_PATH;
  13. class SCH_SHEET_PIN;
  14. class SCH_LINE;
  15. class SCH_TEXT;
  16. class PLOTTER;
  17. enum SCH_LINE_TEST_T
  18. {
  19. ENTIRE_LENGTH_T,
  20. END_POINTS_ONLY_T,
  21. EXCLUDE_END_POINTS_T
  22. };
  23. /* Max number of sheets in a hierarchy project: */
  24. #define NB_MAX_SHEET 500
  25. class SCH_SCREEN : public BASE_SCREEN
  26. {
  27. int m_refCount; ///< Number of sheets referencing this screen.
  28. ///< Delete when it goes to zero.
  29. /**
  30. * Function addConnectedItemsToBlock
  31. * add items connected at \a aPosition to the block pick list.
  32. * <p>
  33. * This method tests all connectible unselected items in the screen that are connected to
  34. * \a aPosition and adds them to the block selection pick list. This is used when a block
  35. * drag is being performed to ensure connections to items in the block are not lost.
  36. *</p>
  37. * @param aPosition = The connection point to test.
  38. */
  39. void addConnectedItemsToBlock( const wxPoint& aPosition );
  40. public:
  41. SCH_SCREEN( KICAD_T aType = SCH_SCREEN_T );
  42. ~SCH_SCREEN();
  43. virtual wxString GetClass() const
  44. {
  45. return wxT( "SCH_SCREEN" );
  46. }
  47. void DecRefCount();
  48. void IncRefCount();
  49. int GetRefCount() const { return m_refCount; }
  50. /**
  51. * Function GetDrawItems().
  52. *
  53. * @return - A pointer to the first item in the linked list of draw items.
  54. */
  55. virtual SCH_ITEM* GetDrawItems() const { return (SCH_ITEM*) BASE_SCREEN::GetDrawItems(); }
  56. virtual void SetDrawItems( SCH_ITEM* aItem ) { BASE_SCREEN::SetDrawItems( aItem ); }
  57. /**
  58. * Function GetCurItem
  59. * returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
  60. * @return SCH_ITEM* - the one selected, or NULL.
  61. */
  62. SCH_ITEM* GetCurItem() const { return (SCH_ITEM*) BASE_SCREEN::GetCurItem(); }
  63. /**
  64. * Function SetCurItem
  65. * sets the currently selected object, m_CurrentItem.
  66. * @param aItem Any object derived from SCH_ITEM
  67. */
  68. void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); }
  69. /**
  70. * Function Clear
  71. * deletes all draw items and clears the project settings.
  72. */
  73. void Clear();
  74. /**
  75. * Free all the items from the schematic associated with the screen.
  76. *
  77. * This does not delete any sub hierarchies.
  78. */
  79. void FreeDrawList();
  80. /**
  81. * Function GetItem
  82. * checks \a aPosition within a distance of \a aAccuracy for items of type \a aFilter.
  83. * @param aPosition Position in drawing units.
  84. * @param aAccuracy The maximum distance within \a Position to check for an item.
  85. * @param aType The type of item to find or #NOT_USED to find any item type.
  86. * @return The item found that meets the search criteria or NULL if none found.
  87. */
  88. SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
  89. KICAD_T aType = NOT_USED ) const;
  90. void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
  91. /**
  92. * Function Draw
  93. * draws all the items in the screen to \a aCanvas.
  94. * @param aCanvas The canvas item to draw on.
  95. * @param aDC The device context to draw on.
  96. * @param aDrawMode The drawing mode.
  97. * @param aColor The drawing color.
  98. */
  99. void Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, int aDrawMode, int aColor = -1 );
  100. /**
  101. * Function Plot
  102. * plots all the schematic objects to \a aPlotter.
  103. *
  104. * @param aPlotter The plotter object to plot to.
  105. */
  106. void Plot( PLOTTER* aPlotter );
  107. /**
  108. * Remove \a aItem from the schematic associated with this screen.
  109. *
  110. * @param aItem - Item to be removed from schematic.
  111. */
  112. void RemoveFromDrawList( SCH_ITEM* aItem );
  113. /**
  114. * Function DeleteItem
  115. * removes \a aItem from the linked list and deletes the object. If \a aItem is
  116. * is a schematic sheet label, it is removed from the screen associated with the
  117. * sheet that contains the label to be deleted.
  118. * @param aItem The schematic object to be deleted from the screen.
  119. */
  120. void DeleteItem( SCH_ITEM* aItem );
  121. bool CheckIfOnDrawList( SCH_ITEM* st );
  122. void AddToDrawList( SCH_ITEM* st );
  123. /**
  124. * Function SchematicCleanUp
  125. * performs routine schematic cleaning including breaking wire and buses and
  126. * deleting identical objects superimposed on top of each other.
  127. *
  128. * @param aCanvas The window to draw on.
  129. * @param aDC The device context used for drawing to \a aCanvas.
  130. * @return True if any schematic clean up was performed.
  131. */
  132. bool SchematicCleanUp( EDA_DRAW_PANEL* aCanvas = NULL, wxDC* aDC = NULL );
  133. /**
  134. * Function TestDanglingEnds
  135. * tests all of the connectible objects in the schematic for unused connection points.
  136. * @param aDC - The device context to draw the dangling status indicators.
  137. * @param aCanvas - The window to draw on.
  138. * @return True if any dangling ends were found.
  139. */
  140. bool TestDanglingEnds( EDA_DRAW_PANEL* aCanvas = NULL, wxDC* aDC = NULL );
  141. /**
  142. * Function ExtractWires
  143. * extracts the old wires, junctions and buses. If \a aCreateCopy is true, replace
  144. * them with a copy. Old item must be put in undo list, and the new ones can be
  145. * modified by clean up safely. If an abort command is made, old wires must be put
  146. * in GetDrawItems(), and copies must be deleted. This is because previously stored
  147. * undo commands can handle pointers on wires or buses, and we do not delete wires or
  148. * buss-es, we must put they in undo list.
  149. *
  150. * Because cleanup delete and/or modify bus and wires, the it is easier is to put
  151. * all wires in undo list and use a new copy of wires for cleanup.
  152. */
  153. SCH_ITEM* ExtractWires( bool aCreateCopy );
  154. /**
  155. * Function ReplaceWires
  156. * replaces all of the wires and junction in the screen with \a aWireList.
  157. * @param aWireList List of wire to replace the existing wires with.
  158. */
  159. void ReplaceWires( SCH_ITEM* aWireList );
  160. /**
  161. * Function MarkConnections
  162. * add all wires and junctions connected to \a aSegment which are not connected any
  163. * component pin to \a aItemList.
  164. * @param aSegment The segment to test for connections.
  165. */
  166. void MarkConnections( SCH_LINE* aSegment );
  167. /**
  168. * Functions GetConnection
  169. * adds all of the wires and junctions to \a aList that make up a connection to the
  170. * object at \a aPosition.
  171. * @param aPosition The position of the first connection object in drawing units.
  172. * @param aList The pick list to add the connect item to.
  173. * @param aFullConnection If true all the objects that make up this connection are
  174. * add to \a aList. Otherwise, only the objects up to the first
  175. * node are added.
  176. * @return The number of items added to \a aList.
  177. */
  178. int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
  179. /**
  180. * Function BreakSegment
  181. * checks every wire and bus for a intersection at \a aPoint and break into two segments
  182. * at \a aPoint if an intersection is found.
  183. * @param aPoint Test this point for an intersection.
  184. * @return True if any wires or buses were broken.
  185. */
  186. bool BreakSegment( const wxPoint& aPoint );
  187. /**
  188. * Function BreakSegmentsOnJunctions
  189. * tests all junctions and bus entries in the schematic for intersections with wires and
  190. * buses and breaks any intersections into multiple segments.
  191. * @return True if any wires or buses were broken.
  192. */
  193. bool BreakSegmentsOnJunctions();
  194. /* full undo redo management : */
  195. // use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
  196. // use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
  197. /**
  198. * Function ClearUndoORRedoList
  199. * free the undo or redo list from List element
  200. * Wrappers are deleted.
  201. * data pointed by wrappers are deleted if not in use in schematic
  202. * i.e. when they are copy of a schematic item or they are no more in use (DELETED)
  203. * @param aList = the UNDO_REDO_CONTAINER to clear
  204. * @param aItemCount = the count of items to remove. < 0 for all items
  205. * items are removed from the beginning of the list.
  206. * So this function can be called to remove old commands
  207. */
  208. virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 );
  209. /**
  210. * Function Save
  211. * writes the data structures for this object out to \a aFile in "*.sch" format.
  212. *
  213. * @param aFile The FILE to write to.
  214. * @return bool - true if success writing else false.
  215. */
  216. bool Save( FILE* aFile ) const;
  217. /**
  218. * Clear the state flags of all the items in the screen.
  219. */
  220. void ClearDrawingState();
  221. int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
  222. /**
  223. * Function IsJunctionNeeded
  224. * tests if a junction is required for the items at \a aPosition on the screen.
  225. * <p>
  226. * A junction is required at \a aPosition if the following criteria are satisfied:
  227. * <ul>
  228. * <li>one wire midpoint, one or more wire endpoints and no junction.</li>
  229. * <li>three or more wire endpoints and no junction.</li>
  230. * <li>two wire midpoints and no junction</li>
  231. * <li>one wire midpoint, a component pin, and no junction.</li>
  232. * <li>three wire endpoints, a component pin, and no junction.</li>
  233. * </ul>
  234. * </p>
  235. * @param aPosition The position to test.
  236. * @return True if a junction is required at \a aPosition.
  237. */
  238. bool IsJunctionNeeded( const wxPoint& aPosition );
  239. /**
  240. * Function IsTerminalPoint
  241. * tests if \a aPosition is a connection point on \a aLayer.
  242. *
  243. * @param aPosition Position to test.
  244. * @param aLayer The layer type to test against. Valid layer types are #LAYER_NOTES,
  245. * #LAYER_BUS, and #LAYER_WIRE.
  246. * @return True if \a Position is a connection point on \a aLayer.
  247. */
  248. bool IsTerminalPoint( const wxPoint& aPosition, int aLayer );
  249. /**
  250. * Function GetPin
  251. * test the screen for a component pin item at \a aPosition.
  252. * @param aPosition Position to test.
  253. * @param aComponent The component if a pin was found, otherwise NULL.
  254. * @param aEndPointOnly Set to true to test if \a aPosition is the connection
  255. * point of the pin.
  256. * @return The pin item if found, otherwise NULL.
  257. */
  258. LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
  259. bool aEndPointOnly = false ) const;
  260. /**
  261. * Function GetSheetLabel
  262. * test the screen if \a aPosition is a sheet label object.
  263. * @param aPosition The position to test.
  264. * @return The sheet label object if found otherwise NULL.
  265. */
  266. SCH_SHEET_PIN* GetSheetLabel( const wxPoint& aPosition );
  267. /**
  268. * Function ClearAnnotation
  269. * clears the annotation for the components in \a aSheetPath on the screen.
  270. * @param aSheetPath The sheet path of the component annotation to clear. If NULL then
  271. * the entire hierarchy is cleared.
  272. */
  273. void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
  274. /**
  275. * Function GetHierarchicalItems
  276. * adds all schematic sheet and component object in the screen to \a aItems.
  277. * @param aItems Hierarchical item list to fill.
  278. */
  279. void GetHierarchicalItems( EDA_ITEMS& aItems );
  280. /**
  281. * Function GetNode
  282. * returns all the items at \a aPosition that form a node.
  283. *
  284. * @param aPosition The wxPoint to test for node items.
  285. * @param aList A #EDA_ITEMS container to place the items found.
  286. * @return The number of node items found at \a aPosition.
  287. */
  288. int GetNode( const wxPoint& aPosition, EDA_ITEMS& aList );
  289. /**
  290. * Function GetWireOrBus
  291. * returns a wire or bus item located at \a aPosition.
  292. *
  293. * @param aPosition The wxPoint to test for node items.
  294. * @return The SCH_LINE* of the wire or bus item found at \a aPosition or NULL if item not
  295. * found.
  296. */
  297. SCH_LINE* GetWireOrBus( const wxPoint& aPosition );
  298. /**
  299. * Function GetLine
  300. * returns a line item located at \a aPosition.
  301. *
  302. * @param aPosition The wxPoint to test for a line item.
  303. * @param aAccuracy Amount to inflate the item hit test bounding box.
  304. * @param aLayer The layer the line is drawn upon.
  305. * @param aSearchType Additional line test criteria.
  306. * @return The SCH_LINE* of the wire item found at \a aPosition or NULL if item not
  307. * found.
  308. */
  309. SCH_LINE* GetLine( const wxPoint& aPosition, int aAccuracy = 0, int aLayer = LAYER_NOTES,
  310. SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T );
  311. SCH_LINE* GetWire( const wxPoint& aPosition, int aAccuracy = 0,
  312. SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
  313. {
  314. return GetLine( aPosition, aAccuracy, LAYER_WIRE, aSearchType );
  315. }
  316. SCH_LINE* GetBus( const wxPoint& aPosition, int aAccuracy = 0,
  317. SCH_LINE_TEST_T aSearchType = ENTIRE_LENGTH_T )
  318. {
  319. return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType );
  320. }
  321. /**
  322. * Function GetLabel
  323. * returns a label item located at \a aPosition.
  324. *
  325. * @param aPosition The wxPoint to test for label items.
  326. * @param aAccuracy Amount to inflate the item hit test bounding box.
  327. * @return The SCH_TEXT* of the label item found at \a aPosition or NULL if item not
  328. * found.
  329. */
  330. SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
  331. /**
  332. * Function SetFootprintField
  333. * searches screen for a component with \a aReference and set the footprint field to
  334. * \a aFootPrint if found.
  335. *
  336. * @param aSheetPath The sheet path used to look up the reference designator.
  337. * @param aReference The reference designator of the component.
  338. * @param aFootPrint The value to set the footprint field.
  339. * @param aSetVisible The value to set the field visibility flag.
  340. * @return True if \a aReference was found otherwise false.
  341. */
  342. bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
  343. const wxString& aFootPrint, bool aSetVisible );
  344. /**
  345. * Function SelectBlockItems
  346. * creates a list of items found when a block command is initiated. The items selected
  347. * depend on the block command. If the drag block command is issued, than any items
  348. * connected to items in the block are also selected.
  349. */
  350. void SelectBlockItems();
  351. /**
  352. * Function UpdatePickList
  353. * adds all the items in the screen within the block selection rectangle to the pick list.
  354. * @return The number of items in the pick list.
  355. */
  356. int UpdatePickList();
  357. virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_ITEM*) aItem ); }
  358. virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem )
  359. {
  360. BASE_SCREEN::InsertItem( aIter, (EDA_ITEM*) aItem );
  361. }
  362. };
  363. /********************************************************/
  364. /* Class to handle the list of *screens* in a hierarchy */
  365. /********************************************************/
  366. // screens are unique, and correspond to .sch files.
  367. class SCH_SCREENS
  368. {
  369. private:
  370. std::vector< SCH_SCREEN* > m_screens;
  371. unsigned int m_index;
  372. public:
  373. SCH_SCREENS();
  374. ~SCH_SCREENS();
  375. int GetCount() const { return m_screens.size(); }
  376. SCH_SCREEN* GetFirst();
  377. SCH_SCREEN* GetNext();
  378. SCH_SCREEN* GetScreen( unsigned int aIndex );
  379. /**
  380. * Function ClearAnnotation
  381. * clears the annotation for all components in the hierarchy.
  382. */
  383. void ClearAnnotation();
  384. /**
  385. * Function SchematicCleanUp
  386. * merges and breaks wire segments in the entire schematic hierarchy.
  387. */
  388. void SchematicCleanUp();
  389. /**
  390. * Function ReplaceDuplicateTimeStamps
  391. * test all sheet and component objects in the schematic for duplicate time stamps
  392. * an replaces them as necessary. Time stamps must be unique in order for complex
  393. * hierarchies know which components go to which sheets.
  394. * @return The number of duplicate time stamps replaced.
  395. */
  396. int ReplaceDuplicateTimeStamps();
  397. /**
  398. * Function SetDate
  399. * sets the date string for every screen to \a aDate.
  400. * @see GetDate()
  401. * @param aDate The date string to set for each screen.
  402. */
  403. void SetDate( const wxString& aDate );
  404. /**
  405. * Function DeleteAllMarkers
  406. * deletes all electronic rules check markers of \a aMarkerType from all the screens in
  407. * the list.
  408. * @param aMarkerType Type of markers to be deleted.
  409. */
  410. void DeleteAllMarkers( int aMarkerType );
  411. private:
  412. void AddScreenToList( SCH_SCREEN* aScreen );
  413. void BuildScreenList( EDA_ITEM* aItem );
  414. };
  415. #endif /* CLASS_SCREEN_H */