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.

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