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.

557 lines
17 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
14 years ago
14 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
* 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
14 years ago
14 years ago
  1. /**
  2. * @file dialog_edit_module_for_Modedit.cpp
  3. *
  4. * @brief Dialog for editing a module properties in module editor (modedit)
  5. */
  6. /*
  7. * This program source code file is part of KiCad, a free EDA CAD application.
  8. *
  9. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  10. * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
  11. * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
  12. * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, you may find one here:
  26. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  27. * or you may search the http://www.gnu.org website for the version 2 license,
  28. * or you may write to the Free Software Foundation, Inc.,
  29. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  30. */
  31. #include <fctsys.h>
  32. #include <class_drawpanel.h>
  33. #include <confirm.h>
  34. #include <pcbnew.h>
  35. #include <kiface_i.h>
  36. #include <gestfich.h>
  37. #include <3d_viewer.h>
  38. #include <wxPcbStruct.h>
  39. #include <base_units.h>
  40. #include <macros.h>
  41. #include <validators.h>
  42. #include <kicad_string.h>
  43. #include <class_module.h>
  44. #include <class_text_mod.h>
  45. #include <module_editor_frame.h>
  46. #include <dialog_edit_module_for_Modedit.h>
  47. #include <wildcards_and_files_ext.h>
  48. #include <pgm_base.h>
  49. #include "3d_cache/dialogs/panel_prev_model.h"
  50. #include "3d_cache/dialogs/3d_cache_dialogs.h"
  51. #include "3d_cache/3d_cache.h"
  52. #include "3d_cache/3d_filename_resolver.h"
  53. size_t DIALOG_MODULE_MODULE_EDITOR::m_page = 0; // remember the last open page during session
  54. DIALOG_MODULE_MODULE_EDITOR::DIALOG_MODULE_MODULE_EDITOR( FOOTPRINT_EDIT_FRAME* aParent,
  55. MODULE* aModule ) :
  56. DIALOG_MODULE_MODULE_EDITOR_BASE( aParent )
  57. {
  58. m_parent = aParent;
  59. m_currentModule = aModule;
  60. // Give an icon
  61. wxIcon icon;
  62. icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
  63. SetIcon( icon );
  64. aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
  65. m_currentModuleCopy = new MODULE( *aModule );
  66. m_PreviewPane = new PANEL_PREV_3D( m_Panel3D,
  67. aParent->Prj().Get3DCacheManager(),
  68. m_currentModuleCopy,
  69. &m_shapes3D_list );
  70. bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
  71. m_FootprintNameCtrl->SetValidator( FILE_NAME_CHAR_VALIDATOR() );
  72. initModeditProperties();
  73. m_NoteBook->SetSelection( m_page );
  74. m_sdbSizerStdButtonsOK->SetDefault();
  75. Layout();
  76. FixOSXCancelButtonIssue();
  77. }
  78. DIALOG_MODULE_MODULE_EDITOR::~DIALOG_MODULE_MODULE_EDITOR()
  79. {
  80. m_shapes3D_list.clear();
  81. // free the memory used by all models, otherwise models which were
  82. // browsed but not used would consume memory
  83. Prj().Get3DCacheManager()->FlushCache( false );
  84. // the GL canvas has to be visible before it is destroyed
  85. m_page = m_NoteBook->GetSelection();
  86. m_NoteBook->SetSelection( 1 );
  87. delete m_referenceCopy;
  88. m_referenceCopy = NULL; // just in case, to avoid double-free
  89. delete m_valueCopy;
  90. m_valueCopy = NULL;
  91. delete m_PreviewPane;
  92. m_PreviewPane = NULL; // just in case, to avoid double-free
  93. // this is already deleted by the board used on preview pane so
  94. // no need to delete here
  95. // delete m_currentModuleCopy;
  96. // m_currentModuleCopy = NULL;
  97. }
  98. void DIALOG_MODULE_MODULE_EDITOR::initModeditProperties()
  99. {
  100. SetFocus();
  101. // Display the default path, given by environment variable KISYS3DMOD
  102. wxString default_path;
  103. wxGetEnv( KISYS3DMOD, &default_path );
  104. #ifdef __WINDOWS__
  105. default_path.Replace( wxT( "/" ), wxT( "\\" ) );
  106. #endif
  107. m_lastSelected3DShapeIndex = -1;
  108. // Init 3D shape list
  109. m_3D_ShapeNameListBox->Clear();
  110. std::list<S3D_INFO>::iterator sM = m_currentModule->Models().begin();
  111. std::list<S3D_INFO>::iterator eM = m_currentModule->Models().end();
  112. m_shapes3D_list.clear();
  113. wxString origPath;
  114. wxString alias;
  115. wxString shortPath;
  116. S3D_FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
  117. while( sM != eM )
  118. {
  119. m_shapes3D_list.push_back( *sM );
  120. origPath = sM->m_Filename;
  121. if( res && res->SplitAlias( origPath, alias, shortPath ) )
  122. {
  123. origPath = alias;
  124. origPath.append( wxT( ":" ) );
  125. origPath.append( shortPath );
  126. }
  127. m_3D_ShapeNameListBox->Append( origPath );
  128. ++sM;
  129. }
  130. m_DocCtrl->SetValue( m_currentModule->GetDescription() );
  131. m_KeywordCtrl->SetValue( m_currentModule->GetKeywords() );
  132. m_referenceCopy = new TEXTE_MODULE( m_currentModule->Reference() );
  133. m_referenceCopy->SetParent( m_currentModule );
  134. m_valueCopy = new TEXTE_MODULE( m_currentModule->Value() );
  135. m_valueCopy->SetParent( m_currentModule );
  136. m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() );
  137. m_ValueCtrl->SetValue( m_valueCopy->GetText() );
  138. m_FootprintNameCtrl->SetValue( m_currentModule->GetFPID().Format() );
  139. m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD components" ) );
  140. m_AttributsCtrl->SetItemToolTip( 1,
  141. _( "Use this attribute for SMD components.\n"
  142. "Only components with this option are put in the footprint position list file" ) );
  143. m_AttributsCtrl->SetItemToolTip( 2,
  144. _( "Use this attribute for \"virtual\" components drawn on board\n"
  145. "like an edge connector (old ISA PC bus for instance)" ) );
  146. // Controls on right side of the dialog
  147. switch( m_currentModule->GetAttributes() & 255 )
  148. {
  149. case 0:
  150. m_AttributsCtrl->SetSelection( 0 );
  151. break;
  152. case MOD_CMS:
  153. m_AttributsCtrl->SetSelection( 1 );
  154. break;
  155. case MOD_VIRTUAL:
  156. m_AttributsCtrl->SetSelection( 2 );
  157. break;
  158. default:
  159. m_AttributsCtrl->SetSelection( 0 );
  160. break;
  161. }
  162. m_AutoPlaceCtrl->SetSelection( (m_currentModule->IsLocked()) ? 1 : 0 );
  163. m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Enable hotkey move commands and Auto Placement" ) );
  164. m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Disable hotkey move commands and Auto Placement" ) );
  165. m_CostRot90Ctrl->SetValue( m_currentModule->GetPlacementCost90() );
  166. m_CostRot180Ctrl->SetValue( m_currentModule->GetPlacementCost180() );
  167. // Initialize dialog relative to masks clearances
  168. m_NetClearanceUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  169. m_SolderMaskMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  170. m_SolderPasteMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  171. wxString msg;
  172. PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_currentModule->GetLocalClearance() );
  173. PutValueInLocalUnits( *m_SolderMaskMarginCtrl, m_currentModule->GetLocalSolderMaskMargin() );
  174. // These 2 parameters are usually < 0, so prepare entering a negative value, if current is 0
  175. PutValueInLocalUnits( *m_SolderPasteMarginCtrl, m_currentModule->GetLocalSolderPasteMargin() );
  176. if( m_currentModule->GetLocalSolderPasteMargin() == 0 )
  177. m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
  178. if( m_currentModule->GetLocalSolderPasteMarginRatio() == 0.0 )
  179. msg.Printf( wxT( "-%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  180. else
  181. msg.Printf( wxT( "%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  182. m_SolderPasteMarginRatioCtrl->SetValue( msg );
  183. // Add solder paste margin ration in per cent
  184. // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
  185. msg.Printf( wxT( "%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  186. if( m_currentModule->GetLocalSolderPasteMarginRatio() == 0.0 &&
  187. msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
  188. m_SolderPasteMarginRatioCtrl->SetValue( wxT( "-" ) + msg );
  189. else
  190. m_SolderPasteMarginRatioCtrl->SetValue( msg );
  191. // if m_3D_ShapeNameListBox is not empty, preselect first 3D shape
  192. if( m_3D_ShapeNameListBox->GetCount() > 0 )
  193. {
  194. m_lastSelected3DShapeIndex = 0;
  195. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  196. if( m_PreviewPane )
  197. m_PreviewPane->SetModelDataIdx( m_lastSelected3DShapeIndex, true );
  198. }
  199. else
  200. {
  201. if( m_PreviewPane )
  202. m_PreviewPane->ResetModelData( true );
  203. }
  204. // We have modified the UI, so call Fit() for m_Panel3D
  205. // to be sure the m_Panel3D sizers are initialized before opening the dialog
  206. m_Panel3D->GetSizer()->Fit( m_Panel3D );
  207. }
  208. void DIALOG_MODULE_MODULE_EDITOR::On3DShapeNameSelected(wxCommandEvent& event)
  209. {
  210. m_lastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetSelection();
  211. if( m_lastSelected3DShapeIndex < 0 ) // happens under wxGTK when deleting an item in m_3D_ShapeNameListBox wxListBox
  212. {
  213. if( m_PreviewPane )
  214. m_PreviewPane->ResetModelData();
  215. return;
  216. }
  217. if( m_lastSelected3DShapeIndex >= (int)m_shapes3D_list.size() )
  218. {
  219. wxMessageBox( wxT( "On3DShapeNameSelected() error" ) );
  220. m_lastSelected3DShapeIndex = -1;
  221. if( m_PreviewPane )
  222. m_PreviewPane->ResetModelData();
  223. return;
  224. }
  225. m_PreviewPane->SetModelDataIdx( m_lastSelected3DShapeIndex );
  226. }
  227. void DIALOG_MODULE_MODULE_EDITOR::Remove3DShape(wxCommandEvent& event)
  228. {
  229. int ii = m_3D_ShapeNameListBox->GetSelection();
  230. if( ii < 0 )
  231. {
  232. if( m_PreviewPane )
  233. m_PreviewPane->ResetModelData( true );
  234. return;
  235. }
  236. m_shapes3D_list.erase( m_shapes3D_list.begin() + ii );
  237. m_3D_ShapeNameListBox->Delete( ii );
  238. if( m_3D_ShapeNameListBox->GetCount() > 0 )
  239. {
  240. if( ii > 0 )
  241. m_lastSelected3DShapeIndex = ii - 1;
  242. else
  243. m_lastSelected3DShapeIndex = 0;
  244. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  245. if( m_PreviewPane )
  246. m_PreviewPane->SetModelDataIdx( m_lastSelected3DShapeIndex, true );
  247. }
  248. else
  249. {
  250. if( m_PreviewPane )
  251. m_PreviewPane->ResetModelData( true );
  252. }
  253. return;
  254. }
  255. void DIALOG_MODULE_MODULE_EDITOR::Edit3DShapeFileName()
  256. {
  257. int idx = m_3D_ShapeNameListBox->GetSelection();
  258. if( idx < 0 )
  259. return;
  260. // Edit filename
  261. wxString filename = m_3D_ShapeNameListBox->GetStringSelection();
  262. wxTextEntryDialog dlg( this, wxEmptyString, wxEmptyString, filename );
  263. bool hasAlias;
  264. S3D_FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
  265. if( dlg.ShowModal() != wxID_OK )
  266. return;
  267. filename = dlg.GetValue();
  268. if( filename.empty() )
  269. return;
  270. if( !res->ValidateFileName( filename, hasAlias ) )
  271. {
  272. wxString msg = _( "Invalid filename: " );
  273. msg.append( filename );
  274. wxMessageBox( msg, _( "Edit 3D file name" ) );
  275. return;
  276. }
  277. m_3D_ShapeNameListBox->SetString( idx, filename );
  278. // if the user has specified an alias in the name then prepend ':'
  279. if( hasAlias )
  280. filename.insert( 0, wxT( ":" ) );
  281. #ifdef __WINDOWS__
  282. // In Kicad files, filenames and paths are stored using Unix notation
  283. filename.Replace( wxT( "\\" ), wxT( "/" ) );
  284. #endif
  285. m_shapes3D_list[idx].m_Filename = filename;
  286. // This assumes that the index didn't change and will just update the filename
  287. if( m_PreviewPane )
  288. m_PreviewPane->UpdateModelName( filename );
  289. return;
  290. }
  291. void DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile()
  292. {
  293. PROJECT& prj = Prj();
  294. S3D_INFO model;
  295. wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
  296. wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
  297. int filter = 0;
  298. if( !sidx.empty() )
  299. {
  300. long tmp;
  301. sidx.ToLong( &tmp );
  302. if( tmp > 0 && tmp <= 0x7FFFFFFF )
  303. filter = (int) tmp;
  304. }
  305. if( !S3D::Select3DModel( m_PreviewPane, Prj().Get3DCacheManager(),
  306. initialpath, filter, &model ) || model.m_Filename.empty() )
  307. {
  308. return;
  309. }
  310. prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
  311. sidx = wxString::Format( wxT( "%i" ), filter );
  312. prj.SetRString( PROJECT::VIEWER_3D_FILTER_INDEX, sidx );
  313. wxString origPath = model.m_Filename;
  314. wxString alias;
  315. wxString shortPath;
  316. S3D_FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
  317. if( res && res->SplitAlias( origPath, alias, shortPath ) )
  318. {
  319. origPath = alias;
  320. origPath.append( wxT( ":" ) );
  321. origPath.append( shortPath );
  322. }
  323. m_3D_ShapeNameListBox->Append( origPath );
  324. #ifdef __WINDOWS__
  325. // In Kicad files, filenames and paths are stored using Unix notation
  326. model.m_Filename.Replace( wxT( "\\" ), wxT( "/" ) );
  327. #endif
  328. m_shapes3D_list.push_back( model );
  329. m_lastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetCount() - 1;
  330. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  331. if( m_PreviewPane )
  332. m_PreviewPane->SetModelDataIdx( m_lastSelected3DShapeIndex, true );
  333. return;
  334. }
  335. void DIALOG_MODULE_MODULE_EDITOR::OnCancelClick( wxCommandEvent& event )
  336. {
  337. EndModal( -1 );
  338. }
  339. void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event )
  340. {
  341. wxString msg;
  342. // First, test for invalid chars in module name
  343. wxString footprintName = m_FootprintNameCtrl->GetValue();
  344. if( ! footprintName.IsEmpty() )
  345. {
  346. if( ! MODULE::IsLibNameValid( footprintName ) )
  347. {
  348. msg.Printf( _( "Error:\none of invalid chars <%s> found\nin <%s>" ),
  349. MODULE::StringLibNameInvalidChars( true ),
  350. GetChars( footprintName ) );
  351. DisplayError( NULL, msg );
  352. return;
  353. }
  354. }
  355. if( !m_PreviewPane->Validate( msg ) ) // Verify the validity of 3D parameters
  356. {
  357. DisplayError( NULL, msg );
  358. return;
  359. }
  360. m_parent->SaveCopyInUndoList( m_currentModule, UR_MODEDIT );
  361. m_currentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
  362. switch( m_AttributsCtrl->GetSelection() )
  363. {
  364. case 0:
  365. m_currentModule->SetAttributes( 0 );
  366. break;
  367. case 1:
  368. m_currentModule->SetAttributes( MOD_CMS );
  369. break;
  370. case 2:
  371. m_currentModule->SetAttributes( MOD_VIRTUAL );
  372. break;
  373. }
  374. m_currentModule->SetPlacementCost90( m_CostRot90Ctrl->GetValue() );
  375. m_currentModule->SetPlacementCost180( m_CostRot180Ctrl->GetValue() );
  376. m_currentModule->SetDescription( m_DocCtrl->GetValue() );
  377. m_currentModule->SetKeywords( m_KeywordCtrl->GetValue() );
  378. // Init footprint name in library
  379. if( ! footprintName.IsEmpty() )
  380. m_currentModule->SetFPID( FPID( footprintName ) );
  381. // Init Fields:
  382. TEXTE_MODULE& reference = m_currentModule->Reference();
  383. reference = *m_referenceCopy;
  384. TEXTE_MODULE& value = m_currentModule->Value();
  385. value = *m_valueCopy;
  386. // Initialize masks clearances
  387. m_currentModule->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) );
  388. m_currentModule->SetLocalSolderMaskMargin( ValueFromTextCtrl( *m_SolderMaskMarginCtrl ) );
  389. m_currentModule->SetLocalSolderPasteMargin( ValueFromTextCtrl( *m_SolderPasteMarginCtrl ) );
  390. double dtmp;
  391. msg = m_SolderPasteMarginRatioCtrl->GetValue();
  392. msg.ToDouble( &dtmp );
  393. // A -50% margin ratio means no paste on a pad, the ratio must be >= -50 %
  394. if( dtmp < -50.0 )
  395. dtmp = -50.0;
  396. // A margin ratio is always <= 0
  397. if( dtmp > 0.0 )
  398. dtmp = 0.0;
  399. m_currentModule->SetLocalSolderPasteMarginRatio( dtmp / 100 );
  400. std::list<S3D_INFO>* draw3D = &m_currentModule->Models();
  401. draw3D->clear();
  402. draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
  403. m_currentModule->CalculateBoundingBox();
  404. m_parent->OnModify();
  405. EndModal( 1 );
  406. }
  407. void DIALOG_MODULE_MODULE_EDITOR::OnEditReference(wxCommandEvent& event)
  408. {
  409. wxPoint tmp = m_parent->GetCrossHairPosition();
  410. m_parent->SetCrossHairPosition( m_referenceCopy->GetTextPosition() );
  411. m_parent->InstallTextModOptionsFrame( m_referenceCopy, NULL );
  412. m_parent->SetCrossHairPosition( tmp );
  413. m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() );
  414. }
  415. void DIALOG_MODULE_MODULE_EDITOR::OnEditValue(wxCommandEvent& event)
  416. {
  417. wxPoint tmp = m_parent->GetCrossHairPosition();
  418. m_parent->SetCrossHairPosition( m_valueCopy->GetTextPosition() );
  419. m_parent->InstallTextModOptionsFrame( m_valueCopy, NULL );
  420. m_parent->SetCrossHairPosition( tmp );
  421. m_ValueCtrl->SetValue( m_valueCopy->GetText() );
  422. }
  423. void DIALOG_MODULE_MODULE_EDITOR::Cfg3DPath( wxCommandEvent& event )
  424. {
  425. if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
  426. if( m_lastSelected3DShapeIndex >= 0 )
  427. if( m_PreviewPane )
  428. m_PreviewPane->SetModelDataIdx( m_lastSelected3DShapeIndex, true );
  429. }