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.

218 lines
6.0 KiB

15 years ago
  1. /***************************************/
  2. /* edit.cpp: Gerbview events functions */
  3. /***************************************/
  4. #include "fctsys.h"
  5. #include "class_drawpanel.h"
  6. #include "confirm.h"
  7. #include "common.h"
  8. #include "gestfich.h"
  9. #include "appl_wxstruct.h"
  10. #include "gerbview.h"
  11. #include "pcbplot.h"
  12. #include "kicad_device_context.h"
  13. #include "gerbview_id.h"
  14. #include "class_GERBER.h"
  15. #include "dialog_helpers.h"
  16. #include "class_DCodeSelectionbox.h"
  17. /* Process the command triggered by the left button of the mouse when a tool
  18. * is already selected.
  19. */
  20. void WinEDA_GerberFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  21. {
  22. BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem();
  23. wxString msg;
  24. if( m_ID_current_state == 0 )
  25. {
  26. if( DrawStruct && DrawStruct->m_Flags )
  27. {
  28. msg.Printf( wxT( "WinEDA_GerberFrame::ProcessCommand err: Struct %d, m_Flags = %X" ),
  29. (unsigned) DrawStruct->Type(),
  30. (unsigned) DrawStruct->m_Flags );
  31. DisplayError( this, msg );
  32. }
  33. else
  34. {
  35. DrawStruct = GerberGeneralLocateAndDisplay();
  36. GetScreen()->SetCurItem( DrawStruct );
  37. if( DrawStruct == NULL )
  38. {
  39. GERBER_IMAGE* gerber = g_GERBER_List[getActiveLayer() ];
  40. if( gerber )
  41. gerber->DisplayImageInfo( );
  42. }
  43. }
  44. }
  45. switch( m_ID_current_state )
  46. {
  47. case 0:
  48. break;
  49. case ID_NO_SELECT_BUTT:
  50. break;
  51. case ID_GERBVIEW_DELETE_ITEM_BUTT:
  52. DrawStruct = GerberGeneralLocateAndDisplay();
  53. if( DrawStruct == NULL )
  54. break;
  55. /* TODO:
  56. Delete_Item( DC, (GERBER_DRAW_ITEM*) DrawStruct );
  57. GetScreen()->SetCurItem( NULL );
  58. GetScreen()->SetModify();
  59. */
  60. break;
  61. default:
  62. DisplayError( this, wxT( "WinEDA_GerberFrame::ProcessCommand error" ) );
  63. break;
  64. }
  65. }
  66. /* Handles the selection of tools, menu, and popup menu commands.
  67. */
  68. void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
  69. {
  70. int id = event.GetId();
  71. int layer = GetScreen()->m_Active_Layer;
  72. GERBER_IMAGE* gerber_layer = g_GERBER_List[layer];
  73. wxPoint pos;
  74. wxGetMousePosition( &pos.x, &pos.y );
  75. pos.y += 20;
  76. switch( id )
  77. {
  78. case wxID_CUT:
  79. case wxID_COPY:
  80. case ID_POPUP_DELETE_BLOCK:
  81. case ID_POPUP_PLACE_BLOCK:
  82. case ID_POPUP_ZOOM_BLOCK:
  83. break;
  84. case ID_POPUP_CANCEL_CURRENT_COMMAND:
  85. DrawPanel->UnManageCursor( );
  86. /* Should not be executed, except bug */
  87. if( GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE )
  88. {
  89. GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
  90. GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
  91. GetScreen()->m_BlockLocate.ClearItemsList();
  92. }
  93. if( m_ID_current_state == 0 )
  94. SetToolID( 0, 0, wxEmptyString );
  95. else
  96. DrawPanel->SetCursor( DrawPanel->m_PanelCursor = DrawPanel->m_PanelDefaultCursor );
  97. break;
  98. default:
  99. DrawPanel->UnManageCursor( 0, 0, wxEmptyString );
  100. break;
  101. }
  102. INSTALL_DC( dc, DrawPanel );
  103. switch( id )
  104. {
  105. case ID_EXIT:
  106. Close( TRUE );
  107. break;
  108. case ID_GERBVIEW_GLOBAL_DELETE:
  109. Erase_Current_Layer( TRUE );
  110. ClearMsgPanel();
  111. break;
  112. case ID_NO_SELECT_BUTT:
  113. SetToolID( 0, 0, wxEmptyString );
  114. break;
  115. case ID_POPUP_CLOSE_CURRENT_TOOL:
  116. SetToolID( 0, 0, wxEmptyString );
  117. break;
  118. case ID_POPUP_CANCEL_CURRENT_COMMAND:
  119. break;
  120. case ID_GERBVIEW_DELETE_ITEM_BUTT:
  121. SetToolID( id, wxCURSOR_BULLSEYE, wxT( "Delete item" ) );
  122. break;
  123. case ID_TOOLBARH_GERBVIEW_SELECT_LAYER:
  124. setActiveLayer(m_SelLayerBox->GetChoice());
  125. DrawPanel->Refresh();
  126. break;
  127. case ID_TOOLBARH_GERBER_SELECT_TOOL:
  128. if( gerber_layer )
  129. {
  130. int tool = m_DCodeSelector->GetSelectedDCodeId();
  131. if( tool != gerber_layer->m_Selected_Tool )
  132. {
  133. gerber_layer->m_Selected_Tool = tool;
  134. DrawPanel->Refresh();
  135. }
  136. }
  137. break;
  138. case ID_GERBVIEW_SHOW_LIST_DCODES:
  139. Liste_D_Codes( );
  140. break;
  141. case ID_GERBVIEW_SHOW_SOURCE:
  142. if( gerber_layer )
  143. {
  144. wxString editorname = wxGetApp().GetEditorName();
  145. if( !editorname.IsEmpty() )
  146. {
  147. wxFileName fn( gerber_layer->m_FileName );
  148. ExecuteFile( this, editorname, QuoteFullPath( fn ) );
  149. }
  150. }
  151. break;
  152. case ID_POPUP_PLACE_BLOCK:
  153. GetScreen()->m_BlockLocate.m_Command = BLOCK_MOVE;
  154. DrawPanel->m_AutoPAN_Request = FALSE;
  155. HandleBlockPlace( &dc );
  156. break;
  157. case ID_POPUP_ZOOM_BLOCK:
  158. GetScreen()->m_BlockLocate.m_Command = BLOCK_ZOOM;
  159. GetScreen()->m_BlockLocate.SetMessageBlock( this );
  160. GetScreen()->m_BlockLocate.SetMessageBlock( this );
  161. HandleBlockEnd( &dc );
  162. break;
  163. case ID_POPUP_DELETE_BLOCK:
  164. GetScreen()->m_BlockLocate.m_Command = BLOCK_DELETE;
  165. GetScreen()->m_BlockLocate.SetMessageBlock( this );
  166. HandleBlockEnd( &dc );
  167. break;
  168. case ID_GERBVIEW_POPUP_DELETE_DCODE_ITEMS:
  169. if( gerber_layer )
  170. Delete_DCode_Items( &dc, gerber_layer->m_Selected_Tool,
  171. ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer );
  172. break;
  173. default:
  174. wxMessageBox( wxT( "WinEDA_GerberFrame::Process_Special_Functions error" ) );
  175. break;
  176. }
  177. SetToolbars();
  178. }
  179. /* Called on a double click of left mouse button.
  180. */
  181. void WinEDA_GerberFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
  182. {
  183. // Currently: no nothing
  184. }