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.

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