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.

222 lines
6.4 KiB

18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2010 <Jean-Pierre Charras>
  5. * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file gerbview/block.cpp
  26. * @brief Block operations: displacement.
  27. */
  28. #include <fctsys.h>
  29. #include <common.h>
  30. #include <class_drawpanel.h>
  31. #include <gerbview_frame.h>
  32. #include <class_gerber_draw_item.h>
  33. #include <class_gerber_file_image.h>
  34. #include <class_gerber_file_image_list.h>
  35. // Call back function used in block command
  36. static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  37. const wxPoint& aPosition, bool erase );
  38. int GERBVIEW_FRAME::BlockCommand( EDA_KEY key )
  39. {
  40. int cmd = 0;
  41. switch( key )
  42. {
  43. default:
  44. cmd = key & 0x255;
  45. break;
  46. case 0:
  47. cmd = BLOCK_MOVE;
  48. break;
  49. case GR_KB_SHIFT:
  50. case GR_KB_CTRL:
  51. case GR_KB_SHIFTCTRL:
  52. case GR_KB_ALT:
  53. break;
  54. case MOUSE_MIDDLE:
  55. cmd = BLOCK_ZOOM;
  56. break;
  57. }
  58. return cmd;
  59. }
  60. void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC )
  61. {
  62. wxASSERT( m_canvas->IsMouseCaptured() );
  63. GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP );
  64. switch( GetScreen()->m_BlockLocate.GetCommand() )
  65. {
  66. case BLOCK_MOVE: /* Move */
  67. if( m_canvas->IsMouseCaptured() )
  68. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  69. Block_Move();
  70. GetScreen()->m_BlockLocate.ClearItemsList();
  71. break;
  72. default:
  73. wxFAIL_MSG( wxT("HandleBlockPlace: Unexpected block command") );
  74. break;
  75. }
  76. m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
  77. GetScreen()->SetModify();
  78. GetScreen()->ClearBlockCommand();
  79. wxASSERT( GetScreen()->m_BlockLocate.GetCount() == 0 );
  80. DisplayToolMsg( wxEmptyString );
  81. }
  82. bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC )
  83. {
  84. bool nextcmd = false;
  85. bool zoom_command = false;
  86. if( m_canvas->IsMouseCaptured() )
  87. switch( GetScreen()->m_BlockLocate.GetCommand() )
  88. {
  89. case BLOCK_MOVE: /* Move */
  90. GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_MOVE );
  91. nextcmd = true;
  92. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  93. m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines );
  94. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  95. break;
  96. case BLOCK_ZOOM: /* Window Zoom */
  97. zoom_command = true;
  98. break;
  99. default:
  100. wxFAIL_MSG( wxT("HandleBlockEnd: Unexpected block command") );
  101. break;
  102. }
  103. if( ! nextcmd )
  104. {
  105. GetScreen()->ClearBlockCommand();
  106. m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString,
  107. false );
  108. }
  109. if( zoom_command )
  110. Window_Zoom( GetScreen()->m_BlockLocate );
  111. return nextcmd ;
  112. }
  113. /* Traces the outline of the block structures of a repositioning move
  114. */
  115. static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon,
  116. bool aErase )
  117. {
  118. BASE_SCREEN* screen = aPanel->GetScreen();
  119. COLOR4D Color = COLOR4D( YELLOW );
  120. if( aErase )
  121. {
  122. screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
  123. if( screen->m_BlockLocate.GetMoveVector().x|| screen->m_BlockLocate.GetMoveVector().y )
  124. {
  125. screen->m_BlockLocate.Draw( aPanel,
  126. aDC,
  127. screen->m_BlockLocate.GetMoveVector(),
  128. g_XorMode,
  129. Color );
  130. }
  131. }
  132. if( screen->m_BlockLocate.GetState() != STATE_BLOCK_STOP )
  133. {
  134. const wxPoint& cross_hair = aPanel->GetParent()->GetCrossHairPosition();
  135. screen->m_BlockLocate.SetMoveVector(
  136. wxPoint( cross_hair.x - screen->m_BlockLocate.GetRight(),
  137. cross_hair.y - screen->m_BlockLocate.GetBottom() ) );
  138. }
  139. screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
  140. if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y )
  141. {
  142. screen->m_BlockLocate.Draw( aPanel, aDC,
  143. screen->m_BlockLocate.GetMoveVector(),
  144. g_XorMode, Color );
  145. }
  146. }
  147. void GERBVIEW_FRAME::Block_Move()
  148. {
  149. wxPoint delta;
  150. wxPoint oldpos;
  151. oldpos = GetCrossHairPosition();
  152. m_canvas->SetMouseCaptureCallback( NULL );
  153. SetCrossHairPosition( oldpos );
  154. m_canvas->MoveCursorToCrossHair();
  155. GetScreen()->SetModify();
  156. GetScreen()->m_BlockLocate.Normalize();
  157. /* Calculate displacement vectors. */
  158. delta = GetScreen()->m_BlockLocate.GetMoveVector();
  159. GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
  160. for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
  161. {
  162. GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
  163. if( gerber == NULL ) // Graphic layer not yet used
  164. continue;
  165. /* Move items in block */
  166. for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
  167. {
  168. GERBER_DRAW_ITEM* gerb_item = item;
  169. if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
  170. gerb_item->MoveAB( delta );
  171. }
  172. }
  173. m_canvas->Refresh( true );
  174. }