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.

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