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.

926 lines
32 KiB

// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 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
13 years ago
12 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 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-2017 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. /**
  27. * @file class_pad_draw_functions.cpp
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <common.h>
  32. #include <trigo.h>
  33. #include <pcb_screen.h>
  34. #include <class_drawpanel.h>
  35. #include <draw_graphic_text.h>
  36. #include <layers_id_colors_and_visibility.h>
  37. #include <pcb_edit_frame.h>
  38. #include <pcbnew_id.h> // ID_TRACK_BUTT
  39. #include <pcbnew.h>
  40. #include <class_board.h>
  41. #include <convert_basic_shapes_to_polygon.h>
  42. /* uncomment this line to show this pad with its specfic size and color
  43. * when it is not on copper layers, and only one solder mask layer or solder paste layer
  44. * is displayed for this pad
  45. * After testing this feature,I am not sure this is a good idea
  46. * but the code is left here.
  47. */
  48. //#define SHOW_PADMASK_REAL_SIZE_AND_COLOR
  49. // Helper class to store parameters used to draw a pad
  50. PAD_DRAWINFO::PAD_DRAWINFO()
  51. {
  52. m_DrawPanel = NULL;
  53. m_DrawMode = GR_COPY;
  54. m_Color = BLACK;
  55. m_HoleColor = BLACK; // could be DARKGRAY;
  56. m_NPHoleColor = YELLOW;
  57. m_NoNetMarkColor = BLUE;
  58. m_PadClearance = 0;
  59. m_Display_padnum = true;
  60. m_Display_netname = true;
  61. m_ShowPadFilled = true;
  62. m_ShowNCMark = true;
  63. m_ShowNotPlatedHole = false;
  64. m_IsPrinting = false;
  65. }
  66. void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
  67. const wxPoint& aOffset )
  68. {
  69. wxSize mask_margin; // margin (clearance) used for some non copper layers
  70. #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
  71. int showActualMaskSize = 0; /* Layer number if the actual pad size on mask layer can
  72. * be displayed i.e. if only one layer is shown for this pad
  73. * and this layer is a mask (solder mask or solder paste
  74. */
  75. #endif
  76. if( m_Flags & DO_NOT_DRAW )
  77. return;
  78. PAD_DRAWINFO drawInfo;
  79. drawInfo.m_Offset = aOffset;
  80. /* We can show/hide pads from the layer manager.
  81. * options are show/hide pads on front and/or back side of the board
  82. * For through pads, we hide them only if both sides are hidden.
  83. * smd pads on back are hidden for all layers (copper and technical layers)
  84. * on back side of the board
  85. * smd pads on front are hidden for all layers (copper and technical layers)
  86. * on front side of the board
  87. * ECO, edge and Draw layers and not considered
  88. */
  89. BOARD* brd = GetBoard();
  90. auto frame = static_cast<PCB_EDIT_FRAME*> ( aPanel->GetParent() );
  91. const auto& cds = frame->Settings().Colors();
  92. bool frontVisible = brd->IsElementVisible( LAYER_PAD_FR );
  93. bool backVisible = brd->IsElementVisible( LAYER_PAD_BK );
  94. if( !frontVisible && !backVisible )
  95. return;
  96. // If pad is only on front side (no layer on back side)
  97. // and if hide front side pads is enabled, do not draw
  98. if( !frontVisible && !( m_layerMask & LSET::BackMask() ).any() )
  99. return;
  100. // If pad is only on back side (no layer on front side)
  101. // and if hide back side pads is enabled, do not draw
  102. if( !backVisible && !( m_layerMask & LSET::FrontMask() ).any() )
  103. return;
  104. wxCHECK_RET( frame != NULL, wxT( "Panel has no parent frame window." ) );
  105. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( frame->GetDisplayOptions() );
  106. PCB_SCREEN* screen = frame->GetScreen();
  107. if( displ_opts && displ_opts->m_DisplayPadFill == SKETCH )
  108. drawInfo.m_ShowPadFilled = false;
  109. else
  110. drawInfo.m_ShowPadFilled = true;
  111. COLOR4D color = COLOR4D::BLACK;
  112. if( m_layerMask[F_Cu] )
  113. {
  114. color = cds.GetItemColor( LAYER_PAD_FR );
  115. }
  116. if( m_layerMask[B_Cu] )
  117. {
  118. color = color.LegacyMix( cds.GetItemColor( LAYER_PAD_BK ) );
  119. }
  120. if( color == BLACK ) // Not on a visible copper layer (i.e. still nothing to show)
  121. {
  122. // If the pad is on only one tech layer, use the layer color else use DARKGRAY
  123. LSET mask_non_copper_layers = m_layerMask & ~LSET::AllCuMask();
  124. #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
  125. mask_non_copper_layers &= brd->GetVisibleLayers();
  126. #endif
  127. PCB_LAYER_ID pad_layer = mask_non_copper_layers.ExtractLayer();
  128. switch( (int) pad_layer )
  129. {
  130. case UNDEFINED_LAYER: // More than one layer
  131. color = DARKGRAY;
  132. break;
  133. case UNSELECTED_LAYER: // Shouldn't really happen...
  134. break;
  135. default:
  136. color = cds.GetLayerColor( pad_layer );
  137. #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
  138. showActualMaskSize = pad_layer;
  139. #endif
  140. }
  141. }
  142. // if SMD or connector pad and high contrast mode
  143. if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
  144. ( GetAttribute() == PAD_ATTRIB_SMD || GetAttribute() == PAD_ATTRIB_CONN ) &&
  145. displ_opts && displ_opts->m_ContrastModeDisplay )
  146. {
  147. // when routing tracks
  148. if( frame->GetToolId() == ID_TRACK_BUTT )
  149. {
  150. PCB_LAYER_ID routeTop = screen->m_Route_Layer_TOP;
  151. PCB_LAYER_ID routeBot = screen->m_Route_Layer_BOTTOM;
  152. // if routing between copper and component layers,
  153. // or the current layer is one of said 2 external copper layers,
  154. // then highlight only the current layer.
  155. if( ( screen->m_Active_Layer == F_Cu || screen->m_Active_Layer == B_Cu ) ||
  156. ( routeTop==F_Cu && routeBot==B_Cu ) ||
  157. ( routeTop==B_Cu && routeBot==F_Cu )
  158. )
  159. {
  160. if( !IsOnLayer( screen->m_Active_Layer ) )
  161. color = COLOR4D( DARKDARKGRAY );
  162. }
  163. // else routing between an internal signal layer and some other
  164. // layer. Grey out all PAD_ATTRIB_SMD pads not on current or the single
  165. // selected external layer.
  166. else if( !IsOnLayer( screen->m_Active_Layer )
  167. && !IsOnLayer( routeTop )
  168. && !IsOnLayer( routeBot ) )
  169. {
  170. color = COLOR4D( DARKDARKGRAY );
  171. }
  172. }
  173. // when not edting tracks, show PAD_ATTRIB_SMD components not on active layer
  174. // as greyed out
  175. else
  176. {
  177. if( !IsOnLayer( screen->m_Active_Layer ) )
  178. color = COLOR4D( DARKDARKGRAY );
  179. }
  180. }
  181. #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
  182. if( showActualMaskSize )
  183. {
  184. switch( showActualMaskSize )
  185. {
  186. case B_Mask:
  187. case F_Mask:
  188. mask_margin.x = mask_margin.y = GetSolderMaskMargin();
  189. break;
  190. case B_Paste:
  191. case F_Paste:
  192. mask_margin = GetSolderPasteMargin();
  193. break;
  194. default:
  195. // Another layer which has no margin to handle
  196. break;
  197. }
  198. }
  199. #endif
  200. // if Contrast mode is ON and a technical layer active, show pads on this
  201. // layer so we can see pads on paste or solder layer and the size of the
  202. // mask
  203. if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
  204. displ_opts && displ_opts->m_ContrastModeDisplay && !IsCopperLayer( screen->m_Active_Layer ) )
  205. {
  206. if( IsOnLayer( screen->m_Active_Layer ) )
  207. {
  208. color = cds.GetLayerColor( screen->m_Active_Layer );
  209. // In high contrast mode, and if the active layer is the mask
  210. // layer shows the pad size with the mask clearance
  211. switch( screen->m_Active_Layer )
  212. {
  213. case B_Mask:
  214. case F_Mask:
  215. mask_margin.x = mask_margin.y = GetSolderMaskMargin();
  216. break;
  217. case B_Paste:
  218. case F_Paste:
  219. mask_margin = GetSolderPasteMargin();
  220. break;
  221. default:
  222. break;
  223. }
  224. }
  225. else
  226. color = DARKDARKGRAY;
  227. }
  228. if( ( aDraw_mode & GR_HIGHLIGHT ) && !( aDraw_mode & GR_AND ) )
  229. color.SetToLegacyHighlightColor();
  230. bool DisplayIsol = displ_opts && displ_opts->m_DisplayPadIsol;
  231. if( !( m_layerMask & LSET::AllCuMask() ).any() )
  232. DisplayIsol = false;
  233. if( ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) &&
  234. brd->IsElementVisible( LAYER_NON_PLATEDHOLES ) )
  235. {
  236. drawInfo.m_ShowNotPlatedHole = true;
  237. drawInfo.m_NPHoleColor = cds.GetItemColor( LAYER_NON_PLATEDHOLES );
  238. }
  239. drawInfo.m_DrawMode = aDraw_mode;
  240. drawInfo.m_Color = color;
  241. drawInfo.m_NoNetMarkColor = cds.GetItemColor( LAYER_NO_CONNECTS );
  242. drawInfo.m_DrawPanel = aPanel;
  243. drawInfo.m_Mask_margin = mask_margin;
  244. drawInfo.m_ShowNCMark = brd->IsElementVisible( LAYER_NO_CONNECTS );
  245. drawInfo.m_IsPrinting = screen->m_IsPrinting;
  246. color.a = 0.666;
  247. /* Get the pad clearance. This has a meaning only for Pcbnew.
  248. * for CvPcb GetClearance() creates debug errors because
  249. * there is no net classes so a call to GetClearance() is made only when
  250. * needed (never needed in CvPcb)
  251. */
  252. drawInfo.m_PadClearance = DisplayIsol ? GetClearance() : 0;
  253. // Draw the pad number
  254. if( displ_opts && !displ_opts->m_DisplayPadNum )
  255. drawInfo.m_Display_padnum = false;
  256. if( displ_opts &&
  257. (( displ_opts ->m_DisplayNetNamesMode == 0 ) || ( displ_opts->m_DisplayNetNamesMode == 2 )) )
  258. drawInfo.m_Display_netname = false;
  259. // Display net names is restricted to pads that are on the active layer
  260. // in high contrast mode display
  261. if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
  262. !IsOnLayer( screen->m_Active_Layer ) && displ_opts && displ_opts->m_ContrastModeDisplay )
  263. drawInfo.m_Display_netname = false;
  264. DrawShape( aPanel->GetClipBox(), aDC, drawInfo );
  265. }
  266. void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
  267. {
  268. wxPoint coord[12];
  269. double angle = m_Orient;
  270. int seg_width;
  271. GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
  272. // calculate pad shape position :
  273. wxPoint shape_pos = ShapePos() - aDrawInfo.m_Offset;
  274. wxSize halfsize = m_Size;
  275. halfsize.x >>= 1;
  276. halfsize.y >>= 1;
  277. switch( GetShape() )
  278. {
  279. case PAD_SHAPE_CIRCLE:
  280. if( aDrawInfo.m_ShowPadFilled )
  281. GRFilledCircle( aClipBox, aDC, shape_pos.x, shape_pos.y,
  282. halfsize.x + aDrawInfo.m_Mask_margin.x, 0,
  283. aDrawInfo.m_Color, aDrawInfo.m_Color );
  284. else
  285. GRCircle( aClipBox, aDC, shape_pos.x, shape_pos.y,
  286. halfsize.x + aDrawInfo.m_Mask_margin.x,
  287. m_PadSketchModePenSize, aDrawInfo.m_Color );
  288. if( aDrawInfo.m_PadClearance )
  289. {
  290. GRCircle( aClipBox,
  291. aDC, shape_pos.x, shape_pos.y,
  292. halfsize.x + aDrawInfo.m_PadClearance,
  293. 0, aDrawInfo.m_Color );
  294. }
  295. break;
  296. case PAD_SHAPE_OVAL:
  297. {
  298. wxPoint segStart, segEnd;
  299. seg_width = BuildSegmentFromOvalShape(segStart, segEnd, angle,
  300. aDrawInfo.m_Mask_margin);
  301. segStart += shape_pos;
  302. segEnd += shape_pos;
  303. if( aDrawInfo.m_ShowPadFilled )
  304. {
  305. GRFillCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
  306. seg_width, aDrawInfo.m_Color );
  307. }
  308. else
  309. {
  310. GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
  311. seg_width, m_PadSketchModePenSize, aDrawInfo.m_Color );
  312. }
  313. // Draw the clearance line
  314. if( aDrawInfo.m_PadClearance )
  315. {
  316. seg_width += 2 * aDrawInfo.m_PadClearance;
  317. GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
  318. seg_width, aDrawInfo.m_Color );
  319. }
  320. }
  321. break;
  322. case PAD_SHAPE_RECT:
  323. case PAD_SHAPE_TRAPEZOID:
  324. BuildPadPolygon( coord, aDrawInfo.m_Mask_margin, angle );
  325. for( int ii = 0; ii < 4; ii++ )
  326. coord[ii] += shape_pos;
  327. GRClosedPoly( aClipBox, aDC, 4, coord, aDrawInfo.m_ShowPadFilled,
  328. aDrawInfo.m_ShowPadFilled ? 0 : m_PadSketchModePenSize,
  329. aDrawInfo.m_Color, aDrawInfo.m_Color );
  330. if( aDrawInfo.m_PadClearance )
  331. {
  332. #define SEGCOUNT 32 // number of segments to approximate a circle
  333. SHAPE_POLY_SET outline;
  334. TransformShapeWithClearanceToPolygon( outline, aDrawInfo.m_PadClearance, SEGCOUNT, 1.0 );
  335. // Draw the polygon: Inflate creates only one convex polygon
  336. if( outline.OutlineCount() > 0 )
  337. {
  338. SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
  339. if( poly.PointCount() > 0 )
  340. {
  341. GRClosedPoly( aClipBox, aDC, poly.PointCount(),
  342. (wxPoint*)&poly.Point( 0 ), false, 0,
  343. aDrawInfo.m_Color, aDrawInfo.m_Color );
  344. }
  345. }
  346. }
  347. break;
  348. case PAD_SHAPE_ROUNDRECT:
  349. {
  350. // Use solder[Paste/Mask]size or pad size to build pad shape to draw
  351. wxSize size( GetSize() );
  352. size += aDrawInfo.m_Mask_margin * 2;
  353. int corner_radius = GetRoundRectCornerRadius( size );
  354. // Draw the polygon: Inflate creates only one convex polygon
  355. SHAPE_POLY_SET outline;
  356. bool filled = aDrawInfo.m_ShowPadFilled;
  357. if( filled )
  358. {
  359. wxPoint centers[4];
  360. GetRoundRectCornerCenters( centers, corner_radius, shape_pos,
  361. size, GetOrientation() );
  362. GRClosedPoly( aClipBox, aDC, 4, centers, true, corner_radius*2,
  363. aDrawInfo.m_Color, aDrawInfo.m_Color );
  364. }
  365. else
  366. {
  367. TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
  368. corner_radius, 64 );
  369. if( outline.OutlineCount() > 0 )
  370. {
  371. SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
  372. if( poly.PointCount() > 0 )
  373. {
  374. GRClosedPoly( aClipBox, aDC, poly.PointCount(),
  375. (wxPoint*)&poly.Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
  376. aDrawInfo.m_Color, aDrawInfo.m_Color );
  377. }
  378. }
  379. }
  380. if( aDrawInfo.m_PadClearance )
  381. {
  382. outline.RemoveAllContours();
  383. size = GetSize();
  384. size.x += aDrawInfo.m_PadClearance * 2;
  385. size.y += aDrawInfo.m_PadClearance * 2;
  386. corner_radius = GetRoundRectCornerRadius() + aDrawInfo.m_PadClearance;
  387. TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
  388. corner_radius, 32 );
  389. if( outline.OutlineCount() > 0 )
  390. {
  391. // Draw the polygon: Inflate creates only one convex polygon
  392. SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
  393. if( clearance_poly.PointCount() > 0 )
  394. {
  395. GRClosedPoly( aClipBox, aDC, clearance_poly.PointCount(),
  396. (wxPoint*)&clearance_poly.Point( 0 ), false, 0,
  397. aDrawInfo.m_Color, aDrawInfo.m_Color );
  398. }
  399. }
  400. }
  401. }
  402. break;
  403. case PAD_SHAPE_CUSTOM:
  404. {
  405. // The full shape has 2 items
  406. // 1- The anchor pad: a round or rect pad located at pad position
  407. // 2- The custom complex shape
  408. // Note: The anchor pad shape is containing by the custom complex shape polygon
  409. // The anchor pad is shown to help user to see where is the anchor, only in sketch mode
  410. // (In filled mode, it is merged with the basic shapes)
  411. wxPoint pad_pos = GetPosition() - aDrawInfo.m_Offset;
  412. // In sketch mode only: Draw the anchor pad: a round or rect pad
  413. if( !aDrawInfo.m_ShowPadFilled )
  414. {
  415. if( GetAnchorPadShape() == PAD_SHAPE_RECT )
  416. {
  417. wxPoint poly[4];
  418. poly[0] = wxPoint( - halfsize.x, - halfsize.y );
  419. poly[1] = wxPoint( - halfsize.x, + halfsize.y );
  420. poly[2] = wxPoint( + halfsize.x, + halfsize.y );
  421. poly[3] = wxPoint( + halfsize.x, - halfsize.y );
  422. for( int ii = 0; ii < 4; ++ii )
  423. {
  424. RotatePoint( &poly[ii], m_Orient );
  425. poly[ii] += pad_pos;
  426. }
  427. GRClosedPoly( aClipBox, aDC, 4, poly, false, 0,
  428. aDrawInfo.m_Color, aDrawInfo.m_Color );
  429. }
  430. else
  431. {
  432. GRCircle( aClipBox, aDC, pad_pos.x, pad_pos.y,
  433. halfsize.x,
  434. m_PadSketchModePenSize, aDrawInfo.m_Color );
  435. }
  436. }
  437. SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
  438. outline.Append( m_customShapeAsPolygon );
  439. CustomShapeAsPolygonToBoardPosition( &outline, pad_pos, GetOrientation() );
  440. SHAPE_LINE_CHAIN* poly;
  441. const int segmentToCircleCount = 32;
  442. if( aDrawInfo.m_Mask_margin.x )
  443. {
  444. SHAPE_POLY_SET clearance_outline;
  445. clearance_outline.Append( outline );
  446. clearance_outline.Inflate( aDrawInfo.m_Mask_margin.x, segmentToCircleCount );
  447. poly = &clearance_outline.Outline( 0 );
  448. }
  449. else
  450. {
  451. // Draw the polygon: only one polygon is expected
  452. // However we provide a multi polygon shape drawing
  453. // ( for the future or to show a non expected shape )
  454. for( int jj = 0; jj < outline.OutlineCount(); ++jj )
  455. {
  456. poly = &outline.Outline( jj );
  457. GRClosedPoly( aClipBox, aDC, poly->PointCount(),
  458. (wxPoint*)&poly->Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
  459. aDrawInfo.m_Color, aDrawInfo.m_Color );
  460. }
  461. }
  462. if( aDrawInfo.m_PadClearance )
  463. {
  464. SHAPE_POLY_SET clearance_outline;
  465. clearance_outline.Append( outline );
  466. clearance_outline.Inflate( aDrawInfo.m_PadClearance, segmentToCircleCount );
  467. for( int jj = 0; jj < clearance_outline.OutlineCount(); ++jj )
  468. {
  469. poly = &clearance_outline.Outline( jj );
  470. if( poly->PointCount() > 0 )
  471. {
  472. GRClosedPoly( aClipBox, aDC, poly->PointCount(),
  473. (wxPoint*)&poly->Point( 0 ), false, 0,
  474. aDrawInfo.m_Color, aDrawInfo.m_Color );
  475. }
  476. }
  477. }
  478. break;
  479. }
  480. default:
  481. break;
  482. }
  483. // Draw the pad hole
  484. wxPoint holepos = m_Pos - aDrawInfo.m_Offset;
  485. int hole = m_Drill.x >> 1;
  486. bool drawhole = hole > 0;
  487. if( !aDrawInfo.m_ShowPadFilled && !aDrawInfo.m_ShowNotPlatedHole )
  488. drawhole = false;
  489. if( drawhole )
  490. {
  491. bool blackpenstate = false;
  492. if( aDrawInfo.m_IsPrinting )
  493. {
  494. blackpenstate = GetGRForceBlackPenState();
  495. GRForceBlackPen( false );
  496. aDrawInfo.m_HoleColor = WHITE;
  497. aDrawInfo.m_NPHoleColor = WHITE;
  498. }
  499. else
  500. {
  501. GRSetDrawMode( aDC, ( aDrawInfo.m_DrawMode != GR_XOR ) ? GR_COPY : GR_XOR );
  502. }
  503. COLOR4D hole_color = aDrawInfo.m_HoleColor;
  504. if( aDrawInfo. m_ShowNotPlatedHole ) // Draw a specific hole color
  505. hole_color = aDrawInfo.m_NPHoleColor;
  506. switch( GetDrillShape() )
  507. {
  508. case PAD_DRILL_SHAPE_CIRCLE:
  509. if( aDC->LogicalToDeviceXRel( hole ) > 1 ) // hole is drawn if hole > 1pixel
  510. GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
  511. hole_color, hole_color );
  512. break;
  513. case PAD_DRILL_SHAPE_OBLONG:
  514. {
  515. wxPoint drl_start, drl_end;
  516. GetOblongDrillGeometry( drl_start, drl_end, seg_width );
  517. GRFilledSegment( aClipBox, aDC, holepos + drl_start,
  518. holepos + drl_end, seg_width, hole_color );
  519. }
  520. break;
  521. default:
  522. break;
  523. }
  524. if( aDrawInfo.m_IsPrinting )
  525. GRForceBlackPen( blackpenstate );
  526. }
  527. GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
  528. // Draw "No connect" ( / or \ or cross X ) if necessary
  529. if( GetNetCode() == 0 && aDrawInfo.m_ShowNCMark )
  530. {
  531. int dx0 = std::min( halfsize.x, halfsize.y );
  532. if( m_layerMask[F_Cu] ) /* Draw \ */
  533. GRLine( aClipBox, aDC, holepos.x - dx0, holepos.y - dx0,
  534. holepos.x + dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
  535. if( m_layerMask[B_Cu] ) // Draw /
  536. GRLine( aClipBox, aDC, holepos.x + dx0, holepos.y - dx0,
  537. holepos.x - dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
  538. }
  539. if( !aDrawInfo.m_IsPrinting )
  540. GRSetDrawMode( aDC, ( aDrawInfo.m_DrawMode != GR_XOR ) ? GR_COPY : GR_XOR );
  541. // Draw the pad number
  542. if( !aDrawInfo.m_Display_padnum && !aDrawInfo.m_Display_netname )
  543. return;
  544. wxPoint tpos0 = shape_pos; // Position of the centre of text
  545. wxPoint tpos = tpos0;
  546. wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x
  547. int shortname_len = 0;
  548. if( aDrawInfo.m_Display_netname )
  549. shortname_len = GetShortNetname().Len();
  550. if( GetShape() == PAD_SHAPE_CIRCLE )
  551. angle = 0;
  552. AreaSize = m_Size;
  553. if( m_Size.y > m_Size.x )
  554. {
  555. angle += 900;
  556. AreaSize.x = m_Size.y;
  557. AreaSize.y = m_Size.x;
  558. }
  559. if( shortname_len > 0 ) // if there is a netname, provides room to display this netname
  560. {
  561. AreaSize.y /= 2; // Text used only the upper area of the
  562. // pad. The lower area displays the net name
  563. tpos.y -= AreaSize.y / 2;
  564. }
  565. // Calculate the position of text, that is the middle point of the upper
  566. // area of the pad
  567. RotatePoint( &tpos, shape_pos, angle );
  568. // Draw text with an angle between -90 deg and + 90 deg
  569. double t_angle = angle;
  570. NORMALIZE_ANGLE_90( t_angle );
  571. /* Note: in next calculations, texte size is calculated for 3 or more
  572. * chars. Of course, pads numbers and nets names can have less than 3
  573. * chars. but after some tries, i found this is gives the best look
  574. */
  575. constexpr int MIN_CHAR_COUNT = 3;
  576. unsigned int tsize;
  577. EDA_RECT* clipBox = aDrawInfo.m_DrawPanel?
  578. aDrawInfo.m_DrawPanel->GetClipBox() : NULL;
  579. if( aDrawInfo.m_Display_padnum )
  580. {
  581. int numpad_len = std::max( (int) m_name.Length(), MIN_CHAR_COUNT );
  582. tsize = std::min( (int) AreaSize.y, AreaSize.x / numpad_len );
  583. if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable when size too small.
  584. {
  585. // tsize reserve room for marges and segments thickness
  586. tsize = ( tsize * 7 ) / 10;
  587. DrawGraphicHaloText( clipBox, aDC, tpos,
  588. aDrawInfo.m_Color, BLACK, WHITE,
  589. m_name, t_angle,
  590. wxSize( tsize , tsize ), GR_TEXT_HJUSTIFY_CENTER,
  591. GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
  592. }
  593. }
  594. // display the short netname, if exists
  595. if( shortname_len == 0 )
  596. return;
  597. shortname_len = std::max( shortname_len, MIN_CHAR_COUNT );
  598. tsize = std::min( AreaSize.y, AreaSize.x / shortname_len );
  599. if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable in size too small.
  600. {
  601. tpos = tpos0;
  602. if( aDrawInfo.m_Display_padnum )
  603. tpos.y += AreaSize.y / 2;
  604. RotatePoint( &tpos, shape_pos, angle );
  605. // tsize reserve room for marges and segments thickness
  606. tsize = ( tsize * 7 ) / 10;
  607. DrawGraphicHaloText( clipBox, aDC, tpos,
  608. aDrawInfo.m_Color, BLACK, WHITE,
  609. GetShortNetname(), t_angle,
  610. wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
  611. GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
  612. }
  613. }
  614. /**
  615. * Function BuildSegmentFromOvalShape
  616. * Has meaning only for OVAL (and ROUND) pads.
  617. * Build an equivalent segment having the same shape as the OVAL shape,
  618. * aSegStart and aSegEnd are the ending points of the equivalent segment of the shape
  619. * aRotation is the asked rotation of the segment (usually m_Orient)
  620. */
  621. int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd,
  622. double aRotation, const wxSize& aMargin) const
  623. {
  624. int width;
  625. if( m_Size.y < m_Size.x ) // Build an horizontal equiv segment
  626. {
  627. int delta = ( m_Size.x - m_Size.y ) / 2;
  628. aSegStart.x = -delta - aMargin.x;
  629. aSegStart.y = 0;
  630. aSegEnd.x = delta + aMargin.x;
  631. aSegEnd.y = 0;
  632. width = m_Size.y + ( aMargin.y * 2 );
  633. }
  634. else // Vertical oval: build a vertical equiv segment
  635. {
  636. int delta = ( m_Size.y -m_Size.x ) / 2;
  637. aSegStart.x = 0;
  638. aSegStart.y = -delta - aMargin.y;
  639. aSegEnd.x = 0;
  640. aSegEnd.y = delta + aMargin.y;
  641. width = m_Size.x + ( aMargin.x * 2 );
  642. }
  643. if( aRotation )
  644. {
  645. RotatePoint( &aSegStart, aRotation);
  646. RotatePoint( &aSegEnd, aRotation);
  647. }
  648. return width;
  649. }
  650. void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
  651. double aRotation ) const
  652. {
  653. wxSize delta;
  654. wxSize halfsize;
  655. halfsize.x = m_Size.x >> 1;
  656. halfsize.y = m_Size.y >> 1;
  657. switch( GetShape() )
  658. {
  659. case PAD_SHAPE_RECT:
  660. // For rectangular shapes, inflate is easy
  661. halfsize += aInflateValue;
  662. // Verify if do not deflate more than than size
  663. // Only possible for inflate negative values.
  664. if( halfsize.x < 0 )
  665. halfsize.x = 0;
  666. if( halfsize.y < 0 )
  667. halfsize.y = 0;
  668. break;
  669. case PAD_SHAPE_TRAPEZOID:
  670. // Trapezoidal pad: verify delta values
  671. delta.x = ( m_DeltaSize.x >> 1 );
  672. delta.y = ( m_DeltaSize.y >> 1 );
  673. // be sure delta values are not to large
  674. if( (delta.x < 0) && (delta.x <= -halfsize.y) )
  675. delta.x = -halfsize.y + 1;
  676. if( (delta.x > 0) && (delta.x >= halfsize.y) )
  677. delta.x = halfsize.y - 1;
  678. if( (delta.y < 0) && (delta.y <= -halfsize.x) )
  679. delta.y = -halfsize.x + 1;
  680. if( (delta.y > 0) && (delta.y >= halfsize.x) )
  681. delta.y = halfsize.x - 1;
  682. break;
  683. default: // is used only for rect and trap. pads
  684. return;
  685. }
  686. // Build the basic rectangular or trapezoid shape
  687. // delta is null for rectangular shapes
  688. aCoord[0].x = -halfsize.x - delta.y; // lower left
  689. aCoord[0].y = +halfsize.y + delta.x;
  690. aCoord[1].x = -halfsize.x + delta.y; // upper left
  691. aCoord[1].y = -halfsize.y - delta.x;
  692. aCoord[2].x = +halfsize.x - delta.y; // upper right
  693. aCoord[2].y = -halfsize.y + delta.x;
  694. aCoord[3].x = +halfsize.x + delta.y; // lower right
  695. aCoord[3].y = +halfsize.y - delta.x;
  696. // Offsetting the trapezoid shape id needed
  697. // It is assumed delta.x or/and delta.y == 0
  698. if( GetShape() == PAD_SHAPE_TRAPEZOID && (aInflateValue.x != 0 || aInflateValue.y != 0) )
  699. {
  700. double angle;
  701. wxSize corr;
  702. if( delta.y ) // lower and upper segment is horizontal
  703. {
  704. // Calculate angle of left (or right) segment with vertical axis
  705. angle = atan2( (double) m_DeltaSize.y, (double) m_Size.y );
  706. // left and right sides are moved by aInflateValue.x in their perpendicular direction
  707. // We must calculate the corresponding displacement on the horizontal axis
  708. // that is delta.x +- corr.x depending on the corner
  709. corr.x = KiROUND( tan( angle ) * aInflateValue.x );
  710. delta.x = KiROUND( aInflateValue.x / cos( angle ) );
  711. // Horizontal sides are moved up and down by aInflateValue.y
  712. delta.y = aInflateValue.y;
  713. // corr.y = 0 by the constructor
  714. }
  715. else if( delta.x ) // left and right segment is vertical
  716. {
  717. // Calculate angle of lower (or upper) segment with horizontal axis
  718. angle = atan2( (double) m_DeltaSize.x, (double) m_Size.x );
  719. // lower and upper sides are moved by aInflateValue.x in their perpendicular direction
  720. // We must calculate the corresponding displacement on the vertical axis
  721. // that is delta.y +- corr.y depending on the corner
  722. corr.y = KiROUND( tan( angle ) * aInflateValue.y );
  723. delta.y = KiROUND( aInflateValue.y / cos( angle ) );
  724. // Vertical sides are moved left and right by aInflateValue.x
  725. delta.x = aInflateValue.x;
  726. // corr.x = 0 by the constructor
  727. }
  728. else // the trapezoid is a rectangle
  729. {
  730. delta = aInflateValue; // this pad is rectangular (delta null).
  731. }
  732. aCoord[0].x += -delta.x - corr.x; // lower left
  733. aCoord[0].y += delta.y + corr.y;
  734. aCoord[1].x += -delta.x + corr.x; // upper left
  735. aCoord[1].y += -delta.y - corr.y;
  736. aCoord[2].x += delta.x - corr.x; // upper right
  737. aCoord[2].y += -delta.y + corr.y;
  738. aCoord[3].x += delta.x + corr.x; // lower right
  739. aCoord[3].y += delta.y - corr.y;
  740. /* test coordinates and clamp them if the offset correction is too large:
  741. * Note: if a coordinate is bad, the other "symmetric" coordinate is bad
  742. * So when a bad coordinate is found, the 2 symmetric coordinates
  743. * are set to the minimun value (0)
  744. */
  745. if( aCoord[0].x > 0 ) // lower left x coordinate must be <= 0
  746. aCoord[0].x = aCoord[3].x = 0;
  747. if( aCoord[1].x > 0 ) // upper left x coordinate must be <= 0
  748. aCoord[1].x = aCoord[2].x = 0;
  749. if( aCoord[0].y < 0 ) // lower left y coordinate must be >= 0
  750. aCoord[0].y = aCoord[1].y = 0;
  751. if( aCoord[3].y < 0 ) // lower right y coordinate must be >= 0
  752. aCoord[3].y = aCoord[2].y = 0;
  753. }
  754. if( aRotation )
  755. {
  756. for( int ii = 0; ii < 4; ii++ )
  757. RotatePoint( &aCoord[ii], aRotation );
  758. }
  759. }