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 <class_sch_screen.h>
35 #include <msgpanel.h>
36 
37 #include <general.h>
38 #include <libeditframe.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 
55  if( blockActive )
56  {
57  AddMenusForBlock( PopMenu, this );
58  PopMenu->AppendSeparator();
59  return true;
60  }
61 
62  LIB_PART* part = GetCurPart();
63 
64  if( !part )
65  return true;
66 
67  // If Command in progress, put menu "cancel"
68  if( item && item->InEditMode() )
69  {
70  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ),
71  KiBitmap( cancel_xpm ) );
72  PopMenu->AppendSeparator();
73  }
74  else
75  {
76  item = LocateItemUsingCursor( aPosition );
77 
78  // If the clarify item selection context menu is aborted, don't show the context menu.
79  if( item == NULL && m_canvas->GetAbortRequest() )
80  {
81  m_canvas->SetAbortRequest( false );
82  return false;
83  }
84 
86  {
87  // If a tool is active, put menu "end tool"
88  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ),
89  KiBitmap( cursor_xpm ) );
90  PopMenu->AppendSeparator();
91  }
92  }
93 
94  if( item )
95  {
96  MSG_PANEL_ITEMS items;
97  item->GetMsgPanelInfo( items );
98  SetMsgPanel( items );
99  }
100  else
101  {
102  return true;
103  }
104 
105  m_drawItem = item;
106  bool not_edited = !item->InEditMode();
107  wxString msg;
108 
109  switch( item->Type() )
110  {
111  case LIB_PIN_T:
112  AddMenusForPin( PopMenu, (LIB_PIN*) item, this );
113  break;
114 
115  case LIB_ARC_T:
116  if( not_edited )
117  {
118  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
121  KiBitmap( move_xpm ) );
122  msg = AddHotkeyName( _( "Drag Arc Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
123  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_xpm ) );
124  }
125 
126  msg = AddHotkeyName( _( "Edit Arc Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
127  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_arc_xpm ) );
128 
129  if( not_edited )
130  {
131  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
132  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
133  }
134  break;
135 
136  case LIB_CIRCLE_T:
137  if( not_edited )
138  {
139  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
142  KiBitmap( move_xpm ) );
143  msg = AddHotkeyName( _( "Drag Circle Outline" ), g_Libedit_Hokeys_Descr, HK_DRAG );
145  KiBitmap( move_rectangle_xpm ) );
146  }
147 
148  msg = AddHotkeyName( _( "Edit Circle Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
150  KiBitmap( options_circle_xpm ) );
151 
152  if( not_edited )
153  {
154  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
156  KiBitmap( delete_circle_xpm ) );
157  }
158  break;
159 
160  case LIB_RECTANGLE_T:
161  if( not_edited )
162  {
163  msg = AddHotkeyName( _( "Move Rectangle" ), g_Libedit_Hokeys_Descr,
166  KiBitmap( move_rectangle_xpm ) );
167  }
168 
169  msg = AddHotkeyName( _( "Edit Rectangle Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
171  KiBitmap( options_rectangle_xpm ) );
172 
173  if( not_edited )
174  {
175  msg = AddHotkeyName( _( "Drag Rectangle Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG );
177  KiBitmap( move_rectangle_xpm ) );
178  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
180  KiBitmap( delete_rectangle_xpm ) );
181  }
182 
183  break;
184 
185  case LIB_TEXT_T:
186  if( not_edited )
187  {
188  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
191  KiBitmap( move_xpm ) );
192  }
193 
194  msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT );
195  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
196 
197  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
198  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
199 
200  if( not_edited )
201  {
202  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
203  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
204  }
205  break;
206 
207  case LIB_POLYLINE_T:
208  if( not_edited )
209  {
210  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
213  KiBitmap( move_xpm ) );
214  msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG );
215  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_exactly_xpm ) );
216  }
217 
218  if( item->IsNew() )
219  {
220  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ),
221  KiBitmap( checked_ok_xpm ) );
222  }
223 
224  msg = AddHotkeyName( _( "Edit Line Options" ), g_Libedit_Hokeys_Descr, HK_EDIT );
226  KiBitmap( options_segment_xpm ) );
227 
228  if( not_edited )
229  {
230  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
232  KiBitmap( delete_xpm ) );
233  }
234 
235  if( item->IsNew() )
236  {
237  if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 )
238  {
239  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
241  msg, KiBitmap( delete_xpm ) );
242  }
243  }
244 
245  break;
246 
247  case LIB_FIELD_T:
248  if( not_edited )
249  {
250  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
253  KiBitmap( move_xpm ) );
254  }
255 
256  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
257  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
258  msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT );
259  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) );
260  break;
261 
262 
263  default:
264  wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ),
265  item->Type() ) );
266  m_drawItem = NULL;
267  break;
268  }
269 
270  PopMenu->AppendSeparator();
271  return true;
272 }
273 
274 // Add menu items for pin edition
275 void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
276 {
277  bool selected = Pin->IsSelected();
278  bool not_in_move = !Pin->IsMoving();
279  wxString msg;
280 
281  if( not_in_move )
282  {
283  msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr,
285  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
286  }
287 
288  msg = AddHotkeyName( _( "Edit" ), g_Libedit_Hokeys_Descr, HK_EDIT);
289  AddMenuItem( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, KiBitmap( edit_xpm ) );
290 
291  msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
292  AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) );
293 
294  if( not_in_move )
295  {
296  msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE );
297  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) );
298  }
299 
300  wxMenu* global_pin_change = new wxMenu;
301  AddMenuItem( PopMenu, global_pin_change,
303  _( "Global" ), KiBitmap( pin_to_xpm ) );
304  AddMenuItem( global_pin_change,
306  selected ? _( "Pin Size to selected pins" ) :
307  _( "Pin Size to Others" ), KiBitmap( pin_size_to_xpm ) );
308  AddMenuItem( global_pin_change,
310  selected ? _( "Pin Name Size to selected pin" ) :
311  _( "Pin Name Size to Others" ), KiBitmap( pin_name_to_xpm ) );
312  AddMenuItem( global_pin_change,
314  selected ? _( "Pin Num Size to selected pin" ) :
315  _( "Pin Num Size to Others" ), KiBitmap( pin_number_to_xpm ) );
316 }
317 
318 
319 /* Add menu commands for block */
320 
321 void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
322 {
323  wxString msg;
324  AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
325  KiBitmap( cancel_xpm ) );
326 
327  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
329  _( "Zoom Block (drag middle mouse)" ),
330  KiBitmap( zoom_area_xpm ) );
331 
332  PopMenu->AppendSeparator();
333 
334  AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
335 
336  if( frame->GetScreen()->m_BlockLocate.GetCommand() == BLOCK_MOVE )
337  {
338  AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
339  KiBitmap( green_xpm ) );
340  AddMenuItem( PopMenu, ID_POPUP_DUPLICATE_BLOCK, _( "Duplicate Block" ), KiBitmap( duplicate_xpm ) );
341  msg = AddHotkeyName( _( "Flip Block Horizonal" ), g_Libedit_Hokeys_Descr, HK_MIRROR_Y );
342  AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
343  KiBitmap( mirror_h_xpm ) );
344  msg = AddHotkeyName( _( "Flip Block Vertical" ), g_Libedit_Hokeys_Descr, HK_MIRROR_X );
345  AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg,
346  KiBitmap( mirror_v_xpm ) );
347  msg = AddHotkeyName( _( "Rotate Counterclockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
348  AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
349  KiBitmap( rotate_ccw_xpm ) );
350  AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
351  }
352 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool IsMoving() const
Definition: base_struct.h:232
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
LIB_ITEM * GetDrawItem()
Definition: libeditframe.h:399
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:230
static LIB_ITEM * m_drawItem
Definition: libeditframe.h:91
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
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:235
bool InEditMode() const
Return the draw item editing mode status.
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
bool IsBlockActive() const
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:784
Definitions for the Eeschema program SCH_SCREEN class.
Class LIB_ITEM definition.
static void AddMenusForPin(wxMenu *PopMenu, LIB_PIN *Pin, LIB_EDIT_FRAME *frame)
Class LIB_PART defines a library part object.
void SetAbortRequest(bool aAbortRequest)
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
The component library editor main window.
Definition: libeditframe.h:51
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:471
LIB_PART * GetCurPart()
Function GetCurPart returns the current part being edited, or NULL if none selected.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
BLOCK_COMMAND_T GetCommand() const
Message panel definition file.
Definition of class LIB_EDIT_FRAME.