KiCad PCB EDA Suite
eeschema/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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2017 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 
30 #include <fctsys.h>
31 #include <kiway.h>
32 #include <eeschema_id.h>
33 #include <class_drawpanel.h>
34 #include <confirm.h>
35 #include <schframe.h>
36 #include <sim/sim_plot_frame.h>
37 #include <menus_helpers.h>
38 
39 #include <sch_bus_entry.h>
40 #include <sch_text.h>
41 #include <sch_marker.h>
42 #include <sch_junction.h>
43 #include <sch_line.h>
44 #include <sch_no_connect.h>
45 #include <sch_component.h>
46 #include <sch_sheet.h>
47 #include <sch_sheet_path.h>
48 #include <sch_bitmap.h>
49 
50 #include <class_netlist_object.h>
51 #include <class_library.h> // fo class SCHLIB_FILTER to filter power parts
52 
53 
54 // TODO(hzeller): These pairs of elmenets should be represented by an object, but don't want
55 // to refactor too much right now to not get in the way with other code changes.
58 
59 
60 void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
61 {
62  SCH_ITEM* item = GetScreen()->GetCurItem();
63  wxPoint gridPosition = GetGridPosition( aPosition );
64 
65  if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) )
66  {
67  m_canvas->SetAutoPanRequest( false );
68  SetRepeatItem( NULL );
69 
70  if( item && item->GetFlags() )
71  {
72  switch( item->Type() )
73  {
74  case SCH_LABEL_T:
75  case SCH_GLOBAL_LABEL_T:
77  case SCH_TEXT_T:
78  case SCH_SHEET_PIN_T:
79  case SCH_SHEET_T:
82  case SCH_JUNCTION_T:
83  case SCH_COMPONENT_T:
84  case SCH_FIELD_T:
85  case SCH_BITMAP_T:
86  case SCH_NO_CONNECT_T:
88  return;
89 
90  case SCH_LINE_T: // May already be drawing segment.
91  break;
92 
93  default:
94  wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) +
95  item->GetClass() + wxT( "> is already being edited." ) );
96  item->ClearFlags();
97  break;
98  }
99  }
100  else
101  {
102  item = LocateAndShowItem( aPosition );
103  }
104  }
105 
106  switch( GetToolId() )
107  {
108  case ID_NO_TOOL_SELECTED:
109  break;
110 
111  case ID_ZOOM_SELECTION:
112  break;
113 
114  case ID_HIGHLIGHT:
115  HighlightConnectionAtPosition( aPosition );
116  break;
117 
118  case ID_NOCONN_BUTT:
119  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
120  {
121  if( GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) == NULL )
122  {
123  SCH_NO_CONNECT* no_connect = AddNoConnect( aDC, gridPosition );
124  SetRepeatItem( no_connect );
125  GetScreen()->SetCurItem( no_connect );
126  m_canvas->SetAutoPanRequest( true );
127  }
128  }
129  else
130  {
132  }
133  break;
134 
135  case ID_JUNCTION_BUTT:
136  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
137  {
138  if( GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) == NULL )
139  {
140  SCH_JUNCTION* junction = AddJunction( aDC, gridPosition, true );
141  SetRepeatItem( junction );
142  GetScreen()->SetCurItem( junction );
143  m_canvas->SetAutoPanRequest( true );
144  }
145  }
146  else
147  {
149  }
150  break;
151 
153  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
154  {
156  m_canvas->SetAutoPanRequest( true );
157  }
158  else
159  {
161  }
162  break;
163 
165  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
166  {
168  m_canvas->SetAutoPanRequest( true );
169  }
170  else
171  {
173  }
174  break;
175 
177  DeleteItemAtCrossHair( aDC );
178  break;
179 
180  case ID_WIRE_BUTT:
181  BeginSegment( aDC, LAYER_WIRE );
182  m_canvas->SetAutoPanRequest( true );
183  break;
184 
185  case ID_BUS_BUTT:
186  BeginSegment( aDC, LAYER_BUS );
187  m_canvas->SetAutoPanRequest( true );
188  break;
189 
191  BeginSegment( aDC, LAYER_NOTES );
192  m_canvas->SetAutoPanRequest( true );
193  break;
194 
196  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
197  {
199  m_canvas->SetAutoPanRequest( true );
200  }
201  else
202  {
204  }
205  break;
206 
207  case ID_ADD_IMAGE_BUTT:
208  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
209  {
210  GetScreen()->SetCurItem( CreateNewImage( aDC ) );
211  m_canvas->SetAutoPanRequest( true );
212  }
213  else
214  {
216  }
217  break;
218 
219  case ID_LABEL_BUTT:
220  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
221  {
223  m_canvas->SetAutoPanRequest( true );
224  }
225  else
226  {
228  }
229  break;
230 
231  case ID_GLABEL_BUTT:
232  case ID_HIERLABEL_BUTT:
233  if( (item == NULL) || (item->GetFlags() == 0) )
234  {
235  if( GetToolId() == ID_GLABEL_BUTT )
237 
238  if( GetToolId() == ID_HIERLABEL_BUTT )
240 
241  m_canvas->SetAutoPanRequest( true );
242  }
243  else
244  {
246  }
247  break;
248 
250  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
251  {
252  item = CreateSheet( aDC );
253 
254  if( item != NULL )
255  {
256  GetScreen()->SetCurItem( item );
257  m_canvas->SetAutoPanRequest( true );
258  }
259  }
260  else
261  {
263  }
264  break;
265 
267  case ID_SHEET_PIN_BUTT:
268  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
270 
271  if( item == NULL )
272  break;
273 
274  if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) )
275  {
277  GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) );
278  else
279  GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) );
280  }
281  else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) )
282  {
284  }
285  break;
286 
288  if( (item == NULL) || (item->GetFlags() == 0) )
289  {
290  GetScreen()->SetCurItem( Load_Component( aDC, NULL,
291  s_CmpNameList, true ) );
292  m_canvas->SetAutoPanRequest( true );
293  }
294  else
295  {
297  }
298  break;
299 
300  case ID_PLACE_POWER_BUTT:
301  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
302  {
303  SCHLIB_FILTER filter;
304  filter.FilterPowerParts( true );
305  GetScreen()->SetCurItem( Load_Component( aDC, &filter,
306  s_PowerNameList, false ) );
307  m_canvas->SetAutoPanRequest( true );
308  }
309  else
310  {
312  }
313  break;
314 
315 #ifdef KICAD_SPICE
316  case ID_SIM_PROBE:
317  {
318  constexpr KICAD_T wiresAndComponents[] = { SCH_LINE_T,
320  item = LocateAndShowItem( aPosition, wiresAndComponents );
321 
322  if( !item )
323  break;
324 
326 
327  for( NETLIST_OBJECT* obj : *netlist )
328  {
329  if( obj->m_Comp == item )
330  {
331  SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
332 
333  if( simFrame )
334  simFrame->AddVoltagePlot( obj->GetNetName() );
335 
336  break;
337  }
338  }
339  }
340  break;
341 
342  case ID_SIM_TUNE:
343  {
344  constexpr KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT };
345  item = LocateAndShowItem( aPosition, fieldsAndComponents );
346 
347  if( !item )
348  return;
349 
350  if( item->Type() != SCH_COMPONENT_T )
351  {
352  item = static_cast<SCH_ITEM*>( item->GetParent() );
353 
354  if( item->Type() != SCH_COMPONENT_T )
355  return;
356  }
357 
358  SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
359 
360  if( simFrame )
361  simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) );
362  }
363  break;
364 #endif /* KICAD_SPICE */
365 
366  default:
368  wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) +
369  wxString::Format( wxT( "%d> selected." ), GetToolId() ) );
370  }
371 }
372 
373 
382 void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
383 
384 {
385  EDA_ITEM* item = GetScreen()->GetCurItem();
386 
387  switch( GetToolId() )
388  {
389  case ID_NO_TOOL_SELECTED:
390  if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
391  {
392  item = LocateAndShowItem( aPosition );
393  }
394 
395  if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
396  break;
397 
398  switch( item->Type() )
399  {
400  case SCH_SHEET_T:
401  m_CurrentSheet->push_back( (SCH_SHEET*) item );
403  break;
404 
405  case SCH_COMPONENT_T:
406  EditComponent( (SCH_COMPONENT*) item );
408 
409  if( item->GetFlags() == 0 )
410  GetScreen()->SetCurItem( NULL );
411 
412  GetCanvas()->Refresh();
413  break;
414 
415  case SCH_TEXT_T:
416  case SCH_LABEL_T:
417  case SCH_GLOBAL_LABEL_T:
419  EditSchematicText( (SCH_TEXT*) item );
420  break;
421 
422  case SCH_BITMAP_T:
423  EditImage( (SCH_BITMAP*) item );
424  break;
425 
426  case SCH_FIELD_T:
429  break;
430 
431  case SCH_MARKER_T:
432  ( (SCH_MARKER*) item )->DisplayMarkerInfo( this );
433  break;
434 
435  default:
436  break;
437  }
438 
439  break;
440 
441  case ID_BUS_BUTT:
442  case ID_WIRE_BUTT:
444  if( item && item->IsNew() )
445  EndSegment( aDC );
446 
447  break;
448  }
449 }
Definition of the SCH_SHEET class for Eeschema.
SCH_NO_CONNECT * AddNoConnect(wxDC *aDC, const wxPoint &aPosition)
Function AddNoConnect add a no connect item to the current schematic sheet at aPosition.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void EditComponent(SCH_COMPONENT *aComponent)
Function EditComponent displays the edit component dialog to edit the parameters of aComponent...
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:269
static const KICAD_T SheetsAndSheetLabels[]
A scan list for schematic sheet and sheet label items.
NETLIST_OBJECT_LIST * BuildNetListBase(bool updateStatusText=true)
BuildNetListBase netlist generation: Creates a flat list which stores all connected objects...
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
SCH_JUNCTION * AddJunction(wxDC *aDC, const wxPoint &aPosition, bool aPutInUndoList=false)
Function AddJunction adds a new junction at aPosition.
void FilterPowerParts(bool aFilterEnable)
set the filtering of power parts
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:230
wxPoint GetGridPosition(const wxPoint &aPosition) const
Function GetGridPosition returns the nearest grid position to aPosition if a screen is defined and sn...
Definition: draw_frame.cpp:586
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:337
void addCurrentItemToList(bool aRedraw=true)
Function addCurrentItemToList adds the item currently being edited to the schematic and adds the chan...
Definition: schframe.cpp:1307
EDA_ITEM * GetParent() const
Definition: base_struct.h:222
std::vector< COMPONENT_SELECTION > HISTORY_LIST
void AddVoltagePlot(const wxString &aNetName)
Adds a voltage plot for a given net name.
void BeginSegment(wxDC *DC, int type)
Function BeginSegment creates a new segment ( WIRE, BUS ) or terminates the current segment in progre...
SCH_TEXT * CreateNewText(wxDC *aDC, int aType)
Definition: edit_label.cpp:66
void DisplayCurrentSheet()
Function DisplayCurrentSheet draws the current sheet on the display.
Definition: hierarch.cpp:279
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:347
void EditComponentFieldText(SCH_FIELD *aField)
Function EditComponentFieldText displays the edit field dialog to edit the parameters of aField...
search types array terminator (End Of Types)
Definition: typeinfo.h:94
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
void SetRepeatItem(SCH_ITEM *aItem)
Function SetRepeatItem clones aItem and owns that clone in this container.
Definition: schframe.cpp:469
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet, wxDC *aDC)
Function CreateSheetPin creates a new SCH_SHEET_PIN object and add it to aSheet at the current cursor...
Definition: sheetlab.cpp:110
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:530
void EndSegment(wxDC *DC)
Function EndSegment called to terminate a bus, wire, or line creation.
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
Definition: schframe.h:120
SCH_BUS_BUS_ENTRY * CreateBusBusEntry()
Definition: busentry.cpp:42
SCH_ITEM * LocateAndShowItem(const wxPoint &aPosition, const KICAD_T aFilterList[]=SCH_COLLECTOR::AllItems, int aHotKeyCommandId=0)
Function LocateAndShowItem checks the schematic at aPosition in logical (drawing) units for a item ma...
static SCH_BASE_FRAME::HISTORY_LIST s_PowerNameList
SCH_SHEET * CreateSheet(wxDC *DC)
Definition: sheet.cpp:352
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
bool HighlightConnectionAtPosition(wxPoint aPosition)
Function HighlightConnectionAtPosition Highlight the connection found at aPosition.
bool DeleteItemAtCrossHair(wxDC *aDC)
Function DeleteItemAtCrossHair delete the item found under the cross hair.
Definition: schedit.cpp:665
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
static SCH_BASE_FRAME::HISTORY_LIST s_CmpNameList
void SetAutoPanRequest(bool aEnable)
void EditSchematicText(SCH_TEXT *TextStruct)
SCH_BITMAP * CreateNewImage(wxDC *aDC)
Implementing SIM_PLOT_FRAME_BASE.
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
Definition of the NETLIST_OBJECT class.
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
Definition the SCH_COMPONENT class for Eeschema.
SCH_COMPONENT * Load_Component(wxDC *aDC, const SCHLIB_FILTER *aFilter, SCH_BASE_FRAME::HISTORY_LIST &aHistoryList, bool aUseLibBrowser)
Function Load_Component loads from a library and places a component.
Definition: getpart.cpp:192
void OnLeftDClick(wxDC *aDC, const wxPoint &aPosition) override
Function OnLeftDClick called on a double click event from the drawpanel mouse handler if an editable ...
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
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=NOT_USED) const
Function GetItem checks aPosition within a distance of aAccuracy for items of type aFilter...
Definition: sch_screen.cpp:203
void OnLeftClick(wxDC *aDC, const wxPoint &aPosition) override
int GetToolId() const
Definition: draw_frame.h:471
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
void EditImage(SCH_BITMAP *aItem)
virtual wxString GetClass() const override
Function GetClass returns the class name.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
SCH_SHEET_PIN * ImportSheetPin(SCH_SHEET *aSheet, wxDC *aDC)
Function ImportSheetPin automatically creates a sheet pin from the hierarchical labels in the schemat...
Definition: sheetlab.cpp:140
Definition for part library class.
void AddTuner(SCH_COMPONENT *aComponent)
Adds a tuner for a component.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_BUS_WIRE_ENTRY * CreateBusWireEntry()
Definition: busentry.cpp:53
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Implementation of the label properties dialog.