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.

205 lines
6.8 KiB

  1. /**
  2. * @file drag.h
  3. * @brief Useful classes and functions used to collect tracks to drag
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 2004-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  9. * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #ifndef _DRAG_H_
  29. #define _DRAG_H_
  30. #include <class_track.h>
  31. #include <vector>
  32. class wxDC;
  33. class wxPoint;
  34. class EDA_DRAW_PANEL;
  35. class MODULE;
  36. class D_PAD;
  37. class CONNECTIONS;
  38. /** Helper classes to handle a list of track segments to drag
  39. * and has info to undo/abort the move command
  40. */
  41. /*
  42. * a DRAG_LIST manages the list of track segments to modify
  43. * when the pad or the module is moving in drag mode
  44. */
  45. /**
  46. * a DRAG_SEGM_PICKER manage one track segment or a via
  47. */
  48. class DRAG_SEGM_PICKER
  49. {
  50. public:
  51. TRACK* m_Track; // pointer to the parent track segment
  52. D_PAD* m_Pad_Start; // pointer to the moving pad
  53. // if the start point should follow this pad
  54. // or NULL
  55. D_PAD* m_Pad_End; // pointer to the moving pad
  56. // if the end point should follow this pad
  57. // or NULL
  58. int m_TempFlags; // flag used in drag vias and drag track segment functions
  59. private:
  60. double m_RotationOffset; // initial orientation of the parent module
  61. // Used to recalculate m_PadStartOffset and m_PadEndOffset
  62. // after a module rotation when dragging
  63. bool m_Flipped; // initial side of the parent module
  64. // Used to recalculate m_PadStartOffset and m_PadEndOffset
  65. // if the module is flipped when dragging
  66. wxPoint m_PadStartOffset; // offset between the pad and the starting point of the track
  67. // usually 0,0, but not always
  68. wxPoint m_PadEndOffset; // offset between the pad and the ending point of the track
  69. // usually 0,0, but not always
  70. wxPoint m_startInitialValue;
  71. wxPoint m_endInitialValue; // For abort command:
  72. // initial m_Start and m_End values for m_Track
  73. public:
  74. DRAG_SEGM_PICKER( TRACK* aTrack );
  75. ~DRAG_SEGM_PICKER() {};
  76. /**
  77. * Set auxiliary parameters relative to calculations needed
  78. * to find track ends positions while dragging pads
  79. * and when modules are rotated, flipped
  80. */
  81. void SetAuxParameters();
  82. /**
  83. * Calculate track ends position while dragging pads
  84. * and when modules are rotated, flipped
  85. * @param aOffset = offset of module or pad position (when moving)
  86. */
  87. void SetTrackEndsCoordinates( wxPoint aOffset );
  88. void RestoreInitialValues()
  89. {
  90. m_Track->SetStart( m_startInitialValue );
  91. m_Track->SetEnd( m_endInitialValue );
  92. }
  93. };
  94. class DRAG_LIST
  95. {
  96. public:
  97. BOARD* m_Brd; // the main board
  98. MODULE* m_Module; // The link to the module to move, or NULL
  99. D_PAD* m_Pad; // The link to the pad to move, or NULL
  100. std::vector<DRAG_SEGM_PICKER> m_DragList; // The list of DRAG_SEGM_PICKER items
  101. public:
  102. DRAG_LIST( BOARD* aPcb )
  103. {
  104. m_Brd = aPcb;
  105. m_Module = NULL;
  106. m_Pad = NULL;
  107. }
  108. /**
  109. * Function ClearList
  110. * clear the .m_Flags of all track segments in m_DragList
  111. * and clear the list.
  112. */
  113. void ClearList();
  114. /** Build the list of track segments connected to pads of aModule
  115. * in m_DragList
  116. * For each selected track segment the EDIT flag is set
  117. */
  118. void BuildDragListe( MODULE* aModule );
  119. /** Build the list of track segments connected to aPad
  120. * in m_DragList
  121. * For each selected track segment the EDIT flag is set
  122. */
  123. void BuildDragListe( D_PAD* aPad );
  124. private:
  125. /** Fills m_DragList with of track segments connected to pads in aConnections
  126. * For each selected track segment the EDIT flag is set
  127. */
  128. void fillList( CONNECTIONS& aConnections );
  129. };
  130. // Global variables:
  131. // a list of DRAG_SEGM_PICKER items used to move or drag tracks.
  132. // Each DRAG_SEGM_PICKER item points a segment to move.
  133. extern std::vector<DRAG_SEGM_PICKER> g_DragSegmentList;
  134. // Functions:
  135. void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC );
  136. /**
  137. * Function EraseDragList
  138. * clear the .m_Flags of all track segments stored in g_DragSegmentList
  139. * and clear the list.
  140. * In order to avoid useless memory reallocation, the memory is not freed
  141. * and will be reused when creating a new list
  142. */
  143. void EraseDragList();
  144. /**
  145. * Function Collect_TrackSegmentsToDrag.
  146. * used to collect track segments in drag track segment
  147. * Build the list of tracks connected to the ref point by calling
  148. * AddSegmentToDragList for each selected track
  149. * Net codes must be up to date, because only tracks having the right net code are tested.
  150. *
  151. * @param aPcb A point the the #BOARD object to collect track segment to drag.
  152. * @param aRefPos = reference point of connection
  153. * @param aLayerMask = layers mask to collect tracks
  154. * @param aNetCode = the net code to consider
  155. * @param aMaxDist = max distance from aRefPos to a track end candidate to collect the track
  156. */
  157. void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LSET aLayerMask,
  158. int aNetCode, int aMaxDist );
  159. /* Add aTrack to the drag list
  160. * flag = STARTPOINT (if the point to drag is the start point of Track)
  161. * or ENDPOINT (if the point to drag is the end point of Track)
  162. */
  163. void AddSegmentToDragList( int flag, TRACK* aTrack );
  164. /*
  165. * Undraw the track segments in list, and set the EDIT flag
  166. * Usually called after the track list is built, to prepare
  167. * the redraw of the list when the mouse is moved
  168. */
  169. void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
  170. #endif // _DRAG_H_