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.

745 lines
26 KiB

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