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.

514 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
* 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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  10. * Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com
  11. * Copyright (C) 2008-2014 Wayne Stambaugh <stambaughw@verizon.net>
  12. * Copyright (C) 2004-2014 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_struct.h>
  38. #include <3d_viewer.h>
  39. #include <wxPcbStruct.h>
  40. #include <base_units.h>
  41. #include <macros.h>
  42. #include <validators.h>
  43. #include <kicad_string.h>
  44. #include <class_module.h>
  45. #include <class_text_mod.h>
  46. #include <module_editor_frame.h>
  47. #include <dialog_edit_module_for_Modedit.h>
  48. #include <wildcards_and_files_ext.h>
  49. DIALOG_MODULE_MODULE_EDITOR::DIALOG_MODULE_MODULE_EDITOR( FOOTPRINT_EDIT_FRAME* aParent,
  50. MODULE* aModule ) :
  51. DIALOG_MODULE_MODULE_EDITOR_BASE( aParent )
  52. {
  53. m_parent = aParent;
  54. m_currentModule = aModule;
  55. // Give an icon
  56. wxIcon icon;
  57. icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
  58. SetIcon( icon );
  59. m_FootprintNameCtrl->SetValidator( FOOTPRINT_NAME_VALIDATOR() );
  60. initModeditProperties();
  61. m_sdbSizerStdButtonsOK->SetDefault();
  62. GetSizer()->SetSizeHints( this );
  63. Centre();
  64. }
  65. DIALOG_MODULE_MODULE_EDITOR::~DIALOG_MODULE_MODULE_EDITOR()
  66. {
  67. for( unsigned ii = 0; ii < m_shapes3D_list.size(); ii++ )
  68. delete m_shapes3D_list[ii];
  69. m_shapes3D_list.clear();
  70. delete m_referenceCopy;
  71. delete m_valueCopy;
  72. delete m_3D_Scale;
  73. delete m_3D_Offset;
  74. delete m_3D_Rotation;
  75. }
  76. void DIALOG_MODULE_MODULE_EDITOR::initModeditProperties()
  77. {
  78. SetFocus();
  79. // Display the default path, given by environment variable KISYS3DMOD
  80. wxString default_path;
  81. wxGetEnv( KISYS3DMOD, &default_path );
  82. #ifdef __WINDOWS__
  83. default_path.Replace( wxT( "/" ), wxT( "\\" ) );
  84. #endif
  85. m_textCtrl3DDefaultPath->SetValue( default_path );
  86. m_lastSelected3DShapeIndex = -1;
  87. // Init 3D shape list
  88. S3D_MASTER* draw3D = m_currentModule->Models();
  89. while( draw3D )
  90. {
  91. if( !draw3D->GetShape3DName().IsEmpty() )
  92. {
  93. S3D_MASTER* draw3DCopy = new S3D_MASTER(NULL);
  94. draw3DCopy->Copy( draw3D );
  95. m_shapes3D_list.push_back( draw3DCopy );
  96. m_3D_ShapeNameListBox->Append( draw3DCopy->GetShape3DName() );
  97. }
  98. draw3D = (S3D_MASTER*) draw3D->Next();
  99. }
  100. m_DocCtrl->SetValue( m_currentModule->GetDescription() );
  101. m_KeywordCtrl->SetValue( m_currentModule->GetKeywords() );
  102. m_referenceCopy = new TEXTE_MODULE( NULL );
  103. m_valueCopy = new TEXTE_MODULE( NULL );
  104. m_referenceCopy->Copy( &m_currentModule->Reference() );
  105. m_valueCopy->Copy( &m_currentModule->Value() );
  106. m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() );
  107. m_ValueCtrl->SetValue( m_valueCopy->GetText() );
  108. m_ValueCtrl->SetValue( m_valueCopy->GetText() );
  109. m_FootprintNameCtrl->SetValue( m_currentModule->GetFPID().Format() );
  110. m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD components" ) );
  111. m_AttributsCtrl->SetItemToolTip( 1,
  112. _( "Use this attribute for SMD components.\nOnly components with this option are put in the footprint position list file" ) );
  113. m_AttributsCtrl->SetItemToolTip( 2,
  114. _( "Use this attribute for \"virtual\" components drawn on board (like a old ISA PC bus connector)" ) );
  115. // Controls on right side of the dialog
  116. switch( m_currentModule->GetAttributes() & 255 )
  117. {
  118. case 0:
  119. m_AttributsCtrl->SetSelection( 0 );
  120. break;
  121. case MOD_CMS:
  122. m_AttributsCtrl->SetSelection( 1 );
  123. break;
  124. case MOD_VIRTUAL:
  125. m_AttributsCtrl->SetSelection( 2 );
  126. break;
  127. default:
  128. m_AttributsCtrl->SetSelection( 0 );
  129. break;
  130. }
  131. m_AutoPlaceCtrl->SetSelection( (m_currentModule->IsLocked()) ? 1 : 0 );
  132. m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Enable hotkey move commands and Auto Placement" ) );
  133. m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Disable hotkey move commands and Auto Placement" ) );
  134. m_CostRot90Ctrl->SetValue( m_currentModule->GetPlacementCost90() );
  135. m_CostRot180Ctrl->SetValue( m_currentModule->GetPlacementCost180() );
  136. // Initialize 3D parameters
  137. m_3D_Scale = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeScale );
  138. m_3D_Offset = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeOffset );
  139. m_3D_Rotation = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeRotation );
  140. // Initialize dialog relative to masks clearances
  141. m_NetClearanceUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  142. m_SolderMaskMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  143. m_SolderPasteMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
  144. wxString msg;
  145. PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_currentModule->GetLocalClearance() );
  146. PutValueInLocalUnits( *m_SolderMaskMarginCtrl, m_currentModule->GetLocalSolderMaskMargin() );
  147. // These 2 parameters are usually < 0, so prepare entering a negative value, if current is 0
  148. PutValueInLocalUnits( *m_SolderPasteMarginCtrl, m_currentModule->GetLocalSolderPasteMargin() );
  149. if( m_currentModule->GetLocalSolderPasteMargin() == 0 )
  150. m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
  151. if( m_currentModule->GetLocalSolderPasteMarginRatio() == 0.0 )
  152. msg.Printf( wxT( "-%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  153. else
  154. msg.Printf( wxT( "%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  155. m_SolderPasteMarginRatioCtrl->SetValue( msg );
  156. // Add solder paste margin ration in per cent
  157. // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
  158. msg.Printf( wxT( "%f" ), m_currentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
  159. if( m_currentModule->GetLocalSolderPasteMarginRatio() == 0.0 &&
  160. msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
  161. m_SolderPasteMarginRatioCtrl->SetValue( wxT( "-" ) + msg );
  162. else
  163. m_SolderPasteMarginRatioCtrl->SetValue( msg );
  164. // if m_3D_ShapeNameListBox is not empty, preselect first 3D shape
  165. if( m_3D_ShapeNameListBox->GetCount() > 0 )
  166. {
  167. m_lastSelected3DShapeIndex = 0;
  168. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  169. Transfert3DValuesToDisplay( m_shapes3D_list[m_lastSelected3DShapeIndex] );
  170. }
  171. // We have modified the UI, so call Fit() for m_Panel3D
  172. // to be sure the m_Panel3D sizers are initialized before opening the dialog
  173. m_Panel3D->GetSizer()->Fit( m_Panel3D );
  174. }
  175. // Initialize 3D info displayed in dialog box from values in aStruct3DSource
  176. void DIALOG_MODULE_MODULE_EDITOR::Transfert3DValuesToDisplay( S3D_MASTER * aStruct3DSource )
  177. {
  178. if( aStruct3DSource )
  179. {
  180. m_3D_Scale->SetValue( aStruct3DSource->m_MatScale );
  181. m_3D_Offset->SetValue( aStruct3DSource->m_MatPosition );
  182. m_3D_Rotation->SetValue( aStruct3DSource->m_MatRotation );
  183. }
  184. else
  185. {
  186. S3DPOINT dummy_vertex( 1.0, 1.0, 1.0 );
  187. m_3D_Scale->SetValue( dummy_vertex );
  188. }
  189. }
  190. /** Copy 3D info displayed in dialog box to values in a item in m_shapes3D_list
  191. * @param aIndexSelection = item index in m_shapes3D_list
  192. */
  193. void DIALOG_MODULE_MODULE_EDITOR::TransfertDisplayTo3DValues( int aIndexSelection )
  194. {
  195. if( aIndexSelection >= (int)m_shapes3D_list.size() )
  196. return;
  197. S3D_MASTER * struct3DDest = m_shapes3D_list[aIndexSelection];
  198. struct3DDest->m_MatScale = m_3D_Scale->GetValue();
  199. struct3DDest->m_MatRotation = m_3D_Rotation->GetValue();
  200. struct3DDest->m_MatPosition = m_3D_Offset->GetValue();
  201. }
  202. void DIALOG_MODULE_MODULE_EDITOR::On3DShapeNameSelected(wxCommandEvent& event)
  203. {
  204. if( m_lastSelected3DShapeIndex >= 0 )
  205. TransfertDisplayTo3DValues( m_lastSelected3DShapeIndex );
  206. m_lastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetSelection();
  207. if( m_lastSelected3DShapeIndex < 0 ) // happens under wxGTK when deleting an item in m_3D_ShapeNameListBox wxListBox
  208. return;
  209. if( m_lastSelected3DShapeIndex >= (int)m_shapes3D_list.size() )
  210. {
  211. wxMessageBox( wxT( "On3DShapeNameSelected() error" ) );
  212. m_lastSelected3DShapeIndex = -1;
  213. return;
  214. }
  215. Transfert3DValuesToDisplay( m_shapes3D_list[m_lastSelected3DShapeIndex] );
  216. }
  217. void DIALOG_MODULE_MODULE_EDITOR::Remove3DShape(wxCommandEvent& event)
  218. {
  219. if( m_lastSelected3DShapeIndex >= 0 )
  220. TransfertDisplayTo3DValues( m_lastSelected3DShapeIndex );
  221. int ii = m_3D_ShapeNameListBox->GetSelection();
  222. if( ii < 0 )
  223. return;
  224. m_shapes3D_list.erase( m_shapes3D_list.begin() + ii );
  225. m_3D_ShapeNameListBox->Delete( ii );
  226. if( m_3D_ShapeNameListBox->GetCount() == 0)
  227. Transfert3DValuesToDisplay( NULL );
  228. else
  229. {
  230. m_lastSelected3DShapeIndex = 0;
  231. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  232. Transfert3DValuesToDisplay( m_shapes3D_list[m_lastSelected3DShapeIndex] );
  233. }
  234. }
  235. void DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile()
  236. {
  237. PROJECT& prj = Prj();
  238. // here, the KISYS3DMOD default path for 3D shape files is expected
  239. // to be already defined (when starting Pcbnew, it is defined
  240. // from the user defined env variable, or set to a default value)
  241. wxFileName fn( wxGetenv( KISYS3DMOD ), wxEmptyString );
  242. wxString default3DPath = fn.GetPathWithSep();
  243. wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
  244. if( !initialpath )
  245. initialpath = default3DPath;
  246. #ifdef __WINDOWS__
  247. initialpath.Replace( wxT( "/" ), wxT( "\\" ) );
  248. #endif
  249. wxString fileFilters = wxGetTranslation( Shapes3DFileWildcard );
  250. fileFilters += wxChar( '|' );
  251. fileFilters += wxGetTranslation( IDF3DFileWildcard );
  252. wxString filename = EDA_FileSelector( _( "3D Shape:" ), initialpath,
  253. wxEmptyString, wxEmptyString,
  254. wxGetTranslation( fileFilters ),
  255. this, wxFD_OPEN, true );
  256. if( filename.IsEmpty() )
  257. return;
  258. fn = filename;
  259. prj.SetRString( PROJECT::VIEWER_3D_PATH, fn.GetPath() );
  260. /* If the file path is already in the 3D shape file default path
  261. * just add the file name relative to this path to the list.
  262. * Otherwise, add the file name with a full or relative path.
  263. * The relative path, when possible, is preferable
  264. * because it preserve use of default path, when the path is a sub path of this path
  265. */
  266. wxString rootpath = filename.SubString( 0, default3DPath.Length()-1 );
  267. bool useRelPath = rootpath.IsSameAs( default3DPath, wxFileName::IsCaseSensitive() );
  268. if( useRelPath )
  269. fn.MakeRelativeTo( default3DPath );
  270. else // Absolute path given, not a subpath of the default path,
  271. // therefore ask if the user wants a relative (to the default path) one
  272. {
  273. wxString msg;
  274. msg.Printf( _( "Use a path relative to '%s'?" ), GetChars( default3DPath ) );
  275. int diag = wxMessageBox( msg, _( "Path type" ),
  276. wxYES_NO | wxICON_QUESTION, this );
  277. if( diag == wxYES ) // Make it relative to the default 3D path
  278. fn.MakeRelativeTo( default3DPath );
  279. }
  280. filename = fn.GetFullPath();
  281. S3D_MASTER* new3DShape = new S3D_MASTER(NULL);
  282. #ifdef __WINDOWS__
  283. // Store filename in Unix notation
  284. filename.Replace( wxT( "\\" ), wxT( "/" ) );
  285. #endif
  286. new3DShape->SetShape3DName( filename );
  287. m_shapes3D_list.push_back( new3DShape );
  288. m_3D_ShapeNameListBox->Append( filename );
  289. if( m_lastSelected3DShapeIndex >= 0 )
  290. TransfertDisplayTo3DValues( m_lastSelected3DShapeIndex );
  291. m_lastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetCount() - 1;
  292. m_3D_ShapeNameListBox->SetSelection( m_lastSelected3DShapeIndex );
  293. Transfert3DValuesToDisplay( m_shapes3D_list[m_lastSelected3DShapeIndex] );
  294. }
  295. void DIALOG_MODULE_MODULE_EDITOR::OnCancelClick( wxCommandEvent& event )
  296. {
  297. EndModal( -1 );
  298. }
  299. void DIALOG_MODULE_MODULE_EDITOR::OnOkClick( wxCommandEvent& event )
  300. {
  301. // First, test for invalid chars in module name
  302. wxString footprintName = m_FootprintNameCtrl->GetValue();
  303. if( ! footprintName.IsEmpty() )
  304. {
  305. if( ! MODULE::IsLibNameValid( footprintName ) )
  306. {
  307. wxString msg;
  308. msg.Printf( _( "Error:\none of invalid chars <%s> found\nin <%s>" ),
  309. MODULE::StringLibNameInvalidChars( true ),
  310. GetChars( footprintName ) );
  311. DisplayError( NULL, msg );
  312. return;
  313. }
  314. }
  315. m_parent->SaveCopyInUndoList( m_currentModule, UR_MODEDIT );
  316. m_currentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
  317. switch( m_AttributsCtrl->GetSelection() )
  318. {
  319. case 0:
  320. m_currentModule->SetAttributes( 0 );
  321. break;
  322. case 1:
  323. m_currentModule->SetAttributes( MOD_CMS );
  324. break;
  325. case 2:
  326. m_currentModule->SetAttributes( MOD_VIRTUAL );
  327. break;
  328. }
  329. m_currentModule->SetPlacementCost90( m_CostRot90Ctrl->GetValue() );
  330. m_currentModule->SetPlacementCost180( m_CostRot180Ctrl->GetValue() );
  331. m_currentModule->SetDescription( m_DocCtrl->GetValue() );
  332. m_currentModule->SetKeywords( m_KeywordCtrl->GetValue() );
  333. // Init footprint name in library
  334. if( ! footprintName.IsEmpty() )
  335. m_currentModule->SetFPID( FPID( footprintName ) );
  336. // Init Fields:
  337. m_currentModule->Reference().Copy( m_referenceCopy );
  338. m_currentModule->Value().Copy( m_valueCopy );
  339. // Initialize masks clearances
  340. m_currentModule->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) );
  341. m_currentModule->SetLocalSolderMaskMargin( ValueFromTextCtrl( *m_SolderMaskMarginCtrl ) );
  342. m_currentModule->SetLocalSolderPasteMargin( ValueFromTextCtrl( *m_SolderPasteMarginCtrl ) );
  343. double dtmp;
  344. wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
  345. msg.ToDouble( &dtmp );
  346. // A -50% margin ratio means no paste on a pad, the ratio must be >= -50 %
  347. if( dtmp < -50.0 )
  348. dtmp = -50.0;
  349. // A margin ratio is always <= 0
  350. if( dtmp > 0.0 )
  351. dtmp = 0.0;
  352. m_currentModule->SetLocalSolderPasteMarginRatio( dtmp / 100 );
  353. // Update 3D shape list
  354. int ii = m_3D_ShapeNameListBox->GetSelection();
  355. if ( ii >= 0 )
  356. TransfertDisplayTo3DValues( ii );
  357. S3D_MASTER* draw3D = m_currentModule->Models();
  358. for( unsigned ii = 0; ii < m_shapes3D_list.size(); ii++ )
  359. {
  360. S3D_MASTER* draw3DCopy = m_shapes3D_list[ii];
  361. if( draw3DCopy->GetShape3DName().IsEmpty() )
  362. continue;
  363. if( draw3D == NULL )
  364. {
  365. draw3D = new S3D_MASTER( draw3D );
  366. m_currentModule->Models().Append( draw3D );
  367. }
  368. draw3D->SetShape3DName( draw3DCopy->GetShape3DName() );
  369. draw3D->m_MatScale = draw3DCopy->m_MatScale;
  370. draw3D->m_MatRotation = draw3DCopy->m_MatRotation;
  371. draw3D->m_MatPosition = draw3DCopy->m_MatPosition;
  372. draw3D = draw3D->Next();
  373. }
  374. // Remove old extra 3D shapes
  375. S3D_MASTER* nextdraw3D;
  376. for( ; draw3D != NULL; draw3D = nextdraw3D )
  377. {
  378. nextdraw3D = (S3D_MASTER*) draw3D->Next();
  379. delete m_currentModule->Models().Remove( draw3D );
  380. }
  381. // Fill shape list with one void entry, if no entry
  382. if( m_currentModule->Models() == NULL )
  383. m_currentModule->Models().PushBack( new S3D_MASTER( m_currentModule ) );
  384. m_currentModule->CalculateBoundingBox();
  385. m_parent->OnModify();
  386. EndModal( 1 );
  387. }
  388. void DIALOG_MODULE_MODULE_EDITOR::OnEditReference(wxCommandEvent& event)
  389. {
  390. wxPoint tmp = m_parent->GetCrossHairPosition();
  391. m_parent->SetCrossHairPosition( m_referenceCopy->GetTextPosition() );
  392. m_parent->InstallTextModOptionsFrame( m_referenceCopy, NULL );
  393. m_parent->SetCrossHairPosition( tmp );
  394. m_ReferenceCtrl->SetValue( m_referenceCopy->GetText() );
  395. }
  396. void DIALOG_MODULE_MODULE_EDITOR::OnEditValue(wxCommandEvent& event)
  397. {
  398. wxPoint tmp = m_parent->GetCrossHairPosition();
  399. m_parent->SetCrossHairPosition( m_valueCopy->GetTextPosition() );
  400. m_parent->InstallTextModOptionsFrame( m_valueCopy, NULL );
  401. m_parent->SetCrossHairPosition( tmp );
  402. m_ValueCtrl->SetValue( m_valueCopy->GetText() );
  403. }