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.

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