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.

281 lines
6.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: class_drawsheet.cpp
  3. // Purpose: member functions for DrawSheetStruct
  4. // header = class_drawsheet.h
  5. // Author: jean-pierre Charras
  6. // Modified by:
  7. // Created: 08/02/2006 18:37:02
  8. // RCS-ID:
  9. // Copyright:
  10. // Licence: License GNU
  11. /////////////////////////////////////////////////////////////////////////////
  12. // For compilers that support precompilation, includes "wx/wx.h".
  13. #include "wx/wxprec.h"
  14. #ifdef __BORLANDC__
  15. #pragma hdrstop
  16. #endif
  17. #ifndef WX_PRECOMP
  18. #include "wx/wx.h"
  19. #endif
  20. #include "fctsys.h"
  21. #include "common.h"
  22. #include "program.h"
  23. #include "libcmp.h"
  24. #include "general.h"
  25. /**********************************************/
  26. /* class to handle a series of sheets *********/
  27. /* a 'path' so to speak.. *********************/
  28. /**********************************************/
  29. DrawSheetPath::DrawSheetPath()
  30. {
  31. for( int i = 0; i<DSLSZ; i++ )
  32. m_sheets[i] = NULL;
  33. m_numSheets = 0;
  34. }
  35. int DrawSheetPath::Cmp( const DrawSheetPath& d ) const
  36. {
  37. if( m_numSheets > d.m_numSheets )
  38. return 1;
  39. if( m_numSheets < d.m_numSheets )
  40. return -1;
  41. //otherwise, same number of sheets.
  42. for( int i = 0; i<m_numSheets; i++ )
  43. {
  44. if( m_sheets[i]->m_TimeStamp > d.m_sheets[i]->m_TimeStamp )
  45. return 1;
  46. if( m_sheets[i]->m_TimeStamp < d.m_sheets[i]->m_TimeStamp )
  47. return -1;
  48. }
  49. return 0;
  50. }
  51. DrawSheetStruct* DrawSheetPath::Last()
  52. {
  53. if( m_numSheets )
  54. return m_sheets[m_numSheets - 1];
  55. return NULL;
  56. }
  57. SCH_SCREEN* DrawSheetPath::LastScreen()
  58. {
  59. if( m_numSheets )
  60. return m_sheets[m_numSheets - 1]->m_AssociatedScreen;
  61. return NULL;
  62. }
  63. EDA_BaseStruct* DrawSheetPath::LastDrawList()
  64. {
  65. if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen )
  66. return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList;
  67. return NULL;
  68. }
  69. void DrawSheetPath::Push( DrawSheetStruct* sheet )
  70. {
  71. wxASSERT( m_numSheets <= DSLSZ );
  72. if( m_numSheets < DSLSZ )
  73. {
  74. m_sheets[m_numSheets] = sheet;
  75. m_numSheets++;
  76. }
  77. }
  78. DrawSheetStruct* DrawSheetPath::Pop()
  79. {
  80. if( m_numSheets > 0 )
  81. {
  82. m_numSheets--;
  83. return m_sheets[m_numSheets];
  84. }
  85. return NULL;
  86. }
  87. wxString DrawSheetPath::Path()
  88. {
  89. wxString s, t;
  90. s = wxT( "/" );
  91. //start at 1 to avoid the root sheet,
  92. //which does not need to be added to the path
  93. //it's timestamp changes anyway.
  94. for( int i = 1; i< m_numSheets; i++ )
  95. {
  96. t.Printf( _( "%8.8lX/" ), m_sheets[i]->m_TimeStamp );
  97. s = s + t;
  98. }
  99. return s;
  100. }
  101. wxString DrawSheetPath::PathHumanReadable()
  102. {
  103. wxString s, t;
  104. s = wxT( "/" );
  105. //start at 1 to avoid the root sheet, as above.
  106. for( int i = 1; i< m_numSheets; i++ )
  107. {
  108. s = s + m_sheets[i]->m_SheetName + wxT( "/" );
  109. }
  110. return s;
  111. }
  112. /***********************************************/
  113. void DrawSheetPath::UpdateAllScreenReferences()
  114. /***********************************************/
  115. {
  116. EDA_BaseStruct* t = LastDrawList();
  117. while( t )
  118. {
  119. if( t->Type() == TYPE_SCH_COMPONENT )
  120. {
  121. SCH_COMPONENT* component = (SCH_COMPONENT*) t;
  122. component->GetField(REFERENCE)->m_Text = component->GetRef( this );
  123. component->m_Multi = component->GetUnitSelection( this );
  124. }
  125. t = t->Next();
  126. }
  127. }
  128. bool DrawSheetPath::operator=( const DrawSheetPath& d1 )
  129. {
  130. m_numSheets = d1.m_numSheets;
  131. int i;
  132. for( i = 0; i<m_numSheets; i++ )
  133. {
  134. m_sheets[i] = d1.m_sheets[i];
  135. }
  136. for( ; i<DSLSZ; i++ )
  137. {
  138. m_sheets[i] = 0;
  139. }
  140. return true;
  141. }
  142. bool DrawSheetPath::operator==( const DrawSheetPath& d1 )
  143. {
  144. if( m_numSheets != d1.m_numSheets )
  145. return false;
  146. for( int i = 0; i<m_numSheets; i++ )
  147. {
  148. if( m_sheets[i] != d1.m_sheets[i] )
  149. return false;
  150. }
  151. return true;
  152. }
  153. bool DrawSheetPath::operator!=( const DrawSheetPath& d1 )
  154. {
  155. if( m_numSheets != d1.m_numSheets )
  156. return true;
  157. for( int i = 0; i<m_numSheets; i++ )
  158. {
  159. if( m_sheets[i] != d1.m_sheets[i] )
  160. return true;
  161. }
  162. return false;
  163. }
  164. /*********************************************************************/
  165. /* Class EDA_SheetList to handle the list of Sheets in a hierarchy */
  166. /*********************************************************************/
  167. /*****************************************/
  168. DrawSheetPath* EDA_SheetList::GetFirst()
  169. /*****************************************/
  170. {
  171. m_index = 0;
  172. if( m_count > 0 )
  173. return &( m_List[0] );
  174. return NULL;
  175. }
  176. /*****************************************/
  177. DrawSheetPath* EDA_SheetList::GetNext()
  178. /*****************************************/
  179. {
  180. if( m_index < m_count )
  181. m_index++;
  182. return GetSheet( m_index );
  183. }
  184. /************************************************/
  185. DrawSheetPath* EDA_SheetList::GetSheet( int index )
  186. /************************************************/
  187. /* return the m_List[index] item
  188. */
  189. {
  190. if( index < m_count )
  191. return &(m_List[index]);
  192. return NULL;
  193. }
  194. /************************************************************************/
  195. void EDA_SheetList::BuildSheetList( DrawSheetStruct* sheet )
  196. /************************************************************************/
  197. {
  198. if( m_List == NULL )
  199. {
  200. int count = sheet->CountSheets();
  201. m_count = count;
  202. m_index = 0;
  203. count *= sizeof(DrawSheetPath);
  204. m_List = (DrawSheetPath*) MyZMalloc( count );
  205. m_currList.Clear();
  206. }
  207. m_currList.Push( sheet );
  208. m_List[m_index] = m_currList;
  209. m_index++;
  210. if( sheet->m_AssociatedScreen != NULL )
  211. {
  212. EDA_BaseStruct* strct = m_currList.LastDrawList();
  213. while( strct )
  214. {
  215. if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
  216. {
  217. DrawSheetStruct* sht = (DrawSheetStruct*) strct;
  218. BuildSheetList( sht );
  219. }
  220. strct = strct->Next();
  221. }
  222. }
  223. m_currList.Pop();
  224. }