KiCad PCB EDA Suite
libedit_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) 2004-2014 KiCad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <fctsys.h>
30 #include <confirm.h>
31 #include <eeschema_id.h>
32 #include <hotkeys.h>
33 #include <sch_draw_panel.h>
34 #include <sch_screen.h>
35 #include <msgpanel.h>
36 
37 #include <general.h>
38 #include <lib_edit_frame.h>
39 #include <class_libentry.h>
40 #include <lib_pin.h>
41 #include <lib_polyline.h>
42 #include <menus_helpers.h>
43 
44 
45 /* functions to add commands and submenus depending on the item */
46 static void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame );
47 static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame );
48 
49 
50 bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
51 {
52  LIB_ITEM* item = GetDrawItem();
53  bool blockActive = GetScreen()->IsBlockActive();
54  wxString msg;
55 
56  if( blockActive )
57  {
58  AddMenusForBlock( PopMenu, this );
59  PopMenu->AppendSeparator();
60  return true;
61  }
62 
63  LIB_PART* part = GetCurPart();
64 
65  if( !part )
66  return true;
67 
68  // If Command in progress, put menu "cancel"
69  if( item && item->InEditMode() )
70  {
71  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ),
72  KiBitmap( cancel_xpm ) );
73  PopMenu->AppendSeparator();
74  }
75  else
76  {
77  item = LocateItemUsingCursor( aPosition );
78 
79  // If the clarify item selection context menu is aborted, don't show the context menu.
80  if( item == NULL && m_canvas->GetAbortRequest() )
81  {
82  m_canvas->SetAbortRequest( false );
83  return false;
84  }
85 
87  {
88  // If a tool is active, put menu "end tool"
89  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ),
90  KiBitmap( cursor_xpm ) );
91  PopMenu->AppendSeparator();
92  }
93  }
94 
95  if( item )
96  {
97  MSG_PANEL_ITEMS items;
98  item->GetMsgPanelInfo( m_UserUnits, items );
99  SetMsgPanel( items );
100  }
101  else
102  {
103  if( GetToolId() == ID_NO_TOOL_SELECTED )
104  {
105  msg = AddHotkeyName( _( "&Paste" ), g_Libedit_Hokeys_Descr, HK_EDIT_PASTE );
106  AddMenuItem( PopMenu, ID_POPUP_PASTE_BLOCK, msg, _( "Pastes copied item(s)" ),
107  KiBitmap( paste_xpm ) );
108  PopMenu->AppendSeparator();
109  }
110 
111  return true;
112  }
113 
114  SetDrawItem( item );
115  bool not_edited = !item->InEditMode();
116 
117  switch( item->Type() )
118  {
119  case LIB_PIN_T:
120  AddMenusForPin( PopMenu, (LIB_PIN*) item, this );
121  break;
122 
123  case LIB_ARC_T:
124  if( not_edited )
125  {
126  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
129  KiBitmap( move_xpm ) );
130  msg = AddHotkeyName( _( "Drag Arc Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
131  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_xpm ) );
132  }
133 
134  msg = AddHotkeyName( _( "Edit Arc Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
135  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_arc_xpm ) );
136 
137  if( not_edited )
138  {
139  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
140  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
141  }
142  break;
143 
144  case LIB_CIRCLE_T:
145  if( not_edited )
146  {
147  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
150  KiBitmap( move_xpm ) );
151  msg = AddHotkeyName( _( "Drag Circle Outline" ), g_Libedit_Hokeys_Descr, HK_DRAG );
153  KiBitmap( move_rectangle_xpm ) );
154  }
155 
156  msg = AddHotkeyName( _( "Edit Circle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
158  KiBitmap( options_circle_xpm ) );
159 
160  if( not_edited )
161  {
162  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
164  KiBitmap( delete_circle_xpm ) );
165  }
166  break;
167 
168  case LIB_RECTANGLE_T:
169  if( not_edited )
170  {
171  msg = AddHotkeyName( _( "Move Rectangle" ), g_Libedit_Hokeys_Descr,
174  KiBitmap( move_rectangle_xpm ) );
175  }
176 
177  msg = AddHotkeyName( _( "Edit Rectangle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
179  KiBitmap( options_rectangle_xpm ) );
180 
181  if( not_edited )
182  {
183  msg = AddHotkeyName( _( "Drag Rectangle Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
185  KiBitmap( move_rectangle_xpm ) );
186  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
188  KiBitmap( delete_rectangle_xpm ) );
189  }
190 
191  break;
192 
193  case LIB_TEXT_T:
194  if( not_edited )
195  {
196  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
199  KiBitmap( move_xpm ) );
200  }
201 
202  msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
203  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
204 
205  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
206  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
207 
208  if( not_edited )
209  {
210  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
211  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
212  }
213  break;
214 
215  case LIB_POLYLINE_T:
216  if( not_edited )
217  {
218  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
221  KiBitmap( move_xpm ) );
222  msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG );
223  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_exactly_xpm ) );
224  }
225 
226  if( item->IsNew() )
227  {
228  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ),
229  KiBitmap( checked_ok_xpm ) );
230  }
231 
232  msg = AddHotkeyName( _( "Edit Line Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
234  KiBitmap( options_segment_xpm ) );
235 
236  if( not_edited )
237  {
238  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
240  KiBitmap( delete_xpm ) );
241  }
242 
243  if( item->IsNew() )
244  {
245  if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 )
246  {
247  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
249  msg, KiBitmap( delete_xpm ) );
250  }
251  }
252 
253  break;
254 
255  case LIB_FIELD_T:
256  if( not_edited )
257  {
258  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
261  KiBitmap( move_xpm ) );
262  }
263 
264  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
265  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
266  msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT );
267  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
268  break;
269 
270 
271  default:
272  wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ),
273  item->Type() ) );
274  SetDrawItem( NULL );
275  break;
276  }
277 
278  PopMenu->AppendSeparator();
279  return true;
280 }
281 
282 void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
283 {
284  bool selected = Pin->IsSelected();
285  bool not_in_move = !Pin->IsMoving();
286  wxString msg;
287 
288  if( not_in_move )
289  {
290  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
292  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
293  }
294 
295  msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT);
296  AddMenuItem( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, KiBitmap( edit_xpm ) );
297 
298  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
299  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
300 
301  if( not_in_move )
302  {
303  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
304  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
305  }
306 
307  wxMenu* global_pin_change = new wxMenu;
308  AddMenuItem( PopMenu, global_pin_change,
310  _( "Global" ), KiBitmap( pin_to_xpm ) );
311  AddMenuItem( global_pin_change,
313  selected ? _( "Push Pin Size to Selected Pin" ) :
314  _( "Push Pin Size to Others" ), KiBitmap( pin_size_to_xpm ) );
315  AddMenuItem( global_pin_change,
317  selected ? _( "Push Pin Name Size to Selected Pin" ) :
318  _( "Push Pin Name Size to Others" ), KiBitmap( pin_name_to_xpm ) );
319  AddMenuItem( global_pin_change,
321  selected ? _( "Push Pin Num Size to Selected Pin" ) :
322  _( "Push Pin Num Size to Others" ), KiBitmap( pin_number_to_xpm ) );
323 }
324 
325 
326 /* Add menu commands for block */
327 
328 void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
329 {
330  wxString msg;
331  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
332  KiBitmap( cancel_xpm ) );
333 
334  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
336  _( "Zoom Block" ),
337  KiBitmap( zoom_area_xpm ) );
338 
339  PopMenu->AppendSeparator();
340 
341  AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
342 
343  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
344  {
345  AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
346  KiBitmap( green_xpm ) );
347 
348  msg = AddHotkeyName( _( "Cut Block" ), g_Schematic_Hokeys_Descr, HK_EDIT_CUT );
349  AddMenuItem( PopMenu, ID_POPUP_CUT_BLOCK, msg, KiBitmap( cut_xpm ) );
350 
351  msg = AddHotkeyName( _( "Copy Block" ), g_Schematic_Hokeys_Descr, HK_EDIT_COPY );
352  AddMenuItem( PopMenu, ID_POPUP_COPY_BLOCK, msg,
353  KiBitmap( copy_xpm ) );
354 
355  AddMenuItem( PopMenu, ID_POPUP_DUPLICATE_BLOCK, _( "Duplicate Block" ),
356  KiBitmap( duplicate_xpm ) );
357 
358  msg = AddHotkeyName( _( "Mirror Block Around Horizontal(X) Axis" ), g_Libedit_Hokeys_Descr, HK_MIRROR_X );
359  AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg,
360  KiBitmap( mirror_v_xpm ) );
361 
362  msg = AddHotkeyName( _( "Mirror Block Around Vertical(Y) Axis" ), g_Libedit_Hokeys_Descr, HK_MIRROR_Y );
363  AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
364  KiBitmap( mirror_h_xpm ) );
365 
366  msg = AddHotkeyName( _( "Rotate Counterclockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
367  AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
368  KiBitmap( rotate_ccw_xpm ) );
369 
370  AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ),
371  KiBitmap( delete_xpm ) );
372  }
373 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
bool IsMoving() const
Definition: base_struct.h:221
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:219
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
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool IsSelected() const
Definition: base_struct.h:224
bool InEditMode() const
Return the draw item editing mode status.
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
Pcbnew hotkeys.
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
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
void SetDrawItem(LIB_ITEM *drawItem)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
Class LIB_ITEM definition.
static void AddMenusForPin(wxMenu *PopMenu, LIB_PIN *Pin, LIB_EDIT_FRAME *frame)
Define a library symbol object.
void SetAbortRequest(bool aAbortRequest)
Definitions for the Eeschema program SCH_SCREEN class.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
LIB_ITEM * LocateItemUsingCursor(const wxPoint &aPosition, const KICAD_T aFilterList[]=LIB_COLLECTOR::AllItems)
The symbol library editor main window.
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) ...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static void AddMenusForBlock(wxMenu *PopMenu, LIB_EDIT_FRAME *frame)
int GetToolId() const
Definition: draw_frame.h:519
LIB_ITEM * GetDrawItem() const
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
Definition of class LIB_EDIT_FRAME.
BLOCK_COMMAND_T GetCommand() const
Message panel definition file.
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:120
struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[]