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