bool FOOTPRINT_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand )
{
    BOARD_ITEM* item = GetCurItem();
    bool        itemCurrentlyEdited = item && item->GetFlags();
    bool        blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;

    if( itemCurrentlyEdited || blockActive )
        return false;

    item = ModeditLocateAndDisplay();

    if( item == NULL )
        return false;

    SetCurItem( item );

    int evt_type = 0;       // Used to post a wxCommandEvent on demand

    switch( item->Type() )
    {
    case PCB_MODULE_T:
        if( aIdCommand == HK_EDIT_ITEM )
            evt_type = ID_POPUP_PCB_EDIT_MODULE_PRMS;

        break;

    case PCB_PAD_T:
        if( aIdCommand == HK_EDIT_ITEM )
            evt_type = ID_POPUP_PCB_EDIT_PAD;

        break;

    case PCB_MODULE_TEXT_T:
        if( aIdCommand == HK_EDIT_ITEM )
            evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;

        break;

    case PCB_MODULE_EDGE_T:
        if( aIdCommand == HK_EDIT_ITEM )
            evt_type = ID_POPUP_MODEDIT_EDIT_BODY_ITEM;

        break;

    default:
        break;
    }

    if( evt_type != 0 )
    {
        wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
        evt.SetEventObject( this );
        evt.SetId( evt_type );
        wxPostEvent( this, evt );
        return true;
    }

    return false;
}
/*
 * Called on a mouse left button double click
 */
