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.

800 lines
32 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
17 years ago
17 years ago
16 years ago
16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file eeschema/onrightclick.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <eeschema_id.h>
  30. #include <class_drawpanel.h>
  31. #include <confirm.h>
  32. #include <wxEeschemaStruct.h>
  33. #include <menus_helpers.h>
  34. #include <general.h>
  35. #include <hotkeys.h>
  36. #include <class_library.h>
  37. #include <sch_bus_entry.h>
  38. #include <sch_marker.h>
  39. #include <sch_text.h>
  40. #include <sch_junction.h>
  41. #include <sch_component.h>
  42. #include <sch_line.h>
  43. #include <sch_no_connect.h>
  44. #include <sch_sheet.h>
  45. #include <sch_sheet_path.h>
  46. #include <sch_bitmap.h>
  47. #include <iostream>
  48. static void AddMenusForBlock( wxMenu* PopMenu, SCH_EDIT_FRAME* frame );
  49. static void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame );
  50. static void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame );
  51. static void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet );
  52. static void AddMenusForSheetPin( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet );
  53. static void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text );
  54. static void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label );
  55. static void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel );
  56. static void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* GLabel );
  57. static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
  58. static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field );
  59. static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame );
  60. static void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap );
  61. static void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry );
  62. /* Prepare context menu when a click on the right mouse button occurs.
  63. *
  64. * This menu is then added to the list of zoom commands.
  65. */
  66. bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
  67. {
  68. SCH_ITEM* item = GetScreen()->GetCurItem();
  69. bool BlockActive = GetScreen()->IsBlockActive();
  70. // Do not start a block command on context menu.
  71. m_canvas->SetCanStartBlock( -1 );
  72. if( BlockActive )
  73. {
  74. AddMenusForBlock( PopMenu, this );
  75. PopMenu->AppendSeparator();
  76. return true;
  77. }
  78. // Try to locate items at cursor position.
  79. if( (item == NULL) || (item->GetFlags() == 0) )
  80. {
  81. item = LocateAndShowItem( aPosition, SCH_COLLECTOR::AllItemsButPins );
  82. // If the clarify item selection context menu is aborted, don't show the context menu.
  83. if( item == NULL && m_canvas->GetAbortRequest() )
  84. {
  85. m_canvas->SetAbortRequest( false );
  86. return false;
  87. }
  88. }
  89. // If a command is in progress: add "cancel" and "end tool" menu
  90. // If
  91. if( GetToolId() != ID_NO_TOOL_SELECTED )
  92. {
  93. if( item && item->GetFlags() )
  94. {
  95. AddMenuItem( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ),
  96. KiBitmap( cancel_xpm ) );
  97. }
  98. else
  99. {
  100. AddMenuItem( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "End Tool" ),
  101. KiBitmap( cursor_xpm ) );
  102. }
  103. PopMenu->AppendSeparator();
  104. switch( GetToolId() )
  105. {
  106. case ID_WIRE_BUTT:
  107. AddMenusForWire( PopMenu, NULL, this );
  108. if( item == NULL )
  109. PopMenu->AppendSeparator();
  110. break;
  111. case ID_BUS_BUTT:
  112. AddMenusForBus( PopMenu, NULL, this );
  113. if( item == NULL )
  114. PopMenu->AppendSeparator();
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. else
  121. {
  122. if( item && item->GetFlags() )
  123. {
  124. AddMenuItem( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ),
  125. KiBitmap( cancel_xpm ) );
  126. PopMenu->AppendSeparator();
  127. }
  128. }
  129. if( item == NULL )
  130. {
  131. if( m_CurrentSheet->Last() != g_RootSheet )
  132. {
  133. AddMenuItem( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, _( "Leave Sheet" ),
  134. KiBitmap( leave_sheet_xpm ) );
  135. PopMenu->AppendSeparator();
  136. }
  137. return true;
  138. }
  139. int flags = item->GetFlags();
  140. bool is_new = (flags & IS_NEW) ? true : false;
  141. switch( item->Type() )
  142. {
  143. case SCH_NO_CONNECT_T:
  144. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete No Connect" ),
  145. KiBitmap( delete_xpm ) );
  146. break;
  147. case SCH_JUNCTION_T:
  148. addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
  149. break;
  150. case SCH_BUS_ENTRY_T:
  151. AddMenusForBusEntry( PopMenu, (SCH_BUS_ENTRY*) item );
  152. break;
  153. case SCH_MARKER_T:
  154. AddMenusForMarkers( PopMenu, (SCH_MARKER*) item, this );
  155. break;
  156. case SCH_TEXT_T:
  157. AddMenusForText( PopMenu, (SCH_TEXT*) item );
  158. break;
  159. case SCH_LABEL_T:
  160. AddMenusForLabel( PopMenu, (SCH_LABEL*) item );
  161. break;
  162. case SCH_GLOBAL_LABEL_T:
  163. AddMenusForGLabel( PopMenu, (SCH_GLOBALLABEL*) item );
  164. break;
  165. case SCH_HIERARCHICAL_LABEL_T:
  166. AddMenusForHLabel( PopMenu, (SCH_HIERLABEL*) item );
  167. break;
  168. case SCH_FIELD_T:
  169. AddMenusForComponentField( PopMenu, (SCH_FIELD*) item );
  170. break;
  171. case SCH_COMPONENT_T:
  172. AddMenusForComponent( PopMenu, (SCH_COMPONENT*) item );
  173. break;
  174. case SCH_BITMAP_T:
  175. AddMenusForBitmap( PopMenu, (SCH_BITMAP*) item );
  176. break;
  177. case SCH_LINE_T:
  178. switch( item->GetLayer() )
  179. {
  180. case LAYER_WIRE:
  181. AddMenusForWire( PopMenu, (SCH_LINE*) item, this );
  182. break;
  183. case LAYER_BUS:
  184. AddMenusForBus( PopMenu, (SCH_LINE*) item, this );
  185. break;
  186. default:
  187. if( is_new )
  188. AddMenuItem( PopMenu, ID_POPUP_END_LINE, _( "End Drawing" ),
  189. KiBitmap( apply_xpm ) );
  190. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Drawing" ),
  191. KiBitmap( delete_xpm ) );
  192. break;
  193. }
  194. break;
  195. case SCH_SHEET_T:
  196. AddMenusForHierchicalSheet( PopMenu, (SCH_SHEET*) item );
  197. break;
  198. case SCH_SHEET_PIN_T:
  199. AddMenusForSheetPin( PopMenu, (SCH_SHEET_PIN*) item );
  200. break;
  201. default:
  202. wxFAIL_MSG( wxString::Format( wxT( "Cannot create context menu for unknown type %d" ),
  203. item->Type() ) );
  204. break;
  205. }
  206. PopMenu->AppendSeparator();
  207. return true;
  208. }
  209. void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field )
  210. {
  211. wxString msg;
  212. if( !Field->GetFlags() )
  213. {
  214. msg = AddHotkeyName( _( "Move Field" ), s_Schematic_Hokeys_Descr,
  215. HK_MOVE_COMPONENT_OR_ITEM );
  216. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
  217. }
  218. msg = AddHotkeyName( _( "Rotate Field" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  219. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_field_xpm ) );
  220. msg = AddHotkeyName( _( "Edit Field" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  221. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  222. }
  223. void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
  224. {
  225. if( Component->Type() != SCH_COMPONENT_T )
  226. {
  227. wxASSERT( 0 );
  228. return;
  229. }
  230. wxString msg;
  231. LIB_ALIAS* libEntry;
  232. LIB_COMPONENT* libComponent = NULL;
  233. libEntry = CMP_LIBRARY::FindLibraryEntry( Component->GetLibName() );
  234. if( libEntry )
  235. libComponent = libEntry->GetComponent();
  236. if( !Component->GetFlags() )
  237. {
  238. msg = _( "Move Component" );
  239. msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text;
  240. msg = AddHotkeyName( msg, s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT_OR_ITEM );
  241. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_xpm ) );
  242. msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  243. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_xpm ) );
  244. }
  245. wxMenu* orientmenu = new wxMenu;
  246. msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  247. AddMenuItem( orientmenu, ID_SCH_ROTATE_COUNTERCLOCKWISE, msg,
  248. KiBitmap( rotate_ccw_xpm ) );
  249. AddMenuItem( orientmenu, ID_SCH_ROTATE_CLOCKWISE, _( "Rotate -" ),
  250. KiBitmap( rotate_cw_xpm ) );
  251. msg = AddHotkeyName( _( "Mirror --" ), s_Schematic_Hokeys_Descr, HK_MIRROR_X_COMPONENT );
  252. AddMenuItem( orientmenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) );
  253. msg = AddHotkeyName( _( "Mirror ||" ), s_Schematic_Hokeys_Descr, HK_MIRROR_Y_COMPONENT );
  254. AddMenuItem( orientmenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) );
  255. msg = AddHotkeyName( _( "Normal" ), s_Schematic_Hokeys_Descr, HK_ORIENT_NORMAL_COMPONENT );
  256. AddMenuItem( orientmenu, ID_SCH_ORIENT_NORMAL, msg, KiBitmap( normal_xpm ) );
  257. AddMenuItem( PopMenu, orientmenu, ID_POPUP_SCH_GENERIC_ORIENT_CMP,
  258. _( "Orient Component" ), KiBitmap( orient_xpm ) );
  259. wxMenu* editmenu = new wxMenu;
  260. msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  261. AddMenuItem( editmenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_component_xpm ) );
  262. if( libComponent && libComponent->IsNormal() )
  263. {
  264. msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_VALUE );
  265. AddMenuItem( editmenu, ID_SCH_EDIT_COMPONENT_VALUE, msg, KiBitmap( edit_comp_value_xpm ) );
  266. AddMenuItem( editmenu, ID_SCH_EDIT_COMPONENT_REFERENCE, _( "Reference" ),
  267. KiBitmap( edit_comp_ref_xpm ) );
  268. msg = AddHotkeyName( _( "Footprint " ), s_Schematic_Hokeys_Descr,
  269. HK_EDIT_COMPONENT_FOOTPRINT );
  270. AddMenuItem( editmenu, ID_SCH_EDIT_COMPONENT_FOOTPRINT, msg,
  271. KiBitmap( edit_comp_footprint_xpm ) );
  272. }
  273. if( libComponent && libComponent->HasConversion() )
  274. AddMenuItem( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP, _( "Convert" ),
  275. KiBitmap( component_select_alternate_shape_xpm ) );
  276. if( libComponent && ( libComponent->GetPartCount() >= 2 ) )
  277. {
  278. wxMenu* sel_unit_menu = new wxMenu; int ii;
  279. for( ii = 0; ii < libComponent->GetPartCount(); ii++ )
  280. {
  281. wxString num_unit;
  282. int unit = Component->GetUnit();
  283. num_unit.Printf( _( "Unit %d %c" ), ii + 1,
  284. "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ ii + 1 ] );
  285. wxMenuItem * item = sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii,
  286. num_unit, wxEmptyString,
  287. wxITEM_CHECK );
  288. if( unit == ii + 1 )
  289. item->Check(true);
  290. }
  291. AddMenuItem( editmenu, sel_unit_menu, ID_POPUP_SCH_SELECT_UNIT_CMP,
  292. _( "Unit" ), KiBitmap( component_select_unit_xpm ) );
  293. }
  294. if( !Component->GetFlags() )
  295. {
  296. AddMenuItem( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP,
  297. _( "Edit with Library Editor" ),
  298. KiBitmap( libedit_xpm ) );
  299. }
  300. AddMenuItem( PopMenu, editmenu, ID_SCH_EDIT_ITEM,
  301. _( "Edit Component" ), KiBitmap( edit_component_xpm ) );
  302. if( !Component->GetFlags() )
  303. {
  304. msg = AddHotkeyName( _( "Copy Component" ), s_Schematic_Hokeys_Descr,
  305. HK_COPY_COMPONENT_OR_LABEL );
  306. AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
  307. msg = AddHotkeyName( _( "Delete Component" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  308. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE_CMP, msg, KiBitmap( delete_xpm ) );
  309. }
  310. if( libEntry && !libEntry->GetDocFileName().IsEmpty() )
  311. AddMenuItem( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), KiBitmap( datasheet_xpm ) );
  312. }
  313. void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
  314. {
  315. wxMenu* menu_change_type = new wxMenu;
  316. wxString msg;
  317. if( !GLabel->GetFlags() )
  318. {
  319. msg = AddHotkeyName( _( "Move Global Label" ), s_Schematic_Hokeys_Descr,
  320. HK_MOVE_COMPONENT_OR_ITEM );
  321. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
  322. msg = AddHotkeyName( _( "Drag Global Label" ), s_Schematic_Hokeys_Descr,
  323. HK_DRAG );
  324. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
  325. msg = AddHotkeyName( _( "Copy Global Label" ), s_Schematic_Hokeys_Descr,
  326. HK_COPY_COMPONENT_OR_LABEL );
  327. AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
  328. }
  329. msg = AddHotkeyName( _( "Rotate Global Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  330. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_glabel_xpm ) );
  331. msg = AddHotkeyName( _( "Edit Global Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  332. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  333. msg = AddHotkeyName( _( "Delete Global Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  334. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_text_xpm ) );
  335. // add menu change type text (to label, glabel, text):
  336. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  337. _( "Change to Hierarchical Label" ), KiBitmap( label2glabel_xpm ) );
  338. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  339. _( "Change to Label" ), KiBitmap( glabel2label_xpm ) );
  340. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  341. _( "Change to Text" ), KiBitmap( glabel2text_xpm ) );
  342. AddMenuItem( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  343. _( "Change Type" ), KiBitmap( gl_change_xpm ) );
  344. }
  345. void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
  346. {
  347. wxMenu* menu_change_type = new wxMenu;
  348. wxString msg;
  349. if( !HLabel->GetFlags() )
  350. {
  351. msg = AddHotkeyName( _( "Move Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  352. HK_MOVE_COMPONENT_OR_ITEM );
  353. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
  354. msg = AddHotkeyName( _( "Drag Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  355. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
  356. msg = AddHotkeyName( _( "Copy Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  357. HK_COPY_COMPONENT_OR_LABEL );
  358. AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
  359. }
  360. msg = AddHotkeyName( _( "Rotate Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  361. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_glabel_xpm ) );
  362. msg = AddHotkeyName( _( "Edit Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  363. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  364. msg = AddHotkeyName( _( "Delete Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  365. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_text_xpm ) );
  366. // add menu change type text (to label, glabel, text):
  367. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  368. _( "Change to Label" ), KiBitmap( glabel2label_xpm ) );
  369. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  370. _( "Change to Text" ), KiBitmap( glabel2text_xpm ) );
  371. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  372. _( "Change to Global Label" ), KiBitmap( label2glabel_xpm ) );
  373. AddMenuItem( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  374. _( "Change Type" ), KiBitmap( gl_change_xpm ) );
  375. }
  376. void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
  377. {
  378. wxMenu* menu_change_type = new wxMenu;
  379. wxString msg;
  380. if( !Label->GetFlags() )
  381. {
  382. msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
  383. HK_MOVE_COMPONENT_OR_ITEM );
  384. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
  385. msg = AddHotkeyName( _( "Drag Label" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  386. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
  387. msg = AddHotkeyName( _( "Copy Label" ), s_Schematic_Hokeys_Descr,
  388. HK_COPY_COMPONENT_OR_LABEL );
  389. AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
  390. }
  391. msg = AddHotkeyName( _( "Rotate Label" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  392. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_ccw_xpm ) );
  393. msg = AddHotkeyName( _( "Edit Label" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  394. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  395. msg = AddHotkeyName( _( "Delete Label" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  396. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_text_xpm ) );
  397. // add menu change type text (to label, glabel, text):
  398. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  399. _( "Change to Hierarchical Label" ), KiBitmap( label2glabel_xpm ) );
  400. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
  401. _( "Change to Text" ), KiBitmap( label2text_xpm ) );
  402. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  403. _( "Change to Global Label" ), KiBitmap( label2glabel_xpm ) );
  404. AddMenuItem( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  405. _( "Change Type" ), KiBitmap( gl_change_xpm ) );
  406. }
  407. void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
  408. {
  409. wxString msg;
  410. wxMenu* menu_change_type = new wxMenu;
  411. if( !Text->GetFlags() )
  412. {
  413. msg = AddHotkeyName( _( "Move Text" ), s_Schematic_Hokeys_Descr,
  414. HK_MOVE_COMPONENT_OR_ITEM );
  415. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
  416. msg = AddHotkeyName( _( "Copy Text" ), s_Schematic_Hokeys_Descr,
  417. HK_COPY_COMPONENT_OR_LABEL );
  418. AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
  419. }
  420. msg = AddHotkeyName( _( "Rotate Text" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  421. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_ccw_xpm ) );
  422. msg = AddHotkeyName( _( "Edit Text" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  423. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
  424. msg = AddHotkeyName( _( "Delete Text" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  425. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_text_xpm ) );
  426. /* add menu change type text (to label, glabel, text),
  427. * but only if this is a single line text
  428. */
  429. if( Text->m_Text.Find( wxT( "\n" ) ) == wxNOT_FOUND )
  430. {
  431. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
  432. _( "Change to Label" ), KiBitmap( label2text_xpm ) );
  433. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
  434. _( "Change to Hierarchical Label" ), KiBitmap( label2glabel_xpm ) );
  435. AddMenuItem( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
  436. _( "Change to Global Label" ), KiBitmap( label2glabel_xpm ) );
  437. AddMenuItem( PopMenu, menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT,
  438. _( "Change Type" ), KiBitmap( gl_change_xpm ) );
  439. }
  440. }
  441. void SCH_EDIT_FRAME::addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction )
  442. {
  443. wxString msg;
  444. SCH_SCREEN* screen = GetScreen();
  445. msg = AddHotkeyName( _( "Delete Junction" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  446. AddMenuItem( aMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_xpm ) );
  447. if( !aJunction->IsNew() )
  448. {
  449. if( m_collectedItems.IsDraggableJunction() )
  450. AddMenuItem( aMenu, ID_SCH_DRAG_ITEM, _( "Drag Junction" ), KiBitmap( move_xpm ) );
  451. if( screen->GetWire( aJunction->GetPosition(), EXCLUDE_END_POINTS_T ) )
  452. AddMenuItem( aMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ),
  453. KiBitmap( break_line_xpm ) );
  454. }
  455. if( screen->GetWireOrBus( aJunction->GetPosition() ) )
  456. {
  457. AddMenuItem( aMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ),
  458. KiBitmap( delete_node_xpm ) );
  459. AddMenuItem( aMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
  460. KiBitmap( delete_connection_xpm ) );
  461. }
  462. }
  463. void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
  464. {
  465. SCH_SCREEN* screen = frame->GetScreen();
  466. wxPoint pos = screen->GetCrossHairPosition();
  467. wxString msg;
  468. if( Wire == NULL )
  469. {
  470. msg = AddHotkeyName( _( "Begin Wire" ), s_Schematic_Hokeys_Descr, HK_BEGIN_WIRE );
  471. AddMenuItem( PopMenu, ID_POPUP_SCH_BEGIN_WIRE, msg, KiBitmap( add_line_xpm ) );
  472. return;
  473. }
  474. bool is_new = Wire->IsNew();
  475. if( is_new )
  476. {
  477. msg = AddHotkeyName( _( "Wire End" ), s_Schematic_Hokeys_Descr, HK_END_CURR_LINEWIREBUS );
  478. AddMenuItem( PopMenu, ID_POPUP_END_LINE, msg, KiBitmap( apply_xpm ) );
  479. return;
  480. }
  481. msg = AddHotkeyName( _( "Drag Wire" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  482. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_track_xpm ) );
  483. PopMenu->AppendSeparator();
  484. msg = AddHotkeyName( _( "Delete Wire" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  485. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_xpm ) );
  486. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ),
  487. KiBitmap( delete_node_xpm ) );
  488. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
  489. KiBitmap( delete_connection_xpm ) );
  490. SCH_LINE* line = screen->GetWireOrBus( screen->GetCrossHairPosition() );
  491. if( line && !line->IsEndPoint( screen->GetCrossHairPosition() ) )
  492. AddMenuItem( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ),
  493. KiBitmap( break_line_xpm ) );
  494. PopMenu->AppendSeparator();
  495. msg = AddHotkeyName( _( "Add Junction" ), s_Schematic_Hokeys_Descr, HK_ADD_JUNCTION );
  496. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, msg, KiBitmap( add_junction_xpm ) );
  497. msg = AddHotkeyName( _( "Add Label" ), s_Schematic_Hokeys_Descr, HK_ADD_LABEL );
  498. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_LABEL, msg, KiBitmap( add_line_label_xpm ) );
  499. // Add global label command only if the cursor is over one end of the wire.
  500. if( Wire->IsEndPoint( pos ) )
  501. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ),
  502. KiBitmap( add_glabel_xpm ) );
  503. }
  504. void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame )
  505. {
  506. wxPoint pos = frame->GetScreen()->GetCrossHairPosition();
  507. wxString msg;
  508. if( Bus == NULL )
  509. {
  510. msg = AddHotkeyName( _( "Begin Bus" ), s_Schematic_Hokeys_Descr, HK_BEGIN_BUS );
  511. AddMenuItem( PopMenu, ID_POPUP_SCH_BEGIN_BUS, msg, KiBitmap( add_bus_xpm ) );
  512. return;
  513. }
  514. bool is_new = Bus->IsNew();
  515. if( is_new )
  516. {
  517. msg = AddHotkeyName( _( "Bus End" ), s_Schematic_Hokeys_Descr, HK_END_CURR_LINEWIREBUS );
  518. AddMenuItem( PopMenu, ID_POPUP_END_LINE, msg, KiBitmap( apply_xpm ) );
  519. return;
  520. }
  521. msg = AddHotkeyName( _( "Delete Bus" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  522. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_bus_xpm ) );
  523. AddMenuItem( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Bus" ), KiBitmap( break_bus_xpm ) );
  524. PopMenu->AppendSeparator();
  525. msg = AddHotkeyName( _( "Add Junction" ), s_Schematic_Hokeys_Descr, HK_ADD_JUNCTION );
  526. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, msg, KiBitmap( add_junction_xpm ) );
  527. msg = AddHotkeyName( _( "Add Label" ), s_Schematic_Hokeys_Descr, HK_ADD_LABEL );
  528. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_LABEL, msg, KiBitmap( add_line_label_xpm ) );
  529. // Add global label command only if the cursor is over one end of the bus.
  530. if( Bus->IsEndPoint( pos ) )
  531. AddMenuItem( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ),
  532. KiBitmap( add_glabel_xpm ) );
  533. }
  534. void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
  535. {
  536. wxString msg;
  537. if( !Sheet->GetFlags() )
  538. {
  539. AddMenuItem( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ),
  540. KiBitmap( enter_sheet_xpm ) );
  541. PopMenu->AppendSeparator();
  542. msg = AddHotkeyName( _( "Move Sheet" ), s_Schematic_Hokeys_Descr,
  543. HK_MOVE_COMPONENT_OR_ITEM );
  544. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_sheet_xpm ) );
  545. msg = AddHotkeyName( _( "Drag Sheet" ), s_Schematic_Hokeys_Descr, HK_DRAG );
  546. AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_sheet_xpm ) );
  547. }
  548. if( Sheet->GetFlags() )
  549. {
  550. AddMenuItem( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), KiBitmap( apply_xpm ) );
  551. }
  552. else
  553. {
  554. msg = AddHotkeyName( _( "Edit Sheet" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  555. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( edit_sheet_xpm ) );
  556. AddMenuItem( PopMenu, ID_POPUP_SCH_RESIZE_SHEET, _( "Resize Sheet" ),
  557. KiBitmap( resize_sheet_xpm ) );
  558. PopMenu->AppendSeparator();
  559. AddMenuItem( PopMenu, ID_POPUP_IMPORT_GLABEL, _( "Import Sheet Pins" ),
  560. KiBitmap( import_hierarchical_label_xpm ) );
  561. if( Sheet->HasUndefinedPins() ) // Sheet has pin labels, and can be cleaned
  562. AddMenuItem( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup Sheet Pins" ),
  563. KiBitmap( options_pinsheet_xpm ) );
  564. PopMenu->AppendSeparator();
  565. msg = AddHotkeyName( _( "Delete Sheet" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  566. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_sheet_xpm ) );
  567. }
  568. }
  569. void AddMenusForSheetPin( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
  570. {
  571. wxString msg;
  572. if( !PinSheet->GetFlags() )
  573. {
  574. msg = AddHotkeyName( _( "Move Sheet Pin" ), s_Schematic_Hokeys_Descr,
  575. HK_MOVE_COMPONENT_OR_ITEM );
  576. AddMenuItem( PopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_xpm ) );
  577. }
  578. AddMenuItem( PopMenu, ID_SCH_EDIT_ITEM, _( "Edit Sheet Pin" ), KiBitmap( edit_xpm ) );
  579. if( !PinSheet->GetFlags() )
  580. AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Sheet Pin" ),
  581. KiBitmap( delete_pinsheet_xpm ) );
  582. }
  583. void AddMenusForBlock( wxMenu* PopMenu, SCH_EDIT_FRAME* frame )
  584. {
  585. wxString msg;
  586. AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ),
  587. KiBitmap( cancel_xpm ) );
  588. PopMenu->AppendSeparator();
  589. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  590. AddMenuItem( PopMenu, ID_POPUP_ZOOM_BLOCK, _( "Window Zoom" ), KiBitmap( zoom_area_xpm ) );
  591. AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( apply_xpm ) );
  592. // After a block move (that is also a block selection) one can reselect
  593. // a block function.
  594. if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
  595. {
  596. msg = AddHotkeyName( _( "Save Block" ), s_Schematic_Hokeys_Descr,
  597. HK_SAVE_BLOCK );
  598. AddMenuItem( PopMenu, wxID_COPY, msg, KiBitmap( copy_button_xpm ) );
  599. AddMenuItem( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), KiBitmap( copyblock_xpm ) );
  600. msg = AddHotkeyName( _( "Drag Block" ), s_Schematic_Hokeys_Descr,
  601. HK_MOVEBLOCK_TO_DRAGBLOCK );
  602. AddMenuItem( PopMenu, ID_POPUP_DRAG_BLOCK, msg, KiBitmap( move_xpm ) );
  603. AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
  604. msg = AddHotkeyName( _( "Mirror Block ||" ), s_Schematic_Hokeys_Descr,
  605. HK_MIRROR_Y_COMPONENT );
  606. AddMenuItem( PopMenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) );
  607. msg = AddHotkeyName( _( "Mirror Block --" ), s_Schematic_Hokeys_Descr,
  608. HK_MIRROR_X_COMPONENT );
  609. AddMenuItem( PopMenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) );
  610. AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, _( "Rotate Block ccw" ),
  611. KiBitmap( rotate_ccw_xpm ) );
  612. #if 0
  613. #ifdef __WINDOWS__
  614. AddMenuItem( menu_other_block_commands, ID_GEN_COPY_BLOCK_TO_CLIPBOARD,
  615. _( "Copy to Clipboard" ), KiBitmap( copy_button_xpm ) );
  616. #endif
  617. #endif
  618. }
  619. }
  620. void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame )
  621. {
  622. AddMenuItem( aPopMenu, ID_POPUP_SCH_DELETE, _( "Delete Marker" ), KiBitmap( delete_xpm ) );
  623. AddMenuItem( aPopMenu, ID_POPUP_SCH_GETINFO_MARKER, _( "Marker Error Info" ),
  624. KiBitmap( info_xpm ) );
  625. }
  626. void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap )
  627. {
  628. wxString msg;
  629. if( aBitmap->GetFlags() == 0 )
  630. {
  631. msg = AddHotkeyName( _( "Move Image" ), s_Schematic_Hokeys_Descr,
  632. HK_MOVE_COMPONENT_OR_ITEM );
  633. AddMenuItem( aPopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_xpm ) );
  634. }
  635. msg = AddHotkeyName( _( "Rotate Image" ), s_Schematic_Hokeys_Descr, HK_ROTATE );
  636. AddMenuItem( aPopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_ccw_xpm ) );
  637. AddMenuItem( aPopMenu, ID_SCH_MIRROR_X, _( "Mirror --" ), KiBitmap( mirror_v_xpm ) );
  638. AddMenuItem( aPopMenu, ID_SCH_MIRROR_Y, _( "Mirror ||" ), KiBitmap( mirror_h_xpm ) );
  639. if( aBitmap->GetFlags() == 0 )
  640. {
  641. msg = AddHotkeyName( _( "Edit Image" ), s_Schematic_Hokeys_Descr, HK_EDIT );
  642. AddMenuItem( aPopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( image_xpm ) );
  643. aPopMenu->AppendSeparator();
  644. msg = AddHotkeyName( _( "Delete Image" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  645. AddMenuItem( aPopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_xpm ) );
  646. }
  647. }
  648. void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry )
  649. {
  650. wxString msg;
  651. if( !aBusEntry->GetFlags() )
  652. {
  653. msg = AddHotkeyName( _( "Move Bus Entry" ), s_Schematic_Hokeys_Descr,
  654. HK_MOVE_COMPONENT_OR_ITEM );
  655. AddMenuItem( aPopMenu, ID_SCH_MOVE_ITEM, msg, KiBitmap( move_xpm ) );
  656. }
  657. if( aBusEntry->GetBusEntryShape() == '\\' )
  658. AddMenuItem( aPopMenu, ID_POPUP_SCH_ENTRY_SELECT_SLASH,
  659. _( "Set Bus Entry Shape /" ), KiBitmap( change_entry_orient_xpm ) );
  660. else
  661. AddMenuItem( aPopMenu, ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH,
  662. _( "Set Bus Entry Shape \\" ), KiBitmap( change_entry_orient_xpm ) );
  663. msg = AddHotkeyName( _( "Delete Bus Entry" ), s_Schematic_Hokeys_Descr, HK_DELETE );
  664. AddMenuItem( aPopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_xpm ) );
  665. }