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.

209 lines
5.0 KiB

14 years ago
18 years ago
18 years ago
18 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
14 years ago
14 years ago
18 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
14 years ago
18 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
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
  1. /**
  2. * @file move-drag_pads.cpp
  3. * @brief Edit footprint pads.
  4. */
  5. #include <fctsys.h>
  6. #include <gr_basic.h>
  7. #include <common.h>
  8. #include <class_drawpanel.h>
  9. #include <trigo.h>
  10. #include <block_commande.h>
  11. #include <pcb_base_frame.h>
  12. #include <class_board.h>
  13. #include <class_module.h>
  14. #include <pcbnew.h>
  15. #include <drag.h>
  16. static D_PAD* s_CurrentSelectedPad;
  17. static wxPoint Pad_OldPos;
  18. /* Cancel move pad command.
  19. */
  20. static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
  21. {
  22. D_PAD* pad = s_CurrentSelectedPad;
  23. Panel->SetMouseCapture( NULL, NULL );
  24. if( pad == NULL )
  25. return;
  26. pad->Draw( Panel, DC, GR_XOR );
  27. pad->ClearFlags();
  28. pad->SetPosition( Pad_OldPos );
  29. pad->Draw( Panel, DC, GR_XOR );
  30. // Pad move in progress: restore origin of dragged tracks, if any.
  31. for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
  32. {
  33. TRACK* track = g_DragSegmentList[ii].m_Track;
  34. track->Draw( Panel, DC, GR_XOR );
  35. track->SetState( IN_EDIT, false );
  36. track->ClearFlags();
  37. g_DragSegmentList[ii].RestoreInitialValues();
  38. track->Draw( Panel, DC, GR_OR );
  39. }
  40. EraseDragList();
  41. s_CurrentSelectedPad = NULL;
  42. }
  43. /* Draw in drag mode when moving a pad.
  44. */
  45. static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  46. bool aErase )
  47. {
  48. TRACK* Track;
  49. D_PAD* pad = s_CurrentSelectedPad;
  50. if( pad == NULL ) // Should not occur
  51. return;
  52. if( aErase )
  53. pad->Draw( aPanel, aDC, GR_XOR );
  54. pad->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
  55. pad->Draw( aPanel, aDC, GR_XOR );
  56. for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
  57. {
  58. Track = g_DragSegmentList[ii].m_Track;
  59. if( aErase )
  60. Track->Draw( aPanel, aDC, GR_XOR );
  61. g_DragSegmentList[ii].SetTrackEndsCoordinates( wxPoint(0, 0) );
  62. Track->Draw( aPanel, aDC, GR_XOR );
  63. }
  64. }
  65. // Function to initialize the "move pad" command
  66. void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
  67. {
  68. if( aPad == NULL )
  69. return;
  70. s_CurrentSelectedPad = aPad;
  71. Pad_OldPos = aPad->GetPosition();
  72. SetMsgPanel( aPad );
  73. m_canvas->SetMouseCapture( Show_Pad_Move, Abort_Move_Pad );
  74. // Draw the pad, in SKETCH mode
  75. aPad->Draw( m_canvas, aDC, GR_XOR );
  76. aPad->SetFlags( IS_MOVED );
  77. aPad->Draw( m_canvas, aDC, GR_XOR );
  78. EraseDragList();
  79. // Build the list of track segments to drag if the command is a drag pad
  80. if( aDragConnectedTracks )
  81. {
  82. DRAG_LIST drglist( GetBoard() );
  83. drglist.BuildDragListe( aPad );
  84. UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
  85. }
  86. }
  87. // Routine to place a moved pad.
  88. void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
  89. {
  90. int dX, dY;
  91. TRACK* track;
  92. if( aPad == NULL )
  93. return;
  94. MODULE* module = aPad->GetParent();
  95. ITEM_PICKER picker( NULL, UR_CHANGED );
  96. PICKED_ITEMS_LIST pickList;
  97. // Save dragged track segments in undo list
  98. for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
  99. {
  100. track = g_DragSegmentList[ii].m_Track;
  101. // Set the old state
  102. if( g_DragSegmentList[ii].m_Pad_Start )
  103. track->SetStart( Pad_OldPos );
  104. if( g_DragSegmentList[ii].m_Pad_End )
  105. track->SetEnd( Pad_OldPos );
  106. picker.SetItem( track );
  107. pickList.PushItem( picker );
  108. }
  109. // Save old module and old items values
  110. aPad->ClearFlags();
  111. wxPoint pad_curr_position = aPad->GetPosition();
  112. aPad->SetPosition( Pad_OldPos );
  113. if( g_DragSegmentList.size() == 0 )
  114. SaveCopyInUndoList( module, UR_CHANGED );
  115. else
  116. {
  117. picker.SetItem( module );
  118. pickList.PushItem( picker );
  119. SaveCopyInUndoList( pickList, UR_CHANGED );
  120. }
  121. aPad->SetPosition( pad_curr_position );
  122. aPad->Draw( m_canvas, DC, GR_XOR );
  123. // Redraw dragged track segments
  124. for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
  125. {
  126. track = g_DragSegmentList[ii].m_Track;
  127. // Set the new state
  128. if( g_DragSegmentList[ii].m_Pad_Start )
  129. track->SetStart( aPad->GetPosition() );
  130. if( g_DragSegmentList[ii].m_Pad_End )
  131. track->SetEnd( aPad->GetPosition() );
  132. if( DC )
  133. track->Draw( m_canvas, DC, GR_XOR );
  134. track->SetState( IN_EDIT, false );
  135. track->ClearFlags();
  136. if( DC )
  137. track->Draw( m_canvas, DC, GR_OR );
  138. }
  139. // Compute local coordinates (i.e refer to module position and for module orient = 0)
  140. dX = aPad->GetPosition().x - Pad_OldPos.x;
  141. dY = aPad->GetPosition().y - Pad_OldPos.y;
  142. RotatePoint( &dX, &dY, -module->GetOrientation() );
  143. aPad->SetX0( dX + aPad->GetPos0().x );
  144. aPad->SetY0( dY + aPad->GetPos0().y );
  145. if( DC )
  146. aPad->Draw( m_canvas, DC, GR_OR );
  147. module->CalculateBoundingBox();
  148. module->SetLastEditTime();
  149. EraseDragList();
  150. OnModify();
  151. m_canvas->SetMouseCapture( NULL, NULL );
  152. }