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.

319 lines
11 KiB

18 years ago
18 years ago
18 years ago
17 years ago
17 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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_DRAWSHEET_H
  5. #define CLASS_DRAWSHEET_H
  6. #include "base_struct.h"
  7. extern SCH_SHEET* g_RootSheet;
  8. /**
  9. * Pin (label) used in sheets to create hierarchical schematics.
  10. *
  11. * A SCH_SHEET_PIN is used to create a hierarchical sheet in the same way a
  12. * pin is used in a component. It connects the objects in the sheet object
  13. * to the objects in the schematic page to the objects in the page that is
  14. * represented by the sheet. In a sheet object, a SCH_SHEET_PIN must be
  15. * connected to a wire, bus, or label. In the schematic page represented by
  16. * the sheet, it corresponds to a hierarchical label.
  17. */
  18. class SCH_SHEET_PIN : public SCH_ITEM, public EDA_TextStruct
  19. {
  20. public:
  21. int m_Edge, m_Shape;
  22. bool m_IsDangling; // TRUE non connected
  23. int m_Number; // used to numbered labels when writing data on file .
  24. // m_Number >= 2
  25. // value 0 is for sheet name and 1 for sheet filename
  26. public: SCH_SHEET_PIN( SCH_SHEET* parent,
  27. const wxPoint& pos = wxPoint( 0, 0 ),
  28. const wxString& text = wxEmptyString );
  29. ~SCH_SHEET_PIN() { }
  30. virtual wxString GetClass() const
  31. {
  32. return wxT( "SCH_SHEET_PIN" );
  33. }
  34. SCH_SHEET_PIN* GenCopy();
  35. SCH_SHEET_PIN* Next()
  36. {
  37. return ( SCH_SHEET_PIN*) Pnext;
  38. }
  39. void Place( WinEDA_SchematicFrame* frame,
  40. wxDC* DC );
  41. void Draw( WinEDA_DrawPanel* panel,
  42. wxDC* DC,
  43. const wxPoint& offset,
  44. int draw_mode,
  45. int Color = -1 );
  46. /**
  47. * Function Save
  48. * writes the data structures for this object out to a FILE in "*.sch"
  49. * format.
  50. * @param aFile The FILE to write to.
  51. * @return bool - true if success writing else false.
  52. */
  53. bool Save( FILE* aFile ) const;
  54. #if defined(DEBUG)
  55. // comment inherited by Doxygen from Base_Struct
  56. void Show( int nestLevel, std::ostream& os );
  57. #endif
  58. /** Function GetPenSize
  59. * @return the size of the "pen" that be used to draw or plot this item
  60. */
  61. virtual int GetPenSize();
  62. /** function CreateGraphicShape
  63. * Calculates the graphic shape (a polygon) associated to the text
  64. * @param aCorner_list = list to fill with polygon corners coordinates
  65. * @param Pos = Position of the shape
  66. */
  67. void CreateGraphicShape( std::vector <wxPoint>& aCorner_list,
  68. const wxPoint& Pos );
  69. // Geometric transforms (used in block operations):
  70. /** virtual function Move
  71. * move item to a new position.
  72. * @param aMoveVector = the displacement vector
  73. */
  74. virtual void Move( const wxPoint& aMoveVector )
  75. {
  76. m_Pos += aMoveVector;
  77. }
  78. /** virtual function Mirror_Y
  79. * mirror item relative to an Y axis
  80. * @param aYaxis_position = the y axis position
  81. */
  82. virtual void Mirror_Y( int aYaxis_position )
  83. {
  84. m_Edge = m_Edge ? 0 : 1;
  85. m_Pos.x -= aYaxis_position;
  86. NEGATE( m_Pos.x );
  87. m_Pos.x += aYaxis_position;
  88. }
  89. };
  90. /* class SCH_SHEET
  91. * This class is the sheet symbol placed in a schematic, and is the entry point
  92. * for a sub schematic
  93. */
  94. class SCH_SHEET : public SCH_ITEM
  95. {
  96. public:
  97. wxString m_SheetName; /* this is equivalent to C101 for
  98. * components: it is stored in F0 ...
  99. * of the file. */
  100. private:
  101. wxString m_FileName; /*also in SCH_SCREEN (redundant),
  102. * but need it here for loading after
  103. * reading the sheet description from
  104. * file. */
  105. public:
  106. int m_SheetNameSize; /* Size (height) of the text, used to
  107. * draw the sheet name */
  108. int m_FileNameSize; /* Size (height) of the text, used to
  109. * draw the file name */
  110. wxPoint m_Pos;
  111. wxSize m_Size; /* Position and Size of *sheet symbol */
  112. int m_Layer;
  113. SCH_SHEET_PIN* m_Label; /* Points Be connection, linked
  114. * list.*/
  115. int m_NbLabel; /* Pins sheet (corresponding to
  116. * hierarchical labels) count */
  117. SCH_SCREEN* m_AssociatedScreen; /* Associated Screen which
  118. * handle the physical data
  119. * In complex hierarchies we
  120. * can have many SCH_SHEET
  121. * using the same data
  122. */
  123. public:
  124. SCH_SHEET( const wxPoint& pos = wxPoint( 0, 0 ) );
  125. ~SCH_SHEET();
  126. virtual wxString GetClass() const
  127. {
  128. return wxT( "SCH_SHEET" );
  129. }
  130. /**
  131. * Function Save
  132. * writes the data structures for this object out to a FILE in "*.sch"
  133. * format.
  134. * @param aFile The FILE to write to.
  135. * @return bool - true if success writing else false.
  136. */
  137. bool Save( FILE* aFile ) const;
  138. void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
  139. SCH_SHEET* GenCopy();
  140. void DisplayInfo( WinEDA_DrawFrame* frame );
  141. /** Function CleanupSheet
  142. * Delete pinsheets which are not corresponding to a hierarchical label
  143. * @param aRedraw = true to redraw Sheet
  144. * @param aFrame = the schematic frame
  145. */
  146. void CleanupSheet( WinEDA_SchematicFrame* frame, bool aRedraw );
  147. /** Function GetPenSize
  148. * @return the size of the "pen" that be used to draw or plot this item
  149. */
  150. virtual int GetPenSize();
  151. /** Function Draw
  152. * Draw the hierarchical sheet shape
  153. * @param aPanel = the current DrawPanel
  154. * @param aDc = the current Device Context
  155. * @param aOffset = draw offset (usually wxPoint(0,0))
  156. * @param aDrawMode = draw mode
  157. * @param aColor = color used to draw sheet. Usually -1 to use the normal
  158. * color for sheet items
  159. */
  160. void Draw( WinEDA_DrawPanel* aPanel,
  161. wxDC* aDC,
  162. const wxPoint& aOffset,
  163. int aDrawMode,
  164. int aColor = -1 );
  165. /** Function HitTest
  166. * @return true if the point aPosRef is within item area
  167. * @param aPosRef = a wxPoint to test
  168. */
  169. bool HitTest( const wxPoint& aPosRef );
  170. /** Function GetBoundingBox
  171. * @return an EDA_Rect giving the bounding box of the sheet
  172. */
  173. EDA_Rect GetBoundingBox();
  174. void SwapData( SCH_SHEET* copyitem );
  175. /** Function ComponentCount
  176. * count our own components, without the power components.
  177. * @return the component count.
  178. */
  179. int ComponentCount();
  180. /** Function Load.
  181. * for the sheet: load the file m_FileName
  182. * if a screen already exists, the file is already read.
  183. * m_AssociatedScreen point on the screen, and its m_RefCount is
  184. * incremented
  185. * else creates a new associated screen and load the data file.
  186. * @param aFrame = a WinEDA_SchematicFrame pointer to the maim schematic
  187. * frame
  188. * @return true if OK
  189. */
  190. bool Load( WinEDA_SchematicFrame* aFrame );
  191. /** Function SearchHierarchy
  192. * search the existing hierarchy for an instance of screen "FileName".
  193. * @param aFilename = the filename to find
  194. * @param aFilename = a location to return a pointer to the screen (if
  195. * found)
  196. * @return bool if found, and a pointer to the screen
  197. */
  198. bool SearchHierarchy( wxString aFilename, SCH_SCREEN** aScreen );
  199. /** Function LocatePathOfScreen
  200. * search the existing hierarchy for an instance of screen "FileName".
  201. * don't bother looking at the root sheet - it must be unique,
  202. * no other references to its m_AssociatedScreen otherwise there would be
  203. * loops
  204. * in the hierarchy.
  205. * @param aScreen = the SCH_SCREEN* screen that we search for
  206. * @param aList = the SCH_SHEET_PATH* that must be used
  207. * @return true if found
  208. */
  209. bool LocatePathOfScreen( SCH_SCREEN* aScreen,
  210. SCH_SHEET_PATH* aList );
  211. /** Function CountSheets
  212. * calculates the number of sheets found in "this"
  213. * this number includes the full subsheets count
  214. * @return the full count of sheets+subsheets contained by "this"
  215. */
  216. int CountSheets();
  217. /** Function GetFileName
  218. * return the filename corresponding to this sheet
  219. * @return a wxString containing the filename
  220. */
  221. wxString GetFileName( void );
  222. // Set a new filename without changing anything else
  223. void SetFileName( const wxString& aFilename )
  224. {
  225. m_FileName = aFilename;
  226. }
  227. /** Function ChangeFileName
  228. * Set a new filename and manage data and associated screen
  229. * The main difficulty is the filename change in a complex hierarchy.
  230. * - if new filename is not already used: change to the new name (and if an
  231. * existing file is found, load it on request)
  232. * - if new filename is already used (a complex hierarchy) : reference the
  233. * sheet.
  234. * @param aFileName = the new filename
  235. * @param aFrame = the schematic frame
  236. */
  237. bool ChangeFileName( WinEDA_SchematicFrame* aFrame,
  238. const wxString& aFileName );
  239. //void RemoveSheet(SCH_SHEET* sheet);
  240. //to remove a sheet, just delete it
  241. //-- the destructor should take care of everything else.
  242. // Geometric transforms (used in block operations):
  243. /** virtual function Move
  244. * move item to a new position.
  245. * @param aMoveVector = the displacement vector
  246. */
  247. virtual void Move( const wxPoint& aMoveVector )
  248. {
  249. m_Pos += aMoveVector;
  250. SCH_SHEET_PIN* label = m_Label;
  251. while( label != NULL )
  252. {
  253. label->Move( aMoveVector );
  254. label = label->Next();
  255. }
  256. }
  257. /** virtual function Mirror_Y
  258. * mirror item relative to an Y axis
  259. * @param aYaxis_position = the y axis position
  260. */
  261. virtual void Mirror_Y( int aYaxis_position );
  262. #if defined(DEBUG)
  263. // comment inherited by Doxygen from Base_Struct
  264. void Show( int nestLevel, std::ostream& os );
  265. #endif
  266. };
  267. #endif /* CLASS_DRAWSHEET_H */