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.

649 lines
22 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
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <kiface_i.h>
  26. #include <confirm.h>
  27. #include <pcb_edit_frame.h>
  28. #include <pcbnew_settings.h>
  29. #include <zones.h>
  30. #include <bitmaps.h>
  31. #include <widgets/unit_binder.h>
  32. #include <zone.h>
  33. #include <pad.h>
  34. #include <board.h>
  35. #include <trigo.h>
  36. #include <dialog_copper_zones_base.h>
  37. #include <kicad_string.h>
  38. class DIALOG_COPPER_ZONE : public DIALOG_COPPER_ZONE_BASE
  39. {
  40. public:
  41. DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings );
  42. private:
  43. PCB_BASE_FRAME* m_Parent;
  44. bool m_settingsExported; // settings will be written to all other zones
  45. ZONE_SETTINGS m_settings;
  46. ZONE_SETTINGS* m_ptr;
  47. std::vector<int> m_listIndexToNetCodeMap;
  48. bool m_netSortingByPadCount;
  49. long m_netFiltering;
  50. static wxString m_netNameShowFilter; // the filter to show nets (default * "*"). Static
  51. // to keep this pattern for an entire Pcbnew session
  52. int m_cornerSmoothingType;
  53. UNIT_BINDER m_cornerRadius;
  54. UNIT_BINDER m_clearance;
  55. UNIT_BINDER m_minWidth;
  56. UNIT_BINDER m_antipadClearance ;
  57. UNIT_BINDER m_spokeWidth;
  58. UNIT_BINDER m_gridStyleRotation;
  59. UNIT_BINDER m_gridStyleThickness;
  60. UNIT_BINDER m_gridStyleGap;
  61. UNIT_BINDER m_islandThreshold;
  62. bool TransferDataToWindow() override;
  63. bool TransferDataFromWindow() override;
  64. /**
  65. * @param aUseExportableSetupOnly is true to use exportable parameters only (used to
  66. * export this setup to other zones).
  67. * @return bool - false if incorrect options, true if ok.
  68. */
  69. bool AcceptOptions( bool aUseExportableSetupOnly = false );
  70. void OnStyleSelection( wxCommandEvent& event ) override;
  71. void OnLayerSelection( wxDataViewEvent& event ) override;
  72. void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
  73. void ExportSetupToOtherCopperZones( wxCommandEvent& event ) override;
  74. void OnRunFiltersButtonClick( wxCommandEvent& event ) override;
  75. void OnUpdateUI( wxUpdateUIEvent& ) override;
  76. void OnButtonCancelClick( wxCommandEvent& event ) override;
  77. void OnClose( wxCloseEvent& event ) override;
  78. void buildAvailableListOfNets();
  79. };
  80. // Initialize static member variables
  81. wxString DIALOG_COPPER_ZONE::m_netNameShowFilter( wxT( "*" ) );
  82. int InvokeCopperZonesEditor( PCB_BASE_FRAME* aCaller, ZONE_SETTINGS* aSettings )
  83. {
  84. DIALOG_COPPER_ZONE dlg( aCaller, aSettings );
  85. return dlg.ShowQuasiModal();
  86. }
  87. DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS* aSettings ) :
  88. DIALOG_COPPER_ZONE_BASE( aParent ),
  89. m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
  90. m_cornerRadius( aParent, m_cornerRadiusLabel, m_cornerRadiusCtrl, m_cornerRadiusUnits ),
  91. m_clearance( aParent, m_clearanceLabel, m_clearanceCtrl, m_clearanceUnits ),
  92. m_minWidth( aParent, m_minWidthLabel, m_minWidthCtrl, m_minWidthUnits ),
  93. m_antipadClearance( aParent, m_antipadLabel, m_antipadCtrl, m_antipadUnits ),
  94. m_spokeWidth( aParent, m_spokeWidthLabel, m_spokeWidthCtrl, m_spokeWidthUnits ),
  95. m_gridStyleRotation( aParent, m_staticTextGrindOrient, m_tcGridStyleOrientation, m_staticTextRotUnits ),
  96. m_gridStyleThickness( aParent, m_staticTextStyleThickness, m_tcGridStyleThickness, m_GridStyleThicknessUnits ),
  97. m_gridStyleGap( aParent, m_staticTextGridGap, m_tcGridStyleGap, m_GridStyleGapUnits ),
  98. m_islandThreshold( aParent, m_islandThresholdLabel, m_tcIslandThreshold, m_islandThresholdUnits )
  99. {
  100. m_Parent = aParent;
  101. m_bitmapNoNetWarning->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
  102. m_ptr = aSettings;
  103. m_settings = *aSettings;
  104. m_settings.SetupLayersList( m_layers, m_Parent, true );
  105. m_settingsExported = false;
  106. m_netFiltering = false;
  107. m_netSortingByPadCount = true; // false = alphabetic sort, true = pad count sort
  108. m_sdbSizerOK->SetDefault();
  109. m_cbRemoveIslands->Bind( wxEVT_CHOICE,
  110. [&]( wxCommandEvent& )
  111. {
  112. // Area mode is index 2
  113. bool val = m_cbRemoveIslands->GetSelection() == 2;
  114. m_tcIslandThreshold->Enable( val );
  115. m_islandThresholdLabel->Enable( val );
  116. m_islandThresholdUnits->Enable( val );
  117. } );
  118. finishDialogSettings();
  119. }
  120. bool DIALOG_COPPER_ZONE::TransferDataToWindow()
  121. {
  122. m_constrainOutline->SetValue( m_settings.m_Zone_45_Only );
  123. m_cbLocked->SetValue( m_settings.m_Locked );
  124. m_cornerSmoothingChoice->SetSelection( m_settings.GetCornerSmoothingType() );
  125. m_cornerRadius.SetValue( m_settings.GetCornerRadius() );
  126. m_PriorityLevelCtrl->SetValue( m_settings.m_ZonePriority );
  127. switch( m_settings.m_ZoneBorderDisplayStyle )
  128. {
  129. case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
  130. case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: m_OutlineDisplayCtrl->SetSelection( 1 ); break;
  131. case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: m_OutlineDisplayCtrl->SetSelection( 2 ); break;
  132. }
  133. m_clearance.SetValue( m_settings.m_ZoneClearance );
  134. m_minWidth.SetValue( m_settings.m_ZoneMinThickness );
  135. switch( m_settings.GetPadConnection() )
  136. {
  137. default:
  138. case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
  139. case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
  140. case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
  141. case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
  142. }
  143. // Do not enable/disable antipad clearance and spoke width. They might be needed if
  144. // a footprint or pad overrides the zone to specify a thermal connection.
  145. m_antipadClearance.SetValue( m_settings.m_ThermalReliefGap );
  146. m_spokeWidth.SetValue( m_settings.m_ThermalReliefSpokeWidth );
  147. m_islandThreshold.SetDataType( EDA_DATA_TYPE::AREA );
  148. m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings.GetMinIslandArea() ) );
  149. m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings.GetIslandRemovalMode() ) );
  150. bool val = m_settings.GetIslandRemovalMode() == ISLAND_REMOVAL_MODE::AREA;
  151. m_tcIslandThreshold->Enable( val );
  152. m_islandThresholdLabel->Enable( val );
  153. m_islandThresholdUnits->Enable( val );
  154. wxString netNameDoNotShowFilter = wxT( "Net-*" );
  155. m_netFiltering = false;
  156. m_netSortingByPadCount = true;
  157. PCBNEW_SETTINGS* cfg = m_Parent->GetPcbNewSettings();
  158. int opt = cfg->m_Zones.net_sort_mode;
  159. m_netFiltering = opt >= 2;
  160. m_netSortingByPadCount = opt % 2;
  161. netNameDoNotShowFilter = cfg->m_Zones.net_filter;
  162. m_ShowNetNameFilter->SetValue( m_netNameShowFilter );
  163. m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
  164. m_showAllNetsOpt->SetValue( !m_netFiltering );
  165. m_sortByPadsOpt->SetValue( m_netSortingByPadCount );
  166. // Build list of nets:
  167. buildAvailableListOfNets();
  168. SetInitialFocus( m_ListNetNameSelection );
  169. switch( m_settings.m_FillMode )
  170. {
  171. case ZONE_FILL_MODE::HATCH_PATTERN: m_GridStyleCtrl->SetSelection( 1 ); break;
  172. default: m_GridStyleCtrl->SetSelection( 0 ); break;
  173. }
  174. m_gridStyleRotation.SetUnits( EDA_UNITS::DEGREES );
  175. m_gridStyleRotation.SetValue( m_settings.m_HatchOrientation * 10 ); // IU is decidegree
  176. // Gives a reasonable value to grid style parameters, if currently there are no defined
  177. // parameters for grid pattern thickness and gap (if the value is 0)
  178. // the grid pattern thickness default value is (arbitrary) m_ZoneMinThickness * 4
  179. // or 1mm
  180. // the grid pattern gap default value is (arbitrary) m_ZoneMinThickness * 6
  181. // or 1.5 mm
  182. int bestvalue = m_settings.m_HatchThickness;
  183. if( bestvalue <= 0 ) // No defined value for m_HatchThickness
  184. bestvalue = std::max( m_settings.m_ZoneMinThickness * 4, Millimeter2iu( 1.0 ) );
  185. m_gridStyleThickness.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
  186. bestvalue = m_settings.m_HatchGap;
  187. if( bestvalue <= 0 ) // No defined value for m_HatchGap
  188. bestvalue = std::max( m_settings.m_ZoneMinThickness * 6, Millimeter2iu( 1.5 ) );
  189. m_gridStyleGap.SetValue( std::max( bestvalue, m_settings.m_ZoneMinThickness ) );
  190. m_spinCtrlSmoothLevel->SetValue( m_settings.m_HatchSmoothingLevel );
  191. m_spinCtrlSmoothValue->SetValue( m_settings.m_HatchSmoothingValue );
  192. m_tcZoneName->SetValue( m_settings.m_Name );
  193. // Enable/Disable some widgets
  194. wxCommandEvent event;
  195. OnStyleSelection( event );
  196. Fit();
  197. return true;
  198. }
  199. void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
  200. {
  201. if( m_ListNetNameSelection->GetSelection() < 0 )
  202. m_ListNetNameSelection->SetSelection( 0 );
  203. bool noNetSelected = m_ListNetNameSelection->GetSelection() == 0;
  204. bool enableSize = !noNetSelected && ( m_cbRemoveIslands->GetSelection() == 2 );
  205. m_bNoNetWarning->Show( noNetSelected );
  206. // Zones with no net never have islands removed
  207. m_cbRemoveIslands->Enable( !noNetSelected );
  208. m_islandThresholdLabel->Enable( enableSize );
  209. m_islandThresholdUnits->Enable( enableSize );
  210. m_tcIslandThreshold->Enable( enableSize );
  211. if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
  212. {
  213. m_cornerSmoothingType = m_cornerSmoothingChoice->GetSelection();
  214. if( m_cornerSmoothingChoice->GetSelection() == ZONE_SETTINGS::SMOOTHING_CHAMFER )
  215. m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
  216. else
  217. m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
  218. }
  219. m_cornerRadiusCtrl->Enable(m_cornerSmoothingType > ZONE_SETTINGS::SMOOTHING_NONE );
  220. }
  221. void DIALOG_COPPER_ZONE::OnButtonCancelClick( wxCommandEvent& event )
  222. {
  223. // After an "Export Settings to Other Zones" cancel and close must return
  224. // ZONE_EXPORT_VALUES instead of wxID_CANCEL.
  225. Close( true );
  226. }
  227. bool DIALOG_COPPER_ZONE::TransferDataFromWindow()
  228. {
  229. m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
  230. if( m_GridStyleCtrl->GetSelection() > 0 )
  231. m_settings.m_FillMode = ZONE_FILL_MODE::HATCH_PATTERN;
  232. else
  233. m_settings.m_FillMode = ZONE_FILL_MODE::POLYGONS;
  234. if( !AcceptOptions() )
  235. return false;
  236. m_settings.m_HatchOrientation = m_gridStyleRotation.GetValue() / 10.0; // value is returned in deci-degree
  237. m_settings.m_HatchThickness = m_gridStyleThickness.GetValue();
  238. m_settings.m_HatchGap = m_gridStyleGap.GetValue();
  239. m_settings.m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
  240. m_settings.m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
  241. *m_ptr = m_settings;
  242. return true;
  243. }
  244. void DIALOG_COPPER_ZONE::OnClose( wxCloseEvent& event )
  245. {
  246. SetReturnCode( m_settingsExported ? ZONE_EXPORT_VALUES : wxID_CANCEL );
  247. event.Skip();
  248. }
  249. bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
  250. {
  251. if( !m_clearance.Validate( 0, Mils2iu( ZONE_CLEARANCE_MAX_VALUE_MIL ) ) )
  252. return false;
  253. if( !m_minWidth.Validate( Mils2iu( ZONE_THICKNESS_MIN_VALUE_MIL ), INT_MAX ) )
  254. return false;
  255. if( !m_cornerRadius.Validate( 0, INT_MAX ) )
  256. return false;
  257. if( !m_spokeWidth.Validate( 0, INT_MAX ) )
  258. return false;
  259. m_gridStyleRotation.SetValue( NormalizeAngle180( m_gridStyleRotation.GetValue() ) );
  260. if( m_settings.m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
  261. {
  262. int minThickness = m_minWidth.GetValue();
  263. if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
  264. return false;
  265. if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
  266. return false;
  267. }
  268. switch( m_PadInZoneOpt->GetSelection() )
  269. {
  270. case 3: m_settings.SetPadConnection( ZONE_CONNECTION::NONE ); break;
  271. case 2: m_settings.SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
  272. case 1: m_settings.SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
  273. case 0: m_settings.SetPadConnection( ZONE_CONNECTION::FULL ); break;
  274. }
  275. switch( m_OutlineDisplayCtrl->GetSelection() )
  276. {
  277. case 0: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
  278. case 1: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
  279. case 2: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
  280. }
  281. PCBNEW_SETTINGS* cfg = m_Parent->GetPcbNewSettings();
  282. cfg->m_Zones.hatching_style = static_cast<int>( m_settings.m_ZoneBorderDisplayStyle );
  283. cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
  284. m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
  285. m_settings.m_ZoneClearance = m_clearance.GetValue();
  286. m_settings.m_ZoneMinThickness = m_minWidth.GetValue();
  287. m_settings.SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
  288. m_settings.SetCornerRadius( m_settings.GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE
  289. ? 0 : m_cornerRadius.GetValue() );
  290. m_settings.m_ZonePriority = m_PriorityLevelCtrl->GetValue();
  291. m_settings.m_Zone_45_Only = m_constrainOutline->GetValue();
  292. m_settings.m_Locked = m_cbLocked->GetValue();
  293. m_settings.m_ThermalReliefGap = m_antipadClearance.GetValue();
  294. m_settings.m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
  295. if( m_settings.m_ThermalReliefSpokeWidth < m_settings.m_ZoneMinThickness )
  296. {
  297. DisplayError( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
  298. return false;
  299. }
  300. cfg->m_Zones.clearance = Iu2Mils( m_settings.m_ZoneClearance );
  301. cfg->m_Zones.min_thickness = Iu2Mils( m_settings.m_ZoneMinThickness );
  302. cfg->m_Zones.thermal_relief_gap = Iu2Mils( m_settings.m_ThermalReliefGap );
  303. cfg->m_Zones.thermal_relief_copper_width = Iu2Mils( m_settings.m_ThermalReliefSpokeWidth );
  304. m_settings.SetIslandRemovalMode(
  305. static_cast<ISLAND_REMOVAL_MODE>( m_cbRemoveIslands->GetSelection() ) );
  306. m_settings.SetMinIslandArea( m_islandThreshold.GetValue() );
  307. // If we use only exportable to others zones parameters, exit here:
  308. if( aUseExportableSetupOnly )
  309. return true;
  310. // Get the layer selection for this zone
  311. int layers = 0;
  312. for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
  313. {
  314. if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
  315. layers++;
  316. }
  317. if( layers == 0 )
  318. {
  319. DisplayError( this, _( "No layer selected." ) );
  320. return false;
  321. }
  322. int netcode = 0;
  323. if( m_ListNetNameSelection->GetSelection() > 0 )
  324. netcode = m_listIndexToNetCodeMap[ m_ListNetNameSelection->GetSelection() ];
  325. m_settings.m_NetcodeSelection = netcode;
  326. m_settings.m_Name = m_tcZoneName->GetValue();
  327. return true;
  328. }
  329. void DIALOG_COPPER_ZONE::OnStyleSelection( wxCommandEvent& event )
  330. {
  331. bool enable = m_GridStyleCtrl->GetSelection() >= 1;
  332. m_tcGridStyleThickness->Enable( enable );
  333. m_tcGridStyleGap->Enable( enable );
  334. m_tcGridStyleOrientation->Enable( enable );
  335. m_spinCtrlSmoothLevel->Enable( enable );
  336. m_spinCtrlSmoothValue->Enable( enable );
  337. }
  338. void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
  339. {
  340. if( event.GetColumn() != 0 )
  341. return;
  342. int row = m_layers->ItemToRow( event.GetItem() );
  343. bool checked = m_layers->GetToggleValue( row, 0 );
  344. wxVariant layerID;
  345. m_layers->GetValue( layerID, row, 2 );
  346. m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
  347. }
  348. void DIALOG_COPPER_ZONE::OnNetSortingOptionSelected( wxCommandEvent& event )
  349. {
  350. m_netFiltering = !m_showAllNetsOpt->GetValue();
  351. m_netSortingByPadCount = m_sortByPadsOpt->GetValue();
  352. m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
  353. buildAvailableListOfNets();
  354. auto cfg = m_Parent->GetPcbNewSettings();
  355. int configValue = m_netFiltering ? 2 : 0;
  356. if( m_netSortingByPadCount )
  357. configValue += 1;
  358. cfg->m_Zones.net_sort_mode = configValue;
  359. cfg->m_Zones.net_filter = m_DoNotShowNetNameFilter->GetValue().ToStdString();
  360. }
  361. void DIALOG_COPPER_ZONE::ExportSetupToOtherCopperZones( wxCommandEvent& event )
  362. {
  363. if( !AcceptOptions( true ) )
  364. return;
  365. // Export settings ( but layer and netcode ) to others copper zones
  366. BOARD* pcb = m_Parent->GetBoard();
  367. for( ZONE* zone : pcb->Zones() )
  368. {
  369. // Cannot export settings from a copper zone
  370. // to a zone keepout:
  371. if( zone->GetIsRuleArea() )
  372. continue;
  373. m_settings.ExportSetting( *zone, false ); // false = partial export
  374. m_settingsExported = true;
  375. m_Parent->OnModify();
  376. }
  377. }
  378. void DIALOG_COPPER_ZONE::OnRunFiltersButtonClick( wxCommandEvent& event )
  379. {
  380. m_netFiltering = true;
  381. m_showAllNetsOpt->SetValue( false );
  382. buildAvailableListOfNets();
  383. }
  384. // The pad count for each netcode, stored in a buffer for a fast access.
  385. // This is needed by the sort function sortNetsByNodes()
  386. static std::vector<int> padCountListByNet;
  387. // Sort nets by decreasing pad count.
  388. // For same pad count, sort by alphabetic names
  389. static bool sortNetsByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
  390. {
  391. int countA = padCountListByNet[ a->GetNetCode() ];
  392. int countB = padCountListByNet[ b->GetNetCode() ];
  393. if( countA == countB )
  394. return a->GetNetname() < b->GetNetname();
  395. else
  396. return countB < countA;
  397. }
  398. // Sort nets by alphabetic names
  399. static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
  400. {
  401. return a->GetNetname() < b->GetNetname();
  402. }
  403. void DIALOG_COPPER_ZONE::buildAvailableListOfNets()
  404. {
  405. NETINFO_LIST& netInfo = m_Parent->GetBoard()->GetNetInfo();
  406. wxArrayString listNetName;
  407. m_listIndexToNetCodeMap.clear();
  408. if( netInfo.GetNetCount() > 0 )
  409. {
  410. // Build the list
  411. std::vector<NETINFO_ITEM*> netBuffer;
  412. netBuffer.reserve( netInfo.GetNetCount() );
  413. int max_netcode = 0;
  414. for( NETINFO_ITEM* net : netInfo )
  415. {
  416. int netcode = net->GetNetCode();
  417. if( netcode > 0 && net->IsCurrent() )
  418. {
  419. netBuffer.push_back( net );
  420. max_netcode = std::max( netcode, max_netcode);
  421. }
  422. }
  423. // sort the list
  424. if( m_netSortingByPadCount )
  425. {
  426. // Build the pad count by net:
  427. padCountListByNet.clear();
  428. std::vector<PAD*> pads = m_Parent->GetBoard()->GetPads();
  429. padCountListByNet.assign( max_netcode + 1, 0 );
  430. for( PAD* pad : pads )
  431. {
  432. int netCode = pad->GetNetCode();
  433. if( netCode >= 0 )
  434. padCountListByNet[ netCode ]++;
  435. }
  436. sort( netBuffer.begin(), netBuffer.end(), sortNetsByNodes );
  437. }
  438. else
  439. {
  440. sort( netBuffer.begin(), netBuffer.end(), sortNetsByNames );
  441. }
  442. for( NETINFO_ITEM* net : netBuffer )
  443. {
  444. listNetName.Add( UnescapeString( net->GetNetname() ) );
  445. m_listIndexToNetCodeMap.push_back( net->GetNetCode() );
  446. }
  447. }
  448. if( m_netFiltering )
  449. {
  450. wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue().Lower();
  451. wxString ShowFilter = m_ShowNetNameFilter->GetValue().Lower();
  452. for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
  453. {
  454. if( listNetName[ii].Lower().Matches( doNotShowFilter ) )
  455. {
  456. listNetName.RemoveAt( ii );
  457. ii--;
  458. }
  459. else if( !listNetName[ii].Lower().Matches( ShowFilter ) )
  460. {
  461. listNetName.RemoveAt( ii );
  462. ii--;
  463. }
  464. }
  465. }
  466. listNetName.Insert( wxT( "<no net>" ), 0 );
  467. m_listIndexToNetCodeMap.insert( m_listIndexToNetCodeMap.begin(), 0 );
  468. // Ensure currently selected net for the zone is visible, regardless of filters
  469. int selectedNetListNdx = 0;
  470. int net_select = m_settings.m_NetcodeSelection;
  471. if( net_select > 0 )
  472. {
  473. NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( net_select );
  474. if( selectedNet )
  475. {
  476. selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() );
  477. if( wxNOT_FOUND == selectedNetListNdx )
  478. {
  479. // the currently selected net must *always* be visible.
  480. // <no net> is the zero'th index, so pick next lowest
  481. listNetName.Insert( selectedNet->GetNetname(), 1 );
  482. selectedNetListNdx = 1;
  483. }
  484. }
  485. }
  486. m_ListNetNameSelection->Clear();
  487. m_ListNetNameSelection->InsertItems( listNetName, 0 );
  488. m_ListNetNameSelection->SetSelection( selectedNetListNdx );
  489. m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
  490. }