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.

1096 lines
34 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
15 years ago
15 years ago
15 years ago
11 years ago
15 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file dialog_edit_component_in_schematic.cpp
  25. */
  26. #include <wx/tooltip.h>
  27. #include <wx/hyperlink.h>
  28. #include <fctsys.h>
  29. #include <pgm_base.h>
  30. #include <kiway.h>
  31. #include <gr_basic.h>
  32. #include <class_drawpanel.h>
  33. #include <confirm.h>
  34. #include <class_sch_screen.h>
  35. #include <schframe.h>
  36. #include <base_units.h>
  37. #include <general.h>
  38. #include <sch_base_frame.h>
  39. #include <class_library.h>
  40. #include <sch_component.h>
  41. #include <dialog_helpers.h>
  42. #include <sch_validators.h>
  43. #include <dialog_edit_component_in_schematic_fbp.h>
  44. /**
  45. * class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC
  46. * is hand coded and implements DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP which
  47. * is maintained by wxFormBuilder. Do not auto-generate this class or file,
  48. * it is hand coded.
  49. */
  50. class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP
  51. {
  52. public:
  53. /** Constructor */
  54. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow* aParent );
  55. /**
  56. * Function InitBuffers
  57. * sets up to edit the given component.
  58. * @param aComponent The component to edit.
  59. */
  60. void InitBuffers( SCH_COMPONENT* aComponent );
  61. private:
  62. friend class SCH_EDIT_FRAME;
  63. SCH_EDIT_FRAME* m_parent;
  64. SCH_COMPONENT* m_cmp;
  65. LIB_PART* m_part;
  66. bool m_skipCopyFromPanel;
  67. static int s_SelectedRow;
  68. /// a copy of the edited component's SCH_FIELDs
  69. SCH_FIELDS m_FieldsBuf;
  70. void setSelectedFieldNdx( int aFieldNdx );
  71. int getSelectedFieldNdx();
  72. /**
  73. * Function copySelectedFieldToPanel
  74. * sets the values displayed on the panel according to
  75. * the currently selected field row
  76. */
  77. void copySelectedFieldToPanel();
  78. /**
  79. * Function copyPanelToSelectedField
  80. * copies the values displayed on the panel fields to the currently
  81. * selected field
  82. * @return bool - true if all fields are OK, else false if the user has put
  83. * bad data into a field, and this value can be used to deny a row change.
  84. */
  85. bool copyPanelToSelectedField();
  86. void copyOptionsToPanel();
  87. void copyPanelToOptions();
  88. void setRowItem( int aFieldNdx, const SCH_FIELD& aField );
  89. // event handlers
  90. void OnCloseDialog( wxCloseEvent& event );
  91. void OnListItemDeselected( wxListEvent& event );
  92. void OnListItemSelected( wxListEvent& event );
  93. void OnCancelButtonClick( wxCommandEvent& event );
  94. void OnOKButtonClick( wxCommandEvent& event );
  95. void SetInitCmp( wxCommandEvent& event );
  96. void addFieldButtonHandler( wxCommandEvent& event );
  97. void deleteFieldButtonHandler( wxCommandEvent& event );
  98. void moveUpButtonHandler( wxCommandEvent& event );
  99. void showButtonHandler( wxCommandEvent& event );
  100. void OnTestChipName( wxCommandEvent& event );
  101. void OnSelectChipName( wxCommandEvent& event );
  102. SCH_FIELD* findField( const wxString& aFieldName );
  103. /**
  104. * Function updateDisplay
  105. * update the listbox showing fields, according to the fields texts
  106. * must be called after a text change in fields, if this change is not an edition
  107. */
  108. void updateDisplay( )
  109. {
  110. for( unsigned ii = FIELD1; ii<m_FieldsBuf.size(); ii++ )
  111. setRowItem( ii, m_FieldsBuf[ii] );
  112. }
  113. };
  114. int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
  115. void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent )
  116. {
  117. wxCHECK_RET( aComponent != NULL && aComponent->Type() == SCH_COMPONENT_T,
  118. wxT( "Invalid component object pointer. Bad Programmer!" ) );
  119. m_canvas->SetIgnoreMouseEvents( true );
  120. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC* dlg = new DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( this );
  121. dlg->InitBuffers( aComponent );
  122. // make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
  123. EnsureTextCtrlWidth( dlg->chipnameTextCtrl );
  124. // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
  125. // frame. Therefore this dialog as a modal frame parent, MUST be run under
  126. // quasimodal mode for the quasimodal frame support to work. So don't use
  127. // the QUASIMODAL macros here.
  128. int ret = dlg->ShowQuasiModal();
  129. if( m_autoplaceFields )
  130. aComponent->AutoAutoplaceFields( GetScreen() );
  131. m_canvas->SetIgnoreMouseEvents( false );
  132. m_canvas->MoveCursorToCrossHair();
  133. dlg->Destroy();
  134. if( ret == wxID_OK )
  135. GetCanvas()->Refresh();
  136. }
  137. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow* aParent ) :
  138. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( aParent )
  139. {
  140. m_parent = (SCH_EDIT_FRAME*) aParent;
  141. m_cmp = NULL;
  142. m_part = NULL;
  143. m_skipCopyFromPanel = false;
  144. wxListItem columnLabel;
  145. columnLabel.SetImage( -1 );
  146. columnLabel.SetText( _( "Name" ) );
  147. fieldListCtrl->InsertColumn( 0, columnLabel );
  148. columnLabel.SetText( _( "Value" ) );
  149. fieldListCtrl->InsertColumn( 1, columnLabel );
  150. m_staticTextUnitSize->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  151. m_staticTextUnitPosX->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  152. m_staticTextUnitPosY->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  153. wxToolTip::Enable( true );
  154. GetSizer()->SetSizeHints( this );
  155. Center();
  156. stdDialogButtonSizerOK->SetDefault();
  157. }
  158. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event )
  159. {
  160. if( !m_skipCopyFromPanel )
  161. {
  162. if( !copyPanelToSelectedField() )
  163. event.Skip(); // do not go to the next row
  164. }
  165. }
  166. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnTestChipName( wxCommandEvent& event )
  167. {
  168. wxString partname = chipnameTextCtrl->GetValue();
  169. LIB_PART* entry = Prj().SchLibs()->FindLibPart( partname );
  170. wxString msg;
  171. if( entry )
  172. {
  173. msg.Printf( _( "Component '%s' found in library '%s'" ),
  174. GetChars( partname ), GetChars( entry->GetLibraryName() ) );
  175. wxMessageBox( msg );
  176. return;
  177. }
  178. msg.Printf( _( "Component '%s' not found in any library" ), GetChars( partname ) );
  179. // Try to find components which have a name "near" the current chip name,
  180. // i.e. the same name when the comparison is case insensitive.
  181. // Could be helpful for old designs when lower cases and upper case were
  182. // equivalent.
  183. std::vector<LIB_ALIAS*> candidates;
  184. Prj().SchLibs()->FindLibraryNearEntries( candidates, partname );
  185. if( candidates.size() == 0 )
  186. {
  187. wxMessageBox( msg );
  188. return;
  189. }
  190. // Some candidates are found. Show them:
  191. msg << wxT("\n") << _( "However, some candidates are found:" );
  192. // add candidate names:
  193. for( unsigned ii = 0; ii < candidates.size(); ii++ )
  194. {
  195. msg << wxT("\n") <<
  196. wxString::Format( _( "'%s' found in library '%s'" ),
  197. GetChars( candidates[ii]->GetName() ),
  198. GetChars( candidates[ii]->GetLibraryName() ) );
  199. }
  200. wxMessageBox( msg );
  201. }
  202. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event )
  203. {
  204. wxArrayString dummy;
  205. int dummyunit = 1;
  206. wxString chipname = m_parent->SelectComponentFromLibrary( NULL, dummy, dummyunit,
  207. true, NULL, NULL );
  208. if( chipname.IsEmpty() )
  209. return;
  210. chipnameTextCtrl->SetValue( chipname );
  211. }
  212. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event )
  213. {
  214. DBG( printf( "OnListItemSelected()\n" ); )
  215. // remember the selected row, statically
  216. s_SelectedRow = event.GetIndex();
  217. copySelectedFieldToPanel();
  218. }
  219. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCloseDialog( wxCloseEvent& event )
  220. {
  221. // On wxWidgets 2.8, and on Linux, calling EndQuasiModal here is mandatory
  222. // Otherwise, the main event loop is never restored, and Eeschema does not
  223. // respond to any event, because the DIALOG_SHIM destructor is never called.
  224. // On wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
  225. // and calls EndQuasiModal.
  226. // therefore calling EndQuasiModal here is not always mandatory but it creates no issues
  227. EndQuasiModal( wxID_CANCEL );
  228. }
  229. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event )
  230. {
  231. EndQuasiModal( wxID_CANCEL );
  232. }
  233. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
  234. {
  235. wxString newname = chipnameTextCtrl->GetValue();
  236. // Save current flags which could be modified by next change settings
  237. STATUS_FLAGS flags = m_cmp->GetFlags();
  238. newname.Replace( wxT( " " ), wxT( "_" ) );
  239. if( newname.IsEmpty() )
  240. {
  241. DisplayError( NULL, _( "No Component Name!" ) );
  242. }
  243. else if( Cmp_KEEPCASE( newname, m_cmp->m_part_name ) )
  244. {
  245. PART_LIBS* libs = Prj().SchLibs();
  246. if( libs->FindLibraryEntry( newname ) == NULL )
  247. {
  248. wxString msg = wxString::Format( _(
  249. "Component '%s' not found!" ), GetChars( newname ) );
  250. DisplayError( this, msg );
  251. }
  252. else // Change component from lib!
  253. {
  254. m_cmp->SetPartName( newname, libs );
  255. }
  256. }
  257. // For components with multiple shapes (De Morgan representation) Set the selected shape:
  258. if( convertCheckBox->IsEnabled() )
  259. {
  260. m_cmp->SetConvert( convertCheckBox->GetValue() ? 2 : 1 );
  261. }
  262. //Set the part selection in multiple part per package
  263. if( m_cmp->GetUnit() )
  264. {
  265. int unit_selection = unitChoice->GetCurrentSelection() + 1;
  266. m_cmp->SetUnitSelection( &m_parent->GetCurrentSheet(), unit_selection );
  267. m_cmp->SetUnit( unit_selection );
  268. }
  269. switch( orientationRadioBox->GetSelection() )
  270. {
  271. case 0:
  272. m_cmp->SetOrientation( CMP_ORIENT_0 );
  273. break;
  274. case 1:
  275. m_cmp->SetOrientation( CMP_ORIENT_90 );
  276. break;
  277. case 2:
  278. m_cmp->SetOrientation( CMP_ORIENT_180 );
  279. break;
  280. case 3:
  281. m_cmp->SetOrientation( CMP_ORIENT_270 );
  282. break;
  283. }
  284. int mirror = mirrorRadioBox->GetSelection();
  285. switch( mirror )
  286. {
  287. case 0:
  288. break;
  289. case 1:
  290. m_cmp->SetOrientation( CMP_MIRROR_X );
  291. break;
  292. case 2:
  293. m_cmp->SetOrientation( CMP_MIRROR_Y );
  294. break;
  295. }
  296. // Restore m_Flag modified by SetUnit() and other change settings
  297. m_cmp->ClearFlags();
  298. m_cmp->SetFlags( flags );
  299. }
  300. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event )
  301. {
  302. bool removeRemainingFields = false;
  303. if( !copyPanelToSelectedField() )
  304. return;
  305. if( ! SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) )
  306. {
  307. DisplayError( NULL, _( "Illegal reference. A reference must start with a letter" ) );
  308. return;
  309. }
  310. // save old cmp in undo list if not already in edit, or moving ...
  311. // or the component to be edited is part of a block
  312. if( m_cmp->m_Flags == 0
  313. || m_parent->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
  314. m_parent->SaveCopyInUndoList( m_cmp, UR_CHANGED );
  315. copyPanelToOptions();
  316. // Delete any fields with no name before we copy all of m_FieldsBuf back into the component.
  317. for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
  318. {
  319. if( m_FieldsBuf[i].GetName( false ).IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
  320. {
  321. // If a field has no value and is not it the field template list, warn the user
  322. // that it will be remove from the component. This gives the user a chance to
  323. // correct the problem before removing the undefined fields. It should also
  324. // resolve most of the bug reports and questions regarding missing fields.
  325. if( !m_FieldsBuf[i].GetName( false ).IsEmpty() && m_FieldsBuf[i].GetText().IsEmpty()
  326. && !m_parent->GetTemplates().HasFieldName( m_FieldsBuf[i].GetName( false ) )
  327. && !removeRemainingFields )
  328. {
  329. wxString msg = wxString::Format(
  330. _( "The field name <%s> does not have a value and is not defined in "
  331. "the field template list. Empty field values are invalid an will "
  332. "be removed from the component. Do you wish to remove this and "
  333. "all remaining undefined fields?" ),
  334. GetChars( m_FieldsBuf[i].GetName( false ) )
  335. );
  336. wxMessageDialog dlg( this, msg, _( "Remove Fields" ), wxYES_NO | wxNO_DEFAULT );
  337. if( dlg.ShowModal() == wxID_NO )
  338. return;
  339. removeRemainingFields = true;
  340. }
  341. m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
  342. continue;
  343. }
  344. ++i;
  345. }
  346. // change all field positions from relative to absolute
  347. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  348. {
  349. m_FieldsBuf[i].SetTextPosition( m_FieldsBuf[i].GetTextPosition() + m_cmp->m_Pos );
  350. }
  351. LIB_PART* entry = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name );
  352. if( entry && entry->IsPower() )
  353. m_FieldsBuf[VALUE].SetText( m_cmp->m_part_name );
  354. // copy all the fields back, and change the length of m_Fields.
  355. m_cmp->SetFields( m_FieldsBuf );
  356. // Reference has a specific initialization, depending on the current active sheet
  357. // because for a given component, in a complex hierarchy, there are more than one
  358. // reference.
  359. m_cmp->SetRef( &m_parent->GetCurrentSheet(), m_FieldsBuf[REFERENCE].GetText() );
  360. m_parent->OnModify();
  361. m_parent->GetScreen()->TestDanglingEnds();
  362. EndQuasiModal( wxID_OK );
  363. }
  364. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::addFieldButtonHandler( wxCommandEvent& event )
  365. {
  366. // in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
  367. // screen contents.
  368. if( !copyPanelToSelectedField() )
  369. return;
  370. unsigned fieldNdx = m_FieldsBuf.size();
  371. SCH_FIELD blank( wxPoint(), fieldNdx, m_cmp );
  372. blank.SetOrientation( m_FieldsBuf[REFERENCE].GetOrientation() );
  373. m_FieldsBuf.push_back( blank );
  374. m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
  375. m_skipCopyFromPanel = true;
  376. setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
  377. setSelectedFieldNdx( fieldNdx );
  378. m_skipCopyFromPanel = false;
  379. }
  380. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEvent& event )
  381. {
  382. unsigned fieldNdx = getSelectedFieldNdx();
  383. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  384. return;
  385. if( fieldNdx < MANDATORY_FIELDS )
  386. {
  387. wxBell();
  388. return;
  389. }
  390. m_skipCopyFromPanel = true;
  391. m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
  392. fieldListCtrl->DeleteItem( fieldNdx );
  393. if( fieldNdx >= m_FieldsBuf.size() )
  394. --fieldNdx;
  395. updateDisplay();
  396. setSelectedFieldNdx( fieldNdx );
  397. m_skipCopyFromPanel = false;
  398. }
  399. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& event )
  400. {
  401. unsigned fieldNdx = getSelectedFieldNdx();
  402. if( fieldNdx == DATASHEET )
  403. {
  404. wxString datasheet_uri = fieldValueTextCtrl->GetValue();
  405. ::wxLaunchDefaultBrowser( datasheet_uri );
  406. }
  407. else if( fieldNdx == FOOTPRINT )
  408. {
  409. // pick a footprint using the footprint picker.
  410. wxString fpid;
  411. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, m_parent );
  412. if( frame->ShowModal( &fpid, this ) )
  413. {
  414. // DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); )
  415. fieldValueTextCtrl->SetValue( fpid );
  416. }
  417. frame->Destroy();
  418. }
  419. }
  420. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& event )
  421. {
  422. unsigned fieldNdx = getSelectedFieldNdx();
  423. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  424. return;
  425. if( fieldNdx <= MANDATORY_FIELDS )
  426. {
  427. wxBell();
  428. return;
  429. }
  430. if( !copyPanelToSelectedField() )
  431. return;
  432. // swap the fieldNdx field with the one before it, in both the vector
  433. // and in the fieldListCtrl
  434. SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
  435. DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n",
  436. TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); )
  437. m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
  438. setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
  439. m_FieldsBuf[fieldNdx] = tmp;
  440. setRowItem( fieldNdx, tmp );
  441. updateDisplay();
  442. m_skipCopyFromPanel = true;
  443. setSelectedFieldNdx( fieldNdx - 1 );
  444. m_skipCopyFromPanel = false;
  445. }
  446. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx )
  447. {
  448. /* deselect old selection, but I think this is done by single selection
  449. * flag within fieldListCtrl.
  450. * fieldListCtrl->SetItemState( s_SelectedRow, 0,
  451. * wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
  452. */
  453. if( aFieldNdx >= (int) m_FieldsBuf.size() )
  454. aFieldNdx = m_FieldsBuf.size() - 1;
  455. if( aFieldNdx < 0 )
  456. aFieldNdx = 0;
  457. fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
  458. fieldListCtrl->EnsureVisible( aFieldNdx );
  459. s_SelectedRow = aFieldNdx;
  460. }
  461. int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx()
  462. {
  463. return s_SelectedRow;
  464. }
  465. SCH_FIELD* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::findField( const wxString& aFieldName )
  466. {
  467. for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
  468. {
  469. if( aFieldName == m_FieldsBuf[i].GetName( false ) )
  470. return &m_FieldsBuf[i];
  471. }
  472. return NULL;
  473. }
  474. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent )
  475. {
  476. m_cmp = aComponent;
  477. /* We have 3 component related field lists to be aware of: 1) UI
  478. presentation, 2) fields in component ram copy, and 3) fields recorded
  479. with component on disk. m_FieldsBuf is the list of UI fields, and this
  480. list is not the same as the list which is in the component, which is
  481. also not the same as the list on disk. All 3 lists are potentially
  482. different. In the UI we choose to preserve the order of the first
  483. MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
  484. the template fieldnames in the exact same order as the template
  485. fieldname editor shows them. Then we append any user defined fieldnames
  486. which came from the component.
  487. */
  488. m_part = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name );
  489. #if 0 && defined(DEBUG)
  490. for( int i = 0; i<aComponent->GetFieldCount(); ++i )
  491. {
  492. printf( "Orig[%d] (x=%d, y=%d)\n", i, aComponent->m_Fields[i].GetTextPosition().x,
  493. aComponent->m_Fields[i].GetTextPosition().y );
  494. }
  495. #endif
  496. // When this code was written, all field constructors ensure that the fixed fields
  497. // are all present within a component. So we can knowingly copy them over
  498. // in the normal order. Copy only the fixed fields at first.
  499. // Please do not break the field constructors.
  500. m_FieldsBuf.clear();
  501. for( int i=0; i<MANDATORY_FIELDS; ++i )
  502. {
  503. m_FieldsBuf.push_back( aComponent->m_Fields[i] );
  504. // make the editable field position relative to the component
  505. m_FieldsBuf[i].SetTextPosition( m_FieldsBuf[i].GetTextPosition() - m_cmp->m_Pos );
  506. }
  507. // Add template fieldnames:
  508. // Now copy in the template fields, in the order that they are present in the
  509. // template field editor UI.
  510. const TEMPLATE_FIELDNAMES& tfnames = m_parent->GetTemplateFieldNames();
  511. for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
  512. {
  513. // add a new field unconditionally to the UI only
  514. SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, m_cmp, it->m_Name );
  515. // See if field by same name already exists in component.
  516. SCH_FIELD* schField = aComponent->FindField( it->m_Name );
  517. // If the field does not already exist in the component, then we
  518. // use defaults from the template fieldname, otherwise the original
  519. // values from the component will be set.
  520. if( !schField )
  521. {
  522. if( !it->m_Visible )
  523. fld.SetVisible( false );
  524. else
  525. fld.SetVisible( true );
  526. fld.SetText( it->m_Value ); // empty? ok too.
  527. }
  528. else
  529. {
  530. fld = *schField;
  531. // make the editable field position relative to the component
  532. fld.SetTextPosition( fld.GetTextPosition() - m_cmp->m_Pos );
  533. }
  534. m_FieldsBuf.push_back( fld );
  535. }
  536. // Lastly, append any original fields from the component which were not added
  537. // from the set of fixed fields nor from the set of template fields.
  538. for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
  539. {
  540. SCH_FIELD* cmp = &aComponent->m_Fields[i];
  541. SCH_FIELD* buf = findField( cmp->GetName( false ) );
  542. if( !buf )
  543. {
  544. int newNdx = m_FieldsBuf.size();
  545. m_FieldsBuf.push_back( *cmp );
  546. // make the editable field position relative to the component
  547. m_FieldsBuf[newNdx].SetTextPosition( m_FieldsBuf[newNdx].GetTextPosition() -
  548. m_cmp->m_Pos );
  549. }
  550. }
  551. #if 0 && defined(DEBUG)
  552. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  553. {
  554. printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
  555. m_FieldsBuf[i].m_Pos.y, TO_UTF8(m_FieldsBuf[i].GetName( false ) ) );
  556. }
  557. #endif
  558. m_FieldsBuf[REFERENCE].SetText( m_cmp->GetRef( &m_parent->GetCurrentSheet() ) );
  559. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  560. {
  561. setRowItem( i, m_FieldsBuf[i] );
  562. }
  563. #if 0 && defined(DEBUG)
  564. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  565. {
  566. printf( "after[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
  567. m_FieldsBuf[i].m_Pos.y );
  568. }
  569. #endif
  570. copyOptionsToPanel();
  571. // disable some options inside the edit dialog
  572. // which can cause problems while dragging
  573. if( m_cmp->IsDragging() )
  574. {
  575. orientationRadioBox->Disable();
  576. mirrorRadioBox->Disable();
  577. chipnameTextCtrl->Disable();
  578. }
  579. // put focus on the list ctrl
  580. fieldListCtrl->SetFocus();
  581. // resume editing at the last row edited, last time dialog was up.
  582. setSelectedFieldNdx( s_SelectedRow );
  583. copySelectedFieldToPanel();
  584. }
  585. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const SCH_FIELD& aField )
  586. {
  587. wxASSERT( aFieldNdx >= 0 );
  588. // insert blanks if aFieldNdx is referencing a "yet to be defined" row
  589. while( aFieldNdx >= fieldListCtrl->GetItemCount() )
  590. {
  591. long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
  592. wxASSERT( ndx >= 0 );
  593. fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
  594. }
  595. fieldListCtrl->SetItem( aFieldNdx, 0, aField.GetName( false ) );
  596. fieldListCtrl->SetItem( aFieldNdx, 1, aField.GetText() );
  597. // recompute the column widths here, after setting texts
  598. fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  599. fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
  600. }
  601. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
  602. {
  603. wxCHECK_RET( m_cmp != NULL, wxT( "Component pointer not initialized." ) );
  604. unsigned fieldNdx = getSelectedFieldNdx();
  605. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  606. return;
  607. SCH_FIELD& field = m_FieldsBuf[fieldNdx];
  608. showCheckBox->SetValue( field.IsVisible() );
  609. rotateCheckBox->SetValue( field.GetOrientation() == TEXT_ORIENT_VERT );
  610. int style = 0;
  611. if( field.IsItalic() )
  612. style = 1;
  613. if( field.IsBold() )
  614. style |= 2;
  615. m_StyleRadioBox->SetSelection( style );
  616. // Select the right text justification
  617. if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
  618. m_FieldHJustifyCtrl->SetSelection( 0 );
  619. else if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
  620. m_FieldHJustifyCtrl->SetSelection( 2 );
  621. else
  622. m_FieldHJustifyCtrl->SetSelection( 1 );
  623. if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
  624. m_FieldVJustifyCtrl->SetSelection( 0 );
  625. else if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
  626. m_FieldVJustifyCtrl->SetSelection( 2 );
  627. else
  628. m_FieldVJustifyCtrl->SetSelection( 1 );
  629. fieldNameTextCtrl->SetValue( field.GetName( false ) );
  630. // the names of the fixed fields are not editable, others are.
  631. fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
  632. fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
  633. // only user defined fields may be moved, and not the top most user defined
  634. // field since it would be moving up into the fixed fields, > not >=
  635. moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
  636. // may only delete user defined fields
  637. deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
  638. fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( field.GetId() ) );
  639. fieldValueTextCtrl->SetValue( field.GetText() );
  640. m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
  641. if( fieldNdx == DATASHEET )
  642. m_show_datasheet_button->SetLabel( _( "Show in Browser" ) );
  643. else if( fieldNdx == FOOTPRINT )
  644. m_show_datasheet_button->SetLabel( _( "Assign Footprint" ) );
  645. else
  646. m_show_datasheet_button->SetLabel( wxEmptyString );
  647. // For power symbols, the value is NOR editable, because value and pin
  648. // name must be same and can be edited only in library editor
  649. if( fieldNdx == VALUE && m_part && m_part->IsPower() )
  650. fieldValueTextCtrl->Enable( false );
  651. else
  652. fieldValueTextCtrl->Enable( true );
  653. textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetSize().x ) );
  654. wxPoint coord = field.GetTextPosition();
  655. wxPoint zero = -m_cmp->m_Pos; // relative zero
  656. // If the field value is empty and the position is at relative zero, we
  657. // set the initial position as a small offset from the ref field, and
  658. // orient it the same as the ref field. That is likely to put it at least
  659. // close to the desired position.
  660. if( coord == zero && field.GetText().IsEmpty() )
  661. {
  662. rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].GetOrientation() == TEXT_ORIENT_VERT );
  663. coord.x = m_FieldsBuf[REFERENCE].GetTextPosition().x
  664. + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
  665. coord.y = m_FieldsBuf[REFERENCE].GetTextPosition().y
  666. + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
  667. // coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
  668. // That is ok, we basically don't want all the new empty fields on
  669. // top of each other.
  670. }
  671. wxString coordText = StringFromValue( g_UserUnit, coord.x );
  672. posXTextCtrl->SetValue( coordText );
  673. coordText = StringFromValue( g_UserUnit, coord.y );
  674. posYTextCtrl->SetValue( coordText );
  675. }
  676. bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField()
  677. {
  678. unsigned fieldNdx = getSelectedFieldNdx();
  679. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  680. return true;
  681. // Check for illegal field text.
  682. if( fieldValueTextCtrl->GetValidator()
  683. && !fieldValueTextCtrl->GetValidator()->Validate( this ) )
  684. return false;
  685. SCH_FIELD& field = m_FieldsBuf[fieldNdx];
  686. field.SetVisible( showCheckBox->GetValue() );
  687. if( rotateCheckBox->GetValue() )
  688. field.SetOrientation( TEXT_ORIENT_VERT );
  689. else
  690. field.SetOrientation( TEXT_ORIENT_HORIZ );
  691. rotateCheckBox->SetValue( field.GetOrientation() == TEXT_ORIENT_VERT );
  692. // Copy the text justification
  693. static const EDA_TEXT_HJUSTIFY_T hjustify[] = {
  694. GR_TEXT_HJUSTIFY_LEFT,
  695. GR_TEXT_HJUSTIFY_CENTER,
  696. GR_TEXT_HJUSTIFY_RIGHT
  697. };
  698. static const EDA_TEXT_VJUSTIFY_T vjustify[] = {
  699. GR_TEXT_VJUSTIFY_BOTTOM,
  700. GR_TEXT_VJUSTIFY_CENTER,
  701. GR_TEXT_VJUSTIFY_TOP
  702. };
  703. field.SetHorizJustify( hjustify[m_FieldHJustifyCtrl->GetSelection()] );
  704. field.SetVertJustify( vjustify[m_FieldVJustifyCtrl->GetSelection()] );
  705. field.SetName( fieldNameTextCtrl->GetValue() );
  706. /* Void fields texts for REFERENCE and VALUE (value is the name of the
  707. * component in lib ! ) are not allowed
  708. * change them only for a new non void value
  709. * When void, usually netlists are broken
  710. */
  711. if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
  712. field.SetText( fieldValueTextCtrl->GetValue() );
  713. setRowItem( fieldNdx, field ); // update fieldListCtrl
  714. int tmp = EDA_GRAPHIC_TEXT_CTRL::ParseSize( textSizeTextCtrl->GetValue(), g_UserUnit );
  715. field.SetSize( wxSize( tmp, tmp ) );
  716. int style = m_StyleRadioBox->GetSelection();
  717. field.SetItalic( (style & 1 ) != 0 );
  718. field.SetBold( (style & 2 ) != 0 );
  719. wxPoint pos;
  720. pos.x = ValueFromString( g_UserUnit, posXTextCtrl->GetValue() );
  721. pos.y = ValueFromString( g_UserUnit, posYTextCtrl->GetValue() );
  722. field.SetTextPosition( pos );
  723. return true;
  724. }
  725. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
  726. {
  727. // Remove non existing choices (choiceCount must be <= number for parts)
  728. int unitcount = m_part ? m_part->GetUnitCount() : 1;
  729. if( unitcount < 1 )
  730. unitcount = 1;
  731. unitChoice->Clear();
  732. for( int ii = 1; ii <= unitcount; ii++ )
  733. {
  734. unitChoice->Append( LIB_PART::SubReference( ii, false ) );
  735. }
  736. // For components with multiple parts per package, set the unit selection
  737. if( m_cmp->GetUnit() <= (int)unitChoice->GetCount() )
  738. unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
  739. // Disable unit selection if only one unit exists:
  740. if( m_cmp->GetUnitCount() <= 1 )
  741. {
  742. unitChoice->Enable( false );
  743. unitsInterchageableLabel->Show( false );
  744. unitsInterchageableText->Show( false );
  745. }
  746. else
  747. {
  748. // Show the "Units are not interchangeable" message option?
  749. if( !m_part || !m_part->UnitsLocked() )
  750. unitsInterchageableLabel->SetLabel( _( "Yes" ) );
  751. else
  752. unitsInterchageableLabel->SetLabel( _( "No" ) );
  753. }
  754. int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
  755. if( orientation == CMP_ORIENT_90 )
  756. orientationRadioBox->SetSelection( 1 );
  757. else if( orientation == CMP_ORIENT_180 )
  758. orientationRadioBox->SetSelection( 2 );
  759. else if( orientation == CMP_ORIENT_270 )
  760. orientationRadioBox->SetSelection( 3 );
  761. else
  762. orientationRadioBox->SetSelection( 0 );
  763. int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
  764. if( mirror == CMP_MIRROR_X )
  765. {
  766. mirrorRadioBox->SetSelection( 1 );
  767. DBG( printf( "mirror=X,1\n" ); )
  768. }
  769. else if( mirror == CMP_MIRROR_Y )
  770. {
  771. mirrorRadioBox->SetSelection( 2 );
  772. DBG( printf( "mirror=Y,2\n" ); )
  773. }
  774. else
  775. mirrorRadioBox->SetSelection( 0 );
  776. // Activate/Desactivate the normal/convert option ? (activated only if
  777. // the component has more than one shape)
  778. if( m_cmp->GetConvert() > 1 )
  779. convertCheckBox->SetValue( true );
  780. if( m_part == NULL || !m_part->HasConversion() )
  781. convertCheckBox->Enable( false );
  782. // Set the component's library name.
  783. chipnameTextCtrl->SetValue( m_cmp->m_part_name );
  784. // Set the component's unique ID time stamp.
  785. m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
  786. (unsigned long) m_cmp->GetTimeStamp() ) );
  787. }
  788. #include <kicad_device_context.h>
  789. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
  790. {
  791. if( !m_cmp )
  792. return;
  793. if( LIB_PART* part = Prj().SchLibs()->FindLibPart( m_cmp->m_part_name ) )
  794. {
  795. // save old cmp in undo list if not already in edit, or moving ...
  796. if( m_cmp->m_Flags == 0 )
  797. m_parent->SaveCopyInUndoList( m_cmp, UR_CHANGED );
  798. INSTALL_UNBUFFERED_DC( dc, m_parent->GetCanvas() );
  799. m_cmp->Draw( m_parent->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );
  800. // Initialize fixed field values to default values found in library
  801. // Note: the field texts are not modified because they are set in schematic,
  802. // the text from libraries is most of time a dummy text
  803. // Only VALUE, REFERENCE , FOOTPRINT and DATASHEET are re-initialized
  804. LIB_FIELD& refField = part->GetReferenceField();
  805. m_cmp->GetField( REFERENCE )->SetTextPosition( refField.GetTextPosition() + m_cmp->m_Pos );
  806. m_cmp->GetField( REFERENCE )->ImportValues( refField );
  807. LIB_FIELD& valField = part->GetValueField();
  808. m_cmp->GetField( VALUE )->SetTextPosition( valField.GetTextPosition() + m_cmp->m_Pos );
  809. m_cmp->GetField( VALUE )->ImportValues( valField );
  810. LIB_FIELD* field = part->GetField(FOOTPRINT);
  811. if( field && m_cmp->GetField( FOOTPRINT ) )
  812. {
  813. m_cmp->GetField( FOOTPRINT )->SetTextPosition( field->GetTextPosition() + m_cmp->m_Pos );
  814. m_cmp->GetField( FOOTPRINT )->ImportValues( *field );
  815. }
  816. field = part->GetField(DATASHEET);
  817. if( field && m_cmp->GetField( DATASHEET ) )
  818. {
  819. m_cmp->GetField( DATASHEET )->SetTextPosition( field->GetTextPosition() + m_cmp->m_Pos );
  820. m_cmp->GetField( DATASHEET )->ImportValues( *field );
  821. }
  822. m_cmp->SetOrientation( CMP_NORMAL );
  823. m_parent->OnModify();
  824. m_cmp->Draw( m_parent->GetCanvas(), &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
  825. EndQuasiModal( wxID_OK );
  826. }
  827. }