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.

332 lines
8.8 KiB

  1. /*****************************************************/
  2. /* Gestion de la configuration generale de EESCHEMA */
  3. /*****************************************************/
  4. /* Gestion de la fenetre de selection des librarires actives, de leur chemin
  5. et du format des netlistes gnres
  6. */
  7. #include "fctsys.h"
  8. #include "common.h"
  9. #include "program.h"
  10. #include "libcmp.h"
  11. #include "general.h"
  12. #include "protos.h"
  13. #include "netlist.h"
  14. #include "id.h"
  15. /* Fonctions Locales */
  16. /***********/
  17. enum {
  18. SAVE_CFG = 1000,
  19. DEL_LIB,
  20. ADD_LIB,
  21. INSERT_LIB,
  22. FORMAT_NETLIST
  23. };
  24. /* Forward declarations */
  25. /* Routines Locales */
  26. /*************************************************/
  27. /* classe derivee pour la frame de Configuration */
  28. /*************************************************/
  29. class WinEDA_ConfigFrame: public wxDialog
  30. {
  31. private:
  32. protected:
  33. public:
  34. WinEDA_SchematicFrame * m_Parent;
  35. wxListBox * m_ListLibr;
  36. wxRadioBox *m_NetFormatBox;
  37. bool m_LibListChanged;
  38. WinEDA_EnterText * LibDirCtrl;
  39. // Constructor and destructor
  40. WinEDA_ConfigFrame(WinEDA_SchematicFrame *parent, const wxPoint& pos);
  41. ~WinEDA_ConfigFrame(void) {};
  42. void OnCloseWindow(wxCloseEvent & event);
  43. void CreateListFormatsNetListes(const wxPoint & pos);
  44. void SaveCfg(wxCommandEvent& event);
  45. void LibDelFct(wxCommandEvent& event);
  46. void AddOrInsertLibrary(wxCommandEvent& event);
  47. void ReturnNetFormat(wxCommandEvent& event);
  48. void ChangeSetup(void);
  49. DECLARE_EVENT_TABLE()
  50. };
  51. /* Construction de la table des evenements pour WinEDA_ConfigFrame */
  52. BEGIN_EVENT_TABLE(WinEDA_ConfigFrame, wxDialog)
  53. EVT_BUTTON(SAVE_CFG, WinEDA_ConfigFrame::SaveCfg)
  54. EVT_BUTTON(DEL_LIB, WinEDA_ConfigFrame::LibDelFct)
  55. EVT_BUTTON(ADD_LIB, WinEDA_ConfigFrame::AddOrInsertLibrary)
  56. EVT_BUTTON(INSERT_LIB, WinEDA_ConfigFrame::AddOrInsertLibrary)
  57. EVT_RADIOBOX(FORMAT_NETLIST, WinEDA_ConfigFrame::ReturnNetFormat)
  58. EVT_CLOSE(WinEDA_ConfigFrame::OnCloseWindow)
  59. END_EVENT_TABLE()
  60. /******************************************************************/
  61. void WinEDA_SchematicFrame::InstallConfigFrame(const wxPoint & pos)
  62. /******************************************************************/
  63. {
  64. WinEDA_ConfigFrame * CfgFrame = new WinEDA_ConfigFrame(this, pos);
  65. CfgFrame->ShowModal(); CfgFrame->Destroy();
  66. }
  67. #define X_SIZE 500
  68. #define Y_SIZE 360
  69. /********************************************************************/
  70. WinEDA_ConfigFrame::WinEDA_ConfigFrame(WinEDA_SchematicFrame *parent,
  71. const wxPoint& framepos):
  72. wxDialog(parent, -1, wxEmptyString, framepos, wxSize(X_SIZE, Y_SIZE),
  73. DIALOG_STYLE )
  74. /*****************************************************************/
  75. /* Constructeur de WinEDA_ConfigFrame: la fenetre de config des librairies
  76. */
  77. {
  78. wxPoint pos;
  79. wxSize size;
  80. int dimy;
  81. wxString msg;
  82. wxButton * Button;
  83. m_Parent = parent;
  84. m_LibListChanged = FALSE;
  85. SetFont(*g_DialogFont);
  86. msg = _("from ") + EDA_Appl->m_CurrentOptionFile;
  87. SetTitle(msg);
  88. /* Creation des boutons de commande */
  89. pos.x = 10; pos.y = 5;
  90. Button = new wxButton(this, SAVE_CFG, _("Save Cfg"), pos);
  91. Button->SetForegroundColour(*wxRED);
  92. pos.x = 230;
  93. Button = new wxButton(this, DEL_LIB, _("Del"), pos);
  94. Button->SetForegroundColour(*wxRED);
  95. pos.x += Button->GetSize().x;
  96. Button = new wxButton(this, ADD_LIB, _("Add"), pos );
  97. Button->SetForegroundColour(wxColor(0,80,0));
  98. pos.x += Button->GetSize().x;
  99. Button = new wxButton(this, INSERT_LIB, _("Ins"), pos );
  100. Button->SetForegroundColour(*wxBLUE);
  101. pos.x = 10; pos.y = 45;
  102. CreateListFormatsNetListes(pos);
  103. pos.x = 235; pos.y = 55;
  104. m_ListLibr = new wxListBox(this,
  105. -1, pos, wxSize(X_SIZE - pos.x -10,225),
  106. 0,NULL,
  107. wxLB_ALWAYS_SB|wxLB_SINGLE);
  108. wxStaticText * Msg = new wxStaticText(this, -1, _("Libraries"),
  109. wxPoint(pos.x, pos.y - 14) );
  110. Msg->SetForegroundColour(wxColour(200,0,0) );
  111. m_ListLibr->InsertItems(g_LibName_List, 0);
  112. // Affichage des extensions des diff�rents fichiers:
  113. dimy = 17;
  114. pos.x = 10;
  115. pos.y = m_NetFormatBox->GetPosition().y + m_NetFormatBox->GetSize().y + 10;
  116. wxStaticBox * Box = new wxStaticBox(this, -1, _("Files ext:"), pos, wxSize(180,110) );
  117. pos.y += 20; pos.x += 10;
  118. msg = _("Cmp file Ext: ") + g_NetCmpExtBuffer;
  119. wxStaticText * text = new wxStaticText(this, -1, msg, pos);
  120. pos.y += dimy;
  121. msg = _("Net file Ext: ") + g_NetExtBuffer;
  122. text = new wxStaticText(this, -1, msg, pos);
  123. pos.y += dimy;
  124. msg = _("Library file Ext: ") + g_LibExtBuffer;
  125. text = new wxStaticText(this, -1, msg, pos);
  126. pos.y += dimy;
  127. msg = _("Symbol file Ext: ") + g_SymbolExtBuffer;
  128. text = new wxStaticText(this, -1, msg, pos);
  129. pos.y += dimy;
  130. msg = _("Schematic file Ext: ") + g_SchExtBuffer;
  131. text = new wxStaticText(this, -1, msg, pos);
  132. int posY = Box->GetPosition().y + Box->GetSize().y + 30;
  133. pos.x = 10; pos.y = MAX(310, posY);
  134. size.x = X_SIZE - pos.x -10; size.y = -1;
  135. LibDirCtrl = new WinEDA_EnterText(this,
  136. _("Library files path:"), g_UserLibDirBuffer,
  137. pos, size);
  138. pos.y += LibDirCtrl->GetDimension().y + 5;
  139. SetClientSize(wxSize(X_SIZE, pos.y) );
  140. }
  141. /***********************************************************/
  142. void WinEDA_ConfigFrame::OnCloseWindow(wxCloseEvent & event)
  143. /***********************************************************/
  144. {
  145. ChangeSetup();
  146. if ( m_LibListChanged )
  147. {
  148. LoadLibraries(m_Parent);
  149. if ( m_Parent->m_Parent->ViewlibFrame )
  150. m_Parent->m_Parent->ViewlibFrame->ReCreateListLib();
  151. }
  152. EndModal(0);
  153. }
  154. /*******************************************/
  155. void WinEDA_ConfigFrame::ChangeSetup(void)
  156. /*******************************************/
  157. {
  158. g_UserLibDirBuffer = LibDirCtrl->GetData();
  159. SetRealLibraryPath( wxT("library") );
  160. }
  161. /******************************************************/
  162. void WinEDA_ConfigFrame::SaveCfg(wxCommandEvent& event)
  163. /******************************************************/
  164. {
  165. ChangeSetup();
  166. m_Parent->Save_Config(this);
  167. }
  168. /********************************************************/
  169. void WinEDA_ConfigFrame::LibDelFct(wxCommandEvent& event)
  170. /********************************************************/
  171. {
  172. int ii;
  173. ii = m_ListLibr->GetSelection();
  174. if ( ii < 0 ) return;
  175. g_LibName_List.RemoveAt(ii);
  176. m_ListLibr->Clear();
  177. m_ListLibr->InsertItems(g_LibName_List, 0);
  178. m_LibListChanged = TRUE;
  179. }
  180. /****************************************************************/
  181. void WinEDA_ConfigFrame::AddOrInsertLibrary(wxCommandEvent& event)
  182. /****************************************************************/
  183. /* Insert or add a library to the existing library list:
  184. New library is put in list before (insert) or after (add)
  185. the selection
  186. */
  187. {
  188. int ii;
  189. wxString FullLibName,ShortLibName, Mask;
  190. ii = m_ListLibr->GetSelection();
  191. if ( ii < 0 ) ii = 0;
  192. ChangeSetup();
  193. if( event.GetId() == ADD_LIB)
  194. {
  195. if( g_LibName_List.GetCount() != 0 ) ii ++; /* Add after selection */
  196. }
  197. Mask = wxT("*") + g_LibExtBuffer;
  198. FullLibName = EDA_FileSelector( _("Library files:"),
  199. g_RealLibDirBuffer, /* Chemin par defaut */
  200. wxEmptyString, /* nom fichier par defaut */
  201. g_LibExtBuffer, /* extension par defaut */
  202. Mask, /* Masque d'affichage */
  203. this,
  204. wxFD_OPEN,
  205. TRUE
  206. );
  207. if ( FullLibName.IsEmpty() ) return;
  208. ShortLibName = MakeReducedFileName(FullLibName,g_RealLibDirBuffer,g_LibExtBuffer);
  209. //Add or insert new library name
  210. if (FindLibrary(ShortLibName) == NULL)
  211. {
  212. m_LibListChanged = TRUE;
  213. g_LibName_List.Insert(ShortLibName, ii);
  214. m_ListLibr->Clear();
  215. m_ListLibr->InsertItems(g_LibName_List, 0);
  216. }
  217. else DisplayError(this, _("Library already in use"));
  218. }
  219. /**************************************************************/
  220. void WinEDA_ConfigFrame::ReturnNetFormat(wxCommandEvent& event)
  221. /**************************************************************/
  222. {
  223. int ii;
  224. ii = m_NetFormatBox->GetSelection();
  225. if ( ii == 0 ) g_NetFormat = NET_TYPE_PCBNEW;
  226. if ( ii == 1 ) g_NetFormat = NET_TYPE_ORCADPCB2;
  227. else if ( ii == 2 ) g_NetFormat = NET_TYPE_CADSTAR;
  228. else if ( ii == 3 ) g_NetFormat = NET_TYPE_SPICE;
  229. else if ( g_NetFormat < NET_TYPE_CUSTOM1 ) g_NetFormat = NET_TYPE_CUSTOM1;
  230. }
  231. /***********************************************************************/
  232. void WinEDA_ConfigFrame::CreateListFormatsNetListes(const wxPoint & pos)
  233. /***********************************************************************/
  234. /* Message de wxRadioBox de selection type netliste */
  235. {
  236. wxString Net_Select[] =
  237. { wxT("&PcbNew"), wxT("&OrcadPcb2"), wxT("&CadStar"), wxT("&Spice"), wxT("Other")};
  238. m_NetFormatBox = new wxRadioBox(this, FORMAT_NETLIST,
  239. _("NetList Formats:"),
  240. pos, wxSize(-1,-1),
  241. 5, Net_Select, 1, wxRA_SPECIFY_COLS);
  242. switch( g_NetFormat )
  243. {
  244. case NET_TYPE_NOT_INIT:
  245. case NET_TYPE_PCBNEW:
  246. m_NetFormatBox->SetSelection(0);
  247. break;
  248. case NET_TYPE_ORCADPCB2:
  249. m_NetFormatBox->SetSelection(1);
  250. break;
  251. case NET_TYPE_CADSTAR:
  252. m_NetFormatBox->SetSelection(2);
  253. break;
  254. case NET_TYPE_SPICE:
  255. m_NetFormatBox->SetSelection(3);
  256. break;
  257. default:
  258. m_NetFormatBox->SetSelection(4);
  259. break;
  260. }
  261. }