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 <libeditframe.h>
38 #include <class_libentry.h>
39 
40 
41 void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
42 {
43  LIB_ITEM* item = m_drawItem;
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  m_drawItem = CreateGraphicItem( part, DC );
108  else if( m_drawItem )
109  {
110  if( m_drawItem->IsNew() )
111  GraphicItemBeginDraw( DC );
112  else
113  EndDrawGraphicItem( DC );
114  }
115  break;
116 
118  m_drawItem = LocateItemUsingCursor( aPosition );
119 
120  if( m_drawItem )
121  deleteItem( DC );
122  else
123  {
124  DisplayCmpDoc();
125 
126  if( m_canvas->GetAbortRequest() )
127  m_canvas->SetAbortRequest( false );
128  }
129  break;
130 
132  SaveCopyInUndoList( part );
133  PlaceAnchor();
135  break;
136 
137  default:
138  wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
140  break;
141  }
142 }
143 
144 
145 /*
146  * Called on a double click:
147  * If an editable item (field, pin, graphic):
148  * Call the suitable dialog editor.
149  */
150 void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
151 {
152  LIB_PART* part = GetCurPart();
153 
154  if( !part )
155  return;
156 
157  if( !m_drawItem || !m_drawItem->InEditMode() )
158  { // We can locate an item
159  m_drawItem = LocateItemUsingCursor( aPosition );
160 
161  if( m_drawItem == NULL )
162  {
163  if( m_canvas->GetAbortRequest() )
164  m_canvas->SetAbortRequest( false );
165 
166  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
167 
168  cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
169  GetEventHandler()->ProcessEvent( cmd );
170  }
171  }
172 
173  if( m_drawItem )
175  else
176  return;
177 
179  bool not_edited = !m_drawItem->InEditMode();
180 
181  switch( m_drawItem->Type() )
182  {
183  case LIB_PIN_T:
184  if( not_edited )
185  {
186  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
187 
188  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
189  GetEventHandler()->ProcessEvent( cmd );
190  }
191  break;
192 
193  case LIB_ARC_T:
194  case LIB_CIRCLE_T:
195  case LIB_RECTANGLE_T:
196  if( not_edited )
198  break;
199 
200  case LIB_POLYLINE_T:
201  if( not_edited )
203  else if( m_drawItem->IsNew() )
204  EndDrawGraphicItem( DC );
205  break;
206 
207  case LIB_TEXT_T:
208  if( not_edited )
209  EditSymbolText( DC, m_drawItem );
210  break;
211 
212  case LIB_FIELD_T:
213  if( not_edited )
215  break;
216 
217  default:
218  wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
219  break;
220  }
221 
223  m_canvas->SetIgnoreMouseEvents( false );
224 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool IsNew() const
Definition: base_struct.h:230
static LIB_ITEM * m_drawItem
Definition: libeditframe.h:91
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
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:347
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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
void deleteItem(wxDC *aDC)
Function deleteItem deletes the currently selected draw item.
Class LIB_ITEM definition.
void GraphicItemBeginDraw(wxDC *DC)
Definition: symbdraw.cpp:238
Class LIB_PART defines a library part object.
void CreatePin(wxDC *DC)
Definition: pinedit.cpp:424
void SetAbortRequest(bool aAbortRequest)
void DisplayCmpDoc()
Function DisplayCmpDoc displays the documentation of the selected component.
Definition: libedit.cpp:464
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
void PlacePin()
Function PlacePin Place at cursor location the pin currently moved (i.e.
Definition: pinedit.cpp:241
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
Definition: draw_frame.cpp:571
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
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
virtual wxString GetClass() const =0
Function GetClass returns the class name.
LIB_ITEM * CreateGraphicItem(LIB_PART *LibEntry, wxDC *DC)
Definition: symbdraw.cpp:148
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:471
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:336
void SetIgnoreMouseEvents(bool aIgnore)
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
LIB_PART * GetCurPart()
Function GetCurPart returns the current part being edited, or NULL if none selected.
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:58
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
void EditField(LIB_FIELD *Field)
Definition: libfield.cpp:39
void PlaceAnchor()
Function PlaceAnchor places an anchor reference coordinate for the current component.
Definition: symbedit.cpp:251
Message panel definition file.
Definition of class LIB_EDIT_FRAME.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Function SaveCopyInUndoList.