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.

1103 lines
33 KiB

  1. /**************************************************************/
  2. /* librairy editor: edition of component general properties */
  3. /**************************************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "program.h"
  8. #include "libcmp.h"
  9. #include "general.h"
  10. #include "protos.h"
  11. enum id_libedit {
  12. ID_PANEL_ALIAS,
  13. ID_PANEL_FIELD,
  14. ID_COPY_DOC_TO_ALIAS,
  15. ID_BROWSE_DOC_FILES,
  16. ID_ADD_ALIAS,
  17. ID_DELETE_ONE_ALIAS,
  18. ID_DELETE_ALL_ALIAS,
  19. ID_ON_SELECT_FIELD
  20. };
  21. /* Routines locales */
  22. /* Variables locales */
  23. extern int CurrentUnit;
  24. /* Classe de la frame des propri�t�s d'un composant en librairie */
  25. /* Cette classe genere une fenetre type NoteBook, pour l'edition des propri�t�s
  26. d'un composant le librairie.
  27. On peut diter:
  28. Texte dimensions et justification de tous les champs (Ref, Val, et autres champs)
  29. Documentation et mots clefs
  30. Nombre de part par boitier
  31. et autres proprirs gnrales
  32. */
  33. #include "dialog_edit_component_in_lib.cpp"
  34. /*****************************************************************/
  35. void WinEDA_LibeditFrame::InstallLibeditFrame(const wxPoint & pos)
  36. /*****************************************************************/
  37. {
  38. wxPoint fpos = pos;
  39. WinEDA_PartPropertiesFrame * frame =
  40. new WinEDA_PartPropertiesFrame(this);
  41. int IsModified = frame->ShowModal(); frame->Destroy();
  42. if ( IsModified ) Refresh();
  43. }
  44. /***************************************************************************/
  45. void WinEDA_PartPropertiesFrame::CopyFieldDataToBuffer(LibDrawField * Field)
  46. /***************************************************************************/
  47. /* copy the field data (name, attributes, size, position... to corresponding buffers
  48. for editing
  49. */
  50. {
  51. int id = Field->m_FieldId;
  52. m_FieldFlags[id] = (Field->m_Attributs & TEXT_NO_VISIBLE) ? 0 : 1;
  53. m_FieldOrient[id] = Field->m_Orient;
  54. if ( Field->m_HJustify == GR_TEXT_HJUSTIFY_LEFT)
  55. m_FieldHJustify[id] = 0;
  56. else if ( Field->m_HJustify == GR_TEXT_HJUSTIFY_RIGHT)
  57. m_FieldHJustify[id] = 2;
  58. else
  59. m_FieldHJustify[id] = 1;
  60. if ( Field->m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM)
  61. m_FieldVJustify[id] = 0;
  62. else if ( Field->m_VJustify == GR_TEXT_VJUSTIFY_TOP)
  63. m_FieldVJustify[id] = 2;
  64. else m_FieldVJustify[id] = 1;
  65. m_FieldText[id] = Field->m_Text;
  66. if ( id >= FIELD1 ) m_FieldName[id] = Field->m_Name;
  67. m_FieldPosition[id] = Field->m_Pos;
  68. // Note: the Y axis for components in lib is from bottom to top
  69. // and the screen axis is top to bottom: we must change the y coord sign for editing
  70. m_FieldPosition[id].y = - m_FieldPosition[id].y;
  71. m_FieldSize[id] = Field->m_Size.x;
  72. }
  73. /***************************************************************************/
  74. void WinEDA_PartPropertiesFrame::CopyBufferToFieldData(LibDrawField * Field)
  75. /***************************************************************************/
  76. /* Copy data from buffers(name, attributes, size, position... )to the
  77. field "Field"
  78. */
  79. {
  80. int hjustify[3] = { GR_TEXT_HJUSTIFY_LEFT , GR_TEXT_HJUSTIFY_CENTER,
  81. GR_TEXT_HJUSTIFY_RIGHT };
  82. int vjustify[3] = { GR_TEXT_VJUSTIFY_BOTTOM , GR_TEXT_VJUSTIFY_CENTER,
  83. GR_TEXT_VJUSTIFY_TOP };
  84. int ii = Field->m_FieldId;
  85. Field->m_Text = m_FieldText[ii];
  86. if ( ii >= FIELD1 && m_FieldName[ii] != ReturnDefaultFieldName(ii) )
  87. Field->m_Name = m_FieldName[ii];
  88. else Field->m_Name.Empty();
  89. Field->m_Size.x = Field->m_Size.y = m_FieldSize[ii];
  90. Field->m_HJustify = hjustify[m_FieldHJustify[ii]];
  91. Field->m_VJustify = vjustify[m_FieldVJustify[ii]];
  92. if ( m_FieldFlags[ii] )
  93. Field->m_Attributs &= ~TEXT_NO_VISIBLE;
  94. else
  95. Field->m_Attributs |= TEXT_NO_VISIBLE;
  96. Field->m_Orient = m_FieldOrient[ii] ? 1 : 0;
  97. Field->m_Pos = m_FieldPosition[ii];
  98. // Note: the Y axis for components in lib is from bottom to top
  99. // and the screen axis is top to bottom: we must change the y coord sign after editing
  100. Field->m_Pos.y = - Field->m_Pos.y;
  101. }
  102. /*****************************************************/
  103. void WinEDA_PartPropertiesFrame::InitBuffers(void)
  104. /*****************************************************/
  105. /* Init the buffers to a default value,
  106. or to values from CurrentLibEntry if CurrentLibEntry != NULL
  107. */
  108. {
  109. int ii;
  110. m_CurrentFieldId = REFERENCE;
  111. for ( ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
  112. {
  113. if ( ii < FIELD1 )
  114. m_FieldName[ii] = ReturnDefaultFieldName(ii);
  115. m_FieldFlags[ii] = 1;
  116. m_FieldOrient[ii] = 0;
  117. m_FieldSize[ii] = DEFAULT_TEXT_SIZE;
  118. m_FieldHJustify[ii] = 1;
  119. m_FieldVJustify[ii] = 1;
  120. }
  121. m_AliasLocation = -1;
  122. if ( CurrentLibEntry == NULL )
  123. {
  124. m_Title = _("Lib Component Properties");
  125. return;
  126. }
  127. wxString msg_text = _("Properties for ");
  128. if ( ! CurrentAliasName.IsEmpty() )
  129. {
  130. m_AliasLocation = LocateAlias( CurrentLibEntry->m_AliasList, CurrentAliasName);
  131. m_Title = msg_text + CurrentAliasName +
  132. _("(alias of ") +
  133. wxString(CurrentLibEntry->m_Name.m_Text)
  134. + wxT(")");
  135. }
  136. else
  137. {
  138. m_Title = msg_text + CurrentLibEntry->m_Name.m_Text;
  139. CurrentAliasName.Empty();
  140. }
  141. CopyFieldDataToBuffer(& CurrentLibEntry->m_Prefix);
  142. CopyFieldDataToBuffer(& CurrentLibEntry->m_Name);
  143. LibDrawField * Field = CurrentLibEntry->Fields;
  144. while ( Field )
  145. {
  146. CopyFieldDataToBuffer(Field);
  147. Field = (LibDrawField*)Field->Pnext;
  148. }
  149. }
  150. /*****************************************************/
  151. void WinEDA_PartPropertiesFrame::BuildPanelAlias(void)
  152. /*****************************************************/
  153. /* create the panel for component alias list editing
  154. */
  155. {
  156. wxButton * Button;
  157. m_PanelAlias->SetFont(*g_DialogFont);
  158. wxBoxSizer * PanelAliasBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  159. m_PanelAlias->SetSizer(PanelAliasBoxSizer);
  160. wxBoxSizer * LeftBoxSizer = new wxBoxSizer(wxVERTICAL);
  161. PanelAliasBoxSizer->Add(LeftBoxSizer, 0 , wxGROW|wxALL, 5);
  162. wxStaticText * Msg = new wxStaticText(m_PanelAlias, -1, _("Alias"));
  163. Msg->SetForegroundColour(wxColour(200,0,0) );
  164. LeftBoxSizer->Add(Msg, 0 , wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
  165. m_PartAliasList = new wxListBox(m_PanelAlias,
  166. -1,
  167. wxDefaultPosition, wxSize(200,250),
  168. 0,NULL,
  169. wxLB_ALWAYS_SB|wxLB_SINGLE);
  170. LeftBoxSizer->Add(m_PartAliasList, 0 , wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  171. wxBoxSizer * RightBoxSizer = new wxBoxSizer(wxVERTICAL);
  172. PanelAliasBoxSizer->Add(RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  173. Button = new wxButton(m_PanelAlias, ID_ADD_ALIAS, _("Add"));
  174. Button->SetForegroundColour(*wxBLUE);
  175. RightBoxSizer->Add(Button, 0 , wxGROW|wxALL, 5);
  176. m_ButtonDeleteOneAlias = new wxButton(m_PanelAlias, ID_DELETE_ONE_ALIAS,
  177. _("Delete"));
  178. m_ButtonDeleteOneAlias->SetForegroundColour(*wxRED);
  179. RightBoxSizer->Add(m_ButtonDeleteOneAlias, 0 , wxGROW|wxALL, 5);
  180. m_ButtonDeleteAllAlias = new wxButton(m_PanelAlias, ID_DELETE_ALL_ALIAS,
  181. _("Delete All"));
  182. m_ButtonDeleteAllAlias->SetForegroundColour(*wxRED);
  183. if ( ! CurrentAliasName.IsEmpty() ) m_ButtonDeleteAllAlias->Enable(FALSE);
  184. RightBoxSizer->Add(m_ButtonDeleteAllAlias, 0 , wxGROW|wxALL, 5);
  185. /* lecture des noms des alias */
  186. if ( CurrentLibEntry )
  187. {
  188. for ( unsigned ii = 0; ii < CurrentLibEntry->m_AliasList.GetCount(); ii += ALIAS_NEXT)
  189. m_PartAliasList->Append(CurrentLibEntry->m_AliasList[ii+ALIAS_NAME]);
  190. }
  191. if ( (CurrentLibEntry == NULL) || (CurrentLibEntry->m_AliasList.GetCount() == 0) )
  192. {
  193. m_ButtonDeleteAllAlias->Enable(FALSE);
  194. m_ButtonDeleteOneAlias->Enable(FALSE);
  195. }
  196. }
  197. /*****************************************************************/
  198. void WinEDA_PartPropertiesFrame::BuildPanelFootprintFilter(void)
  199. /*****************************************************************/
  200. /* create the panel for footprint filtering in cvpcb list
  201. */
  202. {
  203. m_PanelFootprintFilter = new wxPanel( m_NoteBook, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
  204. m_NoteBook->AddPage(m_PanelFootprintFilter, _("Footprint Filter"));
  205. m_PanelFootprintFilter->SetFont(*g_DialogFont);
  206. wxBoxSizer * PanelFpFilterBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  207. m_PanelFootprintFilter->SetSizer(PanelFpFilterBoxSizer);
  208. wxBoxSizer * LeftBoxSizer = new wxBoxSizer(wxVERTICAL);
  209. PanelFpFilterBoxSizer->Add(LeftBoxSizer, 0 , wxGROW|wxALL, 5);
  210. wxStaticText * Msg = new wxStaticText(m_PanelFootprintFilter, -1, _("Footprints"));
  211. Msg->SetForegroundColour(wxColour(200,0,0) );
  212. LeftBoxSizer->Add(Msg, 0 , wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
  213. m_FootprintFilterListBox = new wxListBox(m_PanelFootprintFilter,
  214. -1,
  215. wxDefaultPosition, wxSize(200,250),
  216. 0,NULL,
  217. wxLB_ALWAYS_SB|wxLB_SINGLE);
  218. LeftBoxSizer->Add(m_FootprintFilterListBox, 0 , wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  219. wxBoxSizer * RightBoxSizer = new wxBoxSizer(wxVERTICAL);
  220. PanelFpFilterBoxSizer->Add(RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  221. wxButton * Button = new wxButton(m_PanelFootprintFilter, ID_ADD_FOOTPRINT_FILTER, _("Add"));
  222. Button->SetForegroundColour(*wxBLUE);
  223. RightBoxSizer->Add(Button, 0 , wxGROW|wxALL, 5);
  224. m_ButtonDeleteOneFootprintFilter = new wxButton(m_PanelFootprintFilter, ID_DELETE_ONE_FOOTPRINT_FILTER,
  225. _("Delete"));
  226. m_ButtonDeleteOneFootprintFilter->SetForegroundColour(*wxRED);
  227. RightBoxSizer->Add(m_ButtonDeleteOneFootprintFilter, 0 , wxGROW|wxALL, 5);
  228. m_ButtonDeleteAllFootprintFilter = new wxButton(m_PanelFootprintFilter, ID_DELETE_ALL_FOOTPRINT_FILTER,
  229. _("Delete All"));
  230. m_ButtonDeleteAllFootprintFilter->SetForegroundColour(*wxRED);
  231. RightBoxSizer->Add(m_ButtonDeleteAllFootprintFilter, 0 , wxGROW|wxALL, 5);
  232. /* Read the Footprint Filter list */
  233. if ( CurrentLibEntry )
  234. {
  235. for ( unsigned ii = 0; ii < CurrentLibEntry->m_FootprintList.GetCount(); ii ++)
  236. m_FootprintFilterListBox->Append(CurrentLibEntry->m_FootprintList[ii]);
  237. }
  238. if ( (CurrentLibEntry == NULL) || (CurrentLibEntry->m_FootprintList.GetCount() == 0) )
  239. {
  240. m_ButtonDeleteAllFootprintFilter->Enable(FALSE);
  241. m_ButtonDeleteOneFootprintFilter->Enable(FALSE);
  242. }
  243. }
  244. /*****************************************************/
  245. void WinEDA_PartPropertiesFrame::BuildPanelDoc(void)
  246. /*****************************************************/
  247. /* create the panel for component doc editing
  248. */
  249. {
  250. wxString msg_text;
  251. if ( m_AliasLocation >= 0 )
  252. msg_text = CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_DOC];
  253. else
  254. {
  255. if (CurrentLibEntry && CurrentLibEntry->m_Doc)
  256. msg_text = CurrentLibEntry->m_Doc;
  257. }
  258. m_Doc->SetValue( msg_text );
  259. msg_text.Empty();
  260. if ( m_AliasLocation >= 0 )
  261. msg_text = CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_KEYWORD];
  262. else
  263. {
  264. if (CurrentLibEntry ) msg_text = CurrentLibEntry->m_KeyWord;
  265. }
  266. m_Keywords->SetValue(msg_text);
  267. msg_text.Empty();
  268. if ( m_AliasLocation >= 0 )
  269. msg_text = CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_DOC_FILENAME];
  270. else
  271. {
  272. if (CurrentLibEntry) msg_text = CurrentLibEntry->m_DocFile;
  273. }
  274. m_Docfile->SetValue( msg_text );
  275. if ( m_AliasLocation < 0 ) m_ButtonCopyDoc->Enable(FALSE);
  276. }
  277. /*****************************************************/
  278. void WinEDA_PartPropertiesFrame::BuildPanelBasic(void)
  279. /*****************************************************/
  280. /* create the basic panel for component properties editing
  281. */
  282. {
  283. m_PanelBasic->SetFont(*g_DialogFont);
  284. AsConvertButt = new wxCheckBox(m_PanelBasic,-1, _("As Convert"));
  285. if ( g_AsDeMorgan ) AsConvertButt->SetValue(TRUE);
  286. m_OptionsBoxSizer->Add(AsConvertButt, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  287. ShowPinNumButt = new wxCheckBox(m_PanelBasic,-1, _("Show Pin Num"));
  288. if ( CurrentLibEntry )
  289. {
  290. if ( CurrentLibEntry->m_DrawPinNum ) ShowPinNumButt->SetValue(TRUE);
  291. }
  292. else ShowPinNumButt->SetValue(TRUE);
  293. m_OptionsBoxSizer->Add(ShowPinNumButt, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  294. ShowPinNameButt = new wxCheckBox(m_PanelBasic,-1, _("Show Pin Name"));
  295. if ( CurrentLibEntry )
  296. {
  297. if( CurrentLibEntry->m_DrawPinName ) ShowPinNameButt->SetValue(TRUE);
  298. }
  299. else ShowPinNameButt->SetValue(TRUE);
  300. m_OptionsBoxSizer->Add(ShowPinNameButt, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  301. m_PinsNameInsideButt = new wxCheckBox(m_PanelBasic,-1, _("Pin Name Inside"));
  302. if ( CurrentLibEntry )
  303. {
  304. if ( CurrentLibEntry->m_TextInside ) m_PinsNameInsideButt->SetValue(TRUE);
  305. }
  306. else m_PinsNameInsideButt->SetValue(TRUE);
  307. m_OptionsBoxSizer->Add(m_PinsNameInsideButt, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  308. int number, number_of_units;
  309. if ( CurrentLibEntry ) number_of_units = CurrentLibEntry->m_UnitCount;
  310. else number_of_units = 1;
  311. SelNumberOfUnits->SetValue(number_of_units);
  312. if ( CurrentLibEntry && CurrentLibEntry->m_TextInside)
  313. number = CurrentLibEntry->m_TextInside;
  314. else number = 40;
  315. m_SetSkew->SetValue( number );
  316. if ( CurrentLibEntry )
  317. {
  318. if( CurrentLibEntry->m_Options == ENTRY_POWER )
  319. m_OptionPower->SetValue(TRUE);
  320. }
  321. if ( CurrentLibEntry )
  322. {
  323. if( CurrentLibEntry->m_UnitSelectionLocked )
  324. m_OptionPartsLocked->SetValue(TRUE);
  325. }
  326. }
  327. /*********************************************************/
  328. void WinEDA_PartPropertiesFrame::BuildPanelEditField(void)
  329. /**********************************************************/
  330. /* Create and build the panel managing the fields (REF, VALUE ...)
  331. of the component
  332. */
  333. {
  334. wxString Hjustify_list[] =
  335. { _("Left justify"),_("Center"),_("Right justify")};
  336. wxString Vjustify_list[] =
  337. { _("Bottom justify"),_("Center"),_("Top justify")};
  338. int FieldId = m_CurrentFieldId;
  339. m_PanelField = new wxPanel(m_NoteBook, ID_PANEL_FIELD);
  340. m_PanelField->SetFont(*g_DialogFont);
  341. m_NoteBook->AddPage(m_PanelField, _("Fields"), FALSE);
  342. wxBoxSizer * PanelFieldBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  343. m_PanelField->SetSizer(PanelFieldBoxSizer);
  344. wxBoxSizer * LeftBoxSizer = new wxBoxSizer(wxVERTICAL);
  345. PanelFieldBoxSizer->Add(LeftBoxSizer, 0 , wxGROW|wxALL, 5);
  346. wxBoxSizer * MiddleBoxSizer = new wxBoxSizer(wxVERTICAL);
  347. PanelFieldBoxSizer->Add(MiddleBoxSizer, 0 , wxGROW|wxALL, 5);
  348. m_ShowFieldTextCtrl = new wxCheckBox(m_PanelField,-1,
  349. _("Show Text") );
  350. LeftBoxSizer->Add(m_ShowFieldTextCtrl, 0 , wxGROW|wxALL, 5);
  351. m_VorientFieldTextCtrl = new wxCheckBox(m_PanelField,-1,
  352. _("Vertical"));
  353. LeftBoxSizer->Add(m_VorientFieldTextCtrl, 0 , wxGROW|wxALL, 5);
  354. // Create the box for field name display or edition
  355. m_FieldNameCtrl = new WinEDA_EnterText( m_PanelField,
  356. _("Field Name:"), m_FieldName[FieldId],
  357. LeftBoxSizer, wxSize( 200, -1) );
  358. if ( FieldId < FIELD1 ) m_FieldNameCtrl->Enable(FALSE );
  359. else m_FieldNameCtrl->Enable( TRUE );
  360. // Create the box for text editing (text, size)
  361. m_FieldTextCtrl = new WinEDA_GraphicTextCtrl( m_PanelField,
  362. _("Value:"),
  363. m_FieldText[FieldId], m_FieldSize[FieldId],
  364. g_UnitMetric, LeftBoxSizer, 200);
  365. // Create the box for text editing (position)
  366. m_FieldPositionCtrl = new WinEDA_PositionCtrl( m_PanelField,
  367. _("Pos"), m_FieldPosition[FieldId],
  368. g_UnitMetric , LeftBoxSizer);
  369. m_FieldHJustifyCtrl = new wxRadioBox(m_PanelField,-1,
  370. _("Hor Justify"), wxDefaultPosition, wxDefaultSize,
  371. 3,Hjustify_list, 1 , wxRA_SPECIFY_COLS);
  372. m_FieldHJustifyCtrl->SetSelection(1);
  373. MiddleBoxSizer->Add(m_FieldHJustifyCtrl, 0 , wxGROW|wxALL, 5);
  374. m_FieldVJustifyCtrl = new wxRadioBox(m_PanelField,-1,
  375. _("Vert Justify"), wxDefaultPosition, wxDefaultSize,
  376. 3,Vjustify_list, 1 , wxRA_SPECIFY_COLS);
  377. m_FieldVJustifyCtrl->SetSelection(1);
  378. MiddleBoxSizer->Add(m_FieldVJustifyCtrl, 0 , wxGROW|wxALL, 5);
  379. // Create the field list
  380. wxString fieldnamelist[NUMBER_OF_FIELDS];
  381. for ( int ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
  382. {
  383. if ( m_FieldName[ii].IsEmpty() )
  384. fieldnamelist[ii] = ReturnDefaultFieldName(ii);
  385. else fieldnamelist[ii] = m_FieldName[ii];
  386. }
  387. m_FieldSelection = new wxRadioBox(m_PanelField, ID_ON_SELECT_FIELD,
  388. _("Field to edit"), wxDefaultPosition, wxDefaultSize,
  389. NUMBER_OF_FIELDS, fieldnamelist, 2 , wxRA_SPECIFY_COLS);
  390. PanelFieldBoxSizer->Add(m_FieldSelection, 0 , wxGROW|wxALL, 5);
  391. CopyDataToPanelField();
  392. }
  393. /****************************************************************/
  394. void WinEDA_PartPropertiesFrame::CopyDataToPanelField(void)
  395. /****************************************************************/
  396. /* Set the values displayed on the panel field according to
  397. the current field number
  398. */
  399. {
  400. int FieldId = m_CurrentFieldId;
  401. for ( int ii = FIELD1; ii < NUMBER_OF_FIELDS; ii++ )
  402. {
  403. if ( ! m_FieldName[ii].IsEmpty() )
  404. m_FieldSelection->SetString(ii, m_FieldName[ii]);
  405. else m_FieldSelection->SetString(ii, ReturnDefaultFieldName(ii));
  406. }
  407. if ( m_FieldFlags[FieldId] )
  408. m_ShowFieldTextCtrl->SetValue(TRUE);
  409. else m_ShowFieldTextCtrl->SetValue(FALSE);
  410. if ( m_FieldOrient[FieldId] ) m_VorientFieldTextCtrl->SetValue(TRUE);
  411. else m_VorientFieldTextCtrl->SetValue(FALSE);
  412. m_FieldHJustifyCtrl->SetSelection(m_FieldHJustify[FieldId]);
  413. m_FieldVJustifyCtrl->SetSelection(m_FieldVJustify[FieldId]);
  414. m_FieldPositionCtrl->SetValue(m_FieldPosition[FieldId].x, m_FieldPosition[FieldId].y );
  415. m_FieldNameCtrl->SetValue(m_FieldName[FieldId]);
  416. if ( FieldId < FIELD1 ) m_FieldNameCtrl->Enable(FALSE );
  417. else m_FieldNameCtrl->Enable( TRUE );
  418. m_FieldTextCtrl->SetValue(m_FieldText[FieldId]); // display new text field
  419. m_FieldTextCtrl->SetValue(m_FieldSize[FieldId]); // display new size field
  420. }
  421. /****************************************************************/
  422. void WinEDA_PartPropertiesFrame::CopyPanelFieldToData(void)
  423. /****************************************************************/
  424. /* Copy the values displayed on the panel field to the buffers according to
  425. the current field number
  426. */
  427. {
  428. int id = m_CurrentFieldId;
  429. m_FieldFlags[id] = m_ShowFieldTextCtrl->GetValue();
  430. m_FieldOrient[id] = m_VorientFieldTextCtrl->GetValue();
  431. m_FieldHJustify[id] = m_FieldHJustifyCtrl->GetSelection();
  432. m_FieldVJustify[id] = m_FieldVJustifyCtrl->GetSelection();
  433. m_FieldText[id] = m_FieldTextCtrl->GetText();
  434. m_FieldName[id] = m_FieldNameCtrl->GetValue();
  435. m_FieldPosition[id] = m_FieldPositionCtrl->GetValue();
  436. m_FieldSize[id] = m_FieldTextCtrl->GetTextSize();
  437. }
  438. /********************************************************************/
  439. void WinEDA_PartPropertiesFrame::SelectNewField(wxCommandEvent& event)
  440. /********************************************************************/
  441. /* called when changing the current field selected
  442. Save the current field settings in buffer and display the new one
  443. */
  444. {
  445. CopyPanelFieldToData();
  446. m_CurrentFieldId = m_FieldSelection->GetSelection();
  447. CopyDataToPanelField();
  448. }
  449. /**************************************************************************/
  450. void WinEDA_PartPropertiesFrame::PartPropertiesAccept(wxCommandEvent& event)
  451. /**************************************************************************/
  452. /* Updaye the current component parameters
  453. */
  454. {
  455. int ii, jj;
  456. if( CurrentLibEntry == NULL )
  457. {
  458. Close(); return;
  459. }
  460. m_Parent->m_CurrentScreen->SetModify();
  461. m_Parent->SaveCopyInUndoList(CurrentLibEntry);
  462. CopyPanelFieldToData();
  463. /* A new name could be entered in VALUE field.
  464. Must not be an existing alias name in alias list box */
  465. jj = m_PartAliasList->GetCount();
  466. wxString newvalue = m_FieldText[VALUE];
  467. for ( ii = 0; ii < jj; ii++ )
  468. {
  469. if( newvalue.CmpNoCase(m_PartAliasList->GetString(ii).GetData()) == 0 )
  470. {
  471. wxString msg;
  472. msg.Printf( wxT("Alias %s exists!"), newvalue.GetData());
  473. DisplayError(this, msg);
  474. return;
  475. }
  476. }
  477. /* Update the doc, keyword and doc filename strings */
  478. if ( m_AliasLocation < 0 )
  479. {
  480. CurrentLibEntry->m_Doc = m_Doc->GetValue();
  481. CurrentLibEntry->m_KeyWord = m_Keywords->GetValue();
  482. CurrentLibEntry->m_DocFile = m_Docfile->GetValue();
  483. }
  484. else
  485. {
  486. CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_DOC] = m_Doc->GetValue();
  487. CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_KEYWORD] = m_Keywords->GetValue();
  488. CurrentLibEntry->m_AliasList[m_AliasLocation+ALIAS_DOC_FILENAME] = m_Docfile->GetValue();
  489. }
  490. /* Update the alias list */
  491. /* 1 - Add names: test for a not existing name in old alias list: */
  492. jj = m_PartAliasList->GetCount();
  493. for ( ii = 0; ii < jj; ii++ )
  494. {
  495. if ( LocateAlias( CurrentLibEntry->m_AliasList, m_PartAliasList->GetString(ii)) < 0 )
  496. { // new alias must be created
  497. CurrentLibEntry->m_AliasList.Add(m_PartAliasList->GetString(ii));
  498. CurrentLibEntry->m_AliasList.Add(wxEmptyString); // Add a void doc string
  499. CurrentLibEntry->m_AliasList.Add(wxEmptyString); // Add a void keyword list string
  500. CurrentLibEntry->m_AliasList.Add(wxEmptyString); // Add a void doc filename string
  501. }
  502. }
  503. /* 2 - Remove delete names: test for an non existing name in new alias list: */
  504. int kk, kkmax = CurrentLibEntry->m_AliasList.GetCount();
  505. for ( kk = 0; kk < kkmax; )
  506. {
  507. jj = m_PartAliasList->GetCount();
  508. wxString aliasname = CurrentLibEntry->m_AliasList[kk];
  509. for ( ii = 0; ii < jj; ii++ )
  510. {
  511. if( aliasname.CmpNoCase(m_PartAliasList->GetString(ii).GetData()) == 0 )
  512. {
  513. kk += ALIAS_NEXT; // Alias exist in new list. keep it and test next old name
  514. break;
  515. }
  516. }
  517. if ( ii == jj ) // Alias not found in new list, remove it (4 strings in kk position)
  518. {
  519. for( ii = 0; ii < ALIAS_NEXT; ii++ ) CurrentLibEntry->m_AliasList.RemoveAt(kk);
  520. kkmax = CurrentLibEntry->m_AliasList.GetCount();
  521. }
  522. }
  523. // Void fields for REFERENCE and VALUE are not allowed
  524. if ( m_FieldText[REFERENCE].IsEmpty() )
  525. {
  526. m_FieldText[REFERENCE] = CurrentLibEntry->m_Prefix.m_Text;
  527. }
  528. if ( m_FieldText[VALUE].IsEmpty() )
  529. {
  530. m_FieldText[VALUE] = CurrentLibEntry->m_Name.m_Text;
  531. }
  532. else
  533. {
  534. if ( CurrentLibEntry->m_Name.m_Text != m_FieldText[VALUE] )
  535. m_RecreateToolbar = TRUE;
  536. }
  537. CopyBufferToFieldData(& CurrentLibEntry->m_Prefix);
  538. CopyBufferToFieldData(& CurrentLibEntry->m_Name);
  539. for ( ii = FOOTPRINT; ii < NUMBER_OF_FIELDS; ii++ )
  540. {
  541. LibDrawField * Field = CurrentLibEntry->Fields;
  542. LibDrawField * NextField, * previousField = NULL;
  543. while ( Field )
  544. {
  545. NextField = (LibDrawField*)Field->Pnext;
  546. if( Field->m_FieldId == ii )
  547. {
  548. CopyBufferToFieldData(Field);
  549. // An old field exists; delete it if void
  550. if( Field->m_Text.IsEmpty() )
  551. {
  552. if ( ii < FIELD1 || Field->m_Name.IsEmpty() )
  553. {
  554. delete Field;
  555. if ( previousField ) previousField->Pnext = NextField;
  556. else CurrentLibEntry->Fields = NextField;
  557. }
  558. }
  559. break;
  560. }
  561. previousField = Field;
  562. Field = NextField;
  563. }
  564. if ( Field == NULL) // Do not exists: must be created if not void
  565. {
  566. bool create = FALSE;
  567. if ( ! m_FieldText[ii].IsEmpty() ) create = TRUE;
  568. if ( ! m_FieldName[ii].IsEmpty() && (m_FieldName[ii] != ReturnDefaultFieldName(ii)) )
  569. create = TRUE;
  570. if ( create )
  571. {
  572. Field = new LibDrawField(ii);
  573. CopyBufferToFieldData(Field);
  574. Field->Pnext = CurrentLibEntry->Fields;
  575. CurrentLibEntry->Fields = Field;
  576. }
  577. }
  578. }
  579. /* for a user field (FieldId >= FIELD1), if a field value is void,
  580. fill it with "~" because for a library componenta void field is not a very good idea
  581. (we do not see anything...) and in schematic this text is like a void text */
  582. {
  583. LibDrawField * Field = CurrentLibEntry->Fields;
  584. while ( Field )
  585. {
  586. if( Field->m_FieldId >= FIELD1 )
  587. if ( Field->m_Text.IsEmpty() ) Field->m_Text = wxT("~");
  588. Field = (LibDrawField*)Field->Pnext;
  589. }
  590. }
  591. ii = SelNumberOfUnits->GetValue();
  592. if ( ChangeNbUnitsPerPackage(ii) )
  593. m_RecreateToolbar = TRUE;
  594. if ( AsConvertButt->GetValue() )
  595. {
  596. if ( ! g_AsDeMorgan )
  597. {
  598. g_AsDeMorgan = 1;
  599. if ( SetUnsetConvert() ) m_RecreateToolbar = TRUE;
  600. }
  601. }
  602. else
  603. {
  604. if ( g_AsDeMorgan )
  605. {
  606. g_AsDeMorgan = 0;
  607. if ( SetUnsetConvert() ) m_RecreateToolbar = TRUE;
  608. }
  609. }
  610. CurrentLibEntry->m_DrawPinNum = ShowPinNumButt->GetValue() ? 1 : 0;
  611. CurrentLibEntry->m_DrawPinName = ShowPinNameButt->GetValue() ? 1 : 0;
  612. if ( m_PinsNameInsideButt->GetValue() == FALSE)
  613. CurrentLibEntry->m_TextInside = 0;
  614. else
  615. CurrentLibEntry->m_TextInside = m_SetSkew->GetValue();
  616. if ( m_OptionPower->GetValue() == TRUE)
  617. CurrentLibEntry->m_Options = ENTRY_POWER;
  618. else
  619. CurrentLibEntry->m_Options = ENTRY_NORMAL;
  620. /* Set the option "Units locked".
  621. Obviously, cannot be TRUE if there is only one part */
  622. CurrentLibEntry->m_UnitSelectionLocked = m_OptionPartsLocked->GetValue();
  623. if ( CurrentLibEntry->m_UnitCount <= 1 )
  624. CurrentLibEntry->m_UnitSelectionLocked = FALSE;
  625. if ( m_RecreateToolbar ) m_Parent->ReCreateHToolbar();
  626. m_Parent->DisplayLibInfos();
  627. /* Update the footprint filter list */
  628. CurrentLibEntry->m_FootprintList.Clear();
  629. jj = m_FootprintFilterListBox->GetCount();
  630. for ( ii = 0; ii < jj; ii ++)
  631. CurrentLibEntry->m_FootprintList.Add(m_FootprintFilterListBox->GetString(ii));
  632. EndModal(1);
  633. }
  634. /*******************************************************************************/
  635. void WinEDA_PartPropertiesFrame::CopyDocToAlias(wxCommandEvent& WXUNUSED(event))
  636. /******************************************************************************/
  637. {
  638. if( CurrentLibEntry == NULL ) return;
  639. if ( CurrentAliasName.IsEmpty() ) return;
  640. m_Doc->SetValue(CurrentLibEntry->m_Doc);
  641. m_Docfile->SetValue(CurrentLibEntry->m_DocFile);
  642. m_Keywords->SetValue(CurrentLibEntry->m_KeyWord);
  643. }
  644. /**********************************************************/
  645. void WinEDA_PartPropertiesFrame::DeleteAllAliasOfPart(
  646. wxCommandEvent& WXUNUSED(event))
  647. /**********************************************************/
  648. {
  649. CurrentAliasName.Empty();
  650. if( CurrentLibEntry )
  651. {
  652. if( IsOK(this, _("Ok to Delete Alias LIST") ) )
  653. {
  654. m_PartAliasList->Clear();
  655. m_RecreateToolbar = TRUE;
  656. m_ButtonDeleteAllAlias->Enable(FALSE);
  657. m_ButtonDeleteOneAlias->Enable(FALSE);
  658. }
  659. }
  660. }
  661. /*******************************************************************************/
  662. void WinEDA_PartPropertiesFrame::AddAliasOfPart( wxCommandEvent& WXUNUSED(event))
  663. /*******************************************************************************/
  664. /* Add a new name to the alias list box
  665. New name cannot be the root name, and must not exists
  666. */
  667. {
  668. wxString Line;
  669. wxString aliasname;
  670. if(CurrentLibEntry == NULL) return;
  671. if( Get_Message(_("New alias:"),Line, this) != 0 ) return;
  672. Line.Replace( wxT(" "), wxT("_") );
  673. aliasname = Line;
  674. if ( CurrentLibEntry->m_Name.m_Text.CmpNoCase(Line) == 0 )
  675. {
  676. DisplayError(this, _("This is the Root Part"), 10); return;
  677. }
  678. /* test for an existing name: */
  679. int ii, jj = m_PartAliasList->GetCount();
  680. for ( ii = 0; ii < jj; ii++ )
  681. {
  682. if( aliasname.CmpNoCase(m_PartAliasList->GetString(ii)) == 0 )
  683. {
  684. DisplayError(this, _("Already in use"), 10);
  685. return;
  686. }
  687. }
  688. m_PartAliasList->Append(aliasname);
  689. if ( CurrentAliasName.IsEmpty() ) m_ButtonDeleteAllAlias->Enable(TRUE);
  690. m_ButtonDeleteOneAlias->Enable(TRUE);
  691. m_RecreateToolbar = TRUE;
  692. }
  693. /********************************************************/
  694. void WinEDA_PartPropertiesFrame::DeleteAliasOfPart(
  695. wxCommandEvent& WXUNUSED(event))
  696. /********************************************************/
  697. {
  698. wxString aliasname = m_PartAliasList->GetStringSelection();
  699. if ( aliasname.IsEmpty() ) return;
  700. if ( aliasname == CurrentAliasName )
  701. {
  702. wxString msg = CurrentAliasName + _(" is Current Selected Alias!");
  703. DisplayError(this, msg );
  704. return;
  705. }
  706. int ii = m_PartAliasList->GetSelection();
  707. m_PartAliasList->Delete(ii);
  708. if ( ! CurrentLibEntry || (CurrentLibEntry->m_AliasList.GetCount() == 0) )
  709. {
  710. m_ButtonDeleteAllAlias->Enable(FALSE);
  711. m_ButtonDeleteOneAlias->Enable(FALSE);
  712. }
  713. m_RecreateToolbar = TRUE;
  714. }
  715. /********************************************************************/
  716. bool WinEDA_PartPropertiesFrame::ChangeNbUnitsPerPackage(int MaxUnit)
  717. /********************************************************************/
  718. /* Routine de modification du nombre d'unites par package pour le
  719. composant courant;
  720. */
  721. {
  722. int OldNumUnits, ii, FlagDel = -1;
  723. LibEDA_BaseStruct* DrawItem, * NextDrawItem;
  724. if( CurrentLibEntry == NULL ) return FALSE;
  725. /* Si pas de changement: termine */
  726. if ( CurrentLibEntry->m_UnitCount == MaxUnit ) return FALSE;
  727. OldNumUnits = CurrentLibEntry->m_UnitCount;
  728. if ( OldNumUnits < 1 ) OldNumUnits = 1;
  729. CurrentLibEntry->m_UnitCount = MaxUnit;
  730. /* Traitement des unites enlevees ou rajoutees */
  731. if(OldNumUnits > CurrentLibEntry->m_UnitCount )
  732. {
  733. DrawItem = CurrentLibEntry->m_Drawings;
  734. for ( ; DrawItem != NULL; DrawItem = NextDrawItem)
  735. {
  736. NextDrawItem = DrawItem->Next();
  737. if( DrawItem->m_Unit > MaxUnit ) /* Item a effacer */
  738. {
  739. if( FlagDel < 0 )
  740. {
  741. if( IsOK(this, _("Delete units") ) )
  742. {
  743. /* Si part selectee n'existe plus: selection 1ere unit */
  744. if( CurrentUnit > MaxUnit ) CurrentUnit = 1;
  745. FlagDel = 1;
  746. }
  747. else
  748. {
  749. FlagDel = 0;
  750. MaxUnit = OldNumUnits;
  751. CurrentLibEntry->m_UnitCount = MaxUnit;
  752. return FALSE;
  753. }
  754. }
  755. DeleteOneLibraryDrawStruct(m_Parent->DrawPanel, NULL, CurrentLibEntry,
  756. DrawItem, 0);
  757. }
  758. }
  759. return TRUE;
  760. }
  761. if(OldNumUnits < CurrentLibEntry->m_UnitCount )
  762. {
  763. DrawItem = CurrentLibEntry->m_Drawings;
  764. for ( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
  765. {
  766. /* Duplication des items pour autres elements */
  767. if( DrawItem->m_Unit == 1 )
  768. {
  769. for ( ii = OldNumUnits +1; ii <= MaxUnit; ii ++ )
  770. {
  771. NextDrawItem = CopyDrawEntryStruct(this, DrawItem);
  772. NextDrawItem->Pnext = CurrentLibEntry->m_Drawings;
  773. CurrentLibEntry->m_Drawings = NextDrawItem;
  774. NextDrawItem->m_Unit = ii;
  775. }
  776. }
  777. }
  778. }
  779. return TRUE;
  780. }
  781. /*****************************************************/
  782. bool WinEDA_PartPropertiesFrame::SetUnsetConvert(void)
  783. /*****************************************************/
  784. /* cr�e ou efface (selon option AsConvert) les �l�ments
  785. de la reprsentation convertie d'un composant
  786. */
  787. {
  788. int FlagDel = 0;
  789. LibEDA_BaseStruct* DrawItem = NULL, * NextDrawItem;
  790. if( g_AsDeMorgan ) /* Representation convertie a creer */
  791. {
  792. /* Traitement des elements a ajouter ( pins seulement ) */
  793. if( CurrentLibEntry ) DrawItem = CurrentLibEntry->m_Drawings;
  794. for ( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
  795. {
  796. /* Duplication des items pour autres elements */
  797. if( DrawItem->m_StructType != COMPONENT_PIN_DRAW_TYPE ) continue;
  798. if( DrawItem->m_Convert == 1 )
  799. {
  800. if( FlagDel == 0 )
  801. {
  802. if( IsOK(this, _("Create pins for Convert items")) )
  803. FlagDel = 1;
  804. else
  805. {
  806. if( IsOK(this, _("Part as \"De Morgan\" anymore")) )
  807. return TRUE;
  808. g_AsDeMorgan = 0; return FALSE;
  809. }
  810. }
  811. NextDrawItem = CopyDrawEntryStruct(this, DrawItem);
  812. NextDrawItem->Pnext = CurrentLibEntry->m_Drawings;
  813. CurrentLibEntry->m_Drawings = NextDrawItem;
  814. NextDrawItem->m_Convert = 2;
  815. }
  816. }
  817. }
  818. else /* Representation convertie a supprimer */
  819. {
  820. /* Traitement des elements � supprimer */
  821. if( CurrentLibEntry ) DrawItem = CurrentLibEntry->m_Drawings;
  822. for ( ; DrawItem != NULL; DrawItem = NextDrawItem)
  823. {
  824. NextDrawItem = DrawItem->Next();
  825. if( DrawItem->m_Convert > 1 ) /* Item a effacer */
  826. {
  827. if( FlagDel == 0 )
  828. {
  829. if( IsOK(this, _("Delete Convert items") ) )
  830. {
  831. CurrentConvert = 1;
  832. FlagDel = 1;
  833. }
  834. else
  835. {
  836. g_AsDeMorgan = 1;
  837. return FALSE;
  838. }
  839. }
  840. m_Parent->GetScreen()->SetModify();
  841. DeleteOneLibraryDrawStruct(m_Parent->DrawPanel, NULL, CurrentLibEntry, DrawItem, 0);
  842. }
  843. }
  844. }
  845. return TRUE;
  846. }
  847. /****************************************************************************/
  848. void WinEDA_PartPropertiesFrame::BrowseAndSelectDocFile(wxCommandEvent& event)
  849. /****************************************************************************/
  850. {
  851. wxString FullFileName, mask;
  852. wxString docpath(g_RealLibDirBuffer), filename;
  853. docpath += wxT("doc");
  854. docpath += STRING_DIR_SEP;
  855. mask = wxT("*");
  856. FullFileName = EDA_FileSelector(_("Doc Files"),
  857. docpath, /* Chemin par defaut */
  858. wxEmptyString, /* nom fichier par defaut */
  859. wxEmptyString, /* extension par defaut */
  860. mask, /* Masque d'affichage */
  861. this,
  862. wxFD_OPEN,
  863. TRUE
  864. );
  865. if ( FullFileName.IsEmpty() ) return;
  866. // Suppression du chemin par defaut pour le fichier de doc:
  867. filename = MakeReducedFileName(FullFileName,docpath, wxEmptyString);
  868. m_Docfile->SetValue(filename);
  869. }
  870. /**********************************************************/
  871. void WinEDA_PartPropertiesFrame::DeleteAllFootprintFilter(
  872. wxCommandEvent& WXUNUSED(event))
  873. /**********************************************************/
  874. {
  875. if( IsOK(this, _("Ok to Delete FootprintFilter LIST") ) )
  876. {
  877. m_FootprintFilterListBox->Clear();
  878. m_ButtonDeleteAllFootprintFilter->Enable(FALSE);
  879. m_ButtonDeleteOneFootprintFilter->Enable(FALSE);
  880. }
  881. }
  882. /*******************************************************************************/
  883. void WinEDA_PartPropertiesFrame::AddFootprintFilter( wxCommandEvent& WXUNUSED(event))
  884. /*******************************************************************************/
  885. /* Add a new name to the alias list box
  886. New name cannot be the root name, and must not exists
  887. */
  888. {
  889. wxString Line;
  890. if(CurrentLibEntry == NULL) return;
  891. if( Get_Message(_("New FootprintFilter:"),Line, this) != 0 ) return;
  892. Line.Replace( wxT(" "), wxT("_") );
  893. /* test for an existing name: */
  894. int ii, jj = m_FootprintFilterListBox->GetCount();
  895. for ( ii = 0; ii < jj; ii++ )
  896. {
  897. if( Line.CmpNoCase(m_FootprintFilterListBox->GetString(ii)) == 0 )
  898. {
  899. DisplayError(this, _("Already in use"), 10);
  900. return;
  901. }
  902. }
  903. m_FootprintFilterListBox->Append(Line);
  904. m_ButtonDeleteAllFootprintFilter->Enable(TRUE);
  905. m_ButtonDeleteOneFootprintFilter->Enable(TRUE);
  906. }
  907. /********************************************************/
  908. void WinEDA_PartPropertiesFrame::DeleteOneFootprintFilter(
  909. wxCommandEvent& WXUNUSED(event))
  910. /********************************************************/
  911. {
  912. int ii = m_FootprintFilterListBox->GetSelection();
  913. m_FootprintFilterListBox->Delete(ii);
  914. if ( ! CurrentLibEntry || (m_FootprintFilterListBox->GetCount() == 0) )
  915. {
  916. m_ButtonDeleteAllFootprintFilter->Enable(FALSE);
  917. m_ButtonDeleteOneFootprintFilter->Enable(FALSE);
  918. }
  919. }