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 <class_drawpanel.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( 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, wxID_PASTE, msg,
107  _( "Pastes item(s) from the Clipboard" ),
108  KiBitmap( paste_xpm ) );
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 // Add menu items for pin edition
283 void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
284 {
285  bool selected = Pin->IsSelected();
286  bool not_in_move = !Pin->IsMoving();
287  wxString msg;
288 
289  if( not_in_move )
290  {
291  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
293  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
294  }
295 
296  msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT);
297  AddMenuItem( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, KiBitmap( edit_xpm ) );
298 
299  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
300  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
301 
302  if( not_in_move )
303  {
304  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
305  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
306  }
307 
308  wxMenu* global_pin_change = new wxMenu;
309  AddMenuItem( PopMenu, global_pin_change,
311  _( "Global" ), KiBitmap( pin_to_xpm ) );
312  AddMenuItem( global_pin_change,
314  selected ? _( "Push Pin Size to Selected Pin" ) :
315  _( "Push Pin Size to Others" ), KiBitmap( pin_size_to_xpm ) );
316  AddMenuItem( global_pin_change,
318  selected ? _( "Push Pin Name Size to Selected Pin" ) :
319  _( "Push Pin Name Size to Others" ), KiBitmap( pin_name_to_xpm ) );
320  AddMenuItem( global_pin_change,
322  selected ? _( "Push Pin Num Size to Selected Pin" ) :
323  _( "Push Pin Num Size to Others" ), KiBitmap( pin_number_to_xpm ) );
324 }
325 
326 
327 /* Add menu commands for block */
328 
329 void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
330 {
331  wxString msg;
332  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
333  KiBitmap( cancel_xpm ) );
334 
335  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
337  _( "Zoom Block" ),
338  KiBitmap( zoom_area_xpm ) );
339 
340  PopMenu->AppendSeparator();
341 
342  AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
343 
344  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
345  {
346  AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
347  KiBitmap( green_xpm ) );
348  msg = AddHotkeyName( _( "Cut Block" ), g_Schematic_Hokeys_Descr,
349  HK_EDIT_CUT );
350  AddMenuItem( PopMenu, wxID_CUT, msg, KiBitmap( cut_xpm ) );
351  msg = AddHotkeyName( _( "Copy Block" ), g_Schematic_Hokeys_Descr,
352  HK_EDIT_COPY );
353  AddMenuItem( PopMenu, wxID_COPY, msg, KiBitmap( copy_xpm ) );
354  AddMenuItem( PopMenu, ID_POPUP_DUPLICATE_BLOCK, _( "Duplicate Block" ),
355  KiBitmap( duplicate_xpm ) );
356  msg = AddHotkeyName( _( "Mirror Block Around Horizontal(X) Axis" ), g_Libedit_Hokeys_Descr,
357  HK_MIRROR_X );
358  AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg,
359  KiBitmap( mirror_v_xpm ) );
360  msg = AddHotkeyName( _( "Mirror Block Around Vertical(Y) Axis" ), g_Libedit_Hokeys_Descr,
361  HK_MIRROR_Y );
362  AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
363  KiBitmap( mirror_h_xpm ) );
364  msg = AddHotkeyName( _( "Rotate Counterclockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
365  AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
366  KiBitmap( rotate_ccw_xpm ) );
367  AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
368  }
369 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
bool IsMoving() const
Definition: base_struct.h:229
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:227
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
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
bool IsSelected() const
Definition: base_struct.h:232
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:66
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
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)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:832
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:106
bool GetAbortRequest() const
LIB_ITEM * LocateItemUsingCursor(const wxPoint &aPosition, const KICAD_T aFilterList[]=LIB_COLLECTOR::AllItems)
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
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:496
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.
struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[]