drag.h 6.72 KB
Newer Older
1 2
/**
 * @file drag.h
3
 * @brief Useful classes and functions used to collect tracks to drag
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
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
29

30 31 32 33
#ifndef _DRAG_H_
#define _DRAG_H_


34
#include <class_track.h>
35
#include <vector>
36 37 38


class wxDC;
39
class wxPoint;
40 41 42
class EDA_DRAW_PANEL;
class MODULE;
class D_PAD;
43
class CONNECTIONS;
44

45

46
/** Helper classes to handle a list of track segments to drag
47 48
 * and has info to undo/abort the move command
 */
49 50 51 52 53 54 55 56 57 58

 /*
  * a DRAG_LIST manages the list of track segments to modify
  * when the pad or the module is moving
  */

/*
  * a DRAG_SEGM_PICKER manage one track segment or a via
  */
class DRAG_SEGM_PICKER
59 60
{
public:
61 62 63 64 65 66 67 68
    TRACK*  m_Track;            // pointer to the parent track segment
    D_PAD*  m_Pad_Start;        // pointer to the moving pad
                                // if the start point should follow this pad
                                // or NULL
    D_PAD*  m_Pad_End;          // pointer to the moving pad
                                // if the end point should follow this pad
                                // or NULL
    bool    m_Flag;             // flag used in drag vias and drag track segment functions
69 70

private:
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    double  m_RotationOffset;   // initial orientation of the parent module
                                // Used to recalculate m_PadStartOffset and m_PadEndOffset
                                // after a module rotation when dragging
    bool    m_Flipped;          // initial side of the parent module
                                // Used to recalculate m_PadStartOffset and m_PadEndOffset
                                // if the module is flipped when dragging
    wxPoint m_PadStartOffset;   // offset between the pad and the starting point of the track
                                // usually 0,0, but not always
    wxPoint m_PadEndOffset;     // offset between the pad and the ending point of the track
                                // usually 0,0, but not always
    wxPoint m_startInitialValue;
    wxPoint m_endInitialValue;  // For abort command:
                                // initial m_Start and m_End values for m_Track

public:

    DRAG_SEGM_PICKER( TRACK* aTrack );
    ~DRAG_SEGM_PICKER() {};

    /**
91
     * Set auxiliary parameters relative to calculations needed
92
     * to find track ends positions while dragging pads
93
     * and when modules are rotated, flipped
94 95
     */
    void SetAuxParameters();
96

97 98
    /**
     * Calculate track ends position while dragging pads
99
     * and when modules are rotated, flipped
100 101
     * @param aOffset = offset of module or pad position (when moving)
     */
102
    void SetTrackEndsCoordinates( wxPoint aOffset );
103

104 105 106 107 108 109 110
    void RestoreInitialValues()
    {
        m_Track->SetStart( m_startInitialValue );
        m_Track->SetEnd( m_endInitialValue );
    }
};

111

112 113
class DRAG_LIST
{
dickelbeck's avatar
dickelbeck committed
114
public:
115 116 117
    BOARD*   m_Brd;         // the main board
    MODULE*  m_Module;      // The link to the module to move, or NULL
    D_PAD*   m_Pad;         // The link to the pad to move, or NULL
118

119
    std::vector<DRAG_SEGM_PICKER> m_DragList; // The list of DRAG_SEGM_PICKER items
120

121
public:
122
    DRAG_LIST( BOARD* aPcb )
123
    {
124
        m_Brd = aPcb;
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

    /**
     * Function ClearList
     * clear the .m_Flags of all track segments in m_DragList
     * and clear the list.
     */
    void ClearList();

    /** Build the list of track segments connected to pads of aModule
     *  in m_DragList
     *  For each selected track segment the EDIT flag is set
     */
    void BuildDragListe( MODULE* aModule );

    /** Build the list of track segments connected to aPad
     *  in m_DragList
     *  For each selected track segment the EDIT flag is set
     */
    void BuildDragListe( D_PAD* aPad );

private:

    /** Fills m_DragList with of track segments connected to pads in aConnections
     *  For each selected track segment the EDIT flag is set
     */
151
    void fillList( CONNECTIONS& aConnections );
152 153 154
};


155
// Global variables:
156

157 158 159
// a list of DRAG_SEGM_PICKER items used to move or drag tracks.
// Each DRAG_SEGM_PICKER item points a segment to move.
extern std::vector<DRAG_SEGM_PICKER> g_DragSegmentList;
dickelbeck's avatar
dickelbeck committed
160

161 162
// Functions:
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC );
dickelbeck's avatar
dickelbeck committed
163

164 165
/**
 * Function EraseDragList
166
 * clear the .m_Flags of all track segments stored in g_DragSegmentList
167
 * and clear the list.
168
 * In order to avoid useless memory reallocation, the memory is not freed
169 170 171 172
 * and will be reused when creating a new list
 */
void EraseDragList();

173
/**
174
 * Function Collect_TrackSegmentsToDrag.
175 176 177 178
 * used to collect track segments in drag track segment
 * Build the list of tracks connected to the ref point by calling
 * AddSegmentToDragList for each selected track
 * Net codes must be up to date, because only tracks having the right net code are tested.
179 180
 *
 * @param aPcb A point the the #BOARD object to collect track segment to drag.
181 182 183 184
 * @param aRefPos = reference point of connection
 * @param aLayerMask = layers mask to collect tracks
 * @param aNetCode = the net code to consider
 * @param aMaxDist = max distance from aRefPos to a track end candidate to collect the track
185
 */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
186
void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LSET aLayerMask,
187
                                  int aNetCode, int aMaxDist );
188 189

/* Add aTrack to the drag list
190
 * flag = STARTPOINT (if the point to drag is the start point of Track)
191 192 193 194 195 196 197 198
 * or ENDPOINT (if the point to drag is the end point of Track)
 */
void AddSegmentToDragList( int flag, TRACK* aTrack );

/*
 * Undraw the track segments in list, and set the EDIT flag
 * Usually called after the track list is built, to prepare
 * the redraw of the list when the mouse is moved
dickelbeck's avatar
dickelbeck committed
199
 */
200 201 202
void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );


203
#endif    // _DRAG_H_