KiCad PCB EDA Suite
pagelayout_editor/onrightclick.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
10  * Copyright (C) 2013 CERN
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <fctsys.h>
31 #include <class_drawpanel.h>
32 #include <pl_editor_id.h>
33 
34 #include <pl_editor_frame.h>
35 #include <design_tree_frame.h>
36 #include <properties_frame.h>
37 #include <menus_helpers.h>
39 #include <worksheet_dataitem.h>
40 #include <hotkeys.h>
41 #include <kicad_device_context.h>
42 
43 // Helper function to add menuitems relative to items creation
44 void AddNewItemsCommand( wxMenu* aMainMenu )
45 {
46  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line..." ),
47  KiBitmap( add_dashed_line_xpm ) );
48  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle..." ),
49  KiBitmap( add_rectangle_xpm ) );
50  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text..." ),
51  KiBitmap( text_xpm ) );
52  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap..." ),
53  KiBitmap( image_xpm ) );
55  _( "Append Existing Page Layout Design File..." ),
56  KiBitmap( pagelayout_load_xpm ) );
57 }
58 
59 /* Prepare the right-click pullup menu.
60  * The menu already has a list of zoom commands.
61  */
62 bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
63 {
64  bool busy = GetScreen()->GetCurItem() != NULL;
65  bool blockActive = GetScreen()->IsBlockActive();
66  wxString msg;
67 
68  if( blockActive )
69  {
70 
71  AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ),
72  KiBitmap( cancel_xpm ) );
73  aPopMenu->AppendSeparator();
74  return true;
75  }
76 
77  // If the tool ID_ZOOM_SELECTION is currently in use, add a close command menu
78  if( GetToolId() == ID_ZOOM_SELECTION && !busy )
79  {
80  AddMenuItem( aPopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ),
81  KiBitmap( cursor_xpm ) );
82  aPopMenu->AppendSeparator();
83  }
84 
85  if( ! busy ) // No item currently edited
86  {
89  WORKSHEET_DATAITEM* item = Locate( &dc, aPosition );
90 
91  if( item && old_item != item )
92  {
94  m_canvas->Refresh();
95  }
96 
97  // Add menus to edit and delete the item
98  if( item )
99  {
100  if( (item->GetFlags() & LOCATE_STARTPOINT) )
101  {
102  msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
105  KiBitmap( move_xpm ) );
106  }
107 
108  if( (item->GetFlags() & LOCATE_ENDPOINT ) )
109  {
110  msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
113  KiBitmap( move_xpm ) );
114  }
115 
116  msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
117  HK_MOVE_ITEM );
118  AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
119  KiBitmap( move_xpm ) );
120  aPopMenu->AppendSeparator();
121 
122  msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
123  HK_DELETE_ITEM );
124  AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
125  aPopMenu->AppendSeparator();
126  }
127  }
128  else // An item is currently in edit
129  {
130  msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
131  HK_PLACE_ITEM );
132  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
133  KiBitmap( move_xpm ) );
134  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
135  KiBitmap( cancel_xpm ) );
136  aPopMenu->AppendSeparator();
137  }
138 
139  if( ! busy )
140  {
141  AddNewItemsCommand( aPopMenu );
142  aPopMenu->AppendSeparator();
143  }
144 
145  return true;
146 }
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:223
bool OnRightClick(const wxPoint &aMousePos, wxMenu *aPopMenu) override
#define LOCATE_STARTPOINT
void SelectCell(WORKSHEET_DATAITEM *aItem)
void AddNewItemsCommand(wxMenu *aMainMenu)
#define LOCATE_ENDPOINT
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
bool IsBlockActive() const
Definition: base_screen.h:499
a helper to handle the real device context used in KiCad
description of graphic items and texts to build a title block
PL_EDITOR_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
WORKSHEET_DATAITEM * Locate(wxDC *aDC, const wxPoint &aPosition)
Function Locate.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
#define INSTALL_UNBUFFERED_DC(name, parent)
int GetToolId() const
Definition: draw_frame.h:519
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[]
classes and function to generate graphics to plt or draw titles blocks and frame references ...
static const char * text_xpm[]
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout