2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-17 20:01:27 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
/**
|
|
|
|
* @file move_or_drag_track.cpp
|
|
|
|
* @brief Track editing routines to move and drag track segments or node.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <gr_basic.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <drc_stuff.h>
|
|
|
|
#include <drag.h>
|
|
|
|
#include <pcbnew_id.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
|
|
|
static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel,
|
|
|
|
wxDC* aDC,
|
|
|
|
const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2011-01-21 19:30:59 +00:00
|
|
|
static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2007-09-01 12:00:30 +00:00
|
|
|
static bool InitialiseDragParameters();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
static wxPoint PosInit, s_LastPos;
|
2009-11-18 12:52:19 +00:00
|
|
|
static double s_StartSegmentSlope, s_EndSegmentSlope,
|
|
|
|
s_MovingSegmentSlope,
|
2007-08-10 19:14:51 +00:00
|
|
|
s_StartSegment_Yorg, s_EndSegment_Yorg,
|
|
|
|
s_MovingSegment_Yorg; //slope and intercept parameters of lines
|
2009-11-18 12:52:19 +00:00
|
|
|
bool s_StartPointVertical, s_EndPointVertical,
|
|
|
|
s_MovingSegmentVertical, s_MovingSegmentHorizontal,
|
|
|
|
s_StartPointHorizontal, s_EndPointHorizontal; // vertical or
|
|
|
|
// horizontal line
|
|
|
|
// indicators
|
|
|
|
bool s_StartSegmentPresent, s_EndSegmentPresent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
static PICKED_ITEMS_LIST s_ItemsListPicker;
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
/** Abort function for drag or move track
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2012-09-11 07:33:17 +00:00
|
|
|
static void Abort_MoveTrack( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) aPanel->GetParent();
|
|
|
|
BOARD * pcb = frame->GetBoard();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
pcb->HighLightOFF();
|
2012-09-11 07:33:17 +00:00
|
|
|
pcb->PopHighLight();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
frame->SetCurItem( NULL );
|
|
|
|
aPanel->SetMouseCapture( NULL, NULL );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Undo move and redraw trace segments.
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned jj=0 ; jj < g_DragSegmentList.size(); jj++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK* track = g_DragSegmentList[jj].m_Track;
|
|
|
|
g_DragSegmentList[jj].RestoreInitialValues();
|
2013-03-27 18:32:12 +00:00
|
|
|
track->SetState( IN_EDIT, false );
|
2012-09-11 07:33:17 +00:00
|
|
|
track->ClearFlags();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
// Clear the undo picker list:
|
|
|
|
s_ItemsListPicker.ClearListAndDeleteItems();
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2012-09-11 07:33:17 +00:00
|
|
|
aPanel->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Redraw the moved node according to the mouse cursor position
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) aPanel->GetDisplayOptions();
|
2009-11-18 12:52:19 +00:00
|
|
|
wxPoint moveVector;
|
2015-01-10 10:27:49 +00:00
|
|
|
int tmp = displ_opts->m_DisplayPcbTrackFill;
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayPcbTrackFill = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-01-10 21:55:07 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2011-02-03 19:27:28 +00:00
|
|
|
aErase = true;
|
2012-01-10 21:55:07 +00:00
|
|
|
#else
|
|
|
|
aErase = false;
|
|
|
|
#endif
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// set the new track coordinates
|
|
|
|
wxPoint Pos = aPanel->GetParent()->GetCrossHairPosition();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
moveVector = Pos - s_LastPos;
|
2009-11-18 12:52:19 +00:00
|
|
|
s_LastPos = Pos;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK *track = NULL;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-12-23 10:55:24 +00:00
|
|
|
track = g_DragSegmentList[ii].m_Track;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
|
|
|
if( aErase )
|
2012-09-11 07:33:17 +00:00
|
|
|
track->Draw( aPanel, aDC, draw_mode );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( track->GetFlags() & STARTPOINT )
|
2013-01-13 00:04:00 +00:00
|
|
|
track->SetStart( track->GetStart() + moveVector );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( track->GetFlags() & ENDPOINT )
|
2013-01-13 00:04:00 +00:00
|
|
|
track->SetEnd( track->GetEnd() + moveVector );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
2013-01-13 00:04:00 +00:00
|
|
|
track->SetEnd( track->GetStart() );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
track->Draw( aPanel, aDC, draw_mode );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayPcbTrackFill = tmp;
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
// Display track length
|
2012-09-11 07:33:17 +00:00
|
|
|
if( track )
|
|
|
|
{
|
|
|
|
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
|
2013-01-12 17:32:24 +00:00
|
|
|
frame->SetMsgPanel( track );
|
2012-09-11 07:33:17 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* drawing the track segment movement
|
2007-08-10 19:14:51 +00:00
|
|
|
* > s_MovingSegmentSlope slope = moving track segment slope
|
2009-11-18 12:52:19 +00:00
|
|
|
* > s_StartSegmentSlope slope = slope of the segment connected to the start
|
|
|
|
* point of the moving segment
|
|
|
|
* > s_EndSegmentSlope slope = slope of the segment connected to the end point
|
|
|
|
* of the moving segment
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2007-08-10 19:14:51 +00:00
|
|
|
* moved segment function :
|
|
|
|
* yt=s_MovingSegmentSlope * x + s_MovingSegment_Yorg
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2007-08-10 19:14:51 +00:00
|
|
|
* segment connected to moved segment's start:
|
|
|
|
* y1 = s_StartSegmentSlope * x + s_StartSegment_Yorg
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2007-08-10 19:14:51 +00:00
|
|
|
* segment connected to moved segment's end:
|
|
|
|
* y2=s_EndSegmentSlope * x + s_EndSegment_Yorg
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2007-08-10 19:14:51 +00:00
|
|
|
* first intersection point will be located at
|
|
|
|
* y1=yt ->
|
2009-11-18 12:52:19 +00:00
|
|
|
*
|
|
|
|
* xi1=(s_MovingSegment_Yorg-s_StartSegment_Yorg)/(s_StartSegmentSlope-s_MovingSegmentSlope)
|
2007-08-10 19:14:51 +00:00
|
|
|
* yi1=s_MovingSegmentSlope*xi1+s_MovingSegment_Yorg
|
|
|
|
* or yi1=s_StartSegmentSlope*xi1+s_MovingSegment_Yorg
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2007-08-10 19:14:51 +00:00
|
|
|
* second intersection point
|
|
|
|
* y2=yt ->
|
2009-11-18 12:52:19 +00:00
|
|
|
*
|
|
|
|
* xi2=(s_MovingSegment_Yorg-s_StartSegment_Yorg)/(s_MovingSegmentSlope-s_MovingSegmentSlope)
|
2007-08-10 19:14:51 +00:00
|
|
|
* yi2=s_MovingSegmentSlope*xi2+s_MovingSegment_Yorg
|
|
|
|
* or yi1=s_EndSegmentSlope*xi2+s_MovingSegment_Yorg
|
|
|
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
* !!!!! special attention to vertical segments because
|
|
|
|
* !!!!! their slope=infinite
|
|
|
|
* !!!!! intersection point will be calculated using the
|
|
|
|
* !!!!! segment intersecting it
|
|
|
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
2007-08-20 01:20:48 +00:00
|
|
|
*
|
2009-11-18 12:52:19 +00:00
|
|
|
* Slope parameters are computed once, because they can become undetermined
|
|
|
|
* when moving segments
|
|
|
|
* (i.e. when a segment length is 0) and we want keep them constant
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-15 17:58:35 +00:00
|
|
|
double xi1 = 0, yi1 = 0, xi2 = 0, yi2 = 0; // calculated intersection points
|
|
|
|
double tx1, tx2, ty1, ty2; // temporary storage of points
|
2007-08-10 19:14:51 +00:00
|
|
|
int dx, dy;
|
|
|
|
bool update = true;
|
|
|
|
TRACK* Track;
|
|
|
|
TRACK* tSegmentToStart = NULL, * tSegmentToEnd = NULL;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList.size() == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
/* get the segments :
|
|
|
|
* from last to first in list are:
|
|
|
|
* the segment to move
|
|
|
|
* the segment connected to its end point (if exists)
|
|
|
|
* the segment connected to its start point (if exists)
|
|
|
|
*/
|
|
|
|
int ii = g_DragSegmentList.size() - 1;
|
2012-09-11 07:33:17 +00:00
|
|
|
Track = g_DragSegmentList[ii].m_Track;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2007-12-14 22:31:45 +00:00
|
|
|
if( Track == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
ii--;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( ii >= 0)
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
if( s_EndSegmentPresent )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
// Get the segment connected to the end point
|
2012-09-11 07:33:17 +00:00
|
|
|
tSegmentToEnd = g_DragSegmentList[ii].m_Track;
|
2010-08-31 15:54:05 +00:00
|
|
|
ii--;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( s_StartSegmentPresent )
|
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
// Get the segment connected to the start point
|
|
|
|
if( ii >= 0 )
|
2012-09-11 07:33:17 +00:00
|
|
|
tSegmentToStart = g_DragSegmentList[ii].m_Track;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Undraw the current moved track segments before modification
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-01-10 21:55:07 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2011-09-15 17:58:35 +00:00
|
|
|
// if( erase )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
Track->Draw( aPanel, aDC, draw_mode );
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToStart )
|
2011-02-03 19:27:28 +00:00
|
|
|
tSegmentToStart->Draw( aPanel, aDC, draw_mode );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToEnd )
|
2011-02-03 19:27:28 +00:00
|
|
|
tSegmentToEnd->Draw( aPanel, aDC, draw_mode );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2012-01-23 04:33:36 +00:00
|
|
|
#endif
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Compute the new track segment position
|
|
|
|
wxPoint Pos = aPanel->GetParent()->GetCrossHairPosition();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
dx = Pos.x - s_LastPos.x;
|
|
|
|
dy = Pos.y - s_LastPos.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// move the line by dx and dy
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) ( Track->GetStart().x + dx );
|
|
|
|
ty1 = (double) ( Track->GetStart().y + dy );
|
|
|
|
tx2 = (double) ( Track->GetEnd().x + dx );
|
|
|
|
ty2 = (double) ( Track->GetEnd().y + dy );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
// recalculate the segments new parameters and intersection points
|
|
|
|
// only the intercept will change, segment slopes does not change
|
|
|
|
// because we are moving parallel with is initial state
|
|
|
|
if( !s_MovingSegmentVertical )
|
2009-11-18 12:52:19 +00:00
|
|
|
s_MovingSegment_Yorg = ty1 - ( s_MovingSegmentSlope * tx1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ( !s_EndPointVertical ) && ( !s_MovingSegmentVertical ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
xi2 = ( s_MovingSegment_Yorg - s_EndSegment_Yorg )
|
|
|
|
/ ( s_EndSegmentSlope - s_MovingSegmentSlope );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_EndPointVertical )
|
|
|
|
xi2 = tx2;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//P1=P2
|
|
|
|
if( !s_EndPointHorizontal )
|
|
|
|
xi2 = tx2 - dx;
|
|
|
|
else
|
|
|
|
update = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !s_MovingSegmentVertical )
|
2015-02-27 14:33:13 +00:00
|
|
|
yi2 = ( s_MovingSegmentSlope * xi2 ) + s_MovingSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_EndPointVertical )
|
2015-02-27 14:33:13 +00:00
|
|
|
yi2 = ( s_EndSegmentSlope * xi2 ) + s_EndSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_EndPointHorizontal )
|
|
|
|
update = false;
|
2015-02-27 14:33:13 +00:00
|
|
|
else
|
|
|
|
yi2 = ( s_MovingSegmentSlope * xi2 ) + s_MovingSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ( !s_StartPointVertical ) && ( !s_MovingSegmentVertical ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
xi1 = ( s_MovingSegment_Yorg - s_StartSegment_Yorg )
|
|
|
|
/ ( s_StartSegmentSlope - s_MovingSegmentSlope );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_StartPointVertical )
|
|
|
|
xi1 = tx1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//P1=P2
|
|
|
|
if( !s_StartPointHorizontal )
|
|
|
|
xi1 = tx1 - dx;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_StartPointHorizontal )
|
|
|
|
update = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !s_MovingSegmentVertical )
|
2015-02-27 14:33:13 +00:00
|
|
|
yi1 = ( s_MovingSegmentSlope * xi1 ) + s_MovingSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_StartPointVertical )
|
2015-02-27 14:33:13 +00:00
|
|
|
yi1 = ( s_StartSegmentSlope * xi1 ) + s_StartSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !s_StartPointHorizontal )
|
|
|
|
update = false;
|
|
|
|
else
|
2015-02-27 14:33:13 +00:00
|
|
|
yi2 = ( s_MovingSegmentSlope * xi1 ) + s_MovingSegment_Yorg;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the segment coordinates (if possible)
|
|
|
|
if( tSegmentToStart == NULL )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
xi1 = tx1;
|
2007-12-14 22:31:45 +00:00
|
|
|
yi1 = ty1;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToEnd == NULL )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
xi2 = tx2;
|
2007-12-14 22:31:45 +00:00
|
|
|
yi2 = ty2;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( update )
|
|
|
|
{
|
|
|
|
s_LastPos = Pos;
|
2013-01-13 00:04:00 +00:00
|
|
|
Track->SetStart( wxPoint( KiROUND( xi1 ), KiROUND( yi1 ) ) );
|
|
|
|
Track->SetEnd( wxPoint( KiROUND( xi2 ), KiROUND( yi2 ) ) );
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToEnd )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( tSegmentToEnd->GetFlags() & STARTPOINT )
|
2013-01-13 00:04:00 +00:00
|
|
|
tSegmentToEnd->SetStart( Track->GetEnd() );
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
2013-01-13 00:04:00 +00:00
|
|
|
tSegmentToEnd->SetEnd( Track->GetEnd() );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-02-03 19:27:28 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToStart )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( tSegmentToStart->GetFlags() & STARTPOINT )
|
2013-01-13 00:04:00 +00:00
|
|
|
tSegmentToStart->SetStart( Track->GetStart() );
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
2013-01-13 00:04:00 +00:00
|
|
|
tSegmentToStart->SetEnd( Track->GetStart() );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
Track->Draw( aPanel, aDC, draw_mode );
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToStart )
|
2011-02-03 19:27:28 +00:00
|
|
|
tSegmentToStart->Draw( aPanel, aDC, draw_mode );
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToEnd )
|
2011-02-03 19:27:28 +00:00
|
|
|
tSegmentToEnd->Draw( aPanel, aDC, draw_mode );
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
// Display track length
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
|
2013-01-12 17:32:24 +00:00
|
|
|
frame->SetMsgPanel( Track );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Init variables (slope, Y intersect point, flags) for
|
|
|
|
* Show_Drag_Track_Segment_With_Cte_Slope()
|
2010-08-31 15:54:05 +00:00
|
|
|
* return true if Ok, false if dragging is not possible
|
2007-08-10 19:14:51 +00:00
|
|
|
* (2 colinear segments)
|
|
|
|
*/
|
2009-11-18 12:52:19 +00:00
|
|
|
bool InitialiseDragParameters()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
double tx1, tx2, ty1, ty2; // temporary storage of points
|
|
|
|
TRACK* Track;
|
|
|
|
TRACK* tSegmentToStart = NULL, * tSegmentToEnd = NULL;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList.size() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* get the segments :
|
|
|
|
* from last to first in list are:
|
|
|
|
* the segment to move
|
|
|
|
* the segment connected to its end point (if exists)
|
|
|
|
* the segment connected to its start point (if exists)
|
|
|
|
*/
|
|
|
|
int ii = g_DragSegmentList.size() - 1;
|
2012-09-11 07:33:17 +00:00
|
|
|
Track = g_DragSegmentList[ii].m_Track;
|
2007-08-10 19:14:51 +00:00
|
|
|
if( Track == NULL )
|
2010-08-31 15:54:05 +00:00
|
|
|
return false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
ii--;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( ii >= 0)
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
if( s_EndSegmentPresent )
|
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
tSegmentToEnd = g_DragSegmentList[ii].m_Track; // Get the segment connected to
|
2011-09-15 17:58:35 +00:00
|
|
|
// the end point
|
2010-08-31 15:54:05 +00:00
|
|
|
ii--;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( s_StartSegmentPresent )
|
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
if( ii >= 0 )
|
2012-09-11 07:33:17 +00:00
|
|
|
tSegmentToStart = g_DragSegmentList[ii].m_Track; // Get the segment connected to
|
2011-09-07 19:41:04 +00:00
|
|
|
// the start point
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-05 13:41:34 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
// would be nice to eliminate collinear segments here, so we don't
|
|
|
|
// have to deal with that annoying "Unable to drag this segment: two
|
2009-11-18 12:52:19 +00:00
|
|
|
// collinear segments"
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-03-05 13:41:34 +00:00
|
|
|
s_StartPointVertical = false;
|
2009-11-18 12:52:19 +00:00
|
|
|
s_EndPointVertical = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
s_MovingSegmentVertical = false;
|
|
|
|
s_StartPointHorizontal = false;
|
|
|
|
s_EndPointHorizontal = false;
|
|
|
|
s_MovingSegmentHorizontal = false;
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
// Init parameters for the starting point of the moved segment
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToStart )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( tSegmentToStart->GetFlags() & ENDPOINT )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) tSegmentToStart->GetStart().x;
|
|
|
|
ty1 = (double) tSegmentToStart->GetStart().y;
|
|
|
|
tx2 = (double) tSegmentToStart->GetEnd().x;
|
|
|
|
ty2 = (double) tSegmentToStart->GetEnd().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) tSegmentToStart->GetEnd().x;
|
|
|
|
ty1 = (double) tSegmentToStart->GetEnd().y;
|
|
|
|
tx2 = (double) tSegmentToStart->GetStart().x;
|
|
|
|
ty2 = (double) tSegmentToStart->GetStart().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-13 00:04:00 +00:00
|
|
|
else // move the start point on a line starting at Track->GetStart(), and perpendicular to Track
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) Track->GetStart().x;
|
|
|
|
ty1 = (double) Track->GetStart().y;
|
|
|
|
tx2 = (double) Track->GetEnd().x;
|
|
|
|
ty2 = (double) Track->GetEnd().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
RotatePoint( &tx2, &ty2, tx1, ty1, 900 );
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( tx1 != tx2 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
s_StartSegmentSlope = ( ty2 - ty1 ) / ( tx2 - tx1 );
|
|
|
|
s_StartSegment_Yorg = ty1 - ( ty2 - ty1 ) * tx1 / ( tx2 - tx1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_StartPointVertical = true; //signal first segment vertical
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ty1 == ty2 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
s_StartPointHorizontal = true;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
// Init parameters for the ending point of the moved segment
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tSegmentToEnd )
|
|
|
|
{
|
|
|
|
//check if second line is vertical
|
2011-12-21 13:42:02 +00:00
|
|
|
if( tSegmentToEnd->GetFlags() & STARTPOINT )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) tSegmentToEnd->GetStart().x;
|
|
|
|
ty1 = (double) tSegmentToEnd->GetStart().y;
|
|
|
|
tx2 = (double) tSegmentToEnd->GetEnd().x;
|
|
|
|
ty2 = (double) tSegmentToEnd->GetEnd().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) tSegmentToEnd->GetEnd().x;
|
|
|
|
ty1 = (double) tSegmentToEnd->GetEnd().y;
|
|
|
|
tx2 = (double) tSegmentToEnd->GetStart().x;
|
|
|
|
ty2 = (double) tSegmentToEnd->GetStart().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-13 00:04:00 +00:00
|
|
|
else // move the start point on a line starting at Track->GetEnd(), and perpendicular to Track
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) Track->GetEnd().x;
|
|
|
|
ty1 = (double) Track->GetEnd().y;
|
|
|
|
tx2 = (double) Track->GetStart().x;
|
|
|
|
ty2 = (double) Track->GetStart().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
RotatePoint( &tx2, &ty2, tx1, ty1, -900 );
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( tx2 != tx1 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
s_EndSegmentSlope = ( ty2 - ty1 ) / ( tx2 - tx1 );
|
|
|
|
s_EndSegment_Yorg = ty1 - ( ty2 - ty1 ) * tx1 / ( tx2 - tx1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_EndPointVertical = true; //signal second segment vertical
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ty1 == ty2 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
s_EndPointHorizontal = true;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
// Init parameters for the moved segment
|
2013-01-13 00:04:00 +00:00
|
|
|
tx1 = (double) Track->GetStart().x;
|
|
|
|
ty1 = (double) Track->GetStart().y;
|
|
|
|
tx2 = (double) Track->GetEnd().x;
|
|
|
|
ty2 = (double) Track->GetEnd().y;
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( tx2 != tx1 )
|
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
s_MovingSegmentSlope = ( ty2 - ty1 ) / ( tx2 - tx1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-15 17:58:35 +00:00
|
|
|
s_MovingSegmentVertical = true; // signal vertical line
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ty1 == ty2 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
s_MovingSegmentHorizontal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if drag is possible:
|
|
|
|
if( s_MovingSegmentVertical )
|
|
|
|
{
|
|
|
|
if( s_EndPointVertical || s_StartPointVertical )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( !s_EndPointVertical && ( s_MovingSegmentSlope == s_EndSegmentSlope ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( !s_StartPointVertical && ( s_MovingSegmentSlope == s_StartSegmentSlope ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aCommand )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-15 17:58:35 +00:00
|
|
|
if( !aTrack )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Change highlighted net: the new one will be highlighted
|
2011-09-14 20:04:58 +00:00
|
|
|
GetBoard()->PushHighLight();
|
2011-04-05 17:49:14 +00:00
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
if( GetBoard()->IsHighLightNetON() )
|
2011-10-17 20:01:27 +00:00
|
|
|
HighLight( aDC );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
PosInit = GetCrossHairPosition();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aTrack->Type() == PCB_VIA_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
aTrack->SetFlags( IS_DRAGGED | STARTPOINT | ENDPOINT );
|
2012-09-11 07:33:17 +00:00
|
|
|
AddSegmentToDragList( aTrack->GetFlags(), aTrack );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
if( aCommand != ID_POPUP_PCB_MOVE_TRACK_SEGMENT )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
Collect_TrackSegmentsToDrag( GetBoard(), aTrack->GetStart(),
|
2014-06-24 16:17:18 +00:00
|
|
|
aTrack->GetLayerSet(),
|
2014-02-25 10:40:34 +00:00
|
|
|
aTrack->GetNetCode(), aTrack->GetWidth() / 2 );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
PosInit = aTrack->GetStart();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
STATUS_FLAGS diag = aTrack->IsPointOnEnds( GetCrossHairPosition(), -1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
wxPoint pos;
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
switch( aCommand )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2010-08-31 15:54:05 +00:00
|
|
|
case ID_POPUP_PCB_MOVE_TRACK_SEGMENT: // Move segment
|
2011-12-21 13:42:02 +00:00
|
|
|
aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT );
|
2012-09-11 07:33:17 +00:00
|
|
|
AddSegmentToDragList( aTrack->GetFlags(), aTrack );
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
case ID_POPUP_PCB_DRAG_TRACK_SEGMENT: // drag a segment
|
2013-01-13 00:04:00 +00:00
|
|
|
pos = aTrack->GetStart();
|
2014-06-24 16:17:18 +00:00
|
|
|
Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->GetLayerSet(),
|
2014-02-25 10:40:34 +00:00
|
|
|
aTrack->GetNetCode(), aTrack->GetWidth() / 2 );
|
2013-01-13 00:04:00 +00:00
|
|
|
pos = aTrack->GetEnd();
|
2011-12-21 13:42:02 +00:00
|
|
|
aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT );
|
2014-06-24 16:17:18 +00:00
|
|
|
Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->GetLayerSet(),
|
2014-02-25 10:40:34 +00:00
|
|
|
aTrack->GetNetCode(), aTrack->GetWidth() / 2 );
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
case ID_POPUP_PCB_MOVE_TRACK_NODE: // Drag via or move node
|
2013-01-13 00:04:00 +00:00
|
|
|
pos = (diag & STARTPOINT) ? aTrack->GetStart() : aTrack->GetEnd();
|
2014-06-24 16:17:18 +00:00
|
|
|
Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->GetLayerSet(),
|
2014-02-25 10:40:34 +00:00
|
|
|
aTrack->GetNetCode(), aTrack->GetWidth() / 2 );
|
2007-08-10 19:14:51 +00:00
|
|
|
PosInit = pos;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
aTrack->SetFlags( IS_DRAGGED );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
// Prepare the Undo command
|
2011-09-15 17:58:35 +00:00
|
|
|
ITEM_PICKER picker( aTrack, UR_CHANGED );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetLink( aTrack->Clone() );
|
2009-08-08 06:07:08 +00:00
|
|
|
s_ItemsListPicker.PushItem( picker );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK* draggedtrack = g_DragSegmentList[ii].m_Track;
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( draggedtrack );
|
|
|
|
picker.SetLink( draggedtrack->Clone() );
|
2009-08-08 06:07:08 +00:00
|
|
|
s_ItemsListPicker.PushItem( picker );
|
2012-02-05 13:02:46 +00:00
|
|
|
draggedtrack = (TRACK*) picker.GetLink();
|
2009-08-08 06:07:08 +00:00
|
|
|
draggedtrack->SetStatus( 0 );
|
2011-12-21 13:42:02 +00:00
|
|
|
draggedtrack->ClearFlags();
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
s_LastPos = PosInit;
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( Show_MoveNode, Abort_MoveTrack );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
GetBoard()->SetHighLightNet( aTrack->GetNetCode() );
|
2011-09-14 20:04:58 +00:00
|
|
|
GetBoard()->HighLightON();
|
2009-02-25 16:35:47 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
GetBoard()->DrawHighLight( m_canvas, aDC, GetBoard()->GetHighLightNetCode() );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
|
2008-03-04 05:40:15 +00:00
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
TRACK* TrackToStartPoint = NULL;
|
|
|
|
TRACK* TrackToEndPoint = NULL;
|
2010-08-31 15:54:05 +00:00
|
|
|
bool error = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( !track )
|
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2015-02-27 14:33:13 +00:00
|
|
|
// TODO: Use cleanup functions to merge collinear segments if track
|
2012-09-11 07:33:17 +00:00
|
|
|
// is connected to a collinear segment.
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
s_StartSegmentPresent = s_EndSegmentPresent = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( ( track->start == NULL ) || ( track->start->Type() == PCB_TRACE_T ) )
|
2014-05-17 17:36:02 +00:00
|
|
|
TrackToStartPoint = track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_START, true, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
// Test if more than one segment is connected to this point
|
|
|
|
if( TrackToStartPoint )
|
|
|
|
{
|
2013-03-27 18:32:12 +00:00
|
|
|
TrackToStartPoint->SetState( BUSY, true );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( ( TrackToStartPoint->Type() == PCB_VIA_T )
|
2014-05-17 17:36:02 +00:00
|
|
|
|| track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_START, true, false ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
error = true;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
TrackToStartPoint->SetState( BUSY, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( ( track->end == NULL ) || ( track->end->Type() == PCB_TRACE_T ) )
|
2014-05-17 17:36:02 +00:00
|
|
|
TrackToEndPoint = track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_END, true, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
// Test if more than one segment is connected to this point
|
|
|
|
if( TrackToEndPoint )
|
|
|
|
{
|
2013-03-27 18:32:12 +00:00
|
|
|
TrackToEndPoint->SetState( BUSY, true );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (TrackToEndPoint->Type() == PCB_VIA_T)
|
2014-05-17 17:36:02 +00:00
|
|
|
|| track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_END, true, false ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
error = true;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
TrackToEndPoint->SetState( BUSY, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( error )
|
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
DisplayError( this,
|
|
|
|
_( "Unable to drag this segment: too many segments connected" ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( !TrackToStartPoint || ( TrackToStartPoint->Type() != PCB_TRACE_T ) )
|
2010-08-31 15:54:05 +00:00
|
|
|
s_StartSegmentPresent = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( !TrackToEndPoint || ( TrackToEndPoint->Type() != PCB_TRACE_T ) )
|
2010-08-31 15:54:05 +00:00
|
|
|
s_EndSegmentPresent = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Change high light net: the new one will be highlighted
|
2011-09-14 20:04:58 +00:00
|
|
|
GetBoard()->PushHighLight();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
if( GetBoard()->IsHighLightNetON() )
|
2011-10-17 20:01:27 +00:00
|
|
|
HighLight( DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
track->SetFlags( IS_DRAGGED );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( TrackToStartPoint )
|
|
|
|
{
|
2013-03-28 19:12:46 +00:00
|
|
|
STATUS_FLAGS flag = STARTPOINT;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
if( track->GetStart() != TrackToStartPoint->GetStart() )
|
2007-08-10 19:14:51 +00:00
|
|
|
flag = ENDPOINT;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
AddSegmentToDragList( flag, TrackToStartPoint );
|
2011-12-21 13:42:02 +00:00
|
|
|
track->SetFlags( STARTPOINT );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( TrackToEndPoint )
|
|
|
|
{
|
2013-03-28 19:12:46 +00:00
|
|
|
STATUS_FLAGS flag = STARTPOINT;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
if( track->GetEnd() != TrackToEndPoint->GetStart() )
|
2007-08-10 19:14:51 +00:00
|
|
|
flag = ENDPOINT;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
AddSegmentToDragList( flag, TrackToEndPoint );
|
2011-12-21 13:42:02 +00:00
|
|
|
track->SetFlags( ENDPOINT );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
AddSegmentToDragList( track->GetFlags(), track );
|
|
|
|
|
|
|
|
UndrawAndMarkSegmentsToDrag( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
PosInit = GetCrossHairPosition();
|
|
|
|
s_LastPos = GetCrossHairPosition();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( Show_Drag_Track_Segment_With_Cte_Slope, Abort_MoveTrack );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
GetBoard()->SetHighLightNet( track->GetNetCode() );
|
2011-09-14 20:04:58 +00:00
|
|
|
GetBoard()->HighLightON();
|
2011-12-22 13:28:11 +00:00
|
|
|
GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
// Prepare the Undo command
|
|
|
|
ITEM_PICKER picker( NULL, UR_CHANGED );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
TRACK* draggedtrack = g_DragSegmentList[ii].m_Track;
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( draggedtrack);
|
|
|
|
picker.SetLink ( draggedtrack->Clone() );
|
2009-08-08 06:07:08 +00:00
|
|
|
s_ItemsListPicker.PushItem( picker );
|
2012-02-05 13:02:46 +00:00
|
|
|
draggedtrack = (TRACK*) picker.GetLink();
|
2009-08-08 06:07:08 +00:00
|
|
|
draggedtrack->SetStatus( 0 );
|
2011-12-21 13:42:02 +00:00
|
|
|
draggedtrack->ClearFlags();
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( !InitialiseDragParameters() )
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DisplayError( this, _( "Unable to drag this segment: two collinear segments" ) );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2011-12-22 13:28:11 +00:00
|
|
|
Abort_MoveTrack( m_canvas, DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Place a dragged (or moved) track segment or via
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int errdrc;
|
|
|
|
|
|
|
|
if( Track == NULL )
|
2010-08-31 15:54:05 +00:00
|
|
|
return false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
int current_net_code = Track->GetNetCode();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
// DRC control:
|
2013-03-27 18:32:12 +00:00
|
|
|
if( g_Drc_On )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
errdrc = m_drc->Drc( Track, GetBoard()->m_Track );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( errdrc == BAD_DRC )
|
2010-08-31 15:54:05 +00:00
|
|
|
return false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Redraw the dragged segments
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
errdrc = m_drc->Drc( g_DragSegmentList[ii].m_Track, GetBoard()->m_Track );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( errdrc == BAD_DRC )
|
2010-08-31 15:54:05 +00:00
|
|
|
return false;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DRC Ok: place track segments
|
2011-12-21 13:42:02 +00:00
|
|
|
Track->ClearFlags();
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( IN_EDIT, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Draw dragged tracks
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
Track = g_DragSegmentList[ii].m_Track;
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( IN_EDIT, false );
|
2011-12-21 13:42:02 +00:00
|
|
|
Track->ClearFlags();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
/* Test the connections modified by the move
|
2009-11-18 12:52:19 +00:00
|
|
|
* (only pad connection must be tested, track connection will be
|
2011-09-15 17:58:35 +00:00
|
|
|
* tested by TestNetConnection() ) */
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET layerMask( Track->GetLayer() );
|
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
Track->start = GetBoard()->GetPadFast( Track->GetStart(), layerMask );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-09-07 09:27:02 +00:00
|
|
|
if( Track->start )
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( BEGIN_ONPAD, true );
|
2011-09-07 09:27:02 +00:00
|
|
|
else
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( BEGIN_ONPAD, false );
|
2011-09-07 09:27:02 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
Track->end = GetBoard()->GetPadFast( Track->GetEnd(), layerMask );
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2011-09-07 09:27:02 +00:00
|
|
|
if( Track->end )
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( END_ONPAD, true );
|
2011-09-07 09:27:02 +00:00
|
|
|
else
|
2013-03-27 18:32:12 +00:00
|
|
|
Track->SetState( END_ONPAD, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED );
|
2011-09-07 19:41:04 +00:00
|
|
|
s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
|
2009-08-08 06:07:08 +00:00
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
GetBoard()->PopHighLight();
|
2011-04-15 14:10:20 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( current_net_code > 0 )
|
2011-09-15 17:58:35 +00:00
|
|
|
TestNetConnection( DC, current_net_code );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
m_canvas->Refresh();
|
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|