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 ) );
51  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap" ),
52  KiBitmap( image_xpm ) );
54  _( "Append Existing Page Layout Design File" ),
55  KiBitmap( pagelayout_load_xpm ) );
56 }
57 
58 /* Prepare the right-click pullup menu.
59  * The menu already has a list of zoom commands.
60  */
61 bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
62 {
63  bool busy = GetScreen()->GetCurItem() != NULL;
64  wxString msg;
65 
66  // If the tool ID_ZOOM_SELECTION is currently in use, add a
67  if( GetToolId() == ID_ZOOM_SELECTION && !busy )
68  {
69  AddMenuItem( aPopMenu, ID_NO_TOOL_SELECTED, _( "End Tool" ),
70  KiBitmap( cursor_xpm ) );
71  aPopMenu->AppendSeparator();
72  }
73 
74  if( ! busy ) // No item currently edited
75  {
77  WORKSHEET_DATAITEM* item = Locate( aPosition );
78 
79  if( item && old_item != item )
80  {
82  m_canvas->Refresh();
83  }
84 
85  // Add menus to edit and delete the item
86  if( item )
87  {
88  if( (item->GetFlags() & LOCATE_STARTPOINT) )
89  {
90  msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
93  KiBitmap( move_xpm ) );
94  }
95 
96  if( (item->GetFlags() & LOCATE_ENDPOINT ) )
97  {
98  msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
101  KiBitmap( move_xpm ) );
102  }
103 
104  msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
105  HK_MOVE_ITEM );
106  AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
107  KiBitmap( move_xpm ) );
108  aPopMenu->AppendSeparator();
109 
110  msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
111  HK_DELETE_ITEM );
112  AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
113  aPopMenu->AppendSeparator();
114  }
115  }
116  else // An item is currently in edit
117  {
118  msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
119  HK_PLACE_ITEM );
120  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
121  KiBitmap( move_xpm ) );
122  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
123  KiBitmap( cancel_xpm ) );
124  aPopMenu->AppendSeparator();
125  }
126 
127  if( ! busy )
128  {
129  AddNewItemsCommand( aPopMenu );
130  aPopMenu->AppendSeparator();
131  }
132 
133  return true;
134 }
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
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
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:93
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:465
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