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.

458 lines
14 KiB

16 years ago
16 years ago
  1. /**************************************************************/
  2. /* librairy editor: edition of component general properties */
  3. /**************************************************************/
  4. #include "fctsys.h"
  5. #include "appl_wxstruct.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "gestfich.h"
  10. #include "program.h"
  11. #include "general.h"
  12. #include "protos.h"
  13. #include "libeditframe.h"
  14. #include "class_library.h"
  15. #include "eeschema_id.h"
  16. /* Dialog box to edit a libentry (a component in library) properties */
  17. /* Creates a NoteBook dialog
  18. * Edition:
  19. * Doc and keys words
  20. * Parts per package
  21. * General properties
  22. * Fields are NOT edited here. There is a specific dialog box to do that
  23. */
  24. #include "dialog_edit_component_in_lib.h"
  25. void WinEDA_LibeditFrame::OnEditComponentProperties( wxCommandEvent& event )
  26. {
  27. bool partLocked = GetComponent()->m_UnitSelectionLocked;
  28. EditComponentProperties();
  29. if( partLocked != GetComponent()->m_UnitSelectionLocked )
  30. { // g_EditPinByPinIsOn is set to the better value,
  31. // if m_UnitSelectionLocked has changed
  32. g_EditPinByPinIsOn = GetComponent()->m_UnitSelectionLocked ? true : false;
  33. m_HToolBar->ToggleTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, g_EditPinByPinIsOn );
  34. }
  35. m_HToolBar->Refresh();
  36. DrawPanel->Refresh();
  37. }
  38. void WinEDA_LibeditFrame::EditComponentProperties()
  39. {
  40. DIALOG_EDIT_COMPONENT_IN_LIBRARY dlg( this );
  41. if( dlg.ShowModal() == wxID_CANCEL )
  42. return;
  43. UpdateAliasSelectList();
  44. UpdatePartSelectList();
  45. DisplayLibInfos();
  46. DisplayCmpDoc();
  47. OnModify( );
  48. }
  49. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
  50. {
  51. /* Update the doc, keyword and doc filename strings */
  52. size_t i;
  53. int index;
  54. LIB_COMPONENT* component = m_Parent->GetComponent();
  55. if( component == NULL )
  56. {
  57. EndModal( wxID_CANCEL );
  58. return;
  59. }
  60. m_Parent->SaveCopyInUndoList( component );
  61. wxString aliasname = m_Parent->GetAliasName();
  62. if( aliasname.IsEmpty() ) // The root component is selected
  63. {
  64. component->SetDescription( m_DocCtrl->GetValue() );
  65. component->SetKeyWords( m_KeywordsCtrl->GetValue() );
  66. component->SetDocFileName( m_DocfileCtrl->GetValue() );
  67. }
  68. else // An alias is selected: update keyworks (if thias alias is new, it will be added in aliacd data list)
  69. {
  70. component->SetAliasDataDoc(aliasname, m_DocCtrl->GetValue() );
  71. component->SetAliasDataKeywords(aliasname, m_KeywordsCtrl->GetValue() );
  72. component->SetAliasDataDocFileName(aliasname, m_DocfileCtrl->GetValue() );
  73. }
  74. if( m_PartAliasListCtrl->GetStrings() != component->m_AliasList )
  75. {
  76. wxArrayString aliases = m_PartAliasListCtrl->GetStrings();
  77. /* Add names not existing in the current component alias list. */
  78. for( i = 0; i < aliases.GetCount(); i++ )
  79. {
  80. index = component->m_AliasList.Index( aliases[ i ], false );
  81. if( index != wxNOT_FOUND )
  82. continue;
  83. component->m_AliasList.Add( aliases[ i ] );
  84. }
  85. /* Remove names in the current component that are not in the new alias list. */
  86. for( i = 0; i < component->m_AliasList.GetCount(); i++ )
  87. {
  88. index = aliases.Index( component->m_AliasList[ i ], false );
  89. if( index == wxNOT_FOUND )
  90. continue;
  91. component->m_AliasList.RemoveAt( i );
  92. i--;
  93. }
  94. component->m_AliasList = aliases;
  95. }
  96. index = m_SelNumberOfUnits->GetValue();
  97. ChangeNbUnitsPerPackage( index );
  98. if( m_AsConvertButt->GetValue() )
  99. {
  100. if( !m_Parent->GetShowDeMorgan() )
  101. {
  102. m_Parent->SetShowDeMorgan( true );
  103. SetUnsetConvert();
  104. }
  105. }
  106. else
  107. {
  108. if( m_Parent->GetShowDeMorgan() )
  109. {
  110. m_Parent->SetShowDeMorgan( false );
  111. SetUnsetConvert();
  112. }
  113. }
  114. component->m_DrawPinNum = m_ShowPinNumButt->GetValue() ? 1 : 0;
  115. component->m_DrawPinName = m_ShowPinNameButt->GetValue() ? 1 : 0;
  116. if( m_PinsNameInsideButt->GetValue() == false )
  117. component->m_TextInside = 0; // pin text outside the body (name is on the pin)
  118. else
  119. {
  120. component->m_TextInside = m_SetSkew->GetValue();
  121. // Ensure component->m_TextInside != 0, because the meaning is "text outside".
  122. if( component->m_TextInside == 0 )
  123. component->m_TextInside = 20; // give a reasonnable value
  124. }
  125. if( m_OptionPower->GetValue() == true )
  126. component->SetPower();
  127. else
  128. component->SetNormal();
  129. /* Set the option "Units locked".
  130. * Obviously, cannot be true if there is only one part */
  131. component->m_UnitSelectionLocked = m_OptionPartsLocked->GetValue();
  132. if( component->GetPartCount() <= 1 )
  133. component->m_UnitSelectionLocked = false;
  134. /* Update the footprint filter list */
  135. component->m_FootprintList.Clear();
  136. component->m_FootprintList = m_FootprintFilterListBox->GetStrings();
  137. EndModal( wxID_OK );
  138. }
  139. /*******************************************************************************/
  140. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED (event) )
  141. /******************************************************************************/
  142. {
  143. LIB_COMPONENT* component = m_Parent->GetComponent();
  144. if( component == NULL || m_Parent->GetAliasName().IsEmpty() )
  145. return;
  146. m_DocCtrl->SetValue( component->GetDescription() );
  147. m_DocfileCtrl->SetValue( component->GetDocFileName() );
  148. m_KeywordsCtrl->SetValue( component->GetKeyWords() );
  149. }
  150. /**********************************************************/
  151. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllAliasOfPart(
  152. wxCommandEvent& WXUNUSED (event) )
  153. /**********************************************************/
  154. {
  155. if( m_PartAliasListCtrl->FindString( m_Parent->GetAliasName() )
  156. != wxNOT_FOUND )
  157. {
  158. wxString msg;
  159. msg.Printf( _( "Alias <%s> cannot be removed while it is being \
  160. edited!" ),
  161. GetChars( m_Parent->GetAliasName() ) );
  162. DisplayError( this, msg );
  163. return;
  164. }
  165. LIB_COMPONENT* component = m_Parent->GetComponent();
  166. m_Parent->GetAliasName().Empty();
  167. if( IsOK( this, _( "Remove all aliases from list?" ) ) )
  168. {
  169. m_PartAliasListCtrl->Clear();
  170. m_ButtonDeleteAllAlias->Enable( false );
  171. m_ButtonDeleteOneAlias->Enable( false );
  172. if( component )
  173. component->ClearAliasDataDoc();
  174. }
  175. }
  176. /*******************************************************************************/
  177. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED (event) )
  178. /*******************************************************************************/
  179. /* Add a new name to the alias list box
  180. * New name cannot be the root name, and must not exists
  181. */
  182. {
  183. wxString Line;
  184. wxString aliasname;
  185. LIB_COMPONENT* component = m_Parent->GetComponent();
  186. CMP_LIBRARY* library = m_Parent->GetLibrary();
  187. if( component == NULL )
  188. return;
  189. if( Get_Message( _( "New alias:" ),
  190. _( "Component Alias" ), Line, this ) != 0 )
  191. return;
  192. Line.Replace( wxT( " " ), wxT( "_" ) );
  193. aliasname = Line;
  194. if( m_PartAliasListCtrl->FindString( aliasname ) != wxNOT_FOUND
  195. || library->FindEntry( aliasname ) != NULL )
  196. {
  197. wxString msg;
  198. msg.Printf( _( "Alias or component name <%s> already exists in \
  199. library <%s>." ),
  200. GetChars( aliasname ),
  201. GetChars( library->GetName() ) );
  202. DisplayError( this, msg );
  203. return;
  204. }
  205. m_PartAliasListCtrl->Append( aliasname );
  206. if( m_Parent->GetAliasName().IsEmpty() )
  207. m_ButtonDeleteAllAlias->Enable( true );
  208. m_ButtonDeleteOneAlias->Enable( true );
  209. }
  210. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart(
  211. wxCommandEvent& WXUNUSED (event) )
  212. {
  213. wxString aliasname = m_PartAliasListCtrl->GetStringSelection();
  214. if( aliasname.IsEmpty() )
  215. return;
  216. if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 )
  217. {
  218. wxString msg;
  219. msg.Printf( _( "Alias <%s> cannot be removed while it is being \
  220. edited!" ),
  221. GetChars( aliasname ) );
  222. DisplayError( this, msg );
  223. return;
  224. }
  225. m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() );
  226. LIB_COMPONENT* component = m_Parent->GetComponent();
  227. if( component )
  228. component->RemoveAliasData(aliasname);
  229. if( m_PartAliasListCtrl->IsEmpty() )
  230. {
  231. m_ButtonDeleteAllAlias->Enable( false );
  232. m_ButtonDeleteOneAlias->Enable( false );
  233. }
  234. }
  235. /*
  236. * Change the number of parts per package.
  237. */
  238. bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
  239. {
  240. LIB_COMPONENT* component = m_Parent->GetComponent();
  241. if( component == NULL || component->GetPartCount() == MaxUnit
  242. || MaxUnit < 1 )
  243. return false;
  244. if( MaxUnit < component->GetPartCount()
  245. && !IsOK( this, _( "Delete extra parts from component?" ) ) )
  246. return false;
  247. component->SetPartCount( MaxUnit );
  248. return true;
  249. }
  250. /*
  251. * Set or clear the component alternate body style ( DeMorgan ).
  252. */
  253. bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
  254. {
  255. LIB_COMPONENT* component = m_Parent->GetComponent();
  256. if( component == NULL
  257. || ( m_Parent->GetShowDeMorgan() == component->HasConversion() ) )
  258. return false;
  259. if( m_Parent->GetShowDeMorgan() )
  260. {
  261. if( !IsOK( this, _( "Add new pins for alternate body style \
  262. ( DeMorgan ) to component?" ) ) )
  263. return false;
  264. }
  265. else if( component->HasConversion() )
  266. {
  267. if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from component?" ) ) )
  268. {
  269. m_Parent->SetShowDeMorgan( true );
  270. return false;
  271. }
  272. }
  273. component->SetConversion( m_Parent->GetShowDeMorgan() );
  274. m_Parent->OnModify( );
  275. return true;
  276. }
  277. /****************************************************************************/
  278. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& event )
  279. /****************************************************************************/
  280. {
  281. wxString FullFileName, mask;
  282. wxString docpath, filename;
  283. docpath = wxGetApp().ReturnLastVisitedLibraryPath(wxT( "doc" ));
  284. mask = wxT( "*" );
  285. FullFileName = EDA_FileSelector( _( "Doc Files" ),
  286. docpath, /* Chemin par defaut */
  287. wxEmptyString, /* nom fichier par defaut */
  288. wxEmptyString, /* extension par defaut */
  289. mask, /* Masque d'affichage */
  290. this,
  291. wxFD_OPEN,
  292. true
  293. );
  294. if( FullFileName.IsEmpty() )
  295. return;
  296. /* If the path is already in the library search paths
  297. * list, just add the library name to the list. Otherwise, add
  298. * the library name with the full or relative path.
  299. * the relative path, when possible is preferable,
  300. * because it preserve use of default libraries paths, when the path is a sub path of these default paths
  301. */
  302. wxFileName fn = FullFileName;
  303. wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
  304. filename = wxGetApp().ReturnFilenameWithRelativePathInLibPath(FullFileName);
  305. // Filenames are always stored in unix like mode, ie separator "\" is stored as "/"
  306. // to ensure files are identical under unices and windows
  307. #ifdef __WINDOWS__
  308. filename.Replace(wxT("\\"), wxT("/") );
  309. #endif
  310. m_DocfileCtrl->SetValue( filename );
  311. }
  312. /**********************************************************/
  313. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter(
  314. wxCommandEvent& WXUNUSED (event) )
  315. /**********************************************************/
  316. {
  317. if( IsOK( this, _( "Ok to Delete FootprintFilter LIST" ) ) )
  318. {
  319. m_FootprintFilterListBox->Clear();
  320. m_ButtonDeleteAllFootprintFilter->Enable( false );
  321. m_ButtonDeleteOneFootprintFilter->Enable( false );
  322. }
  323. }
  324. /*******************************************************************************/
  325. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNUSED (event) )
  326. /*******************************************************************************/
  327. /* Add a new name to the alias list box
  328. * New name cannot be the root name, and must not exists
  329. */
  330. {
  331. wxString Line;
  332. LIB_COMPONENT* component = m_Parent->GetComponent();
  333. if( component == NULL )
  334. return;
  335. if( Get_Message( _( "Add Footprint Filter" ), _( "Footprint Filter" ),
  336. Line, this ) != 0 )
  337. return;
  338. Line.Replace( wxT( " " ), wxT( "_" ) );
  339. /* test for an existing name: */
  340. int index = m_FootprintFilterListBox->FindString( Line );
  341. if( index != wxNOT_FOUND )
  342. {
  343. wxString msg;
  344. msg.Printf( _( "Foot print filter <%s> is already defined." ),
  345. GetChars( Line ) );
  346. DisplayError( this, msg );
  347. return;
  348. }
  349. m_FootprintFilterListBox->Append( Line );
  350. m_ButtonDeleteAllFootprintFilter->Enable( true );
  351. m_ButtonDeleteOneFootprintFilter->Enable( true );
  352. }
  353. /********************************************************/
  354. void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteOneFootprintFilter(
  355. wxCommandEvent& WXUNUSED (event) )
  356. /********************************************************/
  357. {
  358. LIB_COMPONENT* component = m_Parent->GetComponent();
  359. int ii = m_FootprintFilterListBox->GetSelection();
  360. m_FootprintFilterListBox->Delete( ii );
  361. if( !component || (m_FootprintFilterListBox->GetCount() == 0) )
  362. {
  363. m_ButtonDeleteAllFootprintFilter->Enable( false );
  364. m_ButtonDeleteOneFootprintFilter->Enable( false );
  365. }
  366. }