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.

360 lines
13 KiB

16 years ago
16 years ago
  1. /********************************************/
  2. /* Definitions for the EESchema program: */
  3. /********************************************/
  4. #ifndef CLASS_DRAWSHEET_PATH_H
  5. #define CLASS_DRAWSHEET_PATH_H
  6. #include "base_struct.h"
  7. /** Info about complex hierarchies handling:
  8. * A hierarchical schematic uses sheets (hierarchical sheets) included in a
  9. * given sheet. Each sheet corresponds to a schematic drawing handled by a
  10. * SCH_SCREEN structure. A SCH_SCREEN structure contains drawings, and have
  11. * a filename to write it's data. Also a SCH_SCREEN display a sheet number
  12. * and the name of the sheet.
  13. *
  14. * In simple (and flat) hierarchies a sheet is linked to a SCH_SCREEN,
  15. * and a SCH_SCREEN is used by only one hierarchical sheet.
  16. *
  17. * In complex hierarchies the same SCH_SCREEN (and its data) is shared between
  18. * more than one sheet. Therefore subsheets (like subsheets in a SCH_SCREEN
  19. * shared by many sheets) can be also shared. So the same SCH_SCREEN must
  20. * handle different components references and parts selection depending on
  21. * which sheet is currently selected, and how a given subsheet is selected.
  22. * 2 sheets share the same SCH_SCREEN (the same drawings) if they have the
  23. * same filename.
  24. *
  25. * In Kicad each component and sheet receives (when created) an unique
  26. * identification called Time Stamp. So each sheet has 2 ids: its time stamp
  27. * (that cannot change) and its name ( that can be edited and therefore is
  28. * not reliable for strong identification). Kicad uses Time Stamp ( a unique
  29. * 32 bit id), to identify sheets in hierarchies.
  30. * A given sheet in a hierarchy is fully labeled by its path (or sheet path)
  31. * that is the list of time stamp found to access it through the hierarchy
  32. * the root sheet is /. All other sheets have a path like /1234ABCD or
  33. * /4567FEDC/AA2233DD/. This path can be displayed as human readable sheet
  34. * name like: / or /sheet1/include_sheet/ or /sheet2/include_sheet/
  35. *
  36. * So to know for a given SCH_SCREEN (a given schematic drawings) we must:
  37. * 1) Handle all references possibilities.
  38. * 2) When acceded by a given selected sheet, display (update) the
  39. * corresponding references and sheet path
  40. *
  41. * The class SCH_SHEET_PATH handles paths used to access a sheet. The class
  42. * SCH_SHEET_LIST allows to handle the full (or partial) list of sheets and
  43. * their paths in a complex hierarchy. The class EDA_ScreenList allow to
  44. * handle the list of SCH_SCREEN. It is useful to clear or save data,
  45. * but is not suitable to handle the full complex hierarchy possibilities
  46. * (usable in flat and simple hierarchies).
  47. */
  48. class SCH_MARKER;
  49. /**
  50. * Class SCH_SHEET_PATH
  51. * handles access to a sheet by way of a path.
  52. * <p>
  53. * The member m_sheets stores the list of sheets from the first (usually
  54. * g_RootSheet) to a given sheet in last position.
  55. * The _last_ sheet is usually the sheet we want to select or reach (which is
  56. * what the function Last() returns).
  57. * Others sheets constitute the "path" from the first to the last sheet.
  58. */
  59. class SCH_SHEET_PATH
  60. {
  61. private:
  62. unsigned m_numSheets;
  63. public:
  64. #define DSLSZ 32 // Max number of levels for a sheet path
  65. SCH_SHEET* m_sheets[DSLSZ];
  66. public:
  67. SCH_SHEET_PATH();
  68. // ~SCH_SHEET_PATH() { };
  69. void Clear()
  70. {
  71. m_numSheets = 0;
  72. }
  73. unsigned GetSheetsCount()
  74. {
  75. return m_numSheets;
  76. }
  77. /** Function Cmp
  78. * Compare if this is the same sheet path as aSheetPathToTest
  79. * @param aSheetPathToTest = sheet path to compare
  80. * @return -1 if different, 0 if same
  81. */
  82. int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
  83. /** Function Last
  84. * returns a pointer to the last sheet of the list
  85. * One can see the others sheet as the "path" to reach this last sheet
  86. */
  87. SCH_SHEET* Last();
  88. /** Function LastScreen
  89. * @return the SCH_SCREEN relative to the last sheet in list
  90. */
  91. SCH_SCREEN* LastScreen();
  92. /** Function LastScreen
  93. * @return a pointer to the first schematic item handled by the
  94. * SCH_SCREEN relative to the last sheet in list
  95. */
  96. SCH_ITEM* LastDrawList();
  97. /**
  98. * Get the last schematic item relative to the first sheet in the list.
  99. *
  100. * @return Last schematic item relative to the first sheet in the list if list
  101. * is not empty. Otherwise NULL.
  102. */
  103. SCH_ITEM* FirstDrawList();
  104. /** Function Push
  105. * store (push) aSheet in list
  106. * @param aSheet = pointer to the SCH_SHEET to store in list
  107. * Push is used when entered a sheet to select or analyze it
  108. * This is like cd <directory> in directories navigation
  109. */
  110. void Push( SCH_SHEET* aSheet );
  111. /** Function Pop
  112. * retrieves (pop) the last entered sheet and remove it from list
  113. * @return a SCH_SHEET* pointer to the removed sheet in list
  114. * Pop is used when leaving a sheet after a selection or analyze
  115. * This is like cd .. in directories navigation
  116. */
  117. SCH_SHEET* Pop();
  118. /** Function Path
  119. * the path uses the time stamps which do not changes even when editing
  120. * sheet parameters
  121. * a path is something like / (root) or /34005677 or /34005677/00AE4523
  122. */
  123. wxString Path();
  124. /**
  125. * Function PathHumanReadable
  126. * returns the sheet path in a human readable form, i.e. as a path made
  127. * from sheet names. The the "normal" path instead uses the time
  128. * stamps in the path. (Time stamps do not change even when editing
  129. * sheet parameters).
  130. */
  131. wxString PathHumanReadable() const;
  132. /** Function BuildSheetPathInfoFromSheetPathValue
  133. * Fill this with data to access to the hierarchical sheet known by its
  134. * path aPath
  135. * @param aPath = path of the sheet to reach (in non human readable format)
  136. * @return true if success else false
  137. */
  138. bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath,
  139. bool aFound = false );
  140. /**
  141. * Function UpdateAllScreenReferences
  142. * updates the reference and the m_Multi parameter (part selection) for all
  143. * components on a screen depending on the actual sheet path.
  144. * Mandatory in complex hierarchies because sheets use the same screen
  145. * (basic schematic)
  146. * but with different references and part selections according to the
  147. * displayed sheet
  148. */
  149. void UpdateAllScreenReferences();
  150. /**
  151. * Find the next schematic item in this sheet ojbect.
  152. *
  153. * @param aType - The type of schematic item object to search for.
  154. * @param aLastItem - Start search from aLastItem. If no aLastItem, search from
  155. * the beginning of the list.
  156. * @param aWrap - Wrap around the end of the list to find the next item if aLastItem
  157. * is defined.
  158. * @return - The next schematic item if found. Otherwise, NULL is returned.
  159. */
  160. SCH_ITEM* FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false );
  161. /**
  162. * Find the previous schematic item in this sheet path object.
  163. *
  164. * @param aItemType - The type of schematic item object to search for.
  165. * @param aLastItem - Start search from aLastItem. If no aLastItem, search from
  166. * the end of the list.
  167. * @param aWrap - Wrap around the beginning of the list to find the next item if aLastItem
  168. * is defined.
  169. * @return - The previous schematic item if found. Otherwise, NULL is returned.
  170. */
  171. SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false );
  172. /**
  173. * Search this sheet path for the next item that matches the search criteria.
  174. *
  175. * @param aSearchData - Criteria to search item against.
  176. * @param aLastItem - Find next item after aLastItem if not NULL.
  177. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  178. */
  179. SCH_ITEM* MatchNextItem( wxFindReplaceData& aSearchData, SCH_ITEM* aLastItem = NULL );
  180. bool operator=( const SCH_SHEET_PATH& d1 );
  181. bool operator==( const SCH_SHEET_PATH& d1 ) const;
  182. bool operator!=( const SCH_SHEET_PATH& d1 ) const;
  183. };
  184. /**
  185. * Class SCH_SHEET_LIST
  186. * handles the list of Sheets in a hiearchy.
  187. * Sheets are not unique, there can be many sheets with the same
  188. * filename and the same SCH_SCREEN reference.
  189. * The schematic (SCH_SCREEN) is shared between these sheets,
  190. * and component references are specific to a sheet path.
  191. * When a sheet is entered, component references and sheet number are updated.
  192. */
  193. class SCH_SHEET_LIST
  194. {
  195. private:
  196. SCH_SHEET_PATH* m_List;
  197. int m_count; /* Number of sheets included in hierarchy,
  198. * starting at the given sheet in constructor .
  199. * the given sheet is counted
  200. */
  201. int m_index; /* internal variable to handle GetNext():
  202. * cleared by GetFirst()
  203. * and incremented by GetNext() after
  204. * returning the next item in m_List
  205. * Also used for internal calculations in
  206. * BuildSheetList()
  207. */
  208. SCH_SHEET_PATH m_currList;
  209. public:
  210. /**
  211. * Constructor
  212. * builds the list of sheets from aSheet.
  213. * If aSheet == NULL (default) build the whole list of sheets in hierarchy.
  214. * So usually call it with no parameter.
  215. */
  216. SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
  217. ~SCH_SHEET_LIST()
  218. {
  219. if( m_List )
  220. free( m_List );
  221. m_List = NULL;
  222. }
  223. /**
  224. * Function GetCount()
  225. * @return the number of sheets in list:
  226. * usually the number of sheets found in the whole hierarchy
  227. */
  228. int GetCount() { return m_count; }
  229. /**
  230. * Function GetFirst
  231. * @return the first item (sheet) in m_List and prepare calls to GetNext()
  232. */
  233. SCH_SHEET_PATH* GetFirst();
  234. /**
  235. * Function GetNext
  236. * @return the next item (sheet) in m_List or NULL if no more item in
  237. * sheet list
  238. */
  239. SCH_SHEET_PATH* GetNext();
  240. /**
  241. * Function GetLast
  242. * returns the last sheet in the sheet list.
  243. *
  244. * @return Last sheet in the list or NULL if sheet list is empty.
  245. */
  246. SCH_SHEET_PATH* GetLast();
  247. /**
  248. * Function GetPrevious
  249. * returns the previous sheet in the sheet list.
  250. *
  251. * @return The previous sheet in the sheet list or NULL if already at the
  252. * beginning of the list.
  253. */
  254. SCH_SHEET_PATH* GetPrevious();
  255. /**
  256. * Function GetSheet
  257. * @return the item (sheet) in aIndex position in m_List or NULL if less
  258. * than index items
  259. * @param aIndex = index in sheet list to get the sheet
  260. */
  261. SCH_SHEET_PATH* GetSheet( int aIndex );
  262. /**
  263. * Function FindNextItem
  264. * searches the entire schematic for the next schematic object.
  265. *
  266. * @param aType - The type of schematic item to find.
  267. * @param aSheetFound - The sheet the item was found in. NULL if the next item
  268. * is not found.
  269. * @param aLastItem - Find next item after aLastItem if not NULL.
  270. * @param aWrap - Wrap past around the end of the list of sheets.
  271. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  272. */
  273. SCH_ITEM* FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
  274. SCH_ITEM* aLastItem = NULL, bool aWrap = true );
  275. /**
  276. * Function FindPreviousItem
  277. * searches the entire schematic for the previous schematic item.
  278. *
  279. * @param aType - The type of schematic item to find.
  280. * @param aSheetFound - The sheet the item was found in. NULL if the previous item
  281. * is not found.
  282. * @param aLastItem - Find the previous item before aLastItem if not NULL.
  283. * @param aWrap - Wrap past around the beginning of the list of sheets.
  284. * @return If found, the previous schematic item. Otherwise, NULL.
  285. */
  286. SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
  287. SCH_ITEM* aLastItem = NULL, bool aWrap = true );
  288. /**
  289. * Function MatchNextItem
  290. * searches the entire schematic for the next item that matches the search criteria.
  291. *
  292. * @param aSearchData - Criteria to search item against.
  293. * @param aSheetFound - The sheet the item was found in. NULL if the next item
  294. * is not found.
  295. * @param aLastItem - Find next item after aLastItem if not NULL.
  296. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  297. */
  298. SCH_ITEM* MatchNextItem( wxFindReplaceData& aSearchData,
  299. SCH_SHEET_PATH** aSheetFound = NULL,
  300. SCH_ITEM* aLastItem = NULL );
  301. private:
  302. /**
  303. * Function BuildSheetList
  304. * builds the list of sheets and their sheet path from \a aSheet.
  305. * If aSheet = g_RootSheet, the full sheet path and sheet list is built
  306. *
  307. * @param aSheet is the starting sheet from which the list is built,
  308. * or NULL indicating that g_RootSheet should be used.
  309. */
  310. void BuildSheetList( SCH_SHEET* sheet );
  311. };
  312. #endif // CLASS_DRAWSHEET_PATH_H