2010-08-31 15:54:05 +00:00
|
|
|
/*********************************/
|
|
|
|
/* functions used to drag tracks */
|
|
|
|
/*********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
/* Fichier dragsegm.cpp */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <drag.h>
|
|
|
|
#include <pcbnew.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_board.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/* a list of DRAG_SEGM items used to move or drag tracks */
|
|
|
|
std::vector<DRAG_SEGM> g_DragSegmentList;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/* helper class to handle a list of track segments to drag or move
|
|
|
|
*/
|
2007-11-02 18:21:43 +00:00
|
|
|
DRAG_SEGM::DRAG_SEGM( TRACK* segm )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-11-02 18:21:43 +00:00
|
|
|
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;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Redraw the list of segments starting in g_DragSegmentList, while moving a footprint */
|
2011-09-07 19:41:04 +00:00
|
|
|
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList.size() == 0 )
|
2007-11-02 18:21:43 +00:00
|
|
|
return;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
wxPoint pos;
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
TRACK* track = g_DragSegmentList[ii].m_Segm;
|
|
|
|
|
2010-12-28 22:38:59 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2012-02-19 04:02:19 +00:00
|
|
|
track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
|
2010-12-28 22:38:59 +00:00
|
|
|
#endif
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
D_PAD* pad = g_DragSegmentList[ii].m_Pad_Start;
|
|
|
|
|
|
|
|
if( pad )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
pos = pad->GetPosition() - g_Offset_Module;
|
|
|
|
track->m_Start = pos;
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad = g_DragSegmentList[ii].m_Pad_End;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pad )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
pos = pad->GetPosition() - g_Offset_Module;
|
|
|
|
track->m_End = pos;
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
track->Draw( panel, DC, GR_XOR );
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/** 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)
|
2007-11-02 18:21:43 +00:00
|
|
|
*/
|
2012-02-19 04:02:19 +00:00
|
|
|
void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* aModule )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
Build_1_Pad_SegmentsToDrag( panel, DC, pad );
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/** 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.
|
2007-11-02 18:21:43 +00:00
|
|
|
*/
|
2012-02-19 04:02:19 +00:00
|
|
|
void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* aPad )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard();
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int net_code = aPad->GetNet();
|
|
|
|
|
|
|
|
TRACK* track = pcb->m_Track->GetStartNetCode( net_code );
|
|
|
|
|
|
|
|
wxPoint pos = aPad->GetPosition();
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int layerMask = aPad->GetLayerMask();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
for( ; track; track = track->Next() )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
if( track->GetNet() != net_code )
|
2010-08-31 15:54:05 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( ( layerMask & track->ReturnMaskLayer() ) == 0 )
|
2010-08-31 15:54:05 +00:00
|
|
|
continue;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pos == track->m_Start )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
AddSegmentToDragList( panel, DC, STARTPOINT, track );
|
|
|
|
g_DragSegmentList.back().m_Pad_Start = aPad;
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pos == track->m_End )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
AddSegmentToDragList( panel, DC, ENDPOINT, track );
|
|
|
|
g_DragSegmentList.back().m_Pad_End = aPad;
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Add the segment"Track" to the drag list, and erase it from screen
|
2007-11-02 18:21:43 +00:00
|
|
|
* flag = STARTPOINT (if the point to drag is the start point of Track) or ENDPOINT
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Track )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
DRAG_SEGM wrapper( Track );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
if( (flag & STARTPOINT) )
|
2010-08-31 15:54:05 +00:00
|
|
|
wrapper.m_Flag |= 1;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
if( (flag & ENDPOINT) )
|
2010-08-31 15:54:05 +00:00
|
|
|
wrapper.m_Flag |= 2;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
Track->Draw( panel, DC, GR_XOR );
|
2011-02-13 17:53:48 +00:00
|
|
|
Track->SetState( IN_EDIT, ON );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
if( (flag & STARTPOINT) )
|
2011-12-21 13:42:02 +00:00
|
|
|
Track->SetFlags( STARTPOINT );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
if( (flag & ENDPOINT) )
|
2011-12-21 13:42:02 +00:00
|
|
|
Track->SetFlags( ENDPOINT );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
Track->Draw( panel, DC, GR_XOR );
|
2010-08-31 15:54:05 +00:00
|
|
|
g_DragSegmentList.push_back( wrapper );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/* Build the list of tracks connected to the ref point
|
2011-09-22 19:16:55 +00:00
|
|
|
* Net codes must be up to date, because only tracks having the right net code are tested.
|
2010-08-31 15:54:05 +00:00
|
|
|
* @param aRefPos = reference point of connection
|
2007-11-02 18:21:43 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC,
|
|
|
|
wxPoint& aRefPos, int LayerMask, int net_code )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard();
|
2007-11-02 18:21:43 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK* track = pcb->m_Track->GetStartNetCode( net_code );
|
2010-08-31 15:54:05 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
for( ; track; track = track->Next() )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2011-09-22 19:16:55 +00:00
|
|
|
if( track->GetNet() != net_code ) // not the same netcodenet code: all candidates tested
|
2010-08-31 15:54:05 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( LayerMask & track->ReturnMaskLayer() ) == 0 )
|
2010-08-31 15:54:05 +00:00
|
|
|
continue; // Cannot be connected, not on the same layer
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( track->IsDragging() )
|
2010-08-31 15:54:05 +00:00
|
|
|
continue; // already put in list
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
int flag = 0;
|
2010-11-12 16:36:43 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( (track->m_Start == aRefPos) && ((track->GetFlags() & STARTPOINT) == 0) )
|
2010-08-31 15:54:05 +00:00
|
|
|
flag |= STARTPOINT;
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( track->m_End == aRefPos && ((track->GetFlags() & ENDPOINT) == 0) )
|
2010-08-31 15:54:05 +00:00
|
|
|
flag |= ENDPOINT;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
// Note: vias will be flagged with both STARTPOINT and ENDPOINT
|
|
|
|
// and must not be entered twice.
|
|
|
|
if( flag )
|
2007-11-02 18:21:43 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
AddSegmentToDragList( panel, DC, flag, track );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
// If a connected via is found at location aRefPos,
|
|
|
|
// collect also tracks connected by this via.
|
2011-10-01 19:24:27 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
2011-09-07 19:41:04 +00:00
|
|
|
Collect_TrackSegmentsToDrag( panel, DC, aRefPos, track->ReturnMaskLayer(),
|
|
|
|
net_code );
|
2007-11-02 18:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function EraseDragList
|
2010-08-31 15:54:05 +00:00
|
|
|
* 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
|
2007-11-02 18:21:43 +00:00
|
|
|
*/
|
2010-08-31 15:54:05 +00:00
|
|
|
void EraseDragList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2011-12-21 13:42:02 +00:00
|
|
|
g_DragSegmentList[ii].m_Segm->ClearFlags();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
g_DragSegmentList.clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|