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 
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  bool blockActive = GetScreen()->IsBlockActive();
65  wxString msg;
66 
67  if( blockActive )
68  {
69 
70  AddMenuItem( aPopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ),
71  KiBitmap( cancel_xpm ) );
72  aPopMenu->AppendSeparator();
73  return true;
74  }
75 
76  // If the tool ID_ZOOM_SELECTION is currently in use, add a close command menu
77  if( GetToolId() == ID_ZOOM_SELECTION && !busy )
78  {
79  AddMenuItem( aPopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ),
80  KiBitmap( cursor_xpm ) );
81  aPopMenu->AppendSeparator();
82  }
83 
84  if( ! busy ) // No item currently edited
85  {
87  WORKSHEET_DATAITEM* item = Locate( aPosition );
88 
89  if( item && old_item != item )
90  {
92  m_canvas->Refresh();
93  }
94 
95  // Add menus to edit and delete the item
96  if( item )
97  {
98  if( (item->GetFlags() & LOCATE_STARTPOINT) )
99  {
100  msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
103  KiBitmap( move_xpm ) );
104  }
105 
106  if( (item->GetFlags() & LOCATE_ENDPOINT ) )
107  {
108  msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
111  KiBitmap( move_xpm ) );
112  }
113 
114  msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
115  HK_MOVE_ITEM );
116  AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
117  KiBitmap( move_xpm ) );
118  aPopMenu->AppendSeparator();
119 
120  msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
121  HK_DELETE_ITEM );
122  AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
123  aPopMenu->AppendSeparator();
124  }
125  }
126  else // An item is currently in edit
127  {
128  msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
129  HK_PLACE_ITEM );
130  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
131  KiBitmap( move_xpm ) );
132  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
133  KiBitmap( cancel_xpm ) );
134  aPopMenu->AppendSeparator();
135  }
136 
137  if( ! busy )
138  {
139  AddNewItemsCommand( aPopMenu );
140  aPopMenu->AppendSeparator();
141  }
142 
143  return true;
144 }
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:338
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:174
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)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
bool IsBlockActive() const
Definition: base_screen.h:499
WORKSHEET_DATAITEM * Locate(const wxPoint &aPosition)
Function Locate.
description of graphic items and texts to build a title block
PL_EDITOR_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:106
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:496
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[]
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout