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  DisplayCmpDoc();
124 
125  break;
126 
128  SaveCopyInUndoList( part );
129  PlaceAnchor();
131  break;
132 
133  default:
134  wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
136  break;
137  }
138 }
139 
140 
141 /*
142  * Called on a double click:
143  * If an editable item (field, pin, graphic):
144  * Call the suitable dialog editor.
145  */
146 void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
147 {
148  LIB_PART* part = GetCurPart();
149 
150  if( !part )
151  return;
152 
153  if( !m_drawItem || !m_drawItem->InEditMode() )
154  { // We can locate an item
155  m_drawItem = LocateItemUsingCursor( aPosition );
156 
157  if( m_drawItem == NULL )
158  {
159  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
160 
161  cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
162  GetEventHandler()->ProcessEvent( cmd );
163  }
164  }
165 
166  if( m_drawItem )
168  else
169  return;
170 
172  bool not_edited = !m_drawItem->InEditMode();
173 
174  switch( m_drawItem->Type() )
175  {
176  case LIB_PIN_T:
177  if( not_edited )
178  {
179  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
180 
181  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
182  GetEventHandler()->ProcessEvent( cmd );
183  }
184  break;
185 
186  case LIB_ARC_T:
187  case LIB_CIRCLE_T:
188  case LIB_RECTANGLE_T:
189  if( not_edited )
191  break;
192 
193  case LIB_POLYLINE_T:
194  if( not_edited )
196  else if( m_drawItem->IsNew() )
197  EndDrawGraphicItem( DC );
198  break;
199 
200  case LIB_TEXT_T:
201  if( not_edited )
202  EditSymbolText( DC, m_drawItem );
203  break;
204 
205  case LIB_FIELD_T:
206  if( not_edited )
208  break;
209 
210  default:
211  wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
212  break;
213  }
214 
216  m_canvas->SetIgnoreMouseEvents( false );
217 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
bool IsNew() const
Definition: base_struct.h:216
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:348
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
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:773
void deleteItem(wxDC *aDC)
Function deleteItem deletes the currently selected draw item.
Class LIB_ITEM definition.
void GraphicItemBeginDraw(wxDC *DC)
Definition: symbdraw.cpp:241
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:455
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:560
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
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:151
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:419
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:339
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.