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.

1438 lines
39 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
11 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
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
12 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
14 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
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
14 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
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
9 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_pad.cpp
  27. * D_PAD class implementation.
  28. */
  29. #include <fctsys.h>
  30. #include <PolyLine.h>
  31. #include <trigo.h>
  32. #include <macros.h>
  33. #include <msgpanel.h>
  34. #include <base_units.h>
  35. #include <bitmaps.h>
  36. #include <view/view.h>
  37. #include <pcbnew.h>
  38. #include <class_board.h>
  39. #include <class_module.h>
  40. #include <polygon_test_point_inside.h>
  41. #include <convert_to_biu.h>
  42. #include <convert_basic_shapes_to_polygon.h>
  43. /**
  44. * Helper function
  45. * Return a string (to be shown to the user) describing a layer mask.
  46. * Useful for showing where is a pad.
  47. * The BOARD is needed because layer names are (somewhat) customizable
  48. */
  49. static wxString LayerMaskDescribe( const BOARD* aBoard, LSET aMask );
  50. int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode
  51. D_PAD::D_PAD( MODULE* parent ) :
  52. BOARD_CONNECTED_ITEM( parent, PCB_PAD_T )
  53. {
  54. m_Size.x = m_Size.y = Mils2iu( 60 ); // Default pad size 60 mils.
  55. m_Drill.x = m_Drill.y = Mils2iu( 30 ); // Default drill size 30 mils.
  56. m_Orient = 0; // Pad rotation in 1/10 degrees.
  57. m_LengthPadToDie = 0;
  58. if( m_Parent && m_Parent->Type() == PCB_MODULE_T )
  59. {
  60. m_Pos = GetParent()->GetPosition();
  61. }
  62. SetShape( PAD_SHAPE_CIRCLE ); // Default pad shape is PAD_CIRCLE.
  63. SetAnchorPadShape( PAD_SHAPE_CIRCLE ); // Default shape for custom shaped pads
  64. // is PAD_CIRCLE.
  65. SetDrillShape( PAD_DRILL_SHAPE_CIRCLE ); // Default pad drill shape is a circle.
  66. m_Attribute = PAD_ATTRIB_STANDARD; // Default pad type is NORMAL (thru hole)
  67. m_LocalClearance = 0;
  68. m_LocalSolderMaskMargin = 0;
  69. m_LocalSolderPasteMargin = 0;
  70. m_LocalSolderPasteMarginRatio = 0.0;
  71. // Parameters for round rect only:
  72. m_padRoundRectRadiusScale = 0.25; // from IPC-7351C standard
  73. m_ZoneConnection = PAD_ZONE_CONN_INHERITED; // Use parent setting by default
  74. m_ThermalWidth = 0; // Use parent setting by default
  75. m_ThermalGap = 0; // Use parent setting by default
  76. m_customShapeClearanceArea = CUST_PAD_SHAPE_IN_ZONE_OUTLINE;
  77. // Set layers mask to default for a standard thru hole pad.
  78. m_layerMask = StandardMask();
  79. SetSubRatsnest( 0 ); // used in ratsnest calculations
  80. m_boundingRadius = -1;
  81. }
  82. LSET D_PAD::StandardMask()
  83. {
  84. static LSET saved = LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask );
  85. return saved;
  86. }
  87. LSET D_PAD::SMDMask()
  88. {
  89. static LSET saved( 3, F_Cu, F_Paste, F_Mask );
  90. return saved;
  91. }
  92. LSET D_PAD::ConnSMDMask()
  93. {
  94. static LSET saved( 2, F_Cu, F_Mask );
  95. return saved;
  96. }
  97. LSET D_PAD::UnplatedHoleMask()
  98. {
  99. static LSET saved = LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask );
  100. return saved;
  101. }
  102. bool D_PAD::IsFlipped() const
  103. {
  104. if( GetParent() && GetParent()->GetLayer() == B_Cu )
  105. return true;
  106. return false;
  107. }
  108. int D_PAD::boundingRadius() const
  109. {
  110. int x, y;
  111. int radius;
  112. switch( GetShape() )
  113. {
  114. case PAD_SHAPE_CIRCLE:
  115. radius = m_Size.x / 2;
  116. break;
  117. case PAD_SHAPE_OVAL:
  118. radius = std::max( m_Size.x, m_Size.y ) / 2;
  119. break;
  120. case PAD_SHAPE_RECT:
  121. radius = 1 + KiROUND( EuclideanNorm( m_Size ) / 2 );
  122. break;
  123. case PAD_SHAPE_TRAPEZOID:
  124. x = m_Size.x + std::abs( m_DeltaSize.y ); // Remember: m_DeltaSize.y is the m_Size.x change
  125. y = m_Size.y + std::abs( m_DeltaSize.x ); // Remember: m_DeltaSize.x is the m_Size.y change
  126. radius = 1 + KiROUND( hypot( x, y ) / 2 );
  127. break;
  128. case PAD_SHAPE_ROUNDRECT:
  129. radius = GetRoundRectCornerRadius();
  130. x = m_Size.x >> 1;
  131. y = m_Size.y >> 1;
  132. radius += 1 + KiROUND( EuclideanNorm( wxSize( x - radius, y - radius )));
  133. break;
  134. case PAD_SHAPE_CUSTOM:
  135. radius = 0;
  136. for( int cnt = 0; cnt < m_customShapeAsPolygon.OutlineCount(); ++cnt )
  137. {
  138. const SHAPE_LINE_CHAIN& poly = m_customShapeAsPolygon.COutline( cnt );
  139. for( int ii = 0; ii < poly.PointCount(); ++ii )
  140. {
  141. int dist = KiROUND( poly.CPoint( ii ).EuclideanNorm() );
  142. radius = std::max( radius, dist );
  143. }
  144. }
  145. radius += 1;
  146. break;
  147. default:
  148. radius = 0;
  149. }
  150. return radius;
  151. }
  152. int D_PAD::GetRoundRectCornerRadius( const wxSize& aSize ) const
  153. {
  154. // radius of rounded corners, usually 25% of shorter pad edge for now
  155. int r = aSize.x > aSize.y ? aSize.y : aSize.x;
  156. r = int( r * m_padRoundRectRadiusScale );
  157. return r;
  158. }
  159. const EDA_RECT D_PAD::GetBoundingBox() const
  160. {
  161. EDA_RECT area;
  162. wxPoint quadrant1, quadrant2, quadrant3, quadrant4;
  163. int x, y, r, dx, dy;
  164. wxPoint center = ShapePos();
  165. wxPoint endPoint;
  166. EDA_RECT endRect;
  167. switch( GetShape() )
  168. {
  169. case PAD_SHAPE_CIRCLE:
  170. area.SetOrigin( center );
  171. area.Inflate( m_Size.x / 2 );
  172. break;
  173. case PAD_SHAPE_OVAL:
  174. /* To get the BoundingBox of an oval pad:
  175. * a) If the pad is ROUND, see method for PAD_SHAPE_CIRCLE above
  176. * OTHERWISE:
  177. * b) Construct EDA_RECT for portion between circular ends
  178. * c) Rotate that EDA_RECT
  179. * d) Add the circular ends to the EDA_RECT
  180. */
  181. // Test if the shape is circular
  182. if( m_Size.x == m_Size.y )
  183. {
  184. area.SetOrigin( center );
  185. area.Inflate( m_Size.x / 2 );
  186. break;
  187. }
  188. if( m_Size.x > m_Size.y )
  189. {
  190. // Pad is horizontal
  191. dx = ( m_Size.x - m_Size.y ) / 2;
  192. dy = m_Size.y / 2;
  193. // Location of end-points
  194. x = dx;
  195. y = 0;
  196. r = dy;
  197. }
  198. else
  199. {
  200. // Pad is vertical
  201. dx = m_Size.x / 2;
  202. dy = ( m_Size.y - m_Size.x ) / 2;
  203. x = 0;
  204. y = dy;
  205. r = dx;
  206. }
  207. // Construct the center rectangle and rotate
  208. area.SetOrigin( center );
  209. area.Inflate( dx, dy );
  210. area = area.GetBoundingBoxRotated( center, m_Orient );
  211. endPoint = wxPoint( x, y );
  212. RotatePoint( &endPoint, m_Orient );
  213. // Add points at each quadrant of circular regions
  214. endRect.SetOrigin( center + endPoint );
  215. endRect.Inflate( r );
  216. area.Merge( endRect );
  217. endRect.SetSize( 0, 0 );
  218. endRect.SetOrigin( center - endPoint );
  219. endRect.Inflate( r );
  220. area.Merge( endRect );
  221. break;
  222. case PAD_SHAPE_RECT:
  223. case PAD_SHAPE_ROUNDRECT:
  224. // Use two opposite corners and track their rotation
  225. // (use symmetry for other points)
  226. quadrant1.x = m_Size.x/2;
  227. quadrant1.y = m_Size.y/2;
  228. quadrant2.x = -m_Size.x/2;
  229. quadrant2.y = m_Size.y/2;
  230. RotatePoint( &quadrant1, m_Orient );
  231. RotatePoint( &quadrant2, m_Orient );
  232. dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
  233. dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
  234. // Set the bbox
  235. area.SetOrigin( ShapePos() );
  236. area.Inflate( dx, dy );
  237. break;
  238. case PAD_SHAPE_TRAPEZOID:
  239. // Use the four corners and track their rotation
  240. // (Trapezoids will not be symmetric)
  241. quadrant1.x = (m_Size.x + m_DeltaSize.y)/2;
  242. quadrant1.y = (m_Size.y - m_DeltaSize.x)/2;
  243. quadrant2.x = -(m_Size.x + m_DeltaSize.y)/2;
  244. quadrant2.y = (m_Size.y + m_DeltaSize.x)/2;
  245. quadrant3.x = -(m_Size.x - m_DeltaSize.y)/2;
  246. quadrant3.y = -(m_Size.y + m_DeltaSize.x)/2;
  247. quadrant4.x = (m_Size.x - m_DeltaSize.y)/2;
  248. quadrant4.y = -(m_Size.y - m_DeltaSize.x)/2;
  249. RotatePoint( &quadrant1, m_Orient );
  250. RotatePoint( &quadrant2, m_Orient );
  251. RotatePoint( &quadrant3, m_Orient );
  252. RotatePoint( &quadrant4, m_Orient );
  253. x = std::min( quadrant1.x, std::min( quadrant2.x, std::min( quadrant3.x, quadrant4.x) ) );
  254. y = std::min( quadrant1.y, std::min( quadrant2.y, std::min( quadrant3.y, quadrant4.y) ) );
  255. dx = std::max( quadrant1.x, std::max( quadrant2.x, std::max( quadrant3.x, quadrant4.x) ) );
  256. dy = std::max( quadrant1.y, std::max( quadrant2.y, std::max( quadrant3.y, quadrant4.y) ) );
  257. area.SetOrigin( ShapePos().x + x, ShapePos().y + y );
  258. area.SetSize( dx-x, dy-y );
  259. break;
  260. case PAD_SHAPE_CUSTOM:
  261. {
  262. SHAPE_POLY_SET polySet( m_customShapeAsPolygon );
  263. // Move shape to actual position
  264. CustomShapeAsPolygonToBoardPosition( &polySet, GetPosition(), GetOrientation() );
  265. quadrant1 = m_Pos;
  266. quadrant2 = m_Pos;
  267. for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
  268. {
  269. const SHAPE_LINE_CHAIN& poly = polySet.COutline( cnt );
  270. for( int ii = 0; ii < poly.PointCount(); ++ii )
  271. {
  272. quadrant1.x = std::min( quadrant1.x, poly.CPoint( ii ).x );
  273. quadrant1.y = std::min( quadrant1.y, poly.CPoint( ii ).y );
  274. quadrant2.x = std::max( quadrant2.x, poly.CPoint( ii ).x );
  275. quadrant2.y = std::max( quadrant2.y, poly.CPoint( ii ).y );
  276. }
  277. }
  278. area.SetOrigin( quadrant1 );
  279. area.SetEnd( quadrant2 );
  280. }
  281. break;
  282. default:
  283. break;
  284. }
  285. return area;
  286. }
  287. void D_PAD::SetDrawCoord()
  288. {
  289. MODULE* module = (MODULE*) m_Parent;
  290. m_Pos = m_Pos0;
  291. if( module == NULL )
  292. return;
  293. double angle = module->GetOrientation();
  294. RotatePoint( &m_Pos.x, &m_Pos.y, angle );
  295. m_Pos += module->GetPosition();
  296. }
  297. void D_PAD::SetLocalCoord()
  298. {
  299. MODULE* module = (MODULE*) m_Parent;
  300. if( module == NULL )
  301. {
  302. m_Pos0 = m_Pos;
  303. return;
  304. }
  305. m_Pos0 = m_Pos - module->GetPosition();
  306. RotatePoint( &m_Pos0.x, &m_Pos0.y, -module->GetOrientation() );
  307. }
  308. void D_PAD::SetAttribute( PAD_ATTR_T aAttribute )
  309. {
  310. m_Attribute = aAttribute;
  311. if( aAttribute == PAD_ATTRIB_SMD )
  312. m_Drill = wxSize( 0, 0 );
  313. }
  314. void D_PAD::SetOrientation( double aAngle )
  315. {
  316. NORMALIZE_ANGLE_POS( aAngle );
  317. m_Orient = aAngle;
  318. }
  319. void D_PAD::Flip( const wxPoint& aCentre )
  320. {
  321. int y = GetPosition().y;
  322. MIRROR( y, aCentre.y ); // invert about x axis.
  323. SetY( y );
  324. MIRROR( m_Pos0.y, 0 );
  325. MIRROR( m_Offset.y, 0 );
  326. MIRROR( m_DeltaSize.y, 0 );
  327. SetOrientation( -GetOrientation() );
  328. // flip pads layers
  329. // PADS items are currently on all copper layers, or
  330. // currently, only on Front or Back layers.
  331. // So the copper layers count is not taken in account
  332. SetLayerSet( FlipLayerMask( m_layerMask ) );
  333. // Flip the basic shapes, in custom pads
  334. FlipPrimitives();
  335. // m_boundingRadius = -1; the shape has not been changed
  336. }
  337. // Flip the basic shapes, in custom pads
  338. void D_PAD::FlipPrimitives()
  339. {
  340. // Flip custom shapes
  341. for( unsigned ii = 0; ii < m_basicShapes.size(); ++ii )
  342. {
  343. PAD_CS_PRIMITIVE& primitive = m_basicShapes[ii];
  344. MIRROR( primitive.m_Start.y, 0 );
  345. MIRROR( primitive.m_End.y, 0 );
  346. primitive.m_ArcAngle = -primitive.m_ArcAngle;
  347. switch( primitive.m_Shape )
  348. {
  349. case S_POLYGON: // polygon
  350. for( unsigned jj = 0; jj < primitive.m_Poly.size(); jj++ )
  351. MIRROR( primitive.m_Poly[jj].y, 0 );
  352. break;
  353. default:
  354. break;
  355. }
  356. }
  357. // Flip local coordinates in merged Polygon
  358. for( int cnt = 0; cnt < m_customShapeAsPolygon.OutlineCount(); ++cnt )
  359. {
  360. SHAPE_LINE_CHAIN& poly = m_customShapeAsPolygon.Outline( cnt );
  361. for( int ii = 0; ii < poly.PointCount(); ++ii )
  362. MIRROR( poly.Point( ii ).y, 0 );
  363. }
  364. }
  365. void D_PAD::AppendConfigs( PARAM_CFG_ARRAY* aResult )
  366. {
  367. // Parameters stored in config are only significant parameters
  368. // for a template.
  369. // So not all parameters are stored, just few.
  370. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrill" ),
  371. &m_Drill.x,
  372. Millimeter2iu( 0.6 ),
  373. Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
  374. NULL, MM_PER_IU ) );
  375. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrillOvalY" ),
  376. &m_Drill.y,
  377. Millimeter2iu( 0.6 ),
  378. Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
  379. NULL, MM_PER_IU ) );
  380. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeH" ),
  381. &m_Size.x,
  382. Millimeter2iu( 1.4 ),
  383. Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
  384. NULL, MM_PER_IU ) );
  385. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeV" ),
  386. &m_Size.y,
  387. Millimeter2iu( 1.4 ),
  388. Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
  389. NULL, MM_PER_IU ) );
  390. }
  391. // Returns the position of the pad.
  392. wxPoint D_PAD::ShapePos() const
  393. {
  394. if( m_Offset.x == 0 && m_Offset.y == 0 )
  395. return m_Pos;
  396. wxPoint loc_offset = m_Offset;
  397. RotatePoint( &loc_offset, m_Orient );
  398. wxPoint shape_pos = m_Pos + loc_offset;
  399. return shape_pos;
  400. }
  401. bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps )
  402. {
  403. bool skip = aSkipUnconnectable && ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED );
  404. if( !skip )
  405. SetName( GetParent()->GetNextPadName( aFillSequenceGaps ) );
  406. return !skip;
  407. }
  408. void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings )
  409. {
  410. // Don't do anything foolish like trying to copy to yourself.
  411. wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
  412. aPad->SetNetCode( GetNetCode() );
  413. if( aCopyLocalSettings )
  414. {
  415. aPad->SetLocalClearance( m_LocalClearance );
  416. aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin );
  417. aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin );
  418. aPad->SetLocalSolderPasteMarginRatio( m_LocalSolderPasteMarginRatio );
  419. aPad->SetZoneConnection( m_ZoneConnection );
  420. aPad->SetThermalWidth( m_ThermalWidth );
  421. aPad->SetThermalGap( m_ThermalGap );
  422. }
  423. }
  424. int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
  425. {
  426. // A pad can have specific clearance parameters that
  427. // overrides its NETCLASS clearance value
  428. int clearance = m_LocalClearance;
  429. if( clearance == 0 )
  430. {
  431. // If local clearance is 0, use the parent footprint clearance value
  432. if( GetParent() && GetParent()->GetLocalClearance() )
  433. clearance = GetParent()->GetLocalClearance();
  434. }
  435. if( clearance == 0 ) // If the parent footprint clearance value = 0, use NETCLASS value
  436. return BOARD_CONNECTED_ITEM::GetClearance( aItem );
  437. // We have a specific clearance.
  438. // if aItem, return the biggest clearance
  439. if( aItem )
  440. {
  441. int hisClearance = aItem->GetClearance();
  442. return std::max( hisClearance, clearance );
  443. }
  444. // Return the specific clearance.
  445. return clearance;
  446. }
  447. // Mask margins handling:
  448. int D_PAD::GetSolderMaskMargin() const
  449. {
  450. int margin = m_LocalSolderMaskMargin;
  451. MODULE* module = GetParent();
  452. if( module )
  453. {
  454. if( margin == 0 )
  455. {
  456. if( module->GetLocalSolderMaskMargin() )
  457. margin = module->GetLocalSolderMaskMargin();
  458. }
  459. if( margin == 0 )
  460. {
  461. BOARD* brd = GetBoard();
  462. margin = brd->GetDesignSettings().m_SolderMaskMargin;
  463. }
  464. }
  465. // ensure mask have a size always >= 0
  466. if( margin < 0 )
  467. {
  468. int minsize = -std::min( m_Size.x, m_Size.y ) / 2;
  469. if( margin < minsize )
  470. margin = minsize;
  471. }
  472. return margin;
  473. }
  474. wxSize D_PAD::GetSolderPasteMargin() const
  475. {
  476. int margin = m_LocalSolderPasteMargin;
  477. double mratio = m_LocalSolderPasteMarginRatio;
  478. MODULE* module = GetParent();
  479. if( module )
  480. {
  481. if( margin == 0 )
  482. margin = module->GetLocalSolderPasteMargin();
  483. BOARD * brd = GetBoard();
  484. if( margin == 0 )
  485. margin = brd->GetDesignSettings().m_SolderPasteMargin;
  486. if( mratio == 0.0 )
  487. mratio = module->GetLocalSolderPasteMarginRatio();
  488. if( mratio == 0.0 )
  489. {
  490. mratio = brd->GetDesignSettings().m_SolderPasteMarginRatio;
  491. }
  492. }
  493. wxSize pad_margin;
  494. pad_margin.x = margin + KiROUND( m_Size.x * mratio );
  495. pad_margin.y = margin + KiROUND( m_Size.y * mratio );
  496. // ensure mask have a size always >= 0
  497. if( pad_margin.x < -m_Size.x / 2 )
  498. pad_margin.x = -m_Size.x / 2;
  499. if( pad_margin.y < -m_Size.y / 2 )
  500. pad_margin.y = -m_Size.y / 2;
  501. return pad_margin;
  502. }
  503. ZoneConnection D_PAD::GetZoneConnection() const
  504. {
  505. MODULE* module = GetParent();
  506. if( m_ZoneConnection == PAD_ZONE_CONN_INHERITED && module )
  507. return module->GetZoneConnection();
  508. else
  509. return m_ZoneConnection;
  510. }
  511. int D_PAD::GetThermalWidth() const
  512. {
  513. MODULE* module = GetParent();
  514. if( m_ThermalWidth == 0 && module )
  515. return module->GetThermalWidth();
  516. else
  517. return m_ThermalWidth;
  518. }
  519. int D_PAD::GetThermalGap() const
  520. {
  521. MODULE* module = GetParent();
  522. if( m_ThermalGap == 0 && module )
  523. return module->GetThermalGap();
  524. else
  525. return m_ThermalGap;
  526. }
  527. void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
  528. {
  529. MODULE* module;
  530. wxString Line;
  531. BOARD* board;
  532. module = (MODULE*) m_Parent;
  533. if( module )
  534. {
  535. aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), module->GetReference(), DARKCYAN ) );
  536. aList.push_back( MSG_PANEL_ITEM( _( "Pad" ), m_name, BROWN ) );
  537. }
  538. aList.push_back( MSG_PANEL_ITEM( _( "Net" ), GetNetname(), DARKCYAN ) );
  539. board = GetBoard();
  540. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ),
  541. LayerMaskDescribe( board, m_layerMask ), DARKGREEN ) );
  542. aList.push_back( MSG_PANEL_ITEM( ShowPadShape(), ShowPadAttr(), DARKGREEN ) );
  543. Line = ::CoordinateToString( m_Size.x );
  544. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), Line, RED ) );
  545. Line = ::CoordinateToString( m_Size.y );
  546. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), Line, RED ) );
  547. Line = ::CoordinateToString( (unsigned) m_Drill.x );
  548. if( GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
  549. {
  550. aList.push_back( MSG_PANEL_ITEM( _( "Drill" ), Line, RED ) );
  551. }
  552. else
  553. {
  554. Line = ::CoordinateToString( (unsigned) m_Drill.x );
  555. wxString msg;
  556. msg = ::CoordinateToString( (unsigned) m_Drill.y );
  557. Line += wxT( "/" ) + msg;
  558. aList.push_back( MSG_PANEL_ITEM( _( "Drill X / Y" ), Line, RED ) );
  559. }
  560. double module_orient_degrees = module ? module->GetOrientationDegrees() : 0;
  561. if( module_orient_degrees != 0.0 )
  562. Line.Printf( wxT( "%3.1f(+%3.1f)" ),
  563. GetOrientationDegrees() - module_orient_degrees,
  564. module_orient_degrees );
  565. else
  566. Line.Printf( wxT( "%3.1f" ), GetOrientationDegrees() );
  567. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), Line, LIGHTBLUE ) );
  568. Line = ::CoordinateToString( m_Pos.x ) + wxT( ", " ) + ::CoordinateToString( m_Pos.y );
  569. aList.push_back( MSG_PANEL_ITEM( _( "Position" ), Line, LIGHTBLUE ) );
  570. if( GetPadToDieLength() )
  571. {
  572. Line = ::CoordinateToString( GetPadToDieLength() );
  573. aList.push_back( MSG_PANEL_ITEM( _( "Length in package" ), Line, CYAN ) );
  574. }
  575. }
  576. void D_PAD::GetOblongDrillGeometry( wxPoint& aStartPoint,
  577. wxPoint& aEndPoint, int& aWidth ) const
  578. {
  579. // calculates the start point, end point and width
  580. // of an equivalent segment which have the same position and width as the hole
  581. int delta_cx, delta_cy;
  582. wxSize halfsize = GetDrillSize();
  583. halfsize.x /= 2;
  584. halfsize.y /= 2;
  585. if( m_Drill.x > m_Drill.y ) // horizontal
  586. {
  587. delta_cx = halfsize.x - halfsize.y;
  588. delta_cy = 0;
  589. aWidth = m_Drill.y;
  590. }
  591. else // vertical
  592. {
  593. delta_cx = 0;
  594. delta_cy = halfsize.y - halfsize.x;
  595. aWidth = m_Drill.x;
  596. }
  597. RotatePoint( &delta_cx, &delta_cy, m_Orient );
  598. aStartPoint.x = delta_cx;
  599. aStartPoint.y = delta_cy;
  600. aEndPoint.x = - delta_cx;
  601. aEndPoint.y = - delta_cy;
  602. }
  603. bool D_PAD::HitTest( const wxPoint& aPosition ) const
  604. {
  605. int dx, dy;
  606. wxPoint shape_pos = ShapePos();
  607. wxPoint delta = aPosition - shape_pos;
  608. // first test: a test point must be inside a minimum sized bounding circle.
  609. int radius = GetBoundingRadius();
  610. if( ( abs( delta.x ) > radius ) || ( abs( delta.y ) > radius ) )
  611. return false;
  612. dx = m_Size.x >> 1; // dx also is the radius for rounded pads
  613. dy = m_Size.y >> 1;
  614. switch( GetShape() )
  615. {
  616. case PAD_SHAPE_CIRCLE:
  617. if( KiROUND( EuclideanNorm( delta ) ) <= dx )
  618. return true;
  619. break;
  620. case PAD_SHAPE_TRAPEZOID:
  621. {
  622. wxPoint poly[4];
  623. BuildPadPolygon( poly, wxSize(0,0), 0 );
  624. RotatePoint( &delta, -m_Orient );
  625. return TestPointInsidePolygon( poly, 4, delta );
  626. }
  627. case PAD_SHAPE_OVAL:
  628. {
  629. RotatePoint( &delta, -m_Orient );
  630. // An oval pad has the same shape as a segment with rounded ends
  631. // After rotation, the test point is relative to an horizontal pad
  632. int dist;
  633. wxPoint offset;
  634. if( dy > dx ) // shape is a vertical oval
  635. {
  636. offset.y = dy - dx;
  637. dist = dx;
  638. }
  639. else //if( dy <= dx ) shape is an horizontal oval
  640. {
  641. offset.x = dy - dx;
  642. dist = dy;
  643. }
  644. return TestSegmentHit( delta, - offset, offset, dist );
  645. }
  646. break;
  647. case PAD_SHAPE_RECT:
  648. RotatePoint( &delta, -m_Orient );
  649. if( (abs( delta.x ) <= dx ) && (abs( delta.y ) <= dy) )
  650. return true;
  651. break;
  652. case PAD_SHAPE_ROUNDRECT:
  653. {
  654. // Check for hit in polygon
  655. SHAPE_POLY_SET outline;
  656. const int segmentToCircleCount = 32;
  657. TransformRoundRectToPolygon( outline, wxPoint(0,0), GetSize(), m_Orient,
  658. GetRoundRectCornerRadius(), segmentToCircleCount );
  659. const SHAPE_LINE_CHAIN &poly = outline.COutline( 0 );
  660. return TestPointInsidePolygon( (const wxPoint*)&poly.CPoint(0), poly.PointCount(), delta );
  661. }
  662. break;
  663. case PAD_SHAPE_CUSTOM:
  664. // Check for hit in polygon
  665. RotatePoint( &delta, -m_Orient );
  666. if( m_customShapeAsPolygon.OutlineCount() )
  667. {
  668. const SHAPE_LINE_CHAIN& poly = m_customShapeAsPolygon.COutline( 0 );
  669. return TestPointInsidePolygon( (const wxPoint*)&poly.CPoint(0), poly.PointCount(), delta );
  670. }
  671. break;
  672. }
  673. return false;
  674. }
  675. bool D_PAD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  676. {
  677. EDA_RECT arect = aRect;
  678. arect.Normalize();
  679. arect.Inflate( aAccuracy );
  680. wxPoint shapePos = ShapePos();
  681. EDA_RECT shapeRect;
  682. int r;
  683. EDA_RECT bb = GetBoundingBox();
  684. wxPoint endCenter;
  685. int radius;
  686. if( !arect.Intersects( bb ) )
  687. return false;
  688. // This covers total containment for all test cases
  689. if( arect.Contains( bb ) )
  690. return true;
  691. switch( GetShape() )
  692. {
  693. case PAD_SHAPE_CIRCLE:
  694. return arect.IntersectsCircle( GetPosition(), GetBoundingRadius() );
  695. case PAD_SHAPE_RECT:
  696. shapeRect.SetOrigin( shapePos );
  697. shapeRect.Inflate( m_Size.x / 2, m_Size.y / 2 );
  698. return arect.Intersects( shapeRect, m_Orient );
  699. case PAD_SHAPE_OVAL:
  700. // Circlular test if dimensions are equal
  701. if( m_Size.x == m_Size.y )
  702. return arect.IntersectsCircle( shapePos, GetBoundingRadius() );
  703. shapeRect.SetOrigin( shapePos );
  704. // Horizontal dimension is greater
  705. if( m_Size.x > m_Size.y )
  706. {
  707. radius = m_Size.y / 2;
  708. shapeRect.Inflate( m_Size.x / 2 - radius, radius );
  709. endCenter = wxPoint( m_Size.x / 2 - radius, 0 );
  710. RotatePoint( &endCenter, m_Orient );
  711. // Test circular ends
  712. if( arect.IntersectsCircle( shapePos + endCenter, radius ) ||
  713. arect.IntersectsCircle( shapePos - endCenter, radius ) )
  714. {
  715. return true;
  716. }
  717. }
  718. else
  719. {
  720. radius = m_Size.x / 2;
  721. shapeRect.Inflate( radius, m_Size.y / 2 - radius );
  722. endCenter = wxPoint( 0, m_Size.y / 2 - radius );
  723. RotatePoint( &endCenter, m_Orient );
  724. // Test circular ends
  725. if( arect.IntersectsCircle( shapePos + endCenter, radius ) ||
  726. arect.IntersectsCircle( shapePos - endCenter, radius ) )
  727. {
  728. return true;
  729. }
  730. }
  731. // Test rectangular portion between rounded ends
  732. if( arect.Intersects( shapeRect, m_Orient ) )
  733. {
  734. return true;
  735. }
  736. break;
  737. case PAD_SHAPE_TRAPEZOID:
  738. /* Trapezoid intersection tests:
  739. * A) Any points of rect inside trapezoid
  740. * B) Any points of trapezoid inside rect
  741. * C) Any sides of trapezoid cross rect
  742. */
  743. {
  744. wxPoint poly[4];
  745. BuildPadPolygon( poly, wxSize( 0, 0 ), 0 );
  746. wxPoint corners[4];
  747. corners[0] = wxPoint( arect.GetLeft(), arect.GetTop() );
  748. corners[1] = wxPoint( arect.GetRight(), arect.GetTop() );
  749. corners[2] = wxPoint( arect.GetRight(), arect.GetBottom() );
  750. corners[3] = wxPoint( arect.GetLeft(), arect.GetBottom() );
  751. for( int i=0; i<4; i++ )
  752. {
  753. RotatePoint( &poly[i], m_Orient );
  754. poly[i] += shapePos;
  755. }
  756. for( int ii=0; ii<4; ii++ )
  757. {
  758. if( TestPointInsidePolygon( poly, 4, corners[ii] ) )
  759. {
  760. return true;
  761. }
  762. if( arect.Contains( poly[ii] ) )
  763. {
  764. return true;
  765. }
  766. if( arect.Intersects( poly[ii], poly[(ii+1) % 4] ) )
  767. {
  768. return true;
  769. }
  770. }
  771. return false;
  772. }
  773. case PAD_SHAPE_ROUNDRECT:
  774. /* RoundRect intersection can be broken up into simple tests:
  775. * a) Test intersection of horizontal rect
  776. * b) Test intersection of vertical rect
  777. * c) Test intersection of each corner
  778. */
  779. r = GetRoundRectCornerRadius();
  780. /* Test A - intersection of horizontal rect */
  781. shapeRect.SetSize( 0, 0 );
  782. shapeRect.SetOrigin( shapePos );
  783. shapeRect.Inflate( m_Size.x / 2, m_Size.y / 2 - r );
  784. // Short-circuit test for zero width or height
  785. if( shapeRect.GetWidth() > 0 && shapeRect.GetHeight() > 0 &&
  786. arect.Intersects( shapeRect, m_Orient ) )
  787. {
  788. return true;
  789. }
  790. /* Test B - intersection of vertical rect */
  791. shapeRect.SetSize( 0, 0 );
  792. shapeRect.SetOrigin( shapePos );
  793. shapeRect.Inflate( m_Size.x / 2 - r, m_Size.y / 2 );
  794. // Short-circuit test for zero width or height
  795. if( shapeRect.GetWidth() > 0 && shapeRect.GetHeight() > 0 &&
  796. arect.Intersects( shapeRect, m_Orient ) )
  797. {
  798. return true;
  799. }
  800. /* Test C - intersection of each corner */
  801. endCenter = wxPoint( m_Size.x / 2 - r, m_Size.y / 2 - r );
  802. RotatePoint( &endCenter, m_Orient );
  803. if( arect.IntersectsCircle( shapePos + endCenter, r ) ||
  804. arect.IntersectsCircle( shapePos - endCenter, r ) )
  805. {
  806. return true;
  807. }
  808. endCenter = wxPoint( m_Size.x / 2 - r, -m_Size.y / 2 + r );
  809. RotatePoint( &endCenter, m_Orient );
  810. if( arect.IntersectsCircle( shapePos + endCenter, r ) ||
  811. arect.IntersectsCircle( shapePos - endCenter, r ) )
  812. {
  813. return true;
  814. }
  815. break;
  816. default:
  817. break;
  818. }
  819. return false;
  820. }
  821. int D_PAD::Compare( const D_PAD* padref, const D_PAD* padcmp )
  822. {
  823. int diff;
  824. if( ( diff = padref->GetShape() - padcmp->GetShape() ) != 0 )
  825. return diff;
  826. if( ( diff = padref->GetDrillShape() - padcmp->GetDrillShape() ) != 0)
  827. return diff;
  828. if( ( diff = padref->m_Drill.x - padcmp->m_Drill.x ) != 0 )
  829. return diff;
  830. if( ( diff = padref->m_Drill.y - padcmp->m_Drill.y ) != 0 )
  831. return diff;
  832. if( ( diff = padref->m_Size.x - padcmp->m_Size.x ) != 0 )
  833. return diff;
  834. if( ( diff = padref->m_Size.y - padcmp->m_Size.y ) != 0 )
  835. return diff;
  836. if( ( diff = padref->m_Offset.x - padcmp->m_Offset.x ) != 0 )
  837. return diff;
  838. if( ( diff = padref->m_Offset.y - padcmp->m_Offset.y ) != 0 )
  839. return diff;
  840. if( ( diff = padref->m_DeltaSize.x - padcmp->m_DeltaSize.x ) != 0 )
  841. return diff;
  842. if( ( diff = padref->m_DeltaSize.y - padcmp->m_DeltaSize.y ) != 0 )
  843. return diff;
  844. // TODO: test custom shapes
  845. // Dick: specctra_export needs this
  846. // Lorenzo: gencad also needs it to implement padstacks!
  847. #if __cplusplus >= 201103L
  848. long long d = padref->m_layerMask.to_ullong() - padcmp->m_layerMask.to_ullong();
  849. if( d < 0 )
  850. return -1;
  851. else if( d > 0 )
  852. return 1;
  853. return 0;
  854. #else
  855. // these strings are not typically constructed, since we don't get here often.
  856. std::string s1 = padref->m_layerMask.to_string();
  857. std::string s2 = padcmp->m_layerMask.to_string();
  858. return s1.compare( s2 );
  859. #endif
  860. }
  861. void D_PAD::Rotate( const wxPoint& aRotCentre, double aAngle )
  862. {
  863. RotatePoint( &m_Pos, aRotCentre, aAngle );
  864. m_Orient = NormalizeAngle360Min( m_Orient + aAngle );
  865. SetLocalCoord();
  866. }
  867. wxString D_PAD::ShowPadShape() const
  868. {
  869. switch( GetShape() )
  870. {
  871. case PAD_SHAPE_CIRCLE:
  872. return _( "Circle" );
  873. case PAD_SHAPE_OVAL:
  874. return _( "Oval" );
  875. case PAD_SHAPE_RECT:
  876. return _( "Rect" );
  877. case PAD_SHAPE_TRAPEZOID:
  878. return _( "Trap" );
  879. case PAD_SHAPE_ROUNDRECT:
  880. return _( "Roundrect" );
  881. case PAD_SHAPE_CUSTOM:
  882. return _( "CustomShape" );
  883. default:
  884. return wxT( "???" );
  885. }
  886. }
  887. wxString D_PAD::ShowPadAttr() const
  888. {
  889. switch( GetAttribute() )
  890. {
  891. case PAD_ATTRIB_STANDARD:
  892. return _( "Std" );
  893. case PAD_ATTRIB_SMD:
  894. return _( "SMD" );
  895. case PAD_ATTRIB_CONN:
  896. return _( "Conn" );
  897. case PAD_ATTRIB_HOLE_NOT_PLATED:
  898. return _( "Not Plated" );
  899. default:
  900. return wxT( "???" );
  901. }
  902. }
  903. wxString D_PAD::GetSelectMenuText() const
  904. {
  905. wxString text;
  906. wxString padlayers( LayerMaskDescribe( GetBoard(), m_layerMask ) );
  907. wxString padname( GetName() );
  908. if( padname.IsEmpty() )
  909. {
  910. text.Printf( _( "Pad on %s of %s" ),
  911. GetChars( padlayers ),
  912. GetChars(GetParent()->GetReference() ) );
  913. }
  914. else
  915. {
  916. text.Printf( _( "Pad %s on %s of %s" ),
  917. GetChars(GetName() ), GetChars( padlayers ),
  918. GetChars(GetParent()->GetReference() ) );
  919. }
  920. return text;
  921. }
  922. BITMAP_DEF D_PAD::GetMenuImage() const
  923. {
  924. return pad_xpm;
  925. }
  926. EDA_ITEM* D_PAD::Clone() const
  927. {
  928. return new D_PAD( *this );
  929. }
  930. bool D_PAD::PadShouldBeNPTH() const
  931. {
  932. return( m_Attribute == PAD_ATTRIB_STANDARD
  933. && m_Drill.x >= m_Size.x && m_Drill.y >= m_Size.y );
  934. }
  935. void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const
  936. {
  937. aCount = 0;
  938. // These 2 types of pads contain a hole
  939. if( m_Attribute == PAD_ATTRIB_STANDARD )
  940. aLayers[aCount++] = LAYER_PADS_PLATEDHOLES;
  941. if( m_Attribute == PAD_ATTRIB_HOLE_NOT_PLATED )
  942. aLayers[aCount++] = LAYER_NON_PLATEDHOLES;
  943. if( IsOnLayer( F_Cu ) && IsOnLayer( B_Cu ) )
  944. {
  945. // Multi layer pad
  946. aLayers[aCount++] = LAYER_PADS_TH;
  947. aLayers[aCount++] = LAYER_PADS_NETNAMES;
  948. }
  949. else if( IsOnLayer( F_Cu ) )
  950. {
  951. aLayers[aCount++] = LAYER_PAD_FR;
  952. aLayers[aCount++] = LAYER_PAD_FR_NETNAMES;
  953. }
  954. else if( IsOnLayer( B_Cu ) )
  955. {
  956. aLayers[aCount++] = LAYER_PAD_BK;
  957. aLayers[aCount++] = LAYER_PAD_BK_NETNAMES;
  958. }
  959. // Check non-copper layers. This list should include all the layers that the
  960. // footprint editor allows a pad to be placed on.
  961. static const PCB_LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
  962. F_Adhes, B_Adhes, F_SilkS, B_SilkS, Dwgs_User, Eco1_User, Eco2_User };
  963. for( PCB_LAYER_ID each_layer : layers_mech )
  964. {
  965. if( IsOnLayer( each_layer ) )
  966. aLayers[aCount++] = each_layer;
  967. }
  968. #ifdef __WXDEBUG__
  969. if( aCount == 0 ) // Should not occur
  970. {
  971. wxString msg;
  972. msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
  973. GetParent() ? GetParent()->GetReference() : "<null>",
  974. GetName().IsEmpty() ? "(unnamed)" : GetName() );
  975. wxLogWarning( msg );
  976. }
  977. #endif
  978. }
  979. unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  980. {
  981. const int HIDE = std::numeric_limits<unsigned int>::max();
  982. BOARD* board = GetBoard();
  983. // Handle Render tab switches
  984. if( ( GetAttribute() == PAD_ATTRIB_STANDARD || GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
  985. && !aView->IsLayerVisible( LAYER_PADS_TH ) )
  986. return HIDE;
  987. if( !IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
  988. return HIDE;
  989. if( IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
  990. return HIDE;
  991. if( IsFrontLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_FR ) )
  992. return HIDE;
  993. if( IsBackLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_BK ) )
  994. return HIDE;
  995. // Only draw the pad if at least one of the layers it crosses is being displayed
  996. if( board && !( board->GetVisibleLayers() & GetLayerSet() ).any() )
  997. return HIDE;
  998. // Netnames will be shown only if zoom is appropriate
  999. if( IsNetnameLayer( aLayer ) )
  1000. {
  1001. int divisor = std::max( m_Size.x, m_Size.y );
  1002. // Pad sizes can be zero briefly when someone is typing a number like "0.5"
  1003. // in the pad properties dialog
  1004. if( divisor == 0 )
  1005. return HIDE;
  1006. return ( Millimeter2iu( 100 ) / divisor );
  1007. }
  1008. // Other layers are shown without any conditions
  1009. return 0;
  1010. }
  1011. const BOX2I D_PAD::ViewBBox() const
  1012. {
  1013. // Bounding box includes soldermask too
  1014. int solderMaskMargin = GetSolderMaskMargin();
  1015. VECTOR2I solderPasteMargin = VECTOR2D( GetSolderPasteMargin() );
  1016. EDA_RECT bbox = GetBoundingBox();
  1017. // Look for the biggest possible bounding box
  1018. int xMargin = std::max( solderMaskMargin, solderPasteMargin.x );
  1019. int yMargin = std::max( solderMaskMargin, solderPasteMargin.y );
  1020. return BOX2I( VECTOR2I( bbox.GetOrigin() ) - VECTOR2I( xMargin, yMargin ),
  1021. VECTOR2I( bbox.GetSize() ) + VECTOR2I( 2 * xMargin, 2 * yMargin ) );
  1022. }
  1023. wxString LayerMaskDescribe( const BOARD *aBoard, LSET aMask )
  1024. {
  1025. // Try the single or no- layer case (easy)
  1026. PCB_LAYER_ID layer = aMask.ExtractLayer();
  1027. switch( (int) layer )
  1028. {
  1029. case UNSELECTED_LAYER:
  1030. return _( "No layers" );
  1031. case UNDEFINED_LAYER:
  1032. break;
  1033. default:
  1034. return aBoard->GetLayerName( layer );
  1035. }
  1036. // Try to be smart and useful, starting with outer copper
  1037. // (which are more important than internal ones)
  1038. wxString layerInfo;
  1039. if( aMask[F_Cu] )
  1040. AccumulateDescription( layerInfo, aBoard->GetLayerName( F_Cu ) );
  1041. if( aMask[B_Cu] )
  1042. AccumulateDescription( layerInfo, aBoard->GetLayerName( B_Cu ) );
  1043. if( ( aMask & LSET::InternalCuMask() ).any() )
  1044. AccumulateDescription( layerInfo, _("Internal" ) );
  1045. if( ( aMask & LSET::AllNonCuMask() ).any() )
  1046. AccumulateDescription( layerInfo, _("Non-copper" ) );
  1047. return layerInfo;
  1048. }
  1049. void D_PAD::ImportSettingsFromMaster( const D_PAD& aMasterPad )
  1050. {
  1051. SetShape( aMasterPad.GetShape() );
  1052. SetLayerSet( aMasterPad.GetLayerSet() );
  1053. SetAttribute( aMasterPad.GetAttribute() );
  1054. // The pad orientation, for historical reasons is the
  1055. // pad rotation + parent rotation.
  1056. // So we have to manage this parent rotation
  1057. double pad_rot = aMasterPad.GetOrientation();
  1058. if( aMasterPad.GetParent() )
  1059. pad_rot -= aMasterPad.GetParent()->GetOrientation();
  1060. if( GetParent() )
  1061. pad_rot += GetParent()->GetOrientation();
  1062. SetOrientation( pad_rot );
  1063. SetSize( aMasterPad.GetSize() );
  1064. SetDelta( wxSize( 0, 0 ) );
  1065. SetOffset( aMasterPad.GetOffset() );
  1066. SetDrillSize( aMasterPad.GetDrillSize() );
  1067. SetDrillShape( aMasterPad.GetDrillShape() );
  1068. SetRoundRectRadiusRatio( aMasterPad.GetRoundRectRadiusRatio() );
  1069. switch( aMasterPad.GetShape() )
  1070. {
  1071. case PAD_SHAPE_TRAPEZOID:
  1072. SetDelta( aMasterPad.GetDelta() );
  1073. break;
  1074. case PAD_SHAPE_CIRCLE:
  1075. // ensure size.y == size.x
  1076. SetSize( wxSize( GetSize().x, GetSize().x ) );
  1077. break;
  1078. default:
  1079. ;
  1080. }
  1081. switch( aMasterPad.GetAttribute() )
  1082. {
  1083. case PAD_ATTRIB_SMD:
  1084. case PAD_ATTRIB_CONN:
  1085. // These pads do not have hole (they are expected to be only on one
  1086. // external copper layer)
  1087. SetDrillSize( wxSize( 0, 0 ) );
  1088. break;
  1089. default:
  1090. ;
  1091. }
  1092. // Add or remove custom pad shapes:
  1093. SetPrimitives( aMasterPad.GetPrimitives() );
  1094. SetAnchorPadShape( aMasterPad.GetAnchorPadShape() );
  1095. MergePrimitivesAsPolygon();
  1096. }
  1097. void D_PAD::SwapData( BOARD_ITEM* aImage )
  1098. {
  1099. assert( aImage->Type() == PCB_PAD_T );
  1100. std::swap( *((MODULE*) this), *((MODULE*) aImage) );
  1101. }