modedit_onclick.cpp 15.8 KB
Newer Older
1 2 3
/**
 * @file modedit_onclick.cpp
 */
plyatov's avatar
plyatov committed
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <3d_viewer.h>
#include <wxPcbStruct.h>
#include <gr_basic.h>

#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>

#include <pcbnew.h>
#include <pcbnew_id.h>
#include <hotkeys.h>
#include <module_editor_frame.h>
#include <dialog_edit_module_for_Modedit.h>
21
#include <menus_helpers.h>
22

23 24

void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
25
{
26
    BOARD_ITEM* item = GetCurItem();
27

28
    m_canvas->CrossHairOff( DC );
29

30
    if( GetToolId() == ID_NO_TOOL_SELECTED )
31
    {
32
        if( item && item->GetFlags() ) // Move item command in progress
33
        {
34 35
            switch( item->Type() )
            {
36
            case PCB_MODULE_TEXT_T:
37 38
                PlaceTexteModule( (TEXTE_MODULE*) item, DC );
                break;
39

40
            case PCB_MODULE_EDGE_T:
41 42 43
                SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
                Place_EdgeMod( (EDGE_MODULE*) item );
                break;
44

45
            case PCB_PAD_T:
46 47
                PlacePad( (D_PAD*) item, DC );
                break;
48

49 50 51 52
            default:
            {
                wxString msg;
                msg.Printf( wxT( "WinEDA_ModEditFrame::OnLeftClick err:Struct %d, m_Flag %X" ),
53
                            item->Type(), item->GetFlags() );
54
                DisplayError( this, msg );
55
                item->ClearFlags();
56 57 58
                break;
            }
            }
59
        }
60

61 62 63 64 65
        else
        {
            if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
               && !wxGetKeyState( WXK_CONTROL ) )
                item = ModeditLocateAndDisplay();
66

67 68
            SetCurItem( item );
        }
69 70
    }

71 72 73
    item = GetCurItem();
    bool no_item_edited = item == NULL || item->GetFlags() == 0;

74
    switch( GetToolId() )
75
    {
76
    case ID_NO_TOOL_SELECTED:
77 78
        break;

79 80 81
    case ID_MODEDIT_CIRCLE_TOOL:
    case ID_MODEDIT_ARC_TOOL:
    case ID_MODEDIT_LINE_TOOL:
82
        if( no_item_edited )
83
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
84
            STROKE_T shape = S_SEGMENT;
85

86
            if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL )
87
                shape = S_CIRCLE;
88

89
            if( GetToolId() == ID_MODEDIT_ARC_TOOL )
90 91
                shape = S_ARC;

92
            SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) );
93
        }
94
        else if( item->IsNew() )
95
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
96
            if( ( (EDGE_MODULE*) item )->GetShape() == S_CIRCLE )
97
            {
98
                End_Edge_Module( (EDGE_MODULE*) item );
99
                SetCurItem( NULL );
100
                m_canvas->Refresh();
101
            }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
102
            else if( ( (EDGE_MODULE*) item )->GetShape() == S_ARC )
103
            {
104
                End_Edge_Module( (EDGE_MODULE*) item );
105
                SetCurItem( NULL );
106
                m_canvas->Refresh();
107
            }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
108
            else if( ( (EDGE_MODULE*) item )->GetShape() == S_SEGMENT )
109
            {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
110
                SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, S_SEGMENT ) );
111 112
            }
            else
113
            {
114
                wxMessageBox( wxT( "ProcessCommand error: unknown shape" ) );
115
            }
116 117 118
        }
        break;

119
    case ID_MODEDIT_DELETE_TOOL:
120
        if( ! no_item_edited )    // Item in edit, cannot delete it
121
            break;
122

123
        item = ModeditLocateAndDisplay();
124

125
        if( item && item->Type() != PCB_MODULE_T ) // Cannot delete the module itself
126
        {
127
            SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
128
            RemoveStruct( item );
129
            SetCurItem( NULL );
130
        }
131

132 133
        break;

134
    case ID_MODEDIT_ANCHOR_TOOL:
135 136
        {
            MODULE* module = GetBoard()->m_Modules;
137

138 139 140
            if( module == NULL    // No module loaded
                || (module->GetFlags() != 0) )
                break;
141

142
            SaveCopyInUndoList( module, UR_MODEDIT );
charras's avatar
charras committed
143

144 145 146
            // set the new relative internal local coordinates of footprint items
            wxPoint moveVector = module->GetPosition() - GetCrossHairPosition();
            module->MoveAnchorPosition( moveVector );
147

148 149 150 151
            // Usually, we do not need to change twice the anchor position,
            // so deselect the active tool
            SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
            SetCurItem( NULL );
152
	        m_canvas->Refresh();
153 154
        }
        break;
155

156
    case ID_MODEDIT_PLACE_GRID_COORD:
157 158 159
        m_canvas->DrawGridAxis( DC, GR_XOR, GetBoard()->GetGridOrigin() );
        SetGridOrigin( GetCrossHairPosition() );
        m_canvas->DrawGridAxis( DC, GR_COPY, GetBoard()->GetGridOrigin() );
160 161 162
        GetScreen()->SetModify();
        break;

163
    case ID_MODEDIT_TEXT_TOOL:
164 165
        if( GetBoard()->m_Modules == NULL )
            break;
166

167
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
168
        CreateTextModule( GetBoard()->m_Modules, DC );
169 170
        break;

171
    case ID_MODEDIT_PAD_TOOL:
172
        if( GetBoard()->m_Modules )
173
        {
174
            SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
175
            AddPad( GetBoard()->m_Modules, true );
176
        }
177

178 179 180
        break;

    default:
181
        DisplayError( this, wxT( "FOOTPRINT_EDIT_FRAME::ProcessCommand error" ) );
182
        SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
183 184
    }

185
    m_canvas->CrossHairOn( DC );
plyatov's avatar
plyatov committed
186 187 188
}


189
bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
plyatov's avatar
plyatov committed
190
{
191
    BOARD_ITEM* item = GetCurItem();
charras's avatar
charras committed
192
    wxString    msg;
193
    bool        blockActive = !GetScreen()->m_BlockLocate.IsIdle();
194

195
    // Simple location of elements where possible.
196
    if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
197
    {
198
        SetCurItem( item = ModeditLocateAndDisplay() );
199 200
    }

201
    // End command in progress.
202
    if( GetToolId() != ID_NO_TOOL_SELECTED )
203
    {
204 205 206
        if( item && item->GetFlags() )
            AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ),
                         KiBitmap( cancel_xpm ) );
207
        else
208
            AddMenuItem( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ),
209
                         KiBitmap( cursor_xpm ) );
210

211 212 213 214
        PopMenu->AppendSeparator();
    }
    else
    {
215
        if( (item && item->GetFlags()) || blockActive )
216
        {
217
            if( blockActive )  // Put block commands in list
218
            {
219
                AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
220
                             _( "Cancel Block" ), KiBitmap( cancel_xpm ) );
221 222
                AddMenuItem( PopMenu, ID_POPUP_ZOOM_BLOCK,
                             _( "Zoom Block (drag middle mouse)" ),
223
                             KiBitmap( zoom_area_xpm ) );
224
                PopMenu->AppendSeparator();
225
                AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK,
226
                             _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
227 228
                AddMenuItem( PopMenu, ID_POPUP_COPY_BLOCK,
                             _( "Copy Block (shift + drag mouse)" ),
229
                             KiBitmap( copyblock_xpm ) );
230 231
                AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK,
                             _( "Mirror Block (alt + drag mouse)" ),
232
                             KiBitmap( mirror_h_xpm ) );
233 234
                AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK,
                             _( "Rotate Block (ctrl + drag mouse)" ),
235
                             KiBitmap( rotate_ccw_xpm ) );
236 237
                AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK,
                             _( "Delete Block (shift+ctrl + drag mouse)" ),
238
                             KiBitmap( delete_xpm ) );
239 240 241
            }
            else
            {
242
                AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
243
                             _( "Cancel" ), KiBitmap( cancel_xpm ) );
244
            }
245

246 247 248 249
            PopMenu->AppendSeparator();
        }
    }

250
    if( blockActive )
251
        return true;
252

253
    if( item  )
