onrightclick.cpp 25 KB
Newer Older
1 2 3
/********************/
/* onrightclick.cpp */
/********************/
plyatov's avatar
plyatov committed
4 5 6

#include "fctsys.h"
#include "common.h"
7
#include "eeschema_id.h"
8 9
#include "class_drawpanel.h"
#include "confirm.h"
10
#include "bitmaps.h"
plyatov's avatar
plyatov committed
11 12 13

#include "program.h"
#include "general.h"
14
#include "class_marker_sch.h"
plyatov's avatar
plyatov committed
15
#include "protos.h"
16
#include "hotkeys.h"
17
#include "class_library.h"
plyatov's avatar
plyatov committed
18 19


20 21 22 23 24
static void AddMenusForBlock( wxMenu* PopMenu, WinEDA_SchematicFrame* frame );
static void AddMenusForWire( wxMenu* PopMenu, EDA_DrawLineStruct* Wire,
                             WinEDA_SchematicFrame* frame );
static void AddMenusForBus( wxMenu* PopMenu, EDA_DrawLineStruct* Bus,
                            WinEDA_SchematicFrame* frame );
25 26
static void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet );
static void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet );
27 28 29 30 31
static void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text );
static void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label );
static void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel );
static void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* GLabel );
static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
32
static void AddMenusForComponentField( wxMenu* PopMenu, SCH_CMP_FIELD* Field );
33 34
static void AddMenusForJunction( wxMenu* PopMenu, DrawJunctionStruct* Junction,
                                 WinEDA_SchematicFrame* frame );
35
static void AddMenusForMarkers( wxMenu* aPopMenu, MARKER_SCH* aMarker,
36
                                WinEDA_SchematicFrame* aFrame );
plyatov's avatar
plyatov committed
37 38


39 40 41 42
/* Prepare context menu when a click on the right mouse button occurs.
 *
 * This menu is then added to the list of zoom commands.
 */
43
bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos,
44
                                          wxMenu*        PopMenu )
45
{
46
    SCH_ITEM* DrawStruct  = (SCH_ITEM*) GetScreen()->GetCurItem();
47 48
    bool      BlockActive =
        (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE);
49

50 51
    // Do not start a block command  on context menu.
    DrawPanel->m_CanStartBlock = -1;
52

53
    if( BlockActive )
54 55
    {
        AddMenusForBlock( PopMenu, this );
56
        PopMenu->AppendSeparator();
57 58
        return true;
    }
59

60 61
    // Try to locate items at cursor position.
    if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
62
    {
63
        DrawStruct = SchematicGeneralLocateAndDisplay( false );
64
        if( DrawStruct && (DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE) )
65
        {
66 67 68
            SCH_SHEET_PIN* slabel;
            slabel = LocateSheetLabel( (SCH_SHEET*) DrawStruct,
                                       GetScreen()->m_Curseur );
69 70 71 72 73
            if( slabel )
                DrawStruct = slabel;
        }
    }

74
    // If Command in progress: add "cancel" and "end tool" menu
75 76 77 78
    if(  m_ID_current_state )
    {
        if( DrawStruct && DrawStruct->m_Flags )
        {
79 80
            ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
                          _( "Cancel" ), cancel_xpm );
81 82 83
        }
        else
        {
84 85
            ADD_MENUITEM( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL,
                          _( "End Tool" ), cancel_tool_xpm );
86 87 88 89 90
        }
        PopMenu->AppendSeparator();
    }
    else
    {
91
        if( DrawStruct && DrawStruct->m_Flags )
92
        {
93 94
            ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
                          _( "Cancel" ), cancel_xpm );
95
            PopMenu->AppendSeparator();
96 97 98 99 100
        }
    }

    if( DrawStruct == NULL )
    {
101
        if( GetSheet()->Last() != g_RootSheet )
102
        {
103 104
            ADD_MENUITEM( PopMenu, ID_POPUP_SCH_LEAVE_SHEET,
                          _( "Leave Sheet" ), leave_sheet_xpm );
105 106
            PopMenu->AppendSeparator();
        }
107
        return true;
108 109
    }

110
    GetScreen()->SetCurItem( DrawStruct );
111 112 113 114

    int  flags  = DrawStruct->m_Flags;
    bool is_new = (flags & IS_NEW) ? TRUE : FALSE;

115
    switch( DrawStruct->Type() )
116 117 118
    {
    case DRAW_NOCONNECT_STRUCT_TYPE:

119 120
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Noconn" ),
                      delete_xpm );
121 122 123 124 125 126 127 128 129
        break;

    case DRAW_JUNCTION_STRUCT_TYPE:
        AddMenusForJunction( PopMenu, (DrawJunctionStruct*) DrawStruct, this );
        break;

    case DRAW_BUSENTRY_STRUCT_TYPE:
        if( !flags )
            ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
130
                          _( "Move Bus Entry" ), move_xpm );
131
        if( GetBusEntryShape( (DrawBusEntryStruct*) DrawStruct ) == '\\' )
132 133
            PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_SLASH,
                            _( "Set Bus Entry /" ) );
134
        else
135 136
            PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH,
                            _( "Set Bus Entry \\" ) );
137
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
138
                      _( "Delete Bus Entry" ), delete_bus_xpm );
139 140
        break;

141
    case TYPE_MARKER_SCH:
142
        AddMenusForMarkers( PopMenu, (MARKER_SCH*) DrawStruct, this );
143 144
        break;

145 146
    case TYPE_SCH_TEXT:
        AddMenusForText( PopMenu, (SCH_TEXT*) DrawStruct );
147 148
        break;

149 150
    case TYPE_SCH_LABEL:
        AddMenusForLabel( PopMenu, (SCH_LABEL*) DrawStruct );
151 152
        break;

153 154
    case TYPE_SCH_GLOBALLABEL:
        AddMenusForGLabel( PopMenu, (SCH_GLOBALLABEL*) DrawStruct );
155
        break;
156 157 158

    case TYPE_SCH_HIERLABEL:
        AddMenusForHLabel( PopMenu, (SCH_HIERLABEL*) DrawStruct );
159
        break;
160 161 162

    case DRAW_PART_TEXT_STRUCT_TYPE:
    {
163
        AddMenusForComponentField( PopMenu, (SCH_CMP_FIELD*) DrawStruct );
164 165 166
        if( flags )
            break;

167 168 169 170 171
        // Many fields are inside a component. If this is the case, add the
        // component menu
        SCH_COMPONENT* Component =
            LocateSmallestComponent( (SCH_SCREEN*) GetScreen() );

172 173 174
        if( Component )
        {
            PopMenu->AppendSeparator();
175
            AddMenusForComponent( PopMenu, Component );
176 177
        }
    }
178
    break;
179

180 181
    case TYPE_SCH_COMPONENT:
        AddMenusForComponent( PopMenu, (SCH_COMPONENT*) DrawStruct );
182 183 184
        break;

    case DRAW_SEGMENT_STRUCT_TYPE:
185

186
//      if( !flags ) PopMenu->Append(ID_POPUP_SCH_MOVE_ITEM_REQUEST, "Move");
187
        switch( DrawStruct->GetLayer() )
188 189 190 191 192 193 194 195 196 197 198
        {
        case LAYER_WIRE:
            AddMenusForWire( PopMenu, (EDA_DrawLineStruct*) DrawStruct, this );
            break;

        case LAYER_BUS:
            AddMenusForBus( PopMenu, (EDA_DrawLineStruct*) DrawStruct, this );
            break;

        default:
            if( is_new )
199 200
                ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "End Drawing" ),
                              apply_xpm );
201
            ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
202
                          _( "Delete Drawing" ), delete_xpm );
203 204 205 206 207 208
            break;
        }

        break;

    case DRAW_SHEET_STRUCT_TYPE:
209
        AddMenusForHierchicalSheet( PopMenu, (SCH_SHEET*) DrawStruct );
210 211
        break;

charras's avatar
charras committed
212
    case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
213
        AddMenusForPinSheet( PopMenu, (SCH_SHEET_PIN*) DrawStruct );
214 215 216 217
        break;

    default:
        wxString msg;
218 219
        msg.Printf( wxT( "WinEDA_SchematicFrame::OnRightClick Error: unknown \
DrawType %d" ),
220
                    DrawStruct->Type() );
221 222 223 224 225
        DisplayError( this, msg );
        break;
    }

    PopMenu->AppendSeparator();
226
    return true;
plyatov's avatar
plyatov committed
227 228 229
}


230
void AddMenusForComponentField( wxMenu* PopMenu, SCH_CMP_FIELD* Field )
231
{
232
    if( !Field->m_Flags )
233 234 235 236 237 238
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
                      _( "Move Field" ), move_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_FIELD,
                  _( "Rotate Field" ), rotate_field_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_FIELD,
                  _( "Edit Field" ), edit_text_xpm );
plyatov's avatar
plyatov committed
239 240
}

241

242
void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
243
{
244 245 246 247 248 249
    if( Component->Type() != TYPE_SCH_COMPONENT )
    {
        wxASSERT( 0 );
        return;
    }

250 251 252
    wxString       msg;
    CMP_LIB_ENTRY* libEntry;
    LIB_COMPONENT* libComponent = NULL;
253

254
    libEntry = CMP_LIBRARY::FindLibraryEntry( Component->m_ChipName );
255

256 257 258 259 260 261 262
    if( libEntry )
    {
        if( libEntry->Type == ALIAS )
            libComponent = ( (LIB_ALIAS*) libEntry )->GetComponent();
        else
            libComponent = (LIB_COMPONENT*) libEntry;
    }
263 264 265

    if( !Component->m_Flags )
    {
266
        msg = _( "Move Component" );
267
        msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text;
268
        msg = AddHotkeyName( msg, s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT );
269
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_CMP_REQUEST,
270
                      msg, move_xpm );
271 272
        msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr,
                             HK_DRAG_COMPONENT );
273 274
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST,
                      msg, move_xpm );
275 276 277
    }

    wxMenu* orientmenu = new wxMenu;
278 279
    msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr,
                         HK_ROTATE_COMPONENT );
280
    ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE,
281
                  msg, rotate_pos_xpm );
282 283 284 285
    ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE,
                  _( "Rotate -" ), rotate_neg_xpm );
    msg = AddHotkeyName( _( "Mirror --" ), s_Schematic_Hokeys_Descr,
                         HK_MIRROR_X_COMPONENT );
286
    ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_X_CMP, msg, mirror_V_xpm );
287 288
    msg = AddHotkeyName( _( "Mirror ||" ), s_Schematic_Hokeys_Descr,
                         HK_MIRROR_Y_COMPONENT );
289
    ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_Y_CMP, msg, mirror_H_xpm );
290 291
    msg = AddHotkeyName( _( "Normal" ), s_Schematic_Hokeys_Descr,
                         HK_ORIENT_NORMAL_COMPONENT );
292
    ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ORIENT_NORMAL_CMP, msg, normal_xpm );
293
    ADD_MENUITEM_WITH_SUBMENU( PopMenu, orientmenu,
294 295
                               ID_POPUP_SCH_GENERIC_ORIENT_CMP,
                               _( "Orient Component" ), orient_xpm );
296 297

    wxMenu* editmenu = new wxMenu;
298 299
    msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr,
                         HK_EDIT_COMPONENT );
300
    ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, msg,
301
                  edit_component_xpm );
302

303
    if( libEntry && libEntry->m_Options != ENTRY_POWER )
304
    {
305 306 307 308
        msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr,
                             HK_EDIT_COMPONENT_VALUE );
        ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg,
                      edit_comp_value_xpm );
309

310 311
        ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_REF_CMP,
                      _( "Reference" ), edit_comp_ref_xpm );
312

313
        msg = AddHotkeyName( _( "Footprint " ), s_Schematic_Hokeys_Descr,
314
                             HK_EDIT_COMPONENT_FOOTPRINT );
315 316
        ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_FOOTPRINT_CMP, msg,
                      edit_comp_footprint_xpm );
317
    }
318

319 320 321 322
    if( libComponent && libComponent->HasConversion() )
        ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP,
                      _( "Convert" ), component_select_alternate_shape_xpm );

323
    if( libComponent && ( libComponent->GetPartCount() >= 2 ) )
