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  {
75  // If an item is currently in edit, finish edit
76  if( item_in_edit )
77  {
78  switch( item->Type() )
79  {
80  case LIB_PIN_T:
81  PlacePin();
82  break;
83 
84  default:
85  EndDrawGraphicItem( DC );
86  break;
87  }
88  }
89  break;
90 
92  if( no_item_edited )
93  CreatePin( DC );
94  else
95  PlacePin();
96  break;
97 
103  if( no_item_edited )
104  m_drawItem = CreateGraphicItem( part, DC );
105  else if( m_drawItem )
106  {
107  if( m_drawItem->IsNew() )
108  GraphicItemBeginDraw( DC );
109  else
110  EndDrawGraphicItem( DC );
111  }
112  break;
113 
115  m_drawItem = LocateItemUsingCursor( aPosition );
116 
117  if( m_drawItem )
118  deleteItem( DC );
119  else
120  DisplayCmpDoc();
121 
122  break;
123 
125  SaveCopyInUndoList( part );
126  PlaceAnchor();
128  break;
129 
130  default:
131  wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
133  break;
134  }
135 }
136 
137 
138 /*
139  * Called on a double click:
140  * If an editable item (field, pin, graphic):
141  * Call the suitable dialog editor.
142  */
143 void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
144 {
145  LIB_PART* part = GetCurPart();
146 
147  if( !part )
148  return;
149 
150  if( !m_drawItem || !m_drawItem->InEditMode() )
151  { // We can locate an item
152  m_drawItem = LocateItemUsingCursor( aPosition );
153 
154  if( m_drawItem == NULL )
155  {
156  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
157 
158  cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
159  GetEventHandler()->ProcessEvent( cmd );
160  }
161  }
162 
163  if( m_drawItem )
165  else
166  return;
167 
169  bool not_edited = !m_drawItem->InEditMode();
170 
171  switch( m_drawItem->Type() )
172  {
173  case LIB_PIN_T:
174  if( not_edited )
175  {
176  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
177 
178  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
179  GetEventHandler()->ProcessEvent( cmd );
180  }
181  break;
182 
183  case LIB_ARC_T:
184  case LIB_CIRCLE_T:
185  case LIB_RECTANGLE_T:
186  if( not_edited )
188  break;
189 
190  case LIB_POLYLINE_T:
191  if( not_edited )
193  else if( m_drawItem->IsNew() )
194  EndDrawGraphicItem( DC );
195  break;
196 
197  case LIB_TEXT_T:
198  if( not_edited )
199  EditSymbolText( DC, m_drawItem );
200  break;
201 
202  case LIB_FIELD_T:
203  if( not_edited )
205  break;
206 
207  default:
208  wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
209  break;
210  }
211 
213  m_canvas->SetIgnoreMouseEvents( false );
214 }
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:754
void deleteItem(wxDC *aDC)
Function deleteItem deletes the currently selected draw item.
Class LIB_ITEM definition.
void GraphicItemBeginDraw(wxDC *DC)
Definition: symbdraw.cpp:234
Class LIB_PART defines a library part object.
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Function SetToolID sets the tool command ID to aId and sets the cursor to aCursor.
Definition: draw_frame.cpp:535
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
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:150
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:406
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:331
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.
int GetDefaultCursor() const
Function GetDefaultCursor return the default cursor shape.
Definition of class LIB_EDIT_FRAME.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Function SaveCopyInUndoList.