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) 2013 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( add_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( ! busy ) // No item currently edited
68  {
70  WORKSHEET_DATAITEM* item = Locate( aPosition );
71 
72  if( item && old_item != item )
73  {
75  m_canvas->Refresh();
76  }
77 
78  // Add menus to edit and delete the item
79  if( item )
80  {
81  if( (item->GetFlags() & LOCATE_STARTPOINT) )
82  {
83  msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
86  KiBitmap( move_xpm ) );
87  }
88 
89  if( (item->GetFlags() & LOCATE_ENDPOINT ) )
90  {
91  msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
94  KiBitmap( move_xpm ) );
95  }
96 
97  msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
98  HK_MOVE_ITEM );
99  AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
100  KiBitmap( move_xpm ) );
101  aPopMenu->AppendSeparator();
102 
103  msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
104  HK_DELETE_ITEM );
105  AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
106  aPopMenu->AppendSeparator();
107  }
108  }
109  else // An item is currently in edit
110  {
111  msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
112  HK_PLACE_ITEM );
113  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
114  KiBitmap( move_xpm ) );
115  AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
116  KiBitmap( cancel_xpm ) );
117  aPopMenu->AppendSeparator();
118  }
119 
120  if( ! busy )
121  {
122  AddNewItemsCommand( aPopMenu );
123  aPopMenu->AppendSeparator();
124  }
125 
126  return true;
127 }
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) ...
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[]
classes and function to generate graphics to plt or draw titles blocks and frame references ...
#define LOCATE_ENDPOINT
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout