modedit.cpp 24.8 KB
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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
/****************/
/* modedit.cpp  */
/****************/

#include "fctsys.h"
#include "appl_wxstruct.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "gestfich.h"
#include "appl_wxstruct.h"
#include "bitmaps.h"
#include "pcbnew_id.h"
#include "trigo.h"

#include "3d_viewer.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
#include "protos.h"

#include "dialog_edit_module_for_Modedit.h"

#include "collectors.h"


BOARD_ITEM* WinEDA_ModuleEditFrame::ModeditLocateAndDisplay( int aHotKeyCode )
{
    BOARD_ITEM* item = GetCurItem();

    if( GetBoard()->m_Modules == NULL )
        return NULL;
    GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();

    // Assign to scanList the proper item types desired based on tool type
    // or hotkey that is in play.

    const KICAD_T* scanList = NULL;

    if( aHotKeyCode )
    {
        // @todo: add switch here and add calls to PcbGeneralLocateAndDisplay(
        // int aHotKeyCode ) when searching is needed from a hotkey handler
    }
    else
    {
        scanList = GENERAL_COLLECTOR::ModulesAndTheirItems;
    }

    m_Collector->Collect( GetBoard(), scanList, GetScreen()->RefPos(
                              true ), guide );

    /* Remove redundancies: when an item is found, we can remove the
     * module from list
     */
    if( m_Collector->GetCount() > 1 )
    {
        for( int ii = 0; ii < m_Collector->GetCount(); ii++ )
        {
            item = (*m_Collector)[ii];
            if( item->Type() != TYPE_MODULE )
                continue;
            m_Collector->Remove( ii );
            ii--;
        }
    }

    if( m_Collector->GetCount() <= 1 )
    {
        item = (*m_Collector)[0];
        SetCurItem( item );
    }
    else    // we can't figure out which item user wants, do popup menu so user
            // can choose
    {
        wxMenu      itemMenu;

        /* Give a title to the selection menu. This is also a cancel
         * menu item **/
        wxMenuItem* item_title =
            new wxMenuItem( &itemMenu, -1, _( "Selection Clarification" ) );
#ifdef __WINDOWS__
        wxFont      bold_font( *wxNORMAL_FONT );
        bold_font.SetWeight( wxFONTWEIGHT_BOLD );
        bold_font.SetStyle( wxFONTSTYLE_ITALIC );
        item_title->SetFont( bold_font );
#endif
        itemMenu.Append( item_title );
        itemMenu.AppendSeparator();

        int limit = MIN( MAX_ITEMS_IN_PICKER, m_Collector->GetCount() );

        for( int ii = 0; ii<limit; ++ii )
        {
            wxString     text;
            const char** xpm;

            item = (*m_Collector)[ii];

            text = item->MenuText( GetBoard() );
            xpm  = item->MenuIcon();

            ADD_MENUITEM( &itemMenu,
                          ID_POPUP_PCB_ITEM_SELECTION_START + ii,
                          text,
                          xpm );
        }

        // this menu's handler is void
        // WinEDA_BasePcbFrame::ProcessItemSelection()
        // and it calls SetCurItem() which in turn calls DisplayInfo() on the
        // item.
        DrawPanel->m_AbortRequest = true;   // changed in false if an item
        PopupMenu( &itemMenu );             // m_AbortRequest = false if an
                                            // item is selected

        DrawPanel->MouseToCursorSchema();

        DrawPanel->m_IgnoreMouseEvents = FALSE;

        // The function ProcessItemSelection() has set the current item, return
        // it.
        item = GetCurItem();
    }

    if( item )
    {
        item->DisplayInfo( this );
    }

    return item;
}


void WinEDA_ModuleEditFrame::LoadModuleFromBoard( wxCommandEvent& event )
{
    GetScreen()->ClearUndoRedoList();
    Load_Module_From_BOARD( NULL );
    GetScreen()->ClrModify();

    if( m_Draw3DFrame )
        m_Draw3DFrame->NewDisplay();
}


