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.

1266 lines
39 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
* 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-2018 KiCad Developers, see AUTHORS.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. #include <wx/tooltip.h>
  24. #include <wx/hyperlink.h>
  25. #include <wx/url.h>
  26. #include <fctsys.h>
  27. #include <pgm_base.h>
  28. #include <kiway.h>
  29. #include <class_drawpanel.h>
  30. #include <confirm.h>
  31. #include <schframe.h>
  32. #include <base_units.h>
  33. #include <sch_reference_list.h>
  34. #include <class_library.h>
  35. #include <sch_component.h>
  36. #include <dialog_helpers.h>
  37. #include <sch_validators.h>
  38. #include <kicad_device_context.h>
  39. #include <symbol_lib_table.h>
  40. #include <bitmaps.h>
  41. #include <dialog_edit_component_in_schematic_fbp.h>
  42. #include <invoke_sch_dialog.h>
  43. #ifdef KICAD_SPICE
  44. #include <dialog_spice_model.h>
  45. #include <netlist_exporter_pspice.h>
  46. #endif /* KICAD_SPICE */
  47. #include "common.h"
  48. #include "eda_doc.h"
  49. #include <list>
  50. /**
  51. * Dialog used to edit #SCH_COMPONENT objects in a schematic.
  52. *
  53. * This is derived from DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP which is maintained by
  54. * wxFormBuilder. Do not auto-generate this class or file, it is hand coded.
  55. */
  56. class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP
  57. {
  58. public:
  59. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT_FRAME* aParent );
  60. /**
  61. * Initialize controls with \a aComponent.
  62. *.
  63. * @param aComponent The component to edit.
  64. */
  65. void InitBuffers( SCH_COMPONENT* aComponent );
  66. SCH_EDIT_FRAME* GetParent() { return dynamic_cast< SCH_EDIT_FRAME* >( wxDialog::GetParent() ); }
  67. private:
  68. friend class SCH_EDIT_FRAME;
  69. SCH_COMPONENT* m_cmp;
  70. LIB_PART* m_part;
  71. bool m_skipCopyFromPanel;
  72. static int s_SelectedRow;
  73. /// a copy of the edited symbol's SCH_FIELDs
  74. SCH_FIELDS m_FieldsBuf;
  75. void setSelectedFieldNdx( int aFieldNdx );
  76. int getSelectedFieldNdx();
  77. /**
  78. * Sets the values displayed on the panel according to the currently selected field row.
  79. */
  80. void copySelectedFieldToPanel();
  81. /**
  82. * Copy the values displayed on the panel fields to the currently selected field.
  83. *
  84. * @return bool - true if all fields are OK, else false if the user has put
  85. * bad data into a field, and this value can be used to deny a row change.
  86. */
  87. bool copyPanelToSelectedField();
  88. void copyOptionsToPanel();
  89. void copyPanelToOptions();
  90. void setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue );
  91. void setRowItem( int aFieldNdx, const SCH_FIELD& aField )
  92. {
  93. // Use default field name for mandatory fields, because they are transalted
  94. // according to the current locale
  95. wxString f_name;
  96. if( aFieldNdx < MANDATORY_FIELDS )
  97. f_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldNdx );
  98. else
  99. f_name = aField.GetName( false );
  100. setRowItem( aFieldNdx, f_name, aField.GetText() );
  101. }
  102. // event handlers
  103. void OnCloseDialog( wxCloseEvent& event ) override;
  104. void OnListItemDeselected( wxListEvent& event ) override;
  105. void OnListItemSelected( wxListEvent& event ) override;
  106. void OnCancelButtonClick( wxCommandEvent& event ) override;
  107. void OnOKButtonClick( wxCommandEvent& event ) override;
  108. void SetInitCmp( wxCommandEvent& event ) override;
  109. void UpdateFields( wxCommandEvent& event ) override;
  110. void addFieldButtonHandler( wxCommandEvent& event ) override;
  111. void deleteFieldButtonHandler( wxCommandEvent& event ) override;
  112. void moveUpButtonHandler( wxCommandEvent& event ) override;
  113. void moveDownButtonHandler( wxCommandEvent& event ) override;
  114. void showButtonHandler( wxCommandEvent& event ) override;
  115. void OnTestChipName( wxCommandEvent& event ) override;
  116. void OnSelectChipName( wxCommandEvent& event ) override;
  117. void OnInitDlg( wxInitDialogEvent& event ) override
  118. {
  119. TransferDataToWindow();
  120. // Now all widgets have the size fixed, call FinishDialogSettings
  121. FinishDialogSettings();
  122. }
  123. void EditSpiceModel( wxCommandEvent& event ) override;
  124. SCH_FIELD* findField( const wxString& aFieldName );
  125. /**
  126. * Update the listbox showing fields according to the field's text.
  127. *
  128. * This must be called after a text change in fields if this change is not an edition.
  129. */
  130. void updateDisplay()
  131. {
  132. fieldListCtrl->DeleteAllItems();
  133. for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
  134. setRowItem( ii, m_FieldsBuf[ii] );
  135. }
  136. };
  137. int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
  138. void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent )
  139. {
  140. wxCHECK_RET( aComponent != NULL && aComponent->Type() == SCH_COMPONENT_T,
  141. wxT( "Invalid component object pointer. Bad Programmer!" ) );
  142. m_canvas->SetIgnoreMouseEvents( true );
  143. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC* dlg = new DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( this );
  144. dlg->InitBuffers( aComponent );
  145. // make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
  146. EnsureTextCtrlWidth( dlg->chipnameTextCtrl );
  147. // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
  148. // frame. Therefore this dialog as a modal frame parent, MUST be run under
  149. // quasimodal mode for the quasimodal frame support to work. So don't use
  150. // the QUASIMODAL macros here.
  151. int ret = dlg->ShowQuasiModal();
  152. if( m_autoplaceFields )
  153. aComponent->AutoAutoplaceFields( GetScreen() );
  154. m_canvas->SetIgnoreMouseEvents( false );
  155. m_canvas->MoveCursorToCrossHair();
  156. dlg->Destroy();
  157. if( ret == wxID_OK )
  158. GetCanvas()->Refresh();
  159. }
  160. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT_FRAME* aParent ) :
  161. DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( aParent )
  162. {
  163. #ifndef KICAD_SPICE
  164. spiceFieldsButton->Hide();
  165. #endif /* not KICAD_SPICE */
  166. m_cmp = NULL;
  167. m_part = NULL;
  168. m_skipCopyFromPanel = false;
  169. wxListItem columnLabel;
  170. columnLabel.SetImage( -1 );
  171. columnLabel.SetText( _( "Name" ) );
  172. fieldListCtrl->InsertColumn( 0, columnLabel );
  173. columnLabel.SetText( _( "Value" ) );
  174. fieldListCtrl->InsertColumn( 1, columnLabel );
  175. m_staticTextUnitSize->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  176. m_staticTextUnitPosX->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  177. m_staticTextUnitPosY->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  178. wxToolTip::Enable( true );
  179. stdDialogButtonSizerOK->SetDefault();
  180. // Configure button logos
  181. addFieldButton->SetBitmap( KiBitmap( plus_xpm ) );
  182. deleteFieldButton->SetBitmap( KiBitmap( minus_xpm ) );
  183. moveUpButton->SetBitmap( KiBitmap( go_up_xpm ) );
  184. moveDownButton->SetBitmap( KiBitmap( go_down_xpm ) );
  185. Fit();
  186. }
  187. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event )
  188. {
  189. if( !m_skipCopyFromPanel )
  190. {
  191. if( !copyPanelToSelectedField() )
  192. event.Skip(); // do not go to the next row
  193. }
  194. }
  195. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnTestChipName( wxCommandEvent& event )
  196. {
  197. LIB_ID id;
  198. wxString msg;
  199. wxString partname = chipnameTextCtrl->GetValue();
  200. if( id.Parse( partname ) != -1 || !id.IsValid() )
  201. {
  202. msg.Printf( _( "\"%s\" is not a valid library symbol indentifier." ), partname );
  203. DisplayError( this, msg );
  204. return;
  205. }
  206. LIB_ALIAS* alias = NULL;
  207. try
  208. {
  209. alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
  210. }
  211. catch( ... )
  212. {
  213. }
  214. if( !alias )
  215. {
  216. msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"" ),
  217. id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
  218. DisplayError( this, msg );
  219. return;
  220. }
  221. msg.Printf( _( "Symbol \"%s\" found in library \"%s\"" ),
  222. id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
  223. DisplayInfoMessage( this, msg );
  224. }
  225. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event )
  226. {
  227. SCH_BASE_FRAME::HISTORY_LIST dummy;
  228. auto sel = GetParent()->SelectComponentFromLibrary( NULL, dummy, true, 0, 0, false );
  229. if( !sel.LibId.IsValid() )
  230. return;
  231. chipnameTextCtrl->SetValue( sel.LibId.Format() );
  232. }
  233. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::EditSpiceModel( wxCommandEvent& event )
  234. {
  235. #ifdef KICAD_SPICE
  236. setSelectedFieldNdx( 0 );
  237. DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_FieldsBuf );
  238. if( dialog.ShowModal() == wxID_OK )
  239. updateDisplay();
  240. #endif /* KICAD_SPICE */
  241. }
  242. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event )
  243. {
  244. // remember the selected row, statically
  245. s_SelectedRow = event.GetIndex();
  246. copySelectedFieldToPanel();
  247. }
  248. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCloseDialog( wxCloseEvent& event )
  249. {
  250. // On wxWidgets 2.8, and on Linux, calling EndQuasiModal here is mandatory
  251. // Otherwise, the main event loop is never restored, and Eeschema does not
  252. // respond to any event, because the DIALOG_SHIM destructor is never called.
  253. // On wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
  254. // and calls EndQuasiModal.
  255. // therefore calling EndQuasiModal here is not always mandatory but it creates no issues
  256. EndQuasiModal( wxID_CANCEL );
  257. }
  258. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event )
  259. {
  260. EndQuasiModal( wxID_CANCEL );
  261. }
  262. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
  263. {
  264. LIB_ID id;
  265. wxString msg;
  266. wxString tmp = chipnameTextCtrl->GetValue();
  267. tmp.Replace( wxT( " " ), wxT( "_" ) );
  268. id.Parse( tmp );
  269. // Save current flags which could be modified by next change settings
  270. STATUS_FLAGS flags = m_cmp->GetFlags();
  271. if( !id.IsValid() )
  272. {
  273. msg.Printf( _( "Symbol library identifier \"%s\" is not valid!" ), tmp );
  274. DisplayError( this, msg );
  275. }
  276. else if( id != m_cmp->GetLibId() )
  277. {
  278. LIB_ALIAS* alias = NULL;
  279. try
  280. {
  281. alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
  282. }
  283. catch( ... )
  284. {
  285. }
  286. if( !alias )
  287. {
  288. msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"!" ),
  289. id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
  290. DisplayError( this, msg );
  291. }
  292. else // Change symbol from lib!
  293. {
  294. m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
  295. }
  296. }
  297. // For symbols with multiple shapes (De Morgan representation) Set the selected shape:
  298. if( convertCheckBox->IsEnabled() )
  299. {
  300. m_cmp->SetConvert( convertCheckBox->GetValue() ? 2 : 1 );
  301. }
  302. //Set the part selection in multiple part per package
  303. if( m_cmp->GetUnit() )
  304. {
  305. int unit_selection = unitChoice->GetCurrentSelection() + 1;
  306. m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
  307. m_cmp->SetUnit( unit_selection );
  308. }
  309. switch( orientationRadioBox->GetSelection() )
  310. {
  311. case 0:
  312. m_cmp->SetOrientation( CMP_ORIENT_0 );
  313. break;
  314. case 1:
  315. m_cmp->SetOrientation( CMP_ORIENT_90 );
  316. break;
  317. case 2:
  318. m_cmp->SetOrientation( CMP_ORIENT_180 );
  319. break;
  320. case 3:
  321. m_cmp->SetOrientation( CMP_ORIENT_270 );
  322. break;
  323. }
  324. int mirror = mirrorRadioBox->GetSelection();
  325. switch( mirror )
  326. {
  327. case 0:
  328. break;
  329. case 1:
  330. m_cmp->SetOrientation( CMP_MIRROR_X );
  331. break;
  332. case 2:
  333. m_cmp->SetOrientation( CMP_MIRROR_Y );
  334. break;
  335. }
  336. // Restore m_Flag modified by SetUnit() and other change settings
  337. m_cmp->ClearFlags();
  338. m_cmp->SetFlags( flags );
  339. }
  340. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event )
  341. {
  342. bool removeRemainingFields = false;
  343. if( !copyPanelToSelectedField() )
  344. return;
  345. if( ! SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) )
  346. {
  347. DisplayError( NULL, _( "Illegal reference. A reference must start with a letter" ) );
  348. return;
  349. }
  350. // save old cmp in undo list if not already in edit, or moving ...
  351. // or the component to be edited is part of a block
  352. if( m_cmp->GetFlags() == 0
  353. || GetParent()->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
  354. GetParent()->SaveCopyInUndoList( m_cmp, UR_CHANGED );
  355. copyPanelToOptions();
  356. // Delete any fields with no name before we copy all of m_FieldsBuf back into the component.
  357. for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
  358. {
  359. if( m_FieldsBuf[i].GetName( false ).IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
  360. {
  361. // If a field has no value and is not it the field template list, warn the user
  362. // that it will be remove from the component. This gives the user a chance to
  363. // correct the problem before removing the undefined fields. It should also
  364. // resolve most of the bug reports and questions regarding missing fields.
  365. if( !m_FieldsBuf[i].GetName( false ).IsEmpty() && m_FieldsBuf[i].GetText().IsEmpty()
  366. && !GetParent()->GetTemplates().HasFieldName( m_FieldsBuf[i].GetName( false ) )
  367. && !removeRemainingFields )
  368. {
  369. wxString msg = wxString::Format(
  370. _( "The field name \"%s\" does not have a value and is not defined in "
  371. "the field template list. Empty field values are invalid an will "
  372. "be removed from the component. Do you wish to remove this and "
  373. "all remaining undefined fields?" ),
  374. GetChars( m_FieldsBuf[i].GetName( false ) )
  375. );
  376. wxMessageDialog dlg( this, msg, _( "Remove Fields" ), wxYES_NO | wxNO_DEFAULT );
  377. if( dlg.ShowModal() == wxID_NO )
  378. return;
  379. removeRemainingFields = true;
  380. }
  381. m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
  382. continue;
  383. }
  384. ++i;
  385. }
  386. // change all field positions from relative to absolute
  387. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  388. {
  389. m_FieldsBuf[i].Offset( m_cmp->m_Pos );
  390. }
  391. LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
  392. if( entry && entry->IsPower() )
  393. m_FieldsBuf[VALUE].SetText( m_cmp->GetLibId().GetLibItemName() );
  394. // copy all the fields back, and change the length of m_Fields.
  395. m_cmp->SetFields( m_FieldsBuf );
  396. // Reference has a specific initialization, depending on the current active sheet
  397. // because for a given component, in a complex hierarchy, there are more than one
  398. // reference.
  399. m_cmp->SetRef( &GetParent()->GetCurrentSheet(), m_FieldsBuf[REFERENCE].GetText() );
  400. // The value, footprint and datasheet fields should be kept in sync in multi-unit
  401. // parts.
  402. if( m_cmp->GetUnitCount() > 1 )
  403. {
  404. const LIB_ID thisLibId = m_cmp->GetLibId();
  405. const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
  406. int thisUnit = m_cmp->GetUnit();
  407. SCH_REFERENCE_LIST components;
  408. GetParent()->GetCurrentSheet().GetComponents( components );
  409. for( unsigned i = 0; i < components.GetCount(); i++ )
  410. {
  411. SCH_REFERENCE component = components[i];
  412. if( component.GetLibPart()->GetLibId() == thisLibId
  413. && component.GetRef() == thisRef
  414. && component.GetUnit() != thisUnit )
  415. {
  416. SCH_COMPONENT* otherUnit = component.GetComp();
  417. GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
  418. otherUnit->GetField( VALUE )->SetText( m_FieldsBuf[VALUE].GetText() );
  419. otherUnit->GetField( FOOTPRINT )->SetText( m_FieldsBuf[FOOTPRINT].GetText() );
  420. otherUnit->GetField( DATASHEET )->SetText( m_FieldsBuf[DATASHEET].GetText() );
  421. }
  422. }
  423. }
  424. GetParent()->OnModify();
  425. GetParent()->GetScreen()->TestDanglingEnds();
  426. EndQuasiModal( wxID_OK );
  427. }
  428. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::addFieldButtonHandler( wxCommandEvent& event )
  429. {
  430. // in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
  431. // screen contents.
  432. if( !copyPanelToSelectedField() )
  433. return;
  434. unsigned fieldNdx = m_FieldsBuf.size();
  435. SCH_FIELD blank( wxPoint(), fieldNdx, m_cmp );
  436. blank.SetTextAngle( m_FieldsBuf[REFERENCE].GetTextAngle() );
  437. m_FieldsBuf.push_back( blank );
  438. m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
  439. m_skipCopyFromPanel = true;
  440. setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
  441. setSelectedFieldNdx( fieldNdx );
  442. m_skipCopyFromPanel = false;
  443. }
  444. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEvent& event )
  445. {
  446. unsigned fieldNdx = getSelectedFieldNdx();
  447. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  448. return;
  449. if( fieldNdx < MANDATORY_FIELDS )
  450. {
  451. wxBell();
  452. return;
  453. }
  454. m_skipCopyFromPanel = true;
  455. m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
  456. fieldListCtrl->DeleteItem( fieldNdx );
  457. if( fieldNdx >= m_FieldsBuf.size() )
  458. --fieldNdx;
  459. updateDisplay();
  460. setSelectedFieldNdx( fieldNdx );
  461. m_skipCopyFromPanel = false;
  462. }
  463. static wxString resolveUriByEnvVars( const wxString& aUri )
  464. {
  465. // URL-like URI: return as is.
  466. wxURL url( aUri );
  467. if( url.GetError() == wxURL_NOERR )
  468. {
  469. return aUri;
  470. }
  471. // Otherwise, the path points to a local file. Resolve environment
  472. // variables if any.
  473. return ExpandEnvVarSubstitutions( aUri );
  474. }
  475. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& event )
  476. {
  477. unsigned fieldNdx = getSelectedFieldNdx();
  478. if( fieldNdx == DATASHEET )
  479. {
  480. wxString datasheet_uri = fieldValueTextCtrl->GetValue();
  481. datasheet_uri = resolveUriByEnvVars( datasheet_uri );
  482. GetAssociatedDocument( this, datasheet_uri );
  483. }
  484. else if( fieldNdx == FOOTPRINT )
  485. {
  486. // pick a footprint using the footprint picker.
  487. wxString fpid;
  488. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, this );
  489. if( frame->ShowModal( &fpid, this ) )
  490. {
  491. // DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); )
  492. fieldValueTextCtrl->SetValue( fpid );
  493. setRowItem( fieldNdx, m_FieldsBuf[fieldNdx].GetName( false ), fpid );
  494. }
  495. frame->Destroy();
  496. }
  497. }
  498. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& event )
  499. {
  500. unsigned fieldNdx = getSelectedFieldNdx();
  501. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  502. return;
  503. if( fieldNdx <= MANDATORY_FIELDS )
  504. {
  505. wxBell();
  506. return;
  507. }
  508. if( !copyPanelToSelectedField() )
  509. return;
  510. // swap the fieldNdx field with the one before it, in both the vector
  511. // and in the fieldListCtrl
  512. SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
  513. DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n",
  514. TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); )
  515. m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
  516. setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
  517. m_FieldsBuf[fieldNdx] = tmp;
  518. setRowItem( fieldNdx, tmp );
  519. updateDisplay();
  520. m_skipCopyFromPanel = true;
  521. setSelectedFieldNdx( fieldNdx - 1 );
  522. m_skipCopyFromPanel = false;
  523. }
  524. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveDownButtonHandler( wxCommandEvent& event )
  525. {
  526. unsigned fieldNdx = getSelectedFieldNdx();
  527. // Ensure there is at least one field after this one
  528. if( fieldNdx >= ( m_FieldsBuf.size() - 1 ) )
  529. {
  530. return;
  531. }
  532. // The first field which can be moved up is the second user field
  533. // so any field which id < MANDATORY_FIELDS cannot be moved down
  534. if( fieldNdx < MANDATORY_FIELDS )
  535. return;
  536. if( !copyPanelToSelectedField() )
  537. return;
  538. // swap the fieldNdx field with the one before it, in both the vector
  539. // and in the fieldListCtrl
  540. SCH_FIELD tmp = m_FieldsBuf[fieldNdx + 1];
  541. m_FieldsBuf[fieldNdx + 1] = m_FieldsBuf[fieldNdx];
  542. setRowItem( fieldNdx + 1, m_FieldsBuf[fieldNdx] );
  543. m_FieldsBuf[fieldNdx + 1].SetId( fieldNdx + 1 );
  544. m_FieldsBuf[fieldNdx] = tmp;
  545. setRowItem( fieldNdx, tmp );
  546. m_FieldsBuf[fieldNdx].SetId( fieldNdx );
  547. updateDisplay( );
  548. m_skipCopyFromPanel = true;
  549. setSelectedFieldNdx( fieldNdx + 1 );
  550. m_skipCopyFromPanel = false;
  551. }
  552. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx )
  553. {
  554. /* deselect old selection, but I think this is done by single selection
  555. * flag within fieldListCtrl.
  556. * fieldListCtrl->SetItemState( s_SelectedRow, 0,
  557. * wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
  558. */
  559. if( aFieldNdx >= (int) m_FieldsBuf.size() )
  560. aFieldNdx = m_FieldsBuf.size() - 1;
  561. if( aFieldNdx < 0 )
  562. aFieldNdx = 0;
  563. fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
  564. fieldListCtrl->EnsureVisible( aFieldNdx );
  565. s_SelectedRow = aFieldNdx;
  566. }
  567. int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx()
  568. {
  569. return s_SelectedRow;
  570. }
  571. SCH_FIELD* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::findField( const wxString& aFieldName )
  572. {
  573. for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
  574. {
  575. if( aFieldName == m_FieldsBuf[i].GetName( false ) )
  576. return &m_FieldsBuf[i];
  577. }
  578. return NULL;
  579. }
  580. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent )
  581. {
  582. m_cmp = aComponent;
  583. /* We have 3 component related field lists to be aware of: 1) UI
  584. presentation, 2) fields in component ram copy, and 3) fields recorded
  585. with component on disk. m_FieldsBuf is the list of UI fields, and this
  586. list is not the same as the list which is in the component, which is
  587. also not the same as the list on disk. All 3 lists are potentially
  588. different. In the UI we choose to preserve the order of the first
  589. MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
  590. the template fieldnames in the exact same order as the template
  591. fieldname editor shows them. Then we append any user defined fieldnames
  592. which came from the component.
  593. */
  594. m_part = GetParent()->GetLibPart( m_cmp->GetLibId(), true );
  595. #if 0 && defined(DEBUG)
  596. for( int i = 0; i<aComponent->GetFieldCount(); ++i )
  597. {
  598. printf( "Orig[%d] (x=%d, y=%d)\n", i,
  599. aComponent->m_Fields[i].GetTextPos().x,
  600. aComponent->m_Fields[i].GetTextPos().y );
  601. }
  602. #endif
  603. // When this code was written, all field constructors ensure that the fixed fields
  604. // are all present within a component. So we can knowingly copy them over
  605. // in the normal order. Copy only the fixed fields at first.
  606. // Please do not break the field constructors.
  607. m_FieldsBuf.clear();
  608. for( int i=0; i<MANDATORY_FIELDS; ++i )
  609. {
  610. m_FieldsBuf.push_back( aComponent->m_Fields[i] );
  611. // make the editable field position relative to the component
  612. m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
  613. // Ensure the Field name reflects the default name, even if the
  614. // local has changed since schematic was read
  615. m_FieldsBuf[i].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
  616. }
  617. // Add template fieldnames:
  618. // Now copy in the template fields, in the order that they are present in the
  619. // template field editor UI.
  620. const TEMPLATE_FIELDNAMES& tfnames = GetParent()->GetTemplateFieldNames();
  621. for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
  622. {
  623. // add a new field unconditionally to the UI only
  624. SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, m_cmp, it->m_Name );
  625. // See if field by same name already exists in component.
  626. SCH_FIELD* schField = aComponent->FindField( it->m_Name );
  627. // If the field does not already exist in the component, then we
  628. // use defaults from the template fieldname, otherwise the original
  629. // values from the component will be set.
  630. if( !schField )
  631. {
  632. if( !it->m_Visible )
  633. fld.SetVisible( false );
  634. else
  635. fld.SetVisible( true );
  636. fld.SetText( it->m_Value ); // empty? ok too.
  637. }
  638. else
  639. {
  640. fld = *schField;
  641. // make the editable field position relative to the component
  642. fld.Offset( -m_cmp->m_Pos );
  643. }
  644. m_FieldsBuf.push_back( fld );
  645. }
  646. // Lastly, append any original fields from the component which were not added
  647. // from the set of fixed fields nor from the set of template fields.
  648. for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
  649. {
  650. SCH_FIELD* cmp = &aComponent->m_Fields[i];
  651. SCH_FIELD* buf = findField( cmp->GetName( false ) );
  652. if( !buf )
  653. {
  654. int newNdx = m_FieldsBuf.size();
  655. m_FieldsBuf.push_back( *cmp );
  656. // make the editable field position relative to the component
  657. m_FieldsBuf[newNdx].Offset( -m_cmp->m_Pos );
  658. }
  659. }
  660. #if 0 && defined(DEBUG)
  661. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  662. {
  663. printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
  664. m_FieldsBuf[i].m_Pos.y, TO_UTF8(m_FieldsBuf[i].GetName( false ) ) );
  665. }
  666. #endif
  667. m_FieldsBuf[REFERENCE].SetText( m_cmp->GetRef( &GetParent()->GetCurrentSheet() ) );
  668. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  669. {
  670. setRowItem( i, m_FieldsBuf[i] );
  671. }
  672. #if 0 && defined(DEBUG)
  673. for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
  674. {
  675. printf( "after[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
  676. m_FieldsBuf[i].m_Pos.y );
  677. }
  678. #endif
  679. copyOptionsToPanel();
  680. // disable some options inside the edit dialog
  681. // which can cause problems while dragging
  682. if( m_cmp->IsDragging() )
  683. {
  684. orientationRadioBox->Disable();
  685. mirrorRadioBox->Disable();
  686. chipnameTextCtrl->Disable();
  687. }
  688. // put focus on the list ctrl
  689. fieldListCtrl->SetFocus();
  690. // resume editing at the last row edited, last time dialog was up.
  691. setSelectedFieldNdx( s_SelectedRow );
  692. copySelectedFieldToPanel();
  693. }
  694. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue )
  695. {
  696. wxASSERT( aFieldNdx >= 0 );
  697. // insert blanks if aFieldNdx is referencing a "yet to be defined" row
  698. while( aFieldNdx >= fieldListCtrl->GetItemCount() )
  699. {
  700. long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
  701. wxASSERT( ndx >= 0 );
  702. fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
  703. }
  704. fieldListCtrl->SetItem( aFieldNdx, 0, aName );
  705. fieldListCtrl->SetItem( aFieldNdx, 1, aValue );
  706. // recompute the column widths here, after setting texts
  707. fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  708. fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
  709. }
  710. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
  711. {
  712. wxCHECK_RET( m_cmp != NULL, wxT( "Component pointer not initialized." ) );
  713. unsigned fieldNdx = getSelectedFieldNdx();
  714. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  715. return;
  716. SCH_FIELD& field = m_FieldsBuf[fieldNdx];
  717. showCheckBox->SetValue( field.IsVisible() );
  718. rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
  719. int style = 0;
  720. if( field.IsItalic() )
  721. style = 1;
  722. if( field.IsBold() )
  723. style |= 2;
  724. m_StyleRadioBox->SetSelection( style );
  725. // Select the right text justification
  726. if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
  727. m_FieldHJustifyCtrl->SetSelection( 0 );
  728. else if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
  729. m_FieldHJustifyCtrl->SetSelection( 2 );
  730. else
  731. m_FieldHJustifyCtrl->SetSelection( 1 );
  732. if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
  733. m_FieldVJustifyCtrl->SetSelection( 0 );
  734. else if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
  735. m_FieldVJustifyCtrl->SetSelection( 2 );
  736. else
  737. m_FieldVJustifyCtrl->SetSelection( 1 );
  738. fieldNameTextCtrl->SetValue( field.GetName( false ) );
  739. // the names of the fixed fields are not editable, others are.
  740. fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
  741. fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
  742. // only user defined fields may be moved, and not the top most user defined
  743. // field since it would be moving up into the fixed fields, > not >=
  744. moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
  745. moveDownButton->Enable( ( fieldNdx >= MANDATORY_FIELDS ) && ( fieldNdx < ( m_FieldsBuf.size() - 1 ) ) );
  746. // may only delete user defined fields
  747. deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
  748. fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( false, field.GetId() ) );
  749. fieldValueTextCtrl->SetValue( field.GetText() );
  750. m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
  751. if( fieldNdx == DATASHEET )
  752. {
  753. m_show_datasheet_button->SetLabel( _( "Show Datasheet" ) );
  754. m_show_datasheet_button->SetToolTip(
  755. _("If your datasheet is given as an http:// link,"
  756. " then pressing this button should bring it up in your webbrowser.") );
  757. }
  758. else if( fieldNdx == FOOTPRINT )
  759. {
  760. m_show_datasheet_button->SetLabel( _( "Browse Footprints" ) );
  761. m_show_datasheet_button->SetToolTip(
  762. _("Open the footprint browser to choose a footprint and assign it.") );
  763. }
  764. else
  765. {
  766. m_show_datasheet_button->SetLabel( wxEmptyString );
  767. m_show_datasheet_button->SetToolTip(
  768. _("Used only for fields Footprint and Datasheet.") );
  769. }
  770. // For power symbols, the value is NOR editable, because value and pin
  771. // name must be same and can be edited only in library editor
  772. if( fieldNdx == VALUE && m_part && m_part->IsPower() )
  773. fieldValueTextCtrl->Enable( false );
  774. else
  775. fieldValueTextCtrl->Enable( true );
  776. textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetTextWidth() ) );
  777. wxPoint coord = field.GetTextPos();
  778. wxPoint zero = -m_cmp->m_Pos; // relative zero
  779. // If the field value is empty and the position is at relative zero, we
  780. // set the initial position as a small offset from the ref field, and
  781. // orient it the same as the ref field. That is likely to put it at least
  782. // close to the desired position.
  783. if( coord == zero && field.GetText().IsEmpty() )
  784. {
  785. rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].GetTextAngle() == TEXT_ANGLE_VERT );
  786. coord.x = m_FieldsBuf[REFERENCE].GetTextPos().x
  787. + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
  788. coord.y = m_FieldsBuf[REFERENCE].GetTextPos().y
  789. + ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
  790. // coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
  791. // That is ok, we basically don't want all the new empty fields on
  792. // top of each other.
  793. }
  794. wxString coordText = StringFromValue( g_UserUnit, coord.x );
  795. posXTextCtrl->SetValue( coordText );
  796. coordText = StringFromValue( g_UserUnit, coord.y );
  797. posYTextCtrl->SetValue( coordText );
  798. }
  799. bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField()
  800. {
  801. unsigned fieldNdx = getSelectedFieldNdx();
  802. if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
  803. return true;
  804. // Check for illegal field text.
  805. if( fieldValueTextCtrl->GetValidator()
  806. && !fieldValueTextCtrl->GetValidator()->Validate( this ) )
  807. return false;
  808. SCH_FIELD& field = m_FieldsBuf[fieldNdx];
  809. field.SetVisible( showCheckBox->GetValue() );
  810. if( rotateCheckBox->GetValue() )
  811. field.SetTextAngle( TEXT_ANGLE_VERT );
  812. else
  813. field.SetTextAngle( TEXT_ANGLE_HORIZ );
  814. rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
  815. // Copy the text justification
  816. static const EDA_TEXT_HJUSTIFY_T hjustify[] = {
  817. GR_TEXT_HJUSTIFY_LEFT,
  818. GR_TEXT_HJUSTIFY_CENTER,
  819. GR_TEXT_HJUSTIFY_RIGHT
  820. };
  821. static const EDA_TEXT_VJUSTIFY_T vjustify[] = {
  822. GR_TEXT_VJUSTIFY_TOP,
  823. GR_TEXT_VJUSTIFY_CENTER,
  824. GR_TEXT_VJUSTIFY_BOTTOM
  825. };
  826. field.SetHorizJustify( hjustify[m_FieldHJustifyCtrl->GetSelection()] );
  827. field.SetVertJustify( vjustify[m_FieldVJustifyCtrl->GetSelection()] );
  828. field.SetName( fieldNameTextCtrl->GetValue() );
  829. /* Void fields texts for REFERENCE and VALUE (value is the name of the
  830. * component in lib ! ) are not allowed
  831. * change them only for a new non void value
  832. * When void, usually netlists are broken
  833. */
  834. if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
  835. field.SetText( fieldValueTextCtrl->GetValue() );
  836. setRowItem( fieldNdx, field ); // update fieldListCtrl
  837. int tmp = EDA_GRAPHIC_TEXT_CTRL::ParseSize( textSizeTextCtrl->GetValue(), g_UserUnit );
  838. field.SetTextSize( wxSize( tmp, tmp ) );
  839. int style = m_StyleRadioBox->GetSelection();
  840. field.SetItalic( (style & 1 ) != 0 );
  841. field.SetBold( (style & 2 ) != 0 );
  842. wxPoint pos;
  843. pos.x = ValueFromString( g_UserUnit, posXTextCtrl->GetValue() );
  844. pos.y = ValueFromString( g_UserUnit, posYTextCtrl->GetValue() );
  845. field.SetTextPos( pos );
  846. return true;
  847. }
  848. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
  849. {
  850. // Remove non existing choices (choiceCount must be <= number for parts)
  851. int unitcount = m_part ? m_part->GetUnitCount() : 1;
  852. if( unitcount < 1 )
  853. unitcount = 1;
  854. unitChoice->Clear();
  855. for( int ii = 1; ii <= unitcount; ii++ )
  856. {
  857. unitChoice->Append( LIB_PART::SubReference( ii, false ) );
  858. }
  859. // For symbols with multiple parts per package, set the unit selection
  860. if( m_cmp->GetUnit() <= (int)unitChoice->GetCount() )
  861. unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
  862. // Disable unit selection if only one unit exists:
  863. if( m_cmp->GetUnitCount() <= 1 )
  864. {
  865. unitChoice->Enable( false );
  866. unitsInterchageableLabel->Show( false );
  867. unitsInterchageableText->Show( false );
  868. }
  869. else
  870. {
  871. // Show the "Units are not interchangeable" message option?
  872. if( !m_part || !m_part->UnitsLocked() )
  873. unitsInterchageableLabel->SetLabel( _( "Yes" ) );
  874. else
  875. unitsInterchageableLabel->SetLabel( _( "No" ) );
  876. }
  877. int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
  878. if( orientation == CMP_ORIENT_90 )
  879. orientationRadioBox->SetSelection( 1 );
  880. else if( orientation == CMP_ORIENT_180 )
  881. orientationRadioBox->SetSelection( 2 );
  882. else if( orientation == CMP_ORIENT_270 )
  883. orientationRadioBox->SetSelection( 3 );
  884. else
  885. orientationRadioBox->SetSelection( 0 );
  886. int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
  887. if( mirror == CMP_MIRROR_X )
  888. {
  889. mirrorRadioBox->SetSelection( 1 );
  890. DBG( printf( "mirror=X,1\n" ); )
  891. }
  892. else if( mirror == CMP_MIRROR_Y )
  893. {
  894. mirrorRadioBox->SetSelection( 2 );
  895. DBG( printf( "mirror=Y,2\n" ); )
  896. }
  897. else
  898. mirrorRadioBox->SetSelection( 0 );
  899. // Activate/Desactivate the normal/convert option ? (activated only if
  900. // the component has more than one shape)
  901. if( m_cmp->GetConvert() > 1 )
  902. convertCheckBox->SetValue( true );
  903. if( m_part == NULL || !m_part->HasConversion() )
  904. convertCheckBox->Enable( false );
  905. // Set the component's library name.
  906. chipnameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
  907. // Set the component's unique ID time stamp.
  908. m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
  909. (unsigned long) m_cmp->GetTimeStamp() ) );
  910. }
  911. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
  912. {
  913. if( !m_cmp )
  914. return;
  915. if( LIB_PART* part = GetParent()->GetLibPart( m_cmp->GetLibId() ) )
  916. {
  917. // save old cmp in undo list if not already in edit, or moving ...
  918. if( m_cmp->GetFlags() == 0 )
  919. GetParent()->SaveCopyInUndoList( m_cmp, UR_CHANGED );
  920. INSTALL_UNBUFFERED_DC( dc, GetParent()->GetCanvas() );
  921. m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );
  922. // Initialize fixed field values to default values found in library
  923. // Note: the field texts are not modified because they are set in schematic,
  924. // the text from libraries is most of time a dummy text
  925. // Only VALUE, REFERENCE , FOOTPRINT and DATASHEET are re-initialized
  926. LIB_FIELD& refField = part->GetReferenceField();
  927. m_cmp->GetField( REFERENCE )->ImportValues( refField );
  928. m_cmp->GetField( REFERENCE )->SetTextPos( refField.GetTextPos() + m_cmp->m_Pos );
  929. LIB_FIELD& valField = part->GetValueField();
  930. m_cmp->GetField( VALUE )->ImportValues( valField );
  931. m_cmp->GetField( VALUE )->SetTextPos( valField.GetTextPos() + m_cmp->m_Pos );
  932. LIB_FIELD* field = part->GetField(FOOTPRINT);
  933. if( field && m_cmp->GetField( FOOTPRINT ) )
  934. {
  935. m_cmp->GetField( FOOTPRINT )->ImportValues( *field );
  936. m_cmp->GetField( FOOTPRINT )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
  937. }
  938. field = part->GetField(DATASHEET);
  939. if( field && m_cmp->GetField( DATASHEET ) )
  940. {
  941. m_cmp->GetField( DATASHEET )->ImportValues( *field );
  942. m_cmp->GetField( DATASHEET )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
  943. }
  944. m_cmp->SetOrientation( CMP_NORMAL );
  945. GetParent()->OnModify();
  946. m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
  947. EndQuasiModal( wxID_OK );
  948. }
  949. }
  950. void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFields( wxCommandEvent& event )
  951. {
  952. SCH_COMPONENT copy( *m_cmp );
  953. std::list<SCH_COMPONENT*> components;
  954. components.push_back( &copy );
  955. InvokeDialogUpdateFields( GetParent(), components, false );
  956. // Copy fields from the modified component copy to the dialog buffer
  957. m_FieldsBuf.clear();
  958. for( int i = 0; i < copy.GetFieldCount(); ++i )
  959. {
  960. copy.m_Fields[i].SetParent( m_cmp );
  961. m_FieldsBuf.push_back( copy.m_Fields[i] );
  962. m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
  963. }
  964. // Update the selected field as well
  965. copySelectedFieldToPanel();
  966. updateDisplay();
  967. }