324 325
    {
        wxMenu* sel_unit_menu = new wxMenu; int ii;
326
        for( ii = 0; ii < libComponent->GetPartCount(); ii++ )
327
        {
328 329 330 331
            wxString num_unit;
            num_unit.Printf( _( "Unit %d %c" ), ii + 1,
                             "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ ii + 1 ] );
            sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii, num_unit );
332
        }
333 334 335 336

        ADD_MENUITEM_WITH_SUBMENU( editmenu, sel_unit_menu,
                                   ID_POPUP_SCH_SELECT_UNIT_CMP,
                                   _( "Unit" ), component_select_unit_xpm );
337 338 339
    }

    ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu,
340 341
                               ID_POPUP_SCH_GENERIC_EDIT_CMP,
                               _( "Edit Component" ), edit_component_xpm );
342 343 344

    if( !Component->m_Flags )
    {
345 346 347 348
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_COMPONENT_CMP,
                      _( "Copy Component" ), import_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP,
                      _( "Delete Component" ), delete_xpm );
349 350
    }

351 352 353
    if( libEntry && !libEntry->m_DocFile.IsEmpty() )
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ),
                      datasheet_xpm );
plyatov's avatar
plyatov committed
354 355 356
}


357
void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
358
{
359
    wxMenu*  menu_change_type = new wxMenu;
360
    wxString msg;
361 362

    if( !GLabel->m_Flags )
363
    {
364 365
        msg = AddHotkeyName( _( "Move Global Label" ),
                             s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT );
366
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
367 368
                      msg, move_text_xpm );
    }
369 370 371 372 373 374
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
                  _( "Rotate Global Label" ), rotate_glabel_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
                  _( "Edit Global Label" ), edit_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
                  _( "Delete Global Label" ), delete_text_xpm );
375 376

    // add menu change type text (to label, glabel, text):
377
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
378
                  _( "Change to Hierarchical Label" ), label2glabel_xpm );
379
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
380
                  _( "Change to Label" ), glabel2label_xpm );
381
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
382
                  _( "Change to Text" ), glabel2text_xpm );
383
    ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type,
384 385
                               ID_POPUP_SCH_CHANGE_TYPE_TEXT,
                               _( "Change Type" ), gl_change_xpm );
plyatov's avatar
plyatov committed
386
}
387 388


389
void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
390
{
391
    wxMenu*  menu_change_type = new wxMenu;
392
    wxString msg;
393 394

    if( !HLabel->m_Flags )
395
    {
396 397
        msg = AddHotkeyName( _( "Move Hierarchical Label" ),
                             s_Schematic_Hokeys_Descr,
398
                             HK_MOVE_COMPONENT );
399
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
400 401
                      msg, move_text_xpm );
    }
402 403 404 405 406 407
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
                  _( "Rotate Hierarchical Label" ), rotate_glabel_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
                  _( "Edit Hierarchical Label" ), edit_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
                  _( "Delete Hierarchical label" ), delete_text_xpm );
408 409 410

    // add menu change type text (to label, glabel, text):
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
411
                  _( "Change to Label" ), glabel2label_xpm );
412
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
413
                  _( "Change to Text" ), glabel2text_xpm );
414
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
415
                  _( "Change to Global Label" ), label2glabel_xpm );
416
    ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type,
417 418
                               ID_POPUP_SCH_CHANGE_TYPE_TEXT,
                               _( "Change Type" ), gl_change_xpm );
419
}
plyatov's avatar
plyatov committed
420

421

422
void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
423
{
424
    wxMenu*  menu_change_type = new wxMenu;
425
    wxString msg;
426 427

    if( !Label->m_Flags )
428
    {
429 430
        msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
                             HK_MOVE_COMPONENT );
431
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
432 433
                      msg, move_text_xpm );
    }
434 435 436 437 438 439
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
                  _( "Rotate Label" ), rotate_pos_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
                  _( "Edit Label" ), edit_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
                  _( "Delete Label" ), delete_text_xpm );
440 441

    // add menu change type text (to label, glabel, text):
442
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
443
                  _( "Change to Hierarchical Label" ), label2glabel_xpm );
444
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
445
                  _( "Change to Text" ), label2text_xpm );
446
    ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
447
                  _( "Change to Global Label" ), label2glabel_xpm );
448
    ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type,
449 450
                               ID_POPUP_SCH_CHANGE_TYPE_TEXT,
                               _( "Change Type" ), gl_change_xpm );
