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.

644 lines
23 KiB

9 years ago
9 years ago
9 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014-2017 CERN
  5. * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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 "pcb_draw_panel_gal.h"
  26. #include <pcb_view.h>
  27. #include <view/wx_view_controls.h>
  28. #include <pcb_painter.h>
  29. #include <drawing_sheet/ds_proxy_view_item.h>
  30. #include <connectivity/connectivity_data.h>
  31. #include <board.h>
  32. #include <footprint.h>
  33. #include <pcb_track.h>
  34. #include <macros.h>
  35. #include <pcb_marker.h>
  36. #include <pcb_base_frame.h>
  37. #include <pcbnew_settings.h>
  38. #include <ratsnest/ratsnest_data.h>
  39. #include <ratsnest/ratsnest_view_item.h>
  40. #include <pgm_base.h>
  41. #include <settings/settings_manager.h>
  42. #include <confirm.h>
  43. #include <progress_reporter.h>
  44. #include <gal/graphics_abstraction_layer.h>
  45. #include <zoom_defines.h>
  46. #include <functional>
  47. #include <memory>
  48. #include <thread>
  49. using namespace std::placeholders;
  50. const LAYER_NUM GAL_LAYER_ORDER[] =
  51. {
  52. LAYER_GP_OVERLAY,
  53. LAYER_SELECT_OVERLAY,
  54. LAYER_DRC_ERROR, LAYER_DRC_WARNING, LAYER_DRC_EXCLUSION, LAYER_MARKER_SHADOWS,
  55. LAYER_PAD_NETNAMES, LAYER_VIA_NETNAMES,
  56. Dwgs_User,
  57. Cmts_User,
  58. Eco1_User, Eco2_User,
  59. Edge_Cuts, Margin,
  60. User_1, ZONE_LAYER_FOR( User_1 ),
  61. User_2, ZONE_LAYER_FOR( User_2 ),
  62. User_3, ZONE_LAYER_FOR( User_3 ),
  63. User_4, ZONE_LAYER_FOR( User_4 ),
  64. User_5, ZONE_LAYER_FOR( User_5 ),
  65. User_6, ZONE_LAYER_FOR( User_6 ),
  66. User_7, ZONE_LAYER_FOR( User_7 ),
  67. User_8, ZONE_LAYER_FOR( User_8 ),
  68. User_9, ZONE_LAYER_FOR( User_9 ),
  69. LAYER_MOD_TEXT, LAYER_MOD_REFERENCES, LAYER_MOD_VALUES,
  70. LAYER_RATSNEST,
  71. LAYER_ANCHOR,
  72. LAYER_VIA_HOLES, LAYER_VIA_HOLEWALLS,
  73. LAYER_PAD_PLATEDHOLES, LAYER_PAD_HOLEWALLS, LAYER_NON_PLATEDHOLES,
  74. LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA,
  75. LAYER_PADS_TH,
  76. LAYER_PAD_FR_NETNAMES, LAYER_PAD_FR,
  77. NETNAMES_LAYER_INDEX( F_Cu ), F_Cu, ZONE_LAYER_FOR( F_Cu ),
  78. F_Mask, ZONE_LAYER_FOR( F_Mask ),
  79. F_SilkS, ZONE_LAYER_FOR( F_SilkS ),
  80. F_Paste, ZONE_LAYER_FOR( F_Paste ),
  81. F_Adhes, ZONE_LAYER_FOR( F_Adhes ),
  82. F_CrtYd, ZONE_LAYER_FOR( F_CrtYd ),
  83. F_Fab, ZONE_LAYER_FOR( F_Fab ),
  84. NETNAMES_LAYER_INDEX( In1_Cu ), In1_Cu, ZONE_LAYER_FOR( In1_Cu ),
  85. NETNAMES_LAYER_INDEX( In2_Cu ), In2_Cu, ZONE_LAYER_FOR( In2_Cu ),
  86. NETNAMES_LAYER_INDEX( In3_Cu ), In3_Cu, ZONE_LAYER_FOR( In3_Cu ),
  87. NETNAMES_LAYER_INDEX( In4_Cu ), In4_Cu, ZONE_LAYER_FOR( In4_Cu ),
  88. NETNAMES_LAYER_INDEX( In5_Cu ), In5_Cu, ZONE_LAYER_FOR( In5_Cu ),
  89. NETNAMES_LAYER_INDEX( In6_Cu ), In6_Cu, ZONE_LAYER_FOR( In6_Cu ),
  90. NETNAMES_LAYER_INDEX( In7_Cu ), In7_Cu, ZONE_LAYER_FOR( In7_Cu ),
  91. NETNAMES_LAYER_INDEX( In8_Cu ), In8_Cu, ZONE_LAYER_FOR( In8_Cu ),
  92. NETNAMES_LAYER_INDEX( In9_Cu ), In9_Cu, ZONE_LAYER_FOR( In9_Cu ),
  93. NETNAMES_LAYER_INDEX( In10_Cu ), In10_Cu, ZONE_LAYER_FOR( In10_Cu ),
  94. NETNAMES_LAYER_INDEX( In11_Cu ), In11_Cu, ZONE_LAYER_FOR( In11_Cu ),
  95. NETNAMES_LAYER_INDEX( In12_Cu ), In12_Cu, ZONE_LAYER_FOR( In12_Cu ),
  96. NETNAMES_LAYER_INDEX( In13_Cu ), In13_Cu, ZONE_LAYER_FOR( In13_Cu ),
  97. NETNAMES_LAYER_INDEX( In14_Cu ), In14_Cu, ZONE_LAYER_FOR( In14_Cu ),
  98. NETNAMES_LAYER_INDEX( In15_Cu ), In15_Cu, ZONE_LAYER_FOR( In15_Cu ),
  99. NETNAMES_LAYER_INDEX( In16_Cu ), In16_Cu, ZONE_LAYER_FOR( In16_Cu ),
  100. NETNAMES_LAYER_INDEX( In17_Cu ), In17_Cu, ZONE_LAYER_FOR( In17_Cu ),
  101. NETNAMES_LAYER_INDEX( In18_Cu ), In18_Cu, ZONE_LAYER_FOR( In18_Cu ),
  102. NETNAMES_LAYER_INDEX( In19_Cu ), In19_Cu, ZONE_LAYER_FOR( In19_Cu ),
  103. NETNAMES_LAYER_INDEX( In20_Cu ), In20_Cu, ZONE_LAYER_FOR( In20_Cu ),
  104. NETNAMES_LAYER_INDEX( In21_Cu ), In21_Cu, ZONE_LAYER_FOR( In21_Cu ),
  105. NETNAMES_LAYER_INDEX( In22_Cu ), In22_Cu, ZONE_LAYER_FOR( In22_Cu ),
  106. NETNAMES_LAYER_INDEX( In23_Cu ), In23_Cu, ZONE_LAYER_FOR( In23_Cu ),
  107. NETNAMES_LAYER_INDEX( In24_Cu ), In24_Cu, ZONE_LAYER_FOR( In24_Cu ),
  108. NETNAMES_LAYER_INDEX( In25_Cu ), In25_Cu, ZONE_LAYER_FOR( In25_Cu ),
  109. NETNAMES_LAYER_INDEX( In26_Cu ), In26_Cu, ZONE_LAYER_FOR( In26_Cu ),
  110. NETNAMES_LAYER_INDEX( In27_Cu ), In27_Cu, ZONE_LAYER_FOR( In27_Cu ),
  111. NETNAMES_LAYER_INDEX( In28_Cu ), In28_Cu, ZONE_LAYER_FOR( In28_Cu ),
  112. NETNAMES_LAYER_INDEX( In29_Cu ), In29_Cu, ZONE_LAYER_FOR( In29_Cu ),
  113. NETNAMES_LAYER_INDEX( In30_Cu ), In30_Cu, ZONE_LAYER_FOR( In30_Cu ),
  114. LAYER_PAD_BK_NETNAMES, LAYER_PAD_BK,
  115. NETNAMES_LAYER_INDEX( B_Cu ), B_Cu, ZONE_LAYER_FOR( B_Cu ),
  116. B_Mask, ZONE_LAYER_FOR( B_Mask ),
  117. B_SilkS, ZONE_LAYER_FOR( B_SilkS ),
  118. B_Paste, ZONE_LAYER_FOR( B_Paste ),
  119. B_Adhes, ZONE_LAYER_FOR( B_Adhes ),
  120. B_CrtYd, ZONE_LAYER_FOR( B_CrtYd ),
  121. B_Fab, ZONE_LAYER_FOR( B_Fab ),
  122. LAYER_DRAWINGSHEET
  123. };
  124. PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
  125. const wxPoint& aPosition, const wxSize& aSize,
  126. KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
  127. EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
  128. {
  129. m_view = new KIGFX::PCB_VIEW( true );
  130. m_view->SetGAL( m_gal );
  131. m_painter = std::make_unique<KIGFX::PCB_PAINTER>( m_gal );
  132. m_view->SetPainter( m_painter.get() );
  133. // This fixes the zoom in and zoom out limits:
  134. m_view->SetScaleLimits( ZOOM_MAX_LIMIT_PCBNEW, ZOOM_MIN_LIMIT_PCBNEW );
  135. setDefaultLayerOrder();
  136. setDefaultLayerDeps();
  137. // View controls is the first in the event handler chain, so the Tool Framework operates
  138. // on updated viewport data.
  139. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  140. // Load display options (such as filled/outline display of items).
  141. // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class)
  142. // which is not always the case (namely when it is used from a wxDialog like the pad editor)
  143. if( !IsDialogPreview() )
  144. {
  145. KIGFX::PCB_VIEW* view = static_cast<KIGFX::PCB_VIEW*>( m_view );
  146. PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() );
  147. if( frame )
  148. view->UpdateDisplayOptions( frame->GetDisplayOptions() );
  149. }
  150. }
  151. PCB_DRAW_PANEL_GAL::~PCB_DRAW_PANEL_GAL()
  152. {
  153. }
  154. void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
  155. {
  156. m_view->Clear();
  157. auto zones = aBoard->Zones();
  158. std::atomic<size_t> next( 0 );
  159. std::atomic<size_t> count_done( 0 );
  160. size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
  161. for( size_t ii = 0; ii < parallelThreadCount; ++ii )
  162. {
  163. std::thread t = std::thread( [ &count_done, &next, &zones ]( )
  164. {
  165. for( size_t i = next.fetch_add( 1 ); i < zones.size(); i = next.fetch_add( 1 ) )
  166. zones[i]->CacheTriangulation();
  167. count_done++;
  168. } );
  169. t.detach();
  170. }
  171. if( m_drawingSheet )
  172. m_drawingSheet->SetFileName( TO_UTF8( aBoard->GetFileName() ) );
  173. // Load drawings
  174. for( BOARD_ITEM* drawing : aBoard->Drawings() )
  175. m_view->Add( drawing );
  176. // Load tracks
  177. for( PCB_TRACK* track : aBoard->Tracks() )
  178. m_view->Add( track );
  179. // Load footprints and its additional elements
  180. for( FOOTPRINT* footprint : aBoard->Footprints() )
  181. m_view->Add( footprint );
  182. // DRC markers
  183. for( PCB_MARKER* marker : aBoard->Markers() )
  184. m_view->Add( marker );
  185. // Finalize the triangulation threads
  186. while( count_done < parallelThreadCount )
  187. {
  188. if( aReporter )
  189. aReporter->KeepRefreshing();
  190. std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) );
  191. }
  192. // Load zones
  193. for( ZONE* zone : aBoard->Zones() )
  194. m_view->Add( zone );
  195. // Ratsnest
  196. m_ratsnest = std::make_unique<RATSNEST_VIEW_ITEM>( aBoard->GetConnectivity() );
  197. m_view->Add( m_ratsnest.get() );
  198. }
  199. void PCB_DRAW_PANEL_GAL::SetDrawingSheet( DS_PROXY_VIEW_ITEM* aDrawingSheet )
  200. {
  201. m_drawingSheet.reset( aDrawingSheet );
  202. m_view->Add( m_drawingSheet.get() );
  203. }
  204. void PCB_DRAW_PANEL_GAL::UpdateColors()
  205. {
  206. COLOR_SETTINGS* cs = nullptr;
  207. PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() );
  208. if( frame )
  209. {
  210. cs = frame->GetColorSettings();
  211. }
  212. else
  213. {
  214. PCBNEW_SETTINGS* app = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
  215. if( app )
  216. cs = Pgm().GetSettingsManager().GetColorSettings( app->m_ColorTheme );
  217. else
  218. cs = Pgm().GetSettingsManager().GetColorSettings();
  219. }
  220. wxCHECK_RET( cs, "null COLOR_SETTINGS" );
  221. auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
  222. rs->LoadColors( cs );
  223. m_gal->SetGridColor( cs->GetColor( LAYER_GRID ) );
  224. m_gal->SetAxesColor( cs->GetColor( LAYER_GRID_AXES ) );
  225. m_gal->SetCursorColor( cs->GetColor( LAYER_CURSOR ) );
  226. }
  227. void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( PCB_LAYER_ID aLayer )
  228. {
  229. // Set display settings for high contrast mode
  230. KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
  231. SetTopLayer( aLayer );
  232. rSettings->SetActiveLayer( aLayer );
  233. rSettings->ClearHighContrastLayers();
  234. rSettings->SetLayerIsHighContrast( aLayer );
  235. if( IsCopperLayer( aLayer ) )
  236. {
  237. // Bring some other layers to the front in case of copper layers and make them colored
  238. // fixme do not like the idea of storing the list of layers here,
  239. // should be done in some other way I guess..
  240. LAYER_NUM layers[] = {
  241. GetNetnameLayer( aLayer ), LAYER_VIA_NETNAMES,
  242. LAYER_PAD_FR_NETNAMES, LAYER_PAD_BK_NETNAMES, LAYER_PAD_NETNAMES,
  243. ZONE_LAYER_FOR( aLayer ),
  244. LAYER_PADS_TH, LAYER_PAD_PLATEDHOLES, LAYER_PAD_HOLEWALLS, LAYER_NON_PLATEDHOLES,
  245. LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES,
  246. LAYER_VIA_HOLEWALLS,
  247. LAYER_DRC_ERROR, LAYER_DRC_WARNING, LAYER_DRC_EXCLUSION, LAYER_MARKER_SHADOWS,
  248. LAYER_SELECT_OVERLAY, LAYER_GP_OVERLAY,
  249. LAYER_RATSNEST, LAYER_CURSOR, LAYER_ANCHOR
  250. };
  251. for( unsigned int i : layers )
  252. rSettings->SetLayerIsHighContrast( i );
  253. // Pads should be shown too
  254. if( aLayer == B_Cu )
  255. {
  256. rSettings->SetLayerIsHighContrast( LAYER_PAD_BK );
  257. rSettings->SetLayerIsHighContrast( LAYER_MOD_BK );
  258. }
  259. else if( aLayer == F_Cu )
  260. {
  261. rSettings->SetLayerIsHighContrast( LAYER_PAD_FR );
  262. rSettings->SetLayerIsHighContrast( LAYER_MOD_FR );
  263. }
  264. }
  265. m_view->UpdateAllLayersColor();
  266. }
  267. void PCB_DRAW_PANEL_GAL::SetTopLayer( PCB_LAYER_ID aLayer )
  268. {
  269. m_view->ClearTopLayers();
  270. setDefaultLayerOrder();
  271. m_view->SetTopLayer( aLayer );
  272. // Layers that should always have on-top attribute enabled
  273. const std::vector<LAYER_NUM> layers = {
  274. LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES,
  275. LAYER_VIA_HOLEWALLS,
  276. LAYER_VIA_NETNAMES,
  277. LAYER_PADS_TH, LAYER_PAD_PLATEDHOLES, LAYER_PAD_HOLEWALLS, LAYER_NON_PLATEDHOLES,
  278. LAYER_PAD_NETNAMES,
  279. LAYER_SELECT_OVERLAY, LAYER_GP_OVERLAY,
  280. LAYER_RATSNEST,
  281. LAYER_DRC_ERROR, LAYER_DRC_WARNING, LAYER_DRC_EXCLUSION, LAYER_MARKER_SHADOWS
  282. };
  283. for( auto layer : layers )
  284. m_view->SetTopLayer( layer );
  285. // Extra layers that are brought to the top if a F.* or B.* is selected
  286. const std::vector<LAYER_NUM> frontLayers = {
  287. F_Cu, F_Adhes, F_Paste, F_SilkS, F_Mask, F_Fab, F_CrtYd, LAYER_PAD_FR,
  288. LAYER_PAD_FR_NETNAMES, NETNAMES_LAYER_INDEX( F_Cu )
  289. };
  290. const std::vector<LAYER_NUM> backLayers = {
  291. B_Cu, B_Adhes, B_Paste, B_SilkS, B_Mask, B_Fab, B_CrtYd, LAYER_PAD_BK,
  292. LAYER_PAD_BK_NETNAMES, NETNAMES_LAYER_INDEX( B_Cu )
  293. };
  294. const std::vector<LAYER_NUM>* extraLayers = nullptr;
  295. // Bring a few more extra layers to the top depending on the selected board side
  296. if( IsFrontLayer( aLayer ) )
  297. extraLayers = &frontLayers;
  298. else if( IsBackLayer( aLayer ) )
  299. extraLayers = &backLayers;
  300. if( extraLayers )
  301. {
  302. for( auto layer : *extraLayers )
  303. {
  304. m_view->SetTopLayer( layer );
  305. if( layer < PCB_LAYER_ID_COUNT )
  306. m_view->SetTopLayer( ZONE_LAYER_FOR( layer ) );
  307. }
  308. // Move the active layer to the top of the stack but below all the overlay layers
  309. if( !IsCopperLayer( aLayer ) )
  310. {
  311. m_view->SetLayerOrder( aLayer, m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 1 );
  312. m_view->SetLayerOrder( ZONE_LAYER_FOR( aLayer ),
  313. m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 2 );
  314. // Fix up pad and via netnames to be below. This is hacky, we need a rethink
  315. // of layer ordering...
  316. m_view->SetLayerOrder( LAYER_PAD_NETNAMES,
  317. m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 3 );
  318. m_view->SetLayerOrder( LAYER_VIA_NETNAMES,
  319. m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 4 );
  320. }
  321. }
  322. else if( IsCopperLayer( aLayer ) )
  323. {
  324. // Display labels for copper layers on the top
  325. m_view->SetTopLayer( GetNetnameLayer( aLayer ) );
  326. m_view->SetTopLayer( ZONE_LAYER_FOR( aLayer ) );
  327. }
  328. else
  329. {
  330. m_view->SetTopLayer( ZONE_LAYER_FOR( aLayer ) );
  331. }
  332. m_view->EnableTopLayer( true );
  333. m_view->UpdateAllLayersOrder();
  334. }
  335. void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard )
  336. {
  337. // Load layer & elements visibility settings
  338. for( LAYER_NUM i = 0; i < PCB_LAYER_ID_COUNT; ++i )
  339. m_view->SetLayerVisible( i, aBoard->IsLayerVisible( PCB_LAYER_ID( i ) ) );
  340. for( GAL_LAYER_ID i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; ++i )
  341. m_view->SetLayerVisible( i, aBoard->IsElementVisible( i ) );
  342. // Via layers controlled by dependencies
  343. m_view->SetLayerVisible( LAYER_VIA_MICROVIA, true );
  344. m_view->SetLayerVisible( LAYER_VIA_BBLIND, true );
  345. m_view->SetLayerVisible( LAYER_VIA_THROUGH, true );
  346. // Pad layers controlled by dependencies
  347. m_view->SetLayerVisible( LAYER_PAD_FR, true );
  348. m_view->SetLayerVisible( LAYER_PAD_BK, true );
  349. // Always enable netname layers, as their visibility is controlled by layer dependencies
  350. for( LAYER_NUM i = NETNAMES_LAYER_ID_START; i < NETNAMES_LAYER_ID_END; ++i )
  351. m_view->SetLayerVisible( i, true );
  352. for( LAYER_NUM i = LAYER_ZONE_START; i < LAYER_ZONE_END; i++ )
  353. m_view->SetLayerVisible( i, true );
  354. // Enable some layers that are GAL specific
  355. m_view->SetLayerVisible( LAYER_PAD_PLATEDHOLES, true );
  356. m_view->SetLayerVisible( LAYER_PAD_HOLEWALLS, true );
  357. m_view->SetLayerVisible( LAYER_VIA_HOLES, true );
  358. m_view->SetLayerVisible( LAYER_VIA_HOLEWALLS, true );
  359. m_view->SetLayerVisible( LAYER_GP_OVERLAY, true );
  360. m_view->SetLayerVisible( LAYER_SELECT_OVERLAY, true );
  361. m_view->SetLayerVisible( LAYER_RATSNEST, true );
  362. m_view->SetLayerVisible( LAYER_MARKER_SHADOWS, true );
  363. }
  364. void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
  365. std::vector<MSG_PANEL_ITEM>& aList )
  366. {
  367. BOARD* board = static_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() )->GetBoard();
  368. int padCount = 0;
  369. int viaCount = 0;
  370. int trackSegmentCount = 0;
  371. std::set<int> netCodes;
  372. int unconnected = board->GetConnectivity()->GetUnconnectedCount();
  373. for( PCB_TRACK* item : board->Tracks() )
  374. {
  375. if( item->Type() == PCB_VIA_T )
  376. viaCount++;
  377. else
  378. trackSegmentCount++;
  379. if( item->GetNetCode() > 0 )
  380. netCodes.insert( item->GetNetCode() );
  381. }
  382. for( FOOTPRINT* footprint : board->Footprints() )
  383. {
  384. for( PAD* pad : footprint->Pads() )
  385. {
  386. padCount++;
  387. if( pad->GetNetCode() > 0 )
  388. netCodes.insert( pad->GetNetCode() );
  389. }
  390. }
  391. aList.emplace_back( _( "Pads" ), wxString::Format( "%d", padCount ) );
  392. aList.emplace_back( _( "Vias" ), wxString::Format( "%d", viaCount ) );
  393. aList.emplace_back( _( "Track Segments" ), wxString::Format( "%d", trackSegmentCount ) );
  394. aList.emplace_back( _( "Nets" ), wxString::Format( "%d", (int) netCodes.size() ) );
  395. aList.emplace_back( _( "Unrouted" ), wxString::Format( "%d", unconnected ) );
  396. }
  397. void PCB_DRAW_PANEL_GAL::OnShow()
  398. {
  399. PCB_BASE_FRAME* frame = nullptr;
  400. if( !IsDialogPreview() )
  401. frame = dynamic_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() );
  402. try
  403. {
  404. // Check if the current rendering back end can be properly initialized
  405. m_view->UpdateItems();
  406. }
  407. catch( const std::runtime_error& e )
  408. {
  409. DisplayError( GetParent(), e.what() );
  410. // Use the fallback if we have one
  411. if( GAL_FALLBACK != m_backend )
  412. {
  413. SwitchBackend( GAL_FALLBACK );
  414. if( frame )
  415. frame->ActivateGalCanvas();
  416. }
  417. }
  418. if( frame )
  419. {
  420. SetTopLayer( frame->GetActiveLayer() );
  421. KIGFX::PAINTER* painter = m_view->GetPainter();
  422. auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
  423. settings->LoadDisplayOptions( frame->GetDisplayOptions(), frame->ShowPageLimits() );
  424. }
  425. }
  426. void PCB_DRAW_PANEL_GAL::setDefaultLayerOrder()
  427. {
  428. for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
  429. {
  430. LAYER_NUM layer = GAL_LAYER_ORDER[i];
  431. wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
  432. m_view->SetLayerOrder( layer, i );
  433. }
  434. }
  435. bool PCB_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
  436. {
  437. bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
  438. setDefaultLayerDeps();
  439. m_gal->SetWorldUnitLength( 1e-9 /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
  440. return rv;
  441. }
  442. void PCB_DRAW_PANEL_GAL::RedrawRatsnest()
  443. {
  444. if( m_ratsnest )
  445. m_view->Update( m_ratsnest.get() );
  446. }
  447. BOX2I PCB_DRAW_PANEL_GAL::GetDefaultViewBBox() const
  448. {
  449. if( m_drawingSheet && m_view->IsLayerVisible( LAYER_DRAWINGSHEET ) )
  450. return m_drawingSheet->ViewBBox();
  451. return BOX2I();
  452. }
  453. void PCB_DRAW_PANEL_GAL::setDefaultLayerDeps()
  454. {
  455. // caching makes no sense for Cairo and other software renderers
  456. auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
  457. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  458. m_view->SetLayerTarget( i, target );
  459. for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
  460. {
  461. LAYER_NUM layer = GAL_LAYER_ORDER[i];
  462. wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
  463. // Set layer display dependencies & targets
  464. if( IsCopperLayer( layer ) )
  465. {
  466. m_view->SetRequired( ZONE_LAYER_FOR( layer ), layer );
  467. m_view->SetRequired( GetNetnameLayer( layer ), layer );
  468. }
  469. else if( IsNonCopperLayer( layer ) )
  470. {
  471. m_view->SetRequired( ZONE_LAYER_FOR( layer ), layer );
  472. }
  473. else if( IsNetnameLayer( layer ) )
  474. {
  475. m_view->SetLayerDisplayOnly( layer );
  476. }
  477. }
  478. m_view->SetLayerTarget( LAYER_ANCHOR, KIGFX::TARGET_NONCACHED );
  479. m_view->SetLayerDisplayOnly( LAYER_ANCHOR );
  480. // Some more required layers settings
  481. m_view->SetRequired( LAYER_VIA_NETNAMES, LAYER_VIAS );
  482. m_view->SetRequired( LAYER_PAD_NETNAMES, LAYER_PADS );
  483. // Holes can be independent of their host objects (cf: printing drill marks)
  484. m_view->SetRequired( LAYER_VIA_HOLES, LAYER_VIAS );
  485. m_view->SetRequired( LAYER_VIA_HOLEWALLS, LAYER_VIAS );
  486. m_view->SetRequired( LAYER_PAD_PLATEDHOLES, LAYER_PADS );
  487. m_view->SetRequired( LAYER_PAD_HOLEWALLS, LAYER_PADS );
  488. m_view->SetRequired( LAYER_NON_PLATEDHOLES, LAYER_PADS );
  489. // Via visibility
  490. m_view->SetRequired( LAYER_VIA_MICROVIA, LAYER_VIAS );
  491. m_view->SetRequired( LAYER_VIA_BBLIND, LAYER_VIAS );
  492. m_view->SetRequired( LAYER_VIA_THROUGH, LAYER_VIAS );
  493. // Pad visibility
  494. m_view->SetRequired( LAYER_PADS_TH, LAYER_PADS );
  495. m_view->SetRequired( LAYER_PAD_FR, LAYER_PADS );
  496. m_view->SetRequired( LAYER_PAD_BK, LAYER_PADS );
  497. // Front footprints
  498. m_view->SetRequired( LAYER_PAD_FR, F_Cu );
  499. m_view->SetRequired( LAYER_PAD_FR_NETNAMES, LAYER_PAD_FR );
  500. // Back footprints
  501. m_view->SetRequired( LAYER_PAD_BK, B_Cu );
  502. m_view->SetRequired( LAYER_PAD_BK_NETNAMES, LAYER_PAD_BK );
  503. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
  504. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
  505. m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
  506. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
  507. m_view->SetLayerTarget( LAYER_RATSNEST, KIGFX::TARGET_OVERLAY );
  508. m_view->SetLayerDisplayOnly( LAYER_RATSNEST );
  509. m_view->SetLayerTarget( LAYER_DRC_ERROR, KIGFX::TARGET_OVERLAY );
  510. m_view->SetLayerDisplayOnly( LAYER_DRC_ERROR );
  511. m_view->SetLayerTarget( LAYER_DRC_WARNING, KIGFX::TARGET_OVERLAY );
  512. m_view->SetLayerDisplayOnly( LAYER_DRC_WARNING );
  513. m_view->SetLayerTarget( LAYER_DRC_EXCLUSION, KIGFX::TARGET_OVERLAY );
  514. m_view->SetLayerDisplayOnly( LAYER_DRC_EXCLUSION );
  515. m_view->SetLayerTarget( LAYER_MARKER_SHADOWS, KIGFX::TARGET_OVERLAY );
  516. m_view->SetLayerDisplayOnly( LAYER_MARKER_SHADOWS );
  517. m_view->SetLayerTarget( LAYER_DRAWINGSHEET, KIGFX::TARGET_NONCACHED );
  518. m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
  519. m_view->SetLayerDisplayOnly( LAYER_GRID );
  520. }
  521. KIGFX::PCB_VIEW* PCB_DRAW_PANEL_GAL::GetView() const
  522. {
  523. return static_cast<KIGFX::PCB_VIEW*>( m_view );
  524. }