KiCad PCB EDA Suite
libedit_onleftclick.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <eeschema_id.h>
34 #include <msgpanel.h>
35 
36 #include <general.h>
37 #include <lib_edit_frame.h>
38 #include <class_libentry.h>
39 
40 
41 void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
42 {
43  LIB_ITEM* item = GetDrawItem();
44  bool item_in_edit = item && item->InEditMode();
45  bool no_item_edited = !item_in_edit;
46 
47  LIB_PART* part = GetCurPart();
48 
49  if( !part ) // No component loaded !
50  return;
51 
52  if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
53  {
54  item = LocateItemUsingCursor( aPosition );
55 
56  if( item )
57  {
58  MSG_PANEL_ITEMS items;
59  item->GetMsgPanelInfo( items );
60 
61  SetMsgPanel( items );
62  }
63  else
64  {
65  DisplayCmpDoc();
66 
67  if( m_canvas->GetAbortRequest() )
68  m_canvas->SetAbortRequest( false );
69  }
70  }
71 
72  switch( GetToolId() )
73  {
74  case ID_ZOOM_SELECTION:
75  break;
76 
78  // If an item is currently in edit, finish edit
79  if( item_in_edit )
80  {
81  switch( item->Type() )
82  {
83  case LIB_PIN_T:
84  PlacePin();
85  break;
86 
87  default:
88  EndDrawGraphicItem( DC );
89  break;
90  }
91  }
92  break;
93 
95  if( no_item_edited )
96  CreatePin( DC );
97  else
98  PlacePin();
99  break;
100 
106  if( no_item_edited )
107  SetDrawItem( CreateGraphicItem( part, DC ) );
108  else if( item )
109  {
110  if( item->IsNew() )
111  GraphicItemBeginDraw( DC );
112  else
113  EndDrawGraphicItem( DC );
114  }
115  break;
116 
118  item = LocateItemUsingCursor( aPosition );
119 
120  if( item )
121  {
122  deleteItem( DC, item );
123  }
124  else
125  {
126  DisplayCmpDoc();
127 
128  if( m_canvas->GetAbortRequest() )
129  m_canvas->SetAbortRequest( false );
130  }
131  break;
132 
134  SaveCopyInUndoList( part );
135  PlaceAnchor();
137  break;
138 
139  default:
140  wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
142  break;
143  }
144 }
145 
146 
147 /*
148  * Called on a double click:
149  * If an editable item (field, pin, graphic):
150  * Call the suitable dialog editor.
151  */
152 void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
153 {
154  LIB_PART* part = GetCurPart();
155  LIB_ITEM* item = GetDrawItem();
156 
157  if( !part )
158  return;
159 
160  if( !item || !item->InEditMode() )
161  { // We can locate an item
163 
164  if( item == NULL )
165  {
166  // The user canceled the disambiguation menu
167  if( m_canvas->GetAbortRequest() )
168  m_canvas->SetAbortRequest( false );
169  else
170  {
171  // If there is only a random double-click, we allow the use to edit the part
172  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
173 
174  cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
175  GetEventHandler()->ProcessEvent( cmd );
176  }
177  }
178  }
179 
180  if( item )
181  SetMsgPanel( item );
182  else
183  return;
184 
186  bool not_edited = !item->InEditMode();
187 
188  switch( item->Type() )
189  {
190  case LIB_PIN_T:
191  if( not_edited )
192  {
193  SetDrawItem( item );
194  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
195 
196  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
197  GetEventHandler()->ProcessEvent( cmd );
198  }
199  break;
200 
201  case LIB_ARC_T:
202  case LIB_CIRCLE_T:
203  case LIB_RECTANGLE_T:
204  if( not_edited )
205  EditGraphicSymbol( DC, item );
206  break;
207 
208  case LIB_POLYLINE_T:
209  if( not_edited )
210  EditGraphicSymbol( DC, item );
211  else if( item->IsNew() )
212  EndDrawGraphicItem( DC );
213  break;
214 
215  case LIB_TEXT_T:
216  if( not_edited )
217  EditSymbolText( DC, item );
218  break;
219 
220  case LIB_FIELD_T:
221  if( not_edited )
222  EditField( (LIB_FIELD*) item );
223  break;
224 
225  default:
226  wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
227  break;
228  }
229 
231  m_canvas->SetIgnoreMouseEvents( false );
232 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
bool IsNew() const
Definition: base_struct.h:227
Field object used in symbol libraries.
Definition: lib_field.h:59
bool InEditMode() const
Return the draw item editing mode status.
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:360
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
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.
void GraphicItemBeginDraw(wxDC *DC)
Definition: symbdraw.cpp:245
Define a library symbol object.
void CreatePin(wxDC *DC)
Definition: pinedit.cpp:428
void SetAbortRequest(bool aAbortRequest)
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: libedit.cpp:656
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
void deleteItem(wxDC *aDC, LIB_ITEM *aItem)
Deletes the currently selected draw item.
void PlacePin()
Place at cursor location the pin currently moved (i.e.
Definition: pinedit.cpp:240
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
Definition: draw_frame.cpp:616
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:98
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
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.
virtual wxString GetClass() const =0
Function GetClass returns the class name.
LIB_ITEM * CreateGraphicItem(LIB_PART *LibEntry, wxDC *DC)
Definition: symbdraw.cpp:153
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
int GetToolId() const
Definition: draw_frame.h:488
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy, UNDO_REDO_T undoType=UR_LIBEDIT)
Create a copy of the current component, and save it in the undo list.
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:343
LIB_ITEM * GetDrawItem() const
void SetIgnoreMouseEvents(bool aIgnore)
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:55
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
Definition of class LIB_EDIT_FRAME.
void EditField(LIB_FIELD *Field)
Definition: libfield.cpp:42
void PlaceAnchor()
Places an anchor reference coordinate for the current component.
Definition: symbedit.cpp:218
Message panel definition file.
static const KICAD_T DoubleClickItems[]
A scan list for all double-clickable library items.