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.

143 lines
5.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <fctsys.h>
  25. #include <class_drawpanel.h>
  26. #include <id.h>
  27. #include <gerbview_id.h>
  28. #include <gerbview.h>
  29. #include <gerbview_frame.h>
  30. #include <menus_helpers.h>
  31. /* Prepare the right-click pullup menu.
  32. * The menu already has a list of zoom commands.
  33. */
  34. bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
  35. {
  36. GERBER_DRAW_ITEM* currItem = (GERBER_DRAW_ITEM*) GetScreen()->GetCurItem();
  37. wxString msg;
  38. bool BlockActive = !GetScreen()->m_BlockLocate.IsIdle();
  39. bool busy = currItem && currItem->GetFlags();
  40. // Do not initiate a start block validation on menu.
  41. m_canvas->SetCanStartBlock( -1 );
  42. // Simple location of elements where possible.
  43. if( !busy )
  44. {
  45. currItem = Locate( aPosition, CURSEUR_OFF_GRILLE );
  46. busy = currItem && currItem->GetFlags();
  47. }
  48. // If command in progress, end command.
  49. if( GetToolId() != ID_NO_TOOL_SELECTED )
  50. {
  51. if( busy )
  52. AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
  53. _( "Cancel" ), KiBitmap( cancel_xpm ) );
  54. else
  55. AddMenuItem( aPopMenu, ID_POPUP_CLOSE_CURRENT_TOOL,
  56. _( "End Tool" ), KiBitmap( cursor_xpm ) );
  57. aPopMenu->AppendSeparator();
  58. }
  59. else
  60. {
  61. if( busy || BlockActive )
  62. {
  63. if( BlockActive )
  64. {
  65. AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
  66. _( "Cancel Block" ), KiBitmap( cancel_xpm ) );
  67. aPopMenu->AppendSeparator();
  68. AddMenuItem( aPopMenu, ID_POPUP_PLACE_BLOCK,
  69. _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
  70. }
  71. else
  72. {
  73. AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
  74. _( "Cancel" ), KiBitmap( cancel_xpm ) );
  75. }
  76. aPopMenu->AppendSeparator();
  77. }
  78. }
  79. if( BlockActive )
  80. return true;
  81. if( currItem )
  82. {
  83. GetScreen()->SetCurItem( currItem );
  84. bool add_separator = false;
  85. // Now, display a context menu
  86. // to allow highlighting items which share the same attributes
  87. // as the selected item (net attributes and aperture attributes)
  88. const GBR_NETLIST_METADATA& net_attr = currItem->GetNetAttributes();
  89. if( ( net_attr.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_PAD ) ||
  90. ( net_attr.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP ) )
  91. {
  92. AddMenuItem( aPopMenu, ID_HIGHLIGHT_CMP_ITEMS,
  93. wxString::Format( _( "Highlight Items of Component \"%s\"" ),
  94. GetChars( net_attr.m_Cmpref ) ),
  95. KiBitmap( file_footprint_xpm ) );
  96. add_separator = true;
  97. }
  98. if( ( net_attr.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_NET ) )
  99. {
  100. AddMenuItem( aPopMenu, ID_HIGHLIGHT_NET_ITEMS,
  101. wxString::Format( _( "Highlight Items of Net \"%s\"" ),
  102. GetChars( net_attr.m_Netname ) ),
  103. KiBitmap( general_ratsnest_xpm ) );
  104. add_separator = true;
  105. }
  106. D_CODE* apertDescr = currItem->GetDcodeDescr();
  107. if( apertDescr && !apertDescr->m_AperFunction.IsEmpty() )
  108. {
  109. AddMenuItem( aPopMenu, ID_HIGHLIGHT_APER_ATTRIBUTE_ITEMS,
  110. wxString::Format( _( "Highlight Aperture Type \"%s\"" ),
  111. GetChars( apertDescr->m_AperFunction ) ),
  112. KiBitmap( flag_xpm ) );
  113. add_separator = true;
  114. }
  115. if( add_separator )
  116. aPopMenu->AppendSeparator();
  117. }
  118. AddMenuItem( aPopMenu, ID_HIGHLIGHT_REMOVE_ALL,
  119. _( "Clear Highlight" ),
  120. KiBitmap( gerbview_clear_layers_xpm ) );
  121. aPopMenu->AppendSeparator();
  122. return true;
  123. }