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.

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