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  SetDrawItem( item );
123  deleteItem( DC );
124  }
125  else
126  {
127  DisplayCmpDoc();
128 
129  if( m_canvas->GetAbortRequest() )
130  m_canvas->SetAbortRequest( false );
131  }
132  break;
133 
135  SaveCopyInUndoList( part );
136  PlaceAnchor();
138  break;
139 
140  default:
141  wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
143  break;
144  }
145 }
146 
147 
148 /*
149  * Called on a double click:
150  * If an editable item (field, pin, graphic):
151  * Call the suitable dialog editor.
152  */
153 void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
154 {
155  LIB_PART* part = GetCurPart();
156  LIB_ITEM* item = GetDrawItem();
157 
158  if( !part )
159  return;
160 
161  if( !item || !item->InEditMode() )
162  { // We can locate an item
164 
165  if( item == NULL )
166  {
167  // The user canceled the disambiguation menu
168  if( m_canvas->GetAbortRequest() )
169  m_canvas->SetAbortRequest( false );
170  else
171  {
172  // If there is only a random double-click, we allow the use to edit the part
173  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
174 
175  cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
176  GetEventHandler()->ProcessEvent( cmd );
177  }
178  }
179  }
180 
181  if( item )
182  SetMsgPanel( item );
183  else
184  return;
185 
187  bool not_edited = !item->InEditMode();
188 
189  switch( item->Type() )
190  {
191  case LIB_PIN_T:
192  if( not_edited )
193  {
194  SetDrawItem( item );
195  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
196 
197  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
198  GetEventHandler()->ProcessEvent( cmd );
199  }
200  break;
201 
202  case LIB_ARC_T:
203  case LIB_CIRCLE_T:
204  case LIB_RECTANGLE_T:
205  if( not_edited )
206  EditGraphicSymbol( DC, item );
207  break;
208 
209  case LIB_POLYLINE_T:
210  if( not_edited )
211  EditGraphicSymbol( DC, item );
212  else if( item->IsNew() )
213  EndDrawGraphicItem( DC );
214  break;
215 
216  case LIB_TEXT_T:
217  if( not_edited )
218  EditSymbolText( DC, item );
219  break;
220 
221  case LIB_FIELD_T:
222  if( not_edited )
223  EditField( (LIB_FIELD*) item );
224  break;
225 
226  default:
227  wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
228  break;
229  }
230 
232  m_canvas->SetIgnoreMouseEvents( false );
233 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
bool IsNew() const
Definition: base_struct.h:245
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:361
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:790
void deleteItem(wxDC *aDC)
Deletes the currently selected draw item.
Class LIB_ITEM definition.
void GraphicItemBeginDraw(wxDC *DC)
Definition: symbdraw.cpp:245
Define a library symbol object.
void CreatePin(wxDC *DC)
Definition: pinedit.cpp:434
void SetAbortRequest(bool aAbortRequest)
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: libedit.cpp:655
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
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:574
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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:476
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:347
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.