2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file drag.h
|
2012-09-11 07:33:17 +00:00
|
|
|
* @brief Useful classes and functions used to collect tracks to drag
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/gdicmn.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_track.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class wxDC;
|
|
|
|
class EDA_DRAW_PANEL;
|
|
|
|
class MODULE;
|
|
|
|
class D_PAD;
|
2012-09-11 07:33:17 +00:00
|
|
|
class CONNECTIONS;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
/** Helper classes to handle a list of track segments to drag
|
2010-08-31 15:54:05 +00:00
|
|
|
* and has info to undo/abort the move command
|
|
|
|
*/
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-09-11 07:33:17 +00:00
|
|
|
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
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2012-09-11 07:33:17 +00:00
|
|
|
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() {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set auxiliary parameters relative to calucaltions needed
|
|
|
|
* to find track ends positions while dragging pads
|
2012-09-12 17:28:55 +00:00
|
|
|
* and when modules are rotated, flipped
|
2012-09-11 07:33:17 +00:00
|
|
|
*/
|
|
|
|
void SetAuxParameters();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
/**
|
|
|
|
* Calculate track ends position while dragging pads
|
2012-09-12 17:28:55 +00:00
|
|
|
* and when modules are rotated, flipped
|
2012-09-11 07:33:17 +00:00
|
|
|
* @param aOffset = offset of module or pad position (when moving)
|
|
|
|
*/
|
|
|
|
void SetTrackEndsCoordinates(wxPoint aOffset);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
void RestoreInitialValues()
|
|
|
|
{
|
|
|
|
m_Track->SetStart( m_startInitialValue );
|
|
|
|
m_Track->SetEnd( m_endInitialValue );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DRAG_LIST
|
|
|
|
{
|
2007-11-02 18:21:43 +00:00
|
|
|
public:
|
2012-09-11 07:33:17 +00:00
|
|
|
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
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
std::vector<DRAG_SEGM_PICKER> m_DragList; // The list of DRAG_SEGM_PICKER items
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
public:
|
|
|
|
DRAG_LIST( BOARD * aPcb )
|
2010-08-31 15:54:05 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
m_Brd = aPcb;
|
2010-08-31 15:54:05 +00:00
|
|
|
}
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
void fillList(CONNECTIONS& aConnections);
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// Global variables:
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// 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;
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// Functions:
|
|
|
|
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC );
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2010-11-12 16:59:16 +00:00
|
|
|
/**
|
|
|
|
* Function EraseDragList
|
2012-09-11 07:33:17 +00:00
|
|
|
* clear the .m_Flags of all track segments stored in g_DragSegmentList
|
2010-08-31 15:54:05 +00:00
|
|
|
* and clear the list.
|
2012-09-11 07:33:17 +00:00
|
|
|
* In order to avoid useless memory reallocation, the memory is not freed
|
2010-08-31 15:54:05 +00:00
|
|
|
* and will be reused when creating a new list
|
|
|
|
*/
|
|
|
|
void EraseDragList();
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
/*
|
|
|
|
* function used to collect track segments in drag track segment
|
|
|
|
*/
|
|
|
|
void Collect_TrackSegmentsToDrag( BOARD* aPcb, wxPoint& point, int LayerMask, int net_code );
|
|
|
|
|
|
|
|
/* Add aTrack to the drag list
|
2010-08-31 15:54:05 +00:00
|
|
|
* flag = STARTPOINT (if the point to drag is the start point of Track)
|
2012-09-11 07:33:17 +00:00
|
|
|
* 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
|
2007-11-02 18:21:43 +00:00
|
|
|
*/
|
2012-09-11 07:33:17 +00:00
|
|
|
void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
|
|
|
|
|
|
|
|
|