254
    {
255
        STATUS_FLAGS flags = item->GetFlags();
256
        switch( item->Type() )
257
        {
258 259 260 261
        case PCB_MODULE_T:
            {
            wxMenu* transform_choice = new wxMenu;
            AddMenuItem( transform_choice, ID_MODEDIT_MODULE_ROTATE, _( "Rotate" ),
262
                         KiBitmap( rotate_module_ccw_xpm ) );
263
            AddMenuItem( transform_choice, ID_MODEDIT_MODULE_MIRROR, _( "Mirror" ),
264
                         KiBitmap( mirror_footprint_axisY_xpm ) );
265
            msg = AddHotkeyName( _( "Edit Module" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
266
            AddMenuItem( PopMenu, ID_POPUP_PCB_EDIT_MODULE_PRMS, msg, KiBitmap( edit_module_xpm ) );
267 268 269 270
            AddMenuItem( PopMenu, transform_choice, ID_MODEDIT_TRANSFORM_MODULE,
                         _( "Transform Module" ), KiBitmap( edit_xpm ) );
            break;
            }
271

272 273 274 275 276 277
        case PCB_PAD_T:
            if( !flags )
            {
                msg = AddHotkeyName( _("Move Pad" ), g_Module_Editor_Hokeys_Descr, HK_MOVE_ITEM );
                AddMenuItem( PopMenu, ID_POPUP_PCB_MOVE_PAD_REQUEST, msg, KiBitmap( move_pad_xpm ) );
            }
278

279 280 281 282 283 284 285 286
            msg = AddHotkeyName( _("Edit Pad" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
            AddMenuItem( PopMenu, ID_POPUP_PCB_EDIT_PAD, msg, KiBitmap( options_pad_xpm ) );
            AddMenuItem( PopMenu, ID_POPUP_PCB_IMPORT_PAD_SETTINGS,
                         _( "New Pad Settings" ), KiBitmap( options_new_pad_xpm ) );
            AddMenuItem( PopMenu, ID_POPUP_PCB_EXPORT_PAD_SETTINGS,
                         _( "Export Pad Settings" ), KiBitmap( export_options_pad_xpm ) );
            msg = AddHotkeyName( _("Delete Pad" ), g_Module_Editor_Hokeys_Descr, HK_DELETE );
            AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_PAD, msg, KiBitmap( delete_pad_xpm ) );
287

288 289 290 291 292 293
            if( !flags )
            {
                PopMenu->AppendSeparator();
                AddMenuItem( PopMenu, ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS,
                             _( "Global Pad Settings" ), KiBitmap( global_options_pad_xpm ) );
            }
294

295
            break;
296

297 298 299 300 301 302 303 304
        case PCB_MODULE_TEXT_T:
            if( !flags )
            {
                msg = AddHotkeyName( _("Move Text Mod." ), g_Module_Editor_Hokeys_Descr,
                                     HK_MOVE_ITEM );
                AddMenuItem( PopMenu, ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST, msg,
                             KiBitmap( move_field_xpm ) );
            }
305

306 307 308
            msg = AddHotkeyName( _("Rotate Text Mod." ), g_Module_Editor_Hokeys_Descr,
                                 HK_ROTATE_ITEM );
            AddMenuItem( PopMenu, ID_POPUP_PCB_ROTATE_TEXTMODULE, msg, KiBitmap( rotate_field_xpm ) );
309

310
            if( !flags )
311
            {
312 313 314 315
                msg = AddHotkeyName( _("Edit Text Mod." ), g_Module_Editor_Hokeys_Descr,
                                     HK_EDIT_ITEM );
                AddMenuItem( PopMenu, ID_POPUP_PCB_EDIT_TEXTMODULE, msg, KiBitmap( edit_text_xpm ) );

316
                if( ( (TEXTE_MODULE*) item )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
317 318 319 320 321 322
                {
                    msg = AddHotkeyName( _("Delete Text Mod." ), g_Module_Editor_Hokeys_Descr,
                                         HK_DELETE );
                    AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE, msg,
                                 KiBitmap( delete_text_xpm ) );
                }
323
            }
324
            break;
325

326
        case PCB_MODULE_EDGE_T:
327
        {
328 329
            if( (flags & IS_NEW) )
                AddMenuItem( PopMenu, ID_POPUP_PCB_STOP_CURRENT_DRAWING, _( "End edge" ),
330
                             KiBitmap( checked_ok_xpm ) );
331

332 333
            if( !flags )
            {
334
                msg = AddHotkeyName( _("Move Edge" ), g_Module_Editor_Hokeys_Descr, HK_MOVE_ITEM );
335 336
                AddMenuItem( PopMenu, ID_POPUP_PCB_MOVE_EDGE, msg, KiBitmap( move_line_xpm ) );
            }
337

338 339
            if( ( flags & (IS_NEW | IS_MOVED) ) == IS_MOVED )
                AddMenuItem( PopMenu, ID_POPUP_PCB_PLACE_EDGE, _( "Place edge" ),
340
                             KiBitmap( checked_ok_xpm ) );
341

342 343 344
            msg = AddHotkeyName( _("Edit" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
            AddMenuItem( PopMenu, ID_POPUP_MODEDIT_EDIT_BODY_ITEM,
                         msg, KiBitmap( options_segment_xpm  ) );
345

346
            msg = AddHotkeyName( _("Delete Edge" ), g_Module_Editor_Hokeys_Descr, HK_DELETE );
347
            AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_EDGE, msg, KiBitmap( delete_xpm ) );
348 349 350 351 352 353 354 355

            wxMenu* edit_global_mnu = new wxMenu;
            AddMenuItem( PopMenu, edit_global_mnu, ID_POPUP_MODEDIT_GLOBAL_EDIT_EDGE,
                         _( "Global Changes" ), KiBitmap( edit_xpm ) );
            AddMenuItem( edit_global_mnu, ID_POPUP_MODEDIT_EDIT_WIDTH_ALL_EDGE,
                         _( "Change Body Items Width" ), KiBitmap( width_segment_xpm ) );
            AddMenuItem( edit_global_mnu, ID_POPUP_MODEDIT_EDIT_LAYER_ALL_EDGE,
                         _( "Change Body Items Layer" ), KiBitmap( select_layer_pair_xpm ) );
356
        }
357 358
        break;

359 360 361 362 363 364 365 366
        case PCB_LINE_T:
        case PCB_TEXT_T:
        case PCB_VIA_T:
        case PCB_TRACE_T:
        case PCB_ZONE_T:
        case PCB_MARKER_T:
        case PCB_DIMENSION_T:
        case PCB_TARGET_T:
367 368 369
            msg.Printf( wxT( "FOOTPRINT_EDIT_FRAME::OnRightClick Error: Unexpected DrawType %d" ),
                        item->Type() );
            DisplayError( this, msg );
370
            break;
371

372 373 374 375 376 377 378
        case SCREEN_T:
        case TYPE_NOT_INIT:
        case PCB_T:
            msg.Printf( wxT( "FOOTPRINT_EDIT_FRAME::OnRightClick Error: illegal DrawType %d" ),
                        item->Type() );
            DisplayError( this, msg );
            break;
379

380 381 382 383 384 385 386 387
        default:
            msg.Printf( wxT( "FOOTPRINT_EDIT_FRAME::OnRightClick Error: unknown DrawType %d" ),
                        item->Type() );
            DisplayError( this, msg );
            break;
        }
        PopMenu->AppendSeparator();
    }
388

389 390 391
    if( ( GetToolId() == ID_MODEDIT_LINE_TOOL ) ||
        ( GetToolId() == ID_MODEDIT_CIRCLE_TOOL ) ||
        ( GetToolId() == ID_MODEDIT_ARC_TOOL ) )
392
    {
393
        AddMenuItem( PopMenu, ID_POPUP_MODEDIT_ENTER_EDGE_WIDTH, _("Set Line Width" ),
394
                     KiBitmap( width_segment_xpm ) );
395 396
        PopMenu->AppendSeparator();
    }
397 398

    return true;
plyatov's avatar
plyatov committed
399 400
}

401 402 403
/*
 * Called on a mouse left button double click
 */
404
void FOOTPRINT_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
405
{
406
    BOARD_ITEM* item = GetCurItem();
407

408
    switch( GetToolId() )
409
    {
410
    case ID_NO_TOOL_SELECTED:
411
        if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
412
        {
413
            item = ModeditLocateAndDisplay();
414 415
        }

416
        if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
417 418
            break;

419
        // Item found
420
        SetCurItem( item );
421
        OnEditItemRequest( DC, item );
422 423
        break;      // end case 0

424
    case ID_PCB_ADD_LINE_BUTT:
425
    {
426
        if( item && item->IsNew() )
427
        {
428
            End_Edge_Module( (EDGE_MODULE*) item );
429
            SetCurItem( NULL );
430
            m_canvas->Refresh();
431
        }
432

433 434 435 436 437 438
        break;
    }

    default:
        break;
    }
plyatov's avatar
plyatov committed
439
}
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477


void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem )
{
    switch( aItem->Type() )
    {
    case PCB_PAD_T:
        InstallPadOptionsFrame( (D_PAD*) aItem );
        m_canvas->MoveCursorToCrossHair();
        break;

    case PCB_MODULE_T:
        {
        DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) aItem );
        int ret = dialog.ShowModal();
        GetScreen()->GetCurItem()->ClearFlags();
        m_canvas->MoveCursorToCrossHair();

        if( ret > 0 )
            m_canvas->Refresh();
        }
        break;

    case PCB_MODULE_TEXT_T:
        InstallTextModOptionsFrame( (TEXTE_MODULE*) aItem, aDC );
        m_canvas->MoveCursorToCrossHair();
        break;

    case PCB_MODULE_EDGE_T :
        m_canvas->MoveCursorToCrossHair();
        InstallFootprintBodyItemPropertiesDlg( (EDGE_MODULE*) aItem );
        m_canvas->Refresh();
        break;

    default:
        break;
    }
}