void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event )
{
    int        id = event.GetId();
    wxPoint    pos;
    bool       redraw = false;

    wxClientDC dc( DrawPanel );

    DrawPanel->PrepareGraphicContext( &dc );
    wxGetMousePosition( &pos.x, &pos.y );

    pos.y += 20;

    switch( id )
    {
    case wxID_CUT:
    case wxID_COPY:
    case ID_TOOLBARH_PCB_SELECT_LAYER:
    case ID_MODEDIT_PAD_SETTINGS:
    case ID_PCB_USER_GRID_SETUP:
    case ID_POPUP_PCB_ROTATE_TEXTEPCB:
    case ID_POPUP_PCB_EDIT_TEXTEPCB:
    case ID_POPUP_PCB_ROTATE_TEXTMODULE:
    case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE:
    case ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE:
    case ID_POPUP_PCB_EDIT_TEXTMODULE:
    case ID_POPUP_PCB_IMPORT_PAD_SETTINGS:
    case ID_POPUP_PCB_EXPORT_PAD_SETTINGS:
    case ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS:
    case ID_POPUP_PCB_STOP_CURRENT_DRAWING:
    case ID_POPUP_PCB_EDIT_EDGE:
    case ID_POPUP_PCB_EDIT_WIDTH_CURRENT_EDGE:
    case ID_POPUP_PCB_EDIT_WIDTH_ALL_EDGE:
    case ID_POPUP_PCB_EDIT_LAYER_CURRENT_EDGE:
    case ID_POPUP_PCB_EDIT_LAYER_ALL_EDGE:
    case ID_POPUP_PCB_ENTER_EDGE_WIDTH:
    case ID_POPUP_DELETE_BLOCK:
    case ID_POPUP_PLACE_BLOCK:
    case ID_POPUP_ZOOM_BLOCK:
    case ID_POPUP_MIRROR_X_BLOCK:
    case ID_POPUP_ROTATE_BLOCK:
    case ID_POPUP_COPY_BLOCK:
        break;

    case ID_POPUP_CANCEL_CURRENT_COMMAND:
    default:
        if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
        {
            //  for all other commands: stop the move in progress
            DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
        }
        if( id != ID_POPUP_CANCEL_CURRENT_COMMAND )
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
        break;
    }

    switch( id )
    {
    case ID_EXIT:
        Close( true );
        break;

    case ID_MODEDIT_SELECT_CURRENT_LIB:
        Select_Active_Library();
        break;

    case ID_MODEDIT_DELETE_PART:
    {
        wxFileName fn = wxFileName( wxEmptyString, m_CurrentLib,
                                    ModuleFileExtension );
        wxString   full_libraryfilename = wxGetApp().FindLibraryPath( fn );
        if( wxFileName::FileExists( full_libraryfilename ) )
            Delete_Module_In_Library( full_libraryfilename );
        break;
    }

    case ID_MODEDIT_NEW_MODULE:
    {
        Clear_Pcb( true );
        GetScreen()->ClearUndoRedoList();
        SetCurItem( NULL );
        GetScreen()->m_Curseur = wxPoint( 0, 0 );

        MODULE* module = Create_1_Module( NULL, wxEmptyString );
        if( module )        // i.e. if create module command not aborted
        {
            // Initialize data relative to nets and netclasses (for a new
            // module the defaults are used)
            // This is mandatory to handle and draw pads
            GetBoard()->m_NetInfo->BuildListOfNets();
            redraw = true;
            module->SetPosition( wxPoint( 0, 0 ) );
            if( GetBoard()->m_Modules )
                GetBoard()->m_Modules->m_Flags = 0;
            Zoom_Automatique( true );
        }
        break;
    }

    case ID_MODEDIT_SAVE_LIBMODULE:
    {
        wxFileName fn;
        fn = wxFileName( wxEmptyString, m_CurrentLib, ModuleFileExtension );
        wxString   full_filename = wxGetApp().FindLibraryPath( fn );
        Save_Module_In_Library( full_filename, GetBoard()->m_Modules,
                                true, true, true );
        GetScreen()->ClrModify();
        break;
    }

    case ID_MODEDIT_INSERT_MODULE_IN_BOARD:
    case ID_MODEDIT_UPDATE_MODULE_IN_BOARD:
    {
        // update module in the current board,
        // not just add it to the board with total disregard for the netlist...
        WinEDA_PcbFrame* pcbframe = (WinEDA_PcbFrame*) GetParent();
        BOARD*           mainpcb  = pcbframe->GetBoard();
        MODULE*          source_module  = NULL;
        MODULE*          module_in_edit = GetBoard()->m_Modules;

        // Search the old module (source) if exists
        // Because this source could be deleted when editing the main board...
        if( module_in_edit->m_Link )        // this is not a new module ...
        {
            source_module = mainpcb->m_Modules;
            for( ;
                source_module != NULL;
                source_module = (MODULE*) source_module->Next() )
            {
                if( module_in_edit->m_Link == source_module->m_TimeStamp )
                    break;
            }
        }
        if( ( source_module == NULL )
            && ( id == ID_MODEDIT_UPDATE_MODULE_IN_BOARD ) ) // source not found
        {
            wxString msg;
            msg.Printf( _( "Unable to find the footprint source on the main board" ) );
            msg << _( "\nCannot update the footprint" );
            DisplayError( this, msg );
            break;
        }

        if( ( source_module != NULL )
            && ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found
        {
            wxString msg;
            msg.Printf( _( "A footprint source was found on the main board" ) );
            msg << _( "\nCannot insert this footprint" );
            DisplayError( this, msg );
            break;
        }

        // Create the "new" module
        MODULE* newmodule = new MODULE( mainpcb );
        newmodule->Copy( module_in_edit );
        newmodule->m_Link = 0;

        // Put the footprint in the main pcb linked list.
        mainpcb->Add( newmodule );

        if( source_module )         // this is an update command
        {
            // In the main board,
            // the new module replace the old module (pos, orient, ref, value
            // and connexions are kept)
            // and the source_module (old module) is deleted
            PICKED_ITEMS_LIST pickList;
            pcbframe->Exchange_Module( source_module, newmodule, &pickList );
            newmodule->m_TimeStamp = module_in_edit->m_Link;
            if( pickList.GetCount() )
                pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
        }
        else        // This is an insert command
        {
            wxPoint cursor_pos = pcbframe->GetScreen()->m_Curseur;
            pcbframe->GetScreen()->m_Curseur = wxPoint( 0, 0 );
            pcbframe->Place_Module( newmodule, NULL );
            pcbframe->GetScreen()->m_Curseur = cursor_pos;
            newmodule->m_TimeStamp = GetTimeStamp();
            pcbframe->SaveCopyInUndoList( newmodule, UR_NEW );
        }

        newmodule->m_Flags = 0;
        GetScreen()->ClrModify();
        pcbframe->SetCurItem( NULL );
        mainpcb->m_Status_Pcb = 0;
    }
    break;

    case ID_MODEDIT_IMPORT_PART:
        GetScreen()->ClearUndoRedoList();
        SetCurItem( NULL );
        Clear_Pcb( true );
        GetScreen()->m_Curseur = wxPoint( 0, 0 );
        Import_Module( NULL );
        redraw = true;
        if( GetBoard()->m_Modules )
            GetBoard()->m_Modules->m_Flags = 0;
        GetScreen()->ClrModify();
        Zoom_Automatique( true );
        if( m_Draw3DFrame )
            m_Draw3DFrame->NewDisplay();
        break;

    case ID_MODEDIT_EXPORT_PART:
        if( GetBoard()->m_Modules )
            Export_Module( GetBoard()->m_Modules, FALSE );
        break;

    case ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART:
        if( GetBoard()->m_Modules )
            Export_Module( GetBoard()->m_Modules, true );
        break;

    case ID_MODEDIT_SHEET_SET:
        break;

    case ID_MODEDIT_LOAD_MODULE:
    {
        wxString full_libraryfilename;
        if( !m_CurrentLib.IsEmpty() )
        {
            wxFileName fn = wxFileName( wxEmptyString, m_CurrentLib,
                                        ModuleFileExtension );
            full_libraryfilename = wxGetApp().FindLibraryPath( fn );
        }

        GetScreen()->ClearUndoRedoList();
        SetCurItem( NULL );
        Clear_Pcb( true );
        GetScreen()->m_Curseur = wxPoint( 0, 0 );
        Load_Module_From_Library( full_libraryfilename, NULL );
        redraw = true;
    }
        if( GetBoard()->m_Modules )
            GetBoard()->m_Modules->m_Flags = 0;

        // if either m_Reference or m_Value are gone, reinstall them -
        // otherwise you cannot see what you are doing on board
        if( GetBoard() && GetBoard()->m_Modules )
        {
            TEXTE_MODULE* ref = GetBoard()->m_Modules->m_Reference;
            TEXTE_MODULE* val = GetBoard()->m_Modules->m_Value;
            if( val && ref )
            {
                ref->m_Type = TEXT_is_REFERENCE;    // just in case ...
                if( ref->m_Text.Length() == 0 )
                    ref->m_Text = L"Ref**";
                val->m_Type = TEXT_is_VALUE;        // just in case ...
                if( val->m_Text.Length() == 0 )
                    val->m_Text = L"Val**";
            }
        }
        GetScreen()->ClrModify();
        Zoom_Automatique( true );
        if( m_Draw3DFrame )
            m_Draw3DFrame->NewDisplay();
        break;

    case ID_MODEDIT_PAD_SETTINGS:
        InstallPadOptionsFrame( NULL, NULL, wxPoint( -1, -1 ) );
        break;

    case ID_MODEDIT_CHECK:
        break;

    case ID_MODEDIT_EDIT_MODULE_PROPERTIES:
        if( GetBoard()->m_Modules )
        {
            SetCurItem( GetBoard()->m_Modules );
            DIALOG_MODULE_MODULE_EDITOR dialog( this,
                                               (MODULE*) GetScreen()->
                                               GetCurItem() );
            int ret = dialog.ShowModal();
            GetScreen()->GetCurItem()->m_Flags = 0;
            if( ret > 0 )
                DrawPanel->Refresh();
        }
        break;

    case ID_MODEDIT_ADD_PAD:
        if( GetBoard()->m_Modules )
            SetToolID( id, wxCURSOR_PENCIL, _( "Add Pad" ) );
        else
        {
            SetToolID( id, wxCURSOR_ARROW, _( "Pad Settings" ) );
            InstallPadOptionsFrame( NULL, NULL, wxPoint( -1, -1 ) );
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
        }
        break;

    case ID_PCB_ADD_LINE_BUTT:
    case ID_PCB_ARC_BUTT:
    case ID_PCB_CIRCLE_BUTT:
    case ID_PCB_ADD_TEXT_BUTT:
        SetToolID( id, wxCURSOR_PENCIL, _( "Add Drawing" ) );
        break;

    case ID_MODEDIT_PLACE_ANCHOR:
        SetToolID( id, wxCURSOR_PENCIL, _( "Place anchor" ) );
        break;

    case ID_NO_SELECT_BUTT:
        SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
        break;

    case ID_POPUP_CLOSE_CURRENT_TOOL:
        break;

    case ID_POPUP_CANCEL_CURRENT_COMMAND:
        break;

    case ID_MODEDIT_DELETE_ITEM_BUTT:
        SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
        break;

    case ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE:
        DrawPanel->MouseToCursorSchema();
        Rotate_Module( NULL, (MODULE*) GetScreen()->GetCurItem(), 900, true );
        redraw = true;
        break;

    case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE:
        DrawPanel->MouseToCursorSchema();
        Rotate_Module( NULL, (MODULE*) GetScreen()->GetCurItem(), -900, true );
        redraw = true;
        break;

    case ID_POPUP_PCB_EDIT_MODULE:
    {
        DIALOG_MODULE_MODULE_EDITOR dialog( this,
                                           (MODULE*) GetScreen()->GetCurItem() );
        int ret = dialog.ShowModal();
        GetScreen()->GetCurItem()->m_Flags = 0;
        GetScreen()->GetCurItem()->m_Flags = 0;
        DrawPanel->MouseToCursorSchema();
        if( ret > 0 )
            DrawPanel->Refresh();
    }
    break;

    case ID_POPUP_PCB_MOVE_PAD_REQUEST:
    {
        DrawPanel->MouseToCursorSchema();
        StartMovePad( (D_PAD*) GetScreen()->GetCurItem(), &dc );
    }
    break;

    case ID_POPUP_PCB_EDIT_PAD:
    {
        InstallPadOptionsFrame( (D_PAD*) GetScreen()->GetCurItem(),
                                &dc, pos );
        DrawPanel->MouseToCursorSchema();
    }
    break;

    case ID_POPUP_PCB_DELETE_PAD:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        DeletePad( (D_PAD*) GetScreen()->GetCurItem() );
        SetCurItem( NULL );
        DrawPanel->MouseToCursorSchema();
        break;

    case ID_POPUP_PCB_IMPORT_PAD_SETTINGS:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        DrawPanel->MouseToCursorSchema();
        Import_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem(), true );
        break;

    case ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        Global_Import_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem(), true );
        DrawPanel->MouseToCursorSchema();
        break;

    case ID_POPUP_PCB_EXPORT_PAD_SETTINGS:
        DrawPanel->MouseToCursorSchema();
        Export_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem() );
        break;

    case ID_POPUP_PCB_EDIT_TEXTMODULE:
    {
        InstallTextModOptionsFrame(
             (TEXTE_MODULE*) GetScreen()->GetCurItem(), &dc );
        DrawPanel->MouseToCursorSchema();
    }
    break;

    case ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST:
    {
        DrawPanel->MouseToCursorSchema();
        StartMoveTexteModule( (TEXTE_MODULE*) GetScreen()->GetCurItem(), &dc );
    }
    break;

    case ID_POPUP_PCB_ROTATE_TEXTMODULE:
    {
        RotateTextModule( (TEXTE_MODULE*) GetScreen()->GetCurItem(), &dc );
        DrawPanel->MouseToCursorSchema();
    }
    break;

    case ID_POPUP_PCB_DELETE_TEXTMODULE:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        DeleteTextModule( (TEXTE_MODULE*) GetScreen()->GetCurItem() );
        SetCurItem( NULL );
        DrawPanel->MouseToCursorSchema();
        break;

    case ID_POPUP_PCB_MOVE_EDGE:
    {
        Start_Move_EdgeMod( (EDGE_MODULE*) GetScreen()->GetCurItem(), &dc );
        DrawPanel->MouseToCursorSchema();
    }
    break;

    case ID_POPUP_PCB_STOP_CURRENT_DRAWING:
        DrawPanel->MouseToCursorSchema();
        if( (GetScreen()->GetCurItem()->m_Flags & IS_NEW) )
        {
            End_Edge_Module( (EDGE_MODULE*) GetScreen()->GetCurItem(), &dc );
            SetCurItem( NULL );
        }
        break;

    case ID_POPUP_PCB_ENTER_EDGE_WIDTH:
    {
        EDGE_MODULE* edge = NULL;
        if( GetScreen()->GetCurItem()
           && ( GetScreen()->GetCurItem()->m_Flags & IS_NEW )
           && ( GetScreen()->GetCurItem()->Type() == TYPE_EDGE_MODULE ) )
        {
            edge = (EDGE_MODULE*) GetScreen()->GetCurItem();
        }
        Enter_Edge_Width( edge, &dc );
        DrawPanel->MouseToCursorSchema();
    }
    break;

    case ID_POPUP_PCB_EDIT_WIDTH_CURRENT_EDGE:
        DrawPanel->MouseToCursorSchema();
        Edit_Edge_Width( (EDGE_MODULE*) GetScreen()->GetCurItem() );
        break;

    case ID_POPUP_PCB_EDIT_WIDTH_ALL_EDGE:
        DrawPanel->MouseToCursorSchema();
        Edit_Edge_Width( NULL );
        break;

    case ID_POPUP_PCB_EDIT_LAYER_CURRENT_EDGE:
        DrawPanel->MouseToCursorSchema();
        Edit_Edge_Layer( (EDGE_MODULE*) GetScreen()->GetCurItem() );
        break;

    case ID_POPUP_PCB_EDIT_LAYER_ALL_EDGE:
        DrawPanel->MouseToCursorSchema();
        Edit_Edge_Layer( NULL );
        break;

    case ID_POPUP_PCB_DELETE_EDGE:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        DrawPanel->MouseToCursorSchema();
        RemoveStruct( GetScreen()->GetCurItem() );
        SetCurItem( NULL );
        break;

    case ID_MODEDIT_MODULE_ROTATE:
    case ID_MODEDIT_MODULE_MIRROR:
        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        Transform( (MODULE*) GetScreen()->GetCurItem(), id );
        redraw = true;
        break;

    case ID_PCB_DRAWINGS_WIDTHS_SETUP:
        InstallOptionsFrame( pos );
        break;

    case ID_PCB_PAD_SETUP:
    {
        BOARD_ITEM* item = GetCurItem();
        if( item )
        {
            if( item->Type() != TYPE_PAD )
                item = NULL;
        }
        InstallPadOptionsFrame( (D_PAD*) item, &dc, pos );
    }
    break;

    case ID_PCB_USER_GRID_SETUP:
        InstallGridFrame( pos );
        break;

    case ID_POPUP_PLACE_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_MOVE;
        DrawPanel->m_AutoPAN_Request = FALSE;
        HandleBlockPlace( &dc );
        break;

    case ID_POPUP_COPY_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_COPY;
        GetScreen()->m_BlockLocate.SetMessageBlock( this );
        DrawPanel->m_AutoPAN_Request = FALSE;
        HandleBlockPlace( &dc );
        break;

    case ID_POPUP_ZOOM_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_ZOOM;
        GetScreen()->m_BlockLocate.SetMessageBlock( this );
        HandleBlockEnd( &dc );
        break;

    case ID_POPUP_DELETE_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_DELETE;
        GetScreen()->m_BlockLocate.SetMessageBlock( this );
        HandleBlockEnd( &dc );
        break;

    case ID_POPUP_ROTATE_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_ROTATE;
        GetScreen()->m_BlockLocate.SetMessageBlock( this );
        HandleBlockEnd( &dc );
        break;

    case ID_POPUP_MIRROR_X_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_MIRROR_X;
        GetScreen()->m_BlockLocate.SetMessageBlock( this );
        HandleBlockEnd( &dc );
        break;

    default:
        DisplayError( this,
                      wxT( "WinEDA_ModuleEditFrame::Process_Special_Functions error" ) );
        break;
    }

    SetToolbars();
    if( redraw )
        DrawPanel->Refresh();
}


