Commit 657f62ab authored by jean-pierre charras's avatar jean-pierre charras
Browse files

fixing bug 626875. Cleaning code

Try to fix block selection issue with some windows managers.
parent fe6591b2
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -1071,11 +1071,13 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5

    /* Count the drag events.  Used to filter mouse moves before starting a
     * block command.  A block command can be started only if MinDragEventCount >
     * MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND in order to avoid spurious block
     * commands. */
     * block command.  A block command can be started only if
     * MinDragEventCount > MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND
     * and m_CanStartBlock >= 0
     * in order to avoid spurious block commands.
     */
    static int MinDragEventCount;
    if( event.Leaving() || event.Entering() )
    if( event.Leaving() /*|| event.Entering()*/ )
    {
        m_CanStartBlock = -1;
    }
@@ -1118,11 +1120,6 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
    if( event.MiddleDown() )
        localbutt = GR_M_MIDDLE_DOWN;

    if( event.ButtonDClick( 2 ) )
    {
    }
    ;                               // Unused

    localrealbutt |= localbutt;     /* compensation default wxGTK */

    /* Compute the cursor position in screen (device) units. */
+1 −1
Original line number Diff line number Diff line
update=22/07/2010 13:46:39
update=31/08/2010 17:44:34
version=1
last_client=pcbnew
[common]
+41 −29
Original line number Diff line number Diff line
/***************************************************************/
/* Edition des Modules: Structures et variables de gestion des */
/*		fonctions de "DRAG" des segments de piste				*/
/***************************************************************/
/**************************************************/
/* Useful class and functions used to drag tracks */
/**************************************************/

/*** Class to handle a list of track segments to drag ***/
/** Helper class to handle a list of track segments to drag
 * and has info to undo/abort the move command
 * a DRAG_SEGM manage one track segment or a via
 */
class DRAG_SEGM
{
public:

    DRAG_SEGM* Pnext;       /* Pointeur de chainage */
    TRACK*  m_Segm;         /* pointeur sur le segment a "dragger */
    D_PAD*  m_Pad_Start;    /* pointeur sur le Pad origine si origine segment sur pad */
    D_PAD*  m_Pad_End;      /* pointeur sur le Pad fin si fin segment sur pad */
@@ -16,31 +16,43 @@ public:

private:
    wxPoint m_StartInitialValue;
    wxPoint    m_EndInitialValue; /* For abort: initial m_Start and m_End values for m_Segm */
    wxPoint m_EndInitialValue;    // For abort: initial m_Start and m_End values for m_Segm


public:

    DRAG_SEGM( TRACK* segm );
    ~DRAG_SEGM();
    ~DRAG_SEGM() {};

    void SetInitialValues();
    void SetInitialValues()
    {
        m_Segm->m_Start = m_StartInitialValue;
        m_Segm->m_End   = m_EndInitialValue;
    }
};

/* Variables */

extern DRAG_SEGM* g_DragSegmentList;    /* pointe le debut de la liste
                                         * des structures DRAG_SEGM */
// a list of DRAG_SEGM items used to move or drag tracks.
// Each DRAG_SEGM item points a segment to move.
extern std::vector<DRAG_SEGM> g_DragSegmentList;

/* routines specifiques */
/* Functions */
void Dessine_Segments_Dragges( WinEDA_DrawPanel* panel, wxDC* DC );
void Build_Drag_Liste( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* Module );
void Build_1_Pad_SegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC, D_PAD* PtPad );
void Collect_TrackSegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC,
                                  wxPoint& point, int MasqueLayer, int net_code );
void    EraseDragListe();


/** function EraseDragList
 * clear the .m_Flags of all track segments managed by in g_DragSegmentList
 * and clear the list.
 * In order to avoid useless memory allocation, the memory is not freed
 * and will be reused when creating a new list
 */
void EraseDragList();

/* Add the segment"Track" to the drag list, and erase it from screen
 * flag = STARTPOINT (if the point to drag is the start point of Track)
 * or ENDPOINT
+72 −103
Original line number Diff line number Diff line
/*********************************************************/
/* Routines relatives a la gestions des pistes en "DRAG" */
/*********************************************************/
/*********************************/
/* functions used to drag tracks */
/*********************************/

/* Fichier dragsegm.cpp */

#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "pcbnew.h"
#include "autorout.h"

#include "protos.h"

#include "drag.h"

/* a list of DRAG_SEGM items used to move or drag tracks */
std::vector<DRAG_SEGM> g_DragSegmentList;

DRAG_SEGM* g_DragSegmentList = NULL;    /* pointe le debut de la liste
                                         * des structures DRAG_SEGM */

/* helper class to handle a list of track segments to drag or move
 */
DRAG_SEGM::DRAG_SEGM( TRACK* segm )
{
    m_Segm = segm;
    m_StartInitialValue = m_Segm->m_Start;
    m_EndInitialValue   = m_Segm->m_End;

    m_Pad_Start = m_Pad_End = NULL;
    m_Flag = 0;
}


DRAG_SEGM::~DRAG_SEGM()
{
}


void DRAG_SEGM::SetInitialValues()
{
    m_Segm->m_Start = m_StartInitialValue;
    m_Segm->m_End   = m_EndInitialValue;
}


/*******************************************************************/
void Dessine_Segments_Dragges( WinEDA_DrawPanel* panel, wxDC* DC )
/*******************************************************************/
@@ -49,38 +33,28 @@ void Dessine_Segments_Dragges( WinEDA_DrawPanel* panel, wxDC* DC )
{
    D_PAD* pt_pad;
    TRACK* Track;
    DRAG_SEGM* pt_drag;

    if( g_DragSegmentList == NULL )
    if( g_DragSegmentList.size() == 0 )
        return;

    pt_drag = g_DragSegmentList;
    for( ; pt_drag; pt_drag = pt_drag->Pnext )
    for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
    {
        int px, py;

        Track = pt_drag->m_Segm;

        wxPoint pos;
        Track = g_DragSegmentList[ii].m_Segm;
        Track->Draw( panel, DC, GR_XOR );   // erase from screen at old position

        pt_pad = pt_drag->m_Pad_Start;
        pt_pad = g_DragSegmentList[ii].m_Pad_Start;
        if( pt_pad )
        {
            px = pt_pad->m_Pos.x - g_Offset_Module.x;
            py = pt_pad->m_Pos.y - g_Offset_Module.y;

            Track->m_Start.x = px;
            Track->m_Start.y = py;
            pos = pt_pad->m_Pos - g_Offset_Module;
            Track->m_Start = pos;
        }

        pt_pad = pt_drag->m_Pad_End;
        pt_pad = g_DragSegmentList[ii].m_Pad_End;
        if( pt_pad )
        {
            px = pt_pad->m_Pos.x - g_Offset_Module.x;
            py = pt_pad->m_Pos.y - g_Offset_Module.y;

            Track->m_End.x = px;
            Track->m_End.y = py;
            pos = pt_pad->m_Pos - g_Offset_Module;
            Track->m_End = pos;
        }

        Track->Draw( panel, DC, GR_XOR );
@@ -91,13 +65,10 @@ void Dessine_Segments_Dragges( WinEDA_DrawPanel* panel, wxDC* DC )
/*************************************************************************/
void Build_Drag_Liste( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* Module )
/*************************************************************************/

/* Construit la liste des segments connectes aus pads du module Module
 *  pour le drag de ces segments
 *  la liste est mise a l'adresse pointee par pt_drag.
 *  la variable globale nb_drag_segment est incrementee du nombre de segments
 *  Met l'attribut EDIT sur les segments selectionnes
 *  et les affiche en mode EDIT (sketch)
/** Build the list of track segments connected to pads of a given module
 *  by populate the std::vector<DRAG_SEGM> g_DragSegmentList
 *  For each selected track segment set the EDIT flag
 *  and redraw them in EDIT mode (sketch mode)
 */
{
    D_PAD* pt_pad;
@@ -115,9 +86,11 @@ void Build_Drag_Liste( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* Module )
/**********************************************************************************/
void Build_1_Pad_SegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC, D_PAD* PtPad )
/**********************************************************************************/

/* Routine construisant la liste les segments de piste connectes au pad PtPad
 *  Les net_codes sont supposes a jour.
/** Build the list of track segments connected to a given pad
 *  by populate the std::vector<DRAG_SEGM> g_DragSegmentList
 *  For each selected track segment set the EDIT flag
 *  and redraw them in EDIT mode (sketch mode)
 *  Net codes must be OK.
 */
{
    TRACK*  Track;
@@ -133,21 +106,21 @@ void Build_1_Pad_SegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC, D_PAD* PtPad
    for( ; Track; Track = Track->Next() )
    {
        if( Track->GetNet() != net_code )
            break;                                                      /* hors zone */
            break;

        if( ( MasqueLayer & Track->ReturnMaskLayer() ) == 0 )
            continue;                                                   /* couches differentes */
            continue;

        if( pos == Track->m_Start )
        {
            AddSegmentToDragList( panel, DC, STARTPOINT, Track );
            g_DragSegmentList->m_Pad_Start = PtPad;
            g_DragSegmentList.back().m_Pad_Start = PtPad;
        }

        if( pos == Track->m_End )
        {
            AddSegmentToDragList( panel, DC, ENDPOINT, Track );
            g_DragSegmentList->m_Pad_End = PtPad;
            g_DragSegmentList.back().m_Pad_End = PtPad;
        }
    }
}
@@ -157,23 +130,17 @@ void Build_1_Pad_SegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC, D_PAD* PtPad
void AddSegmentToDragList( WinEDA_DrawPanel* panel, wxDC* DC,
                           int flag, TRACK* Track )
/******************************************************************/

/* Add the segment"Track" to the drag list, and erase it from screen
 *  flag = STARTPOINT (if the point to drag is the start point of Track) or ENDPOINT
 */
{
    DRAG_SEGM* pt_drag;

    pt_drag = new DRAG_SEGM( Track );

    pt_drag->Pnext = g_DragSegmentList;
    g_DragSegmentList = pt_drag;
    DRAG_SEGM wrapper( Track );

    if( (flag & STARTPOINT) )
        pt_drag->m_Flag |= 1;
        wrapper.m_Flag |= 1;

    if( (flag & ENDPOINT) )
        pt_drag->m_Flag |= 2;
        wrapper.m_Flag |= 2;

    Track->Draw( panel, DC, GR_XOR );
    Track->SetState( EDIT, ON );
@@ -185,66 +152,68 @@ void AddSegmentToDragList( WinEDA_DrawPanel* panel, wxDC* DC,
        Track->m_Flags |= ENDPOINT;

    Track->Draw( panel, DC, GR_XOR );
    g_DragSegmentList.push_back( wrapper );
}


/**********************************************************************************/
void Collect_TrackSegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC,
                                  wxPoint& point, int MasqueLayer, int net_code )
                                  wxPoint& aRefPos, int MasqueLayer, int net_code )
/**********************************************************************************/

/* Routine construisant la liste les segments de piste connectes a la via Via
 *  Les net_codes sont supposes a jour.
/* Build the list of tracks connected to the ref point
 *  Net codes must be OK.
 * @param aRefPos = reference point of connection
 */
{
    BOARD* pcb = ( (WinEDA_BasePcbFrame*)( panel->GetParent() ) )->GetBoard();

    TRACK* track = pcb->m_Track->GetStartNetCode( net_code );

    for( ; track; track = track->Next() )
    {
        if( track->GetNet() != net_code )
            break;                                                      /* hors zone */
        if( track->GetNet() != net_code )   // Bad net, not connected
            break;

        if( ( MasqueLayer & track->ReturnMaskLayer() ) == 0 )
            continue;                                                   /* couches differentes */
            continue;                       // Cannot be connected, not on the same layer

        if( track->m_Flags & IS_DRAGGED )
            continue;                                                   // already in list
            continue;                       // already put in list

        if( track->m_Start == point )
        {
            AddSegmentToDragList( panel, DC, STARTPOINT, track );
        }
        int flag = 0;
        
        if( track->m_End == point )
        if( (track->m_Start == aRefPos) && ((track->m_Flags & STARTPOINT) == 0) )
            flag |= STARTPOINT;

        if( track->m_End == aRefPos && ((track->m_Flags & ENDPOINT) == 0)  )
            flag |= ENDPOINT;

        // Note: vias will be flagged with both STARTPOINT and ENDPOINT
        // and must not be entered twice.
        if( flag )
        {
            AddSegmentToDragList( panel, DC, ENDPOINT, track );
            AddSegmentToDragList( panel, DC, flag, track );
            // If a connected via is found at location aRefPos,
            // collect also tracks connected by this via.
            if( track->Type() == TYPE_VIA )
                Collect_TrackSegmentsToDrag( panel, DC, aRefPos,
                                            track->ReturnMaskLayer(),
                                            net_code );
        }
    }
}


/*****************************/
void EraseDragListe()
/*****************************/

/* Routine de liberation memoire de la liste des structures DRAG_SEGM
 *  remet a zero le pointeur global g_DragSegmentList
/** function EraseDragList
 * clear the .m_Flags of all track segments found in g_DragSegmentList
 * and clear the list.
 * the memory is not freed and will be reused when creating a new list
 */
void EraseDragList()
{
    DRAG_SEGM* pt_drag;
    DRAG_SEGM* NextStruct;

    if( g_DragSegmentList == NULL )
        return;

    pt_drag = g_DragSegmentList;
    for( ; pt_drag != NULL; pt_drag = NextStruct )
    {
        NextStruct = pt_drag->Pnext;
        pt_drag->m_Segm->m_Flags = 0;
        delete pt_drag;
    }
    for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
        g_DragSegmentList[ii].m_Segm->m_Flags = 0;

    g_DragSegmentList = NULL;
    g_DragSegmentList.clear();
}
+15 −24
Original line number Diff line number Diff line
@@ -112,20 +112,15 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
    if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
        DrawGeneralRatsnest( DC );

    if( g_DragSegmentList ) /* Should not occur ! */
    {
        EraseDragListe();
    }
    EraseDragList();
 
    if( g_Drag_Pistes_On )
    {
        Build_Drag_Liste( DrawPanel, DC, module );
        ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
        for( DRAG_SEGM* pt_drag = g_DragSegmentList;
             pt_drag != NULL;
             pt_drag = pt_drag->Pnext )
        for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
        {
            TRACK* segm = pt_drag->m_Segm;
            TRACK* segm = g_DragSegmentList[ii].m_Segm;
            itemWrapper.m_PickedItem = segm;
            itemWrapper.m_Link = segm->Copy();
            itemWrapper.m_Link->SetState( EDIT, OFF );
@@ -155,7 +150,6 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
 */
void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
{
    DRAG_SEGM*            pt_drag;
    TRACK*                pt_segm;
    MODULE*               module;
    WinEDA_PcbFrame*      pcbframe = (WinEDA_PcbFrame*) Panel->GetParent();
@@ -176,24 +170,23 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
            if( g_Drag_Pistes_On )
            {
                /* Erase on screen dragged tracks */
                pt_drag = g_DragSegmentList;
                for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
                for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
                {
                    pt_segm = pt_drag->m_Segm;
                    pt_segm = g_DragSegmentList[ii].m_Segm;
                    pt_segm->Draw( Panel, DC, GR_XOR );
                }
            }

            /* Go to old position for dragged tracks */
            pt_drag = g_DragSegmentList;
            for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
            for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
            {
                pt_segm = pt_drag->m_Segm; pt_segm->SetState( EDIT, OFF );
                pt_drag->SetInitialValues();
                pt_segm = g_DragSegmentList[ii].m_Segm;
                pt_segm->SetState( EDIT, OFF );
                g_DragSegmentList[ii].SetInitialValues();
                pt_segm->Draw( Panel, DC, GR_OR );
            }

            EraseDragListe();
            EraseDragList();
            module->m_Flags = 0;
        }

@@ -466,21 +459,19 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module,
    if( DC )
        module->Draw( DrawPanel, DC, GR_OR );

    if( g_DragSegmentList )
    if( g_DragSegmentList.size() )
    {
        /* Redraw dragged track segments */
        for( DRAG_SEGM* pt_drag = g_DragSegmentList;
             pt_drag != NULL;
             pt_drag = pt_drag->Pnext )
        for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
        {
            pt_segm = pt_drag->m_Segm;
            pt_segm = g_DragSegmentList[ii].m_Segm;
            pt_segm->SetState( EDIT, OFF );
            if( DC )
                pt_segm->Draw( DrawPanel, DC, GR_OR );
        }

        // Delete drag list
        EraseDragListe();
        EraseDragList();
    }

    g_Drag_Pistes_On = FALSE;
Loading