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.

440 lines
16 KiB

  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 wxFindReplaceData;
  49. class SCH_SCREEN;
  50. class SCH_MARKER;
  51. class SCH_SHEET;
  52. class SCH_ITEM;
  53. class SCH_REFERENCE_LIST;
  54. /**
  55. * Class SCH_SHEET_PATH
  56. * handles access to a sheet by way of a path.
  57. * <p>
  58. * The member m_sheets stores the list of sheets from the first (usually
  59. * g_RootSheet) to a given sheet in last position.
  60. * The _last_ sheet is usually the sheet we want to select or reach (which is
  61. * what the function Last() returns).
  62. * Others sheets constitute the "path" from the first to the last sheet.
  63. * </p>
  64. */
  65. class SCH_SHEET_PATH
  66. {
  67. #define DSLSZ 32 // Max number of levels for a sheet path
  68. SCH_SHEET* m_sheets[ DSLSZ ];
  69. unsigned m_numSheets;
  70. public:
  71. SCH_SHEET_PATH();
  72. void Clear()
  73. {
  74. m_numSheets = 0;
  75. }
  76. unsigned GetSheetsCount()
  77. {
  78. return m_numSheets;
  79. }
  80. /**
  81. * Function Cmp
  82. * Compare if this is the same sheet path as aSheetPathToTest
  83. * @param aSheetPathToTest = sheet path to compare
  84. * @return -1 if different, 0 if same
  85. */
  86. int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
  87. /**
  88. * Function Last
  89. * returns a pointer to the last sheet of the list
  90. * One can see the others sheet as the "path" to reach this last sheet
  91. */
  92. SCH_SHEET* Last();
  93. /**
  94. * Function LastScreen
  95. * @return the SCH_SCREEN relative to the last sheet in list
  96. */
  97. SCH_SCREEN* LastScreen();
  98. /**
  99. * Function LastDrawList
  100. * @return a pointer to the first schematic item handled by the
  101. * SCH_SCREEN relative to the last sheet in list
  102. */
  103. SCH_ITEM* LastDrawList();
  104. /**
  105. * Get the last schematic item relative to the first sheet in the list.
  106. *
  107. * @return Last schematic item relative to the first sheet in the list if list
  108. * is not empty. Otherwise NULL.
  109. */
  110. SCH_ITEM* FirstDrawList();
  111. /**
  112. * Function Push
  113. * store (push) aSheet in list
  114. * @param aSheet = pointer to the SCH_SHEET to store in list
  115. * Push is used when entered a sheet to select or analyze it
  116. * This is like cd &ltdirectory&gt in directories navigation
  117. */
  118. void Push( SCH_SHEET* aSheet );
  119. /**
  120. * Function Pop
  121. * retrieves (pop) the last entered sheet and remove it from list
  122. * @return a SCH_SHEET* pointer to the removed sheet in list
  123. * Pop is used when leaving a sheet after a selection or analyze
  124. * This is like cd .. in directories navigation
  125. */
  126. SCH_SHEET* Pop();
  127. /**
  128. * Function Path
  129. * the path uses the time stamps which do not changes even when editing
  130. * sheet parameters
  131. * a path is something like / (root) or /34005677 or /34005677/00AE4523
  132. */
  133. wxString Path();
  134. /**
  135. * Function PathHumanReadable
  136. * returns the sheet path in a human readable form, i.e. as a path made
  137. * from sheet names. The the "normal" path instead uses the time
  138. * stamps in the path. (Time stamps do not change even when editing
  139. * sheet parameters).
  140. */
  141. wxString PathHumanReadable() const;
  142. /**
  143. * Function BuildSheetPathInfoFromSheetPathValue
  144. * Fill this with data to access to the hierarchical sheet known by its path \a aPath
  145. * @param aPath = path of the sheet to reach (in non human readable format)
  146. * @param aFound - Please document me.
  147. * @return true if success else false
  148. */
  149. bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound = false );
  150. /**
  151. * Function UpdateAllScreenReferences
  152. * updates the reference and the m_Multi parameter (part selection) for all
  153. * components on a screen depending on the actual sheet path.
  154. * Mandatory in complex hierarchies because sheets use the same screen
  155. * (basic schematic)
  156. * but with different references and part selections according to the
  157. * displayed sheet
  158. */
  159. void UpdateAllScreenReferences();
  160. /**
  161. * Function AnnotatePowerSymbols
  162. * annotates the power symbols only starting at \a aReference in the sheet path.
  163. * @param aReference A pointer to the number for the reference designator of the
  164. * first power symbol to be annotated. If the pointer is NULL
  165. * the annotation starts at 1. The number is incremented for
  166. * each power symbol annotated.
  167. */
  168. void AnnotatePowerSymbols( int* aReference );
  169. /**
  170. * Function GetComponents
  171. * adds a SCH_REFERENCE() object to \a aReferences for each component in the sheet.
  172. * @param aReferences List of references to populate.
  173. * @param aIncludePowerSymbols Set to false to only get normal components.
  174. */
  175. void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true );
  176. /**
  177. * Function SetFootprintField
  178. * searches last sheet in the path for a component with \a aReference and set the footprint
  179. * field to \a aFootPrint if found.
  180. *
  181. * @param aReference The reference designator of the component.
  182. * @param aFootPrint The value to set the footprint field.
  183. * @param aSetVisible The value to set the field visibility flag.
  184. * @return True if \a aReference was found otherwise false.
  185. */
  186. bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
  187. bool aSetVisible );
  188. /**
  189. * Find the next schematic item in this sheet object.
  190. *
  191. * @param aType - The type of schematic item object to search for.
  192. * @param aLastItem - Start search from aLastItem. If no aLastItem, search from
  193. * the beginning of the list.
  194. * @param aWrap - Wrap around the end of the list to find the next item if aLastItem
  195. * is defined.
  196. * @return - The next schematic item if found. Otherwise, NULL is returned.
  197. */
  198. SCH_ITEM* FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false );
  199. /**
  200. * Find the previous schematic item in this sheet path object.
  201. *
  202. * @param aType - The type of schematic item object to search for.
  203. * @param aLastItem - Start search from aLastItem. If no aLastItem, search from
  204. * the end of the list.
  205. * @param aWrap - Wrap around the beginning of the list to find the next item if aLastItem
  206. * is defined.
  207. * @return - The previous schematic item if found. Otherwise, NULL is returned.
  208. */
  209. SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false );
  210. /**
  211. * Search this sheet path for the next item that matches the search criteria.
  212. *
  213. * @param aSearchData - Criteria to search item against.
  214. * @param aLastItem - Find next item after aLastItem if not NULL.
  215. * @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
  216. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  217. */
  218. SCH_ITEM* MatchNextItem( wxFindReplaceData& aSearchData, SCH_ITEM* aLastItem,
  219. wxPoint * aFindLocation );
  220. SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& d1 );
  221. bool operator==( const SCH_SHEET_PATH& d1 ) const;
  222. bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
  223. };
  224. /**
  225. * Class SCH_SHEET_LIST
  226. * handles the list of Sheets in a hierarchy.
  227. * Sheets are not unique, there can be many sheets with the same
  228. * filename and the same SCH_SCREEN reference.
  229. * The schematic (SCH_SCREEN) is shared between these sheets,
  230. * and component references are specific to a sheet path.
  231. * When a sheet is entered, component references and sheet number are updated.
  232. */
  233. class SCH_SHEET_LIST
  234. {
  235. private:
  236. SCH_SHEET_PATH* m_List;
  237. int m_count; /* Number of sheets included in hierarchy,
  238. * starting at the given sheet in constructor .
  239. * the given sheet is counted
  240. */
  241. int m_index; /* internal variable to handle GetNext():
  242. * cleared by GetFirst()
  243. * and incremented by GetNext() after
  244. * returning the next item in m_List
  245. * Also used for internal calculations in
  246. * BuildSheetList()
  247. */
  248. SCH_SHEET_PATH m_currList;
  249. public:
  250. /**
  251. * Constructor
  252. * builds the list of sheets from aSheet.
  253. * If aSheet == NULL (default) build the whole list of sheets in hierarchy.
  254. * So usually call it with no parameter.
  255. */
  256. SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
  257. ~SCH_SHEET_LIST()
  258. {
  259. if( m_List )
  260. free( m_List );
  261. m_List = NULL;
  262. }
  263. /**
  264. * Function GetCount
  265. * @return the number of sheets in list:
  266. * usually the number of sheets found in the whole hierarchy
  267. */
  268. int GetCount() { return m_count; }
  269. /**
  270. * Function GetFirst
  271. * @return the first item (sheet) in m_List and prepare calls to GetNext()
  272. */
  273. SCH_SHEET_PATH* GetFirst();
  274. /**
  275. * Function GetNext
  276. * @return the next item (sheet) in m_List or NULL if no more item in
  277. * sheet list
  278. */
  279. SCH_SHEET_PATH* GetNext();
  280. /**
  281. * Function GetLast
  282. * returns the last sheet in the sheet list.
  283. *
  284. * @return Last sheet in the list or NULL if sheet list is empty.
  285. */
  286. SCH_SHEET_PATH* GetLast();
  287. /**
  288. * Function GetPrevious
  289. * returns the previous sheet in the sheet list.
  290. *
  291. * @return The previous sheet in the sheet list or NULL if already at the
  292. * beginning of the list.
  293. */
  294. SCH_SHEET_PATH* GetPrevious();
  295. /**
  296. * Function GetSheet
  297. * @return the item (sheet) in aIndex position in m_List or NULL if less
  298. * than index items
  299. * @param aIndex = index in sheet list to get the sheet
  300. */
  301. SCH_SHEET_PATH* GetSheet( int aIndex );
  302. /**
  303. * Function IsModified
  304. * checks the entire hierarchy for any modifications.
  305. * @returns True if the hierarchy is modified otherwise false.
  306. */
  307. bool IsModified();
  308. void ClearModifyStatus();
  309. /**
  310. * Function AnnotatePowerSymbols
  311. * clear and annotates the entire hierarchy of the sheet path list.
  312. */
  313. void AnnotatePowerSymbols();
  314. /**
  315. * Function GetComponents
  316. * adds a SCH_REFERENCE() object to \a aReferences for each component in the list
  317. * of sheets.
  318. * @param aReferences List of references to populate.
  319. * @param aIncludePowerSymbols Set to false to only get normal components.
  320. */
  321. void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true );
  322. /**
  323. * Function FindNextItem
  324. * searches the entire schematic for the next schematic object.
  325. *
  326. * @param aType - The type of schematic item to find.
  327. * @param aSheetFound - The sheet the item was found in. NULL if the next item
  328. * is not found.
  329. * @param aLastItem - Find next item after aLastItem if not NULL.
  330. * @param aWrap - Wrap past around the end of the list of sheets.
  331. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  332. */
  333. SCH_ITEM* FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
  334. SCH_ITEM* aLastItem = NULL, bool aWrap = true );
  335. /**
  336. * Function FindPreviousItem
  337. * searches the entire schematic for the previous schematic item.
  338. *
  339. * @param aType - The type of schematic item to find.
  340. * @param aSheetFound - The sheet the item was found in. NULL if the previous item
  341. * is not found.
  342. * @param aLastItem - Find the previous item before aLastItem if not NULL.
  343. * @param aWrap - Wrap past around the beginning of the list of sheets.
  344. * @return If found, the previous schematic item. Otherwise, NULL.
  345. */
  346. SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
  347. SCH_ITEM* aLastItem = NULL, bool aWrap = true );
  348. /**
  349. * Function MatchNextItem
  350. * searches the entire schematic for the next item that matches the search criteria.
  351. *
  352. * @param aSearchData - Criteria to search item against.
  353. * @param aSheetFound - The sheet the item was found in. NULL if the next item
  354. * is not found.
  355. * @param aLastItem - Find next item after aLastItem if not NULL.
  356. * @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
  357. * @return If found, Returns the next schematic item. Otherwise, returns NULL.
  358. */
  359. SCH_ITEM* MatchNextItem( wxFindReplaceData& aSearchData,
  360. SCH_SHEET_PATH** aSheetFound,
  361. SCH_ITEM* aLastItem,
  362. wxPoint* aFindLocation );
  363. /**
  364. * Function SetFootprintField
  365. * searches all the sheets for a component with \a aReference and set the footprint
  366. * field to \a aFootPrint if found.
  367. *
  368. * @param aReference The reference designator of the component.
  369. * @param aFootPrint The value to set the footprint field.
  370. * @param aSetVisible The value to set the field visibility flag.
  371. * @return True if \a aReference was found otherwise false.
  372. */
  373. bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
  374. bool aSetVisible );
  375. private:
  376. /**
  377. * Function BuildSheetList
  378. * builds the list of sheets and their sheet path from \a aSheet.
  379. * If aSheet = g_RootSheet, the full sheet path and sheet list is built
  380. *
  381. * @param aSheet is the starting sheet from which the list is built,
  382. * or NULL indicating that g_RootSheet should be used.
  383. */
  384. void BuildSheetList( SCH_SHEET* aSheet );
  385. };
  386. #endif // CLASS_DRAWSHEET_PATH_H