/* Execute a geometric transform on the current footprint.
 *  The footprint, after transform is always in reference position and
 * orientation:
 *  position 0,0
 *  orientation 0, component side.
 */
void WinEDA_ModuleEditFrame::Transform( MODULE* module, int transform )
{
    D_PAD*          pad = module->m_Pads;
    EDA_BaseStruct* PtStruct = module->m_Drawings;
    TEXTE_MODULE*   textmod;
    EDGE_MODULE*    edgemod;
    int             angle = 900; // Necessary +- 900 (+- 90 degrees) )

    switch( transform )
    {
    case ID_MODEDIT_MODULE_ROTATE:
        module->SetOrientation( angle );

        for( ; pad != NULL; pad = (D_PAD*) pad->Next() )
        {
            pad->m_Pos0    = pad->m_Pos;
            pad->m_Orient -= angle;
            RotatePoint( &pad->m_Offset.x, &pad->m_Offset.y, angle );
            EXCHG( pad->m_Size.x, pad->m_Size.y );
            RotatePoint( &pad->m_DeltaSize.x, &pad->m_DeltaSize.y, -angle );
        }

        module->m_Reference->m_Pos0    = module->m_Reference->m_Pos;
        module->m_Reference->m_Orient += angle;
        if( module->m_Reference->m_Orient >= 1800 )
            module->m_Reference->m_Orient -= 1800;
        module->m_Value->m_Pos0    = module->m_Value->m_Pos;
        module->m_Value->m_Orient += angle;
        if( module->m_Value->m_Orient >= 1800 )
            module->m_Value->m_Orient -= 1800;

        for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
        {
            if( PtStruct->Type() == TYPE_EDGE_MODULE )
            {
                edgemod = (EDGE_MODULE*) PtStruct;
                edgemod->m_Start0 = edgemod->m_Start;
                edgemod->m_End0   = edgemod->m_End;
            }
            if( PtStruct->Type() == TYPE_TEXTE_MODULE )
            {
                textmod = (TEXTE_MODULE*) PtStruct;
                textmod->m_Pos0 = textmod->m_Pos;
            }
        }

        module->m_Orient = 0;
        break;

    case ID_MODEDIT_MODULE_MIRROR:
        for( ; pad != NULL; pad = (D_PAD*) pad->Next() )
        {
            NEGATE( pad->m_Pos.y );
            NEGATE( pad->m_Pos0.y );
            NEGATE( pad->m_Offset.y );
            NEGATE( pad->m_DeltaSize.y );
            if( pad->m_Orient )
                pad->m_Orient = 3600 - pad->m_Orient;
        }

        /* Reverse mirror of reference. */
        textmod = module->m_Reference;
        NEGATE( textmod->m_Pos.y );
        NEGATE( textmod->m_Pos0.y );
        if( textmod->m_Orient )
            textmod->m_Orient = 3600 - textmod->m_Orient;

        /* Reverse mirror of value. */
        textmod = module->m_Value;
        NEGATE( textmod->m_Pos.y );
        NEGATE( textmod->m_Pos0.y );
        if( textmod->m_Orient )
            textmod->m_Orient = 3600 - textmod->m_Orient;

        /* Reverse mirror of footprints. */
        PtStruct = module->m_Drawings;
        for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
        {
            switch( PtStruct->Type() )
            {
            case TYPE_EDGE_MODULE:
                edgemod = (EDGE_MODULE*) PtStruct;
                NEGATE( edgemod->m_Start.y );
                NEGATE( edgemod->m_End.y );
                /* Invert local coordinates */
                NEGATE( edgemod->m_Start0.y );
                NEGATE( edgemod->m_End0.y );
                break;

            case TYPE_TEXTE_MODULE:
                /* Reverse mirror position and mirror. */
                textmod = (TEXTE_MODULE*) PtStruct;
                NEGATE( textmod->m_Pos.y );
                NEGATE( textmod->m_Pos0.y );
                if( textmod->m_Orient )
                    textmod->m_Orient = 3600 - textmod->m_Orient;
                break;

            default:
                DisplayError( this, wxT( "Draw type undefined" ) );
                break;
            }
        }

        break;

    default:
        DisplayInfoMessage( this, wxT( "Not available" ) );
        break;
    }

    module->Set_Rectangle_Encadrement();
}