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.

1194 lines
31 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
14 years ago
18 years ago
19 years ago
18 years ago
19 years ago
19 years ago
19 years ago
19 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
19 years ago
19 years ago
17 years ago
17 years ago
18 years ago
18 years ago
18 years ago
9 years ago
7 years ago
16 years ago
16 years ago
16 years ago
17 years ago
17 years ago
17 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
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
17 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, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2019 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 <fctsys.h>
  27. #include <gr_basic.h>
  28. #include <common.h>
  29. #include <trigo.h>
  30. #include <macros.h>
  31. #include <pcb_screen.h>
  32. #include <gr_text.h>
  33. #include <pcb_base_frame.h>
  34. #include <class_board.h>
  35. #include <class_track.h>
  36. #include <pcbnew.h>
  37. #include <base_units.h>
  38. #include <msgpanel.h>
  39. #include <bitmaps.h>
  40. #include <view/view.h>
  41. #include <math/util.h> // for KiROUND
  42. #include <pgm_base.h>
  43. #include <settings/color_settings.h>
  44. #include <settings/settings_manager.h>
  45. /**
  46. * Function ShowClearance
  47. * tests to see if the clearance border is drawn on the given track.
  48. * @return bool - true if should draw clearance, else false.
  49. */
  50. static bool ShowClearance( const PCB_DISPLAY_OPTIONS& aDisplOpts, const TRACK* aTrack )
  51. {
  52. // maybe return true for tracks and vias, not for zone segments
  53. return IsCopperLayer( aTrack->GetLayer() )
  54. && ( aTrack->Type() == PCB_TRACE_T || aTrack->Type() == PCB_VIA_T
  55. || aTrack->Type() == PCB_ARC_T )
  56. && ( ( aDisplOpts.m_ShowTrackClearanceMode == PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_NEW_AND_EDITED_TRACKS_AND_VIA_AREAS
  57. && ( aTrack->IsDragging() || aTrack->IsMoving() || aTrack->IsNew() ) )
  58. || ( aDisplOpts.m_ShowTrackClearanceMode == PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_ALWAYS )
  59. );
  60. }
  61. TRACK::TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) :
  62. BOARD_CONNECTED_ITEM( aParent, idtype )
  63. {
  64. m_Width = Millimeter2iu( 0.2 );
  65. }
  66. EDA_ITEM* TRACK::Clone() const
  67. {
  68. return new TRACK( *this );
  69. }
  70. EDA_ITEM* ARC::Clone() const
  71. {
  72. return new ARC( *this );
  73. }
  74. VIA::VIA( BOARD_ITEM* aParent ) :
  75. TRACK( aParent, PCB_VIA_T )
  76. {
  77. SetViaType( VIATYPE::THROUGH );
  78. m_BottomLayer = B_Cu;
  79. SetDrillDefault();
  80. }
  81. EDA_ITEM* VIA::Clone() const
  82. {
  83. return new VIA( *this );
  84. }
  85. wxString VIA::GetSelectMenuText( EDA_UNITS aUnits ) const
  86. {
  87. wxString format;
  88. BOARD* board = GetBoard();
  89. switch( GetViaType() )
  90. {
  91. case VIATYPE::BLIND_BURIED:
  92. format = _( "Blind/Buried Via %s %s on %s - %s" );
  93. break;
  94. case VIATYPE::MICROVIA:
  95. format = _( "Micro Via %s %s on %s - %s" );
  96. break;
  97. // else say nothing about normal (through) vias
  98. default:
  99. format = _( "Via %s %s on %s - %s" );
  100. break;
  101. }
  102. if( board )
  103. {
  104. // say which layers, only two for now
  105. PCB_LAYER_ID topLayer;
  106. PCB_LAYER_ID botLayer;
  107. LayerPair( &topLayer, &botLayer );
  108. return wxString::Format( format.GetData(), MessageTextFromValue( aUnits, m_Width ),
  109. GetNetnameMsg(), board->GetLayerName( topLayer ), board->GetLayerName( botLayer ) );
  110. }
  111. else
  112. {
  113. return wxString::Format( format.GetData(), MessageTextFromValue( aUnits, m_Width ),
  114. GetNetnameMsg(), wxT( "??" ), wxT( "??" ) );
  115. }
  116. }
  117. BITMAP_DEF VIA::GetMenuImage() const
  118. {
  119. return via_xpm;
  120. }
  121. int TRACK::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
  122. {
  123. // Currently tracks have no specific clearance parameter on a per track or per
  124. // segment basis. The NETCLASS clearance is used.
  125. return BOARD_CONNECTED_ITEM::GetClearance( aItem );
  126. }
  127. int VIA::GetDrillValue() const
  128. {
  129. if( m_Drill > 0 ) // Use the specific value.
  130. return m_Drill;
  131. // Use the default value from the Netclass
  132. NETCLASSPTR netclass = GetNetClass();
  133. if( GetViaType() == VIATYPE::MICROVIA )
  134. return netclass->GetuViaDrill();
  135. return netclass->GetViaDrill();
  136. }
  137. STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) const
  138. {
  139. STATUS_FLAGS result = 0;
  140. if( min_dist < 0 )
  141. min_dist = m_Width / 2;
  142. if( min_dist == 0 )
  143. {
  144. if( m_Start == point )
  145. result |= STARTPOINT;
  146. if( m_End == point )
  147. result |= ENDPOINT;
  148. }
  149. else
  150. {
  151. double dist = GetLineLength( m_Start, point );
  152. if( min_dist >= KiROUND( dist ) )
  153. result |= STARTPOINT;
  154. dist = GetLineLength( m_End, point );
  155. if( min_dist >= KiROUND( dist ) )
  156. result |= ENDPOINT;
  157. }
  158. return result;
  159. }
  160. const EDA_RECT TRACK::GetBoundingBox() const
  161. {
  162. // end of track is round, this is its radius, rounded up
  163. int radius = ( m_Width + 1 ) / 2;
  164. int ymax, xmax, ymin, xmin;
  165. if( Type() == PCB_VIA_T )
  166. {
  167. ymax = m_Start.y;
  168. xmax = m_Start.x;
  169. ymin = m_Start.y;
  170. xmin = m_Start.x;
  171. }
  172. else
  173. {
  174. ymax = std::max( m_Start.y, m_End.y );
  175. xmax = std::max( m_Start.x, m_End.x );
  176. ymin = std::min( m_Start.y, m_End.y );
  177. xmin = std::min( m_Start.x, m_End.x );
  178. }
  179. ymax += radius;
  180. xmax += radius;
  181. ymin -= radius;
  182. xmin -= radius;
  183. // return a rectangle which is [pos,dim) in nature. therefore the +1
  184. EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
  185. return ret;
  186. }
  187. void TRACK::Rotate( const wxPoint& aRotCentre, double aAngle )
  188. {
  189. RotatePoint( &m_Start, aRotCentre, aAngle );
  190. RotatePoint( &m_End, aRotCentre, aAngle );
  191. }
  192. void ARC::Rotate( const wxPoint& aRotCentre, double aAngle )
  193. {
  194. RotatePoint( &m_Start, aRotCentre, aAngle );
  195. RotatePoint( &m_End, aRotCentre, aAngle );
  196. RotatePoint( &m_Mid, aRotCentre, aAngle );
  197. }
  198. void TRACK::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
  199. {
  200. if( aFlipLeftRight )
  201. {
  202. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  203. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  204. }
  205. else
  206. {
  207. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  208. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  209. }
  210. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  211. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  212. }
  213. void ARC::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
  214. {
  215. if( aFlipLeftRight )
  216. {
  217. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  218. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  219. m_Mid.x = aCentre.x - ( m_Mid.x - aCentre.x );
  220. }
  221. else
  222. {
  223. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  224. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  225. m_Mid.y = aCentre.y - ( m_Mid.y - aCentre.y );
  226. }
  227. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  228. SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
  229. }
  230. void VIA::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
  231. {
  232. if( aFlipLeftRight )
  233. {
  234. m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
  235. m_End.x = aCentre.x - ( m_End.x - aCentre.x );
  236. }
  237. else
  238. {
  239. m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
  240. m_End.y = aCentre.y - ( m_End.y - aCentre.y );
  241. }
  242. if( GetViaType() != VIATYPE::THROUGH )
  243. {
  244. int copperLayerCount = GetBoard()->GetCopperLayerCount();
  245. PCB_LAYER_ID top_layer;
  246. PCB_LAYER_ID bottom_layer;
  247. LayerPair( &top_layer, &bottom_layer );
  248. top_layer = FlipLayer( top_layer, copperLayerCount );
  249. bottom_layer = FlipLayer( bottom_layer, copperLayerCount );
  250. SetLayerPair( top_layer, bottom_layer );
  251. }
  252. }
  253. // see class_track.h
  254. SEARCH_RESULT TRACK::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
  255. {
  256. KICAD_T stype = *scanTypes;
  257. // If caller wants to inspect my type
  258. if( stype == Type() )
  259. {
  260. if( SEARCH_RESULT::QUIT == inspector( this, testData ) )
  261. return SEARCH_RESULT::QUIT;
  262. }
  263. return SEARCH_RESULT::CONTINUE;
  264. }
  265. bool VIA::IsOnLayer( PCB_LAYER_ID layer_number ) const
  266. {
  267. PCB_LAYER_ID bottom_layer, top_layer;
  268. LayerPair( &top_layer, &bottom_layer );
  269. wxASSERT( top_layer <= bottom_layer );
  270. if( top_layer <= layer_number && layer_number <= bottom_layer )
  271. return true;
  272. else
  273. return false;
  274. }
  275. LSET VIA::GetLayerSet() const
  276. {
  277. if( GetViaType() == VIATYPE::THROUGH )
  278. return LSET::AllCuMask();
  279. // VIA_BLIND_BURIED or VIA_MICRVIA:
  280. LSET layermask;
  281. wxASSERT( m_Layer <= m_BottomLayer );
  282. // PCB_LAYER_IDs are numbered from front to back, this is top to bottom.
  283. for( LAYER_NUM id = m_Layer; id <= m_BottomLayer; ++id )
  284. {
  285. layermask.set( id );
  286. }
  287. return layermask;
  288. }
  289. void VIA::SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer )
  290. {
  291. m_Layer = aTopLayer;
  292. m_BottomLayer = aBottomLayer;
  293. SanitizeLayers();
  294. }
  295. void VIA::SetTopLayer( PCB_LAYER_ID aLayer )
  296. {
  297. m_Layer = aLayer;
  298. }
  299. void VIA::SetBottomLayer( PCB_LAYER_ID aLayer )
  300. {
  301. m_BottomLayer = aLayer;
  302. }
  303. void VIA::LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const
  304. {
  305. PCB_LAYER_ID t_layer = F_Cu;
  306. PCB_LAYER_ID b_layer = B_Cu;
  307. if( GetViaType() != VIATYPE::THROUGH )
  308. {
  309. b_layer = m_BottomLayer;
  310. t_layer = m_Layer;
  311. if( b_layer < t_layer )
  312. std::swap( b_layer, t_layer );
  313. }
  314. if( top_layer )
  315. *top_layer = t_layer;
  316. if( bottom_layer )
  317. *bottom_layer = b_layer;
  318. }
  319. PCB_LAYER_ID VIA::TopLayer() const
  320. {
  321. return m_Layer;
  322. }
  323. PCB_LAYER_ID VIA::BottomLayer() const
  324. {
  325. return m_BottomLayer;
  326. }
  327. void VIA::SanitizeLayers()
  328. {
  329. if( GetViaType() == VIATYPE::THROUGH )
  330. {
  331. m_Layer = F_Cu;
  332. m_BottomLayer = B_Cu;
  333. }
  334. if( m_BottomLayer < m_Layer )
  335. std::swap( m_BottomLayer, m_Layer );
  336. }
  337. void TRACK::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
  338. {
  339. BOARD* brd = GetBoard();
  340. auto color = Pgm().GetSettingsManager().GetColorSettings()->GetColor( m_Layer );
  341. if( !brd->IsLayerVisible( m_Layer ) || !brd->IsElementVisible( LAYER_TRACKS ) )
  342. return;
  343. auto displ_opts = aFrame->GetDisplayOptions();
  344. color.a = 0.588;
  345. // Draw track as line if width <= 1pixel:
  346. if( aDC->LogicalToDeviceXRel( m_Width ) <= 1 )
  347. {
  348. GRLine( nullptr, aDC, m_Start + aOffset, m_End + aOffset, m_Width, color );
  349. return;
  350. }
  351. if( !displ_opts.m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
  352. {
  353. GRCSegm( nullptr, aDC, m_Start + aOffset, m_End + aOffset, m_Width, color );
  354. }
  355. else
  356. {
  357. GRFillCSegm( nullptr, aDC, m_Start.x + aOffset.x, m_Start.y + aOffset.y,
  358. m_End.x + aOffset.x, m_End.y + aOffset.y, m_Width, color );
  359. }
  360. }
  361. void TRACK::ViewGetLayers( int aLayers[], int& aCount ) const
  362. {
  363. // Show the track and its netname on different layers
  364. aLayers[0] = GetLayer();
  365. aLayers[1] = GetNetnameLayer( aLayers[0] );
  366. aCount = 2;
  367. }
  368. unsigned int TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  369. {
  370. const int HIDE = std::numeric_limits<unsigned int>::max();
  371. if( !aView->IsLayerVisible( LAYER_TRACKS ) )
  372. return HIDE;
  373. // Netnames will be shown only if zoom is appropriate
  374. if( IsNetnameLayer( aLayer ) )
  375. {
  376. return ( Millimeter2iu( 4 ) / ( m_Width + 1 ) );
  377. }
  378. // Other layers are shown without any conditions
  379. return 0;
  380. }
  381. const BOX2I TRACK::ViewBBox() const
  382. {
  383. BOX2I bbox = GetBoundingBox();
  384. bbox.Inflate( 2 * GetClearance() );
  385. return bbox;
  386. }
  387. void VIA::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
  388. {
  389. int radius;
  390. int fillvia = 0;
  391. PCB_SCREEN* screen = aFrame->GetScreen();
  392. auto& displ_opts = aFrame->GetDisplayOptions();
  393. BOARD* brd = GetBoard();
  394. COLOR4D color = Pgm().GetSettingsManager().GetColorSettings()->GetColor(
  395. LAYER_VIAS + static_cast<int>( GetViaType() ) );
  396. if( displ_opts.m_DisplayViaFill == FILLED )
  397. fillvia = 1;
  398. if( !brd->IsElementVisible( LAYER_VIAS + static_cast<int>( GetViaType() ) ) )
  399. return;
  400. // Only draw the via if at least one of the layers it crosses is being displayed
  401. if( !( brd->GetVisibleLayers() & GetLayerSet() ).any() )
  402. return;
  403. color.a = 0.588;
  404. radius = m_Width >> 1;
  405. // for small via size on screen (radius < 4 pixels) draw a simplified shape
  406. int radius_in_pixels = aDC->LogicalToDeviceXRel( radius );
  407. bool fast_draw = false;
  408. // Vias are drawn as a filled circle or a double circle. The hole will be drawn later
  409. int drill_radius = GetDrillValue() / 2;
  410. int inner_radius = radius - aDC->DeviceToLogicalXRel( 2 );
  411. if( radius_in_pixels < MIN_VIA_DRAW_SIZE )
  412. {
  413. fast_draw = true;
  414. fillvia = false;
  415. }
  416. if( fillvia )
  417. {
  418. GRFilledCircle( nullptr, aDC, m_Start + aOffset, radius, color );
  419. }
  420. else
  421. {
  422. GRCircle( nullptr, aDC, m_Start + aOffset, radius, 0, color );
  423. if ( fast_draw )
  424. return;
  425. GRCircle( nullptr, aDC, m_Start + aOffset, inner_radius, 0, color );
  426. }
  427. if( fillvia )
  428. {
  429. bool blackpenstate = false;
  430. if( screen->m_IsPrinting )
  431. {
  432. blackpenstate = GetGRForceBlackPenState();
  433. GRForceBlackPen( false );
  434. color = WHITE;
  435. }
  436. else
  437. {
  438. color = BLACK; // or DARKGRAY;
  439. }
  440. // Draw hole if the radius is > 1pixel.
  441. if( aDC->LogicalToDeviceXRel( drill_radius ) > 1 )
  442. GRFilledCircle( nullptr, aDC, m_Start.x + aOffset.x, m_Start.y + aOffset.y,
  443. drill_radius, 0, color, color );
  444. if( screen->m_IsPrinting )
  445. GRForceBlackPen( blackpenstate );
  446. }
  447. else
  448. {
  449. if( drill_radius < inner_radius ) // We can show the via hole
  450. GRCircle( nullptr, aDC, m_Start + aOffset, drill_radius, 0, color );
  451. }
  452. if( ShowClearance( displ_opts, this ) )
  453. {
  454. GRCircle( nullptr, aDC, m_Start + aOffset, radius + GetClearance(), 0, color );
  455. }
  456. // for Micro Vias, draw a partial cross : X on component layer, or + on copper layer
  457. // (so we can see 2 superimposed microvias ):
  458. if( GetViaType() == VIATYPE::MICROVIA )
  459. {
  460. int ax, ay, bx, by;
  461. if( IsOnLayer( B_Cu ) )
  462. {
  463. ax = radius; ay = 0;
  464. bx = drill_radius; by = 0;
  465. }
  466. else
  467. {
  468. ax = ay = (radius * 707) / 1000;
  469. bx = by = (drill_radius * 707) / 1000;
  470. }
  471. // lines '|' or '\'
  472. GRLine( nullptr, aDC, m_Start.x + aOffset.x - ax, m_Start.y + aOffset.y - ay,
  473. m_Start.x + aOffset.x - bx, m_Start.y + aOffset.y - by, 0, color );
  474. GRLine( nullptr, aDC, m_Start.x + aOffset.x + bx, m_Start.y + aOffset.y + by,
  475. m_Start.x + aOffset.x + ax, m_Start.y + aOffset.y + ay, 0, color );
  476. // lines - or '/'
  477. GRLine( nullptr, aDC, m_Start.x + aOffset.x + ay, m_Start.y + aOffset.y - ax,
  478. m_Start.x + aOffset.x + by, m_Start.y + aOffset.y - bx, 0, color );
  479. GRLine( nullptr, aDC, m_Start.x + aOffset.x - by, m_Start.y + aOffset.y + bx,
  480. m_Start.x + aOffset.x - ay, m_Start.y + aOffset.y + ax, 0, color );
  481. }
  482. // for Buried Vias, draw a partial line : orient depending on layer pair
  483. // (so we can see superimposed buried vias ):
  484. if( GetViaType() == VIATYPE::BLIND_BURIED )
  485. {
  486. int ax = 0, ay = radius, bx = 0, by = drill_radius;
  487. PCB_LAYER_ID layer_top, layer_bottom;
  488. LayerPair( &layer_top, &layer_bottom );
  489. // lines for the top layer
  490. RotatePoint( &ax, &ay, layer_top * 3600.0 / brd->GetCopperLayerCount( ) );
  491. RotatePoint( &bx, &by, layer_top * 3600.0 / brd->GetCopperLayerCount( ) );
  492. GRLine( nullptr, aDC, m_Start.x + aOffset.x - ax, m_Start.y + aOffset.y - ay,
  493. m_Start.x + aOffset.x - bx, m_Start.y + aOffset.y - by, 0, color );
  494. // lines for the bottom layer
  495. ax = 0; ay = radius; bx = 0; by = drill_radius;
  496. RotatePoint( &ax, &ay, layer_bottom * 3600.0 / brd->GetCopperLayerCount( ) );
  497. RotatePoint( &bx, &by, layer_bottom * 3600.0 / brd->GetCopperLayerCount( ) );
  498. GRLine( nullptr, aDC, m_Start.x + aOffset.x - ax, m_Start.y + aOffset.y - ay,
  499. m_Start.x + aOffset.x - bx, m_Start.y + aOffset.y - by, 0, color );
  500. }
  501. // Display the short netname:
  502. if( GetNetCode() == NETINFO_LIST::UNCONNECTED )
  503. return;
  504. if( displ_opts.m_DisplayNetNamesMode == 0 || displ_opts.m_DisplayNetNamesMode == 1 )
  505. return;
  506. NETINFO_ITEM* net = GetNet();
  507. if( net == NULL )
  508. return;
  509. wxString text = UnescapeString( net->GetShortNetname() );
  510. int len = text.Len();
  511. if( len > 0 )
  512. {
  513. // calculate a good size for the text
  514. int tsize = m_Width / len;
  515. if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE )
  516. {
  517. tsize = (tsize * 7) / 10; // small reduction to give a better look, inside via
  518. GRHaloText( aDC, m_Start, color, WHITE, BLACK, text, 0, wxSize( tsize, tsize ),
  519. GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, tsize/7, false, false );
  520. }
  521. }
  522. }
  523. void VIA::ViewGetLayers( int aLayers[], int& aCount ) const
  524. {
  525. aLayers[0] = LAYER_VIAS_HOLES;
  526. aLayers[1] = LAYER_VIAS_NETNAMES;
  527. aCount = 3;
  528. // Just show it on common via & via holes layers
  529. switch( GetViaType() )
  530. {
  531. case VIATYPE::THROUGH:
  532. aLayers[2] = LAYER_VIA_THROUGH;
  533. break;
  534. case VIATYPE::BLIND_BURIED:
  535. aLayers[2] = LAYER_VIA_BBLIND;
  536. aLayers[3] = m_Layer;
  537. aLayers[4] = m_BottomLayer;
  538. aCount += 2;
  539. break;
  540. case VIATYPE::MICROVIA:
  541. aLayers[2] = LAYER_VIA_MICROVIA;
  542. break;
  543. default:
  544. aLayers[2] = LAYER_GP_OVERLAY;
  545. wxASSERT( false );
  546. break;
  547. }
  548. }
  549. unsigned int VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  550. {
  551. constexpr unsigned int HIDE = std::numeric_limits<unsigned int>::max();
  552. // Netnames will be shown only if zoom is appropriate
  553. if( IsNetnameLayer( aLayer ) )
  554. return m_Width == 0 ? HIDE : ( Millimeter2iu( 10 ) / m_Width );
  555. BOARD* board = GetBoard();
  556. // Only draw the via if at least one of the layers it crosses is being displayed
  557. if( board && ( board->GetVisibleLayers() & GetLayerSet() ).any()
  558. && aView->IsLayerVisible( LAYER_VIAS ) )
  559. {
  560. switch( m_ViaType )
  561. {
  562. case VIATYPE::THROUGH:
  563. if( !aView->IsLayerVisible( LAYER_VIA_THROUGH ) )
  564. return HIDE;
  565. break;
  566. case VIATYPE::BLIND_BURIED:
  567. if( !aView->IsLayerVisible( LAYER_VIA_BBLIND ) )
  568. return HIDE;
  569. break;
  570. case VIATYPE::MICROVIA:
  571. if( !aView->IsLayerVisible( LAYER_VIA_MICROVIA ) )
  572. return HIDE;
  573. break;
  574. default:
  575. break;
  576. }
  577. return 0;
  578. }
  579. return HIDE;
  580. }
  581. // see class_track.h
  582. void TRACK::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
  583. {
  584. wxString msg;
  585. BOARD* board = GetBoard();
  586. // Display basic infos
  587. GetMsgPanelInfoBase( aUnits, aList );
  588. // Display full track length (in Pcbnew)
  589. if( board )
  590. {
  591. int count;
  592. double trackLen;
  593. double lenPadToDie;
  594. std::tie( count, trackLen, lenPadToDie ) = board->GetTrackLength( *this );
  595. msg = MessageTextFromValue( aUnits, trackLen );
  596. aList.emplace_back( _( "Length" ), msg, DARKCYAN );
  597. if( lenPadToDie != 0 )
  598. {
  599. msg = MessageTextFromValue( aUnits, trackLen + lenPadToDie );
  600. aList.emplace_back( _( "Full Length" ), msg, DARKCYAN );
  601. msg = MessageTextFromValue( aUnits, lenPadToDie, true );
  602. aList.emplace_back( _( "Pad To Die Length" ), msg, DARKCYAN );
  603. }
  604. }
  605. NETCLASSPTR netclass = GetNetClass();
  606. if( netclass )
  607. {
  608. aList.emplace_back( _( "NC Name" ), netclass->GetName(), DARKMAGENTA );
  609. msg = MessageTextFromValue( aUnits, netclass->GetClearance(), true );
  610. aList.emplace_back( _( "NC Clearance" ), msg, DARKMAGENTA );
  611. msg = MessageTextFromValue( aUnits, netclass->GetTrackWidth(), true );
  612. aList.emplace_back( _( "NC Width" ), msg, DARKMAGENTA );
  613. msg = MessageTextFromValue( aUnits, netclass->GetViaDiameter(), true );
  614. aList.emplace_back( _( "NC Via Size" ), msg, DARKMAGENTA );
  615. msg = MessageTextFromValue( aUnits, netclass->GetViaDrill(), true );
  616. aList.emplace_back( _( "NC Via Drill"), msg, DARKMAGENTA );
  617. }
  618. }
  619. void TRACK::GetMsgPanelInfoBase_Common( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
  620. {
  621. wxString msg;
  622. // Display Net Name
  623. if( GetBoard() )
  624. {
  625. NETINFO_ITEM* net = GetNet();
  626. if( net )
  627. msg = UnescapeString( net->GetNetname() );
  628. else
  629. msg = wxT( "<no name>" );
  630. aList.emplace_back( _( "NetName" ), msg, RED );
  631. // Display net code : (useful in test or debug)
  632. msg.Printf( wxT( "%d" ), GetNetCode() );
  633. aList.emplace_back( _( "NetCode" ), msg, RED );
  634. }
  635. #if defined(DEBUG)
  636. // Display the flags
  637. msg.Printf( wxT( "0x%08X" ), m_Flags );
  638. aList.emplace_back( wxT( "Flags" ), msg, BLUE );
  639. #if 0
  640. // Display start and end pointers:
  641. msg.Printf( wxT( "%p" ), start );
  642. aList.push_back( MSG_PANEL_ITEM( wxT( "start ptr" ), msg, BLUE ) );
  643. msg.Printf( wxT( "%p" ), end );
  644. aList.push_back( MSG_PANEL_ITEM( wxT( "end ptr" ), msg, BLUE ) );
  645. // Display this ptr
  646. msg.Printf( wxT( "%p" ), this );
  647. aList.push_back( MSG_PANEL_ITEM( wxT( "this" ), msg, BLUE ) );
  648. #endif
  649. #if 0
  650. // Display start and end positions:
  651. msg.Printf( wxT( "%d %d" ), m_Start.x, m_Start.y );
  652. aList.push_back( MSG_PANEL_ITEM( wxT( "Start pos" ), msg, BLUE ) );
  653. msg.Printf( wxT( "%d %d" ), m_End.x, m_End.y );
  654. aList.push_back( MSG_PANEL_ITEM( wxT( "End pos" ), msg, BLUE ) );
  655. #endif
  656. #endif // defined(DEBUG)
  657. // Display the State member
  658. msg = wxT( ". . " );
  659. if( GetState( TRACK_LOCKED ) )
  660. msg[0] = 'L';
  661. if( GetState( TRACK_AR ) )
  662. msg[2] = 'A';
  663. aList.emplace_back( _( "Status" ), msg, MAGENTA );
  664. }
  665. void TRACK::GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
  666. {
  667. wxString msg;
  668. BOARD* board = GetBoard();
  669. aList.emplace_back( _( "Type" ), _( "Track" ), DARKCYAN );
  670. GetMsgPanelInfoBase_Common( aUnits, aList );
  671. // Display layer
  672. if( board )
  673. msg = board->GetLayerName( m_Layer );
  674. else
  675. msg.Printf(wxT("%d"), m_Layer );
  676. aList.emplace_back( _( "Layer" ), msg, BROWN );
  677. // Display width
  678. msg = MessageTextFromValue( aUnits, m_Width, true );
  679. aList.emplace_back( _( "Width" ), msg, DARKCYAN );
  680. // Display segment length
  681. msg = ::MessageTextFromValue( aUnits, GetLength() );
  682. aList.emplace_back( _( "Segment Length" ), msg, DARKCYAN );
  683. }
  684. void VIA::GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
  685. {
  686. wxString msg;
  687. BOARD* board = GetBoard();
  688. switch( GetViaType() )
  689. {
  690. default:
  691. case VIATYPE::NOT_DEFINED:
  692. msg = wxT( "???" ); // Not used yet, does not exist currently
  693. break;
  694. case VIATYPE::MICROVIA:
  695. msg = _( "Micro Via" ); // from external layer (TOP or BOTTOM) from
  696. // the near neighbor inner layer only
  697. break;
  698. case VIATYPE::BLIND_BURIED:
  699. msg = _( "Blind/Buried Via" ); // from inner or external to inner
  700. // or external layer (no restriction)
  701. break;
  702. case VIATYPE::THROUGH:
  703. msg = _( "Through Via" ); // Usual via (from TOP to BOTTOM layer only )
  704. break;
  705. }
  706. aList.emplace_back( _( "Type" ), msg, DARKCYAN );
  707. GetMsgPanelInfoBase_Common( aUnits, aList );
  708. // Display layer pair
  709. PCB_LAYER_ID top_layer, bottom_layer;
  710. LayerPair( &top_layer, &bottom_layer );
  711. if( board )
  712. msg = board->GetLayerName( top_layer ) + wxT( "/" )
  713. + board->GetLayerName( bottom_layer );
  714. else
  715. msg.Printf( wxT( "%d/%d" ), top_layer, bottom_layer );
  716. aList.emplace_back( _( "Layers" ), msg, BROWN );
  717. // Display width
  718. msg = MessageTextFromValue( aUnits, m_Width, true );
  719. // Display diameter value:
  720. aList.emplace_back( _( "Diameter" ), msg, DARKCYAN );
  721. // Display drill value
  722. msg = MessageTextFromValue( aUnits, GetDrillValue() );
  723. wxString title = _( "Drill" );
  724. title += wxT( " " );
  725. bool drl_specific = true;
  726. if( GetBoard() )
  727. {
  728. NETINFO_ITEM* net = GetNet();
  729. int drill_class_value = 0;
  730. if( net )
  731. {
  732. if( GetViaType() == VIATYPE::MICROVIA )
  733. drill_class_value = net->GetMicroViaDrillSize();
  734. else
  735. drill_class_value = net->GetViaDrillSize();
  736. }
  737. drl_specific = GetDrillValue() != drill_class_value;
  738. }
  739. if( drl_specific )
  740. title += _( "(Specific)" );
  741. else
  742. title += _( "(NetClass)" );
  743. aList.emplace_back( title, msg, RED );
  744. }
  745. bool TRACK::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  746. {
  747. return TestSegmentHit( aPosition, m_Start, m_End, aAccuracy + ( m_Width / 2 ) );
  748. }
  749. bool ARC::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  750. {
  751. int max_dist = aAccuracy + ( m_Width / 2 );
  752. wxPoint center = GetPosition();
  753. wxPoint relpos = aPosition - center;
  754. double dist = EuclideanNorm( relpos );
  755. double radius = GetRadius();
  756. if( std::abs( dist - radius ) > max_dist )
  757. return false;
  758. double arc_angle_start = GetArcAngleStart(); // Always 0.0 ... 360 deg, in 0.1 deg
  759. double arc_hittest = ArcTangente( relpos.y, relpos.x );
  760. // Calculate relative angle between the starting point of the arc, and the test point
  761. arc_hittest -= arc_angle_start;
  762. // Normalise arc_hittest between 0 ... 360 deg
  763. NORMALIZE_ANGLE_POS( arc_hittest );
  764. double arc_angle = GetAngle();
  765. if( arc_angle < 0 )
  766. return arc_hittest >= 3600 + arc_angle;
  767. return arc_hittest <= GetAngle();
  768. }
  769. bool VIA::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  770. {
  771. int max_dist = aAccuracy + ( m_Width / 2 );
  772. // rel_pos is aPosition relative to m_Start (or the center of the via)
  773. wxPoint rel_pos = aPosition - m_Start;
  774. double dist = (double) rel_pos.x * rel_pos.x + (double) rel_pos.y * rel_pos.y;
  775. return dist <= (double) max_dist * max_dist;
  776. }
  777. bool TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  778. {
  779. EDA_RECT arect = aRect;
  780. arect.Inflate( aAccuracy );
  781. if( aContained )
  782. /* Tracks are a special case:
  783. * they are considered inside the rect if one end is inside the rect */
  784. return arect.Contains( GetStart() ) || arect.Contains( GetEnd() );
  785. else
  786. return arect.Intersects( GetStart(), GetEnd() );
  787. }
  788. bool ARC::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  789. {
  790. EDA_RECT box;
  791. EDA_RECT arect = aRect;
  792. arect.Inflate( aAccuracy );
  793. box.SetOrigin( GetStart() );
  794. box.Merge( GetMid() );
  795. box.Merge( GetEnd() );
  796. box.Inflate( GetWidth() / 2 );
  797. if( aContained )
  798. return arect.Contains( box );
  799. else
  800. return arect.Intersects( box );
  801. }
  802. bool VIA::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  803. {
  804. EDA_RECT box;
  805. EDA_RECT arect = aRect;
  806. arect.Inflate( aAccuracy );
  807. box.SetOrigin( GetStart() );
  808. box.Inflate( GetWidth() / 2 );
  809. if( aContained )
  810. {
  811. return arect.Contains( box );
  812. }
  813. else
  814. {
  815. return arect.IntersectsCircle( GetStart(), GetWidth() / 2 );
  816. }
  817. }
  818. wxString TRACK::GetSelectMenuText( EDA_UNITS aUnits ) const
  819. {
  820. return wxString::Format( _("Track %s %s on %s, length: %s" ),
  821. MessageTextFromValue( aUnits, m_Width ),
  822. GetNetnameMsg(),
  823. GetLayerName(),
  824. MessageTextFromValue( aUnits, GetLength() ) );
  825. }
  826. BITMAP_DEF TRACK::GetMenuImage() const
  827. {
  828. return add_tracks_xpm;
  829. }
  830. void TRACK::SwapData( BOARD_ITEM* aImage )
  831. {
  832. assert( aImage->Type() == PCB_TRACE_T );
  833. std::swap( *((TRACK*) this), *((TRACK*) aImage) );
  834. }
  835. void ARC::SwapData( BOARD_ITEM* aImage )
  836. {
  837. assert( aImage->Type() == PCB_ARC_T );
  838. std::swap( *this, *static_cast<ARC*>( aImage ) );
  839. }
  840. void VIA::SwapData( BOARD_ITEM* aImage )
  841. {
  842. assert( aImage->Type() == PCB_VIA_T );
  843. std::swap( *((VIA*) this), *((VIA*) aImage) );
  844. }
  845. const wxPoint ARC::GetPosition() const
  846. {
  847. auto center = GetArcCenter( VECTOR2I( m_Start ), VECTOR2I( m_Mid ), VECTOR2I( m_End ) );
  848. return wxPoint( center.x, center.y );
  849. }
  850. double ARC::GetRadius() const
  851. {
  852. auto center = GetArcCenter( VECTOR2I( m_Start ), VECTOR2I( m_Mid ), VECTOR2I( m_End ) );
  853. return GetLineLength( wxPoint( center ), m_Start );
  854. }
  855. double ARC::GetAngle() const
  856. {
  857. wxPoint center = GetPosition();
  858. wxPoint p0 = m_Start - center;
  859. wxPoint p1 = m_Mid - center;
  860. wxPoint p2 = m_End - center;
  861. double angle1 = ArcTangente( p1.y, p1.x ) - ArcTangente( p0.y, p0.x );
  862. double angle2 = ArcTangente( p2.y, p2.x ) - ArcTangente( p1.y, p1.x );
  863. return NormalizeAngle180( angle1 ) + NormalizeAngle180( angle2 );
  864. }
  865. double ARC::GetArcAngleStart() const
  866. {
  867. wxPoint center = GetPosition();
  868. double angleStart = ArcTangente( m_Start.y - center.y,
  869. m_Start.x - center.x );
  870. return NormalizeAnglePos( angleStart );
  871. }
  872. double ARC::GetArcAngleEnd() const
  873. {
  874. wxPoint center = GetPosition();
  875. double angleEnd = ArcTangente( m_End.y - center.y,
  876. m_End.x - center.x );
  877. return NormalizeAnglePos( angleEnd );
  878. }
  879. #if defined(DEBUG)
  880. wxString TRACK::ShowState( int stateBits )
  881. {
  882. wxString ret;
  883. if( stateBits & IS_LINKED )
  884. ret << wxT( " | IS_LINKED" );
  885. if( stateBits & TRACK_AR )
  886. ret << wxT( " | TRACK_AR" );
  887. if( stateBits & TRACK_LOCKED )
  888. ret << wxT( " | TRACK_LOCKED" );
  889. if( stateBits & IN_EDIT )
  890. ret << wxT( " | IN_EDIT" );
  891. if( stateBits & IS_DRAGGED )
  892. ret << wxT( " | IS_DRAGGED" );
  893. if( stateBits & DO_NOT_DRAW )
  894. ret << wxT( " | DO_NOT_DRAW" );
  895. if( stateBits & IS_DELETED )
  896. ret << wxT( " | IS_DELETED" );
  897. if( stateBits & BUSY )
  898. ret << wxT( " | BUSY" );
  899. if( stateBits & END_ONPAD )
  900. ret << wxT( " | END_ONPAD" );
  901. if( stateBits & BEGIN_ONPAD )
  902. ret << wxT( " | BEGIN_ONPAD" );
  903. if( stateBits & FLAG0 )
  904. ret << wxT( " | FLAG0" );
  905. if( stateBits & FLAG1 )
  906. ret << wxT( " | FLAG1" );
  907. return ret;
  908. }
  909. #endif