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.

292 lines
11 KiB

16 years ago
16 years ago
  1. /****************************/
  2. /* EESchema - libedit_onrightclick.cpp */
  3. /****************************/
  4. /* , In library editor, create the pop menu when clicking on mouse right button
  5. */
  6. #include "fctsys.h"
  7. #include "gr_basic.h"
  8. #include "common.h"
  9. #include "macros.h"
  10. #include "confirm.h"
  11. #include "bitmaps.h"
  12. #include "eeschema_id.h"
  13. #include "hotkeys.h"
  14. #include "class_sch_screen.h"
  15. #include "general.h"
  16. #include "protos.h"
  17. #include "libeditframe.h"
  18. #include "class_libentry.h"
  19. #include "lib_pin.h"
  20. #include "lib_polyline.h"
  21. /* functions to add commands and submenus depending on the item */
  22. static void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame );
  23. static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame );
  24. bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
  25. {
  26. LIB_DRAW_ITEM* DrawEntry = LocateItemUsingCursor( aPosition );
  27. bool BlockActive = GetScreen()->IsBlockActive();
  28. if( BlockActive )
  29. {
  30. AddMenusForBlock( PopMenu, this );
  31. PopMenu->AppendSeparator();
  32. return true;
  33. }
  34. if( m_component == NULL )
  35. return true;
  36. // If Command in progress, put menu "cancel"
  37. if( DrawEntry && DrawEntry->m_Flags )
  38. {
  39. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ), cancel_xpm );
  40. PopMenu->AppendSeparator();
  41. }
  42. else if( GetToolId() != ID_NO_TOOL_SELECTED )
  43. { // If a tool is active, put menu "end tool"
  44. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ), cancel_tool_xpm );
  45. PopMenu->AppendSeparator();
  46. }
  47. if( DrawEntry )
  48. DrawEntry->DisplayInfo( this );
  49. else
  50. return true;
  51. m_drawItem = DrawEntry;
  52. wxString msg;
  53. switch( DrawEntry->Type() )
  54. {
  55. case LIB_PIN_T:
  56. AddMenusForPin( PopMenu, (LIB_PIN*) DrawEntry, this );
  57. break;
  58. case LIB_ARC_T:
  59. if( DrawEntry->m_Flags == 0 )
  60. {
  61. msg = AddHotkeyName( _( "Move Arc" ), s_Libedit_Hokeys_Descr,
  62. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  63. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_arc_xpm );
  64. msg = AddHotkeyName( _( "Drag Arc Size" ), s_Libedit_Hokeys_Descr, HK_DRAG );
  65. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_arc_xpm );
  66. }
  67. msg = AddHotkeyName( _( "Edit Arc Options" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  68. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_arc_xpm );
  69. if( DrawEntry->m_Flags == 0 )
  70. {
  71. msg = AddHotkeyName( _( "Delete Arc" ), s_Libedit_Hokeys_Descr, HK_DELETE );
  72. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_arc_xpm );
  73. }
  74. break;
  75. case LIB_CIRCLE_T:
  76. if( DrawEntry->m_Flags == 0 )
  77. {
  78. msg = AddHotkeyName( _( "Move Circle" ), s_Libedit_Hokeys_Descr,
  79. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  80. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_circle_xpm );
  81. }
  82. if( DrawEntry->m_Flags == 0 )
  83. {
  84. msg = AddHotkeyName( _( "Drag Circle Outline" ), s_Libedit_Hokeys_Descr, HK_DRAG );
  85. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_rectangle_xpm );
  86. }
  87. msg = AddHotkeyName( _( "Edit Circle Options" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  88. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_circle_xpm );
  89. if( DrawEntry->m_Flags == 0 )
  90. {
  91. msg = AddHotkeyName( _( "Delete Circle" ), s_Libedit_Hokeys_Descr, HK_DELETE );
  92. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_circle_xpm );
  93. }
  94. break;
  95. case LIB_RECTANGLE_T:
  96. if( DrawEntry->m_Flags == 0 )
  97. {
  98. msg = AddHotkeyName( _( "Move Rectangle" ), s_Libedit_Hokeys_Descr,
  99. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  100. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_rectangle_xpm );
  101. }
  102. msg = AddHotkeyName( _( "Edit Rectangle Options" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  103. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_rectangle_xpm );
  104. if( DrawEntry->m_Flags == 0 )
  105. {
  106. msg = AddHotkeyName( _( "Drag Rectangle Edge" ), s_Libedit_Hokeys_Descr, HK_DRAG );
  107. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_rectangle_xpm );
  108. }
  109. if( DrawEntry->m_Flags == 0 )
  110. {
  111. msg = AddHotkeyName( _( "Delete Rectangle" ), s_Libedit_Hokeys_Descr, HK_DELETE );
  112. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_rectangle_xpm );
  113. }
  114. break;
  115. case LIB_TEXT_T:
  116. if( DrawEntry->m_Flags == 0 )
  117. {
  118. msg = AddHotkeyName( _( "Move Text" ), s_Libedit_Hokeys_Descr,
  119. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  120. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_text_xpm );
  121. }
  122. msg = AddHotkeyName( _( "Edit Text" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  123. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, edit_text_xpm );
  124. msg = AddHotkeyName( _( "Rotate Text" ), s_Libedit_Hokeys_Descr, HK_ROTATE );
  125. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT, msg, edit_text_xpm );
  126. if( DrawEntry->m_Flags == 0 )
  127. {
  128. msg = AddHotkeyName( _( "Delete Text" ), s_Libedit_Hokeys_Descr, HK_DELETE );
  129. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_text_xpm );
  130. }
  131. break;
  132. case LIB_POLYLINE_T:
  133. if( DrawEntry->m_Flags == 0 )
  134. {
  135. msg = AddHotkeyName( _( "Move Line" ), s_Libedit_Hokeys_Descr,
  136. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  137. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_line_xpm );
  138. msg = AddHotkeyName( _( "Drag Edge Point" ), s_Libedit_Hokeys_Descr, HK_DRAG );
  139. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_line_xpm );
  140. }
  141. if( DrawEntry->m_Flags & IS_NEW )
  142. {
  143. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ), apply_xpm );
  144. }
  145. msg = AddHotkeyName( _( "Edit Line Options" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  146. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_segment_xpm );
  147. if( DrawEntry->m_Flags == 0 )
  148. {
  149. msg = AddHotkeyName( _( "Delete Line " ), s_Libedit_Hokeys_Descr, HK_DELETE );
  150. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_segment_xpm );
  151. }
  152. else if( (DrawEntry->m_Flags & IS_NEW) )
  153. {
  154. if( ( (LIB_POLYLINE*) DrawEntry )->GetCornerCount() > 2 )
  155. {
  156. msg = AddHotkeyName( _( "Delete Segment" ), s_Libedit_Hokeys_Descr, HK_DELETE );
  157. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT,
  158. msg, delete_segment_xpm );
  159. }
  160. }
  161. break;
  162. case LIB_FIELD_T:
  163. if( DrawEntry->m_Flags == 0 )
  164. {
  165. msg = AddHotkeyName( _( "Move Field" ), s_Libedit_Hokeys_Descr,
  166. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  167. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_field_xpm );
  168. }
  169. msg = AddHotkeyName( _( "Field Rotate" ), s_Libedit_Hokeys_Descr, HK_ROTATE );
  170. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM, msg, rotate_field_xpm );
  171. msg = AddHotkeyName( _( "Field Edit" ), s_Libedit_Hokeys_Descr, HK_EDIT );
  172. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, edit_text_xpm );
  173. break;
  174. default:
  175. wxString msg;
  176. msg.Printf( wxT( "LIB_EDIT_FRAME::OnRightClick Error: unknown StructType %d" ),
  177. DrawEntry->Type() );
  178. DisplayError( this, msg );
  179. m_drawItem = NULL;
  180. break;
  181. }
  182. PopMenu->AppendSeparator();
  183. return true;
  184. }
  185. void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
  186. {
  187. bool selected = (Pin->m_Selected & IS_SELECTED) != 0;
  188. bool not_in_move = (Pin->m_Flags == 0);
  189. wxString msg;
  190. if( not_in_move )
  191. {
  192. msg = AddHotkeyName( _( "Move Pin " ), s_Libedit_Hokeys_Descr,
  193. HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
  194. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_xpm );
  195. }
  196. msg = AddHotkeyName( _( "Edit Pin " ), s_Libedit_Hokeys_Descr, HK_EDIT);
  197. ADD_MENUITEM( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, edit_xpm );
  198. msg = AddHotkeyName( _( "Rotate Pin " ), s_Libedit_Hokeys_Descr, HK_ROTATE );
  199. ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_PIN, msg, rotate_pin_xpm );
  200. if( not_in_move )
  201. {
  202. msg = AddHotkeyName( _( "Delete Pin " ), s_Libedit_Hokeys_Descr, HK_DELETE );
  203. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_pin_xpm );
  204. }
  205. wxMenu* global_pin_change = new wxMenu;
  206. ADD_MENUITEM_WITH_SUBMENU( PopMenu, global_pin_change,
  207. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
  208. _( "Global" ), pin_to_xpm );
  209. ADD_MENUITEM( global_pin_change,
  210. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM,
  211. selected ? _( "Pin Size to selected pins" ) :
  212. _( "Pin Size to Others" ), pin_size_to_xpm );
  213. ADD_MENUITEM( global_pin_change,
  214. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM,
  215. selected ? _( "Pin Name Size to selected pin" ) :
  216. _( "Pin Name Size to Others" ), pin_name_to_xpm );
  217. ADD_MENUITEM( global_pin_change,
  218. ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
  219. selected ? _( "Pin Num Size to selected pin" ) :
  220. _( "Pin Num Size to Others" ), pin_number_to_xpm );
  221. }
  222. /* Add menu commands for block */
  223. void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
  224. {
  225. ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ), cancel_xpm );
  226. if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
  227. ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK,
  228. _( "Zoom Block (drag middle mouse)" ),
  229. zoom_selected_xpm );
  230. PopMenu->AppendSeparator();
  231. ADD_MENUITEM( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), apply_xpm );
  232. if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
  233. {
  234. ADD_MENUITEM( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ), green_xpm );
  235. ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), copyblock_xpm );
  236. ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, _( "Mirror Block ||" ), mirror_H_xpm );
  237. ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), delete_xpm );
  238. }
  239. }