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.

1281 lines
36 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
4 years ago
17 years ago
17 years ago
18 years ago
18 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
18 years ago
4 years ago
4 years ago
4 years ago
4 years ago
18 years ago
18 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 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) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <pcb_base_frame.h>
  27. #include <core/mirror.h>
  28. #include <connectivity/connectivity_data.h>
  29. #include <board.h>
  30. #include <board_design_settings.h>
  31. #include <convert_basic_shapes_to_polygon.h>
  32. #include <pcb_track.h>
  33. #include <base_units.h>
  34. #include <bitmaps.h>
  35. #include <string_utils.h>
  36. #include <view/view.h>
  37. #include <settings/color_settings.h>
  38. #include <settings/settings_manager.h>
  39. #include <i18n_utility.h>
  40. #include <geometry/seg.h>
  41. #include <geometry/shape_segment.h>
  42. #include <geometry/shape_circle.h>
  43. #include <geometry/shape_arc.h>
  44. #include <drc/drc_engine.h>
  45. #include <pcb_painter.h>
  46. #include <trigo.h>
  47. using KIGFX::PCB_PAINTER;
  48. using KIGFX::PCB_RENDER_SETTINGS;
  49. PCB_TRACK::PCB_TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) :
  50. BOARD_CONNECTED_ITEM( aParent, idtype )
  51. {
  52. m_Width = pcbIUScale.mmToIU( 0.2 ); // Gives a reasonable default width
  53. }
  54. EDA_ITEM* PCB_TRACK::Clone() const
  55. {
  56. return new PCB_TRACK( *this );
  57. }
  58. PCB_ARC::PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ) :
  59. PCB_TRACK( aParent, PCB_ARC_T )
  60. {
  61. m_Start = aArc->GetP0();
  62. m_End = aArc->GetP1();
  63. m_Mid = aArc->GetArcMid();
  64. }
  65. EDA_ITEM* PCB_ARC::Clone() const
  66. {
  67. return new PCB_ARC( *this );
  68. }
  69. PCB_VIA::PCB_VIA( BOARD_ITEM* aParent ) :
  70. PCB_TRACK( aParent, PCB_VIA_T )
  71. {
  72. SetViaType( VIATYPE::THROUGH );
  73. m_bottomLayer = B_Cu;
  74. SetDrillDefault();
  75. m_removeUnconnectedLayer = false;
  76. m_keepTopBottomLayer = true;
  77. m_isFree = false;
  78. }
  79. EDA_ITEM* PCB_VIA::Clone() const
  80. {
  81. return new PCB_VIA( *this );
  82. }
  83. wxString PCB_VIA::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
  84. {
  85. wxString formatStr;
  86. switch( GetViaType() )
  87. {
  88. case VIATYPE::BLIND_BURIED: formatStr = _( "Blind/Buried Via %s on %s" ); break;
  89. case VIATYPE::MICROVIA: formatStr = _( "Micro Via %s on %s" ); break;
  90. default: formatStr = _( "Via %s on %s" ); break;
  91. }
  92. return wxString::Format( formatStr,
  93. GetNetnameMsg(),
  94. layerMaskDescribe() );
  95. }
  96. BITMAPS PCB_VIA::GetMenuImage() const
  97. {
  98. return BITMAPS::via;
  99. }
  100. bool PCB_TRACK::ApproxCollinear( const PCB_TRACK& aTrack )
  101. {
  102. SEG a( m_Start, m_End );
  103. SEG b( aTrack.GetStart(), aTrack.GetEnd() );
  104. return a.ApproxCollinear( b );
  105. }
  106. int PCB_TRACK::GetLocalClearance( wxString* aSource ) const
  107. {
  108. // Not currently implemented
  109. return 0;
  110. }
  111. MINOPTMAX<int> PCB_TRACK::GetWidthConstraint( wxString* aSource ) const
  112. {
  113. DRC_CONSTRAINT constraint;
  114. if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
  115. {
  116. BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
  117. constraint = bds.m_DRCEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, this, nullptr, m_layer );
  118. }
  119. if( aSource )
  120. *aSource = constraint.GetName();
  121. return constraint.Value();
  122. }
  123. int PCB_VIA::GetMinAnnulus( PCB_LAYER_ID aLayer, wxString* aSource ) const
  124. {
  125. if( !FlashLayer( aLayer ) )
  126. {
  127. if( aSource )
  128. *aSource = _( "removed annular ring" );
  129. return 0;
  130. }
  131. DRC_CONSTRAINT constraint;
  132. if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
  133. {
  134. BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
  135. constraint = bds.m_DRCEngine->EvalRules( ANNULAR_WIDTH_CONSTRAINT, this, nullptr, aLayer );
  136. }
  137. if( constraint.Value().HasMin() )
  138. {
  139. if( aSource )
  140. *aSource = constraint.GetName();
  141. return constraint.Value().Min();
  142. }
  143. return 0;
  144. }
  145. int PCB_VIA::GetDrillValue() const
  146. {
  147. if( m_drill > 0 ) // Use the specific value.
  148. return m_drill;
  149. // Use the default value from the Netclass
  150. NETCLASS* netclass = GetEffectiveNetClass();
  151. if( GetViaType() == VIATYPE::MICROVIA )
  152. return netclass->GetuViaDrill();
  153. return netclass->GetViaDrill();
  154. }
  155. EDA_ITEM_FLAGS PCB_TRACK::IsPointOnEnds( const VECTOR2I& point, int min_dist ) const
  156. {
  157. EDA_ITEM_FLAGS result = 0;
  158. if( min_dist < 0 )
  159. min_dist = m_Width / 2;
  160. if( min_dist == 0 )
  161. {
  162. if( m_Start == point )
  163. result |= STARTPOINT;
  164. if( m_End == point )
  165. result |= ENDPOINT;
  166. }
  167. else
  168. {
  169. double dist = GetLineLength( m_Start, point );
  170. if( min_dist >= KiROUND( dist ) )
  171. result |= STARTPOINT;
  172. dist = GetLineLength( m_End, point );
  173. if( min_dist >= KiROUND( dist ) )
  174. result |= ENDPOINT;
  175. }
  176. return result;
  177. }
  178. const BOX2I PCB_TRACK::GetBoundingBox() const
  179. {
  180. // end of track is round, this is its radius, rounded up
  181. int radius = ( m_Width + 1 ) / 2;
  182. int ymax, xmax, ymin, xmin;
  183. if( Type() == PCB_VIA_T )
  184. {
  185. ymax = m_Start.y;
  186. xmax = m_Start.x;
  187. ymin = m_Start.y;
  188. xmin = m_Start.x;
  189. }
  190. else if( Type() == PCB_ARC_T )
  191. {
  192. std::shared_ptr<SHAPE> arc = GetEffectiveShape();
  193. BOX2I bbox = arc->BBox();
  194. xmin = bbox.GetLeft();
  195. xmax = bbox.GetRight();
  196. ymin = bbox.GetTop();
  197. ymax = bbox.GetBottom();
  198. }
  199. else
  200. {
  201. ymax = std::max( m_Start.y, m_End.y );
  202. xmax = std::max( m_Start.x, m_End.x );
  203. ymin = std::min( m_Start.y, m_End.y );
  204. xmin = std::min( m_Start.x, m_End.x );
  205. }
  206. ymax += radius;
  207. xmax += radius;
  208. ymin -= radius;
  209. xmin -= radius;
  210. // return a rectangle which is [pos,dim) in nature. therefore the +1
  211. BOX2I ret( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin + 1, ymax - ymin + 1 ) );
  212. return ret;
  213. }
  214. double PCB_TRACK::GetLength() const
  215. {
  216. return GetLineLength( m_Start, m_End );
  217. }
  218. void PCB_TRACK::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  219. {
  220. RotatePoint( m_Start, aRotCentre, aAngle );
  221. RotatePoint( m_End, aRotCentre, aAngle );
  222. }
  223. void PCB_ARC::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  224. {
  225. RotatePoint( m_Start, aRotCentre, aAngle );
  226. RotatePoint( m_End, aRotCentre, aAngle );
  227. RotatePoint( m_Mid, aRotCentre, aAngle );
  228. }
  229. void PCB_TRACK::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
  230. {
  231. if( aMirrorAroundXAxis )
  232. {
  233. MIRROR( m_Start.y, aCentre.y );
  234. MIRROR( m_End.y, aCentre.y );
  235. }
  236. else
  237. {
  238. MIRROR( m_Start.x, aCentre.x );
  239. MIRROR( m_End.x, aCentre.x );
  240. }
  241. }
  242. void PCB_ARC::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
  243. {
  244. if( aMirrorAroundXAxis )
  245. {
  246. MIRROR( m_Start.y, aCentre.y );
  247. MIRROR( m_End.y, aCentre.y );
  248. MIRROR( m_Mid.y, aCentre.y );
  249. }
  250. else
  251. {
  252. MIRROR( m_Start.x, aCentre.x );
  253. MIRROR( m_End.x, aCentre.x );
  254. MIRROR( m_Mid.x, aCentre.x );
  255. }
  256. }
  257. void PCB_TRACK::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  258. {
  259. if( aFlipLeftRight )
  260. {
  261. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  262. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  263. }
  264. else
  265. {
  266. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  267. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  268. }
  269. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  270. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  271. }
  272. void PCB_ARC::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  273. {
  274. if( aFlipLeftRight )
  275. {
  276. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  277. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  278. m_Mid.x = aCentre.x - ( m_Mid.x - aCentre.x );
  279. }
  280. else
  281. {
  282. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  283. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  284. m_Mid.y = aCentre.y - ( m_Mid.y - aCentre.y );
  285. }
  286. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  287. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  288. }
  289. bool PCB_ARC::IsCCW() const
  290. {
  291. VECTOR2I start_end = m_End - m_Start;
  292. VECTOR2I start_mid = m_Mid - m_Start;
  293. return start_end.Cross( start_mid ) < 0;
  294. }
  295. void PCB_VIA::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  296. {
  297. if( aFlipLeftRight )
  298. {
  299. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  300. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  301. }
  302. else
  303. {
  304. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  305. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  306. }
  307. if( GetViaType() != VIATYPE::THROUGH )
  308. {
  309. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  310. PCB_LAYER_ID top_layer;
  311. PCB_LAYER_ID bottom_layer;
  312. LayerPair( &top_layer, &bottom_layer );
  313. top_layer = FlipLayer( top_layer, copperLayerCount );
  314. bottom_layer = FlipLayer( bottom_layer, copperLayerCount );
  315. SetLayerPair( top_layer, bottom_layer );
  316. }
  317. }
  318. // see class_track.h
  319. INSPECT_RESULT PCB_TRACK::Visit( INSPECTOR inspector, void* testData,
  320. const std::vector<KICAD_T>& aScanTypes )
  321. {
  322. for( KICAD_T scanType : aScanTypes )
  323. {
  324. if( scanType == Type() )
  325. {
  326. if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
  327. return INSPECT_RESULT::QUIT;
  328. }
  329. }
  330. return INSPECT_RESULT::CONTINUE;
  331. }
  332. std::shared_ptr<SHAPE_SEGMENT> PCB_VIA::GetEffectiveHoleShape() const
  333. {
  334. return std::make_shared<SHAPE_SEGMENT>( SEG( m_Start, m_Start ), m_drill );
  335. }
  336. bool PCB_VIA::IsTented() const
  337. {
  338. const BOARD* board = GetBoard();
  339. if( board )
  340. return board->GetTentVias();
  341. else
  342. return true;
  343. }
  344. int PCB_VIA::GetSolderMaskExpansion() const
  345. {
  346. const BOARD* board = GetBoard();
  347. if( board )
  348. return board->GetDesignSettings().m_SolderMaskExpansion;
  349. else
  350. return 0;
  351. }
  352. bool PCB_VIA::IsOnLayer( PCB_LAYER_ID aLayer ) const
  353. {
  354. #if 0
  355. // Nice and simple, but raises its ugly head in performance profiles....
  356. return GetLayerSet().test( aLayer );
  357. #endif
  358. if( aLayer >= m_layer && aLayer <= m_bottomLayer )
  359. return true;
  360. if( !IsTented() )
  361. {
  362. if( aLayer == F_Mask )
  363. return IsOnLayer( F_Cu );
  364. else if( aLayer == B_Mask )
  365. return IsOnLayer( B_Cu );
  366. }
  367. return false;
  368. }
  369. LSET PCB_VIA::GetLayerSet() const
  370. {
  371. LSET layermask;
  372. if( GetViaType() == VIATYPE::THROUGH )
  373. layermask = LSET::AllCuMask();
  374. else
  375. wxASSERT( m_layer <= m_bottomLayer );
  376. // PCB_LAYER_IDs are numbered from front to back, this is top to bottom.
  377. for( int id = m_layer; id <= m_bottomLayer; ++id )
  378. layermask.set( id );
  379. if( !IsTented() )
  380. {
  381. if( layermask.test( F_Cu ) )
  382. layermask.set( F_Mask );
  383. if( layermask.test( B_Cu ) )
  384. layermask.set( B_Mask );
  385. }
  386. return layermask;
  387. }
  388. void PCB_VIA::SetLayerSet( LSET aLayerSet )
  389. {
  390. bool first = true;
  391. for( PCB_LAYER_ID layer : aLayerSet.Seq() )
  392. {
  393. if( first )
  394. {
  395. m_layer = layer;
  396. first = false;
  397. }
  398. m_bottomLayer = layer;
  399. }
  400. }
  401. void PCB_VIA::SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer )
  402. {
  403. m_layer = aTopLayer;
  404. m_bottomLayer = aBottomLayer;
  405. SanitizeLayers();
  406. }
  407. void PCB_VIA::SetTopLayer( PCB_LAYER_ID aLayer )
  408. {
  409. m_layer = aLayer;
  410. }
  411. void PCB_VIA::SetBottomLayer( PCB_LAYER_ID aLayer )
  412. {
  413. m_bottomLayer = aLayer;
  414. }
  415. void PCB_VIA::LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const
  416. {
  417. PCB_LAYER_ID t_layer = F_Cu;
  418. PCB_LAYER_ID b_layer = B_Cu;
  419. if( GetViaType() != VIATYPE::THROUGH )
  420. {
  421. b_layer = m_bottomLayer;
  422. t_layer = m_layer;
  423. if( b_layer < t_layer )
  424. std::swap( b_layer, t_layer );
  425. }
  426. if( top_layer )
  427. *top_layer = t_layer;
  428. if( bottom_layer )
  429. *bottom_layer = b_layer;
  430. }
  431. PCB_LAYER_ID PCB_VIA::TopLayer() const
  432. {
  433. return m_layer;
  434. }
  435. PCB_LAYER_ID PCB_VIA::BottomLayer() const
  436. {
  437. return m_bottomLayer;
  438. }
  439. void PCB_VIA::SanitizeLayers()
  440. {
  441. if( GetViaType() == VIATYPE::THROUGH )
  442. {
  443. m_layer = F_Cu;
  444. m_bottomLayer = B_Cu;
  445. }
  446. if( m_bottomLayer < m_layer )
  447. std::swap( m_bottomLayer, m_layer );
  448. }
  449. bool PCB_VIA::FlashLayer( LSET aLayers ) const
  450. {
  451. for( auto layer : aLayers.Seq() )
  452. {
  453. if( FlashLayer( layer ) )
  454. return true;
  455. }
  456. return false;
  457. }
  458. bool PCB_VIA::FlashLayer( int aLayer ) const
  459. {
  460. // Return the "normal" shape if the caller doesn't specify a particular layer
  461. if( aLayer == UNDEFINED_LAYER )
  462. return true;
  463. const BOARD* board = GetBoard();
  464. if( !board )
  465. return true;
  466. if( !IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) ) )
  467. return false;
  468. if( !m_removeUnconnectedLayer )
  469. return true;
  470. if( m_keepTopBottomLayer && ( aLayer == m_layer || aLayer == m_bottomLayer ) )
  471. return true;
  472. // Must be static to keep from raising its ugly head in performance profiles
  473. static std::initializer_list<KICAD_T> connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
  474. PCB_PAD_T };
  475. // Do not check zones. Doing so results in race conditions when the via collides with
  476. // two different zones of different priorities.
  477. // See https://gitlab.com/kicad/code/kicad/-/issues/11299.
  478. return board->GetConnectivity()->IsConnectedOnLayer( this, aLayer, connectedTypes, true );
  479. }
  480. void PCB_TRACK::ViewGetLayers( int aLayers[], int& aCount ) const
  481. {
  482. // Show the track and its netname on different layers
  483. aLayers[0] = GetLayer();
  484. aLayers[1] = GetNetnameLayer( aLayers[0] );
  485. aCount = 2;
  486. if( IsLocked() )
  487. aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
  488. }
  489. double PCB_TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  490. {
  491. constexpr double HIDE = std::numeric_limits<double>::max();
  492. PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
  493. PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
  494. if( !aView->IsLayerVisible( LAYER_TRACKS ) )
  495. return HIDE;
  496. if( IsNetnameLayer( aLayer ) )
  497. {
  498. if( GetNetCode() <= NETINFO_LIST::UNCONNECTED )
  499. return HIDE;
  500. // Hide netnames on dimmed tracks
  501. if( renderSettings->GetHighContrast() )
  502. {
  503. if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
  504. return HIDE;
  505. }
  506. // When drawing netnames, clip the track to the viewport
  507. VECTOR2I start( GetStart() );
  508. VECTOR2I end( GetEnd() );
  509. BOX2D viewport = aView->GetViewport();
  510. BOX2I clipBox( viewport.GetOrigin(), viewport.GetSize() );
  511. ClipLine( &clipBox, start.x, start.y, end.x, end.y );
  512. VECTOR2I line = ( end - start );
  513. double length = line.EuclideanNorm();
  514. // Check if the track is long enough to have a netname displayed
  515. if( length < 6 * GetWidth() )
  516. return HIDE;
  517. // Netnames will be shown only if zoom is appropriate
  518. return ( double ) pcbIUScale.mmToIU( 4 ) / ( m_Width + 1 );
  519. }
  520. if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
  521. {
  522. // Hide shadow if the main layer is not shown
  523. if( !aView->IsLayerVisible( m_layer ) )
  524. return HIDE;
  525. // Hide shadow on dimmed tracks
  526. if( renderSettings->GetHighContrast() )
  527. {
  528. if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
  529. return HIDE;
  530. }
  531. }
  532. // Other layers are shown without any conditions
  533. return 0.0;
  534. }
  535. const BOX2I PCB_TRACK::ViewBBox() const
  536. {
  537. BOX2I bbox = GetBoundingBox();
  538. const BOARD* board = GetBoard();
  539. if( board )
  540. bbox.Inflate( 2 * board->GetDesignSettings().GetBiggestClearanceValue() );
  541. else
  542. bbox.Inflate( GetWidth() ); // Add a bit extra for safety
  543. return bbox;
  544. }
  545. void PCB_VIA::ViewGetLayers( int aLayers[], int& aCount ) const
  546. {
  547. aLayers[0] = LAYER_VIA_HOLES;
  548. aLayers[1] = LAYER_VIA_HOLEWALLS;
  549. aLayers[2] = LAYER_VIA_NETNAMES;
  550. // Just show it on common via & via holes layers
  551. switch( GetViaType() )
  552. {
  553. case VIATYPE::THROUGH: aLayers[3] = LAYER_VIA_THROUGH; break;
  554. case VIATYPE::BLIND_BURIED: aLayers[3] = LAYER_VIA_BBLIND; break;
  555. case VIATYPE::MICROVIA: aLayers[3] = LAYER_VIA_MICROVIA; break;
  556. default: aLayers[3] = LAYER_GP_OVERLAY; break;
  557. }
  558. aCount = 4;
  559. if( IsLocked() )
  560. aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
  561. }
  562. double PCB_VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  563. {
  564. constexpr double HIDE = (double)std::numeric_limits<double>::max();
  565. PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
  566. PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
  567. const BOARD* board = GetBoard();
  568. LSET visible = LSET::AllLayersMask();
  569. // Meta control for hiding all vias
  570. if( !aView->IsLayerVisible( LAYER_VIAS ) )
  571. return HIDE;
  572. // Handle board visibility
  573. if( board )
  574. visible = board->GetVisibleLayers() & board->GetEnabledLayers();
  575. // In high contrast mode don't show vias that don't cross the high-contrast layer
  576. if( renderSettings->GetHighContrast() )
  577. {
  578. PCB_LAYER_ID highContrastLayer = renderSettings->GetPrimaryHighContrastLayer();
  579. if( LSET::FrontTechMask().Contains( highContrastLayer ) )
  580. highContrastLayer = F_Cu;
  581. else if( LSET::BackTechMask().Contains( highContrastLayer ) )
  582. highContrastLayer = B_Cu;
  583. if( !GetLayerSet().Contains( highContrastLayer ) )
  584. return HIDE;
  585. }
  586. if( IsViaPadLayer( aLayer ) )
  587. {
  588. if( !FlashLayer( visible ) )
  589. return HIDE;
  590. }
  591. else if( IsHoleLayer( aLayer ) )
  592. {
  593. if( m_viaType == VIATYPE::BLIND_BURIED || m_viaType == VIATYPE::MICROVIA )
  594. {
  595. // Show a blind or micro via's hole if it crosses a visible layer
  596. if( !( visible & GetLayerSet() ).any() )
  597. return HIDE;
  598. }
  599. else
  600. {
  601. // Show a through via's hole if any physical layer is shown
  602. if( !( visible & LSET::PhysicalLayersMask() ).any() )
  603. return HIDE;
  604. }
  605. }
  606. else if( IsNetnameLayer( aLayer ) )
  607. {
  608. if( renderSettings->GetHighContrast() )
  609. {
  610. // Hide netnames unless via is flashed to a high-contrast layer
  611. if( !FlashLayer( renderSettings->GetPrimaryHighContrastLayer() ) )
  612. return HIDE;
  613. }
  614. else
  615. {
  616. // Hide netnames unless pad is flashed to a visible layer
  617. if( !FlashLayer( visible ) )
  618. return HIDE;
  619. }
  620. // Netnames will be shown only if zoom is appropriate
  621. return m_Width == 0 ? HIDE : ( (double)pcbIUScale.mmToIU( 10 ) / m_Width );
  622. }
  623. // Passed all tests; show.
  624. return 0.0;
  625. }
  626. // see class_track.h
  627. void PCB_TRACK::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  628. {
  629. wxString msg;
  630. BOARD* board = GetBoard();
  631. aList.emplace_back( _( "Type" ),
  632. Type() == PCB_ARC_T ? _( "Track (arc)" ) : _( "Track" ) );
  633. GetMsgPanelInfoBase_Common( aFrame, aList );
  634. aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
  635. aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( m_Width ) );
  636. if( Type() == PCB_ARC_T )
  637. {
  638. double radius = static_cast<PCB_ARC*>( this )->GetRadius();
  639. aList.emplace_back( _( "Radius" ), aFrame->MessageTextFromValue( radius ) );
  640. }
  641. aList.emplace_back( _( "Segment Length" ), aFrame->MessageTextFromValue( GetLength() ) );
  642. // Display full track length (in Pcbnew)
  643. if( board && GetNetCode() > 0 )
  644. {
  645. int count;
  646. double trackLen;
  647. double lenPadToDie;
  648. std::tie( count, trackLen, lenPadToDie ) = board->GetTrackLength( *this );
  649. aList.emplace_back( _( "Routed Length" ), aFrame->MessageTextFromValue( trackLen ) );
  650. if( lenPadToDie != 0 )
  651. {
  652. msg = aFrame->MessageTextFromValue( lenPadToDie );
  653. aList.emplace_back( _( "Pad To Die Length" ), msg );
  654. msg = aFrame->MessageTextFromValue( trackLen + lenPadToDie );
  655. aList.emplace_back( _( "Full Length" ), msg );
  656. }
  657. }
  658. wxString source;
  659. int clearance = GetOwnClearance( GetLayer(), &source );
  660. aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
  661. aFrame->MessageTextFromValue( clearance ) ),
  662. wxString::Format( _( "(from %s)" ), source ) );
  663. MINOPTMAX<int> c = GetWidthConstraint( &source );
  664. if( c.HasMax() )
  665. {
  666. aList.emplace_back( wxString::Format( _( "Width Constraints: min %s, max %s" ),
  667. aFrame->MessageTextFromValue( c.Min() ),
  668. aFrame->MessageTextFromValue( c.Max() ) ),
  669. wxString::Format( _( "(from %s)" ), source ) );
  670. }
  671. else
  672. {
  673. aList.emplace_back( wxString::Format( _( "Width Constraints: min %s" ),
  674. aFrame->MessageTextFromValue( c.Min() ) ),
  675. wxString::Format( _( "(from %s)" ), source ) );
  676. }
  677. }
  678. void PCB_VIA::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  679. {
  680. wxString msg;
  681. switch( GetViaType() )
  682. {
  683. case VIATYPE::MICROVIA: msg = _( "Micro Via" ); break;
  684. case VIATYPE::BLIND_BURIED: msg = _( "Blind/Buried Via" ); break;
  685. case VIATYPE::THROUGH: msg = _( "Through Via" ); break;
  686. default: msg = _( "Via" ); break;
  687. }
  688. aList.emplace_back( _( "Type" ), msg );
  689. GetMsgPanelInfoBase_Common( aFrame, aList );
  690. aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
  691. aList.emplace_back( _( "Diameter" ), aFrame->MessageTextFromValue( m_Width ) );
  692. aList.emplace_back( _( "Hole" ), aFrame->MessageTextFromValue( GetDrillValue() ) );
  693. wxString source;
  694. int clearance = GetOwnClearance( GetLayer(), &source );
  695. aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
  696. aFrame->MessageTextFromValue( clearance ) ),
  697. wxString::Format( _( "(from %s)" ), source ) );
  698. int minAnnulus = GetMinAnnulus( GetLayer(), &source );
  699. aList.emplace_back( wxString::Format( _( "Min Annular Width: %s" ),
  700. aFrame->MessageTextFromValue( minAnnulus ) ),
  701. wxString::Format( _( "(from %s)" ), source ) );
  702. }
  703. void PCB_TRACK::GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame,
  704. std::vector<MSG_PANEL_ITEM>& aList ) const
  705. {
  706. aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
  707. aList.emplace_back( _( "Resolved Netclass" ),
  708. UnescapeString( GetEffectiveNetClass()->GetName() ) );
  709. #if 0 // Enable for debugging
  710. if( GetBoard() )
  711. aList.emplace_back( _( "NetCode" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
  712. aList.emplace_back( wxT( "Flags" ), wxString::Format( wxT( "0x%08X" ), m_flags ) );
  713. aList.emplace_back( wxT( "Start pos" ), wxString::Format( wxT( "%d %d" ),
  714. m_Start.x,
  715. m_Start.y ) );
  716. aList.emplace_back( wxT( "End pos" ), wxString::Format( wxT( "%d %d" ),
  717. m_End.x,
  718. m_End.y ) );
  719. #endif
  720. if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
  721. aList.emplace_back( _( "Status" ), _( "Locked" ) );
  722. }
  723. wxString PCB_VIA::layerMaskDescribe() const
  724. {
  725. const BOARD* board = GetBoard();
  726. PCB_LAYER_ID top_layer;
  727. PCB_LAYER_ID bottom_layer;
  728. LayerPair( &top_layer, &bottom_layer );
  729. return board->GetLayerName( top_layer ) + wxT( " - " ) + board->GetLayerName( bottom_layer );
  730. }
  731. bool PCB_TRACK::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  732. {
  733. return TestSegmentHit( aPosition, m_Start, m_End, aAccuracy + ( m_Width / 2 ) );
  734. }
  735. bool PCB_ARC::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  736. {
  737. int max_dist = aAccuracy + ( m_Width / 2 );
  738. // Short-circuit common cases where the arc is connected to a track or via at an endpoint
  739. if( EuclideanNorm( GetStart() - aPosition ) <= max_dist ||
  740. EuclideanNorm( GetEnd() - aPosition ) <= max_dist )
  741. {
  742. return true;
  743. }
  744. VECTOR2I center = GetPosition();
  745. VECTOR2I relpos = aPosition - center;
  746. double dist = EuclideanNorm( relpos );
  747. double radius = GetRadius();
  748. if( std::abs( dist - radius ) > max_dist )
  749. return false;
  750. EDA_ANGLE arc_angle = GetAngle();
  751. EDA_ANGLE arc_angle_start = GetArcAngleStart(); // Always 0.0 ... 360 deg
  752. EDA_ANGLE arc_hittest( relpos );
  753. // Calculate relative angle between the starting point of the arc, and the test point
  754. arc_hittest -= arc_angle_start;
  755. // Normalise arc_hittest between 0 ... 360 deg
  756. arc_hittest.Normalize();
  757. if( arc_angle < ANGLE_0 )
  758. return arc_hittest >= ANGLE_360 + arc_angle;
  759. return arc_hittest <= arc_angle;
  760. }
  761. bool PCB_VIA::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  762. {
  763. int max_dist = aAccuracy + ( m_Width / 2 );
  764. // rel_pos is aPosition relative to m_Start (or the center of the via)
  765. VECTOR2I rel_pos = aPosition - m_Start;
  766. double dist = (double) rel_pos.x * rel_pos.x + (double) rel_pos.y * rel_pos.y;
  767. return dist <= (double) max_dist * max_dist;
  768. }
  769. bool PCB_TRACK::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  770. {
  771. BOX2I arect = aRect;
  772. arect.Inflate( aAccuracy );
  773. if( aContained )
  774. return arect.Contains( GetStart() ) && arect.Contains( GetEnd() );
  775. else
  776. return arect.Intersects( GetStart(), GetEnd() );
  777. }
  778. bool PCB_ARC::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  779. {
  780. BOX2I arect = aRect;
  781. arect.Inflate( aAccuracy );
  782. BOX2I box( GetStart() );
  783. box.Merge( GetMid() );
  784. box.Merge( GetEnd() );
  785. box.Inflate( GetWidth() / 2 );
  786. if( aContained )
  787. return arect.Contains( box );
  788. else
  789. return arect.Intersects( box );
  790. }
  791. bool PCB_VIA::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  792. {
  793. BOX2I arect = aRect;
  794. arect.Inflate( aAccuracy );
  795. BOX2I box( GetStart() );
  796. box.Inflate( GetWidth() / 2 );
  797. if( aContained )
  798. return arect.Contains( box );
  799. else
  800. return arect.IntersectsCircle( GetStart(), GetWidth() / 2 );
  801. }
  802. wxString PCB_TRACK::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
  803. {
  804. return wxString::Format( Type() == PCB_ARC_T ? _("Track (arc) %s on %s, length %s" )
  805. : _("Track %s on %s, length %s" ),
  806. GetNetnameMsg(),
  807. GetLayerName(),
  808. aUnitsProvider->MessageTextFromValue( GetLength() ) );
  809. }
  810. BITMAPS PCB_TRACK::GetMenuImage() const
  811. {
  812. return BITMAPS::add_tracks;
  813. }
  814. void PCB_TRACK::SwapData( BOARD_ITEM* aImage )
  815. {
  816. assert( aImage->Type() == PCB_TRACE_T );
  817. std::swap( *((PCB_TRACK*) this), *((PCB_TRACK*) aImage) );
  818. }
  819. void PCB_ARC::SwapData( BOARD_ITEM* aImage )
  820. {
  821. assert( aImage->Type() == PCB_ARC_T );
  822. std::swap( *this, *static_cast<PCB_ARC*>( aImage ) );
  823. }
  824. void PCB_VIA::SwapData( BOARD_ITEM* aImage )
  825. {
  826. assert( aImage->Type() == PCB_VIA_T );
  827. std::swap( *((PCB_VIA*) this), *((PCB_VIA*) aImage) );
  828. }
  829. VECTOR2I PCB_ARC::GetPosition() const
  830. {
  831. VECTOR2I center = CalcArcCenter( m_Start, m_Mid, m_End );
  832. return center;
  833. }
  834. double PCB_ARC::GetRadius() const
  835. {
  836. auto center = CalcArcCenter( m_Start, m_Mid , m_End );
  837. return GetLineLength( center, m_Start );
  838. }
  839. EDA_ANGLE PCB_ARC::GetAngle() const
  840. {
  841. VECTOR2I center = GetPosition();
  842. EDA_ANGLE angle1 = EDA_ANGLE( m_Mid - center ) - EDA_ANGLE( m_Start - center );
  843. EDA_ANGLE angle2 = EDA_ANGLE( m_End - center ) - EDA_ANGLE( m_Mid - center );
  844. return angle1.Normalize180() + angle2.Normalize180();
  845. }
  846. EDA_ANGLE PCB_ARC::GetArcAngleStart() const
  847. {
  848. EDA_ANGLE angleStart( m_Start - GetPosition() );
  849. return angleStart.Normalize();
  850. }
  851. EDA_ANGLE PCB_ARC::GetArcAngleEnd() const
  852. {
  853. EDA_ANGLE angleEnd( m_End - GetPosition() );
  854. return angleEnd.Normalize();
  855. }
  856. bool PCB_TRACK::cmp_tracks::operator() ( const PCB_TRACK* a, const PCB_TRACK* b ) const
  857. {
  858. if( a->GetNetCode() != b->GetNetCode() )
  859. return a->GetNetCode() < b->GetNetCode();
  860. if( a->GetLayer() != b->GetLayer() )
  861. return a->GetLayer() < b->GetLayer();
  862. if( a->Type() != b->Type() )
  863. return a->Type() < b->Type();
  864. if( a->m_Uuid != b->m_Uuid )
  865. return a->m_Uuid < b->m_Uuid;
  866. return a < b;
  867. }
  868. std::shared_ptr<SHAPE> PCB_TRACK::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  869. {
  870. return std::make_shared<SHAPE_SEGMENT>( m_Start, m_End, m_Width );
  871. }
  872. std::shared_ptr<SHAPE> PCB_VIA::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  873. {
  874. if( aFlash == FLASHING::ALWAYS_FLASHED
  875. || ( aFlash == FLASHING::DEFAULT && FlashLayer( aLayer ) ) )
  876. {
  877. return std::make_shared<SHAPE_CIRCLE>( m_Start, m_Width / 2 );
  878. }
  879. else
  880. {
  881. return std::make_shared<SHAPE_CIRCLE>( m_Start, GetDrillValue() / 2 );
  882. }
  883. }
  884. std::shared_ptr<SHAPE> PCB_ARC::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  885. {
  886. return std::make_shared<SHAPE_ARC>( GetStart(), GetMid(), GetEnd(), GetWidth() );
  887. }
  888. void PCB_TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  889. PCB_LAYER_ID aLayer, int aClearanceValue,
  890. int aError, ERROR_LOC aErrorLoc,
  891. bool ignoreLineWidth ) const
  892. {
  893. wxASSERT_MSG( !ignoreLineWidth, wxT( "IgnoreLineWidth has no meaning for tracks." ) );
  894. switch( Type() )
  895. {
  896. case PCB_VIA_T:
  897. {
  898. int radius = ( m_Width / 2 ) + aClearanceValue;
  899. TransformCircleToPolygon( aCornerBuffer, m_Start, radius, aError, aErrorLoc );
  900. break;
  901. }
  902. case PCB_ARC_T:
  903. {
  904. const PCB_ARC* arc = static_cast<const PCB_ARC*>( this );
  905. int width = m_Width + ( 2 * aClearanceValue );
  906. TransformArcToPolygon( aCornerBuffer, arc->GetStart(), arc->GetMid(),
  907. arc->GetEnd(), width, aError, aErrorLoc );
  908. break;
  909. }
  910. default:
  911. {
  912. int width = m_Width + ( 2 * aClearanceValue );
  913. TransformOvalToPolygon( aCornerBuffer, m_Start, m_End, width, aError, aErrorLoc );
  914. break;
  915. }
  916. }
  917. }
  918. static struct TRACK_VIA_DESC
  919. {
  920. TRACK_VIA_DESC()
  921. {
  922. ENUM_MAP<VIATYPE>::Instance()
  923. .Undefined( VIATYPE::NOT_DEFINED )
  924. .Map( VIATYPE::THROUGH, _HKI( "Through" ) )
  925. .Map( VIATYPE::BLIND_BURIED, _HKI( "Blind/buried" ) )
  926. .Map( VIATYPE::MICROVIA, _HKI( "Micro" ) );
  927. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  928. if( layerEnum.Choices().GetCount() == 0 )
  929. {
  930. layerEnum.Undefined( UNDEFINED_LAYER );
  931. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  932. layerEnum.Map( *seq, LSET::Name( *seq ) );
  933. }
  934. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  935. // Track
  936. REGISTER_TYPE( PCB_TRACK );
  937. propMgr.InheritsAfter( TYPE_HASH( PCB_TRACK ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
  938. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "Width" ),
  939. &PCB_TRACK::SetWidth, &PCB_TRACK::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
  940. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ),
  941. new PROPERTY<PCB_TRACK, int, BOARD_ITEM>( _HKI( "Origin X" ),
  942. &PCB_TRACK::SetX, &PCB_TRACK::GetX, PROPERTY_DISPLAY::PT_COORD ) );
  943. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ),
  944. new PROPERTY<PCB_TRACK, int, BOARD_ITEM>( _HKI( "Origin Y" ),
  945. &PCB_TRACK::SetY, &PCB_TRACK::GetY, PROPERTY_DISPLAY::PT_COORD ) );
  946. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End X" ),
  947. &PCB_TRACK::SetEndX, &PCB_TRACK::GetEndX, PROPERTY_DISPLAY::PT_COORD ) );
  948. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End Y" ),
  949. &PCB_TRACK::SetEndY, &PCB_TRACK::GetEndY, PROPERTY_DISPLAY::PT_COORD ) );
  950. // Arc
  951. REGISTER_TYPE( PCB_ARC );
  952. propMgr.InheritsAfter( TYPE_HASH( PCB_ARC ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
  953. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "Width" ),
  954. &PCB_ARC::SetWidth, &PCB_ARC::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
  955. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ),
  956. new PROPERTY<PCB_ARC, int, BOARD_ITEM>( _HKI( "Origin X" ),
  957. &PCB_TRACK::SetX, &PCB_ARC::GetX, PROPERTY_DISPLAY::PT_COORD ) );
  958. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ),
  959. new PROPERTY<PCB_ARC, int, BOARD_ITEM>( _HKI( "Origin Y" ),
  960. &PCB_TRACK::SetY, &PCB_ARC::GetY, PROPERTY_DISPLAY::PT_COORD ) );
  961. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End X" ),
  962. &PCB_TRACK::SetEndX, &PCB_ARC::GetEndX, PROPERTY_DISPLAY::PT_COORD ) );
  963. propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End Y" ),
  964. &PCB_TRACK::SetEndY, &PCB_ARC::GetEndY, PROPERTY_DISPLAY::PT_COORD ) );
  965. // Via
  966. REGISTER_TYPE( PCB_VIA );
  967. propMgr.InheritsAfter( TYPE_HASH( PCB_VIA ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
  968. // TODO layerset for vias?
  969. // TODO test drill, use getdrillvalue?
  970. propMgr.ReplaceProperty( TYPE_HASH( PCB_TRACK ), _HKI( "Width" ),
  971. new PROPERTY<PCB_VIA, int, PCB_TRACK>( _HKI( "Diameter" ),
  972. &PCB_VIA::SetWidth, &PCB_VIA::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
  973. propMgr.AddProperty( new PROPERTY<PCB_VIA, int>( _HKI( "Hole" ),
  974. &PCB_VIA::SetDrill, &PCB_VIA::GetDrillValue, PROPERTY_DISPLAY::PT_SIZE ) );
  975. propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
  976. new PROPERTY_ENUM<PCB_VIA, PCB_LAYER_ID, BOARD_ITEM>( _HKI( "Layer Top" ),
  977. &PCB_VIA::SetLayer, &PCB_VIA::GetLayer ) );
  978. propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA, PCB_LAYER_ID>( _HKI( "Layer Bottom" ),
  979. &PCB_VIA::SetBottomLayer, &PCB_VIA::BottomLayer ) );
  980. propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA, VIATYPE>( _HKI( "Via Type" ),
  981. &PCB_VIA::SetViaType, &PCB_VIA::GetViaType ) );
  982. }
  983. } _TRACK_VIA_DESC;
  984. ENUM_TO_WXANY( VIATYPE );