plyatov's avatar
plyatov committed
451
}
452 453


454
void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
455
{
456 457 458
    wxMenu* menu_change_type = new wxMenu;

    if( !Text->m_Flags )
459 460 461 462 463 464 465 466
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
                      _( "Move Text" ), move_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Text" ),
                  rotate_pos_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Text" ),
                  edit_text_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Text" ),
                  delete_text_xpm );
467

468 469 470
    /* add menu change type text (to label, glabel, text),
     * but only if this is a single line text
     */
471
    if( Text->m_Text.Find( wxT( "\n" ) ) ==  wxNOT_FOUND )
472 473 474
    {
        ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL,
                      _( "Change to Label" ), label2text_xpm );
475 476 477 478 479 480
        ADD_MENUITEM( menu_change_type,
                      ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
                      _( "Change to Hierarchical Label" ),
                      label2glabel_xpm );
        ADD_MENUITEM( menu_change_type,
                      ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL,
481 482
                      _( "Change to Glabel" ), label2glabel_xpm );
        ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type,
483 484
                                   ID_POPUP_SCH_CHANGE_TYPE_TEXT,
                                   _( "Change Type" ), gl_change_xpm );
485
    }
plyatov's avatar
plyatov committed
486 487 488
}


489 490
void AddMenusForJunction( wxMenu* PopMenu, DrawJunctionStruct* Junction,
                          WinEDA_SchematicFrame* frame )
491
{
492 493 494 495
    bool is_new = (Junction->m_Flags & IS_NEW) ? TRUE : FALSE;

    if( !is_new )
    {
496
        if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(),
497
                        WIREITEM | BUSITEM | EXCLUDE_WIRE_BUS_ENDPOINTS ) )
498 499
            ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE,
                          _( "Break Wire" ), break_line_xpm );
500 501
    }

502 503
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Junction" ),
                  delete_xpm );
504

505
    if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(),
506 507
                    WIREITEM | BUSITEM ) )
    {
508 509 510 511
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE,
                      _( "Delete Node" ), delete_node_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION,
                      _( "Delete Connection" ), delete_connection_xpm );
512
    }
plyatov's avatar
plyatov committed
513 514
}

515 516 517

void AddMenusForWire( wxMenu* PopMenu, EDA_DrawLineStruct* Wire,
                      WinEDA_SchematicFrame* frame )
518
{
519 520 521 522
    bool    is_new = (Wire->m_Flags & IS_NEW) ? TRUE : FALSE;
    wxPoint pos    = frame->GetScreen()->m_Curseur;

    if( is_new )
523
    {
524
        ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "Wire End" ), apply_xpm );
525
        return;
526
    }
527

528 529
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, _( "Drag Wire" ),
                  move_track_xpm );
530 531
    PopMenu->AppendSeparator();
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Wire" ), delete_xpm );
532 533 534 535
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ),
                  delete_node_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION,
                  _( "Delete Connection" ), delete_connection_xpm );
536

537
    if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(),
538
                    WIREITEM | BUSITEM | EXCLUDE_WIRE_BUS_ENDPOINTS ) )
539 540
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ),
                      break_line_xpm );
541 542 543

    PopMenu->AppendSeparator();

544 545 546 547
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ),
                  add_junction_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ),
                  add_line_label_xpm );
548

549
    // Add global label command only if the cursor is over one end of the wire.
550 551
    if( ( pos.x == Wire->m_Start.x && pos.y == Wire->m_Start.y)
       || ( pos.x == Wire->m_End.x && pos.y == Wire->m_End.y ) )
552 553
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL,
                      _( "Add Global Label" ), add_glabel_xpm );
plyatov's avatar
plyatov committed
554 555
}

556 557 558

void AddMenusForBus( wxMenu* PopMenu, EDA_DrawLineStruct* Bus,
                     WinEDA_SchematicFrame* frame )
559
{
560 561 562 563
    bool    is_new = (Bus->m_Flags & IS_NEW) ? TRUE : FALSE;
    wxPoint pos    = frame->GetScreen()->m_Curseur;

    if( is_new )
564
    {
565
        ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "Bus End" ), apply_xpm );
566 567
        return;
    }
568

569 570
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Bus" ),
                  delete_bus_xpm );
571