void FOOTPRINT_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
    BOARD_ITEM* item = GetCurItem();

    switch( GetToolId() )
    {
    case ID_NO_TOOL_SELECTED:
        if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
        {
            item = ModeditLocateAndDisplay();
        }

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

        // Item found
        SetCurItem( item );
        OnEditItemRequest( DC, item );
        break;      // end case 0

    case ID_PCB_ADD_LINE_BUTT:
    {
        if( item && item->IsNew() )
        {
            End_Edge_Module( (EDGE_MODULE*) item );
            SetCurItem( NULL );
            m_canvas->Refresh();
        }

        break;
    }

    default:
        break;
    }
}
void WinEDA_ModuleEditFrame::OnLeftClick(wxDC * DC, const wxPoint& MousePos)
/*************************************************************************/
/* Traite les commandes declenchée par le bouton gauche de la souris,
	quand un outil est deja selectionné
*/
{
EDA_BaseStruct * DrawStruct = m_CurrentScreen->m_CurrentItem;

	GetScreen()->CursorOff(DrawPanel, DC);
	if ( m_ID_current_state == 0 )
		{
		if ( DrawStruct && DrawStruct->m_Flags ) // Commande "POPUP" en cours
			{
			switch (DrawStruct->m_StructType )
				{
				case TYPETEXTEMODULE:
					SaveCopyInUndoList();
					PlaceTexteModule( (TEXTE_MODULE *) DrawStruct, DC);
					break;

				case TYPEEDGEMODULE:
					SaveCopyInUndoList();
					Place_EdgeMod( (EDGE_MODULE *) DrawStruct, DC);
					break;

				case TYPEPAD:
					PlacePad((D_PAD *)DrawStruct, DC);
					break;

				default:
					{
					wxString msg;
					msg.Printf(
wxT("WinEDA_ModEditFrame::ProcessCommand err: m_Flags != 0\nStruct @%p, type %d m_Flag %X")
, DrawStruct, DrawStruct->m_StructType, DrawStruct->m_Flags);
					DisplayError(this, msg);
					DrawStruct->m_Flags = 0;
					break;
					}
				}
			}
		}

	DrawStruct = m_CurrentScreen->m_CurrentItem;
	if ( ! DrawStruct || (DrawStruct->m_Flags == 0) )
		{
		m_CurrentScreen->m_CurrentItem = DrawStruct = ModeditLocateAndDisplay();
		}

	switch ( m_ID_current_state )
		{
		case 0:
			break;

		case ID_NO_SELECT_BUTT:
			break;

		case ID_PCB_CIRCLE_BUTT:
		case ID_PCB_ARC_BUTT:
		case ID_LINE_COMMENT_BUTT:
			if ( ! DrawStruct || DrawStruct->m_Flags == 0)
				{
				int shape = S_SEGMENT;
				if ( m_ID_current_state == ID_PCB_CIRCLE_BUTT) shape = S_CIRCLE;
				if ( m_ID_current_state == ID_PCB_ARC_BUTT) shape = S_ARC;

				m_CurrentScreen->m_CurrentItem =
					Begin_Edge_Module((EDGE_MODULE *) NULL, DC, shape);
				}

			else if ( (DrawStruct->m_Flags & IS_NEW) )
				{
				if ( ((EDGE_MODULE*)DrawStruct)->m_Shape == S_CIRCLE )
					{
					End_Edge_Module((EDGE_MODULE *) DrawStruct, DC);
					m_CurrentScreen->m_CurrentItem = NULL;
					}
				else if ( ((EDGE_MODULE*)DrawStruct)->m_Shape == S_ARC )
					{
					End_Edge_Module((EDGE_MODULE *) DrawStruct, DC);
					m_CurrentScreen->m_CurrentItem = NULL;
					}
				else if ( ((EDGE_MODULE*)DrawStruct)->m_Shape == S_SEGMENT )
					{
					m_CurrentScreen->m_CurrentItem =
						Begin_Edge_Module((EDGE_MODULE *) DrawStruct, DC, 0);
					}
				else  DisplayError(this, wxT("ProcessCommand error: DrawStruct/ flags error"));
				}
			break;

		case ID_MODEDIT_DELETE_ITEM_BUTT:
			if ( !DrawStruct || (DrawStruct->m_Flags == 0) )
				{
				DrawStruct = ModeditLocateAndDisplay();
				if ( DrawStruct && (DrawStruct->m_Flags == 0) )
					{
					SaveCopyInUndoList();
					RemoveStruct(DrawStruct, DC);
					m_CurrentScreen->m_CurrentItem = DrawStruct = NULL;
					}
				}
			break;

		case ID_MODEDIT_PLACE_ANCHOR:
			SaveCopyInUndoList();
			Place_Ancre(m_Pcb->m_Modules, DC);
			m_Pcb->m_Modules->m_Flags = 0;
			m_CurrentScreen->m_Curseur = wxPoint(0,0);
			Recadre_Trace(TRUE);
			Place_Module(m_Pcb->m_Modules, DC);
			RedrawActiveWindow(DC, TRUE);
			SetToolID( 0, wxCURSOR_ARROW, wxEmptyString);
			m_CurrentScreen->m_CurrentItem = NULL;
			break;

		case ID_TEXT_COMMENT_BUTT:
			SaveCopyInUndoList();
			CreateTextModule(m_Pcb->m_Modules, DC);
			break;

		case ID_MODEDIT_ADD_PAD:
			if ( m_Pcb->m_Modules )
			{
				SaveCopyInUndoList();
				AddPad(m_Pcb->m_Modules, DC);
			}
			break;

		default :
				DrawPanel->SetCursor(wxCURSOR_ARROW);
				DisplayError(this, wxT("WinEDA_ModuleEditFrame::ProcessCommand error"));
				m_ID_current_state = 0;
				break;
		}
	GetScreen()->CursorOn(DrawPanel, DC);
}
void WinEDA_ModuleEditFrame::OnRightClick(const wxPoint& MousePos,
			wxMenu * PopMenu)
/*********************************************************************/
/* Prepare le menu PullUp affiché par un click sur le bouton droit
de la souris.
   Ce menu est ensuite complété par la liste des commandes de ZOOM
*/
{
EDA_BaseStruct *DrawStruct = m_CurrentScreen->m_CurrentItem;
wxString msg;
bool append_set_width = FALSE;
bool BlockActive = (m_CurrentScreen->BlockLocate.m_Command !=  BLOCK_IDLE);

	 // Simple localisation des elements si possible
	if ( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
	{
		m_CurrentScreen->m_CurrentItem = DrawStruct = ModeditLocateAndDisplay();
	}

	// Si commande en cours: affichage fin de commande
	if (  m_ID_current_state )
	{
		if ( DrawStruct && DrawStruct->m_Flags )
		{
			ADD_MENUITEM(PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
				_("Cancel"), cancel_xpm);
		}
		else
			ADD_MENUITEM(PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL,
				_("End Tool"), cancel_tool_xpm );
		PopMenu->AppendSeparator();
	}

	else
	{
		if ( (DrawStruct && DrawStruct->m_Flags) || BlockActive )
		{
			if ( BlockActive )	// Put block commnands in list
			{
				ADD_MENUITEM(PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
					_("Cancel Block"), cancel_xpm );
				ADD_MENUITEM(PopMenu, ID_POPUP_ZOOM_BLOCK,
					_("Zoom Block (Midd butt drag)"), zoom_selected_xpm );
				PopMenu->AppendSeparator();
				ADD_MENUITEM(PopMenu, ID_POPUP_PLACE_BLOCK,
					_("Place Block"), apply_xpm );
				ADD_MENUITEM(PopMenu, ID_POPUP_COPY_BLOCK,
					_("Copy Block (shift + drag mouse)"), copyblock_xpm );
				ADD_MENUITEM(PopMenu, ID_POPUP_MIRROR_X_BLOCK,
					_("Mirror Block (alt + drag mouse)"), mirror_H_xpm );
				ADD_MENUITEM(PopMenu, ID_POPUP_ROTATE_BLOCK,
					_("Rotate Block (ctrl + drag mouse)"), rotate_pos_xpm );
				ADD_MENUITEM(PopMenu, ID_POPUP_DELETE_BLOCK,
					_("Delete Block (shift+ctrl + drag mouse)"), delete_xpm );
			}
			else
			{
			ADD_MENUITEM(PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
				_("Cancel"), cancel_xpm);
			}
			PopMenu->AppendSeparator();
		}
	}

	if ( DrawStruct == NULL ) return;

int flags = DrawStruct->m_Flags;

	switch ( DrawStruct->m_StructType )
	{
		case TYPEMODULE:
		{
		wxMenu * transform_choice = new wxMenu;
			ADD_MENUITEM(transform_choice, ID_MODEDIT_MODULE_ROTATE,
				_("Rotate"), rotate_module_pos_xpm);
			ADD_MENUITEM(transform_choice, ID_MODEDIT_MODULE_MIRROR,
				_("Mirror"), mirror_H_xpm);
#if 0
			transform_choice->Append(ID_MODEDIT_MODULE_SCALE, _("Scale"));
			transform_choice->Append(ID_MODEDIT_MODULE_SCALE, _("Scale X"));
			transform_choice->Append(ID_MODEDIT_MODULE_SCALE, _("Scale Y"));
#endif
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_EDIT_MODULE,
				_("Edit Module"), Edit_Module_xpm);
			ADD_MENUITEM_WITH_SUBMENU(PopMenu, transform_choice,
				ID_MODEDIT_TRANSFORM_MODULE,
				_("Transform Module"), edit_xpm);
			break;
		}

		case TYPEPAD:
			if( !flags )
			{
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_MOVE_PAD_REQUEST,
							_("Move Pad"), move_pad_xpm);
			}
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_EDIT_PAD, _("Edit Pad"), options_pad_xpm);
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_IMPORT_PAD_SETTINGS,
					_("New Pad Settings"), options_new_pad_xpm);
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_EXPORT_PAD_SETTINGS,
				_("Export Pad Settings"), Export_Options_Pad_xpm);
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_DELETE_PAD,
					_("delete Pad"), Delete_Pad_xpm);
			if( !flags )
				{
				PopMenu->AppendSeparator();
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS,
					_("Global Pad Settings"), global_options_pad_xpm);
				}
			break;

		case TYPETEXTEMODULE:
			if( !flags )
			{
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST,
							_("Move Text Mod."), Move_Field_xpm );
			}
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_ROTATE_TEXTMODULE,
				_("Rotate Text Mod."), Rotate_Field_xpm);
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_EDIT_TEXTMODULE,
				_("Edit Text Mod."), edit_text_xpm);
			if ( ((TEXTE_MODULE*)DrawStruct)->m_Type == TEXT_is_DIVERS)
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_DELETE_TEXTMODULE,
					_("Delete Text Mod."), delete_text_xpm);
			break;

		case TYPEEDGEMODULE:
			{
			if( (flags & IS_NEW) )
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_STOP_CURRENT_DRAWING,
					_("End edge"), apply_xpm);
			if( !flags )
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_MOVE_EDGE,
					_("Move edge"), move_line_xpm);
			if( (flags & (IS_NEW|IS_MOVED)) == IS_MOVED)
				ADD_MENUITEM(PopMenu,ID_POPUP_PCB_PLACE_EDGE,
					_("Place edge"), apply_xpm);
			wxMenu * edit_mnu = new wxMenu;
			ADD_MENUITEM_WITH_SUBMENU(PopMenu, edit_mnu,
				ID_POPUP_PCB_EDIT_EDGE, _("Edit"), edit_xpm);
			ADD_MENUITEM(edit_mnu, ID_POPUP_PCB_EDIT_WIDTH_CURRENT_EDGE,
				_("Edit Width (Current)"), width_segment_xpm);
			ADD_MENUITEM(edit_mnu, ID_POPUP_PCB_EDIT_WIDTH_ALL_EDGE,
				_("Edit Width (All)"), width_segment_xpm);
			ADD_MENUITEM(edit_mnu, ID_POPUP_PCB_EDIT_LAYER_CURRENT_EDGE,
				_("Edit Layer (Current)"), select_layer_pair_xpm);
			ADD_MENUITEM(edit_mnu, ID_POPUP_PCB_EDIT_LAYER_ALL_EDGE,
				_("Edit Layer (All)"), select_layer_pair_xpm);
			ADD_MENUITEM(PopMenu,ID_POPUP_PCB_DELETE_EDGE,
				_("Delete edge"), delete_xpm);
			append_set_width = TRUE;
			}
			break;

		case TYPEDRAWSEGMENT:
		case TYPETEXTE:
		case TYPEVIA:
		case TYPETRACK:
		case TYPEZONE:
		case TYPEMARQUEUR:
		case TYPECOTATION:
		case TYPEMIRE:
			break;

		case TYPESCREEN:
		case TYPE_NOT_INIT:
		case TYPEPCB:
		case PCB_EQUIPOT_STRUCT_TYPE:
			msg.Printf(
				wxT("WinEDA_ModuleEditFrame::OnRightClick Error: illegal DrawType %d"),
				DrawStruct->m_StructType);
			DisplayError(this, msg );
			break;

		default:
			msg.Printf(
				wxT("WinEDA_ModuleEditFrame::OnRightClick Error: unknown DrawType %d"),
				DrawStruct->m_StructType);
			DisplayError(this, msg );
			break;
	}
	PopMenu->AppendSeparator();

	if ( append_set_width ||
		( m_ID_current_state && ((m_ID_current_state == ID_LINE_COMMENT_BUTT) ||
			 (m_ID_current_state == ID_PCB_CIRCLE_BUTT) ||
			 (m_ID_current_state == ID_PCB_ARC_BUTT)) ) )
	{
		ADD_MENUITEM(PopMenu,ID_POPUP_PCB_ENTER_EDGE_WIDTH,
			_("Set Width"), width_segment_xpm);
		PopMenu->AppendSeparator();
	}

}
void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{
    BOARD_ITEM* item = GetCurItem();

    m_canvas->CrossHairOff( DC );

    if( GetToolId() == ID_NO_TOOL_SELECTED )
    {
        if( item && item->GetFlags() ) // Move item command in progress
        {
            switch( item->Type() )
            {
            case PCB_MODULE_TEXT_T:
                PlaceTexteModule( static_cast<TEXTE_MODULE*>( item ), DC );
                break;

            case PCB_MODULE_EDGE_T:
                SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
                Place_EdgeMod( static_cast<EDGE_MODULE*>( item ) );
                break;

            case PCB_PAD_T:
                PlacePad( static_cast<D_PAD*>( item ), DC );
                break;

            default:
            {
                wxString msg;
                msg.Printf( wxT( "WinEDA_ModEditFrame::OnLeftClick err:Struct %d, m_Flag %X" ),
                            item->Type(), item->GetFlags() );
                DisplayError( this, msg );
                item->ClearFlags();
                break;
            }
            }
        }

        else
        {
            if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
                    && !wxGetKeyState( WXK_CONTROL ) )
                item = ModeditLocateAndDisplay();

            SetCurItem( item );
        }
    }

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

    switch( GetToolId() )
    {
    case ID_NO_TOOL_SELECTED:
        break;

    case ID_MODEDIT_CIRCLE_TOOL:
    case ID_MODEDIT_ARC_TOOL:
    case ID_MODEDIT_LINE_TOOL:
        if( no_item_edited )
        {
            STROKE_T shape = S_SEGMENT;

            if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL )
                shape = S_CIRCLE;

            if( GetToolId() == ID_MODEDIT_ARC_TOOL )
                shape = S_ARC;

            SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) );
        }
        else if( item->IsNew() )
        {
            if( ( (EDGE_MODULE*) item )->GetShape() == S_CIRCLE )
            {
                End_Edge_Module( (EDGE_MODULE*) item );
                SetCurItem( NULL );
                m_canvas->Refresh();
            }
            else if( ( (EDGE_MODULE*) item )->GetShape() == S_ARC )
            {
                End_Edge_Module( (EDGE_MODULE*) item );
                SetCurItem( NULL );
                m_canvas->Refresh();
            }
            else if( ( (EDGE_MODULE*) item )->GetShape() == S_SEGMENT )
            {
                SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, S_SEGMENT ) );
            }
            else
            {
                wxMessageBox( wxT( "ProcessCommand error: unknown shape" ) );
            }
        }
        break;

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

        item = ModeditLocateAndDisplay();

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

        break;

    case ID_MODEDIT_ANCHOR_TOOL:
    {
        MODULE* module = GetBoard()->m_Modules;

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

        SaveCopyInUndoList( module, UR_MODEDIT );

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

        // 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 );
        m_canvas->Refresh();
    }
    break;

    case ID_MODEDIT_PLACE_GRID_COORD:
        m_canvas->DrawGridAxis( DC, GR_XOR, GetBoard()->GetGridOrigin() );
        SetGridOrigin( GetCrossHairPosition() );
        m_canvas->DrawGridAxis( DC, GR_COPY, GetBoard()->GetGridOrigin() );
        GetScreen()->SetModify();
        break;

    case ID_MODEDIT_TEXT_TOOL:
        if( GetBoard()->m_Modules == NULL )
            break;

        SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
        CreateTextModule( GetBoard()->m_Modules, DC );
        break;

    case ID_MODEDIT_PAD_TOOL:
        if( GetBoard()->m_Modules )
        {
            SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
            AddPad( GetBoard()->m_Modules, true );
        }

        break;

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

    m_canvas->CrossHairOn( DC );
}
bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
    BOARD_ITEM* item = GetCurItem();
    wxString    msg;
    bool        blockActive = !GetScreen()->m_BlockLocate.IsIdle();

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

    // End command in progress.
    if( GetToolId() != ID_NO_TOOL_SELECTED )
    {
        if( item && item->GetFlags() )
            AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ),
                         KiBitmap( cancel_xpm ) );
        else
            AddMenuItem( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ),
                         KiBitmap( cursor_xpm ) );

        PopMenu->AppendSeparator();
    }
    else
    {
        if( (item && item->GetFlags()) || blockActive )
        {
            if( blockActive )  // Put block commands in list
            {
                AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
                             _( "Cancel Block" ), KiBitmap( cancel_xpm ) );
                AddMenuItem( PopMenu, ID_POPUP_ZOOM_BLOCK,
                             _( "Zoom Block (drag middle mouse)" ),
                             KiBitmap( zoom_area_xpm ) );
                PopMenu->AppendSeparator();
                AddMenuItem( PopMenu, ID_POPUP_PLACE_BLOCK,
                             _( "Place Block" ), KiBitmap( checked_ok_xpm ) );
                AddMenuItem( PopMenu, ID_POPUP_COPY_BLOCK,
                             _( "Copy Block (shift + drag mouse)" ),
                             KiBitmap( copyblock_xpm ) );
                AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK,
                             _( "Mirror Block (alt + drag mouse)" ),
                             KiBitmap( mirror_h_xpm ) );
                AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK,
                             _( "Rotate Block (ctrl + drag mouse)" ),
                             KiBitmap( rotate_ccw_xpm ) );
                AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK,
                             _( "Delete Block (shift+ctrl + drag mouse)" ),
                             KiBitmap( delete_xpm ) );
            }
            else
            {
                AddMenuItem( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND,
                             _( "Cancel" ), KiBitmap( cancel_xpm ) );
            }

            PopMenu->AppendSeparator();
        }
    }

    if( blockActive )
        return true;

    if( item  )
    {
        STATUS_FLAGS flags = item->GetFlags();
        switch( item->Type() )
        {
        case PCB_MODULE_T:
        {
            wxMenu* transform_choice = new wxMenu;
            AddMenuItem( transform_choice, ID_MODEDIT_MODULE_ROTATE, _( "Rotate" ),
                         KiBitmap( rotate_module_ccw_xpm ) );
            AddMenuItem( transform_choice, ID_MODEDIT_MODULE_MIRROR, _( "Mirror" ),
                         KiBitmap( mirror_footprint_axisY_xpm ) );
            msg = AddHotkeyName( _( "Edit Module" ), g_Module_Editor_Hokeys_Descr, HK_EDIT_ITEM );
            AddMenuItem( PopMenu, ID_POPUP_PCB_EDIT_MODULE_PRMS, msg, KiBitmap( edit_module_xpm ) );
            AddMenuItem( PopMenu, transform_choice, ID_MODEDIT_TRANSFORM_MODULE,
                         _( "Transform Module" ), KiBitmap( edit_xpm ) );
            break;
        }

        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 ) );
            }

            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 ) );

            if( !flags )
            {
                PopMenu->AppendSeparator();
                AddMenuItem( PopMenu, ID_POPUP_PCB_GLOBAL_IMPORT_PAD_SETTINGS,
                             _( "Global Pad Settings" ), KiBitmap( global_options_pad_xpm ) );
            }

            break;

        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 ) );
            }

            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 ) );

            if( !flags )
            {
                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 ) );

                if( ( static_cast<TEXTE_MODULE*>( item ) )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
                {
                    msg = AddHotkeyName( _("Delete Text Mod." ), g_Module_Editor_Hokeys_Descr,
                                         HK_DELETE );
                    AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE, msg,
                                 KiBitmap( delete_text_xpm ) );
                }
            }
            break;

        case PCB_MODULE_EDGE_T:
        {
            if( (flags & IS_NEW) )
                AddMenuItem( PopMenu, ID_POPUP_PCB_STOP_CURRENT_DRAWING, _( "End edge" ),
                             KiBitmap( checked_ok_xpm ) );

            if( !flags )
            {
                msg = AddHotkeyName( _("Move Edge" ), g_Module_Editor_Hokeys_Descr, HK_MOVE_ITEM );
                AddMenuItem( PopMenu, ID_POPUP_PCB_MOVE_EDGE, msg, KiBitmap( move_line_xpm ) );
            }

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

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

            msg = AddHotkeyName( _("Delete Edge" ), g_Module_Editor_Hokeys_Descr, HK_DELETE );
            AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_EDGE, msg, KiBitmap( delete_xpm ) );

            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 ) );
        }
        break;

        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:
            msg.Printf( wxT( "FOOTPRINT_EDIT_FRAME::OnRightClick Error: Unexpected DrawType %d" ),
                        item->Type() );
            DisplayError( this, msg );
            break;

        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;

        default:
            msg.Printf( wxT( "FOOTPRINT_EDIT_FRAME::OnRightClick Error: unknown DrawType %d" ),
                        item->Type() );
            DisplayError( this, msg );
            break;
        }
        PopMenu->AppendSeparator();
    }

    if( ( GetToolId() == ID_MODEDIT_LINE_TOOL ) ||
            ( GetToolId() == ID_MODEDIT_CIRCLE_TOOL ) ||
            ( GetToolId() == ID_MODEDIT_ARC_TOOL ) )
    {
        AddMenuItem( PopMenu, ID_POPUP_MODEDIT_ENTER_EDGE_WIDTH, _("Set Line Width" ),
                     KiBitmap( width_segment_xpm ) );
        PopMenu->AppendSeparator();
    }

    return true;
}
/*
 * Called on a mouse left button double click
 */
void FOOTPRINT_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
    BOARD_ITEM* item = GetCurItem();

    switch( GetToolId() )
    {
    case ID_NO_TOOL_SELECTED:
        if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
        {
            item = ModeditLocateAndDisplay();
        }

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

        // Item found
        SetCurItem( item );

        switch( item->Type() )
        {
        case PCB_PAD_T:
            InstallPadOptionsFrame( (D_PAD*) item );
            m_canvas->MoveCursorToCrossHair();
            break;

        case PCB_MODULE_T:
            {
            DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) item );
            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*) item, DC );
            m_canvas->MoveCursorToCrossHair();
            break;

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

        default:
            break;
        }

        break;      // end case 0

    case ID_PCB_ADD_LINE_BUTT:
    {
        if( item && item->IsNew() )
        {
            End_Edge_Module( (EDGE_MODULE*) item );
            SetCurItem( NULL );
            m_canvas->Refresh();
        }

        break;
    }

    default:
        break;
    }
}