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.

398 lines
14 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
* 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. * @file select_layers_to_pcb.cpp
  3. * @brief Dialog to choose equivalence between gerber layers and pcb layers
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <fctsys.h>
  28. #include <kiface_i.h>
  29. #include <gerbview.h>
  30. #include <gerbview_frame.h>
  31. #include <gerbview_id.h>
  32. #include <gerber_file_image.h>
  33. #include <gerber_file_image_list.h>
  34. #include <select_layers_to_pcb.h>
  35. // Imported function
  36. extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
  37. enum swap_layer_id {
  38. ID_LAYERS_MAP_DIALOG = ID_GERBER_END_LIST,
  39. ID_BUTTON_0,
  40. ID_TEXT_0 = ID_BUTTON_0 + GERBER_DRAWLAYERS_COUNT
  41. };
  42. /*
  43. * This dialog shows the gerber files loaded, and allows user to choose:
  44. * what gerber file and what board layer are used
  45. * the number of copper layers
  46. */
  47. int LAYERS_MAP_DIALOG::m_exportBoardCopperLayersCount = 2;
  48. BEGIN_EVENT_TABLE( LAYERS_MAP_DIALOG, LAYERS_MAP_DIALOG_BASE )
  49. EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + GERBER_DRAWLAYERS_COUNT-1,
  50. wxEVT_COMMAND_BUTTON_CLICKED,
  51. LAYERS_MAP_DIALOG::OnSelectLayer )
  52. END_EVENT_TABLE()
  53. LAYERS_MAP_DIALOG::LAYERS_MAP_DIALOG( GERBVIEW_FRAME* parent ) :
  54. LAYERS_MAP_DIALOG_BASE( parent )
  55. {
  56. m_Parent = parent;
  57. initDialog();
  58. // Resize the dialog
  59. Layout();
  60. GetSizer()->SetSizeHints( this );
  61. Centre();
  62. }
  63. void LAYERS_MAP_DIALOG::initDialog()
  64. {
  65. wxStaticText* label;
  66. wxStaticText* text;
  67. int item_ID;
  68. wxString msg;
  69. wxSize goodSize;
  70. for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
  71. {
  72. // Specify the default value for each member of these arrays.
  73. m_buttonTable[ii] = -1;
  74. m_layersLookUpTable[ii] = UNSELECTED_LAYER;
  75. }
  76. // Ensure we have:
  77. // at least 2 copper layers and less than max pacb copper layers count
  78. // and even layers count because a board *must* have even layers count
  79. normalizeBrdLayersCount();
  80. int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1;
  81. m_comboCopperLayersCount->SetSelection( idx );
  82. LAYER_NUM pcb_layer_num = 0;
  83. m_gerberActiveLayersCount = 0;
  84. GERBER_FILE_IMAGE_LIST* images = m_Parent->GetGerberLayout()->GetImagesList();
  85. for( unsigned ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
  86. {
  87. if( images->GetGbrImage( ii ) == NULL )
  88. break;
  89. if( (pcb_layer_num == m_exportBoardCopperLayersCount - 1)
  90. && (m_exportBoardCopperLayersCount > 1) )
  91. pcb_layer_num = F_Cu;
  92. m_buttonTable[m_gerberActiveLayersCount] = ii;
  93. m_layersLookUpTable[ii] = pcb_layer_num;
  94. m_gerberActiveLayersCount++;
  95. ++pcb_layer_num;
  96. }
  97. if( m_gerberActiveLayersCount <= GERBER_DRAWLAYERS_COUNT/2 ) // Only one list is enough
  98. {
  99. m_staticlineSep->Hide();
  100. }
  101. wxFlexGridSizer* flexColumnBoxSizer = m_flexLeftColumnBoxSizer;
  102. for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
  103. {
  104. // Each Gerber layer has an associated static text string (to
  105. // identify that layer), a button (for invoking a child dialog
  106. // box to change which Pcbnew layer that the Gerber layer is
  107. // mapped to), and a second static text string (to depict which
  108. // Pcbnew layer that the Gerber layer has been mapped to). Each
  109. // of those items are placed into the left hand column, middle
  110. // column, and right hand column (respectively) of the Flexgrid
  111. // sizer, and the color of the second text string is set to
  112. // fuchsia or blue (to respectively indicate whether the Gerber
  113. // layer has been mapped to a Pcbnew layer or is not being
  114. // exported at all). (Experimentation has shown that if a text
  115. // control is used to depict which Pcbnew layer that each Gerber
  116. // layer is mapped to (instead of a static text string), then
  117. // those controls do not behave in a fully satisfactory manner
  118. // in the Linux version. Even when the read-only attribute is
  119. // specified for all of those controls, they can still be selected
  120. // when the arrow keys or Tab key is used to step through all of
  121. // the controls within the dialog box, and directives to set the
  122. // foreground color of the text of each such control to blue (to
  123. // indicate that the text is of a read-only nature) are disregarded.
  124. // Specify a FlexGrid sizer with an appropriate number of rows
  125. // and three columns. If nb_items < 16, then the number of rows
  126. // is nb_items; otherwise, the number of rows is 16 (with two
  127. // separate columns of controls being used if nb_items > 16).
  128. if( ii == GERBER_DRAWLAYERS_COUNT/2 )
  129. flexColumnBoxSizer = m_flexRightColumnBoxSizer;
  130. // Provide a text string to identify the Gerber layer
  131. msg.Printf( _( "Layer %d" ), m_buttonTable[ii] + 1 );
  132. label = new wxStaticText( this,
  133. wxID_STATIC, msg, wxDefaultPosition,
  134. wxDefaultSize, 0 );
  135. flexColumnBoxSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  136. /* Add file name and extension without path. */
  137. wxFileName fn( images->GetGbrImage( ii )->m_FileName );
  138. label = new wxStaticText( this,
  139. wxID_STATIC, fn.GetFullName(),
  140. wxDefaultPosition, wxDefaultSize );
  141. flexColumnBoxSizer->Add( label, 0,
  142. wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  143. // Provide a button for this layer (which will invoke a child dialog box)
  144. item_ID = ID_BUTTON_0 + ii;
  145. wxButton * Button = new wxButton( this,
  146. item_ID, wxT( "..." ),
  147. wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
  148. flexColumnBoxSizer->Add( Button, 0, wxALIGN_CENTER_VERTICAL | wxALL );
  149. // Provide another text string to specify which Pcbnew layer that this
  150. // Gerber layer is initially mapped to, and set the initial text to
  151. // specify the appropriate Pcbnew layer, and set the foreground color
  152. // of the text to fuchsia (to indicate that the layer is being exported).
  153. item_ID = ID_TEXT_0 + ii;
  154. // When the first of these text strings is being added, determine what
  155. // size is necessary to to be able to display any possible string
  156. // without it being truncated. Then specify that size as the minimum
  157. // size for all of these text strings. (If this minimum size is not
  158. // determined in this fashion, then it is possible for the display of
  159. // one or more of these strings to be truncated after different Pcbnew
  160. // layers are selected.)
  161. if( ii == 0 )
  162. {
  163. msg = _( "Do not export" );
  164. text = new wxStaticText( this,
  165. item_ID, msg, wxDefaultPosition,
  166. wxDefaultSize, 0 );
  167. goodSize = text->GetSize();
  168. for( LAYER_NUM jj = 0; jj < GERBER_DRAWLAYERS_COUNT; ++jj )
  169. {
  170. text->SetLabel( GetPCBDefaultLayerName( jj ) );
  171. if( goodSize.x < text->GetSize().x )
  172. goodSize.x = text->GetSize().x;
  173. }
  174. msg = GetPCBDefaultLayerName( m_layersLookUpTable[m_buttonTable[ii]] );
  175. text->SetLabel( msg );
  176. }
  177. else
  178. {
  179. msg = GetPCBDefaultLayerName( m_layersLookUpTable[m_buttonTable[ii]] );
  180. text = new wxStaticText( this,
  181. item_ID, msg, wxDefaultPosition,
  182. wxDefaultSize, 0 );
  183. }
  184. text->SetMinSize( goodSize );
  185. flexColumnBoxSizer->Add( text, 1, wxALIGN_CENTER_VERTICAL | wxALL,
  186. 5 );
  187. m_layersList[ii] = text;
  188. }
  189. }
  190. /* Ensure m_exportBoardCopperLayersCount = 2 to BOARD_COPPER_LAYERS_MAX_COUNT
  191. * and it is an even value because Boards have always an even layer count
  192. */
  193. void LAYERS_MAP_DIALOG::normalizeBrdLayersCount()
  194. {
  195. if( ( m_exportBoardCopperLayersCount & 1 ) )
  196. m_exportBoardCopperLayersCount++;
  197. if( m_exportBoardCopperLayersCount > GERBER_DRAWLAYERS_COUNT )
  198. m_exportBoardCopperLayersCount = GERBER_DRAWLAYERS_COUNT;
  199. if( m_exportBoardCopperLayersCount < 2 )
  200. m_exportBoardCopperLayersCount = 2;
  201. }
  202. /*
  203. * Called when user change the current board copper layers count
  204. */
  205. void LAYERS_MAP_DIALOG::OnBrdLayersCountSelection( wxCommandEvent& event )
  206. {
  207. int id = event.GetSelection();
  208. m_exportBoardCopperLayersCount = (id+1) * 2;
  209. }
  210. /*
  211. * reset pcb layers selection to the default value
  212. */
  213. void LAYERS_MAP_DIALOG::OnResetClick( wxCommandEvent& event )
  214. {
  215. wxString msg;
  216. int ii;
  217. LAYER_NUM layer;
  218. for( ii = 0, layer = 0; ii < m_gerberActiveLayersCount; ii++, ++layer )
  219. {
  220. if( (layer == m_exportBoardCopperLayersCount - 1)
  221. && (m_exportBoardCopperLayersCount > 1) )
  222. layer = F_Cu;
  223. m_layersLookUpTable[ii] = layer;
  224. msg = GetPCBDefaultLayerName( layer );
  225. m_layersList[ii]->SetLabel( msg );
  226. m_layersList[ii]->SetForegroundColour( wxNullColour );
  227. m_buttonTable[ii] = ii;
  228. }
  229. }
  230. /* Stores the current layers selection in config
  231. */
  232. void LAYERS_MAP_DIALOG::OnStoreSetup( wxCommandEvent& event )
  233. {
  234. wxConfigBase* config = Kiface().KifaceSettings();
  235. config->Write( wxT("BrdLayersCount"), m_exportBoardCopperLayersCount );
  236. wxString key;
  237. for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
  238. {
  239. key.Printf( wxT("GbrLyr%dToPcb"), ii );
  240. config->Write( key, m_layersLookUpTable[ii] );
  241. }
  242. }
  243. void LAYERS_MAP_DIALOG::OnGetSetup( wxCommandEvent& event )
  244. {
  245. wxConfigBase* config = Kiface().KifaceSettings();
  246. config->Read( wxT("BrdLayersCount"), &m_exportBoardCopperLayersCount );
  247. normalizeBrdLayersCount();
  248. int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1;
  249. m_comboCopperLayersCount->SetSelection( idx );
  250. wxString key;
  251. for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
  252. {
  253. key.Printf( wxT("GbrLyr%dToPcb"), ii );
  254. int ilayer;
  255. config->Read( key, &ilayer);
  256. m_layersLookUpTable[ii] = ilayer;
  257. }
  258. for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ )
  259. {
  260. LAYER_NUM layer = m_layersLookUpTable[ii];
  261. if( layer == UNSELECTED_LAYER )
  262. {
  263. m_layersList[ii]->SetLabel( _( "Do not export" ) );
  264. m_layersList[ii]->SetForegroundColour( *wxBLUE );
  265. }
  266. else
  267. {
  268. m_layersList[ii]->SetLabel( GetPCBDefaultLayerName( layer ) );
  269. m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
  270. }
  271. }
  272. }
  273. void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event )
  274. {
  275. int ii;
  276. ii = event.GetId() - ID_BUTTON_0;
  277. if( (ii < 0) || (ii >= GERBER_DRAWLAYERS_COUNT) )
  278. {
  279. wxFAIL_MSG( wxT("Bad layer id") );
  280. return;
  281. }
  282. LAYER_NUM jj = m_layersLookUpTable[m_buttonTable[ii]];
  283. if( jj != UNSELECTED_LAYER && !IsValidLayer( jj ) )
  284. jj = B_Cu; // (Defaults to "Copper" layer.)
  285. jj = m_Parent->SelectPCBLayer( jj, m_exportBoardCopperLayersCount, true );
  286. if( jj != UNSELECTED_LAYER && !IsValidLayer( jj ) )
  287. return;
  288. if( jj != m_layersLookUpTable[m_buttonTable[ii]] )
  289. {
  290. m_layersLookUpTable[m_buttonTable[ii]] = jj;
  291. if( jj == UNSELECTED_LAYER )
  292. {
  293. m_layersList[ii]->SetLabel( _( "Do not export" ) );
  294. // Change the text color to blue (to highlight
  295. // that this layer is *not* being exported)
  296. m_layersList[ii]->SetForegroundColour( *wxBLUE );
  297. }
  298. else
  299. {
  300. m_layersList[ii]->SetLabel( GetPCBDefaultLayerName( jj ) );
  301. // Change the text color to fuchsia (to highlight
  302. // that this layer *is* being exported)
  303. m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) );
  304. }
  305. }
  306. }
  307. void LAYERS_MAP_DIALOG::OnOkClick( wxCommandEvent& event )
  308. {
  309. /* Make some test about copper layers:
  310. * Board must have enough copper layers to handle selected internal layers
  311. */
  312. normalizeBrdLayersCount();
  313. int inner_layer_max = 0;
  314. for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii )
  315. {
  316. if( m_layersLookUpTable[ii] < F_Cu )
  317. {
  318. if( m_layersLookUpTable[ii ] > inner_layer_max )
  319. inner_layer_max = m_layersLookUpTable[ii];
  320. }
  321. }
  322. // inner_layer_max must be less than (or equal to) the number of
  323. // internal copper layers
  324. // internal copper layers = m_exportBoardCopperLayersCount-2
  325. if( inner_layer_max > m_exportBoardCopperLayersCount-2 )
  326. {
  327. wxMessageBox(
  328. _("The exported board has not enough copper layers to handle selected inner layers") );
  329. return;
  330. }
  331. EndModal( wxID_OK );
  332. }