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>
40 #include <hotkeys.h>
41 
42 // Helper function to add menuitems relative to items creation
43 void AddNewItemsCommand( wxMenu* aMainMenu )
44 {
45  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line" ),
46  KiBitmap( add_dashed_line_xpm ) );
47  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle" ),
48  KiBitmap( add_rectangle_xpm ) );
49  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text" ),
50  KiBitmap( text_xpm ) );
52  _( "Append Page Layout Descr File" ),
53  KiBitmap( import_xpm ) );
55  _( "Add Bitmap" ),
56  KiBitmap( image_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  wxString msg;
66 
67  // If the tool ID_ZOOM_SELECTION is currently in use, add a
68  if( GetToolId() == ID_ZOOM_SELECTION && !busy )
69  {
70  AddMenuItem( aPopMenu, ID_NO_TOOL_SELECTED, _( "End Tool" ),
71  KiBitmap( cursor_xpm ) );
72  aPopMenu->AppendSeparator();
73  }
74 
75  if( ! busy ) // No item currently edited
76  {
78  WORKSHEET_DATAITEM* item = Locate( aPosition );
79 
80  if( item && old_item != item )
81  {
83  m_canvas->Refresh();
84  }
85 
86  // Add menus to edit and delete the item
87  if( item )
88  {
89  if( (item->GetFlags() & LOCATE_STARTPOINT) )
90  {
91  msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
94  KiBitmap( move_xpm ) );
95  }
96 
97  if( (item->GetFlags() & LOCATE_ENDPOINT ) )
98  {
99  msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
102  KiBitmap( move_xpm ) );
103  }
104 
105  msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
106  HK_MOVE_ITEM );
107  AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
108  KiBitmap( move_xpm ) );
109  aPopMenu->AppendSeparator();
110 
111  msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
112  HK_DELETE_ITEM );
113  AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
114  aPopMenu->AppendSeparator();
115  }
116  }
117  else // An item is currently in edit
118  {
119  msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
120  HK_PLACE_ITEM );
121  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
122  KiBitmap( move_xpm ) );
123  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
124  KiBitmap( cancel_xpm ) );
125  aPopMenu->AppendSeparator();
126  }
127 
128  if( ! busy )
129  {
130  AddNewItemsCommand( aPopMenu );
131  aPopMenu->AppendSeparator();
132  }
133 
134  return true;
135 }
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
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:55
bool OnRightClick(const wxPoint &aMousePos, wxMenu *aPopMenu) override
description of graphic items and texts to build a title block
void SelectCell(WORKSHEET_DATAITEM *aItem)
void AddNewItemsCommand(wxMenu *aMainMenu)
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
WORKSHEET_DATAITEM * Locate(const wxPoint &aPosition)
Function Locate.
PL_EDITOR_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
#define LOCATE_STARTPOINT
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
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) ...
int GetToolId() const
Definition: draw_frame.h:419
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[]
#define LOCATE_ENDPOINT
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout