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.

185 lines
6.1 KiB

16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.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. #include <fctsys.h>
  26. #include <eeschema_id.h>
  27. #include <sch_draw_panel.h>
  28. #include <sch_edit_frame.h>
  29. #include <menus_helpers.h>
  30. #include <advanced_config.h>
  31. #include <class_library.h>
  32. #include <connection_graph.h>
  33. #include <general.h>
  34. #include <hotkeys.h>
  35. #include <sch_bus_entry.h>
  36. #include <sch_junction.h>
  37. #include <sch_component.h>
  38. #include <sch_line.h>
  39. #include <sch_sheet.h>
  40. #include <sch_sheet_path.h>
  41. #include <symbol_lib_table.h>
  42. #include <sch_view.h>
  43. #include <tool/tool_manager.h>
  44. #include <tools/sch_actions.h>
  45. #include <tools/sch_selection_tool.h>
  46. static void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame );
  47. static void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet );
  48. static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component,
  49. SYMBOL_LIB_TABLE* aLibs );
  50. bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
  51. {
  52. SCH_ITEM* item = GetScreen()->GetCurItem();
  53. wxString msg;
  54. // If a command is in progress: add "cancel" and "end tool" menu
  55. if( GetToolId() != ID_NO_TOOL_SELECTED )
  56. {
  57. switch( GetToolId() )
  58. {
  59. case ID_BUS_BUTT:
  60. AddMenusForBus( PopMenu, NULL, this );
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. switch( item->Type() )
  67. {
  68. case SCH_COMPONENT_T:
  69. AddMenusForComponent( PopMenu, (SCH_COMPONENT*) item, Prj().SchSymbolLibTable() );
  70. break;
  71. case SCH_LINE_T:
  72. switch( item->GetLayer() )
  73. {
  74. case LAYER_BUS:
  75. AddMenusForBus( PopMenu, (SCH_LINE*) item, this );
  76. break;
  77. }
  78. break;
  79. case SCH_SHEET_T:
  80. AddMenusForHierchicalSheet( PopMenu, (SCH_SHEET*) item );
  81. break;
  82. }
  83. return true;
  84. }
  85. void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, SYMBOL_LIB_TABLE* aLibs )
  86. {
  87. wxString msg;
  88. LIB_PART* part = NULL;
  89. LIB_ALIAS* alias = NULL;
  90. try
  91. {
  92. alias = aLibs->LoadSymbol( Component->GetLibId() );
  93. }
  94. catch( ... )
  95. {
  96. }
  97. if( alias )
  98. part = alias->GetPart();
  99. wxMenu* editmenu = new wxMenu;
  100. if( part && part->HasConversion() )
  101. AddMenuItem( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP, _( "Convert" ),
  102. KiBitmap( component_select_alternate_shape_xpm ) );
  103. if( part && part->GetUnitCount() >= 2 )
  104. {
  105. wxMenu* sel_unit_menu = new wxMenu; int ii;
  106. for( ii = 0; ii < part->GetUnitCount(); ii++ )
  107. {
  108. wxString num_unit;
  109. int unit = Component->GetUnit();
  110. num_unit.Printf( _( "Unit %s" ), GetChars( LIB_PART::SubReference( ii + 1, false ) ) );
  111. wxMenuItem * item = sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii,
  112. num_unit, wxEmptyString,
  113. wxITEM_CHECK );
  114. if( unit == ii + 1 )
  115. item->Check(true);
  116. // The ID max for these submenus is ID_POPUP_SCH_SELECT_UNIT_CMP_MAX
  117. // See eeschema_id to modify this value.
  118. if( ii >= (ID_POPUP_SCH_SELECT_UNIT_CMP_MAX - ID_POPUP_SCH_SELECT_UNIT1) )
  119. break; // We have used all IDs for these submenus
  120. }
  121. AddMenuItem( editmenu, sel_unit_menu, ID_POPUP_SCH_SELECT_UNIT_CMP,
  122. _( "Unit" ), KiBitmap( component_select_unit_xpm ) );
  123. }
  124. }
  125. void AddMenusForBus( wxMenu* PopMenu, SCH_LINE* Bus, SCH_EDIT_FRAME* frame )
  126. {
  127. SCH_SELECTION_TOOL* selTool = frame->GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
  128. wxPoint pos = frame->GetCrossHairPosition();
  129. wxString msg;
  130. // TODO(JE) remove once real-time is enabled
  131. if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
  132. {
  133. frame->RecalculateConnections();
  134. // Have to pick up the pointer again because it may have been changed by SchematicCleanUp
  135. bool actionCancelled = false;
  136. Bus = dynamic_cast<SCH_LINE*>( selTool->SelectPoint( pos, SCH_COLLECTOR::AllItemsButPins,
  137. &actionCancelled ) );
  138. wxASSERT( Bus );
  139. }
  140. // Bus unfolding menu (only available if bus is properly defined)
  141. wxMenu* bus_unfold_menu = frame->GetUnfoldBusMenu( Bus );
  142. if( bus_unfold_menu )
  143. PopMenu->AppendSubMenu( bus_unfold_menu, _( "Unfold Bus" ) );
  144. }
  145. void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
  146. {
  147. AddMenuItem( PopMenu, ID_POPUP_IMPORT_HLABEL_TO_SHEETPIN, _( "Import Sheet Pins" ),
  148. KiBitmap( import_hierarchical_label_xpm ) );
  149. if( Sheet->HasUndefinedPins() ) // Sheet has pin labels, and can be cleaned
  150. AddMenuItem( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup Sheet Pins" ),
  151. KiBitmap( options_pinsheet_xpm ) );
  152. }