1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eeschema/onleftclick.cpp
*/
#include <fctsys.h>
#include <eeschema_id.h>
#include <class_drawpanel.h>
#include <schframe.h>
#include <menus_helpers.h>
#include <sch_bus_entry.h>
#include <sch_text.h>
#include <sch_marker.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_component.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_bitmap.h>
#include <class_library.h> // fo class SCHLIB_FILTER to filter power parts
// TODO(hzeller): These pairs of elmenets should be represented by an object, but don't want
// to refactor too much right now to not get in the way with other code changes.
static wxArrayString s_CmpNameList;
static int s_CmpLastUnit;
static wxArrayString s_PowerNameList;
static int s_LastPowerUnit;
void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
{
SCH_ITEM* item = GetScreen()->GetCurItem();
wxPoint gridPosition = GetGridPosition( aPosition );
if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) )
{
m_canvas->SetAutoPanRequest( false );
SetRepeatItem( NULL );
if( item && item->GetFlags() )
{
switch( item->Type() )
{
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
case SCH_TEXT_T:
case SCH_SHEET_PIN_T:
case SCH_SHEET_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_BUS_BUS_ENTRY_T:
case SCH_JUNCTION_T:
case SCH_COMPONENT_T:
case SCH_FIELD_T:
case SCH_BITMAP_T:
case SCH_NO_CONNECT_T:
addCurrentItemToList();
return;
case SCH_LINE_T: // May already be drawing segment.
break;
default:
wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) +
item->GetClass() + wxT( "> is already being edited." ) );
item->ClearFlags();
break;
}
}
else
{
item = LocateAndShowItem( aPosition );
}
}
switch( GetToolId() )
{
case ID_NO_TOOL_SELECTED:
break;
case ID_HIERARCHY_PUSH_POP_BUTT:
if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) )
break;
item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly );
if( item ) // The user has clicked on a sheet: this is an enter sheet command
{
m_CurrentSheet->Push( (SCH_SHEET*) item );
DisplayCurrentSheet();
}
else if( m_CurrentSheet->Last() != g_RootSheet )
{ // The user has clicked ouside a sheet:this is an leave sheet command
m_CurrentSheet->Pop();
DisplayCurrentSheet();
}
break;
case ID_NOCONN_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
if( GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) == NULL )
{
SCH_NO_CONNECT* no_connect = AddNoConnect( aDC, gridPosition );
SetRepeatItem( no_connect );
GetScreen()->SetCurItem( no_connect );
m_canvas->SetAutoPanRequest( true );
}
}
else
{
addCurrentItemToList();
}
break;
case ID_JUNCTION_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
if( GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) == NULL )
{
SCH_JUNCTION* junction = AddJunction( aDC, gridPosition, true );
SetRepeatItem( junction );
GetScreen()->SetCurItem( junction );
m_canvas->SetAutoPanRequest( true );
}
}
else
{
addCurrentItemToList();
}
break;
case ID_WIRETOBUS_ENTRY_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
CreateBusWireEntry();
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_BUSTOBUS_ENTRY_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
CreateBusBusEntry();
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
DeleteItemAtCrossHair( aDC );
break;
case ID_WIRE_BUTT:
BeginSegment( aDC, LAYER_WIRE );
m_canvas->SetAutoPanRequest( true );
break;
case ID_BUS_BUTT:
BeginSegment( aDC, LAYER_BUS );
m_canvas->SetAutoPanRequest( true );
break;
case ID_LINE_COMMENT_BUTT:
BeginSegment( aDC, LAYER_NOTES );
m_canvas->SetAutoPanRequest( true );
break;
case ID_TEXT_COMMENT_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_ADD_IMAGE_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateNewImage( aDC ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_LABEL_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_GLABEL_BUTT:
case ID_HIERLABEL_BUTT:
if( (item == NULL) || (item->GetFlags() == 0) )
{
if( GetToolId() == ID_GLABEL_BUTT )
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) );
if( GetToolId() == ID_HIERLABEL_BUTT )
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_HIERLABEL ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_SHEET_SYMBOL_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
item = CreateSheet( aDC );
if( item != NULL )
{
GetScreen()->SetCurItem( item );
m_canvas->SetAutoPanRequest( true );
}
}
else
{
addCurrentItemToList();
}
break;
case ID_IMPORT_HLABEL_BUTT:
case ID_SHEET_PIN_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels );
if( item == NULL )
break;
if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) )
{
if( GetToolId() == ID_IMPORT_HLABEL_BUTT )
GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) );
else
GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) );
}
else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) )
{
addCurrentItemToList();
}
break;
case ID_SCH_PLACE_COMPONENT:
if( (item == NULL) || (item->GetFlags() == 0) )
{
GetScreen()->SetCurItem( Load_Component( aDC, NULL,
s_CmpNameList, s_CmpLastUnit, true ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
case ID_PLACE_POWER_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
SCHLIB_FILTER filter;
filter.FilterPowerParts( true );
GetScreen()->SetCurItem( Load_Component( aDC, &filter,
s_PowerNameList, s_LastPowerUnit, false ) );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList();
}
break;
default:
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) +
wxString::Format( wxT( "%d> selected." ), GetToolId() ) );
}
}
/**
* Function OnLeftDClick
* called on a double click event from the drawpanel mouse handler
* if an editable item is found (text, component)
* Call the suitable dialog editor.
* Id a create command is in progress:
* validate and finish the command
*/
void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
{
EDA_ITEM* item = GetScreen()->GetCurItem();
switch( GetToolId() )
{
case ID_NO_TOOL_SELECTED:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
item = LocateAndShowItem( aPosition );
}
if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
break;
switch( item->Type() )
{
case SCH_SHEET_T:
m_CurrentSheet->Push( (SCH_SHEET*) item );
DisplayCurrentSheet();
break;
case SCH_COMPONENT_T:
EditComponent( (SCH_COMPONENT*) item );
GetCanvas()->MoveCursorToCrossHair();
if( item->GetFlags() == 0 )
GetScreen()->SetCurItem( NULL );
GetCanvas()->Refresh();
break;
case SCH_TEXT_T:
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
EditSchematicText( (SCH_TEXT*) item );
break;
case SCH_BITMAP_T:
EditImage( (SCH_BITMAP*) item );
break;
case SCH_FIELD_T:
EditComponentFieldText( (SCH_FIELD*) item );
GetCanvas()->MoveCursorToCrossHair();
break;
case SCH_MARKER_T:
( (SCH_MARKER*) item )->DisplayMarkerInfo( this );
break;
default:
break;
}
break;
case ID_BUS_BUTT:
case ID_WIRE_BUTT:
case ID_LINE_COMMENT_BUTT:
if( item && item->IsNew() )
EndSegment( aDC );
break;
}
}
|