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.

369 lines
14 KiB

16 years ago
  1. /**
  2. * @file libedit_onrightclick.cpp
  3. * @brief Library editor: create the pop menus when clicking on mouse right button
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 2004-2014 KiCad Developers, see change_log.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <fctsys.h>
  28. #include <confirm.h>
  29. #include <eeschema_id.h>
  30. #include <hotkeys.h>
  31. #include <class_drawpanel.h>
  32. #include <sch_screen.h>
  33. #include <msgpanel.h>
  34. #include <general.h>
  35. #include <lib_edit_frame.h>
  36. #include <class_libentry.h>
  37. #include <lib_pin.h>
  38. #include <lib_polyline.h>
  39. #include <menus_helpers.h>
  40. /* functions to add commands and submenus depending on the item */
  41. static void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame );
  42. static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame );
  43. bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
  44. {
  45. LIB_ITEM* item = GetDrawItem();
  46. bool blockActive = GetScreen()->IsBlockActive();
  47. wxString msg;
  48. if( blockActive )
  49. {
  50. AddMenusForBlock( PopMenu, this );
  51. PopMenu->AppendSeparator();
  52. return true;
  53. }
  54. LIB_PART* part = GetCurPart();
  55. if( !part )
  56. return true;
  57. // If Command in progress, put menu "cancel"
  58. if( item && item->InEditMode() )
  59. {
  60. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ),
  61. KiBitmap( cancel_xpm ) );
  62. PopMenu->AppendSeparator();
  63. }
  64. else
  65. {
  66. item = LocateItemUsingCursor( aPosition );
  67. // If the clarify item selection context menu is aborted, don't show the context menu.
  68. if( item == NULL && m_canvas->GetAbortRequest() )
  69. {
  70. m_canvas->SetAbortRequest( false );
  71. return false;
  72. }
  73. if( GetToolId() != ID_NO_TOOL_SELECTED )
  74. {
  75. // If a tool is active, put menu "end tool"
  76. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ),
  77. KiBitmap( cursor_xpm ) );
  78. PopMenu->AppendSeparator();
  79. }
  80. }
  81. if( item )
  82. {
  83. MSG_PANEL_ITEMS items;
  84. item->GetMsgPanelInfo( items );
  85. SetMsgPanel( items );
  86. }
  87. else
  88. {
  89. if( GetToolId() == ID_NO_TOOL_SELECTED )
  90. {
  91. msg = AddHotkeyName( _( "&Paste" ), g_Libedit_Hokeys_Descr, HK_EDIT_PASTE );
  92. AddMenuItem( PopMenu, wxID_PASTE, msg,
  93. _( "Pastes item(s) from the Clipboard" ),
  94. KiBitmap( paste_xpm ) );
  95. }
  96. return true;
  97. }
  98. SetDrawItem( item );
  99. bool not_edited = !item->InEditMode();
  100. switch( item->Type() )
  101. {
  102. case LIB_PIN_T:
  103. AddMenusForPin( PopMenu, (LIB_PIN*) item, this );
  104. break;
  105. case LIB_ARC_T:
  106. if( not_edited )
  107. {
  108. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  109. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  110. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  111. KiBitmap( move_xpm ) );
  112. msg = AddHotkeyName( _( "Drag Arc Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  113. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_xpm ) );
  114. }
  115. msg = AddHotkeyName( _( "Edit Arc Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  116. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_arc_xpm ) );
  117. if( not_edited )
  118. {
  119. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  120. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  121. }
  122. break;
  123. case LIB_CIRCLE_T:
  124. if( not_edited )
  125. {
  126. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  127. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  128. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  129. KiBitmap( move_xpm ) );
  130. msg = AddHotkeyName( _( "Drag Circle Outline" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  131. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg,
  132. KiBitmap( move_rectangle_xpm ) );
  133. }
  134. msg = AddHotkeyName( _( "Edit Circle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
  135. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  136. KiBitmap( options_circle_xpm ) );
  137. if( not_edited )
  138. {
  139. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  140. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  141. KiBitmap( delete_circle_xpm ) );
  142. }
  143. break;
  144. case LIB_RECTANGLE_T:
  145. if( not_edited )
  146. {
  147. msg = AddHotkeyName( _( "Move Rectangle" ), g_Libedit_Hokeys_Descr,
  148. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  149. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  150. KiBitmap( move_rectangle_xpm ) );
  151. }
  152. msg = AddHotkeyName( _( "Edit Rectangle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
  153. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  154. KiBitmap( options_rectangle_xpm ) );
  155. if( not_edited )
  156. {
  157. msg = AddHotkeyName( _( "Drag Rectangle Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  158. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg,
  159. KiBitmap( move_rectangle_xpm ) );
  160. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  161. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  162. KiBitmap( delete_rectangle_xpm ) );
  163. }
  164. break;
  165. case LIB_TEXT_T:
  166. if( not_edited )
  167. {
  168. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  169. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  170. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  171. KiBitmap( move_xpm ) );
  172. }
  173. msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
  174. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  175. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  176. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  177. if( not_edited )
  178. {
  179. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  180. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  181. }
  182. break;
  183. case LIB_POLYLINE_T:
  184. if( not_edited )
  185. {
  186. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  187. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  188. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  189. KiBitmap( move_xpm ) );
  190. msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  191. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_exactly_xpm ) );
  192. }
  193. if( item->IsNew() )
  194. {
  195. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ),
  196. KiBitmap( checked_ok_xpm ) );
  197. }
  198. msg = AddHotkeyName( _( "Edit Line Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
  199. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  200. KiBitmap( options_segment_xpm ) );
  201. if( not_edited )
  202. {
  203. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  204. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  205. KiBitmap( delete_xpm ) );
  206. }
  207. if( item->IsNew() )
  208. {
  209. if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 )
  210. {
  211. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  212. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT,
  213. msg, KiBitmap( delete_xpm ) );
  214. }
  215. }
  216. break;
  217. case LIB_FIELD_T:
  218. if( not_edited )
  219. {
  220. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  221. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  222. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  223. KiBitmap( move_xpm ) );
  224. }
  225. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  226. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  227. msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
  228. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  229. break;
  230. default:
  231. wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ),
  232. item->Type() ) );
  233. SetDrawItem( NULL );
  234. break;
  235. }
  236. PopMenu->AppendSeparator();
  237. return true;
  238. }
  239. // Add menu items for pin edition
  240. void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
  241. {
  242. bool selected = Pin->IsSelected();
  243. bool not_in_move = !Pin->IsMoving();
  244. wxString msg;
  245. if( not_in_move )
  246. {
  247. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  248. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  249. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
  250. }
  251. msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT);
  252. AddMenuItem( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, KiBitmap( edit_xpm ) );
  253. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  254. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  255. if( not_in_move )
  256. {
  257. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  258. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  259. }
  260. wxMenu* global_pin_change = new wxMenu;
  261. AddMenuItem( PopMenu, global_pin_change,
  262. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
  263. _( "Global" ), KiBitmap( pin_to_xpm ) );
  264. AddMenuItem( global_pin_change,
  265. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM,
  266. selected ? _( "Push Pin Size to Selected Pin" ) :
  267. _( "Push Pin Size to Others" ), KiBitmap( pin_size_to_xpm ) );
  268. AddMenuItem( global_pin_change,
  269. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM,
  270. selected ? _( "Push Pin Name Size to Selected Pin" ) :
  271. _( "Push Pin Name Size to Others" ), KiBitmap( pin_name_to_xpm ) );
  272. AddMenuItem( global_pin_change,
  273. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
  274. selected ? _( "Push Pin Num Size to Selected Pin" ) :
  275. _( "Push Pin Num Size to Others" ), KiBitmap( pin_number_to_xpm ) );
  276. }
  277. /* Add menu commands for block */
  278. void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
  279. {
  280. wxString msg;
  281. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
  282. KiBitmap( cancel_xpm ) );
  283. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  284. AddMenuItem( PopMenu, ID_POPUP_ZOOM_BLOCK,
  285. _( "Zoom Block" ),
  286. KiBitmap( zoom_area_xpm ) );
  287. PopMenu->AppendSeparator();
  288. AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
  289. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  290. {
  291. AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
  292. KiBitmap( green_xpm ) );
  293. msg = AddHotkeyName( _( "Cut Block" ), g_Schematic_Hokeys_Descr,
  294. HK_EDIT_CUT );
  295. AddMenuItem( PopMenu, wxID_CUT, msg, KiBitmap( cut_xpm ) );
  296. msg = AddHotkeyName( _( "Copy Block" ), g_Schematic_Hokeys_Descr,
  297. HK_EDIT_COPY );
  298. AddMenuItem( PopMenu, wxID_COPY, msg, KiBitmap( copy_xpm ) );
  299. AddMenuItem( PopMenu, ID_POPUP_DUPLICATE_BLOCK, _( "Duplicate Block" ),
  300. KiBitmap( duplicate_xpm ) );
  301. msg = AddHotkeyName( _( "Mirror Block Around Horizontal(X) Axis" ), g_Libedit_Hokeys_Descr,
  302. HK_MIRROR_X );
  303. AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg,
  304. KiBitmap( mirror_v_xpm ) );
  305. msg = AddHotkeyName( _( "Mirror Block Around Vertical(Y) Axis" ), g_Libedit_Hokeys_Descr,
  306. HK_MIRROR_Y );
  307. AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
  308. KiBitmap( mirror_h_xpm ) );
  309. msg = AddHotkeyName( _( "Rotate Counterclockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  310. AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
  311. KiBitmap( rotate_ccw_xpm ) );
  312. AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
  313. }
  314. }