572 573
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Bus" ),
                  break_bus_xpm );
574 575

    PopMenu->AppendSeparator();
576 577 578 579
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ),
                  add_junction_xpm );
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ),
                  add_line_label_xpm );
580

581
    // Add global label command only if the cursor is over one end of the bus.
582 583
    if( ( pos.x == Bus->m_Start.x && pos.y == Bus->m_Start.y)
       || ( pos.x == Bus->m_End.x && pos.y == Bus->m_End.y ) )
584 585
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL,
                      _( "Add Global Label" ), add_glabel_xpm );
plyatov's avatar
plyatov committed
586 587
}

588

589
void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
590
{
591 592
    if( !Sheet->m_Flags )
    {
593 594
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET,
                      _( "Enter Sheet" ), enter_sheet_xpm );
595
        PopMenu->AppendSeparator();
596 597
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
                      _( "Move Sheet" ), move_sheet_xpm );
598 599 600 601
    }

    if( Sheet->m_Flags )
    {
602 603
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ),
                      apply_xpm );
604 605 606
    }
    else
    {
607 608 609 610
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET, _( "Edit Sheet" ),
                      edit_sheet_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_RESIZE_SHEET, _( "Resize Sheet" ),
                      resize_sheet_xpm );
charras's avatar
charras committed
611
        PopMenu->AppendSeparator();
612 613
        ADD_MENUITEM( PopMenu, ID_POPUP_IMPORT_GLABEL, _( "Import PinSheets" ),
                      import_hierarchical_label_xpm );
614 615 616
        if( Sheet->m_Label )  // Sheet has pin labels, and can be cleaned
            ADD_MENUITEM( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET,
                          _( "Cleanup PinSheets" ), options_pinsheet_xpm );
charras's avatar
charras committed
617
        PopMenu->AppendSeparator();
618 619
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Sheet" ),
                      delete_sheet_xpm );
620
    }
plyatov's avatar
plyatov committed
621 622 623
}


624
void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
625
{
626
    if( !PinSheet->m_Flags )
627 628
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_PINSHEET,
                      _( "Move PinSheet" ), move_xpm );
plyatov's avatar
plyatov committed
629

630 631
    ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_PINSHEET, _( "Edit PinSheet" ),
                  edit_xpm );
plyatov's avatar
plyatov committed
632

633
    if( !PinSheet->m_Flags )
634 635
        ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete PinSheet" ),
                      delete_pinsheet_xpm );
plyatov's avatar
plyatov committed
636 637
}

638 639

void AddMenusForBlock( wxMenu* PopMenu, WinEDA_SchematicFrame* frame )
640 641 642
{
    ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
                  _( "Cancel Block" ), cancel_xpm );
643 644 645

    PopMenu->AppendSeparator();

646
    if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
647 648
        ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK, _( "Window Zoom" ),
                      zoom_selected_xpm );
649

650
    ADD_MENUITEM( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), apply_xpm );
651

652 653 654
    // After a block move (that is also a block selection) one can reselect
    // a block function.
    if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
655
    {
656
        ADD_MENUITEM( PopMenu, wxID_COPY, _( "Save Block" ), copy_button );
657 658 659 660 661 662 663 664
        ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ),
                      copyblock_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_DRAG_BLOCK, _( "Drag Block" ),
                      move_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ),
                      delete_xpm );
        ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_Y_BLOCK,
                      _( "Mirror Block ||" ), mirror_H_xpm );
plyatov's avatar
plyatov committed
665
#if 0
666
  #ifdef __WINDOWS__
667 668
        ADD_MENUITEM( menu_other_block_commands,
                      ID_GEN_COPY_BLOCK_TO_CLIPBOARD,
669
                      _( "Copy to Clipboard" ), copy_button );
plyatov's avatar
plyatov committed
670 671
  #endif
#endif
672
    }
plyatov's avatar
plyatov committed
673
}
674

675

676
void AddMenusForMarkers( wxMenu* aPopMenu, MARKER_SCH* aMarker,
677
                         WinEDA_SchematicFrame* aFrame )
678
{
679 680 681 682
    ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_DELETE, _( "Delete Marker" ),
                  delete_xpm );
    ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_GETINFO_MARKER,
                  _( "Marker Error Info" ), info_xpm );
683
}