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.

669 lines
27 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
17 years ago
16 years ago
16 years ago
  1. /********************/
  2. /* onrightclick.cpp */
  3. /********************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "eeschema_id.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "bitmaps.h"
  10. #include "class_sch_screen.h"
  11. #include "wxEeschemaStruct.h"
  12. #include "general.h"
  13. #include "protos.h"
  14. #include "hotkeys.h"
  15. #include "class_library.h"
  16. #include "sch_bus_entry.h"
  17. #include "sch_marker.h"
  18. #include "sch_text.h"
  19. #include "sch_junction.h"
  20. #include "sch_component.h"
  21. #include "sch_line.h"
  22. #include "sch_no_connect.h"
  23. #include "sch_sheet.h"
  24. #include "sch_sheet_path.h"
  25. #include <iostream>
  26. using namespace std;
  27. static void AddMenusForBlock( wxMenu* PopMenu, SCH_EDIT_FRAME* frame );
  28. static void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame );
  29. static void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame );
  30. static void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet );
  31. static void AddMenusForSheetPin( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet );
  32. static void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text );
  33. static void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label );
  34. static void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel );
  35. static void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* GLabel );
  36. static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
  37. static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field );
  38. static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame );
  39. /* Prepare context menu when a click on the right mouse button occurs.
  40. *
  41. * This menu is then added to the list of zoom commands.
  42. */
  43. bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
  44. {
  45. SCH_ITEM* item = GetScreen()->GetCurItem();
  46. bool BlockActive = GetScreen()->IsBlockActive();
  47. // Do not start a block command on context menu.
  48. DrawPanel->m_CanStartBlock = -1;
  49. if( BlockActive )
  50. {
  51. AddMenusForBlock( PopMenu, this );
  52. PopMenu->AppendSeparator();
  53. return true;
  54. }
  55. // Try to locate items at cursor position.
  56. if( (item == NULL) || (item->GetFlags() == 0) )
  57. {
  58. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::AllItemsButPins );
  59. // If the clarify item selection context menu is aborted, don't show the context menu.
  60. if( item == NULL && DrawPanel->m_AbortRequest )
  61. {
  62. DrawPanel->m_AbortRequest = false;
  63. return false;
  64. }
  65. }
  66. // If Command in progress: add "cancel" and "end tool" menu
  67. if( GetToolId() != ID_NO_TOOL_SELECTED )
  68. {
  69. if( item && item->GetFlags() )
  70. {
  71. ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
  72. }
  73. else
  74. {
  75. ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "End Tool" ), cancel_tool_xpm );
  76. }
  77. PopMenu->AppendSeparator();
  78. }
  79. else
  80. {
  81. if( item && item->GetFlags() )
  82. {
  83. ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
  84. PopMenu->AppendSeparator();
  85. }
  86. }
  87. if( item == NULL )
  88. {
  89. if( GetSheet()->Last() != g_RootSheet )
  90. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, _( "Leave Sheet" ), leave_sheet_xpm );
  91. PopMenu->AppendSeparator();
  92. return true;
  93. }
  94. int flags = item->GetFlags();
  95. bool is_new = (flags & IS_NEW) ? true : false;
  96. switch( item->Type() )
  97. {
  98. case SCH_NO_CONNECT_T:
  99. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete No Connect" ), delete_xpm );
  100. break;
  101. case SCH_JUNCTION_T:
  102. addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
  103. break;
  104. case SCH_BUS_ENTRY_T:
  105. if( !flags )
  106. {
  107. wxString msg = AddHotkeyName( _( "Move Bus Entry" ), s_Schematic_Hokeys_Descr,
  108. HK_MOVE_COMPONENT_OR_ITEM );
  109. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_xpm );
  110. }
  111. if( GetBusEntryShape( (SCH_BUS_ENTRY*) item ) == '\\' )
  112. PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_SLASH, _( "Set Bus Entry /" ) );
  113. else
  114. PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH, _( "Set Bus Entry \\" ) );
  115. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Bus Entry" ), delete_bus_xpm );
  116. break;
  117. case SCH_MARKER_T:
  118. AddMenusForMarkers( PopMenu, (SCH_MARKER*) item, this );
  119. break;
  120. case SCH_TEXT_T:
  121. AddMenusForText( PopMenu, (SCH_TEXT*) item );
  122. break;
  123. case SCH_LABEL_T:
  124. AddMenusForLabel( PopMenu, (SCH_LABEL*) item );
  125. break;
  126. case SCH_GLOBAL_LABEL_T:
  127. AddMenusForGLabel( PopMenu, (SCH_GLOBALLABEL*) item );
  128. break;
  129. case SCH_HIERARCHICAL_LABEL_T:
  130. AddMenusForHLabel( PopMenu, (SCH_HIERLABEL*) item );
  131. break;
  132. case SCH_FIELD_T:
  133. AddMenusForComponentField( PopMenu, (SCH_FIELD*) item );
  134. break;
  135. case SCH_COMPONENT_T:
  136. AddMenusForComponent( PopMenu, (SCH_COMPONENT*) item );
  137. break;
  138. case SCH_LINE_T:
  139. switch( item->GetLayer() )
  140. {
  141. case LAYER_WIRE:
  142. AddMenusForWire( PopMenu, (SCH_LINE*) item, this );
  143. break;
  144. case LAYER_BUS:
  145. AddMenusForBus( PopMenu, (SCH_LINE*) item, this );
  146. break;
  147. default:
  148. if( is_new )
  149. ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "End Drawing" ), apply_xpm );
  150. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Drawing" ), delete_xpm );
  151. break;
  152. }
  153. break;
  154. case SCH_SHEET_T:
  155. AddMenusForHierchicalSheet( PopMenu, (SCH_SHEET*) item );
  156. break;
  157. case SCH_SHEET_PIN_T:
  158. AddMenusForSheetPin( PopMenu, (SCH_SHEET_PIN*) item );
  159. break;
  160. default:
  161. wxFAIL_MSG( wxString::Format( wxT( "Cannot create context menu for unknown type %d" ),
  162. item->Type() ) );
  163. break;
  164. }
  165. PopMenu->AppendSeparator();
  166. return true;
  167. }
  168. void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field )
  169. {
  170. wxString msg;
  171. if( !Field->GetFlags() )
  172. {
  173. msg = AddHotkeyName( _( "Move Field" ), s_Schematic_Hokeys_Descr,
  174. HK_MOVE_COMPONENT_OR_ITEM );
  175. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_text_xpm );
  176. }
  177. msg = AddHotkeyName( _( "Rotate Field" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  178. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_FIELD, msg, rotate_field_xpm );
  179. msg = AddHotkeyName( _( "Edit Field" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  180. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_FIELD, msg, edit_text_xpm );
  181. }
  182. void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
  183. {
  184. if( Component->Type() != SCH_COMPONENT_T )
  185. {
  186. wxASSERT( 0 );
  187. return;
  188. }
  189. wxString msg;
  190. LIB_ALIAS* libEntry;
  191. LIB_COMPONENT* libComponent = NULL;
  192. libEntry = CMP_LIBRARY::FindLibraryEntry( Component->GetLibName() );
  193. if( libEntry )
  194. libComponent = libEntry->GetComponent();
  195. if( !Component->GetFlags() )
  196. {
  197. msg = _( "Move Component" );
  198. msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text;
  199. msg = AddHotkeyName( msg, s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT_OR_ITEM );
  200. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_xpm );
  201. msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  202. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_xpm );
  203. }
  204. wxMenu* orientmenu = new wxMenu;
  205. msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  206. ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE, msg, rotate_CCW_xpm );
  207. ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE, _( "Rotate -" ), rotate_CW_xpm );
  208. msg = AddHotkeyName( _( "Mirror --" ), s_Schematic_Hokeys_Descr, HK_MIRROR_X_COMPONENT );
  209. ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_X_CMP, msg, mirror_V_xpm );
  210. msg = AddHotkeyName( _( "Mirror ||" ), s_Schematic_Hokeys_Descr, HK_MIRROR_Y_COMPONENT );
  211. ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_Y_CMP, msg, mirror_H_xpm );
  212. msg = AddHotkeyName( _( "Normal" ), s_Schematic_Hokeys_Descr, HK_ORIENT_NORMAL_COMPONENT );
  213. ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ORIENT_NORMAL_CMP, msg, normal_xpm );
  214. ADD_MENUITEM_WITH_SUBMENU( PopMenu, orientmenu, ID_POPUP_SCH_GENERIC_ORIENT_CMP,
  215. _( "Orient Component" ), orient_xpm );
  216. wxMenu* editmenu = new wxMenu;
  217. msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  218. ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, msg, edit_component_xpm );
  219. if( libComponent && libComponent->IsNormal() )
  220. {
  221. msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_VALUE );
  222. ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg, edit_comp_value_xpm );
  223. ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_REF_CMP, _( "Reference" ), edit_comp_ref_xpm );
  224. msg = AddHotkeyName( _( "Footprint " ), s_Schematic_Hokeys_Descr,
  225. HK_EDIT_COMPONENT_FOOTPRINT );
  226. ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_FOOTPRINT_CMP, msg, edit_comp_footprint_xpm );
  227. }
  228. if( libComponent && libComponent->HasConversion() )
  229. ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP, _( "Convert" ),
  230. component_select_alternate_shape_xpm );
  231. if( libComponent && ( libComponent->GetPartCount() >= 2 ) )
  232. {
  233. wxMenu* sel_unit_menu = new wxMenu; int ii;
  234. for( ii = 0; ii < libComponent->GetPartCount(); ii++ )
  235. {
  236. wxString num_unit;
  237. int unit = Component->GetUnit();
  238. num_unit.Printf( _( "Unit %d %c" ), ii + 1,
  239. "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ ii + 1 ] );
  240. wxMenuItem * item = sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii,
  241. num_unit, wxEmptyString,
  242. wxITEM_CHECK );
  243. if( unit == ii + 1 )
  244. item->Check(true);
  245. }
  246. ADD_MENUITEM_WITH_SUBMENU( editmenu, sel_unit_menu, ID_POPUP_SCH_SELECT_UNIT_CMP,
  247. _( "Unit" ), component_select_unit_xpm );
  248. }
  249. if( !Component->GetFlags() )
  250. {
  251. ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Library Editor" ),
  252. libedit_xpm );
  253. }
  254. ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP,
  255. _( "Edit Component" ), edit_component_xpm );
  256. if( !Component->GetFlags() )
  257. {
  258. msg = AddHotkeyName( _( "Copy Component" ), s_Schematic_Hokeys_Descr,
  259. HK_COPY_COMPONENT_OR_LABEL );
  260. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
  261. msg = AddHotkeyName( _( "Delete Component" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  262. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP, msg, delete_xpm );
  263. }
  264. if( libEntry && !libEntry->GetDocFileName().IsEmpty() )
  265. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), datasheet_xpm );
  266. }
  267. void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
  268. {
  269. wxMenu* menu_change_type = new wxMenu;
  270. wxString msg;
  271. if( !GLabel->GetFlags() )
  272. {
  273. msg = AddHotkeyName( _( "Move Global Label" ), s_Schematic_Hokeys_Descr,
  274. HK_MOVE_COMPONENT_OR_ITEM );
  275. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_text_xpm );
  276. msg = AddHotkeyName( _( "Drag Global Label" ), s_Schematic_Hokeys_Descr,
  277. HK_DRAG );
  278. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_text_xpm );
  279. msg = AddHotkeyName( _( "Copy Global Label" ), s_Schematic_Hokeys_Descr,
  280. HK_COPY_COMPONENT_OR_LABEL );
  281. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
  282. }
  283. msg = AddHotkeyName( _( "Rotate Global Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  284. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, msg, rotate_glabel_xpm );
  285. msg = AddHotkeyName( _( "Edit Global Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  286. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, msg, edit_text_xpm );
  287. msg = AddHotkeyName( _( "Delete Global Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  288. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_text_xpm );
  289. // add menu change type text (to label, glabel, text):
  290. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  291. _( "Change to Hierarchical Label" ), label2glabel_xpm );
  292. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  293. _( "Change to Label" ), glabel2label_xpm );
  294. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  295. _( "Change to Text" ), glabel2text_xpm );
  296. ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  297. _( "Change Type" ), gl_change_xpm );
  298. }
  299. void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
  300. {
  301. wxMenu* menu_change_type = new wxMenu;
  302. wxString msg;
  303. if( !HLabel->GetFlags() )
  304. {
  305. msg = AddHotkeyName( _( "Move Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  306. HK_MOVE_COMPONENT_OR_ITEM );
  307. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_text_xpm );
  308. msg = AddHotkeyName( _( "Drag Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  309. HK_DRAG );
  310. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_text_xpm );
  311. msg = AddHotkeyName( _( "Copy Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  312. HK_COPY_COMPONENT_OR_LABEL );
  313. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
  314. }
  315. msg = AddHotkeyName( _( "Rotate Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  316. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, msg, rotate_glabel_xpm );
  317. msg = AddHotkeyName( _( "Edit Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  318. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, msg, edit_text_xpm );
  319. msg = AddHotkeyName( _( "Delete Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  320. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_text_xpm );
  321. // add menu change type text (to label, glabel, text):
  322. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  323. _( "Change to Label" ), glabel2label_xpm );
  324. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  325. _( "Change to Text" ), glabel2text_xpm );
  326. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  327. _( "Change to Global Label" ), label2glabel_xpm );
  328. ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  329. _( "Change Type" ), gl_change_xpm );
  330. }
  331. void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
  332. {
  333. wxMenu* menu_change_type = new wxMenu;
  334. wxString msg;
  335. if( !Label->GetFlags() )
  336. {
  337. msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
  338. HK_MOVE_COMPONENT_OR_ITEM );
  339. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_text_xpm );
  340. msg = AddHotkeyName( _( "Drag Label" ), s_Schematic_Hokeys_Descr,
  341. HK_DRAG );
  342. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_text_xpm );
  343. msg = AddHotkeyName( _( "Copy Label" ), s_Schematic_Hokeys_Descr,
  344. HK_COPY_COMPONENT_OR_LABEL );
  345. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
  346. }
  347. msg = AddHotkeyName( _( "Rotate Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  348. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, msg, rotate_CCW_xpm );
  349. msg = AddHotkeyName( _( "Edit Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  350. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, msg, edit_text_xpm );
  351. msg = AddHotkeyName( _( "Delete Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  352. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_text_xpm );
  353. // add menu change type text (to label, glabel, text):
  354. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  355. _( "Change to Hierarchical Label" ), label2glabel_xpm );
  356. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  357. _( "Change to Text" ), label2text_xpm );
  358. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  359. _( "Change to Global Label" ), label2glabel_xpm );
  360. ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  361. _( "Change Type" ), gl_change_xpm );
  362. }
  363. void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
  364. {
  365. wxString msg;
  366. wxMenu* menu_change_type = new wxMenu;
  367. if( !Text->GetFlags() )
  368. {
  369. msg = AddHotkeyName( _( "Move Text" ), s_Schematic_Hokeys_Descr,
  370. HK_MOVE_COMPONENT_OR_ITEM );
  371. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_text_xpm );
  372. msg = AddHotkeyName( _( "Copy Text" ), s_Schematic_Hokeys_Descr,
  373. HK_COPY_COMPONENT_OR_LABEL );
  374. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, copy_button );
  375. }
  376. msg = AddHotkeyName( _( "Rotate Text" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  377. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, msg, rotate_CCW_xpm );
  378. msg = AddHotkeyName( _( "Edit Text" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  379. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, msg, edit_text_xpm );
  380. msg = AddHotkeyName( _( "Delete Text" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  381. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_text_xpm );
  382. /* add menu change type text (to label, glabel, text),
  383. * but only if this is a single line text
  384. */
  385. if( Text->m_Text.Find( wxT( "\n" ) ) == wxNOT_FOUND )
  386. {
  387. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  388. _( "Change to Label" ), label2text_xpm );
  389. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  390. _( "Change to Hierarchical Label" ), label2glabel_xpm );
  391. ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  392. _( "Change to Global Label" ), label2glabel_xpm );
  393. ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  394. _( "Change Type" ), gl_change_xpm );
  395. }
  396. }
  397. void SCH_EDIT_FRAME::addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction )
  398. {
  399. wxString msg;
  400. SCH_SCREEN* screen = GetScreen();
  401. msg = AddHotkeyName( _( "Delete Junction" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  402. ADD_MENUITEM( aMenu, ID_POPUP_SCH_DELETE, msg, delete_xpm );
  403. if( !aJunction->IsNew() )
  404. {
  405. if( m_collectedItems.IsDraggableJunction() )
  406. ADD_MENUITEM( aMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, _( "Drag Junction" ), move_xpm );
  407. if( screen->GetWire( aJunction->m_Pos, EXCLUDE_END_POINTS_T ) )
  408. ADD_MENUITEM( aMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
  409. }
  410. if( screen->GetWireOrBus( aJunction->m_Pos ) )
  411. {
  412. ADD_MENUITEM( aMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm );
  413. ADD_MENUITEM( aMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
  414. delete_connection_xpm );
  415. }
  416. }
  417. void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
  418. {
  419. bool is_new = Wire->IsNew();
  420. SCH_SCREEN* screen = frame->GetScreen();
  421. wxPoint pos = screen->GetCrossHairPosition();
  422. wxString msg;
  423. if( is_new )
  424. {
  425. ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "Wire End" ), apply_xpm );
  426. return;
  427. }
  428. msg = AddHotkeyName( _( "Drag Wire" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  429. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, msg, move_track_xpm );
  430. PopMenu->AppendSeparator();
  431. msg = AddHotkeyName( _( "Delete Wire" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  432. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_xpm );
  433. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm );
  434. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
  435. delete_connection_xpm );
  436. SCH_LINE* line = screen->GetWireOrBus( screen->GetCrossHairPosition() );
  437. if( line && !line->IsEndPoint( screen->GetCrossHairPosition() ) )
  438. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
  439. PopMenu->AppendSeparator();
  440. msg = AddHotkeyName( _( "Add Junction" ), s_Schematic_Hokeys_Descr, HK_ADD_JUNCTION );
  441. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, msg, add_junction_xpm );
  442. msg = AddHotkeyName( _( "Add Label" ), s_Schematic_Hokeys_Descr, HK_ADD_LABEL );
  443. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, msg, add_line_label_xpm );
  444. // Add global label command only if the cursor is over one end of the wire.
  445. if( ( pos == Wire->m_Start ) || ( pos == Wire->m_End ) )
  446. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ), add_glabel_xpm );
  447. }
  448. void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame )
  449. {
  450. bool is_new = Bus->IsNew();
  451. wxPoint pos = frame->GetScreen()->GetCrossHairPosition();
  452. wxString msg;
  453. if( is_new )
  454. {
  455. ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "Bus End" ), apply_xpm );
  456. return;
  457. }
  458. msg = AddHotkeyName( _( "Delete Bus" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  459. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_bus_xpm );
  460. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Bus" ), break_bus_xpm );
  461. PopMenu->AppendSeparator();
  462. msg = AddHotkeyName( _( "Add Junction" ), s_Schematic_Hokeys_Descr, HK_ADD_JUNCTION );
  463. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, msg, add_junction_xpm );
  464. msg = AddHotkeyName( _( "Add Label" ), s_Schematic_Hokeys_Descr, HK_ADD_LABEL );
  465. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, msg, add_line_label_xpm );
  466. // Add global label command only if the cursor is over one end of the bus.
  467. if( ( pos == Bus->m_Start ) || ( pos == Bus->m_End ) )
  468. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ), add_glabel_xpm );
  469. }
  470. void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
  471. {
  472. wxString msg;
  473. if( !Sheet->GetFlags() )
  474. {
  475. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ), enter_sheet_xpm );
  476. PopMenu->AppendSeparator();
  477. msg = AddHotkeyName( _( "Move Sheet" ), s_Schematic_Hokeys_Descr,
  478. HK_MOVE_COMPONENT_OR_ITEM );
  479. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, move_sheet_xpm );
  480. msg = AddHotkeyName( _( "Drag Sheet" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  481. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_sheet_xpm );
  482. }
  483. if( Sheet->GetFlags() )
  484. {
  485. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), apply_xpm );
  486. }
  487. else
  488. {
  489. msg = AddHotkeyName( _( "Edit Sheet" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  490. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET, msg, edit_sheet_xpm );
  491. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_RESIZE_SHEET, _( "Resize Sheet" ),
  492. resize_sheet_xpm );
  493. PopMenu->AppendSeparator();
  494. ADD_MENUITEM( PopMenu, ID_POPUP_IMPORT_GLABEL, _( "Import Sheet Pins" ),
  495. import_hierarchical_label_xpm );
  496. if( Sheet->HasUndefinedPins() ) // Sheet has pin labels, and can be cleaned
  497. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup Sheet Pins" ),
  498. options_pinsheet_xpm );
  499. PopMenu->AppendSeparator();
  500. msg = AddHotkeyName( _( "Delete Sheet" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  501. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_sheet_xpm );
  502. }
  503. }
  504. void AddMenusForSheetPin( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
  505. {
  506. wxString msg;
  507. if( !PinSheet->GetFlags() )
  508. {
  509. msg = AddHotkeyName( _( "Move Sheet Pin" ), s_Schematic_Hokeys_Descr,
  510. HK_MOVE_COMPONENT_OR_ITEM );
  511. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_SHEET_PIN, msg, move_xpm );
  512. }
  513. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET_PIN, _( "Edit Sheet Pin" ), edit_xpm );
  514. if( !PinSheet->GetFlags() )
  515. ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Sheet Pin" ), delete_pinsheet_xpm );
  516. }
  517. void AddMenusForBlock( wxMenu* PopMenu, SCH_EDIT_FRAME* frame )
  518. {
  519. wxString msg;
  520. ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ), cancel_xpm );
  521. PopMenu->AppendSeparator();
  522. if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
  523. ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK, _( "Window Zoom" ),
  524. zoom_area_xpm );
  525. ADD_MENUITEM( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), apply_xpm );
  526. // After a block move (that is also a block selection) one can reselect
  527. // a block function.
  528. if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
  529. {
  530. ADD_MENUITEM( PopMenu, wxID_COPY, _( "Save Block" ), copy_button );
  531. ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), copyblock_xpm );
  532. msg = AddHotkeyName( _( "Drag Block" ), s_Schematic_Hokeys_Descr,
  533. HK_MOVEBLOCK_TO_DRAGBLOCK );
  534. ADD_MENUITEM( PopMenu, ID_POPUP_DRAG_BLOCK, msg, move_xpm );
  535. ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), delete_xpm );
  536. ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, _( "Mirror Block ||" ), mirror_H_xpm );
  537. ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_X_BLOCK, _( "Mirror Block --" ), mirror_V_xpm );
  538. ADD_MENUITEM( PopMenu, ID_POPUP_ROTATE_BLOCK, _( "Rotate Block ccw" ), rotate_CCW_xpm );
  539. #if 0
  540. #ifdef __WINDOWS__
  541. ADD_MENUITEM( menu_other_block_commands, ID_GEN_COPY_BLOCK_TO_CLIPBOARD,
  542. _( "Copy to Clipboard" ), copy_button );
  543. #endif
  544. #endif
  545. }
  546. }
  547. void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame )
  548. {
  549. ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_DELETE, _( "Delete Marker" ), delete_xpm );
  550. ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_GETINFO_MARKER, _( "Marker Error Info" ), info_xpm );
  551. }