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.

142 lines
3.6 KiB

  1. /**************************/
  2. /* EESchema - selpart.cpp */
  3. /**************************/
  4. /* Routine de selection d'un composant en librairie
  5. */
  6. #include "fctsys.h"
  7. #include "gr_basic.h"
  8. #include "common.h"
  9. #include "program.h"
  10. #include "libcmp.h"
  11. #include "general.h"
  12. #include "protos.h"
  13. /* Routines locales */
  14. /* Variables locales */
  15. /***************************************************************/
  16. LibraryStruct * SelectLibraryFromList(WinEDA_DrawFrame * frame)
  17. /***************************************************************/
  18. /* Routine pour selectionner une librairie a partir d'une liste
  19. */
  20. {
  21. int ii, NumOfLibs = NumOfLibraries();
  22. LibraryStruct *Lib = NULL;
  23. static wxString OldLibName;
  24. WinEDAListBox * ListBox;
  25. wxString LibName;
  26. const wxChar ** ListNames;
  27. if (NumOfLibs == 0)
  28. {
  29. DisplayError(frame, _("No libraries are loaded"));
  30. return(NULL) ;
  31. }
  32. ListNames = GetLibNames();
  33. ListBox = new WinEDAListBox(frame,
  34. _("Select Lib"), ListNames, OldLibName, NULL,
  35. wxColour(150,255,255));
  36. ListBox->MoveMouseToOrigin();
  37. ii = ListBox->ShowModal(); ListBox->Destroy();
  38. if (ii >= 0) /* Recherche de la librairie */
  39. {
  40. Lib = FindLibrary(ListNames[ii]);
  41. }
  42. free (ListNames);
  43. return(Lib);
  44. }
  45. /******************************************************************************************/
  46. int DisplayComponentsNamesInLib( WinEDA_DrawFrame * frame,
  47. LibraryStruct *Library, wxString & Buffer, wxString & OldName)
  48. /******************************************************************************************/
  49. /* Routine de selection d'un composant en librairie, par affichage de la
  50. liste des composants de cette librairie
  51. Si Library == NULL, selection de librairie demandee
  52. sinon recherche uniquement dans library
  53. Retourne
  54. 1 si composant selectionne
  55. 0 si commande annulee
  56. */
  57. {
  58. int ii;
  59. wxString msg;
  60. EDA_LibComponentStruct *LibEntry;
  61. WinEDAListBox * ListBox;
  62. const wxChar ** ListNames;
  63. if(Library == NULL) Library = SelectLibraryFromList(frame);
  64. if(Library == NULL) return(0);
  65. PQCompFunc((PQCompFuncType) LibraryEntryCompare);
  66. LibEntry = (EDA_LibComponentStruct *) PQFirst(&Library->m_Entries, FALSE);
  67. ii = 0;
  68. while( LibEntry )
  69. {
  70. ii++;
  71. LibEntry = (EDA_LibComponentStruct *) PQNext(Library->m_Entries, LibEntry, NULL);
  72. }
  73. ListNames = (const wxChar**) MyZMalloc( (ii+1) * sizeof(wxChar*));
  74. msg.Printf( _("Select component (%d items)"), ii );
  75. ii = 0;
  76. LibEntry = (EDA_LibComponentStruct *) PQFirst(&Library->m_Entries, FALSE);
  77. while( LibEntry )
  78. {
  79. ListNames[ii++] = LibEntry->m_Name.m_Text.GetData();
  80. LibEntry = (EDA_LibComponentStruct *) PQNext(Library->m_Entries, LibEntry, NULL);
  81. }
  82. // Qsort(ListNames,StrNumICmp);
  83. ListBox = new WinEDAListBox(frame, msg,
  84. ListNames, OldName, DisplayCmpDoc,
  85. wxColour(255,255,200));
  86. ListBox->MoveMouseToOrigin();
  87. ii = ListBox->ShowModal(); ListBox->Destroy();
  88. if ( ii >= 0 ) Buffer = ListNames[ii];
  89. free (ListNames);
  90. if ( ii < 0 ) return 0;
  91. return 1;
  92. }
  93. /************************************************************/
  94. int GetNameOfPartToLoad(WinEDA_DrawFrame * frame,
  95. LibraryStruct *Library, wxString & BufName)
  96. /************************************************************/
  97. /*
  98. Routine de selection du nom d'un composant en librairie pour chargement,
  99. dans la librairie Library.
  100. Si Library == NULL, il y aura demande de selection d'une librairie
  101. Retourne
  102. 1 si composant selectionne
  103. 0 si commande annulee
  104. place le nom du composant a charger, selectionne a partir d'une liste dans
  105. BufName
  106. */
  107. {
  108. int ii;
  109. static wxString OldCmpName;
  110. ii = DisplayComponentsNamesInLib(frame, Library, BufName, OldCmpName);
  111. if( ii <= 0 ) return 0;
  112. OldCmpName = BufName;
  113. return( 1 );
  114. }