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.

454 lines
15 KiB

17 years ago
16 years ago
16 years ago
16 years ago
  1. /************************/
  2. /* modedit_onclick.cpp */
  3. /************************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "class_drawpanel.h"
  7. #include "confirm.h"
  8. #include "3d_viewer.h"
  9. #include "pcbnew.h"
  10. #include "wxPcbStruct.h"
  11. #include "module_editor_frame.h"
  12. #include "dialog_edit_module_for_Modedit.h"
  13. #include "bitmaps.h"
  14. #include "protos.h"
  15. #include "pcbnew_id.h"
  16. #include "hotkeys.h"
  17. /* Handle the left click in footprint editor
  18. */
  19. void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  20. {
  21. BOARD_ITEM* item = GetCurItem();
  22. DrawPanel->CrossHairOff( DC );
  23. if( GetToolId() == ID_NO_TOOL_SELECTED )
  24. {
  25. if( item && item->m_Flags ) // Move item command in progress
  26. {
  27. switch( item->Type() )
  28. {
  29. case TYPE_TEXTE_MODULE:
  30. PlaceTexteModule( (TEXTE_MODULE*) item, DC );
  31. break;
  32. case TYPE_EDGE_MODULE:
  33. SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
  34. Place_EdgeMod( (EDGE_MODULE*) item );
  35. break;
  36. case TYPE_PAD:
  37. PlacePad( (D_PAD*) item, DC );
  38. break;
  39. default:
  40. {
  41. wxString msg;
  42. msg.Printf( wxT( "WinEDA_ModEditFrame::OnLeftClick err:Struct %d, m_Flag %X" ),
  43. item->Type(), item->m_Flags );
  44. DisplayError( this, msg );
  45. item->m_Flags = 0;
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. item = GetCurItem();
  52. if( !item || (item->m_Flags == 0) )
  53. {
  54. if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
  55. && !wxGetKeyState( WXK_CONTROL ) )
  56. item = ModeditLocateAndDisplay();
  57. SetCurItem( item );
  58. }
  59. switch( GetToolId() )
  60. {
  61. case ID_NO_TOOL_SELECTED:
  62. break;
  63. case ID_MODEDIT_CIRCLE_TOOL:
  64. case ID_MODEDIT_ARC_TOOL:
  65. case ID_MODEDIT_LINE_TOOL:
  66. if( !item || item->m_Flags == 0 )
  67. {
  68. int shape = S_SEGMENT;
  69. if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL )
  70. shape = S_CIRCLE;
  71. if( GetToolId() == ID_MODEDIT_ARC_TOOL )
  72. shape = S_ARC;
  73. SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) );
  74. }
  75. else if( item->IsNew() )
  76. {
  77. if( ( (EDGE_MODULE*) item )->m_Shape == S_CIRCLE )
  78. {
  79. End_Edge_Module( (EDGE_MODULE*) item );
  80. SetCurItem( NULL );
  81. DrawPanel->Refresh();
  82. }
  83. else if( ( (EDGE_MODULE*) item )->m_Shape == S_ARC )
  84. {
  85. End_Edge_Module( (EDGE_MODULE*) item );
  86. SetCurItem( NULL );
  87. DrawPanel->Refresh();
  88. }
  89. else if( ( (EDGE_MODULE*) item )->m_Shape == S_SEGMENT )
  90. {
  91. SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, 0 ) );
  92. }
  93. else
  94. DisplayError( this, wxT( "ProcessCommand error: item flags error" ) );
  95. }
  96. break;
  97. case ID_MODEDIT_DELETE_TOOL:
  98. if( item == NULL || // No item to delete
  99. (item->m_Flags != 0) ) // Item in edit, cannot delete it
  100. break;
  101. if( item->Type() != TYPE_MODULE ) // Cannot delete the module itself
  102. {
  103. SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
  104. RemoveStruct( item );
  105. SetCurItem( NULL );
  106. }
  107. break;
  108. case ID_MODEDIT_ANCHOR_TOOL:
  109. {
  110. MODULE* module = GetBoard()->m_Modules;
  111. if( module == NULL // No module loaded
  112. || (module->m_Flags != 0) )
  113. break;
  114. module->m_Flags = 0;
  115. SaveCopyInUndoList( module, UR_MODEDIT );
  116. Place_Ancre( module ); // set the new relatives internal coordinates of items
  117. RedrawScreen( wxPoint( 0, 0 ), true );
  118. // Replace the module in position 0, to recalculate absolutes coordinates of items
  119. module->SetPosition( wxPoint( 0, 0 ) );
  120. SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
  121. SetCurItem( NULL );
  122. DrawPanel->Refresh();
  123. }
  124. break;
  125. case ID_MODEDIT_PLACE_GRID_COORD:
  126. DrawPanel->DrawGridAxis( DC, GR_XOR );
  127. GetScreen()->m_GridOrigin = GetScreen()->GetCrossHairPosition();
  128. DrawPanel->DrawGridAxis( DC, GR_COPY );
  129. GetScreen()->SetModify();
  130. break;
  131. case ID_MODEDIT_TEXT_TOOL:
  132. if( GetBoard()->m_Modules == NULL )
  133. break;
  134. SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
  135. CreateTextModule( GetBoard()->m_Modules, DC );
  136. break;
  137. case ID_MODEDIT_PAD_TOOL:
  138. if( GetBoard()->m_Modules )
  139. {
  140. SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
  141. AddPad( GetBoard()->m_Modules, true );
  142. }
  143. break;
  144. default:
  145. DisplayError( this, wxT( "WinEDA_ModuleEditFrame::ProcessCommand error" ) );
  146. SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
  147. }
  148. DrawPanel->CrossHairOn( DC );
  149. }
  150. /* Handle the right click in the footprint editor:
  151. * Create the pull up menu
  152. * After this menu is built, the standard ZOOM menu is added
  153. */
  154. bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  155. {
  156. BOARD_ITEM* item = GetCurItem();
  157. wxString msg;
  158. bool append_set_width = FALSE;
  159. bool blockActive = GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE;
  160. // Simple location of elements where possible.
  161. if( ( item == NULL ) || ( item->m_Flags == 0 ) )
  162. {
  163. SetCurItem( item = ModeditLocateAndDisplay() );
  164. }
  165. // End command in progress.
  166. if( GetToolId() != ID_NO_TOOL_SELECTED )
  167. {
  168. if( item && item->m_Flags )
  169. ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
  170. else
  171. ADD_MENUITEM( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ), cancel_tool_xpm );
  172. PopMenu->AppendSeparator();
  173. }
  174. else
  175. {
  176. if( (item && item->m_Flags) || blockActive )
  177. {
  178. if( blockActive ) // Put block commands in list
  179. {
  180. ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
  181. _( "Cancel Block" ), cancel_xpm );
  182. ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK,
  183. _( "Zoom Block (drag middle mouse)" ),
  184. zoom_selected_xpm );
  185. PopMenu->AppendSeparator();
  186. ADD_MENUITEM( PopMenu, ID_POPUP_PLACE_BLOCK,
  187. _( "Place Block" ), apply_xpm );
  188. ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK,
  189. _( "Copy Block (shift + drag mouse)" ),
  190. copyblock_xpm );
  191. ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_X_BLOCK,
  192. _( "Mirror Block (alt + drag mouse)" ),
  193. mirror_H_xpm );
  194. ADD_MENUITEM( PopMenu, ID_POPUP_ROTATE_BLOCK,
  195. _( "Rotate Block (ctrl + drag mouse)" ),
  196. rotate_pos_xpm );
  197. ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK,
  198. _( "Delete Block (shift+ctrl + drag mouse)" ),
  199. delete_xpm );
  200. }
  201. else
  202. {
  203. ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
  204. _( "Cancel" ), cancel_xpm );
  205. }
  206. PopMenu->AppendSeparator();
  207. }
  208. }
  209. if( (item == NULL) || blockActive )
  210. return true;
  211. int flags = item->m_Flags;
  212. switch( item->Type() )
  213. {
  214. case TYPE_MODULE:
  215. {
  216. wxMenu* transform_choice = new wxMenu;
  217. ADD_MENUITEM( transform_choice, ID_MODEDIT_MODULE_ROTATE, _( "Rotate" ),
  218. rotate_module_pos_xpm );
  219. ADD_MENUITEM( transform_choice, ID_MODEDIT_MODULE_MIRROR, _( "Mirror" ), mirror_H_xpm );
  220. msg = AddHotkeyName( _( "Edit Module" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
  221. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_MODULE, msg, edit_module_xpm );
  222. ADD_MENUITEM_WITH_SUBMENU( PopMenu, transform_choice, ID_MODEDIT_TRANSFORM_MODULE,
  223. _( "Transform Module" ), edit_xpm );
  224. break;
  225. }
  226. case TYPE_PAD:
  227. if( !flags )
  228. {
  229. msg = AddHotkeyName( _("Move Pad" ), g_Module_Editor_Hokeys_Descr, HK_MOVE_ITEM );
  230. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_PAD_REQUEST, msg, move_pad_xpm );
  231. }
  232. msg = AddHotkeyName( _("Edit Pad" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
  233. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_PAD, msg, options_pad_xpm );
  234. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_IMPORT_PAD_SETTINGS,
  235. _( "New Pad Settings" ), options_new_pad_xpm );
  236. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EXPORT_PAD_SETTINGS,
  237. _( "Export Pad Settings" ), export_options_pad_xpm );
  238. msg = AddHotkeyName( _("Delete Pad" ), g_Module_Editor_Hokeys_Descr, HK_DELETE );
  239. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_PAD, msg, delete_pad_xpm );
  240. if( !flags )
  241. {
  242. PopMenu->AppendSeparator();
  243. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS,
  244. _( "Global Pad Settings" ), global_options_pad_xpm );
  245. }
  246. break;
  247. case TYPE_TEXTE_MODULE:
  248. if( !flags )
  249. {
  250. msg = AddHotkeyName( _("Move Text Mod." ), g_Module_Editor_Hokeys_Descr,
  251. HK_MOVE_ITEM );
  252. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST, msg, move_field_xpm );
  253. }
  254. msg = AddHotkeyName( _("Rotate Text Mod." ), g_Module_Editor_Hokeys_Descr,
  255. HK_ROTATE_ITEM );
  256. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ROTATE_TEXTMODULE, msg, rotate_field_xpm );
  257. if( !flags )
  258. {
  259. msg = AddHotkeyName( _("Edit Text Mod." ), g_Module_Editor_Hokeys_Descr,
  260. HK_EDIT_ITEM );
  261. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_TEXTMODULE, msg, edit_text_xpm );
  262. if( ( (TEXTE_MODULE*) item )->m_Type == TEXT_is_DIVERS )
  263. {
  264. msg = AddHotkeyName( _("Delete Text Mod." ), g_Module_Editor_Hokeys_Descr,
  265. HK_DELETE );
  266. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE, msg, delete_text_xpm );
  267. }
  268. }
  269. break;
  270. case TYPE_EDGE_MODULE:
  271. {
  272. if( (flags & IS_NEW) )
  273. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_STOP_CURRENT_DRAWING, _( "End edge" ), apply_xpm );
  274. if( !flags )
  275. {
  276. msg = AddHotkeyName( _("Move edge" ), g_Module_Editor_Hokeys_Descr, HK_MOVE_ITEM );
  277. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_EDGE, msg, move_line_xpm );
  278. }
  279. if( ( flags & (IS_NEW | IS_MOVED) ) == IS_MOVED )
  280. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_PLACE_EDGE, _( "Place edge" ), apply_xpm );
  281. wxMenu* edit_mnu = new wxMenu;
  282. ADD_MENUITEM_WITH_SUBMENU( PopMenu, edit_mnu, ID_POPUP_PCB_EDIT_EDGE, _( "Edit" ),
  283. edit_xpm );
  284. ADD_MENUITEM( edit_mnu, ID_POPUP_PCB_EDIT_WIDTH_CURRENT_EDGE,
  285. _( "Edit Width (Current)" ), width_segment_xpm );
  286. ADD_MENUITEM( edit_mnu, ID_POPUP_PCB_EDIT_WIDTH_ALL_EDGE,
  287. _( "Edit Width (All)" ), width_segment_xpm );
  288. ADD_MENUITEM( edit_mnu, ID_POPUP_PCB_EDIT_LAYER_CURRENT_EDGE,
  289. _( "Edit Layer (Current)" ), select_layer_pair_xpm );
  290. ADD_MENUITEM( edit_mnu, ID_POPUP_PCB_EDIT_LAYER_ALL_EDGE,
  291. _( "Edit Layer (All)" ), select_layer_pair_xpm );
  292. msg = AddHotkeyName( _("Delete edge" ), g_Module_Editor_Hokeys_Descr, HK_DELETE );
  293. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_EDGE, msg, delete_xpm );
  294. append_set_width = TRUE;
  295. }
  296. break;
  297. case TYPE_DRAWSEGMENT:
  298. case TYPE_TEXTE:
  299. case TYPE_VIA:
  300. case TYPE_TRACK:
  301. case TYPE_ZONE:
  302. case TYPE_MARKER_PCB:
  303. case TYPE_DIMENSION:
  304. case TYPE_MIRE:
  305. break;
  306. case TYPE_SCREEN:
  307. case TYPE_NOT_INIT:
  308. case TYPE_PCB:
  309. msg.Printf( wxT( "WinEDA_ModuleEditFrame::OnRightClick Error: illegal DrawType %d" ),
  310. item->Type() );
  311. DisplayError( this, msg );
  312. break;
  313. default:
  314. msg.Printf( wxT( "WinEDA_ModuleEditFrame::OnRightClick Error: unknown DrawType %d" ),
  315. item->Type() );
  316. DisplayError( this, msg );
  317. break;
  318. }
  319. PopMenu->AppendSeparator();
  320. if( append_set_width
  321. || ( ( GetToolId() != ID_NO_TOOL_SELECTED )
  322. && ( ( GetToolId() == ID_PCB_ADD_LINE_BUTT )
  323. || ( GetToolId() == ID_PCB_CIRCLE_BUTT )
  324. || ( GetToolId() == ID_PCB_ARC_BUTT ) ) ) )
  325. {
  326. ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ENTER_EDGE_WIDTH, _("Set Width" ), width_segment_xpm );
  327. PopMenu->AppendSeparator();
  328. }
  329. return true;
  330. }
  331. /* Handle the double click in the footprint editor:
  332. * If the double clicked item is editable: call the corresponding editor.
  333. */
  334. void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
  335. {
  336. BOARD_ITEM* item = GetCurItem();
  337. wxPoint pos = GetPosition();
  338. switch( GetToolId() )
  339. {
  340. case ID_NO_TOOL_SELECTED:
  341. if( ( item == NULL ) || ( item->m_Flags == 0 ) )
  342. {
  343. item = ModeditLocateAndDisplay();
  344. }
  345. if( ( item == NULL ) || ( item->m_Flags != 0 ) )
  346. break;
  347. // Item found
  348. SetCurItem( item );
  349. switch( item->Type() )
  350. {
  351. case TYPE_PAD:
  352. InstallPadOptionsFrame( (D_PAD*) item );
  353. DrawPanel->MoveCursorToCrossHair();
  354. break;
  355. case TYPE_MODULE:
  356. {
  357. DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) item );
  358. int ret = dialog.ShowModal();
  359. GetScreen()->GetCurItem()->m_Flags = 0;
  360. DrawPanel->MoveCursorToCrossHair();
  361. if( ret > 0 )
  362. DrawPanel->Refresh();
  363. }
  364. break;
  365. case TYPE_TEXTE_MODULE:
  366. InstallTextModOptionsFrame( (TEXTE_MODULE*) item, DC );
  367. DrawPanel->MoveCursorToCrossHair();
  368. break;
  369. default:
  370. break;
  371. }
  372. break; // end case 0
  373. case ID_PCB_ADD_LINE_BUTT:
  374. {
  375. if( item && item->IsNew() )
  376. {
  377. End_Edge_Module( (EDGE_MODULE*) item );
  378. SetCurItem( NULL );
  379. DrawPanel->Refresh();
  380. }
  381. break;
  382. }
  383. default:
  384. break;
  385. }
  386. }