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.

352 lines
13 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 <class_sch_screen.h>
  33. #include <msgpanel.h>
  34. #include <general.h>
  35. #include <libeditframe.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. if( blockActive )
  48. {
  49. AddMenusForBlock( PopMenu, this );
  50. PopMenu->AppendSeparator();
  51. return true;
  52. }
  53. LIB_PART* part = GetCurPart();
  54. if( !part )
  55. return true;
  56. // If Command in progress, put menu "cancel"
  57. if( item && item->InEditMode() )
  58. {
  59. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ),
  60. KiBitmap( cancel_xpm ) );
  61. PopMenu->AppendSeparator();
  62. }
  63. else
  64. {
  65. item = LocateItemUsingCursor( aPosition );
  66. // If the clarify item selection context menu is aborted, don't show the context menu.
  67. if( item == NULL && m_canvas->GetAbortRequest() )
  68. {
  69. m_canvas->SetAbortRequest( false );
  70. return false;
  71. }
  72. if( GetToolId() != ID_NO_TOOL_SELECTED )
  73. {
  74. // If a tool is active, put menu "end tool"
  75. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ),
  76. KiBitmap( cursor_xpm ) );
  77. PopMenu->AppendSeparator();
  78. }
  79. }
  80. if( item )
  81. {
  82. MSG_PANEL_ITEMS items;
  83. item->GetMsgPanelInfo( items );
  84. SetMsgPanel( items );
  85. }
  86. else
  87. {
  88. return true;
  89. }
  90. m_drawItem = item;
  91. bool not_edited = !item->InEditMode();
  92. wxString msg;
  93. switch( item->Type() )
  94. {
  95. case LIB_PIN_T:
  96. AddMenusForPin( PopMenu, (LIB_PIN*) item, this );
  97. break;
  98. case LIB_ARC_T:
  99. if( not_edited )
  100. {
  101. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  102. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  103. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  104. KiBitmap( move_xpm ) );
  105. msg = AddHotkeyName( _( "Drag Arc Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  106. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_xpm ) );
  107. }
  108. msg = AddHotkeyName( _( "Edit Arc Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  109. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_arc_xpm ) );
  110. if( not_edited )
  111. {
  112. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  113. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  114. }
  115. break;
  116. case LIB_CIRCLE_T:
  117. if( not_edited )
  118. {
  119. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  120. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  121. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  122. KiBitmap( move_xpm ) );
  123. msg = AddHotkeyName( _( "Drag Circle Outline" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  124. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg,
  125. KiBitmap( move_rectangle_xpm ) );
  126. }
  127. msg = AddHotkeyName( _( "Edit Circle Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  128. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  129. KiBitmap( options_circle_xpm ) );
  130. if( not_edited )
  131. {
  132. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  133. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  134. KiBitmap( delete_circle_xpm ) );
  135. }
  136. break;
  137. case LIB_RECTANGLE_T:
  138. if( not_edited )
  139. {
  140. msg = AddHotkeyName( _( "Move Rectangle" ), g_Libedit_Hokeys_Descr,
  141. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  142. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  143. KiBitmap( move_rectangle_xpm ) );
  144. }
  145. msg = AddHotkeyName( _( "Edit Rectangle Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  146. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  147. KiBitmap( options_rectangle_xpm ) );
  148. if( not_edited )
  149. {
  150. msg = AddHotkeyName( _( "Drag Rectangle Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  151. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg,
  152. KiBitmap( move_rectangle_xpm ) );
  153. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  154. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  155. KiBitmap( delete_rectangle_xpm ) );
  156. }
  157. break;
  158. case LIB_TEXT_T:
  159. if( not_edited )
  160. {
  161. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  162. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  163. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  164. KiBitmap( move_xpm ) );
  165. }
  166. msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  167. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  168. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  169. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  170. if( not_edited )
  171. {
  172. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  173. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  174. }
  175. break;
  176. case LIB_POLYLINE_T:
  177. if( not_edited )
  178. {
  179. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  180. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  181. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  182. KiBitmap( move_xpm ) );
  183. msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG );
  184. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_exactly_xpm ) );
  185. }
  186. if( item->IsNew() )
  187. {
  188. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ),
  189. KiBitmap( checked_ok_xpm ) );
  190. }
  191. msg = AddHotkeyName( _( "Edit Line Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  192. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg,
  193. KiBitmap( options_segment_xpm ) );
  194. if( not_edited )
  195. {
  196. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  197. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg,
  198. KiBitmap( delete_xpm ) );
  199. }
  200. if( item->IsNew() )
  201. {
  202. if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 )
  203. {
  204. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  205. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT,
  206. msg, KiBitmap( delete_xpm ) );
  207. }
  208. }
  209. break;
  210. case LIB_FIELD_T:
  211. if( not_edited )
  212. {
  213. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  214. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  215. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg,
  216. KiBitmap( move_xpm ) );
  217. }
  218. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  219. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  220. msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT );
  221. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  222. break;
  223. default:
  224. wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ),
  225. item->Type() ) );
  226. m_drawItem = NULL;
  227. break;
  228. }
  229. PopMenu->AppendSeparator();
  230. return true;
  231. }
  232. // Add menu items for pin edition
  233. void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
  234. {
  235. bool selected = Pin->IsSelected();
  236. bool not_in_move = !Pin->IsMoving();
  237. wxString msg;
  238. if( not_in_move )
  239. {
  240. msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
  241. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  242. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
  243. }
  244. msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT);
  245. AddMenuItem( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, KiBitmap( edit_xpm ) );
  246. msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  247. AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
  248. if( not_in_move )
  249. {
  250. msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
  251. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
  252. }
  253. wxMenu* global_pin_change = new wxMenu;
  254. AddMenuItem( PopMenu, global_pin_change,
  255. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
  256. _( "Global" ), KiBitmap( pin_to_xpm ) );
  257. AddMenuItem( global_pin_change,
  258. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM,
  259. selected ? _( "Pin Size to selected pins" ) :
  260. _( "Pin Size to Others" ), KiBitmap( pin_size_to_xpm ) );
  261. AddMenuItem( global_pin_change,
  262. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM,
  263. selected ? _( "Pin Name Size to selected pin" ) :
  264. _( "Pin Name Size to Others" ), KiBitmap( pin_name_to_xpm ) );
  265. AddMenuItem( global_pin_change,
  266. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
  267. selected ? _( "Pin Num Size to selected pin" ) :
  268. _( "Pin Num Size to Others" ), KiBitmap( pin_number_to_xpm ) );
  269. }
  270. /* Add menu commands for block */
  271. void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
  272. {
  273. wxString msg;
  274. AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
  275. KiBitmap( cancel_xpm ) );
  276. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  277. AddMenuItem( PopMenu, ID_POPUP_ZOOM_BLOCK,
  278. _( "Zoom Block (drag middle mouse)" ),
  279. KiBitmap( zoom_area_xpm ) );
  280. PopMenu->AppendSeparator();
  281. AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
  282. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  283. {
  284. AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
  285. KiBitmap( green_xpm ) );
  286. AddMenuItem( PopMenu, ID_POPUP_DUPLICATE_BLOCK, _( "Duplicate Block" ), KiBitmap( duplicate_xpm ) );
  287. msg = AddHotkeyName( _( "Flip Block Horizonal" ), g_Libedit_Hokeys_Descr, HK_MIRROR_Y );
  288. AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
  289. KiBitmap( mirror_h_xpm ) );
  290. msg = AddHotkeyName( _( "Flip Block Vertical" ), g_Libedit_Hokeys_Descr, HK_MIRROR_X );
  291. AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg,
  292. KiBitmap( mirror_v_xpm ) );
  293. msg = AddHotkeyName( _( "Rotate Counterclockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
  294. AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
  295. KiBitmap( rotate_ccw_xpm ) );
  296. AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
  297. }
  298. }