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.

385 lines
9.1 KiB

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
18 years ago
18 years ago
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialog_drc.h
  3. // Author: jean-pierre Charras
  4. // Licence: GPL
  5. /////////////////////////////////////////////////////////////////////////////
  6. #ifndef _DIALOG_DRC_H_
  7. #define _DIALOG_DRC_H_
  8. #include <wx/htmllbox.h>
  9. // forward declarations
  10. class DRCLISTBOX;
  11. //end forward declarations
  12. #include "fctsys.h"
  13. #include "pcbnew.h"
  14. #include "class_drawpanel.h"
  15. #include "wxstruct.h"
  16. #include "drc_stuff.h"
  17. #include "dialog_drc_base.h"
  18. // outside @end control identifiers since wxFormBuilder knows not DRCLISTBOX
  19. #define ID_DRCLISTCTRL 14000
  20. #define ID_POPUP_UNCONNECTED_A 14001
  21. #define ID_POPUP_UNCONNECTED_B 14002
  22. #define ID_POPUP_MARKERS_A 14003
  23. #define ID_POPUP_MARKERS_B 14004
  24. /*!
  25. * DrcDialog class declaration
  26. */
  27. class DIALOG_DRC_CONTROL: public DIALOG_DRC_CONTROL_BASE
  28. {
  29. public:
  30. BOARD_DESIGN_SETTINGS* m_BrdSettings;
  31. /// Constructors
  32. DIALOG_DRC_CONTROL( DRC* aTester, WinEDA_PcbFrame* parent );
  33. ~DIALOG_DRC_CONTROL(){};
  34. /**
  35. * Function Show
  36. * overloads the wxDialog::Show() function so it can position the
  37. * dialog at its remembered size and position.
  38. */
  39. bool Show( bool show );
  40. private:
  41. static wxSize s_LastSize; ///< last position and size
  42. static wxPoint s_LastPos;
  43. /**
  44. * Function writeReport
  45. * outputs the MARKER items and unconnecte DRC_ITEMs with commentary to an
  46. * open text file.
  47. * @param fpOut The text file to write the report to.
  48. */
  49. void writeReport( FILE* fpOut );
  50. void InitValues( );
  51. void SetDrcParmeters( );
  52. /// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_CHECKBOX
  53. void OnReportCheckBoxClicked( wxCommandEvent& event );
  54. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_BROWSE_RPT_FILE
  55. void OnButtonBrowseRptFileClick( wxCommandEvent& event );
  56. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_STARTDRC
  57. void OnStartdrcClick( wxCommandEvent& event );
  58. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_LIST_UNCONNECTED
  59. void OnListUnconnectedClick( wxCommandEvent& event );
  60. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DELETE_ALL
  61. void OnDeleteAllClick( wxCommandEvent& event );
  62. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DELETE_ONE
  63. void OnDeleteOneClick( wxCommandEvent& event );
  64. /// wxEVT_LEFT_DCLICK event handler for ID_CLEARANCE_LIST
  65. void OnLeftDClickClearance( wxMouseEvent& event );
  66. /// wxEVT_RIGHT_UP event handler for ID_CLEARANCE_LIST
  67. void OnRightUpClearance( wxMouseEvent& event );
  68. /// wxEVT_LEFT_DCLICK event handler for ID_UNCONNECTED_LIST
  69. void OnLeftDClickUnconnected( wxMouseEvent& event );
  70. /// wxEVT_RIGHT_UP event handler for ID_UNCONNECTED_LIST
  71. void OnRightUpUnconnected( wxMouseEvent& event );
  72. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
  73. void OnCancelClick( wxCommandEvent& event );
  74. /// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
  75. void OnOkClick( wxCommandEvent& event );
  76. void OnMarkerSelectionEvent( wxCommandEvent& event );
  77. void OnUnconnectedSelectionEvent( wxCommandEvent& event );
  78. void DelDRCMarkers();
  79. void RedrawDrawPanel();
  80. void OnPopupMenu( wxCommandEvent& event );
  81. DRC* m_tester;
  82. WinEDA_PcbFrame* m_Parent;
  83. int m_UnconnectedCount;
  84. };
  85. /**
  86. * Class DRC_LIST_MARKERS
  87. * is an implementation of the interface named DRC_ITEM_LIST which uses
  88. * a BOARD instance to fulfill the interface. No ownership is taken of the
  89. * BOARD.
  90. */
  91. class DRC_LIST_MARKERS : public DRC_ITEM_LIST
  92. {
  93. BOARD* m_board;
  94. public:
  95. DRC_LIST_MARKERS( BOARD* aBoard ) :
  96. m_board(aBoard)
  97. {
  98. }
  99. /* no destructor since we do not own anything to delete, not even the BOARD.
  100. ~DRC_LIST_MARKERS() {}
  101. */
  102. //-----<Interface DRC_ITEM_LIST>---------------------------------------
  103. void DeleteAllItems()
  104. {
  105. m_board->DeleteMARKERs();
  106. }
  107. const DRC_ITEM* GetItem( int aIndex )
  108. {
  109. const MARKER_PCB* marker = m_board->GetMARKER( aIndex );
  110. if( marker )
  111. return &marker->GetReporter();
  112. return NULL;
  113. }
  114. void DeleteItem( int aIndex )
  115. {
  116. MARKER_PCB* marker = m_board->GetMARKER( aIndex );
  117. if( marker )
  118. m_board->Delete( marker );
  119. }
  120. /**
  121. * Function GetCount
  122. * returns the number of items in the list.
  123. */
  124. int GetCount()
  125. {
  126. return m_board->GetMARKERCount();
  127. }
  128. //-----</Interface DRC_ITEM_LIST>--------------------------------------
  129. };
  130. /**
  131. * Class DRC_LIST_UNCONNECTED
  132. * is an implementation of the interface named DRC_ITEM_LIST which uses
  133. * a vector of pointers to DRC_ITEMs to fulfill the interface. No ownership is taken of the
  134. * vector, which will reside in class DRC
  135. */
  136. class DRC_LIST_UNCONNECTED : public DRC_ITEM_LIST
  137. {
  138. DRC_LIST* m_vector;
  139. public:
  140. DRC_LIST_UNCONNECTED( DRC_LIST* aList ) :
  141. m_vector(aList)
  142. {
  143. }
  144. /* no destructor since we do not own anything to delete, not even the BOARD.
  145. ~DRC_LIST_UNCONNECTED() {}
  146. */
  147. //-----<Interface DRC_ITEM_LIST>---------------------------------------
  148. void DeleteAllItems()
  149. {
  150. if( m_vector )
  151. {
  152. for( unsigned i=0; i<m_vector->size(); ++i )
  153. delete (*m_vector)[i];
  154. m_vector->clear();
  155. }
  156. }
  157. const DRC_ITEM* GetItem( int aIndex )
  158. {
  159. if( m_vector && (unsigned)aIndex < m_vector->size() )
  160. {
  161. const DRC_ITEM* item = (*m_vector)[aIndex];
  162. return item;
  163. }
  164. return NULL;
  165. }
  166. void DeleteItem( int aIndex )
  167. {
  168. if( m_vector && (unsigned)aIndex < m_vector->size() )
  169. {
  170. delete (*m_vector)[aIndex];
  171. m_vector->erase( m_vector->begin()+aIndex );
  172. }
  173. }
  174. /**
  175. * Function GetCount
  176. * returns the number of items in the list.
  177. */
  178. int GetCount()
  179. {
  180. if( m_vector )
  181. {
  182. return m_vector->size();
  183. }
  184. return 0;
  185. }
  186. //-----</Interface DRC_ITEM_LIST>--------------------------------------
  187. };
  188. /**
  189. * Class DRCLISTBOX
  190. * is used to display a DRC_ITEM_LIST.
  191. */
  192. class DRCLISTBOX : public wxHtmlListBox
  193. {
  194. private:
  195. DRC_ITEM_LIST* m_list; ///< wxHtmlListBox does not own the list, I do
  196. public:
  197. DRCLISTBOX( wxWindow* parent, wxWindowID id = wxID_ANY,
  198. const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
  199. long style = 0, const wxString choices[] = NULL, int unused = 0)
  200. : wxHtmlListBox( parent, id, pos, size, style )
  201. {
  202. m_list = 0;
  203. }
  204. ~DRCLISTBOX()
  205. {
  206. delete m_list; // I own it, I destroy it.
  207. }
  208. /**
  209. * Function SetList
  210. * sets the DRC_ITEM_LIST for this listbox. Ownership of the DRC_ITEM_LIST is
  211. * transfered to this DRCLISTBOX.
  212. * @param aList The DRC_ITEM_LIST* containing the DRC_ITEMs which will be
  213. * displayed in the wxHtmlListBox
  214. */
  215. void SetList( DRC_ITEM_LIST* aList )
  216. {
  217. delete m_list;
  218. m_list = aList;
  219. SetItemCount( aList->GetCount() );
  220. Refresh();
  221. }
  222. /**
  223. * Function GetItem
  224. * returns a requested DRC_ITEM* or NULL.
  225. */
  226. const DRC_ITEM* GetItem( int aIndex )
  227. {
  228. if( m_list )
  229. {
  230. return m_list->GetItem( aIndex );
  231. }
  232. return NULL;
  233. }
  234. /**
  235. * Function OnGetItem
  236. * returns the html text associated with the DRC_ITEM given by index 'n'.
  237. * @param n An index into the list.
  238. * @return wxString - the simple html text to show in the listbox.
  239. */
  240. wxString OnGetItem( size_t n ) const
  241. {
  242. if( m_list )
  243. {
  244. const DRC_ITEM* item = m_list->GetItem( (int) n );
  245. if( item )
  246. return item->ShowHtml();
  247. }
  248. return wxString();
  249. }
  250. /**
  251. * Function OnGetItem
  252. * returns the html text associated with the given index 'n'.
  253. * @param n An index into the list.
  254. * @return wxString - the simple html text to show in the listbox.
  255. */
  256. wxString OnGetItemMarkup( size_t n ) const
  257. {
  258. return OnGetItem( n );
  259. }
  260. /**
  261. * Function DeleteElement
  262. * will delete one of the items in the list.
  263. * @param aIndex The index into the list to delete.
  264. */
  265. void DeleteItem( int aIndex )
  266. {
  267. if( m_list )
  268. {
  269. int selection = GetSelection();
  270. m_list->DeleteItem( aIndex );
  271. int count = m_list->GetCount();
  272. SetItemCount( count );
  273. // if old selection >= new count
  274. if( selection >= count )
  275. SetSelection( count-1 ); // -1 is "no selection"
  276. Refresh();
  277. }
  278. }
  279. /**
  280. * Function DeleteAllItems
  281. * deletes all items in the list.
  282. */
  283. void DeleteAllItems()
  284. {
  285. if( m_list )
  286. {
  287. m_list->DeleteAllItems();
  288. SetItemCount(0);
  289. SetSelection( -1 ); // -1 is no selection
  290. Refresh();
  291. }
  292. }
  293. };
  294. #endif // _DIALOG_DRC_H_